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

[NPA-125] unable to configure dhcp options with combination of 'num' and 'name' field. #250

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
26 changes: 4 additions & 22 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,32 +388,14 @@ def run(self, ib_obj_type, ib_spec):

# Iterate over each option and remove the 'num' key
if current_object.get('options') or proposed_object.get('options'):
num_present, name_present = False, False
if proposed_object.get('options'):
# get options from proposed_object and check if it should not have mix of 'name' and 'num'
for option in proposed_object['options']:
if 'num' in option:
num_present = True
elif 'name' in option:
name_present = True
if num_present and name_present:
raise Exception("options should not have mix of 'name' and 'num'")

proposed_object['options'] = sorted(proposed_object['options'], key=lambda x: x['value'])
# remove use_options false from proposed_object
proposed_object['options'] = [option for option in proposed_object['options'] if option.get('use_option', True)]

if current_object.get('options'):
for option in current_object['options']:
if num_present:
option.pop('name', None)
else:
option.pop('num', None)

# remove use_options false from current_object
current_object['options'] = [option for option in current_object['options'] if option.get('use_option', True)]

# Assuming 'current_object' is the dictionary containing the 'options' list
current_object['options'] = sorted(current_object['options'], key=lambda x: x['value'])

if (ib_obj_type == NIOS_RANGE):
if proposed_object.get('new_start_addr'):
proposed_object['start_addr'] = proposed_object.get('new_start_addr')
Expand Down Expand Up @@ -677,7 +659,7 @@ def compare_objects(self, current_object, proposed_object):
# If the lists are of a different length the objects can not be
# equal and False will be returned before comparing the lists items
# this code part will work for members assignment
if key == 'members' and (len(proposed_item) != len(current_item)):
if key in ['members', 'options'] and (len(proposed_item) != len(current_item)):
return False

for subitem in proposed_item:
Expand All @@ -686,7 +668,7 @@ def compare_objects(self, current_object, proposed_object):

# If the lists are of a different length the objects and order of element mismatch
# Ignore DHCP options while comparing due to extra num param is get response
if proposed_item != current_item:
if key == 'logic_filter_rules' and proposed_item != current_item:
return False

elif isinstance(proposed_item, dict):
Expand Down
Loading