From a202509ba48ec567286e307719580b83f5711c4e Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Thu, 14 Mar 2019 11:46:33 +0800 Subject: [PATCH] fixing resource facts (#53727) --- .../cloud/azure/azure_rm_resource_facts.py | 7 +++---- .../targets/azure_rm_keyvault/aliases | 1 - .../targets/azure_rm_resource/tasks/main.yml | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_resource_facts.py b/lib/ansible/modules/cloud/azure/azure_rm_resource_facts.py index 82ec43f9313..94251ce4618 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_resource_facts.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_resource_facts.py @@ -127,7 +127,7 @@ class AzureRMResourceFacts(AzureRMModuleBase): ) # store the results of the module operation self.results = dict( - response=None + response=[] ) self.mgmt_client = None self.url = None @@ -189,7 +189,6 @@ class AzureRMResourceFacts(AzureRMModuleBase): if skiptoken: query_parameters['skiptoken'] = skiptoken response = self.mgmt_client.query(self.url, "GET", query_parameters, header_parameters, None, [200, 404], 0, 0) - try: response = json.loads(response.text) if isinstance(response, dict): @@ -198,8 +197,8 @@ class AzureRMResourceFacts(AzureRMModuleBase): skiptoken = response.get('nextLink') else: self.results['response'] = self.results['response'] + [response] - except Exception: - self.results['response'] = [] + except Exception as e: + self.fail('Failed to parse response: ' + str(e)) if not skiptoken: break return self.results diff --git a/test/integration/targets/azure_rm_keyvault/aliases b/test/integration/targets/azure_rm_keyvault/aliases index 6c6c358e79e..4bae91b92f1 100644 --- a/test/integration/targets/azure_rm_keyvault/aliases +++ b/test/integration/targets/azure_rm_keyvault/aliases @@ -3,4 +3,3 @@ destructive shippable/azure/group2 azure_rm_keyvaultkey azure_rm_keyvaultsecret -disabled diff --git a/test/integration/targets/azure_rm_resource/tasks/main.yml b/test/integration/targets/azure_rm_resource/tasks/main.yml index 6eecfc10dec..7db8f51ee83 100644 --- a/test/integration/targets/azure_rm_resource/tasks/main.yml +++ b/test/integration/targets/azure_rm_resource/tasks/main.yml @@ -65,6 +65,27 @@ resource_name: "{{ nsgname }}" register: output +- name: Assert value was returned + assert: + that: + - not output.changed + - output.response[0]['name'] != None + - output.response | length == 1 + +- name: Try to query a list + azure_rm_resource_facts: + api_version: '2018-02-01' + resource_group: "{{ resource_group }}" + provider: network + resource_type: networksecuritygroups + register: output +- name: Assert value was returned + assert: + that: + - not output.changed + - output.response[0]['name'] != None + - output.response | length >= 1 + - name: Create storage account that requires LRO polling azure_rm_resource: polling_timeout: 600