From 14c05d9e2b4069fe6d57402189d9e80dea2cf149 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sat, 25 Feb 2017 16:36:00 -0500 Subject: [PATCH] roll up of fixes for nxos_config (#21949) * fixes provider to not log entries * fixes nxapi send_request with config statements * fixes nxapi get_config() * updates nxos_config integration tests --- lib/ansible/module_utils/nxos.py | 14 +++++++------- lib/ansible/modules/network/nxos/nxos_config.py | 2 +- .../targets/nxos_config/tests/cli/backup.yaml | 2 +- .../targets/nxos_config/tests/cli/defaults.yaml | 2 +- .../targets/nxos_config/tests/cli/src_basic.yaml | 2 +- .../nxos_config/tests/cli/src_match_none.yaml | 2 +- .../targets/nxos_config/tests/nxapi/backup.yaml | 2 +- .../targets/nxos_config/tests/nxapi/defaults.yaml | 2 +- .../nxos_config/tests/nxapi/multilevel.yaml | 1 + .../targets/nxos_config/tests/nxapi/src_basic.yaml | 2 +- .../nxos_config/tests/nxapi/src_match_none.yaml | 3 +-- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index 6fd3a2960c..9f9f4418a4 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -50,7 +50,7 @@ nxos_argument_spec = { 'validate_certs': dict(type='bool'), 'timeout': dict(type='int'), - 'provider': dict(type='dict', no_log=True), + 'provider': dict(type='dict'), 'transport': dict(choices=['cli', 'nxapi']) } @@ -212,7 +212,7 @@ class Nxapi: # only 10 show commands can be encoded in each request # messages sent to the remote device if output != 'config': - commands = collections.deque(commands) + commands = collections.deque(to_list(commands)) stack = list() requests = list() @@ -230,7 +230,8 @@ class Nxapi: requests.append(data) else: - requests = commands + body = self._request_builder(commands, 'config') + requests = [self._module.jsonify(body)] headers = {'Content-Type': 'application/json'} result = list() @@ -241,7 +242,7 @@ class Nxapi: headers['Cookie'] = self._nxapi_auth response, headers = fetch_url( - self._module, self._url, data=data, headers=headers, + self._module, self._url, data=req, headers=headers, timeout=timeout, method='POST' ) self._nxapi_auth = headers.get('set-cookie') @@ -275,7 +276,7 @@ class Nxapi: return self._device_configs[cmd] except KeyError: out = self.send_request(cmd) - cfg = str(out['result'][0]['output']).strip() + cfg = str(out[0]).strip() self._device_configs[cmd] = cfg return cfg @@ -309,8 +310,7 @@ class Nxapi: def load_config(self, commands): """Sends the ordered set of commands to the device """ - cmds = ['configure terminal'] - cmds.extend(commands) + commands = to_list(commands) self.send_request(commands, output='config') diff --git a/lib/ansible/modules/network/nxos/nxos_config.py b/lib/ansible/modules/network/nxos/nxos_config.py index 34ad8d6696..5087f90f42 100644 --- a/lib/ansible/modules/network/nxos/nxos_config.py +++ b/lib/ansible/modules/network/nxos/nxos_config.py @@ -325,7 +325,7 @@ def main(): result = dict(changed=False, warnings=warnings) if module.params['backup']: - result['__backup__'] = module.config.get_config() + result['__backup__'] = get_config(module) if any((module.params['src'], module.params['lines'])): run(module, result) diff --git a/test/integration/targets/nxos_config/tests/cli/backup.yaml b/test/integration/targets/nxos_config/tests/cli/backup.yaml index 7670923fb4..7133852a1f 100644 --- a/test/integration/targets/nxos_config/tests/cli/backup.yaml +++ b/test/integration/targets/nxos_config/tests/cli/backup.yaml @@ -34,7 +34,7 @@ - assert: that: - "result.changed == true" - - "result.updates is not defined" + - "result.updates is defined" - name: collect any backup files find: diff --git a/test/integration/targets/nxos_config/tests/cli/defaults.yaml b/test/integration/targets/nxos_config/tests/cli/defaults.yaml index 59f2c5f76d..1a9575b352 100644 --- a/test/integration/targets/nxos_config/tests/cli/defaults.yaml +++ b/test/integration/targets/nxos_config/tests/cli/defaults.yaml @@ -23,7 +23,7 @@ - assert: that: - "result.changed == true" - - "result.updates is not defined" + - "result.updates is defined" - name: check device with defaults included nxos_config: diff --git a/test/integration/targets/nxos_config/tests/cli/src_basic.yaml b/test/integration/targets/nxos_config/tests/cli/src_basic.yaml index 8ae2288df8..7d2c8717c1 100644 --- a/test/integration/targets/nxos_config/tests/cli/src_basic.yaml +++ b/test/integration/targets/nxos_config/tests/cli/src_basic.yaml @@ -22,7 +22,7 @@ that: - "result.changed == true" # https://github.com/ansible/ansible-modules-core/issues/4807 - - "result.updates is not defined" + - "result.updates is defined" - name: check device with config nxos_config: diff --git a/test/integration/targets/nxos_config/tests/cli/src_match_none.yaml b/test/integration/targets/nxos_config/tests/cli/src_match_none.yaml index 0e7c19cbf8..121517a42b 100644 --- a/test/integration/targets/nxos_config/tests/cli/src_match_none.yaml +++ b/test/integration/targets/nxos_config/tests/cli/src_match_none.yaml @@ -23,7 +23,7 @@ that: - "result.changed == true" # Defend https://github.com/ansible/ansible-modules-core/issues/4807 - - "result.updates is not defined" + - "result.updates is defined" - name: check device with config nxos_config: diff --git a/test/integration/targets/nxos_config/tests/nxapi/backup.yaml b/test/integration/targets/nxos_config/tests/nxapi/backup.yaml index a33ab38413..bc7a511da8 100644 --- a/test/integration/targets/nxos_config/tests/nxapi/backup.yaml +++ b/test/integration/targets/nxos_config/tests/nxapi/backup.yaml @@ -34,7 +34,7 @@ - assert: that: - "result.changed == true" - - "result.updates is not defined" + - "result.updates is defined" - name: collect any backup files find: diff --git a/test/integration/targets/nxos_config/tests/nxapi/defaults.yaml b/test/integration/targets/nxos_config/tests/nxapi/defaults.yaml index 39c53846b3..cc867d398a 100644 --- a/test/integration/targets/nxos_config/tests/nxapi/defaults.yaml +++ b/test/integration/targets/nxos_config/tests/nxapi/defaults.yaml @@ -23,7 +23,7 @@ - assert: that: - "result.changed == true" - - "result.updates is not defined" + - "result.updates is defined" - name: check device with defaults included nxos_config: diff --git a/test/integration/targets/nxos_config/tests/nxapi/multilevel.yaml b/test/integration/targets/nxos_config/tests/nxapi/multilevel.yaml index f1524fa76a..12ff417a8a 100644 --- a/test/integration/targets/nxos_config/tests/nxapi/multilevel.yaml +++ b/test/integration/targets/nxos_config/tests/nxapi/multilevel.yaml @@ -4,6 +4,7 @@ - name: setup nxos_config: lines: feature bgp + match: none provider: "{{ nxapi }}" - name: configure multi level command diff --git a/test/integration/targets/nxos_config/tests/nxapi/src_basic.yaml b/test/integration/targets/nxos_config/tests/nxapi/src_basic.yaml index d76e01107f..7ca8007557 100644 --- a/test/integration/targets/nxos_config/tests/nxapi/src_basic.yaml +++ b/test/integration/targets/nxos_config/tests/nxapi/src_basic.yaml @@ -21,7 +21,7 @@ that: - "result.changed == true" # https://github.com/ansible/ansible-modules-core/issues/4807 - - "result.updates is not defined" + - "result.updates is defined" - name: check device with config nxos_config: diff --git a/test/integration/targets/nxos_config/tests/nxapi/src_match_none.yaml b/test/integration/targets/nxos_config/tests/nxapi/src_match_none.yaml index a0855ff270..f0ab6f3158 100644 --- a/test/integration/targets/nxos_config/tests/nxapi/src_match_none.yaml +++ b/test/integration/targets/nxos_config/tests/nxapi/src_match_none.yaml @@ -22,13 +22,12 @@ that: - "result.changed == true" # https://github.com/ansible/ansible-modules-core/issues/4807 - - "result.updates is not defined" + - "result.updates is defined" - name: check device with config nxos_config: src: basic/config.j2 provider: "{{ nxapi }}" - match: none register: result - assert: