1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
This commit is contained in:
Chris Archibald 2019-03-27 07:14:17 -07:00 committed by John R Barker
parent 0943e2a0df
commit 194af05832
2 changed files with 15 additions and 12 deletions

View file

@ -213,28 +213,30 @@ class NetAppOntapServiceProcessorNetwork(object):
def modify_service_processor_network(self, params=None): def modify_service_processor_network(self, params=None):
""" """
Modify a service processor network Modify a service processor network.
:param params: A dict of modified options.
When dhcp is not set to v4, ip_address, netmask, and gateway_ip_address must be specified even if remains the same.
""" """
if params.get('is_enabled') is None: # is-enabled is mandatory for ZAPI service-processor-network-modify if self.parameters['is_enabled'] is False:
params['is_enabled'] = self.parameters['is_enabled'] if params.get('is_enabled') and len(params) > 1:
if params['is_enabled'] is False: self.module.fail_json(msg='Error: Cannot modify any other parameter for a service processor network if option "is_enabled" is set to false.')
if len(params) > 1: elif params.get('is_enabled') is None and len(params) > 0:
self.module.fail_json(msg='Error: Cannot modify any other parameter for a disabled service processor network') self.module.fail_json(msg='Error: Cannot modify a service processor network if it is disabled.')
sp_modify = netapp_utils.zapi.NaElement('service-processor-network-modify') sp_modify = netapp_utils.zapi.NaElement('service-processor-network-modify')
sp_modify.add_new_child("node", self.parameters['node']) sp_modify.add_new_child("node", self.parameters['node'])
sp_modify.add_new_child("address-type", self.parameters['address_type']) sp_modify.add_new_child("address-type", self.parameters['address_type'])
sp_attributes = dict() sp_attributes = dict()
for item_key in params: for item_key in self.parameters:
if item_key in self.na_helper.zapi_string_keys: if item_key in self.na_helper.zapi_string_keys:
zapi_key = self.na_helper.zapi_string_keys.get(item_key) zapi_key = self.na_helper.zapi_string_keys.get(item_key)
sp_attributes[zapi_key] = params[item_key] sp_attributes[zapi_key] = self.parameters[item_key]
elif item_key in self.na_helper.zapi_bool_keys: elif item_key in self.na_helper.zapi_bool_keys:
zapi_key = self.na_helper.zapi_bool_keys.get(item_key) zapi_key = self.na_helper.zapi_bool_keys.get(item_key)
sp_attributes[zapi_key] = self.na_helper.get_value_for_bool(from_zapi=False, value=params[item_key]) sp_attributes[zapi_key] = self.na_helper.get_value_for_bool(from_zapi=False, value=self.parameters[item_key])
elif item_key in self.na_helper.zapi_bool_keys: elif item_key in self.na_helper.zapi_int_keys:
zapi_key = self.na_helper.zapi_int_keys.get(item_key) zapi_key = self.na_helper.zapi_int_keys.get(item_key)
sp_attributes[zapi_key] = self.na_helper.get_value_for_int(from_zapi=False, value=params[item_key]) sp_attributes[zapi_key] = self.na_helper.get_value_for_int(from_zapi=False, value=self.parameters[item_key])
sp_modify.translate_struct(sp_attributes) sp_modify.translate_struct(sp_attributes)
try: try:
self.server.invoke_successfully(sp_modify, enable_tunneling=True) self.server.invoke_successfully(sp_modify, enable_tunneling=True)

View file

@ -183,10 +183,11 @@ class TestMyModule(unittest.TestCase):
def test_modify_error_on_disabled_sp(self): def test_modify_error_on_disabled_sp(self):
''' a more interesting test ''' ''' a more interesting test '''
data = self.mock_args(enable=False) data = self.mock_args(enable=False)
data['ip_address'] = self.mock_sp['ip_address']
set_module_args(data) set_module_args(data)
with pytest.raises(AnsibleFailJson) as exc: with pytest.raises(AnsibleFailJson) as exc:
self.get_sp_mock_object('sp-disabled').apply() self.get_sp_mock_object('sp-disabled').apply()
assert 'Error: Cannot modify any other parameter for a disabled service processor network' in \ assert 'Error: Cannot modify a service processor network if it is disabled.' in \
exc.value.args[0]['msg'] exc.value.args[0]['msg']
def test_modify_sp(self): def test_modify_sp(self):