ios_logging: Fix some smaller issues, add unit test (#32321)

* ios_logging: Fix typo in documentation

* ios_logging: Fix traceback when setting buffered destination without size

When the size parameter is not configured while configuring the buffered
destination, a traceback occurs due to the fact that validate_size expects the
parameter to be an int. Explicitely converting value to int makes the
check work for every case.

* ios_logging: Update size parameter documentation

Update the documentation of the size paramter to reflect the current behaviour
of setting a default of 4096 for the buffered dest.

* ios_logging: Add unit test

Add unit test for ios_logging testing the behaviour clarified in the previous
commits.

* ios_logging: Fix python 2.6 compliance
This commit is contained in:
Paul Neumann 2017-10-31 04:55:07 +01:00 committed by Trishna Guha
commit 53fead7c96
3 changed files with 80 additions and 11 deletions

View file

@ -38,7 +38,7 @@ options:
dest:
description:
- Destination of the logs.
choices: ['on', 'host', console', 'monitor', 'buffered']
choices: ['on', 'host', 'console', 'monitor', 'buffered']
name:
description:
- If value of C(dest) is I(file) it indicates file-name,
@ -48,6 +48,7 @@ options:
description:
- Size of buffer. The acceptable value is in range from 4096 to
4294967295 bytes.
default: 4096
facility:
description:
- Set logging facility.
@ -128,7 +129,7 @@ from ansible.module_utils.ios import ios_argument_spec, check_args
def validate_size(value, module):
if value:
if not int(4096) <= value <= int(4294967295):
if not int(4096) <= int(value) <= int(4294967295):
module.fail_json(msg='size must be between 4096 and 4294967295')
else:
return value
@ -148,32 +149,32 @@ def map_obj_to_commands(updates, module):
if state == 'absent' and w in have:
if dest == 'host':
commands.append('no logging host {}'.format(name))
commands.append('no logging host {0}'.format(name))
elif dest:
commands.append('no logging {}'.format(dest))
commands.append('no logging {0}'.format(dest))
else:
module.fail_json(msg='dest must be among console, monitor, buffered, host, on')
if facility:
commands.append('no logging facility {}'.format(facility))
commands.append('no logging facility {0}'.format(facility))
if state == 'present' and w not in have:
if facility:
commands.append('logging facility {}'.format(facility))
commands.append('logging facility {0}'.format(facility))
if dest == 'host':
commands.append('logging host {}'.format(name))
commands.append('logging host {0}'.format(name))
elif dest == 'on':
commands.append('logging on')
elif dest == 'buffered' and size:
commands.append('logging buffered {}'.format(size))
commands.append('logging buffered {0}'.format(size))
else:
dest_cmd = 'logging {}'.format(dest)
dest_cmd = 'logging {0}'.format(dest)
if level:
dest_cmd += ' {}'.format(level)
dest_cmd += ' {0}'.format(level)
commands.append(dest_cmd)
return commands
@ -228,7 +229,7 @@ def parse_level(line, dest):
level = 'debugging'
else:
match = re.search(r'logging {} (\S+)'.format(dest), line, re.M)
match = re.search(r'logging {0} (\S+)'.format(dest), line, re.M)
if match:
if match.group(1) in level_group:
level = match.group(1)