ios_logging handling platform difference (#35232)

* ios_logging handling platform difference

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* fix unit test

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
pull/35260/head
Trishna Guha 7 years ago committed by GitHub
parent 6f67d68f5a
commit fd4fdbf01f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -123,8 +123,9 @@ import re
from copy import deepcopy
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.common.utils import remove_default_spec
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_capabilities
from ansible.module_utils.network.ios.ios import ios_argument_spec, check_args
@ -136,7 +137,7 @@ def validate_size(value, module):
return value
def map_obj_to_commands(updates, module):
def map_obj_to_commands(updates, module, os_version):
commands = list()
want, have = updates
for w in want:
@ -150,7 +151,10 @@ def map_obj_to_commands(updates, module):
if state == 'absent' and w in have:
if dest == 'host':
commands.append('no logging host {0}'.format(name))
if '12.' in os_version:
commands.append('no logging {0}'.format(name))
else:
commands.append('no logging host {0}'.format(name))
elif dest:
commands.append('no logging {0}'.format(dest))
else:
@ -164,7 +168,10 @@ def map_obj_to_commands(updates, module):
commands.append('logging facility {0}'.format(facility))
if dest == 'host':
commands.append('logging host {0}'.format(name))
if '12.' in os_version:
commands.append('logging {0}'.format(name))
else:
commands.append('logging host {0}'.format(name))
elif dest == 'on':
commands.append('logging on')
@ -176,11 +183,11 @@ def map_obj_to_commands(updates, module):
commands.append('logging buffered {0}'.format(size))
else:
dest_cmd = 'logging {0}'.format(dest)
if level:
dest_cmd += ' {0}'.format(level)
commands.append(dest_cmd)
if dest:
dest_cmd = 'logging {0}'.format(dest)
if level:
dest_cmd += ' {0}'.format(level)
commands.append(dest_cmd)
return commands
@ -268,6 +275,14 @@ def map_config_to_obj(module):
'facility': parse_facility(line, dest),
'level': parse_level(line, dest)
})
elif validate_ip_address(match.group(1)):
dest = 'host'
obj.append({
'dest': dest,
'name': match.group(1),
'facility': parse_facility(line, dest),
'level': parse_level(line, dest)
})
else:
ip_match = re.search(r'\d+\.\d+\.\d+\.\d+', match.group(1), re.M)
if ip_match:
@ -278,6 +293,7 @@ def map_config_to_obj(module):
'facility': parse_facility(line, dest),
'level': parse_level(line, dest)
})
return obj
@ -373,6 +389,9 @@ def main():
required_if=required_if,
supports_check_mode=True)
device_info = get_capabilities(module)
os_version = device_info['device_info']['network_os_version']
warnings = list()
check_args(module, warnings)
@ -383,7 +402,7 @@ def main():
want = map_params_to_obj(module, required_if=required_if)
have = map_config_to_obj(module)
commands = map_obj_to_commands((want, have), module)
commands = map_obj_to_commands((want, have), module, os_version)
result['commands'] = commands
if commands:

@ -42,11 +42,16 @@ class TestIosLoggingModule(TestIosModule):
self.mock_load_config = patch('ansible.modules.network.ios.ios_logging.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_capabilities = patch('ansible.modules.network.ios.ios_logging.get_capabilities')
self.get_capabilities = self.mock_get_capabilities.start()
self.get_capabilities.return_value = {'device_info': {'network_os_version': '15.6(2)T'}}
def tearDown(self):
super(TestIosLoggingModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_get_capabilities.stop()
def load_fixtures(self, commands=None):
self.get_config.return_value = load_fixture('ios_logging_config.cfg')

Loading…
Cancel
Save