This commit is contained in:
Chris Archibald 2019-08-14 07:26:12 -07:00 committed by Jake Jackson
parent 4cae96109b
commit fed6598e28
2 changed files with 17 additions and 2 deletions

View file

@ -119,7 +119,8 @@ class NetAppOntapIgroupInitiator(object):
:rtype: list() or None
"""
igroup_info = netapp_utils.zapi.NaElement('igroup-get-iter')
attributes = dict(query={'initiator-group-info': {'initiator-group-name': self.parameters['initiator_group']}})
attributes = dict(query={'initiator-group-info': {'initiator-group-name': self.parameters['initiator_group'],
'vserver': self.parameters['vserver']}})
igroup_info.translate_struct(attributes)
result, current = None, []
@ -156,8 +157,9 @@ class NetAppOntapIgroupInitiator(object):
def apply(self):
self.autosupport_log()
initiators, present = self.get_initiators(), None
initiators = self.get_initiators()
for initiator in self.parameters['names']:
present = None
if initiator in initiators:
present = True
cd_action = self.na_helper.get_cd_action(present, self.parameters)

View file

@ -64,6 +64,8 @@ class MockONTAPConnection(object):
self.xml_in = xml
if self.kind == 'initiator':
xml = self.build_igroup_initiator()
elif self.kind == 'initiator_fail':
raise netapp_utils.zapi.NaApiError(code='TEST', message="This exception is from the unit test")
self.xml_out = xml
return xml
@ -202,3 +204,14 @@ class TestMyModule(unittest.TestCase):
obj.apply()
assert data['name'] not in current_list
assert not exc.value.args[0]['changed']
def test_if_all_methods_catch_exception(self):
data = self.mock_args()
set_module_args(data)
my_obj = self.get_initiator_mock_object('initiator_fail')
with pytest.raises(AnsibleFailJson) as exc:
my_obj.get_initiators()
assert 'Error fetching igroup info ' in exc.value.args[0]['msg']
with pytest.raises(AnsibleFailJson) as exc:
my_obj.modify_initiator(data['name'], 'igroup-add')
assert 'Error modifying igroup initiator ' in exc.value.args[0]['msg']