From 335ee5908d407f2345548a05cad81ffaa1bc150e Mon Sep 17 00:00:00 2001 From: Isaac Beckman Date: Tue, 22 Jan 2019 13:05:01 +0200 Subject: [PATCH] IBM_Storage: fix host_add_ports (#49420) iscsi_name and fcaddress fields are not required by default. This commit make sure that no exception is thrown if only on field supplied --- lib/ansible/module_utils/ibm_sa_utils.py | 2 +- lib/ansible/modules/storage/ibm/ibm_sa_host_ports.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/ibm_sa_utils.py b/lib/ansible/module_utils/ibm_sa_utils.py index ad793252f98..7c9539c1bad 100644 --- a/lib/ansible/module_utils/ibm_sa_utils.py +++ b/lib/ansible/module_utils/ibm_sa_utils.py @@ -76,7 +76,7 @@ def build_pyxcli_command(fields): """ Builds the args for pyxcli using the exact args from ansible""" pyxcli_args = {} for field in fields: - if field in AVAILABLE_PYXCLI_FIELDS and fields[field]: + if field in AVAILABLE_PYXCLI_FIELDS and fields[field] != '': pyxcli_args[field] = fields[field] return pyxcli_args diff --git a/lib/ansible/modules/storage/ibm/ibm_sa_host_ports.py b/lib/ansible/modules/storage/ibm/ibm_sa_host_ports.py index ede30d43b57..7523e1e2b33 100644 --- a/lib/ansible/modules/storage/ibm/ibm_sa_host_ports.py +++ b/lib/ansible/modules/storage/ibm/ibm_sa_host_ports.py @@ -99,7 +99,7 @@ def main(): xcli_client = connect_ssl(module) # required args - ports = None + ports = [] try: ports = xcli_client.cmd.host_list_ports( host=module.params.get('host')).as_list @@ -109,9 +109,14 @@ def main(): port_exists = False ports = [port.get('port_name') for port in ports] + fc_ports = (module.params.get('fcaddress') + if module.params.get('fcaddress') else []) + iscsi_ports = (module.params.get('iscsi_name') + if module.params.get('iscsi_name') else []) for port in ports: - if port in module.params.get('iscsi_name', "") or port in module.params.get('fcaddress', ""): + if port in iscsi_ports or port in fc_ports: port_exists = True + break state_changed = False if state == 'present' and not port_exists: state_changed = execute_pyxcli_command(