From f84ff216b668916e66d99235343c0d524fc335fc Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Wed, 6 Sep 2017 17:37:44 -0400 Subject: [PATCH] Generalize nxos_bgp event-history detection (#28890) * More general handling of event-history * Update unit tests --- lib/ansible/modules/network/nxos/nxos_bgp.py | 10 +++------- .../modules/network/nxos/fixtures/nxos_bgp_config.cfg | 11 ----------- test/units/modules/network/nxos/test_nxos_bgp.py | 4 ++-- 3 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 test/units/modules/network/nxos/fixtures/nxos_bgp_config.cfg diff --git a/lib/ansible/modules/network/nxos/nxos_bgp.py b/lib/ansible/modules/network/nxos/nxos_bgp.py index d63b8775d3..2dd8db5ab4 100644 --- a/lib/ansible/modules/network/nxos/nxos_bgp.py +++ b/lib/ansible/modules/network/nxos/nxos_bgp.py @@ -412,7 +412,6 @@ def get_value(arg, config): command = PARAM_TO_COMMAND_KEYMAP.get(arg) if command.split()[0] == 'event-history': - command_re = re.compile(r'\s+{0}\s*'.format(command), re.M) has_size = re.search(r'^\s+{0} size\s(?P.*)$'.format(command), config, re.M) if command == 'event-history detail': @@ -420,11 +419,8 @@ def get_value(arg, config): else: value = 'size_small' - if command_re.search(config): - if has_size: - value = 'size_%s' % has_size.group('value') - else: - value = True + if has_size: + value = 'size_%s' % has_size.group('value') elif arg in ['enforce_first_as', 'fast_external_fallover']: no_command_re = re.compile(r'no\s+{0}\s*'.format(command), re.M) @@ -687,7 +683,7 @@ def main(): if candidate: candidate = candidate.items_text() - load_config(module, candidate) + warnings.extend(load_config(module, candidate)) result['changed'] = True result['commands'] = candidate else: diff --git a/test/units/modules/network/nxos/fixtures/nxos_bgp_config.cfg b/test/units/modules/network/nxos/fixtures/nxos_bgp_config.cfg deleted file mode 100644 index 516948a0b8..0000000000 --- a/test/units/modules/network/nxos/fixtures/nxos_bgp_config.cfg +++ /dev/null @@ -1,11 +0,0 @@ -feature bgp - -router bgp 65535 - router-id 192.168.1.1 - event-history cli size medium - event-history detail - vrf test2 - address-family ipv4 unicast - timers bgp 1 10 - neighbor 3.3.3.5 - address-family ipv4 unicast diff --git a/test/units/modules/network/nxos/test_nxos_bgp.py b/test/units/modules/network/nxos/test_nxos_bgp.py index 2d3cdedb33..275b3bdbb2 100644 --- a/test/units/modules/network/nxos/test_nxos_bgp.py +++ b/test/units/modules/network/nxos/test_nxos_bgp.py @@ -42,8 +42,8 @@ class TestNxosBgpModule(TestNxosModule): self.mock_get_config.stop() def load_fixtures(self, commands=None, device=''): - self.get_config.return_value = load_fixture('', 'nxos_bgp_config.cfg') - self.load_config.return_value = None + self.get_config.return_value = load_fixture('nxos_bgp', 'config.cfg') + self.load_config.return_value = [] def test_nxos_bgp(self): set_module_args(dict(asn=65535, router_id='1.1.1.1'))