text: """DHCPv4 address request process"""
  
  # pylint: disable=invalid-name,line-too-long
  
  import pytest
  
  import misc
  import srv_control
  import srv_msg
  
  
  @pytest.mark.v4
  @pytest.mark.request
  @pytest.mark.parametrize("backend", ['memfile', 'mysql', 'postgresql'])
  def test_v4_request_selecting_success_chaddr(backend):
  
      misc.test_setup()
      srv_control.define_temporary_lease_db_backend(backend)
      srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.1')
      srv_control.build_and_send_config_files()
      srv_control.start_srv('DHCP', 'started')
  
      misc.test_procedure()
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
  
      misc.test_procedure()
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.check_leases(srv_msg.get_all_leases(), backend=backend)
  
  
  @pytest.mark.v4
  @pytest.mark.request
  @pytest.mark.parametrize("backend", ['memfile', 'mysql', 'postgresql'])
  def test_v4_request_selecting_success_chaddr_multiple_pools(backend):
  
      misc.test_setup()
      srv_control.define_temporary_lease_db_backend(backend)
      srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.1')
      srv_control.new_pool('192.168.50.2-192.168.50.2', 0)
      srv_control.new_pool('192.168.50.3-192.168.50.3', 0)
      srv_control.build_and_send_config_files()
      srv_control.start_srv('DHCP', 'started')
  
      misc.test_procedure()
      srv_msg.client_requests_option(1)
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:01')
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:01')
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.check_leases(srv_msg.get_all_leases(), backend=backend)
  
      misc.test_procedure()
      srv_msg.client_requests_option(1)
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:02')
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_content('yiaddr', '192.168.50.2')
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:02')
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.2')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.2')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.check_leases(srv_msg.get_all_leases(), backend=backend)
  
      misc.test_procedure()
      srv_msg.client_requests_option(1)
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:03')
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_content('yiaddr', '192.168.50.3')
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:03')
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.3')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.3')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.check_leases(srv_msg.get_all_leases(), backend=backend)
  
  
  @pytest.mark.v4
  @pytest.mark.request
  def test_v4_request_selecting_success_chaddr_empty_pool():
  
      misc.test_setup()
      srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.1')
      srv_control.build_and_send_config_files()
      srv_control.start_srv('DHCP', 'started')
  
      misc.test_procedure()
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.response_check_option_content(54, 'value', '$(SRV4_ADDR)')
  
      misc.test_procedure()
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.response_check_option_content(54, 'value', '$(SRV4_ADDR)')
  
      misc.test_procedure()
      srv_msg.client_requests_option(1)
      srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04')
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_dont_wait_for_message()
  
  
  @pytest.mark.v4
  @pytest.mark.request
  @pytest.mark.parametrize("backend", ['memfile', 'mysql', 'postgresql'])
  def test_v4_request_selecting_success_client_id(backend):
  
      misc.test_setup()
      srv_control.define_temporary_lease_db_backend(backend)
      srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.1')
      srv_control.build_and_send_config_files()
      srv_control.start_srv('DHCP', 'started')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_does_include_with_value('client_id', '00010203040506')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_include_option(61)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.response_check_option_content(61, 'value', '00010203040506')
  
      misc.test_procedure()
      srv_msg.client_does_include_with_value('client_id', '00010203040506')
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_include_option(61)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.response_check_option_content(61, 'value', '00010203040506')
      srv_msg.check_leases(srv_msg.get_all_leases(), backend=backend)
  
  
  @pytest.mark.v4
  @pytest.mark.request
  def test_v4_request_selecting_success_client_id_empty_pool():
  
      misc.test_setup()
      srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.1')
      srv_control.build_and_send_config_files()
      srv_control.start_srv('DHCP', 'started')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_does_include_with_value('client_id', '00010203040506')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_include_option(61)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.response_check_option_content(61, 'value', '00010203040506')
  
      misc.test_procedure()
      srv_msg.client_does_include_with_value('client_id', '00010203040506')
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_include_option(61)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.response_check_option_content(61, 'value', '00010203040506')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_does_include_with_value('client_id', '00020304050607')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_dont_wait_for_message()
  
  
  @pytest.mark.v4
  @pytest.mark.request
  def test_v4_request_selecting_success_client_id_chaddr_empty_pool():
  
      misc.test_setup()
      srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.1')
      srv_control.build_and_send_config_files()
      srv_control.start_srv('DHCP', 'started')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_does_include_with_value('client_id', '00010203040506')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_include_option(61)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.response_check_option_content(61, 'value', '00010203040506')
  
      misc.test_procedure()
      srv_msg.client_does_include_with_value('client_id', '00010203040506')
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_include_option(61)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
      srv_msg.response_check_option_content(61, 'value', '00010203040506')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:11')
      srv_msg.client_does_include_with_value('client_id', '11020304050607')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_dont_wait_for_message()
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_does_include_with_value('client_id', '11020304050607')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_dont_wait_for_message()
  
  
  @pytest.mark.v4
  @pytest.mark.request
  def test_v4_request_selecting_success_second_request_fail():
  
      misc.test_setup()
      srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.1')
      srv_control.build_and_send_config_files()
      srv_control.start_srv('DHCP', 'started')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('DISCOVER')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'OFFER')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:00:00:00')
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'ACK')
      srv_msg.response_check_content('yiaddr', '192.168.50.1')
      srv_msg.response_check_include_option(1)
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_option_content(1, 'value', '255.255.255.0')
  
      misc.test_procedure()
      srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:22:11:00')
      srv_msg.client_copy_option('server_id')
      srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1')
      srv_msg.client_requests_option(1)
      srv_msg.client_send_msg('REQUEST')
  
      misc.pass_criteria()
      srv_msg.send_wait_for_message('MUST', 'NAK')
      srv_msg.response_check_include_option(54)
      srv_msg.response_check_option_content(54, 'value', '$(SRV4_ADDR)')
  