* Working Cisco IOS macro editing (fixes #55211) * Working Cisco IOS macro editing [fixed pylints] (fixes #55211) * Added integration tests for edit_macro * Added conditional integration tests for ios_config macro * Cosmetic fix: when near block for added conditional integration tests for ios_config macro * Move teardown to always for block
This commit is contained in:
parent
81aabdc94f
commit
4a0c875447
3 changed files with 94 additions and 7 deletions
|
@ -161,22 +161,35 @@ class Cliconf(CliconfBase):
|
|||
return resp
|
||||
|
||||
def edit_macro(self, candidate=None, commit=True, replace=None, comment=None):
|
||||
"""
|
||||
ios_config:
|
||||
lines: "{{ macro_lines }}"
|
||||
parents: "macro name {{ macro_name }}"
|
||||
after: '@'
|
||||
match: line
|
||||
replace: block
|
||||
"""
|
||||
resp = {}
|
||||
operations = self.get_device_operations()
|
||||
self.check_edit_config_capabiltiy(operations, candidate, commit, replace, comment)
|
||||
self.check_edit_config_capability(operations, candidate, commit, replace, comment)
|
||||
|
||||
results = []
|
||||
requests = []
|
||||
if commit:
|
||||
commands = ''
|
||||
self.send_command('config terminal')
|
||||
time.sleep(0.1)
|
||||
# first item: macro command
|
||||
commands += (candidate.pop(0) + '\n')
|
||||
multiline_delimiter = candidate.pop(-1)
|
||||
for line in candidate:
|
||||
if line != 'None':
|
||||
commands += (' ' + line + '\n')
|
||||
self.send_command('config terminal', sendonly=True)
|
||||
commands += (multiline_delimiter + '\n')
|
||||
obj = {'command': commands, 'sendonly': True}
|
||||
results.append(self.send_command(**obj))
|
||||
requests.append(commands)
|
||||
|
||||
time.sleep(0.1)
|
||||
self.send_command('end', sendonly=True)
|
||||
time.sleep(0.1)
|
||||
results.append(self.send_command('\n'))
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
A12345678 123456789 123456789 123456789 123456789 123456789 123456789
|
||||
B12345678 123456789 123456789 123456789 123456789 123456789 123456789
|
||||
C12345678 123456789 123456789 123456789 123456789 123456789 123456789
|
||||
D12345678 123456789 123456789 123456789 123456789 123456789 123456789
|
||||
E12345678 123456789 123456789 123456789 123456789 123456789 123456789
|
||||
F12345678 123456789 123456789 123456789 123456789 123456789 123456789
|
||||
G12345678 123456789 123456789 123456789 123456789 123456789 123456789
|
||||
H12345678 123456789 123456789 123456789 123456789 123456789 123456789
|
66
test/integration/targets/ios_config/tests/cli/macro.yaml
Normal file
66
test/integration/targets/ios_config/tests/cli/macro.yaml
Normal file
|
@ -0,0 +1,66 @@
|
|||
---
|
||||
|
||||
- debug: msg="START cli/cli_macro.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: "Check for macro support"
|
||||
ios_command:
|
||||
commands:
|
||||
- "show parser macro brief"
|
||||
register: supports_macro
|
||||
ignore_errors: yes
|
||||
|
||||
- name: "ios_config macro integration tests"
|
||||
when: supports_macro is succeeded
|
||||
block:
|
||||
|
||||
- name: "Define macro name"
|
||||
set_fact:
|
||||
macro_name: 'MACRO_ANSIBLE_TEST'
|
||||
|
||||
- name: "setup - remove configuration"
|
||||
ios_config:
|
||||
lines:
|
||||
- 'no macro name {{ macro_name }}'
|
||||
- 'do show clock'
|
||||
match: none
|
||||
|
||||
- name: "configure macro"
|
||||
ios_config:
|
||||
parents: "macro name {{ macro_name }}"
|
||||
# before: [ 'no macro name ...']
|
||||
multiline_delimiter: '@'
|
||||
after: '@'
|
||||
match: line
|
||||
replace: block
|
||||
lines: "{{ lookup('template', 'basic/macro.j2') }}"
|
||||
register: result
|
||||
|
||||
- name: "Check if macro has been added"
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: "configure macro again - idempotent check"
|
||||
ios_config:
|
||||
parents: "macro name {{ macro_name }}"
|
||||
multiline_delimiter: '@'
|
||||
after: '@'
|
||||
match: line
|
||||
replace: block
|
||||
lines: "{{ lookup('template', 'basic/macro.j2') }}"
|
||||
register: result
|
||||
|
||||
- name: "macro already/correctly configured ?"
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
always:
|
||||
- name: "teardown"
|
||||
ios_config:
|
||||
lines:
|
||||
- "no macro name {{ macro_name }}"
|
||||
- 'do show clock'
|
||||
match: none
|
||||
|
||||
- debug: msg="END cli/cli_macro.yaml on connection={{ ansible_connection }}"
|
Loading…
Reference in a new issue