From fa6e39ddf204532f420ba0993f0b0db61daac134 Mon Sep 17 00:00:00 2001 From: Chris Archibald Date: Tue, 18 Jun 2019 10:47:48 -0700 Subject: [PATCH] Backport/2.8/57320 (#58009) * new feature (cherry picked from commit dbeaf30f975190cc20fbece88b12d8dd062aad07) * add fragment --- ...-allow-you-to-add-port-when-creating-a-portset.yml | 2 ++ .../modules/storage/netapp/na_ontap_portset.py | 11 ++++++----- .../modules/storage/netapp/test_na_ontap_portset.py | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/57320-Portset-did-not-allow-you-to-add-port-when-creating-a-portset.yml diff --git a/changelogs/fragments/57320-Portset-did-not-allow-you-to-add-port-when-creating-a-portset.yml b/changelogs/fragments/57320-Portset-did-not-allow-you-to-add-port-when-creating-a-portset.yml new file mode 100644 index 0000000000..ea51dba75d --- /dev/null +++ b/changelogs/fragments/57320-Portset-did-not-allow-you-to-add-port-when-creating-a-portset.yml @@ -0,0 +1,2 @@ +bugfixes: + - na_ontap_portset - Fixed issue that portset did not allow you to add port when creating a portset \ No newline at end of file diff --git a/lib/ansible/modules/storage/netapp/na_ontap_portset.py b/lib/ansible/modules/storage/netapp/na_ontap_portset.py index 42b35cac27..2cb2d7b289 100644 --- a/lib/ansible/modules/storage/netapp/na_ontap_portset.py +++ b/lib/ansible/modules/storage/netapp/na_ontap_portset.py @@ -211,7 +211,7 @@ class NetAppONTAPPortset(object): :return: None """ for port in ports: - self.modify_port(port, 'portset-remove') + self.modify_port(port, 'portset-remove', 'removing') def add_ports(self): """ @@ -222,9 +222,9 @@ class NetAppONTAPPortset(object): if self.parameters.get('ports') == [''] or self.parameters.get('ports') is None: return for port in self.parameters['ports']: - self.modify_port(port, 'portset-add') + self.modify_port(port, 'portset-add', 'adding') - def modify_port(self, port, zapi): + def modify_port(self, port, zapi, action): """ Add or remove an port to/from a portset """ @@ -237,8 +237,8 @@ class NetAppONTAPPortset(object): try: self.server.invoke_successfully(portset_modify, enable_tunneling=True) except netapp_utils.zapi.NaApiError as error: - self.module.fail_json(msg='Error modifying port in portset %s: %s' % (self.parameters['name'], - to_native(error)), + self.module.fail_json(msg='Error %s port in portset %s: %s' % (action, self.parameters['name'], + to_native(error)), exception=traceback.format_exc()) def apply(self): @@ -257,6 +257,7 @@ class NetAppONTAPPortset(object): else: if cd_action == 'create': self.create_portset() + self.add_ports() elif cd_action == 'delete': self.delete_portset() elif modify: diff --git a/test/units/modules/storage/netapp/test_na_ontap_portset.py b/test/units/modules/storage/netapp/test_na_ontap_portset.py index 2a80fd3e48..7b5f356ddd 100644 --- a/test/units/modules/storage/netapp/test_na_ontap_portset.py +++ b/test/units/modules/storage/netapp/test_na_ontap_portset.py @@ -102,6 +102,7 @@ class TestMyModule(unittest.TestCase): name = 'test' type = 'mixed' vserver = 'ansible_test' + ports = ['a1', 'a2'] else: hostname = 'hostname' username = 'username' @@ -109,13 +110,15 @@ class TestMyModule(unittest.TestCase): name = 'name' type = 'mixed' vserver = 'vserver' + ports = ['a1', 'a2'] return dict({ 'hostname': hostname, 'username': username, 'password': password, 'name': name, 'type': type, - 'vserver': vserver + 'vserver': vserver, + 'ports': ports }) def test_module_fail_when_required_args_missing(self):