From 2b4e096204f14023834016b832ba65afbc96c53f Mon Sep 17 00:00:00 2001 From: Wlodek Wencel Date: Fri, 11 Dec 2020 12:59:51 +0100 Subject: [PATCH 1/2] changed incorrect tests, added missing --- .../test_host_reservation_conflicts.py | 780 +++++++-------- .../test_host_reservation_conflicts_mysql.py | 904 ------------------ tests/dhcpv4/process/test_v4_release.py | 8 +- tests/dhcpv4/process/test_v4_request_part1.py | 17 +- .../protosupport/multi_protocol_functions.py | 2 +- .../kea6_server/mysql_reservation.py | 2 +- .../kea6_server/pgsql_reservation.py | 8 +- tests/srv_control.py | 2 + 8 files changed, 350 insertions(+), 1373 deletions(-) delete mode 100644 tests/dhcpv4/kea_only/host_reservation/test_host_reservation_conflicts_mysql.py diff --git a/tests/dhcpv4/kea_only/host_reservation/test_host_reservation_conflicts.py b/tests/dhcpv4/kea_only/host_reservation/test_host_reservation_conflicts.py index dd449350..16cc2423 100644 --- a/tests/dhcpv4/kea_only/host_reservation/test_host_reservation_conflicts.py +++ b/tests/dhcpv4/kea_only/host_reservation/test_host_reservation_conflicts.py @@ -7,30 +7,94 @@ import pytest import misc import srv_control import srv_msg +from forge_cfg import world + + +def _add_reservation(reservation, exp_result=0, exp_failed=False): + cmd = {"command": "reservation-add", "arguments": {"reservation": reservation}, "service": ['dhcp4']} + if "subnet-id" not in cmd["arguments"]["reservation"]: + cmd["arguments"]["reservation"].update({"subnet-id": 1}) + result = srv_msg.send_ctrl_cmd_via_http(command=cmd, exp_result=exp_result, exp_failed=exp_failed) + if result is None: + return None + return result[0] @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -def test_v4_host_reservation_conflicts_duplicate_mac_reservations(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_duplicate_mac_reservations(backend): misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.10', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') # the same MAC address - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.12', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') # the same MAC address + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.10', + 0, + 'hw-address', + 'ff:01:02:03:ff:04') # the same MAC address + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.12', + 0, + 'hw-address', + 'ff:01:02:03:ff:04') # the same MAC address + srv_control.build_and_send_config_files('SSH', 'config-file') + srv_control.start_srv_during_process('DHCP', 'configuration') + + # expected error logs + srv_msg.log_contains(r'ERROR \[kea-dhcp4.dhcp4') + srv_msg.log_contains(r'failed to add new host using the HW address') + else: + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.open_control_channel() + srv_control.dump_db_reservation(backend) + srv_control.new_db_backend_reservation(backend, 'hw-address', 'ff:01:02:03:ff:11') + srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', backend, 1) + srv_control.update_db_backend_reservation('ipv4_address', '192.168.50.2', backend, 1) + srv_control.update_db_backend_reservation('dhcp4_subnet_id', 1, backend, 1) + + srv_control.new_db_backend_reservation(backend, 'hw-address', 'ff:01:02:03:ff:11') + srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', backend, 2) + srv_control.update_db_backend_reservation('ipv4_address', '192.168.50.3', backend, 2) + srv_control.update_db_backend_reservation('dhcp4_subnet_id', 1, backend, 2) + + # expect failure due to db constrain on unique hw-address + srv_control.upload_db_reservation(backend, exp_failed=True) + + +@pytest.mark.v4 +@pytest.mark.host_reservation +@pytest.mark.kea_only +@pytest.mark.parametrize("backend", ['MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_duplicate_mac_reservations_command_control(backend): + misc.test_setup() + srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + srv_control.enable_db_backend_reservation(backend) srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv_during_process('DHCP', 'configuration') + srv_control.start_srv('DHCP', 'started') + assert _add_reservation({"hw-address": "ff:01:02:03:ff:77", "ip-address": "192.168.50.2"})["text"] == "Host added." + assert _add_reservation({"hw-address": "ff:01:02:03:ff:66", "ip-address": "192.168.50.2"}, exp_result=1)["text"] == "Database duplicate entry error" - # expected error logs - srv_msg.log_contains(r'ERROR \[kea-dhcp4.dhcp4') - srv_msg.log_contains(r'failed to add new host using the HW address') + +@pytest.mark.v4 +@pytest.mark.host_reservation +@pytest.mark.kea_only +@pytest.mark.parametrize("backend", ['MySQL', 'PostgreSQL']) +def test_v4_host_reservation_allowed_duplicate_mac_reservations_command_control(backend): + misc.test_setup() + srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') + srv_control.set_conf_parameter_global('ip-reservations-unique', False) + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + srv_control.enable_db_backend_reservation(backend) + srv_control.build_and_send_config_files('SSH', 'config-file') + srv_control.start_srv('DHCP', 'started') + assert _add_reservation({"hw-address": "ff:01:02:03:ff:77", "ip-address": "192.168.50.2"})["text"] == "Host added." + assert _add_reservation({"hw-address": "ff:01:02:03:ff:66", "ip-address": "192.168.50.2"})["text"] == "Host added." @pytest.mark.v4 @@ -51,7 +115,6 @@ def test_v4_host_reservation_conflicts_duplicate_ip_reservations(): 'bb:bb:bb:bb:bb:bb') srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv_during_process('DHCP', 'configuration') - # expected error logs srv_msg.log_contains(r'ERROR \[kea-dhcp4.dhcp4') srv_msg.log_contains(r'failed to add new host using the HW address') @@ -60,25 +123,36 @@ def test_v4_host_reservation_conflicts_duplicate_ip_reservations(): @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -def test_v4_host_reservation_duplicate_ip_reservations_allowed(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_duplicate_ip_reservations_allowed(backend): the_same_ip_address = '192.168.50.10' misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + srv_control.enable_db_backend_reservation(backend) # allow non-unique IP address in multiple reservations srv_control.set_conf_parameter_global('ip-reservations-unique', False) - srv_control.host_reservation_in_subnet('ip-address', - the_same_ip_address, # the same IP - 0, - 'hw-address', - 'aa:aa:aa:aa:aa:aa') - srv_control.host_reservation_in_subnet('ip-address', - the_same_ip_address, # the same IP - 0, - 'hw-address', - 'bb:bb:bb:bb:bb:bb') + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + the_same_ip_address, # the same IP + 0, + 'hw-address', + 'aa:aa:aa:aa:aa:aa') + srv_control.host_reservation_in_subnet('ip-address', + the_same_ip_address, # the same IP + 0, + 'hw-address', + 'bb:bb:bb:bb:bb:bb') + srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') + if backend != "memfile": + assert _add_reservation({"hw-address": "aa:aa:aa:aa:aa:aa", "ip-address": the_same_ip_address})["text"] == "Host added." + assert _add_reservation({"hw-address": "bb:bb:bb:bb:bb:bb", "ip-address": the_same_ip_address})["text"] == "Host added." + # these error logs should not appear srv_msg.log_doesnt_contain(r'ERROR \[kea-dhcp4.dhcp4') srv_msg.log_doesnt_contain(r'failed to add new host using the HW address') @@ -103,6 +177,7 @@ def test_v4_host_reservation_duplicate_ip_reservations_allowed(): srv_msg.response_check_content('yiaddr', the_same_ip_address) 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(),) # release taken IP address misc.test_procedure() @@ -133,6 +208,7 @@ def test_v4_host_reservation_duplicate_ip_reservations_allowed(): srv_msg.response_check_content('yiaddr', the_same_ip_address) 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(),) # try to request address by aa:aa:aa:aa:aa:aa again, the IP address should be just # from the pool (ie. 192.168.50.1) as 192.168.50.10 is already taken by bb:bb:bb:bb:bb:bb @@ -155,26 +231,42 @@ def test_v4_host_reservation_duplicate_ip_reservations_allowed(): 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 for leases is still memfile @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -def test_v4_host_reservation_conflicts_duplicate_reservations_different_subnets(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_duplicate_reservations_different_subnets(backend): misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') - srv_control.config_srv_another_subnet_no_interface('192.168.51.0/24', - '192.168.51.1-192.168.51.50') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.10', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.51.12', - 1, - 'hw-address', - 'ff:01:02:03:ff:04') + if backend == 'memfile': + srv_control.config_srv_another_subnet_no_interface('192.168.51.0/24', + '192.168.51.1-192.168.51.50') + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.10', + 0, + 'hw-address', + 'ff:01:02:03:ff:04') + srv_control.host_reservation_in_subnet('ip-address', + '192.168.51.12', + 1, + 'hw-address', + 'ff:01:02:03:ff:04') + else: + srv_control.dump_db_reservation(backend) + srv_control.new_db_backend_reservation(backend, 'hw-address', 'ff:01:02:03:ff:11') + srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', backend, 1) + srv_control.update_db_backend_reservation('ipv4_address', '192.168.50.2', backend, 1) + srv_control.update_db_backend_reservation('dhcp4_subnet_id', 1, backend, 1) + + srv_control.new_db_backend_reservation(backend, 'hw-address', 'ff:01:02:03:ff:11') + srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', backend, 2) + srv_control.update_db_backend_reservation('ipv4_address', '192.168.51.3', backend, 2) + srv_control.update_db_backend_reservation('dhcp4_subnet_id', 2, backend, 2) + srv_control.upload_db_reservation(backend) + srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') @@ -182,9 +274,12 @@ def test_v4_host_reservation_conflicts_duplicate_reservations_different_subnets( @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_used_address(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_used_address(backend): misc.test_setup() + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.2') srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') @@ -219,15 +314,25 @@ def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_us srv_msg.send_wait_for_message('MUST', 'ACK') misc.test_setup() + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.3') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.2', - 0, - 'hw-address', - 'ff:01:02:03:ff:77') + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.2', + 0, + 'hw-address', + 'ff:01:02:03:ff:77') + else: + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) + srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'reconfigured') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:77", "ip-address": "192.168.50.2"}) + misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:77') srv_msg.client_send_msg('DISCOVER') @@ -235,23 +340,35 @@ def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_us misc.pass_criteria() srv_msg.send_wait_for_message('MUST', 'OFFER') srv_msg.response_check_content('yiaddr', '192.168.50.2', expected=False) + srv_msg.response_check_content('yiaddr', '192.168.50.3') @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_used_address_2(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_reserve_assigned_address_to_different_client(backend): misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.2') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.2', - 0, - 'hw-address', - 'ff:01:02:03:ff:11') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.2', + 0, + 'hw-address', + 'ff:01:02:03:ff:11') + else: + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) + srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:11", "ip-address": "192.168.50.2"}) + misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:11') srv_msg.client_send_msg('DISCOVER') @@ -284,15 +401,25 @@ def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_us misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.3') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.2', - 0, - 'hw-address', - 'ff:01:02:03:ff:77') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.2', + 0, + 'hw-address', + 'ff:01:02:03:ff:77') + else: + srv_control.dump_db_reservation(backend) + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'reconfigured') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:77", "ip-address": "192.168.50.2"}) + misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:77') srv_msg.client_send_msg('DISCOVER') @@ -305,18 +432,29 @@ def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_us @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_used_address_3(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_change_reserved_address_during_reconfigure(backend): misc.test_setup() # reconfigure different address for same MAC from outside of the pool srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.9') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.10', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.10', + 0, + 'hw-address', + 'ff:01:02:03:ff:04') + else: + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) + srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.10"}) + misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') srv_msg.client_send_msg('DISCOVER') @@ -335,15 +473,25 @@ def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_us misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.9') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.30', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.30', + 0, + 'hw-address', + 'ff:01:02:03:ff:04') + else: + srv_control.dump_db_reservation(backend) + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'reconfigured') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.30"}) + misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') srv_msg.client_send_msg('DISCOVER') @@ -365,109 +513,12 @@ def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_us @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_switched_mac_in_reservations_in_pool(): - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.30') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.10', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - 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.10') - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.30') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.10', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - 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.10', expected=False) - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_switched_mac_in_reservations_out_of_pool(): - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.30') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - 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.50') - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.30') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - 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.50', expected=False) - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_add_reservation_for_host_that_has_leases(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_reconfigure_server_add_reservation_for_host_that_has_lease(backend): misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') @@ -489,15 +540,25 @@ def test_v4_host_reservation_conflicts_reconfigure_server_add_reservation_for_ho misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.50', + 0, + 'hw-address', + 'ff:01:02:03:ff:04') + else: + srv_control.dump_db_reservation(backend) + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'reconfigured') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.50"}) + misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') srv_msg.client_send_msg('DISCOVER') @@ -542,14 +603,16 @@ def test_v4_host_reservation_conflicts_reconfigure_server_add_reservation_for_ho @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -@pytest.mark.disabled -def test_v4_host_reservation_conflicts_renew_address_that_has_been_reserved_during_reconfiguration(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_renew_address_using_different_mac_that_has_been_reserved_during_reconfiguration(backend): misc.test_setup() srv_control.set_time('renew-timer', 3) srv_control.set_time('rebind-timer', 50) srv_control.set_time('valid-lifetime', 500) srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') @@ -577,174 +640,24 @@ def test_v4_host_reservation_conflicts_renew_address_that_has_been_reserved_duri srv_control.set_time('rebind-timer', 50) srv_control.set_time('valid-lifetime', 500) srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.10') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - srv_msg.client_send_msg('DISCOVER') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.5', + 0, + 'hw-address', + 'ff:01:02:03:ff:04') + else: + srv_control.dump_db_reservation(backend) + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5', expected=False) - - misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_renew_address_using_different_mac_that_has_been_reserved_during_reconfiguration(): - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.10') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'reconfigured') - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5', expected=False) - - misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -@pytest.mark.disabled -def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_during_reconfigure(): - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.10') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.5"}) misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') @@ -764,14 +677,6 @@ def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_d srv_msg.forge_sleep(6, 'seconds') - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5') - misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') srv_msg.client_copy_option('server_id') @@ -779,28 +684,38 @@ def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_d 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.5') + srv_msg.send_wait_for_message('MUST', 'NAK') @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_during_reconfigure_2(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_during_reconfigure(backend): misc.test_setup() srv_control.set_time('renew-timer', 3) srv_control.set_time('rebind-timer', 50) srv_control.set_time('valid-lifetime', 500) srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.5', + 0, + 'hw-address', + 'ff:01:02:03:ff:01') + else: + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) + srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:01", "ip-address": "192.168.50.5"}) + misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') srv_msg.client_send_msg('DISCOVER') @@ -825,14 +740,25 @@ def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_d srv_control.set_time('rebind-timer', 50) srv_control.set_time('valid-lifetime', 500) srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.60') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.50', + 0, + 'hw-address', + 'ff:01:02:03:ff:01') + else: + srv_control.dump_db_reservation(backend) + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) + srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'reconfigured') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:01", "ip-address": "192.168.50.50"}) + misc.test_procedure() srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') @@ -865,82 +791,41 @@ def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_d @pytest.mark.v4 @pytest.mark.host_reservation @pytest.mark.kea_only -@pytest.mark.disabled -def test_v4_host_reservation_conflicts_rebind_address_which_reservation_changed_during_reconfigure(): +@pytest.mark.parametrize("backend", ['memfile', 'MySQL', 'PostgreSQL']) +def test_v4_host_reservation_conflicts_rebind_address_which_reservation_changed_during_reconfigure(backend): misc.test_setup() srv_control.set_time('renew-timer', 3) srv_control.set_time('rebind-timer', 4) srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') + srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.5', + 0, + 'hw-address', + 'ff:01:02:03:ff:01') + else: + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) + srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:01", "ip-address": "192.168.50.5"}) misc.test_procedure() srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 4) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.10') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5', expected=False) misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') srv_msg.client_copy_option('server_id') srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') srv_msg.client_send_msg('REQUEST') @@ -949,57 +834,32 @@ def test_v4_host_reservation_conflicts_rebind_address_which_reservation_changed_ srv_msg.send_wait_for_message('MUST', 'ACK') srv_msg.response_check_content('yiaddr', '192.168.50.5') - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_rebind_address_which_reservation_changed_during_reconfigure_2(): + srv_msg.forge_sleep(5, 'seconds') misc.test_setup() srv_control.set_time('renew-timer', 3) srv_control.set_time('rebind-timer', 4) srv_control.set_time('valid-lifetime', 500) srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') + srv_control.open_control_channel() + srv_control.agent_control_channel(world.f_cfg.mgmt_address) + if backend == 'memfile': + srv_control.host_reservation_in_subnet('ip-address', + '192.168.50.50', + 0, + 'hw-address', + 'ff:01:02:03:ff:01') + else: + srv_control.dump_db_reservation(backend) + srv_control.add_hooks('libdhcp_host_cmds.so') + srv_control.enable_db_backend_reservation(backend) - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 4) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.60') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') srv_control.build_and_send_config_files('SSH', 'config-file') srv_control.start_srv('DHCP', 'reconfigured') + if backend != 'memfile': + _add_reservation({"hw-address": "ff:01:02:03:ff:01", "ip-address": "192.168.50.50"}) + misc.test_procedure() srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') diff --git a/tests/dhcpv4/kea_only/host_reservation/test_host_reservation_conflicts_mysql.py b/tests/dhcpv4/kea_only/host_reservation/test_host_reservation_conflicts_mysql.py deleted file mode 100644 index 51ee3897..00000000 --- a/tests/dhcpv4/kea_only/host_reservation/test_host_reservation_conflicts_mysql.py +++ /dev/null @@ -1,904 +0,0 @@ -"""Host Reservation DHCPv4""" - -# pylint: disable=invalid-name,line-too-long - -import pytest - -import srv_msg -import srv_control -import misc - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_duplicate_mac_reservations_mysql(): - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') - srv_control.new_db_backend_reservation('MySQL', 'hw-address', 'ff:01:02:03:ff:11') - srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', 'MySQL', 1) - srv_control.update_db_backend_reservation('ipv4_address', '192.168.50.2', 'MySQL', 1) - srv_control.update_db_backend_reservation('dhcp4_subnet_id', 1, 'MySQL', 1) - - srv_control.new_db_backend_reservation('MySQL', 'hw-address', 'ff:01:02:03:ff:11') - srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', 'MySQL', 2) - srv_control.update_db_backend_reservation('ipv4_address', '192.168.50.3', 'MySQL', 2) - srv_control.update_db_backend_reservation('dhcp4_subnet_id', 1, 'MySQL', 2) - - # expect failure due to db constrain on unique hw-address - srv_control.upload_db_reservation('MySQL', exp_failed=True) - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_duplicate_reservations_different_subnets_mysql(): - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') - srv_control.config_srv_another_subnet_no_interface('192.168.51.0/24', - '192.168.51.1-192.168.51.50') - srv_control.new_db_backend_reservation('MySQL', 'hw-address', 'ff:01:02:03:ff:11') - srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', 'MySQL', 1) - srv_control.update_db_backend_reservation('ipv4_address', '192.168.50.2', 'MySQL', 1) - srv_control.update_db_backend_reservation('dhcp4_subnet_id', 1, 'MySQL', 1) - - srv_control.new_db_backend_reservation('MySQL', 'hw-address', 'ff:01:02:03:ff:11') - srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', 'MySQL', 2) - srv_control.update_db_backend_reservation('ipv4_address', '192.168.51.3', 'MySQL', 2) - srv_control.update_db_backend_reservation('dhcp4_subnet_id', 2, 'MySQL', 2) - srv_control.upload_db_reservation('MySQL') - - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_mysql_reconfigure_server_with_reservation_of_used_address(): - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.2') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:11') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:11') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'ACK') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:55') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:55') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'ACK') - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.3') - - srv_control.new_db_backend_reservation('MySQL', 'hw-address', 'ff:01:02:03:ff:77') - srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', 'MySQL', 1) - srv_control.update_db_backend_reservation('ipv4_address', '192.168.50.2', 'MySQL', 1) - srv_control.update_db_backend_reservation('dhcp4_subnet_id', 1, 'MySQL', 1) - srv_control.upload_db_reservation('MySQL') - - # Reserve address 192.168.50.2 in subnet 0 for host uniquely identified by hw-address ff:01:02:03:ff:77. - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:77') - 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.2', expected=False) - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_mysql_reconfigure_server_with_reservation_of_used_address_2(): - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.2') - - srv_control.new_db_backend_reservation('MySQL', 'hw-address', 'ff:01:02:03:ff:11') - srv_control.update_db_backend_reservation('hostname', 'reserved-hostname', 'MySQL', 1) - srv_control.update_db_backend_reservation('ipv4_address', '192.168.50.2', 'MySQL', 1) - srv_control.update_db_backend_reservation('dhcp4_subnet_id', 1, 'MySQL', 1) - srv_control.upload_db_reservation('MySQL') - - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:11') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:11') - 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') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:55') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:55') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'ACK') - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.3') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.2', - 0, - 'hw-address', - 'ff:01:02:03:ff:77') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:77') - 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.2', expected=False) - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_with_reservation_of_used_address_3(): - misc.test_setup() - # reconfigure different address for same MAC from outside of the pool - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.9') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.10', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - 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.10') - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.9') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.30', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.30') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - 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.30') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_switched_mac_in_reservations_in_pool(): - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.30') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.10', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - 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.10') - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.30') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.10', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - 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.10', expected=False) - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_switched_mac_in_reservations_out_of_pool(): - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.30') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - 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.50') - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.30') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - 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.50', expected=False) - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_reconfigure_server_add_reservation_for_host_that_has_leases(): - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - 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.5') - - misc.test_setup() - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - 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', 'ff:01:02:03:ff:04') - 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.50') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - 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.50') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_copy_option('server_id') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - 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.5') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_renew_address_that_has_been_reserved_during_reconfiguration(): - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.10') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5', expected=False) - - misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_renew_address_using_different_mac_that_has_been_reserved_during_reconfiguration(): - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.10') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5', expected=False) - - misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_during_reconfigure(): - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.10') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5', expected=False) - - misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_renew_address_which_reservation_changed_during_reconfigure_2(): - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 50) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.60') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - 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.50') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.50') - 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.50') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_rebind_address_which_reservation_changed_during_reconfigure(): - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 4) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 4) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.10') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:04') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5', expected=False) - - misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - # TODO indeed this is a bug, or incomplete feature, kea should remove lease when: - # address X was assigned to client A - # kea was reconfigured and address X is now reserved for client B - # client A tried to rebind address but he was denied - which is good - # bud kea didn't reclaim that address, it will be waiting until valid lifetime will pass - - misc.test_procedure() - 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_wait_for_message('MUST', 'OFFER') - srv_msg.response_check_content('yiaddr', '192.168.50.5') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - -@pytest.mark.v4 -@pytest.mark.host_reservation -@pytest.mark.kea_only -def test_v4_host_reservation_conflicts_rebind_address_which_reservation_changed_during_reconfigure_2(): - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 4) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.50') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.5', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'started') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('DISCOVER') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'OFFER') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - 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.5') - - srv_msg.forge_sleep(5, 'seconds') - - misc.test_setup() - srv_control.set_time('renew-timer', 3) - srv_control.set_time('rebind-timer', 4) - srv_control.set_time('valid-lifetime', 500) - srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.60') - srv_control.host_reservation_in_subnet('ip-address', - '192.168.50.50', - 0, - 'hw-address', - 'ff:01:02:03:ff:01') - srv_control.build_and_send_config_files('SSH', 'config-file') - srv_control.start_srv('DHCP', 'reconfigured') - - misc.test_procedure() - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.5') - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_send_msg('REQUEST') - - misc.pass_criteria() - srv_msg.send_wait_for_message('MUST', 'NAK') - - srv_msg.forge_sleep(6, 'seconds') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - 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.50') - - misc.test_procedure() - srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:01') - srv_msg.client_copy_option('server_id') - srv_msg.client_does_include_with_value('requested_addr', '192.168.50.50') - 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.50') diff --git a/tests/dhcpv4/process/test_v4_release.py b/tests/dhcpv4/process/test_v4_release.py index 3d546199..1b42a2f2 100644 --- a/tests/dhcpv4/process/test_v4_release.py +++ b/tests/dhcpv4/process/test_v4_release.py @@ -11,15 +11,18 @@ import srv_msg @pytest.mark.v4 @pytest.mark.release -def test_v4_release_success(): +@pytest.mark.parametrize("backend", ['memfile', 'mysql', 'postgresql']) +def test_v4_release_success(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('SSH', 'config-file') 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:11:11:22') srv_msg.client_send_msg('DISCOVER') misc.pass_criteria() @@ -30,6 +33,7 @@ def test_v4_release_success(): misc.test_procedure() srv_msg.client_copy_option('server_id') + srv_msg.client_sets_value('Client', 'chaddr', '00:00:00:11:11:22') 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') @@ -38,6 +42,8 @@ def test_v4_release_success(): srv_msg.send_wait_for_message('MUST', 'ACK') srv_msg.response_check_content('yiaddr', '192.168.50.1') srv_msg.response_check_option_content(1, 'value', '255.255.255.0') + my_lease = srv_msg.get_all_leases() + srv_msg.check_leases(my_lease, backend=backend) misc.test_procedure() srv_msg.client_copy_option('server_id') diff --git a/tests/dhcpv4/process/test_v4_request_part1.py b/tests/dhcpv4/process/test_v4_request_part1.py index ad4762b0..1c18bd8c 100644 --- a/tests/dhcpv4/process/test_v4_request_part1.py +++ b/tests/dhcpv4/process/test_v4_request_part1.py @@ -11,9 +11,11 @@ import srv_msg @pytest.mark.v4 @pytest.mark.request -def test_v4_request_selecting_success_chaddr(): +@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('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') @@ -39,13 +41,16 @@ def test_v4_request_selecting_success_chaddr(): 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 -def test_v4_request_selecting_success_chaddr_multiple_pools(): +@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) @@ -75,6 +80,7 @@ def test_v4_request_selecting_success_chaddr_multiple_pools(): 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) @@ -99,6 +105,7 @@ def test_v4_request_selecting_success_chaddr_multiple_pools(): 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) @@ -123,6 +130,7 @@ def test_v4_request_selecting_success_chaddr_multiple_pools(): 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 @@ -171,9 +179,11 @@ def test_v4_request_selecting_success_chaddr_empty_pool(): @pytest.mark.v4 @pytest.mark.request -def test_v4_request_selecting_success_client_id(): +@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('SSH', 'config-file') srv_control.start_srv('DHCP', 'started') @@ -209,6 +219,7 @@ def test_v4_request_selecting_success_client_id(): 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 diff --git a/tests/protosupport/multi_protocol_functions.py b/tests/protosupport/multi_protocol_functions.py index 32056d34..793e8eef 100644 --- a/tests/protosupport/multi_protocol_functions.py +++ b/tests/protosupport/multi_protocol_functions.py @@ -602,7 +602,7 @@ def check_leases(leases_list, backend='memfile', destination=world.f_cfg.mgmt_ad assert False, "Lease do NOT contain lease: %s" % json.dumps(lease) # TODO write check if there is more than one entry of the same type - elif backend in ['mysql', 'postgresql']: + elif backend.lower() in ['mysql', 'postgresql', 'pgsql']: for lease in leases_list: if world.f_cfg.proto == 'v4': table = 'lease4' diff --git a/tests/softwaresupport/kea6_server/mysql_reservation.py b/tests/softwaresupport/kea6_server/mysql_reservation.py index e862c1e0..d9021b6d 100644 --- a/tests/softwaresupport/kea6_server/mysql_reservation.py +++ b/tests/softwaresupport/kea6_server/mysql_reservation.py @@ -278,7 +278,7 @@ def clear_all_reservations(): db_name = world.f_cfg.db_name db_user = world.f_cfg.db_user db_passwd = world.f_cfg.db_passwd - command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6;' \ + command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts;' \ ' do mysql -u {db_user} -p{db_passwd} -e "SET foreign_key_checks = 0;' \ ' delete from $table_name" {db_name}; done'.format(**locals()) fabric_run_command(command) diff --git a/tests/softwaresupport/kea6_server/pgsql_reservation.py b/tests/softwaresupport/kea6_server/pgsql_reservation.py index 8af51b70..9e9f0265 100644 --- a/tests/softwaresupport/kea6_server/pgsql_reservation.py +++ b/tests/softwaresupport/kea6_server/pgsql_reservation.py @@ -229,9 +229,11 @@ def upload_db_reservation(exp_failed=False): fabric_send_file("db_reservation", remote_db_path) copy_configuration_file("db_reservation") remove_local_file("db_reservation") - result = fabric_sudo_command('PGPASSWORD={db_passwd} psql -h localhost -U {db_user} -d {db_name} < {remote_db_path}'.format(**locals()), ignore_errors=True) + result = fabric_sudo_command('PGPASSWORD={db_passwd} psql -h localhost -U {db_user} -d {db_name} < {remote_db_path}'.format(**locals()), + ignore_errors=True) + # pgsql insert do not return non zero status on failed command, we need to check stdout if exp_failed: - if result.failed: + if 'ERROR: current transaction is aborted' in result.stdout: fail_spotted = True else: assert result.succeeded @@ -244,7 +246,7 @@ def clear_all_reservations(): db_name = world.f_cfg.db_name db_user = world.f_cfg.db_user db_passwd = world.f_cfg.db_passwd - command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts lease4 lease6; do PGPASSWORD={db_passwd} psql -h localhost -U {db_user} -d {db_name} -c "delete from $table_name" ; done'.format(**locals()) + command = 'for table_name in dhcp4_options dhcp6_options ipv6_reservations hosts; do PGPASSWORD={db_passwd} psql -h localhost -U {db_user} -d {db_name} -c "delete from $table_name" ; done'.format(**locals()) fabric_run_command(command) diff --git a/tests/srv_control.py b/tests/srv_control.py index 01f60f23..f1fc50aa 100644 --- a/tests/srv_control.py +++ b/tests/srv_control.py @@ -297,6 +297,8 @@ def enable_db_backend_reservation(db_type): elif db_type == 'Cassandra': cql_reservation.enable_db_backend_reservation() cql_reservation.clear_all_reservations() + elif db_type == "memfile": + pass else: assert False, "Database type not recognised." -- GitLab From f325b3ecc03c991bc6125271f32cca976f6395a5 Mon Sep 17 00:00:00 2001 From: Wlodek Wencel Date: Sun, 13 Dec 2020 06:04:02 +0100 Subject: [PATCH 2/2] fixed parameter in test --- .../test_host_reservation_address_conflicts_mysql.py | 2 +- .../test_host_reservation_address_conflicts_pgsql.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dhcpv6/kea_only/host_reservation/test_host_reservation_address_conflicts_mysql.py b/tests/dhcpv6/kea_only/host_reservation/test_host_reservation_address_conflicts_mysql.py index 6a861590..13882d1d 100644 --- a/tests/dhcpv6/kea_only/host_reservation/test_host_reservation_address_conflicts_mysql.py +++ b/tests/dhcpv6/kea_only/host_reservation/test_host_reservation_address_conflicts_mysql.py @@ -397,7 +397,7 @@ def test_v6_host_reservation_mysql_conflicts_reconfigure_server_with_reservation srv_msg.response_check_option_content(3, 'sub-option', 5) srv_msg.response_check_suboption_content(5, 3, 'validlft', 0) srv_msg.response_check_suboption_content(5, 3, 'addr', '3000::2') - srv_msg.response_check_suboption_content(5, 3, 'validlft', 197) + srv_msg.response_check_suboption_content(5, 3, 'validlft', 107) srv_msg.response_check_suboption_content(5, 3, 'addr', '3000::3') misc.test_procedure() diff --git a/tests/dhcpv6/kea_only/host_reservation/test_host_reservation_address_conflicts_pgsql.py b/tests/dhcpv6/kea_only/host_reservation/test_host_reservation_address_conflicts_pgsql.py index 7b194108..f64534a5 100644 --- a/tests/dhcpv6/kea_only/host_reservation/test_host_reservation_address_conflicts_pgsql.py +++ b/tests/dhcpv6/kea_only/host_reservation/test_host_reservation_address_conflicts_pgsql.py @@ -407,7 +407,7 @@ def test_v6_host_reservation_pgsql_conflicts_reconfigure_server_with_reservation srv_msg.response_check_option_content(3, 'sub-option', 5) srv_msg.response_check_suboption_content(5, 3, 'validlft', 0) srv_msg.response_check_suboption_content(5, 3, 'addr', '3000::2') - srv_msg.response_check_suboption_content(5, 3, 'validlft', 197) + srv_msg.response_check_suboption_content(5, 3, 'validlft', 107) srv_msg.response_check_suboption_content(5, 3, 'addr', '3000::3') misc.test_procedure() -- GitLab