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

FIX compare_object function for List type fields. #285

Merged
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
30 changes: 14 additions & 16 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def run(self, ib_obj_type, ib_spec):
# Removes keys from the proposed_object that are empty and do not exist in current_object.
# Fix the issue to update the optional fields of the object with default empty values
proposed_object = self.clean_empty_keys(current_object, proposed_object)
modified = not self.compare_objects(current_object, proposed_object)
modified = not self.compare_objects(current_object, proposed_object, ib_obj_type)
if 'extattrs' in proposed_object:
proposed_object['extattrs'] = normalize_extattrs(proposed_object['extattrs'])

Expand Down Expand Up @@ -710,7 +710,7 @@ def compare_extattrs(self, current_extattrs, proposed_extattrs):
def verify_list_order(self, proposed_data, current_data):
return len(proposed_data) == len(current_data) and all(a == b for a, b in zip(proposed_data, current_data))

def compare_objects(self, current_object, proposed_object):
def compare_objects(self, current_object, proposed_object, ib_obj_type=None):
for key, proposed_item in iteritems(proposed_object):
current_item = current_object.get(key)

Expand All @@ -727,21 +727,21 @@ def compare_objects(self, current_object, proposed_object):
# equal, and False will be returned before comparing the list items
# this code part will work for members' assignment

if (key in ('members', 'options', 'delegate_to', 'forwarding_servers', 'stub_members', 'ssh_keys', 'vlans')
and (len(proposed_item) != len(current_item))):
if key in ('members', 'options', 'delegate_to', 'forwarding_servers', 'stub_members', 'ssh_keys', 'vlans') \
and len(proposed_item) != len(current_item):
return False

# Validate the Sequence of the List data
if key in ('external_servers', 'list_values') and not self.verify_list_order(proposed_item, current_item):
return False

if key == 'ipv4addrs' and current_item and isinstance(current_item[0], dict) and proposed_item:
current_config = current_item[0]
dhcp_flag = current_config.get('configure_for_dhcp', False)
for subitem in proposed_item:
if not isinstance(subitem, dict):
continue # Skip non-dict items

for subitem in proposed_item:
if not isinstance(subitem, dict):
continue # Skip non-dict items
if ib_obj_type == NIOS_HOST_RECORD and key == 'ipv4addrs':
current_config = current_item[0]
dhcp_flag = current_config.get('configure_for_dhcp', False)
# Host IPv4addrs wont contain use_nextserver and nextserver
# If DHCP is false.
use_nextserver = subitem.get('use_nextserver', False)
Expand All @@ -758,11 +758,9 @@ def compare_objects(self, current_object, proposed_object):
except KeyError:
pass

if not self.issubset(subitem, current_item):
return False
if not self.issubset(subitem, current_item):
return False

# 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 key == 'logic_filter_rules' and proposed_item != current_item:
return False

Expand All @@ -778,7 +776,7 @@ def compare_objects(self, current_object, proposed_object):
if not self.compare_extattrs(current_extattrs, proposed_extattrs):
return False

if self.compare_objects(current_item, proposed_item) is False:
if self.compare_objects(current_item, proposed_item, ib_obj_type) is False:
return False
else:
continue
Expand Down Expand Up @@ -826,7 +824,7 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
test_obj_filter = dict([('name', old_name)])
else:
test_obj_filter = dict([('name', old_name), ('view', obj_filter['view'])])
# if there are multiple records with same name and different ip
# if there are multiple records with the same name and different ip
elif (ib_obj_type == NIOS_A_RECORD):
test_obj_filter = dict([('name', old_name), ('ipv4addr', obj_filter['ipv4addr'])])
try:
Expand Down
Loading