mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix the eos_banner idempotency (#22413)
The map_config_to_obj calls the run_commands helper function, which returns a list of results. However, the map_params_to_obj return a single string. Therefore, the comparison between the two datasets could never be equal, breaking idempotency. Also, the 'no banner' command should be run on absent only if there's a banner text set. Fixes #22194
This commit is contained in:
parent
0f82674c0e
commit
c57729944b
2 changed files with 3 additions and 4 deletions
|
@ -102,7 +102,7 @@ def map_obj_to_commands(updates, module):
|
||||||
want, have = updates
|
want, have = updates
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent' and have['text']:
|
||||||
commands.append('no banner %s' % module.params['banner'])
|
commands.append('no banner %s' % module.params['banner'])
|
||||||
|
|
||||||
elif state == 'present':
|
elif state == 'present':
|
||||||
|
@ -117,7 +117,7 @@ def map_config_to_obj(module):
|
||||||
output = run_commands(module, ['show banner %s' % module.params['banner']])
|
output = run_commands(module, ['show banner %s' % module.params['banner']])
|
||||||
obj = {'banner': module.params['banner'], 'state': 'absent'}
|
obj = {'banner': module.params['banner'], 'state': 'absent'}
|
||||||
if output:
|
if output:
|
||||||
obj['text'] = output
|
obj['text'] = output[0]
|
||||||
obj['state'] = 'present'
|
obj['state'] = 'present'
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@ -155,7 +155,6 @@ def main():
|
||||||
result = {'changed': False}
|
result = {'changed': False}
|
||||||
if warnings:
|
if warnings:
|
||||||
result['warnings'] = warnings
|
result['warnings'] = warnings
|
||||||
|
|
||||||
want = map_params_to_obj(module)
|
want = map_params_to_obj(module)
|
||||||
have = map_config_to_obj(module)
|
have = map_config_to_obj(module)
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class TestEosBannerModule(TestEosModule):
|
||||||
self.mock_load_config.stop()
|
self.mock_load_config.stop()
|
||||||
|
|
||||||
def load_fixtures(self, commands=None):
|
def load_fixtures(self, commands=None):
|
||||||
self.run_commands.return_value = load_fixture('eos_banner_show_banner.txt').strip()
|
self.run_commands.return_value = [load_fixture('eos_banner_show_banner.txt').strip()]
|
||||||
self.load_config.return_value = dict(diff=None, session='session')
|
self.load_config.return_value = dict(diff=None, session='session')
|
||||||
|
|
||||||
def test_eos_banner_create(self):
|
def test_eos_banner_create(self):
|
||||||
|
|
Loading…
Reference in a new issue