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

Iosxr attribute error #27122 (#27425)

* WIP fixing iosxr_logging idempotency

* remove debug stuff from module, add teardown section to start of test
This commit is contained in:
David Newswanger 2017-07-28 10:37:34 -04:00 committed by Trishna Guha
parent 36c6d0f748
commit 3b1f2aeb16
3 changed files with 42 additions and 19 deletions

View file

@ -122,7 +122,6 @@ def validate_size(value, module):
def map_obj_to_commands(updates, module): def map_obj_to_commands(updates, module):
commands = list() commands = list()
want, have = updates want, have = updates
for w in want: for w in want:
dest = w['dest'] dest = w['dest']
name = w['name'] name = w['name']
@ -162,7 +161,6 @@ def map_obj_to_commands(updates, module):
dest_cmd += ' {}'.format(level) dest_cmd += ' {}'.format(level)
commands.append(dest_cmd) commands.append(dest_cmd)
return commands return commands
@ -208,7 +206,7 @@ def parse_name(line, dest):
def parse_level(line, dest): def parse_level(line, dest):
level_group = ('emergencies', 'alerts', 'critical', 'errors', 'warnings', level_group = ('emergencies', 'alerts', 'critical', 'errors', 'warning',
'notifications', 'informational', 'debugging') 'notifications', 'informational', 'debugging')
if dest == 'hostnameprefix': if dest == 'hostnameprefix':
@ -228,25 +226,25 @@ def parse_level(line, dest):
def map_config_to_obj(module): def map_config_to_obj(module):
obj = [] obj = []
dest_group = ('console', 'hostnameprefix', 'monitor', 'buffered', 'on') dest_group = ('console', 'hostnameprefix', 'monitor', 'buffered', 'on')
data = get_config(module, flags=['logging']) data = get_config(module, flags=['logging'])
lines = data.split("\n")
for line in data.split('\n'): for line in lines:
match = re.search(r'logging (\S+)', line, re.M) match = re.search(r'logging (\S+)', line, re.M)
if match:
if match.group(1) in dest_group: if match.group(1) in dest_group:
dest = match.group(1) dest = match.group(1)
else: obj.append({
pass 'dest': dest,
obj.append({'dest': dest,
'name': parse_name(line, dest), 'name': parse_name(line, dest),
'size': parse_size(line, dest), 'size': parse_size(line, dest),
'facility': parse_facility(line), 'facility': parse_facility(line),
'level': parse_level(line, dest)}) 'level': parse_level(line, dest)
})
return obj return obj

View file

@ -10,7 +10,7 @@
- assert: - assert:
that: that:
- 'result.chaned == true' - 'result.changed == true'
- '"logging host 172.16.0.1" in result.commands' - '"logging host 172.16.0.1" in result.commands'
- '"logging facility local7" in result.commands' - '"logging facility local7" in result.commands'

View file

@ -1,4 +1,29 @@
--- ---
# Remove old logging entries so that they don't conflict with tests
- name: Remove host logging
iosxr_logging:
dest: hostnameprefix
name: 172.16.0.1
state: absent
provider: "{{ cli }}"
- name: Remove console logging
iosxr_logging:
dest: console
level: warning
state: absent
provider: "{{ cli }}"
register: result
- name: Remove buffer
iosxr_logging:
dest: buffered
size: 4800000
state: absent
provider: "{{ cli }}"
register: result
# Start tests
- name: Set up host logging - name: Set up host logging
iosxr_logging: iosxr_logging:
dest: hostnameprefix dest: hostnameprefix
@ -9,7 +34,7 @@
- assert: - assert:
that: that:
- 'result.chaned == true' - 'result.changed == true'
- '"logging hostnameprefix 172.16.0.1" in result.commands' - '"logging hostnameprefix 172.16.0.1" in result.commands'
- '"logging facility local7" in result.commands' - '"logging facility local7" in result.commands'
@ -50,10 +75,10 @@
that: that:
- 'result.changed == false' - 'result.changed == false'
- name: Console logging with level warnings - name: Console logging with level warning
iosxr_logging: iosxr_logging:
dest: console dest: console
level: warnings level: warning
state: present state: present
provider: "{{ cli }}" provider: "{{ cli }}"
register: result register: result
@ -61,7 +86,7 @@
- assert: - assert:
that: that:
- 'result.changed == true' - 'result.changed == true'
- '"logging console warnings" in result.commands' - '"logging console warning" in result.commands'
- name: Configure Buffer size - name: Configure Buffer size
iosxr_logging: iosxr_logging:
@ -78,7 +103,7 @@
- name: remove logging as collection tearDown - name: remove logging as collection tearDown
iosxr_logging: iosxr_logging:
aggregate: aggregate:
- { dest: console, level: warnings, state: absent } - { dest: console, level: warning, state: absent }
- { dest: buffered, size: 4800000, state: absent } - { dest: buffered, size: 4800000, state: absent }
provider: "{{ cli }}" provider: "{{ cli }}"
register: result register: result