From e8cddfd452f9db4df6611ae65af54229eb2b2def Mon Sep 17 00:00:00 2001 From: David Soper Date: Tue, 26 Mar 2019 08:57:46 -0500 Subject: [PATCH] Fix bug in data returns for some queries used by facts module (#52832) * Fix bug in data returns for some queries used by facts module * Add additional query to return all servers (up to 5000) * Fix key checking in rest_api --- lib/ansible/module_utils/remote_management/intersight.py | 5 +++-- .../remote_management/intersight/intersight_facts.py | 1 + .../remote_management/intersight/intersight_rest_api.py | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/remote_management/intersight.py b/lib/ansible/module_utils/remote_management/intersight.py index 25329726d22..fa50f815a43 100644 --- a/lib/ansible/module_utils/remote_management/intersight.py +++ b/lib/ansible/module_utils/remote_management/intersight.py @@ -190,8 +190,9 @@ class IntersightModule(): except Exception as e: self.module.fail_json(msg="API error: %s " % str(e)) - if response.length > 0: - return json.loads(response.read()) + response_data = response.read() + if len(response_data) > 0: + return json.loads(response_data) return {} def intersight_call(self, http_method="", resource_path="", query_params=None, body=None, moid=None, name=None): diff --git a/lib/ansible/modules/remote_management/intersight/intersight_facts.py b/lib/ansible/modules/remote_management/intersight/intersight_facts.py index 442008308d5..3704c858755 100644 --- a/lib/ansible/modules/remote_management/intersight/intersight_facts.py +++ b/lib/ansible/modules/remote_management/intersight/intersight_facts.py @@ -85,6 +85,7 @@ def get_servers(module, intersight): 'resource_path': '/compute/PhysicalSummaries', 'query_params': { '$filter': query_str, + '$top': 5000 } } response_dict = intersight.call_api(**options) diff --git a/lib/ansible/modules/remote_management/intersight/intersight_rest_api.py b/lib/ansible/modules/remote_management/intersight/intersight_rest_api.py index eb4e211d5ed..f02817c871a 100644 --- a/lib/ansible/modules/remote_management/intersight/intersight_rest_api.py +++ b/lib/ansible/modules/remote_management/intersight/intersight_rest_api.py @@ -150,7 +150,7 @@ def get_resource(intersight): def compare_values(expected, actual): try: for (key, value) in iteritems(expected): - if re.search(r'P(ass)?w(or)?d', key) or not actual.get(key): + if re.search(r'P(ass)?w(or)?d', key) or key not in actual: # do not compare any password related attributes or attributes that are not in the actual resource continue if not compare_values(value, actual[key]): @@ -184,8 +184,10 @@ def configure_resource(intersight, moid): 'resource_path': intersight.module.params['resource_path'], 'body': intersight.module.params['api_body'], } - intersight.call_api(**options) - intersight.result['api_response'] = get_resource(intersight) + resp = intersight.call_api(**options) + if 'Moid' not in resp: + resp = get_resource(intersight) + intersight.result['api_response'] = resp intersight.result['changed'] = True