From a284c3f7eaf0b6419a960d4913c88dc377db676a Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sat, 25 Feb 2017 17:48:09 -0500 Subject: [PATCH] roll up of fixes for nxos_facts (#21954) * fixes commands to work with nxapi * updates test case timeouts --- lib/ansible/module_utils/nxos.py | 17 +++++++------- .../modules/network/nxos/nxos_facts.py | 22 +++++++++---------- .../nxos_facts/tests/nxapi/all_facts.yaml | 1 + .../nxos_facts/tests/nxapi/not_hardware.yaml | 1 + 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index 9f9f4418a45..7f2b8c36f7f 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -208,7 +208,7 @@ class Nxapi: return dict(ins_api=msg) - def send_request(self, commands, output='text'): + def send_request(self, commands, output='text', check_status=True): # only 10 show commands can be encoded in each request # messages sent to the remote device if output != 'config': @@ -255,12 +255,13 @@ class Nxapi: except ValueError: self._module.fail_json(msg='unable to parse response') - output = response['ins_api']['outputs']['output'] - for item in to_list(output): - if item['code'] != '200': - self._error(output=output, **item) - else: - result.append(item['body']) + if check_status: + output = response['ins_api']['outputs']['output'] + for item in to_list(output): + if item['code'] != '200': + self._error(output=output, **item) + else: + result.append(item['body']) return result @@ -288,7 +289,7 @@ class Nxapi: queue = list() responses = list() - _send = lambda commands, output: self.send_request(commands, output) + _send = lambda commands, output: self.send_request(commands, output, check_status=check_rc) for item in to_list(commands): if is_json(item['command']): diff --git a/lib/ansible/modules/network/nxos/nxos_facts.py b/lib/ansible/modules/network/nxos/nxos_facts.py index fa00162733e..d20c6c1f1db 100644 --- a/lib/ansible/modules/network/nxos/nxos_facts.py +++ b/lib/ansible/modules/network/nxos/nxos_facts.py @@ -16,9 +16,11 @@ # along with Ansible. If not, see . # -ANSIBLE_METADATA = {'status': ['preview'], - 'supported_by': 'community', - 'version': '1.0'} +ANSIBLE_METADATA = { + 'status': ['preview'], + 'supported_by': 'community', + 'version': '1.0' +} DOCUMENTATION = """ --- @@ -181,7 +183,6 @@ import re from ansible.module_utils.nxos import run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.connection import exec_command from ansible.module_utils.six import iteritems @@ -239,7 +240,7 @@ class Config(FactsBase): class Hardware(FactsBase): COMMANDS = [ - 'dir', + {'command': 'dir', 'output': 'text'}, 'show system resources | json' ] @@ -287,13 +288,12 @@ class Interfaces(FactsBase): data = run_commands(self.module, ['show interface | json'])[0] self.facts['interfaces'] = self.populate_interfaces(data) - rc, out, err = exec_command(self.module, 'show ipv6 interface | json') - if rc == 0: - if out: - self.parse_ipv6_interfaces(out) + out = run_commands(self.module, ['show ipv6 interface | json']) + if out[0]: + self.parse_ipv6_interfaces(out) - rc, out, err = exec_command(self.module, 'show lldp neighbors') - if rc == 0: + out = run_commands(self.module, ['show lldp neighbors'], check_rc=False) + if out and out[0]: self.facts['neighbors'] = self.populate_neighbors(out) def populate_interfaces(self, data): diff --git a/test/integration/targets/nxos_facts/tests/nxapi/all_facts.yaml b/test/integration/targets/nxos_facts/tests/nxapi/all_facts.yaml index 45a8eba10e7..cde952b8fe6 100644 --- a/test/integration/targets/nxos_facts/tests/nxapi/all_facts.yaml +++ b/test/integration/targets/nxos_facts/tests/nxapi/all_facts.yaml @@ -7,6 +7,7 @@ provider: "{{ nxapi }}" gather_subset: - all + timeout: 60 register: result diff --git a/test/integration/targets/nxos_facts/tests/nxapi/not_hardware.yaml b/test/integration/targets/nxos_facts/tests/nxapi/not_hardware.yaml index 0daf6bc25a8..1123e108525 100644 --- a/test/integration/targets/nxos_facts/tests/nxapi/not_hardware.yaml +++ b/test/integration/targets/nxos_facts/tests/nxapi/not_hardware.yaml @@ -7,6 +7,7 @@ provider: "{{ nxapi }}" gather_subset: - "!hardware" + timeout: 30 register: result - assert: