From 94a1d86d70f02c1c7fa55426a428e656566c1359 Mon Sep 17 00:00:00 2001 From: Dhanuka <42544330+dnuka@users.noreply.github.com> Date: Fri, 11 Jan 2019 19:46:20 +0530 Subject: [PATCH] redfish_utils: fix reference to local variable 'systems_service' (#50298) * fixes issue 50296 * fixes the indentation of the return statement * Adds a conditional test into `_find_systems_resource()` to check the existence of the Members of System resource * updates the error message * harden the conditional test * Add a changelog --- ..._reference_to_local_variable_systems_service.yaml | 3 +++ lib/ansible/module_utils/redfish_utils.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/50298-redfish_utils_fix_reference_to_local_variable_systems_service.yaml diff --git a/changelogs/fragments/50298-redfish_utils_fix_reference_to_local_variable_systems_service.yaml b/changelogs/fragments/50298-redfish_utils_fix_reference_to_local_variable_systems_service.yaml new file mode 100644 index 00000000000..4ce58f7c00f --- /dev/null +++ b/changelogs/fragments/50298-redfish_utils_fix_reference_to_local_variable_systems_service.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- redfish_utils - fix reference to local variable 'systems_service' diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index a3a3d389320..b3816755606 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -133,10 +133,14 @@ class RedfishUtils(object): if response['ret'] is False: return response data = response['data'] - for member in data[u'Members']: - systems_service = member[u'@odata.id'] - self.systems_uri = systems_service - return {'ret': True} + if data.get(u'Members'): + for member in data[u'Members']: + systems_service = member[u'@odata.id'] + self.systems_uri = systems_service + return {'ret': True} + else: + return {'ret': False, + 'msg': "ComputerSystem's Members array is either empty or missing"} def _find_updateservice_resource(self, uri): response = self.get_request(self.root_uri + uri)