From c57729944b945c6f38299666d5bee928c02277a1 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Thu, 9 Mar 2017 13:43:54 +0100 Subject: [PATCH] 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 --- lib/ansible/modules/network/eos/eos_banner.py | 5 ++--- test/units/modules/network/eos/test_eos_banner.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/network/eos/eos_banner.py b/lib/ansible/modules/network/eos/eos_banner.py index 3469631c371..113885720c1 100644 --- a/lib/ansible/modules/network/eos/eos_banner.py +++ b/lib/ansible/modules/network/eos/eos_banner.py @@ -102,7 +102,7 @@ def map_obj_to_commands(updates, module): want, have = updates state = module.params['state'] - if state == 'absent': + if state == 'absent' and have['text']: commands.append('no banner %s' % module.params['banner']) elif state == 'present': @@ -117,7 +117,7 @@ def map_config_to_obj(module): output = run_commands(module, ['show banner %s' % module.params['banner']]) obj = {'banner': module.params['banner'], 'state': 'absent'} if output: - obj['text'] = output + obj['text'] = output[0] obj['state'] = 'present' return obj @@ -155,7 +155,6 @@ def main(): result = {'changed': False} if warnings: result['warnings'] = warnings - want = map_params_to_obj(module) have = map_config_to_obj(module) diff --git a/test/units/modules/network/eos/test_eos_banner.py b/test/units/modules/network/eos/test_eos_banner.py index 04a5d20873c..e249ca993d3 100644 --- a/test/units/modules/network/eos/test_eos_banner.py +++ b/test/units/modules/network/eos/test_eos_banner.py @@ -40,7 +40,7 @@ class TestEosBannerModule(TestEosModule): self.mock_load_config.stop() 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') def test_eos_banner_create(self):