diff --git a/lib/ansible/modules/network/nxos/nxos_bgp_af.py b/lib/ansible/modules/network/nxos/nxos_bgp_af.py index efed961a58..c92c4607f6 100644 --- a/lib/ansible/modules/network/nxos/nxos_bgp_af.py +++ b/lib/ansible/modules/network/nxos/nxos_bgp_af.py @@ -279,7 +279,6 @@ BOOL_PARAMS = [ 'additional_paths_receive', 'additional_paths_send', 'advertise_l2vpn_evpn', - 'client_to_client', 'dampening_state', 'default_information_originate', 'suppress_inactive', @@ -420,8 +419,15 @@ def get_value(arg, config, module): if has_tablemap: value = has_tablemap.group('value') + elif arg == 'client_to_client': + no_command_re = re.compile(r'^\s+no\s{0}\s*$'.format(command), re.M) + value = True + + if no_command_re.search(config): + value = False + elif arg in BOOL_PARAMS: - command_re = re.compile(r'\s+{0}\s*'.format(command), re.M) + command_re = re.compile(r'^\s+{0}\s*$'.format(command), re.M) value = False if command_re.search(config): @@ -674,14 +680,12 @@ def state_present(module, existing, proposed, candidate): if module.params['vrf'] != 'default': parents.append('vrf {0}'.format(module.params['vrf'])) - if len(commands) == 1: - candidate.add(commands, parents=parents) - elif len(commands) > 1: - parents.append('address-family {0} {1}'.format(module.params['afi'], - module.params['safi'])) - if addr_family_command in commands: - commands.remove(addr_family_command) - candidate.add(commands, parents=parents) + addr_family_command = "address-family {0} {1}".format(module.params['afi'], + module.params['safi']) + parents.append(addr_family_command) + if addr_family_command in commands: + commands.remove(addr_family_command) + candidate.add(commands, parents=parents) def state_absent(module, candidate): diff --git a/test/units/modules/network/nxos/fixtures/nxos_bgp/config.cfg b/test/units/modules/network/nxos/fixtures/nxos_bgp/config.cfg new file mode 100644 index 0000000000..516948a0b8 --- /dev/null +++ b/test/units/modules/network/nxos/fixtures/nxos_bgp/config.cfg @@ -0,0 +1,11 @@ +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_af.py b/test/units/modules/network/nxos/test_nxos_bgp_af.py index b3c7f0bb19..b3c8bb616f 100644 --- a/test/units/modules/network/nxos/test_nxos_bgp_af.py +++ b/test/units/modules/network/nxos/test_nxos_bgp_af.py @@ -42,7 +42,7 @@ class TestNxosBgpAfModule(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.get_config.return_value = load_fixture('nxos_bgp', 'config.cfg') self.load_config.return_value = None def test_nxos_bgp_af(self): @@ -89,3 +89,12 @@ class TestNxosBgpAfModule(TestNxosModule): dampening_reuse_time=1900, dampening_max_suppress_time=10)) result = self.execute_module(failed=True) self.assertEqual(result['msg'], 'dampening_routemap cannot be used with the dampening_half_time param') + + def test_nxos_bgp_af_client(self): + set_module_args(dict(asn=65535, afi='ipv4', safi='unicast', + client_to_client=False)) + self.execute_module( + changed=True, + commands=['router bgp 65535', 'address-family ipv4 unicast', + 'no client-to-client reflection'] + )