def test_iosxr_lag_interfaces_merged(self): set_module_args( dict( config=[ dict( name="Bundle-Ether10", mode="active", members=[ dict( member="GigabitEthernet0/0/0/0", mode="inherit", ), dict( member="GigabitEthernet0/0/0/1", mode="passive", ), ], links=dict(max_active=10, min_active=2), ), dict( name="Bundle-Ether11", mode="active", members=[ dict( member="GigabitEthernet0/0/0/8", mode="passive", ), dict( member="GigabitEthernet0/0/0/9", mode="passive", ), ], ), ], state="merged", ), ) commands = [ "interface Bundle-Ether10", "bundle minimum-active links 2", "bundle maximum-active links 10", "lacp mode active", "interface GigabitEthernet0/0/0/1", "bundle id 10 mode passive", "interface GigabitEthernet0/0/0/0", "bundle id 10 mode inherit", "interface Bundle-Ether11", "lacp mode active", "interface GigabitEthernet0/0/0/8", "bundle id 11 mode passive", "interface GigabitEthernet0/0/0/9", "bundle id 11 mode passive", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_change_netconf_port(self): self.get_config.return_value = """ netconf-yang agent ssh ! ssh server netconf vrf default """ self.load_config.return_value = "dummy diff" set_module_args(dict(netconf_port=9000, state="present")) result = self.execute_module(changed=True) self.assertEqual(result["commands"], ["ssh server netconf port 9000"])
def test_iosxr_prefix_list_deleted(self): run_cfg = dedent( """ipv6 prefix-list test2\n 4 remark test\n! \nipv4 prefix-list test1\n 3 remark test1\n 2 permit 10.0.0.0/24\n!""", ) self.get_config.return_value = run_cfg set_module_args(dict(state="deleted")) commands = ["no ipv4 prefix-list test1", "no ipv6 prefix-list test2"] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_disable_netconf_service(self): self.get_config.return_value = ''' netconf-yang agent ssh ! ssh server netconf vrf default ''' self.load_config.return_value = 'dummy diff' set_module_args(dict(netconf_port=830, netconf_vrf='default', state='absent')) result = self.execute_module(changed=True) self.assertEqual(result['commands'], ['no netconf-yang agent ssh', 'no ssh server netconf port 830', 'no ssh server netconf vrf default'])
def test_iosxr_config_lines_w_parents(self): lines = ['shutdown'] parents = ['interface GigabitEthernet0/0'] candidate = parents + lines set_module_args(dict(lines=lines, parents=parents)) module = MagicMock() module.params = {'lines': lines, 'parents': parents, 'src': None} candidate_config = iosxr_config.get_candidate(module) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff( candidate_config, self.running_config)) commands = ['interface GigabitEthernet0/0', 'shutdown'] self.execute_module(changed=True, commands=commands)
def test_iosxr_ospf_interfaces_deleted_idempotent(self): set_module_args( dict( config=[ dict( name="GigabitEthernet0/0/0/1", type="gigabitethernet", ), ], state="deleted", ), ) self.execute_module(changed=False, commands=[])
def test_iosxr_user_update_password_changed(self): set_module_args( dict( name="test", configured_password="******", update_password="******", ), ) result = self.execute_module(changed=True) self.assertEqual( result["commands"], ["username test", "username test secret test"], )
def test_iosxr_l2_interfaces_deleted(self): self._prepare() set_module_args(dict(state="deleted")) commands = [ "interface GigabitEthernet0/0/0/1", "no l2transport", "interface GigabitEthernet0/0/0/3.900", "no encapsulation dot1q", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_change_netconf_vrf(self): self.get_config.return_value = ''' netconf-yang agent ssh ! ssh server netconf vrf default ''' self.load_config.return_value = 'dummy diff' set_module_args(dict(netconf_vrf='new_default', state='present')) result = self.execute_module(changed=True) self.assertEqual(result['commands'], ['ssh server netconf vrf new_default'])
def test_iosxr_static_routes_deleted_afi(self): set_module_args( dict( config=[ dict(address_families=[dict(afi="ipv4", safi="unicast")]) ], state="deleted", ) ) commands = ["router static", "no address-family ipv4 unicast"] self.execute_module(changed=True, commands=commands)
def test_iosxr_lacp_merged(self): set_module_args( dict( config=dict(system=dict(priority=12, mac=dict(address="00c1.4c00.bd15"))), state="merged", )) commands = [ "lacp system mac 00c1.4c00.bd15", "lacp system priority 12", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_l3_interfaces_deleted(self): self._prepare() set_module_args(dict(state="deleted")) commands = [ "interface GigabitEthernet0/0/0/0", "no ipv4 address", "no ipv6 address", "interface GigabitEthernet0/0/0/1", "no ipv4 address", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_config_before_after_no_change(self): lines = ["hostname router"] set_module_args( dict( lines=lines, before=["test1", "test2"], after=["test3", "test4"], ), ) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff( "\n".join(lines), self.running_config, ), ) self.execute_module()
def test_iosxr_config_lines_w_parents(self): lines = ["shutdown"] parents = ["interface GigabitEthernet0/0"] set_module_args(dict(lines=lines, parents=parents)) module = MagicMock() module.params = {"lines": lines, "parents": parents, "src": None} candidate_config = iosxr_config.get_candidate(module) self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff( candidate_config, self.running_config, ), ) commands = ["interface GigabitEthernet0/0", "shutdown"] self.execute_module(changed=True, commands=commands)
def test_iosxr_ospf_interfaces_deleted(self): set_module_args( dict( config=[ dict(name="GigabitEthernet0/0/0/0", type="gigabitethernet") ], state="deleted", )) commands = [ "no router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0" ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_system_state_absent(self): set_module_args(dict(state="absent")) commands = [ "no hostname", "no domain name", "no domain lookup disable", "no domain lookup source-interface MgmtEth0/0/CPU0/0", "no domain list redhat.com", "no domain list cisco.com", "no domain name-server 8.8.8.8", "no domain name-server 8.8.4.4", ] self.execute_module(changed=True, commands=commands)
def test_iosxr_bgp_address_family_replaced(self): run_cfg = dedent( """\ router bgp 65536 address-family ipv4 unicast bgp attribute-download advertise best-external dynamic-med interval 10 bgp scan-time 20 redistribute connected metric 10 redistribute isis test3 metric 4 redistribute application test1 metric 10 allocate-label all address-family ipv4 mvpn """, ) self.get_config.return_value = run_cfg set_module_args( dict( config=dict( as_number="65536", address_family=[ dict( afi="ipv4", safi="unicast", dynamic_med=4, redistribute=[ dict( protocol="application", id="test1", metric=10, ), dict(protocol="connected", metric=10), dict(protocol="isis", id="test3", metric=4), ], ), ], ), state="replaced", ), ) commands = [ "router bgp 65536", "address-family ipv4 unicast", "no advertise best-external", "no allocate-label all", "no bgp attribute-download", "no bgp scan-time 20", "dynamic-med interval 4", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_lldp_global_deleted(self): self._prepare() set_module_args(dict(state="deleted")) commands = [ "no lldp holdtime 100", "no lldp reinit 2", "no lldp subinterfaces enable", "no lldp timer 3000", "no lldp tlv-select management-address disable", "no lldp tlv-select system-description disable", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_enable_netconf_service(self): self.get_config.return_value = "" self.load_config.return_value = "dummy diff" set_module_args( dict(netconf_port=830, netconf_vrf="default", state="present"), ) result = self.execute_module(changed=True) self.assertEqual( result["commands"], [ "netconf-yang agent ssh", "ssh server netconf port 830", "ssh server netconf vrf default", ], )
def test_iosxr_ospfv2_merged_idempotent(self): set_module_args( dict( config=dict(processes=[ dict( process_id="30", default_metric=10, cost=2, areas=[dict(area_id="11", default_cost=5)], ), ], ), state="merged", ), ) self.execute_module(changed=False, commands=[])
def test_iosxr_ospfv2_deleted(self): set_module_args( dict( config=dict(processes=[dict(process_id="30", cost=2)]), state="deleted", ) ) commands = [ "router ospf 30", "no cost 2", "no default-metric 10", "no area 11 default-cost 5", ] self.execute_module(changed=True, commands=commands)
def test_iosxr_prefix_list_rendered(self): set_module_args( dict( config=[ dict( afi="ipv6", prefix_lists=[ dict( name="test2", entries=[ dict( sequence=4, action="remark", description="test", ) ], ) ], ), dict( afi="ipv4", prefix_lists=[ dict( name="test1", entries=[ dict( sequence=3, action="remark", description="test1", ), dict( sequence=2, action="permit", prefix="10.0.0.0/24", ), ], ) ], ), ], state="rendered", )) commands = [ "ipv6 prefix-list test2 4 remark test", "ipv4 prefix-list test1 2 permit 10.0.0.0/24", "ipv4 prefix-list test1 3 remark test1", ] result = self.execute_module(changed=False) self.assertEqual(sorted(result["rendered"]), sorted(commands))
def test_iosxr_ospfv2_deleted(self): set_module_args( dict( config=dict(processes=[dict(process_id="30", cost=2)]), state="deleted", ), ) commands = [ "router ospf 30", "no cost 2", "no default-metric 10", "no area 11 default-cost 5", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_facts_gather_subset_default(self): set_module_args(dict()) result = self.execute_module() ansible_facts = result['ansible_facts'] self.assertIn('hardware', ansible_facts['ansible_net_gather_subset']) self.assertIn('default', ansible_facts['ansible_net_gather_subset']) self.assertIn('interfaces', ansible_facts['ansible_net_gather_subset']) self.assertEqual('iosxr01', ansible_facts['ansible_net_hostname']) self.assertEqual(['disk0:', 'flash0:'], ansible_facts['ansible_net_filesystems']) self.assertIn('GigabitEthernet0/0/0/0', ansible_facts['ansible_net_interfaces'].keys()) self.assertEqual('3095', ansible_facts['ansible_net_memtotal_mb']) self.assertEqual('1499', ansible_facts['ansible_net_memfree_mb'])
def test_iosxr_lldp_interfaces_deleted(self): self._prepare() set_module_args(dict(state="deleted")) commands = [ "interface GigabitEthernet0/0/0/0", "no lldp transmit disable", "no lldp destination mac-address ieee-nearest-bridge", "interface GigabitEthernet0/0/0/1", "no lldp destination mac-address ieee-nearest-non-tmpr-bridge", "no lldp receive disable", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_bgp_nbr_af_deleted(self): self.maxDiff = None run_cfg = dedent( """\ router bgp 1 bgp router-id 1.2.3.4 neighbor 1.1.1.1 remote-as 5 address-family ipv4 unicast origin-as validation disable bestpath origin-as allow invalid aigp aigp send med send-community-ebgp multipath allowas-in 4 maximum-prefix 10 20 restart 10 as-override capability orf prefix both send-extended-community-ebgp default-originate next-hop-self send-community-gshut-ebgp soft-reconfiguration inbound send-multicast-attributes remove-private-AS inbound entire-aspath next-hop-unchanged multipath vrf vrf1 rd auto address-family ipv4 unicast neighbor 1.2.1.2 remote-as 5 address-family ipv4 unicast multipath capability orf prefix both default-originate """, ) self.get_config.return_value = run_cfg set_module_args(dict(config=dict(), state="deleted")) commands = [ "router bgp 1", "neighbor 1.1.1.1", "no address-family ipv4 unicast", "vrf vrf1", "neighbor 1.2.1.2", "no address-family ipv4 unicast", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_iosxr_acls_overridden_idempotent(self): set_module_args( dict( config=[ dict( afi="ipv4", acls=[ dict( name="acl_2", aces=[ dict( sequence="10", grant="deny", protocol="ipv4", destination=dict(any="true"), source=dict(any="true"), ), dict( sequence="20", grant="permit", protocol="tcp", destination=dict(any="true"), source=dict(host="192.168.1.100"), ), ], ) ], ), dict( afi="ipv6", acls=[ dict( name="acl6_1", aces=[ dict( sequence="10", grant="deny", protocol="icmpv6", destination=dict(any="true"), source=dict(any="true"), ) ], ) ], ), ], state="overridden", )) self.execute_module(changed=False, commands=[])
def test_iosxr_prefix_lists_replaced_idempotent(self): run_cfg = dedent( """ipv6 prefix-list test2\n 4 remark test\n! \nipv4 prefix-list test1\n 3 remark test1\n 2 permit 10.0.0.0/24\n!""", ) self.get_config.return_value = run_cfg set_module_args( dict( config=[ dict( afi="ipv6", prefix_lists=[ dict( name="test2", entries=[ dict( sequence=4, action="remark", description="test", ), ], ), ], ), dict( afi="ipv4", prefix_lists=[ dict( name="test1", entries=[ dict( sequence=3, action="remark", description="test1", ), dict( sequence=2, action="permit", prefix="10.0.0.0/24", ), ], ), ], ), ], state="replaced", ), ) self.execute_module(changed=False, commands=[])
def test_iosxr_config_replace_block(self): lines = ['description test string', 'test string'] parents = ['interface GigabitEthernet0/0'] set_module_args(dict(lines=lines, replace='block', parents=parents)) commands = parents + lines module = MagicMock() module.params = {'lines': lines, 'parents': parents, 'src': None} candidate_config = iosxr_config.get_candidate(module) self.conn.get_diff = MagicMock( return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config, diff_replace='block', path=parents)) self.execute_module(changed=True, commands=commands)
def test_iosxr_config_match_none(self): lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string'] parents = ['interface GigabitEthernet0/0'] set_module_args(dict(lines=lines, parents=parents, match='none')) commands = parents + lines module = MagicMock() module.params = {'lines': lines, 'parents': parents, 'src': None} candidate_config = iosxr_config.get_candidate(module) self.conn.get_diff = MagicMock( return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config, diff_match='none', path=parents)) self.execute_module(changed=True, commands=commands, sort=False)