diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-01-03 10:24:20 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-01-03 10:26:43 +0100 |
commit | cdc1748b8489251a45875736a99633740529ea0c (patch) | |
tree | d2d6a4c64bc7e0152a38b5805bbeec56213e92ae /smoketest/scripts | |
parent | cb16068ccde3b39f2e0e2aa450da7df55f782c1c (diff) | |
download | vyos-1x-cdc1748b8489251a45875736a99633740529ea0c.tar.gz vyos-1x-cdc1748b8489251a45875736a99633740529ea0c.zip |
dhcp: T3180: bugfix assignment of sliced ranges to config dict
A reference to a dictionary key obtained by a for loop can not be used to update
values inside that dictionaries key. You must use the original path to the
nested dictionaries key.
Diffstat (limited to 'smoketest/scripts')
-rwxr-xr-x | smoketest/scripts/cli/test_service_dhcp-server.py | 72 |
1 files changed, 67 insertions, 5 deletions
diff --git a/smoketest/scripts/cli/test_service_dhcp-server.py b/smoketest/scripts/cli/test_service_dhcp-server.py index 5bf4b100e..c9ec9ebc0 100755 --- a/smoketest/scripts/cli/test_service_dhcp-server.py +++ b/smoketest/scripts/cli/test_service_dhcp-server.py @@ -23,8 +23,9 @@ from vyos.configsession import ConfigSessionError from vyos.util import cmd from vyos.util import process_named_running from vyos.util import read_file -from vyos.template import inc_ip from vyos.template import address_from_cidr +from vyos.template import inc_ip +from vyos.template import dec_ip from vyos.template import netmask_from_cidr PROCESS_NAME = 'dhcpd' @@ -48,7 +49,7 @@ class TestServiceDHCPServer(unittest.TestCase): self.session.commit() del self.session - def test_single_pool_range(self): + def test_dhcp_single_pool_range(self): shared_net_name = 'SMOKE-1' range_0_start = inc_ip(subnet, 10) @@ -93,7 +94,7 @@ class TestServiceDHCPServer(unittest.TestCase): # Check for running process self.assertTrue(process_named_running(PROCESS_NAME)) - def test_single_pool_options(self): + def test_dhcp_single_pool_options(self): shared_net_name = 'SMOKE-0815' range_0_start = inc_ip(subnet, 10) @@ -197,7 +198,7 @@ class TestServiceDHCPServer(unittest.TestCase): # Check for running process self.assertTrue(process_named_running(PROCESS_NAME)) - def test_single_pool_static_mapping(self): + def test_dhcp_single_pool_static_mapping(self): shared_net_name = 'SMOKE-2' pool = base_path + ['shared-network-name', shared_net_name, 'subnet', subnet] @@ -246,7 +247,7 @@ class TestServiceDHCPServer(unittest.TestCase): # Check for running process self.assertTrue(process_named_running(PROCESS_NAME)) - def test_multi_pools(self): + def test_dhcp_multiple_pools(self): lease_time = '14400' for network in ['0', '1', '2', '3']: @@ -320,5 +321,66 @@ class TestServiceDHCPServer(unittest.TestCase): # Check for running process self.assertTrue(process_named_running(PROCESS_NAME)) + def test_dhcp_exclude_not_in_range(self): + # T3180: verify else path when slicing DHCP ranges and exclude address + # is not part of the DHCP range + range_0_start = inc_ip(subnet, 10) + range_0_stop = inc_ip(subnet, 20) + + pool = base_path + ['shared-network-name', 'EXCLUDE-TEST', 'subnet', subnet] + self.session.set(pool + ['default-router', router]) + self.session.set(pool + ['exclude', router]) + self.session.set(pool + ['range', '0', 'start', range_0_start]) + self.session.set(pool + ['range', '0', 'stop', range_0_stop]) + + # commit changes + self.session.commit() + + # VErify + config = read_file(DHCPD_CONF) + network = address_from_cidr(subnet) + netmask = netmask_from_cidr(subnet) + + self.assertIn(f'subnet {network} netmask {netmask}' + r' {', config) + self.assertIn(f'option routers {router};', config) + self.assertIn(f'range {range_0_start} {range_0_stop};', config) + + # Check for running process + self.assertTrue(process_named_running(PROCESS_NAME)) + + def test_dhcp_exclude_in_range(self): + # T3180: verify else path when slicing DHCP ranges and exclude address + # is not part of the DHCP range + range_0_start = inc_ip(subnet, 10) + range_0_stop = inc_ip(subnet, 100) + + # the DHCP exclude addresse is blanked out of the range which is done + # by slicing one range into two ranges + exclude_addr = inc_ip(range_0_start, 20) + range_0_stop_excl = dec_ip(exclude_addr, 1) + range_0_start_excl = inc_ip(exclude_addr, 1) + + pool = base_path + ['shared-network-name', 'EXCLUDE-TEST-2', 'subnet', subnet] + self.session.set(pool + ['default-router', router]) + self.session.set(pool + ['exclude', exclude_addr]) + self.session.set(pool + ['range', '0', 'start', range_0_start]) + self.session.set(pool + ['range', '0', 'stop', range_0_stop]) + + # commit changes + self.session.commit() + + # VErify + config = read_file(DHCPD_CONF) + network = address_from_cidr(subnet) + netmask = netmask_from_cidr(subnet) + + self.assertIn(f'subnet {network} netmask {netmask}' + r' {', config) + self.assertIn(f'option routers {router};', config) + self.assertIn(f'range {range_0_start} {range_0_stop_excl};', config) + self.assertIn(f'range {range_0_start_excl} {range_0_stop};', config) + + # Check for running process + self.assertTrue(process_named_running(PROCESS_NAME)) + if __name__ == '__main__': unittest.main(verbosity=2) |