Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dhcp: T6692: Fix range options not present when exclude is used #4203

Open
wants to merge 1 commit into
base: current
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading