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

Fixes #30281 eos_banner integration test failure (#30283)

* Fixes #30281 Configure login prompt for eos_banner

* Fix unit test

* Fix pep8 issue
This commit is contained in:
Ganesh Nalawade 2017-09-14 13:56:32 +05:30 committed by GitHub
parent ec59650528
commit 3ff527b1d2
3 changed files with 29 additions and 7 deletions

View file

@ -92,8 +92,10 @@ session_name:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.eos import load_config, run_commands
from ansible.module_utils.eos import eos_argument_spec, check_args
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_text
def map_obj_to_commands(updates, module):
commands = list()
want, have = updates
@ -106,7 +108,7 @@ def map_obj_to_commands(updates, module):
commands.append({'cmd': 'no banner %s' % module.params['banner']})
elif state == 'present':
if isinstance(have['text'], str):
if isinstance(have['text'], string_types):
if want['text'] != have['text']:
commands.append('banner %s' % module.params['banner'])
commands.extend(want['text'].strip().split('\n'))
@ -122,7 +124,6 @@ def map_obj_to_commands(updates, module):
commands.append({'cmd': 'banner %s' % module.params['banner'],
'input': want['text'].strip('\n')})
return commands
def map_config_to_obj(module):
@ -139,7 +140,7 @@ def map_config_to_obj(module):
else:
banner_response_key = 'motd'
if isinstance(output[0], dict) and banner_response_key in output[0].keys():
obj['text'] = output[0][banner_response_key].strip('\n')
obj['text'] = output[0]
obj['state'] = 'present'
return obj

View file

@ -64,7 +64,7 @@ class AnsibleFailJson(Exception):
class TestEosModule(unittest.TestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False, transport='cli'):
def execute_module(self, failed=False, changed=False, commands=None, inputs=None, sort=True, defaults=False, transport='cli'):
self.load_fixtures(commands, transport=transport)
@ -76,10 +76,24 @@ class TestEosModule(unittest.TestCase):
self.assertEqual(result['changed'], changed, result)
if commands is not None:
if sort:
self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
if transport == 'eapi':
cmd = []
value = []
for item in result['commands']:
cmd.append(item['cmd'])
if 'input' in item:
value.append(item['input'])
if sort:
self.assertEqual(sorted(commands), sorted(cmd), cmd)
else:
self.assertEqual(commands, cmd, cmd)
if inputs:
self.assertEqual(inputs, value, value)
else:
self.assertEqual(commands, result['commands'], result['commands'])
if sort:
self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
else:
self.assertEqual(commands, result['commands'], result['commands'])
return result

View file

@ -58,6 +58,13 @@ class TestEosBannerModule(TestEosModule):
commands = ['no banner login']
self.execute_module(changed=True, commands=commands)
def test_eos_banner_create_with_eapi_transport(self):
set_module_args(dict(banner='login', text='test\nbanner\nstring',
transport='eapi'))
commands = ['banner login']
inputs = ['test\nbanner\nstring']
self.execute_module(changed=True, commands=commands, inputs=inputs, transport='eapi')
def test_eos_banner_remove_with_eapi_transport(self):
set_module_args(dict(banner='login', state='absent', transport='eapi'))
commands = ['no banner login']