def test_nxos_lldp_interfaces_deleted_all(self): set_module_args(dict(state="deleted")) commands = [ 'interface Ethernet1/2', 'lldp receive', 'no lldp tlv-set vlan 12', 'interface Ethernet1/1', 'lldp receive', 'lldp transmit' ] self.execute_module(changed=True, commands=commands)
def test_nxos_acls_merged_idempotent(self): set_module_args( dict(config=[ dict(afi="ipv4", acls=[ dict(name="ACL1v4", aces=[ dict(grant="permit", destination=dict(any=True), source=dict(any=True), sequence=10, protocol="ip"), dict(grant="deny", destination=dict(any=True), source=dict(any=True), sequence=20, protocol="udp") ]), ]), dict(afi="ipv6", acls=[ dict(name="ACL1v6", aces=[ dict( grant="permit", destination=dict(any=True), source=dict(any=True), sequence=10, protocol="sctp", ) ]) ]) ], state="merged")) self.execute_module(changed=False, commands=[])
def test_nxos_static_routes_merged(self): set_module_args( dict( config=[ dict(address_families=[ dict( afi="ipv4", routes=[ dict( dest="192.0.2.32/28", next_hops=[ dict( forward_router_address="192.0.2.40", interface="Ethernet1/2", admin_distance=5, ) ], ) ], ) ]) ], state="merged", )) commands = [ "configure terminal", "ip route 192.0.2.32/28 Ethernet1/2 192.0.2.40 5", ] self.execute_module(changed=True, commands=commands)
def test_nxos_acl_interfaces_replaced(self): set_module_args( dict(config=[ dict(name="Ethernet1/2", access_groups=[ dict(afi="ipv6", acls=[ dict(name="ACL1v6", direction="in", port=True) ]) ]), dict(name="Ethernet1/5", access_groups=[ dict(afi="ipv4", acls=[ dict(name="ACL2v4", direction="in", port=True) ]) ]) ], state="replaced")) commands = [ 'interface Ethernet1/2', 'no ip access-group ACL1v4 out', 'ipv6 port traffic-filter ACL1v6 in', 'interface Ethernet1/5', 'ip port access-group ACL2v4 in' ] self.execute_module(changed=True, commands=commands)
def test_nxos_acls_deletedace(self): set_module_args( dict( config=[ dict( afi="ipv6", acls=[ dict( name="ACL1v6", aces=[ dict( grant="permit", destination=dict(any=True), source=dict(any=True), sequence=10, protocol="sctp", ) ], ) ], ) ], state="deleted", ) ) commands = ["ipv6 access-list ACL1v6", "no 10 permit sctp any any"] self.execute_module(changed=True, commands=commands)
def test_nxos_acls_merged(self): set_module_args( dict(config=[ dict(afi="ipv4", acls=[ dict(name="ACL2v4", aces=[ dict(grant="deny", destination=dict(any=True), source=dict(any=True), fragments=True, sequence=20, protocol="tcp", protocol_options=dict(tcp=dict( ack=True))) ]) ]), dict(afi="ipv6", acls=[dict(name="ACL2v6")]) ], state="merged")) commands = [ 'ip access-list ACL2v4', '20 deny tcp any any ack fragments', 'ipv6 access-list ACL2v6' ] self.execute_module(changed=True, commands=commands)
def test_nxos_acl_interfaces_overridden(self): set_module_args( dict( config=[ dict( name="Ethernet1/3", access_groups=[ dict( afi="ipv4", acls=[ dict(name="ACL2v4", direction="out"), dict( name="PortACL", direction="in", port=True, ), ], ), ], ), ], state="overridden", ), ) commands = [ "interface Ethernet1/2", "no ip access-group ACL1v4 out", "interface Ethernet1/4", "no ipv6 port traffic-filter ACL2v6 in", "interface Ethernet1/3", "ip access-group ACL2v4 out", "ip port access-group PortACL in", ] self.execute_module(changed=True, commands=commands)
def test_nxos_lldp_interfaces_parsed(self): set_module_args( dict( running_config="""interface Ethernet1/1 lldp receive no lldp transmit interface Ethernet1/2 no lldp receive lldp tlv-set vlan 12""", state="parsed", )) result = self.execute_module(changed=False) compare_list = [ { "name": "Ethernet1/1", "receive": True, "transmit": False }, { "name": "Ethernet1/2", "receive": False, "tlv_set": { "vlan": 12 } }, ] self.assertEqual(result["parsed"], compare_list, result["parsed"])
def test_nxos_static_routes_replaced_idempotent(self): set_module_args( dict( config=[ dict( address_families=[ dict( afi="ipv4", routes=[ dict( dest="192.0.2.16/28", next_hops=[ dict( forward_router_address="192.0.2.24", route_name="initial_route", ), ], ), ], ), ], ), ], state="replaced", ), ) self.execute_module(changed=False, commands=[])
def test_nxos_static_routes_overridden(self): set_module_args( dict( config=[ dict(address_families=[ dict( afi="ipv4", routes=[ dict( dest="192.0.2.112/28", next_hops=[ dict( forward_router_address="192.0.2.68", route_name="overridden_route", dest_vrf="end_vrf", ) ], ) ], ) ]) ], state="overridden", )) commands = [ "configure terminal", "no ip route 192.0.2.16/28 192.0.2.24 name initial_route", "ip route 192.0.2.112/28 192.0.2.68 vrf end_vrf name overridden_route", "vrf context test", "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3", "no ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf", ] self.execute_module(changed=True, commands=commands)
def test_nxos_acl_interfaces_merged_idempotent(self): set_module_args( dict( config=[ dict( name="Ethernet1/2", access_groups=[ dict( afi="ipv4", acls=[dict(name="ACL1v4", direction="out")], ), ], ), dict( name="Ethernet1/4", access_groups=[ dict( afi="ipv6", acls=[ dict( name="ACL2v6", direction="in", port=True, ), ], ), ], ), ], state="merged", ), ) self.execute_module(changed=False, commands=[])
def test_nxos_acls_rendered(self): set_module_args( dict( config=[ dict( afi="ipv4", acls=[ dict( name="ACL1v4", aces=[ dict( grant="permit", destination=dict(any=True), source=dict(any=True), sequence=10, protocol="ip", ), dict( grant="deny", destination=dict(any=True), source=dict(any=True), sequence=20, protocol="udp", ), ], ) ], ), dict( afi="ipv6", acls=[ dict( name="ACL1v6", aces=[ dict( grant="permit", destination=dict(any=True), source=dict(any=True), sequence=10, protocol="sctp", ) ], ) ], ), ], state="rendered", ) ) commands = [ "ip access-list ACL1v4", "10 permit ip any any", "20 deny udp any any", "ipv6 access-list ACL1v6", "10 permit sctp any any", ] result = self.execute_module(changed=False) self.assertEqual( sorted(result["rendered"]), sorted(commands), result["rendered"] )
def test_nxos_acl_interfaces_rendered(self): set_module_args( dict(config=[ dict(name="Ethernet1/2", access_groups=[ dict(afi="ipv4", acls=[dict( name="ACL1v4", direction="out", )]) ]), dict(name="Ethernet1/4", access_groups=[ dict(afi="ipv6", acls=[ dict(name="ACL2v6", direction="in", port=True) ]) ]), ], state="rendered")) commands = [ 'interface Ethernet1/2', 'ip access-group ACL1v4 out', 'interface Ethernet1/4', 'ipv6 port traffic-filter ACL2v6 in' ] result = self.execute_module(changed=False) self.assertEqual(sorted(result['rendered']), sorted(commands), result['rendered'])
def test_nxos_acl_interfaces_gathered(self): set_module_args(dict(config=[], state="gathered")) result = self.execute_module(changed=False) compare_list = [ { "access_groups": [ { "acls": [{ "direction": "out", "name": "ACL1v4" }], "afi": "ipv4", }, ], "name": "Ethernet1/2", }, { "access_groups": [ { "acls": [{ "direction": "in", "name": "ACL2v6", "port": True }], "afi": "ipv6", }, ], "name": "Ethernet1/4", }, ] self.assertEqual(result["gathered"], compare_list, result["gathered"])
def test_nxos_static_routes_deletedroute(self): set_module_args( dict( config=[ dict( vrf="test", address_families=[ dict( afi="ipv6", routes=[ dict( dest="2001:db8:12::/32", next_hops=[ dict( forward_router_address= "2001:db8::1001", route_name="ipv6_route", admin_distance=3, ) ], ) ], ) ], ) ], state="deleted", )) commands = [ "vrf context test", "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3", ] self.execute_module(changed=True, commands=commands)
def test_nxos_lldp_interfaces_deleted_intf(self): set_module_args( dict(config=[dict(name="Ethernet1/2")], state="deleted")) commands = [ 'interface Ethernet1/2', 'lldp receive', 'no lldp tlv-set vlan 12' ] self.execute_module(changed=True, commands=commands)
def test_nxos_acls_overridden(self): set_module_args( dict(config=[ dict(afi="ipv4", acls=[ dict(name="ACL2v4", aces=[ dict(grant="permit", destination=dict(host="192.0.2.28"), source=dict(any=True), log=True, sequence=50, protocol="icmp", protocol_options=dict(icmp=dict( administratively_prohibited=True))), dict(remark="Overridden ACL") ]) ]) ], state="overridden")) commands = [ 'no ip access-list ACL1v4', 'no ipv6 access-list ACL1v6', 'ip access-list ACL2v4', '50 permit icmp any host 192.0.2.28 administratively-prohibited log', 'remark Overridden ACL' ] self.execute_module(changed=True, commands=commands)
def test_nxos_static_routes_rendered(self): set_module_args( dict( config=[ dict( vrf="testvrf", address_families=[ dict( afi="ipv6", routes=[ dict( dest="1200:10::/64", next_hops=[ dict( forward_router_address= "2048:ae12::/64", interface="Eth1/4", admin_distance=5, ) ], ) ], ) ], ) ], state="rendered", )) commands = [ "vrf context testvrf", "ipv6 route 1200:10::/64 Ethernet1/4 2048:ae12::/64 5", ] result = self.execute_module(changed=False) self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"])
def test_nxos_acls_replaced(self): set_module_args( dict(config=[ dict(afi="ipv4", acls=[ dict(name="ACL1v4", aces=[ dict(grant="permit", destination=dict(host="192.0.2.28"), source=dict(any=True), log=True, sequence=50, protocol="icmp", protocol_options=dict(icmp=dict( administratively_prohibited=True))) ]) ]) ], state="replaced")) commands = [ 'ip access-list ACL1v4', 'no 20 deny udp any any', 'no 10 permit ip any any', '50 permit icmp any host 192.0.2.28 administratively-prohibited log' ] self.execute_module(changed=True, commands=commands)
def test_nxos_acl_interfaces_gathered(self): set_module_args(dict(config=[], state="gathered")) result = self.execute_module(changed=False) compare_list = [{ 'access_groups': [{ 'acls': [{ 'direction': 'out', 'name': 'ACL1v4' }], 'afi': 'ipv4' }], 'name': 'Ethernet1/2' }, { 'access_groups': [{ 'acls': [{ 'direction': 'in', 'name': 'ACL2v6', 'port': True }], 'afi': 'ipv6' }], 'name': 'Ethernet1/4' }] self.assertEqual(result['gathered'], compare_list, result['gathered'])
def test_nxos_acl_interfaces_parsed(self): set_module_args( dict( running_config= '''interface Ethernet1/2\n ip access-group ACL1v4 out\n interface Ethernet1/4\n \ ipv6 port traffic-filter ACL2v6 in''', state="parsed")) result = self.execute_module(changed=False) compare_list = [{ 'access_groups': [{ 'acls': [{ 'direction': 'out', 'name': 'ACL1v4' }], 'afi': 'ipv4' }], 'name': 'Ethernet1/2' }, { 'access_groups': [{ 'acls': [{ 'direction': 'in', 'name': 'ACL2v6', 'port': True }], 'afi': 'ipv6' }], 'name': 'Ethernet1/4' }] self.assertEqual(result['parsed'], compare_list, result['parsed'])
def test_nxos_static_routes_replaced(self): set_module_args( dict( config=[ dict(address_families=[ dict( afi="ipv4", routes=[ dict( dest="192.0.2.16/28", next_hops=[ dict( forward_router_address="192.0.2.50", tag=12, route_name="replaced_route", ) ], ) ], ) ]) ], state="replaced", )) commands = [ "configure terminal", "no ip route 192.0.2.16/28 192.0.2.24 name initial_route", "ip route 192.0.2.16/28 192.0.2.50 name replaced_route tag 12", ] self.execute_module(changed=True, commands=commands)
def test_nxos_lldp_interfaces_merged_idempotent(self): set_module_args( dict(config=[ dict(name="Ethernet1/2", receive=False, tlv_set=dict(vlan=12)), dict(name="Ethernet1/1", receive=True, transmit=False) ], state="merged")) self.execute_module(changed=False, commands=[])
def test_nxos_static_routes_deletedvrf(self): set_module_args(dict(config=[dict(vrf="test")], state="deleted")) commands = [ "vrf context test", "no ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf", "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3", ] self.execute_module(changed=True, commands=commands)
def test_nxos_acl_interfaces_deletedafi(self): set_module_args( dict(config=[ dict(name="Ethernet1/2", access_groups=[dict(afi="ipv4")]) ], state="deleted")) commands = ['interface Ethernet1/2', 'no ip access-group ACL1v4 out'] self.execute_module(changed=True, commands=commands)
def test_nxos_static_routes_gathered(self): set_module_args(dict(config=[], state="gathered")) result = self.execute_module(changed=False) compare_list = [ { "vrf": "test", "address_families": [ { "routes": [ { "dest": "192.0.2.96/28", "next_hops": [ { "dest_vrf": "dest_vrf", "forward_router_address": "192.0.2.122", }, ], }, ], "afi": "ipv4", }, { "routes": [ { "dest": "2001:db8:12::/32", "next_hops": [ { "route_name": "ipv6_route", "forward_router_address": "2001:db8::1001", "admin_distance": 3, }, ], }, ], "afi": "ipv6", }, ], }, { "address_families": [ { "routes": [ { "dest": "192.0.2.16/28", "next_hops": [ { "route_name": "initial_route", "forward_router_address": "192.0.2.24", }, ], }, ], "afi": "ipv4", }, ], }, ] self.assertEqual(result["gathered"], compare_list, result["gathered"])
def test_nxos_lldp_interfaces_merged(self): set_module_args( dict(config=[ dict(name="Ethernet1/3", receive=False, tlv_set=dict(vlan=123)) ], state="merged")) commands = [ 'interface Ethernet1/3', 'no lldp receive', 'lldp tlv-set vlan 123' ] self.execute_module(changed=True, commands=commands)
def test_nxos_static_routes_deletedafi(self): set_module_args( dict( config=[dict(address_families=[dict(afi="ipv4")])], state="deleted", )) commands = [ "configure terminal", "no ip route 192.0.2.16/28 192.0.2.24 name initial_route", ] self.execute_module(changed=True, commands=commands)
def test_nxos_lldp_interfaces_overridden(self): set_module_args( dict(config=[ dict(name="Ethernet1/4", receive=True, transmit=False) ], state="overridden")) commands = [ 'interface Ethernet1/4', 'lldp receive', 'no lldp transmit', 'interface Ethernet1/1', 'lldp receive', 'lldp transmit', 'interface Ethernet1/2', 'lldp receive', 'no lldp tlv-set vlan 12' ] self.execute_module(changed=True, commands=commands)
def test_nxos_acls_gathered(self): set_module_args(dict(config=[], state="gathered")) result = self.execute_module(changed=False) compare_list = [{ 'acls': [{ 'aces': [{ 'destination': { 'any': True }, 'sequence': 10, 'protocol': 'sctp', 'source': { 'any': True }, 'grant': 'permit' }], 'name': 'ACL1v6' }], 'afi': 'ipv6' }, { 'acls': [{ 'aces': [{ 'destination': { 'any': True }, 'sequence': 10, 'protocol': 'ip', 'source': { 'any': True }, 'grant': 'permit' }, { 'destination': { 'any': True }, 'sequence': 20, 'protocol': 'udp', 'source': { 'any': True }, 'grant': 'deny' }], 'name': 'ACL1v4' }], 'afi': 'ipv4' }] self.assertEqual(result['gathered'], compare_list, result['gathered'])