Skip to content

Commit

Permalink
[FIX] BUG fixed for NsGroup NPA-147,148,149,150,151 and 152 (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
JkhatriInfobox authored Sep 13, 2024
1 parent fb245f5 commit 3c9ea1a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 21 additions & 11 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def run(self, ib_obj_type, ib_spec):
proposed_object[key] = self.module.params[key]

# If configure_by_dns is set to False and view is 'default', then delete the default dns
if not proposed_object.get('configure_for_dns') and proposed_object.get('view') == 'default'\
if not proposed_object.get('configure_for_dns') and proposed_object.get('view') == 'default' \
and ib_obj_type == NIOS_HOST_RECORD:
del proposed_object['view']

Expand All @@ -360,7 +360,7 @@ def run(self, ib_obj_type, ib_spec):
current_object = each
break
# To check for existing Host_record with same name with input Host_record by IP
elif each.get('ipv4addrs') and each.get('ipv4addrs')[0].get('ipv4addr')\
elif each.get('ipv4addrs') and each.get('ipv4addrs')[0].get('ipv4addr') \
== proposed_object.get('ipv4addrs')[0].get('ipv4addr'):
current_object = each
# Else set the current_object with input value
Expand Down Expand Up @@ -647,11 +647,14 @@ def compare_extattrs(self, current_extattrs, proposed_extattrs):
return False
return True

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):
for key, proposed_item in iteritems(proposed_object):
current_item = current_object.get(key)

# if proposed has a key that current doesn't then the objects are
# if proposed has a key that current doesn't, then the objects are
# not equal and False will be immediately returned
if current_item is None:
return False
Expand All @@ -660,25 +663,30 @@ def compare_objects(self, current_object, proposed_object):
if key == 'aliases':
if set(current_item) != set(proposed_item):
return False
# 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 in ['members', 'options'] and (len(proposed_item) != len(current_item)):
# If the lists are of a different length, the objects cannot be
# 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')
and (len(proposed_item) != len(current_item))):
return False

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

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

# If the lists are of a different length the objects and order of element mismatch
# 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

elif isinstance(proposed_item, dict):
# Compare the items of the dict to see if they are equal. A
# difference stops the comparison and returns false. If they
# are equal move on to the next item
# are equal, move on to the next item

# Checks if extattrs existing in proposed object
if key == 'extattrs':
Expand Down Expand Up @@ -746,7 +754,8 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
if ib_obj:
obj_filter['name'] = new_name
elif old_ipv4addr_exists and (len(ib_obj) == 0):
raise Exception("object with name: '%s', ipv4addr: '%s' is not found" % (old_name, test_obj_filter['ipv4addr']))
raise Exception(
"object with name: '%s', ipv4addr: '%s' is not found" % (old_name, test_obj_filter['ipv4addr']))
else:
raise Exception("object with name: '%s' is not found" % (old_name))
update = True
Expand Down Expand Up @@ -931,7 +940,8 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
# throws exception if start_addr and end_addr doesn't exists for updating range
if (new_start_arg and new_end_arg):
if not ib_obj:
raise Exception('Specified range %s-%s not found' % (obj_filter['start_addr'], obj_filter['end_addr']))
raise Exception(
'Specified range %s-%s not found' % (obj_filter['start_addr'], obj_filter['end_addr']))
else:
ib_obj = self.get_object(ib_obj_type, obj_filter.copy(), return_fields=list(ib_spec.keys()))
return ib_obj, update, new_name
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/nios_nsgroup_forwardstubserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
infoblox.nios_modules.nios_nsgroup_forwardstubserver:
name: my-forwardstub-group
comment: "this is a forward/stub nameserver group"
nameservers:
external_servers:
- name: first
address: 192.168.0.10
- name: second
Expand Down

0 comments on commit 3c9ea1a

Please sign in to comment.