1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Peter Sprygada 2017-02-25 16:36:00 -05:00 committed by GitHub
parent f9b108e319
commit 14c05d9e2b
11 changed files with 17 additions and 17 deletions

View file

@ -50,7 +50,7 @@ nxos_argument_spec = {
'validate_certs': dict(type='bool'), 'validate_certs': dict(type='bool'),
'timeout': dict(type='int'), 'timeout': dict(type='int'),
'provider': dict(type='dict', no_log=True), 'provider': dict(type='dict'),
'transport': dict(choices=['cli', 'nxapi']) 'transport': dict(choices=['cli', 'nxapi'])
} }
@ -212,7 +212,7 @@ class Nxapi:
# only 10 show commands can be encoded in each request # only 10 show commands can be encoded in each request
# messages sent to the remote device # messages sent to the remote device
if output != 'config': if output != 'config':
commands = collections.deque(commands) commands = collections.deque(to_list(commands))
stack = list() stack = list()
requests = list() requests = list()
@ -230,7 +230,8 @@ class Nxapi:
requests.append(data) requests.append(data)
else: else:
requests = commands body = self._request_builder(commands, 'config')
requests = [self._module.jsonify(body)]
headers = {'Content-Type': 'application/json'} headers = {'Content-Type': 'application/json'}
result = list() result = list()
@ -241,7 +242,7 @@ class Nxapi:
headers['Cookie'] = self._nxapi_auth headers['Cookie'] = self._nxapi_auth
response, headers = fetch_url( response, headers = fetch_url(
self._module, self._url, data=data, headers=headers, self._module, self._url, data=req, headers=headers,
timeout=timeout, method='POST' timeout=timeout, method='POST'
) )
self._nxapi_auth = headers.get('set-cookie') self._nxapi_auth = headers.get('set-cookie')
@ -275,7 +276,7 @@ class Nxapi:
return self._device_configs[cmd] return self._device_configs[cmd]
except KeyError: except KeyError:
out = self.send_request(cmd) out = self.send_request(cmd)
cfg = str(out['result'][0]['output']).strip() cfg = str(out[0]).strip()
self._device_configs[cmd] = cfg self._device_configs[cmd] = cfg
return cfg return cfg
@ -309,8 +310,7 @@ class Nxapi:
def load_config(self, commands): def load_config(self, commands):
"""Sends the ordered set of commands to the device """Sends the ordered set of commands to the device
""" """
cmds = ['configure terminal'] commands = to_list(commands)
cmds.extend(commands)
self.send_request(commands, output='config') self.send_request(commands, output='config')

View file

@ -325,7 +325,7 @@ def main():
result = dict(changed=False, warnings=warnings) result = dict(changed=False, warnings=warnings)
if module.params['backup']: if module.params['backup']:
result['__backup__'] = module.config.get_config() result['__backup__'] = get_config(module)
if any((module.params['src'], module.params['lines'])): if any((module.params['src'], module.params['lines'])):
run(module, result) run(module, result)

View file

@ -34,7 +34,7 @@
- assert: - assert:
that: that:
- "result.changed == true" - "result.changed == true"
- "result.updates is not defined" - "result.updates is defined"
- name: collect any backup files - name: collect any backup files
find: find:

View file

@ -23,7 +23,7 @@
- assert: - assert:
that: that:
- "result.changed == true" - "result.changed == true"
- "result.updates is not defined" - "result.updates is defined"
- name: check device with defaults included - name: check device with defaults included
nxos_config: nxos_config:

View file

@ -22,7 +22,7 @@
that: that:
- "result.changed == true" - "result.changed == true"
# https://github.com/ansible/ansible-modules-core/issues/4807 # https://github.com/ansible/ansible-modules-core/issues/4807
- "result.updates is not defined" - "result.updates is defined"
- name: check device with config - name: check device with config
nxos_config: nxos_config:

View file

@ -23,7 +23,7 @@
that: that:
- "result.changed == true" - "result.changed == true"
# Defend https://github.com/ansible/ansible-modules-core/issues/4807 # Defend https://github.com/ansible/ansible-modules-core/issues/4807
- "result.updates is not defined" - "result.updates is defined"
- name: check device with config - name: check device with config
nxos_config: nxos_config:

View file

@ -34,7 +34,7 @@
- assert: - assert:
that: that:
- "result.changed == true" - "result.changed == true"
- "result.updates is not defined" - "result.updates is defined"
- name: collect any backup files - name: collect any backup files
find: find:

View file

@ -23,7 +23,7 @@
- assert: - assert:
that: that:
- "result.changed == true" - "result.changed == true"
- "result.updates is not defined" - "result.updates is defined"
- name: check device with defaults included - name: check device with defaults included
nxos_config: nxos_config:

View file

@ -4,6 +4,7 @@
- name: setup - name: setup
nxos_config: nxos_config:
lines: feature bgp lines: feature bgp
match: none
provider: "{{ nxapi }}" provider: "{{ nxapi }}"
- name: configure multi level command - name: configure multi level command

View file

@ -21,7 +21,7 @@
that: that:
- "result.changed == true" - "result.changed == true"
# https://github.com/ansible/ansible-modules-core/issues/4807 # https://github.com/ansible/ansible-modules-core/issues/4807
- "result.updates is not defined" - "result.updates is defined"
- name: check device with config - name: check device with config
nxos_config: nxos_config:

View file

@ -22,13 +22,12 @@
that: that:
- "result.changed == true" - "result.changed == true"
# https://github.com/ansible/ansible-modules-core/issues/4807 # https://github.com/ansible/ansible-modules-core/issues/4807
- "result.updates is not defined" - "result.updates is defined"
- name: check device with config - name: check device with config
nxos_config: nxos_config:
src: basic/config.j2 src: basic/config.j2
provider: "{{ nxapi }}" provider: "{{ nxapi }}"
match: none
register: result register: result
- assert: - assert: