Skip to content

Commit

Permalink
dhcp: T6692: Fix range options not present when exclude is used
Browse files Browse the repository at this point in the history
Add smoketest to verify range options are present with `exclude`
  • Loading branch information
sarthurdev committed Nov 21, 2024
1 parent 1c8321a commit 4e49794
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
23 changes: 20 additions & 3 deletions smoketest/scripts/cli/test_service_dhcp-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ def test_dhcp_exclude_not_in_range(self):
self.cli_set(pool + ['subnet-id', '1'])
self.cli_set(pool + ['option', 'default-router', router])
self.cli_set(pool + ['exclude', router])
self.cli_set(pool + ['range', '0', 'option', 'default-router', router])
self.cli_set(pool + ['range', '0', 'start', range_0_start])
self.cli_set(pool + ['range', '0', 'stop', range_0_stop])

Expand All @@ -569,6 +570,11 @@ def test_dhcp_exclude_not_in_range(self):
self.verify_config_value(obj, ['Dhcp4', 'shared-networks'], 'name', 'EXCLUDE-TEST')
self.verify_config_value(obj, ['Dhcp4', 'shared-networks', 0, 'subnet4'], 'subnet', subnet)

pool_obj = {
'pool': f'{range_0_start} - {range_0_stop}',
'option-data': [{'name': 'routers', 'data': router}]
}

# Verify options
self.verify_config_object(
obj,
Expand All @@ -579,7 +585,7 @@ def test_dhcp_exclude_not_in_range(self):
self.verify_config_object(
obj,
['Dhcp4', 'shared-networks', 0, 'subnet4', 0, 'pools'],
{'pool': f'{range_0_start} - {range_0_stop}'})
pool_obj)

# Check for running process
self.assertTrue(process_named_running(PROCESS_NAME))
Expand All @@ -600,6 +606,7 @@ def test_dhcp_exclude_in_range(self):
self.cli_set(pool + ['subnet-id', '1'])
self.cli_set(pool + ['option', 'default-router', router])
self.cli_set(pool + ['exclude', exclude_addr])
self.cli_set(pool + ['range', '0', 'option', 'default-router', router])
self.cli_set(pool + ['range', '0', 'start', range_0_start])
self.cli_set(pool + ['range', '0', 'stop', range_0_stop])

Expand All @@ -612,6 +619,16 @@ def test_dhcp_exclude_in_range(self):
self.verify_config_value(obj, ['Dhcp4', 'shared-networks'], 'name', 'EXCLUDE-TEST-2')
self.verify_config_value(obj, ['Dhcp4', 'shared-networks', 0, 'subnet4'], 'subnet', subnet)

pool_obj = {
'pool': f'{range_0_start} - {range_0_stop_excl}',
'option-data': [{'name': 'routers', 'data': router}]
}

pool_exclude_obj = {
'pool': f'{range_0_start_excl} - {range_0_stop}',
'option-data': [{'name': 'routers', 'data': router}]
}

# Verify options
self.verify_config_object(
obj,
Expand All @@ -621,12 +638,12 @@ def test_dhcp_exclude_in_range(self):
self.verify_config_object(
obj,
['Dhcp4', 'shared-networks', 0, 'subnet4', 0, 'pools'],
{'pool': f'{range_0_start} - {range_0_stop_excl}'})
pool_obj)

self.verify_config_object(
obj,
['Dhcp4', 'shared-networks', 0, 'subnet4', 0, 'pools'],
{'pool': f'{range_0_start_excl} - {range_0_stop}'})
pool_exclude_obj)

# Check for running process
self.assertTrue(process_named_running(PROCESS_NAME))
Expand Down
8 changes: 8 additions & 0 deletions src/conf_mode/service_dhcp-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def dhcp_slice_range(exclude_list, range_dict):
'start' : range_start,
'stop' : str(ip_address(e) -1)
}

if 'option' in range_dict:
r['option'] = range_dict['option']

# On the next run our address range will start one address after
# the exclude address
range_start = str(ip_address(e) + 1)
Expand All @@ -104,6 +108,10 @@ def dhcp_slice_range(exclude_list, range_dict):
'start': str(ip_address(e) + 1),
'stop': str(range_stop)
}

if 'option' in range_dict:
r['option'] = range_dict['option']

if not (ip_address(r['start']) > ip_address(r['stop'])):
output.append(r)
else:
Expand Down

0 comments on commit 4e49794

Please sign in to comment.