mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixes ios_logging idempotency issues (#40701)
* Fixes ios_logging idempotency issues * Added intergration tests & minor fixes * Minor fixes in tests * Minor fixes in tests #2 * eos_logging fixes after PR review
This commit is contained in:
parent
083ddb9bc2
commit
a013cdc747
2 changed files with 69 additions and 17 deletions
|
@ -121,7 +121,6 @@ commands:
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.common.utils import remove_default_spec, validate_ip_address
|
from ansible.module_utils.network.common.utils import remove_default_spec, validate_ip_address
|
||||||
from ansible.module_utils.network.ios.ios import get_config, load_config
|
from ansible.module_utils.network.ios.ios import get_config, load_config
|
||||||
|
@ -138,6 +137,7 @@ def validate_size(value, module):
|
||||||
|
|
||||||
|
|
||||||
def map_obj_to_commands(updates, module, os_version):
|
def map_obj_to_commands(updates, module, os_version):
|
||||||
|
dest_group = ('console', 'monitor', 'buffered', 'on')
|
||||||
commands = list()
|
commands = list()
|
||||||
want, have = updates
|
want, have = updates
|
||||||
for w in want:
|
for w in want:
|
||||||
|
@ -149,14 +149,20 @@ def map_obj_to_commands(updates, module, os_version):
|
||||||
state = w['state']
|
state = w['state']
|
||||||
del w['state']
|
del w['state']
|
||||||
|
|
||||||
|
if facility:
|
||||||
|
w['dest'] = 'facility'
|
||||||
|
|
||||||
if state == 'absent' and w in have:
|
if state == 'absent' and w in have:
|
||||||
|
if dest:
|
||||||
if dest == 'host':
|
if dest == 'host':
|
||||||
if '12.' in os_version:
|
if '12.' in os_version:
|
||||||
commands.append('no logging {0}'.format(name))
|
commands.append('no logging {0}'.format(name))
|
||||||
else:
|
else:
|
||||||
commands.append('no logging host {0}'.format(name))
|
commands.append('no logging host {0}'.format(name))
|
||||||
elif dest:
|
|
||||||
|
elif dest in dest_group:
|
||||||
commands.append('no logging {0}'.format(dest))
|
commands.append('no logging {0}'.format(dest))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='dest must be among console, monitor, buffered, host, on')
|
module.fail_json(msg='dest must be among console, monitor, buffered, host, on')
|
||||||
|
|
||||||
|
@ -165,6 +171,13 @@ def map_obj_to_commands(updates, module, os_version):
|
||||||
|
|
||||||
if state == 'present' and w not in have:
|
if state == 'present' and w not in have:
|
||||||
if facility:
|
if facility:
|
||||||
|
present = False
|
||||||
|
|
||||||
|
for entry in have:
|
||||||
|
if entry['dest'] == 'facility' and entry['facility'] == facility:
|
||||||
|
present = True
|
||||||
|
|
||||||
|
if not present:
|
||||||
commands.append('logging facility {0}'.format(facility))
|
commands.append('logging facility {0}'.format(facility))
|
||||||
|
|
||||||
if dest == 'host':
|
if dest == 'host':
|
||||||
|
@ -177,6 +190,13 @@ def map_obj_to_commands(updates, module, os_version):
|
||||||
commands.append('logging on')
|
commands.append('logging on')
|
||||||
|
|
||||||
elif dest == 'buffered' and size:
|
elif dest == 'buffered' and size:
|
||||||
|
present = False
|
||||||
|
|
||||||
|
for entry in have:
|
||||||
|
if entry['dest'] == 'buffered' and entry['size'] == size and entry['level'] == level:
|
||||||
|
present = True
|
||||||
|
|
||||||
|
if not present:
|
||||||
if level and level != 'debugging':
|
if level and level != 'debugging':
|
||||||
commands.append('logging buffered {0} {1}'.format(size, level))
|
commands.append('logging buffered {0} {1}'.format(size, level))
|
||||||
else:
|
else:
|
||||||
|
@ -293,7 +313,6 @@ def map_config_to_obj(module):
|
||||||
'facility': parse_facility(line, dest),
|
'facility': parse_facility(line, dest),
|
||||||
'level': parse_level(line, dest)
|
'level': parse_level(line, dest)
|
||||||
})
|
})
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
@ -355,7 +374,6 @@ def map_params_to_obj(module, required_if=None):
|
||||||
'level': module.params['level'],
|
'level': module.params['level'],
|
||||||
'state': module.params['state']
|
'state': module.params['state']
|
||||||
})
|
})
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
@ -412,5 +430,6 @@ def main():
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -99,6 +99,7 @@
|
||||||
- 'result.changed == true'
|
- 'result.changed == true'
|
||||||
- '"logging buffered 8000" in result.commands'
|
- '"logging buffered 8000" in result.commands'
|
||||||
|
|
||||||
|
|
||||||
- name: Change logging parameters using aggregate
|
- name: Change logging parameters using aggregate
|
||||||
ios_logging:
|
ios_logging:
|
||||||
aggregate:
|
aggregate:
|
||||||
|
@ -113,11 +114,42 @@
|
||||||
- '"logging buffered 9000" in result.commands'
|
- '"logging buffered 9000" in result.commands'
|
||||||
- '"logging console notifications" in result.commands'
|
- '"logging console notifications" in result.commands'
|
||||||
|
|
||||||
|
- name: Set both logging destination and facility
|
||||||
|
ios_logging:
|
||||||
|
dest: buffered
|
||||||
|
facility: uucp
|
||||||
|
level: alerts
|
||||||
|
size: 4096
|
||||||
|
state: present
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == true'
|
||||||
|
- '"logging buffered 4096 alerts" in result.commands'
|
||||||
|
- '"logging facility uucp" in result.commands'
|
||||||
|
|
||||||
|
- name: Set both logging destination and facility (idempotent)
|
||||||
|
ios_logging:
|
||||||
|
dest: buffered
|
||||||
|
facility: uucp
|
||||||
|
level: alerts
|
||||||
|
size: 4096
|
||||||
|
state: present
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == false'
|
||||||
|
|
||||||
- name: remove logging as collection tearDown
|
- name: remove logging as collection tearDown
|
||||||
ios_logging:
|
ios_logging:
|
||||||
aggregate:
|
aggregate:
|
||||||
- { dest: console, level: notifications }
|
- { dest: console, level: notifications }
|
||||||
- { dest: buffered, size: 9000 }
|
- { dest: buffered, size: 4096, level: alerts }
|
||||||
|
- { facility: uucp }
|
||||||
state: absent
|
state: absent
|
||||||
provider: "{{ cli }}"
|
provider: "{{ cli }}"
|
||||||
register: result
|
register: result
|
||||||
|
@ -127,3 +159,4 @@
|
||||||
- 'result.changed == true'
|
- 'result.changed == true'
|
||||||
- '"no logging console" in result.commands'
|
- '"no logging console" in result.commands'
|
||||||
- '"no logging buffered" in result.commands'
|
- '"no logging buffered" in result.commands'
|
||||||
|
- '"no logging facility uucp" in result.commands'
|
||||||
|
|
Loading…
Reference in a new issue