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

Fix vyos banner idempotent (#26338)

* fix vyos_banner idempotent

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

* fix vyos_banner unit test

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha 2017-07-03 13:08:08 +05:30 committed by GitHub
parent 483346d94b
commit 1b427aa419
2 changed files with 9 additions and 8 deletions

View file

@ -94,16 +94,17 @@ def spec_to_commands(updates, module):
want, have = updates want, have = updates
state = module.params['state'] state = module.params['state']
if state == 'absent' or (state == 'absent' and if state == 'absent':
'text' in have.keys() and have['text']): if have.get('state') != 'absent' or (have.get('state') != 'absent' and
commands.append('delete system login banner %s' % module.params['banner']) 'text' in have.keys() and have['text']):
commands.append('delete system login banner %s' % module.params['banner'])
elif state == 'present': elif state == 'present':
if want['text'] and (want['text'] != have.get('text')): if want['text'] and (want['text'] != have.get('text')):
banner_cmd = 'set system login banner %s ' % module.params['banner'] banner_cmd = 'set system login banner %s ' % module.params['banner']
banner_cmd += '"' banner_cmd += "'"
banner_cmd += want['text'].strip() banner_cmd += want['text'].strip()
banner_cmd += '"' banner_cmd += "'"
commands.append(banner_cmd) commands.append(banner_cmd)
return commands return commands
@ -120,7 +121,7 @@ def config_to_dict(module):
output = match output = match
if output: if output:
obj['text'] = output obj['text'] = output[0][1:-1]
obj['state'] = 'present' obj['state'] = 'present'
return obj return obj

View file

@ -44,10 +44,10 @@ class TestVyosBannerModule(TestVyosModule):
def test_vyos_banner_create(self): def test_vyos_banner_create(self):
set_module_args(dict(banner='pre-login', text='test\nbanner\nstring')) set_module_args(dict(banner='pre-login', text='test\nbanner\nstring'))
commands = ['set system login banner pre-login "test\nbanner\nstring"'] commands = ["set system login banner pre-login 'test\nbanner\nstring'"]
self.execute_module(changed=True, commands=commands) self.execute_module(changed=True, commands=commands)
def test_vyos_banner_remove(self): def test_vyos_banner_remove(self):
set_module_args(dict(banner='pre-login', state='absent')) set_module_args(dict(banner='pre-login', state='absent'))
commands = ['delete system login banner pre-login'] commands = ['delete system login banner pre-login']
self.execute_module(changed=True, commands=commands) self.execute_module(changed=False, commands=[])