mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix nios modules (#48559)
* resolves 47839 * update name * update name Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com> * update name tests Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com> * update name tests Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com> * modifying the condn Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com>
This commit is contained in:
parent
8cd395f595
commit
feac12f9b7
5 changed files with 97 additions and 10 deletions
|
@ -216,15 +216,6 @@ class WapiModule(WapiBase):
|
|||
# get object reference
|
||||
ib_obj_ref, update, new_name = self.get_object_ref(self.module, ib_obj_type, obj_filter, ib_spec)
|
||||
|
||||
if ib_obj_ref:
|
||||
current_object = ib_obj_ref[0]
|
||||
if 'extattrs' in current_object:
|
||||
current_object['extattrs'] = flatten_extattrs(current_object['extattrs'])
|
||||
ref = current_object.pop('_ref')
|
||||
else:
|
||||
current_object = obj_filter
|
||||
ref = None
|
||||
|
||||
proposed_object = {}
|
||||
for key, value in iteritems(ib_spec):
|
||||
if self.module.params[key] is not None:
|
||||
|
@ -233,6 +224,20 @@ class WapiModule(WapiBase):
|
|||
else:
|
||||
proposed_object[key] = self.module.params[key]
|
||||
|
||||
if ib_obj_ref:
|
||||
if len(ib_obj_ref) > 1:
|
||||
for each in ib_obj_ref:
|
||||
if each['ipv4addr'] == proposed_object['ipv4addr']:
|
||||
current_object = each
|
||||
else:
|
||||
current_object = ib_obj_ref[0]
|
||||
if 'extattrs' in current_object:
|
||||
current_object['extattrs'] = flatten_extattrs(current_object['extattrs'])
|
||||
ref = current_object.pop('_ref')
|
||||
else:
|
||||
current_object = obj_filter
|
||||
ref = None
|
||||
|
||||
# checks if the name's field has been updated
|
||||
if update and new_name:
|
||||
proposed_object['name'] = new_name
|
||||
|
@ -252,6 +257,11 @@ class WapiModule(WapiBase):
|
|||
if (ib_obj_type in (NIOS_HOST_RECORD, NIOS_NETWORK_VIEW, NIOS_DNS_VIEW)):
|
||||
proposed_object = self.on_update(proposed_object, ib_spec)
|
||||
res = self.update_object(ref, proposed_object)
|
||||
if (ib_obj_type in (NIOS_A_RECORD, NIOS_AAAA_RECORD)):
|
||||
# popping 'view' key as update of 'view' is not supported with respect to a:record/aaaa:record
|
||||
proposed_object = self.on_update(proposed_object, ib_spec)
|
||||
del proposed_object['view']
|
||||
res = self.update_object(ref, proposed_object)
|
||||
elif 'network_view' in proposed_object:
|
||||
proposed_object.pop('network_view')
|
||||
if not self.module.check_mode and res is None:
|
||||
|
@ -339,6 +349,8 @@ class WapiModule(WapiBase):
|
|||
if old_name and new_name:
|
||||
if (ib_obj_type == NIOS_HOST_RECORD):
|
||||
test_obj_filter = dict([('name', old_name), ('view', obj_filter['view'])])
|
||||
elif (ib_obj_type in (NIOS_AAAA_RECORD, NIOS_A_RECORD)):
|
||||
test_obj_filter = obj_filter
|
||||
else:
|
||||
test_obj_filter = dict([('name', old_name)])
|
||||
# get the object reference
|
||||
|
@ -356,8 +368,9 @@ class WapiModule(WapiBase):
|
|||
test_obj_filter = dict([('name', name)])
|
||||
else:
|
||||
test_obj_filter = dict([('name', name), ('view', obj_filter['view'])])
|
||||
# check if test_obj_filter is empty copy passed obj_filter
|
||||
else:
|
||||
test_obj_filter = dict([('name', name)])
|
||||
test_obj_filter = obj_filter
|
||||
ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=ib_spec.keys())
|
||||
elif (ib_obj_type == NIOS_ZONE):
|
||||
# del key 'restart_if_needed' as nios_zone get_object fails with the key present
|
||||
|
|
|
@ -102,6 +102,17 @@ EXAMPLES = '''
|
|||
username: admin
|
||||
password: admin
|
||||
connection: local
|
||||
|
||||
- name: update an A record name
|
||||
nios_a_record:
|
||||
name: {new_name: a_new.ansible.com, old_name: a.ansible.com}
|
||||
ipv4: 192.168.10.1
|
||||
state: present
|
||||
provider:
|
||||
host: "{{ inventory_hostname_short }}"
|
||||
username: admin
|
||||
password: admin
|
||||
connection: local
|
||||
'''
|
||||
|
||||
RETURN = ''' # '''
|
||||
|
|
|
@ -102,6 +102,17 @@ EXAMPLES = '''
|
|||
username: admin
|
||||
password: admin
|
||||
connection: local
|
||||
|
||||
- name: update an AAAA record name
|
||||
nios_aaaa_record:
|
||||
name: {new_name: aaaa_new.ansible.com, old_name: aaaa.ansible.com}
|
||||
ipv6: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
|
||||
state: present
|
||||
provider:
|
||||
host: "{{ inventory_hostname_short }}"
|
||||
username: admin
|
||||
password: admin
|
||||
connection: local
|
||||
'''
|
||||
|
||||
RETURN = ''' # '''
|
||||
|
|
|
@ -131,3 +131,29 @@ class TestNiosARecordModule(TestNiosModule):
|
|||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.delete_object.assert_called_once_with(ref)
|
||||
|
||||
def test_nios_a_record_update_record_name(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'a_new.ansible.com', 'old_name': 'a.ansible.com'},
|
||||
'comment': 'comment', 'extattrs': None}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"name": "a_new.ansible.com",
|
||||
"old_name": "a.ansible.com",
|
||||
"extattrs": {}
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.update_object.called_once_with(test_object)
|
||||
|
|
|
@ -131,3 +131,29 @@ class TestNiosAAAARecordModule(TestNiosModule):
|
|||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.delete_object.assert_called_once_with(ref)
|
||||
|
||||
def test_nios_aaaa_record_update_record_name(self):
|
||||
self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'aaaa_new.ansible.com', 'old_name': 'aaaa.ansible.com'},
|
||||
'comment': 'comment', 'extattrs': None}
|
||||
|
||||
test_object = [
|
||||
{
|
||||
"comment": "test comment",
|
||||
"_ref": "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
|
||||
"name": "aaaa_new.ansible.com",
|
||||
"old_name": "aaaa.ansible.com",
|
||||
"extattrs": {}
|
||||
}
|
||||
]
|
||||
|
||||
test_spec = {
|
||||
"name": {"ib_req": True},
|
||||
"comment": {},
|
||||
"extattrs": {}
|
||||
}
|
||||
|
||||
wapi = self._get_wapi(test_object)
|
||||
res = wapi.run('testobject', test_spec)
|
||||
|
||||
self.assertTrue(res['changed'])
|
||||
wapi.update_object.called_once_with(test_object)
|
||||
|
|
Loading…
Reference in a new issue