diff options
-rwxr-xr-x | smoketest/scripts/cli/test_service_dhcp-server.py | 36 | ||||
-rwxr-xr-x | src/conf_mode/dhcp_server.py | 39 |
2 files changed, 56 insertions, 19 deletions
diff --git a/smoketest/scripts/cli/test_service_dhcp-server.py b/smoketest/scripts/cli/test_service_dhcp-server.py index c9ec9ebc0..db7b2dda4 100755 --- a/smoketest/scripts/cli/test_service_dhcp-server.py +++ b/smoketest/scripts/cli/test_service_dhcp-server.py @@ -369,7 +369,7 @@ class TestServiceDHCPServer(unittest.TestCase): # commit changes self.session.commit() - # VErify + # Verify config = read_file(DHCPD_CONF) network = address_from_cidr(subnet) netmask = netmask_from_cidr(subnet) @@ -382,5 +382,39 @@ class TestServiceDHCPServer(unittest.TestCase): # Check for running process self.assertTrue(process_named_running(PROCESS_NAME)) + def test_dhcp_relay_server(self): + # Listen on specific address and return DHCP leases from a non + # directly connected pool + self.session.set(base_path + ['listen-address', router]) + + relay_subnet = '10.0.0.0/16' + relay_router = inc_ip(relay_subnet, 1) + + range_0_start = '10.0.1.0' + range_0_stop = '10.0.250.255' + + pool = base_path + ['shared-network-name', 'RELAY', 'subnet', relay_subnet] + self.session.set(pool + ['default-router', relay_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() + + config = read_file(DHCPD_CONF) + network = address_from_cidr(subnet) + netmask = netmask_from_cidr(subnet) + # Check the relay network + self.assertIn(f'subnet {network} netmask {netmask}' + r' { }', config) + + relay_network = address_from_cidr(relay_subnet) + relay_netmask = netmask_from_cidr(relay_subnet) + self.assertIn(f'subnet {relay_network} netmask {relay_netmask}' + r' {', config) + self.assertIn(f'option routers {relay_router};', config) + self.assertIn(f'range {range_0_start} {range_0_stop};', config) + + # Check for running process + self.assertTrue(process_named_running(PROCESS_NAME)) + if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/src/conf_mode/dhcp_server.py b/src/conf_mode/dhcp_server.py index 392a69427..84a8736e8 100755 --- a/src/conf_mode/dhcp_server.py +++ b/src/conf_mode/dhcp_server.py @@ -110,24 +110,27 @@ def get_config(config=None): # T2665: defaults include lease time per TAG node which need to be added to # individual subnet definitions default_values = defaults(base + ['shared-network-name', 'subnet']) - for network, network_config in (dict_search('shared_network_name', dhcp).items() or {}): - for subnet, subnet_config in (dict_search('subnet', network_config).items() or {}): - if 'lease' not in subnet_config: - dhcp['shared_network_name'][network]['subnet'][subnet] = dict_merge( - default_values, dhcp['shared_network_name'][network]['subnet'][subnet]) - - # If exclude IP addresses are defined we need to slice them out of - # the defined ranges - if {'exclude', 'range'} <= set(subnet_config): - new_range_id = 0 - new_range_dict = {} - for r, r_config in subnet_config['range'].items(): - for slice in dhcp_slice_range(subnet_config['exclude'], r_config): - new_range_dict.update({new_range_id : slice}) - new_range_id +=1 - - dhcp['shared_network_name'][network]['subnet'][subnet].update( - {'range' : new_range_dict}) + + if 'shared_network_name' in dhcp: + for network, network_config in dhcp['shared_network_name'].items(): + if 'subnet' in network_config: + for subnet, subnet_config in network_config['subnet'].items(): + if 'lease' not in subnet_config: + dhcp['shared_network_name'][network]['subnet'][subnet] = dict_merge( + default_values, dhcp['shared_network_name'][network]['subnet'][subnet]) + + # If exclude IP addresses are defined we need to slice them out of + # the defined ranges + if {'exclude', 'range'} <= set(subnet_config): + new_range_id = 0 + new_range_dict = {} + for r, r_config in subnet_config['range'].items(): + for slice in dhcp_slice_range(subnet_config['exclude'], r_config): + new_range_dict.update({new_range_id : slice}) + new_range_id +=1 + + dhcp['shared_network_name'][network]['subnet'][subnet].update( + {'range' : new_range_dict}) return dhcp |