def setUp(self): dir_name = os.path.dirname(os.path.abspath(__file__)) f, self.jobfile = tempfile.mkstemp() init_runtime(runtime) runtime.configuration.load() runtime.job = Job(jobfile=self.jobfile, runtime=runtime, **runtime.configuration.components.job) mgr = runtime.tasks task = mgr.Task(testscript=os.path.join( dir_name, 'mock_yamls/trigger_datafile.yaml'), taskid='awesome') self.testbed = load( os.path.join(dir_name, 'mock_testbeds/testbed.yaml')) self.mock_testbed_devices() Blitz.parameters = ParameterMap() Blitz.uid = 'test.dev' Blitz.parameters['testbed'] = self.testbed self.blitz_obj = Blitz() self.uid = self.blitz_obj.uid self.blitz_obj.parent = self self.blitz_obj.parent.parameters = mock.Mock() self.dev = Device(name='PE1', os='iosxe') self.dev.custom = {'abstraction': {'order': ['os']}} self.blitz_obj.parameters['test_sections'] = [{ 'section1': [{ 'execute': { 'command': 'cmd', 'device': 'PE1' } }] }] sections = self.blitz_obj._discover() self.kwargs = { 'self': self.blitz_obj, 'testbed': self.testbed, 'section': sections[0].__testcls__(sections[0]), 'name': '' }
def test_vni_lines_confg(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='iosxr') intf1 = Interface(name='nve100', device=dev1, \ aliases=['PE1_1']) # Apply configuration intf1.source_interface = Interface(name='Loopback0', device=dev1) vni = Vni(100, device=dev1) vni.mcast_group = '225.1.1.1 0.0.0.0' intf1.add_vni(vni) # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface nve100', ' member vni 100', ' mcast-group 225.1.1.1 0.0.0.0', ' exit', ' source-interface Loopback0', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={'vnis':None}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface nve100', ' no member vni 100', ' exit' ]))
def test_NveInterface_L2vni_mcast(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') intf1 = Interface(name='nve1', device=dev1) # Defining attributes section intf1.nve_bgp_host_reachability = True intf1.nve_src_intf_loopback = 'Loopback0' intf1.nve_vni = '20000' intf1.nve_vni_mcast_group = '239.1.1.2' intf1.nve_vni_local_routing = True # Build config cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface nve1', ' host-reachability protocol bgp', ' source-interface Loopback0', ' member vni 20000', ' mcast-group 239.1.1.2 local-routing', ' exit', ' exit' ])) # Build unconfig partial_uncfg_1 = intf1.build_unconfig(apply=False, attributes={ 'nve_bgp_host_reachability': True, 'nve_vni': '20000' }) # Check config build correctly self.assertMultiLineEqual( str(partial_uncfg_1), '\n'.join([ 'interface nve1', ' no host-reachability protocol bgp', ' no member vni 20000', ' exit' ])) # Build unconfig partial_uncfg_2 = intf1.build_unconfig( apply=False, attributes={'nve_src_intf_loopback': 'Loopback0'}) # Check config build correctly self.assertMultiLineEqual( str(partial_uncfg_2), '\n'.join( ['interface nve1', ' no source-interface Loopback0', ' exit']))
def test_uncfg_interface(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='nxos') intf1 = Interface(name='Ethernet3/7', device=dev1) intf2 = Interface(name='Vlan100', device=dev1) # vrf = Vrf(name='test', testbed=testbed) # dev1.add_feature(vrf) # make intf2 as L2 interface intf2.mtu = 500 intf1.mtu = 500 # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join(['interface Ethernet3/7', ' mtu 500', ' exit'])) cfgs = intf2.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join(['interface Vlan100', ' mtu 500', ' exit'])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'default interface Ethernet3/7', ])) uncfgs = intf2.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual(str(uncfgs), '\n'.join([ 'no interface Vlan100', ]))
def test_BundleEtherInterface(self): Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxr') lo0 = Interface(device=dev1, name='Loopback0') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2') bundle = Interface(device=dev1, name='Bundle-Ether1') self.assertEqual(bundle.interface_number, 1) bundle.ipv4 = '14.14.14.14/24' bundle.ipv6 = '14:14:14::4/64' intf1.bundle = bundle intf1.bundle_mode = 'active' intf2.bundle = bundle cfg = bundle.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface Bundle-Ether1', ' ipv4 address 14.14.14.14/24', ' ipv6 address 14:14:14::4/64', ' exit', ])) cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/0/1', ' bundle id 1 mode active', ' exit', ])) cfg = intf2.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/0/2', ' bundle id 1', ' exit', ]))
def test_ospf_device_build_config(self): # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') # Create VRF objects vrf0 = Vrf('default') # Create OSPF object ospf1 = Ospf() # Add OSPF configurations to vrf default ospf1.device_attr[dev1].vrf_attr[vrf0].instance = '30' ospf1.device_attr[dev1].vrf_attr[vrf0].pref_all = 115 ospf1.device_attr[dev1].vrf_attr[vrf0].nsr_enable = True # Add OSPF to the device dev1.add_feature(ospf1) # Build config cfgs = dev1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'router ospf 30', ' distance 115', ' nsr', ' exit', ])) # Unconfigure nsr ospf_uncfg = dev1.build_unconfig( apply=False, attributes={ 'ospf': { 'device_attr': { dev1.name: 'vrf_attr__default__nsr_enable', } } }) # Check unconfig strings built correctly self.assertMultiLineEqual( str(ospf_uncfg), '\n'.join([ 'router ospf 30', ' no nsr', ' exit', ]))
def setUp(self): dir_name = os.path.dirname(os.path.abspath(__file__)) self.testbed = load(os.path.join(dir_name, 'mock_testbeds/testbed.yaml')) Blitz.parameters = ParameterMap() Blitz.uid = 'test.dev' Blitz.parameters['testbed'] = self.testbed self.blitz_obj = Blitz() self.uid = self.blitz_obj.uid self.blitz_obj.parent = self self.blitz_obj.parent.parameters = Mock() self.dev = Device( name='PE1', os='iosxe') self.dev.custom = {'abstraction': {'order': ['os']}} self.blitz_obj.parameters['test_sections'] = [{'section1': [{'action': {'command': 'a'}}]}] sections = self.blitz_obj._discover() self.kwargs = {'self': self.blitz_obj, 'section': sections[0], 'name': ''}
def test_port_channel_interface(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='nxos') intf1 = Interface(name='port-channel10', device=dev1) # Apply configuration intf1.channel_group_mode = 'on' intf1.switchport_enable = False intf1.ipv4 = '11.0.1.1/24' intf1.shutdown = False intf1.switchport_enable = False intf1.mtu = 9111 uut1_int3 = Interface(name='Ethernet0/0/1', device=dev1) intf1.add_member(uut1_int3) # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet0/0/1', ' channel-group 10 mode on', ' exit', 'interface port-channel10', ' mtu 9111', ' no shutdown', ' no switchport', ' ip address 11.0.1.1 255.255.255.0', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface Ethernet0/0/1', ' no channel-group 10 mode on', ' exit', 'no interface port-channel10' ]))
def test_port_channel_interface_trunk_vlans(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='nxos') intf1 = Interface(name='port-channel10', device=dev1) # Apply configuration intf1.channel_group_mode = 'active' intf1.enabled = True intf1.switchport_enable = True intf1.switchport_mode = 'trunk' intf1.trunk_vlans = "2-5,11-105,111-205" uut1_int3 = Interface(name='Ethernet0/0/1', device=dev1) intf1.add_member(uut1_int3) # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet0/0/1', ' channel-group 10 mode active', ' exit', 'interface port-channel10', ' no shutdown', ' switchport', ' switchport mode trunk', ' switchport trunk allowed vlan 2-5,11-105,111-205', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface Ethernet0/0/1', ' no channel-group 10 mode active', ' exit', 'no interface port-channel10' ]))
def _api_device_update(arguments, testbed, step, command, device=None, common_api=None): """ Updating the device obj with regards to the user input 1) Allow user to both provide device in the body and arguments of the action 2) Allow user to provide device value in either body or arguments of the action 3) Allow user to provide no device for api's that are common utils """ # if api and arguments both contains device, need to make sure # that the device in the arguments is as same as the one in api if arguments.get('device') and device: if arguments.get('device') != device.name and\ arguments.get('device') != device.alias: step.errored('Device provided in the arguments {} ' 'is not as same as the one provided in api {}' .format(arguments['device'], device)) if device: return device # if not device in api and arguments contains device need to make sure # that device is a valid one and exist in the testbed if arguments.get('device'): try: arg_device = testbed.devices[arguments['device']] except KeyError as e: step.errored('Cannot find device {} in testbed'.format( arguments['device'])) arguments['device'] = arg_device return arg_device # if common api if common_api: return Device(name='a', os='', custom={'abstraction':{'order': ['os']}}) step.errored("No device is provided and the api '{}'" "is not a common api".format(command))
def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='iosxr') # Interface self.intf1 = Interface(name='GigabitEthernet0/0/0/1', device=self.dev1) self.intf1.shutdown = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/1', ' no shutdown', ' exit', ]))
def test_remove_af(self): # Add a device to it tb = Genie.testbed = Testbed() dev1 = Device(testbed=tb, name='dev1', os='nxos') dev2 = Device(testbed=tb, name='dev2', os='nxos') rip = Rip(instance_id=5) rip.add_force_vrf(None) dev1.add_feature(rip) dev2.add_feature(rip) # Configure rip rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].distance = 5 output = rip.build_config(apply=False) self.assertMultiLineDictEqual(output, {'dev1': 'feature rip\n' 'router rip 5\n' ' address-family ipv4 unicast\n' ' distance 5\n' ' exit\n' ' exit', 'dev2': 'feature rip\n' 'router rip 5\n' ' address-family ipv4 unicast\n' ' exit\n' ' exit'}) output = rip.build_unconfig( attributes={ 'device_attr': { 'dev1': { 'vrf_attr': { None: { 'address_family_attr': { 'ipv4 unicast': None}}}}}}, apply=False) self.assertMultiLineDictEqual(output, {'dev1': 'router rip 5\n no address-family ipv4 unicast\n exit'})
def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='nxos') # Interface self.intf1 = Interface(name='Ethernet2/1', device=self.dev1) self.intf1.enabled = True self.intf1.switchport_enable = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet2/1', ' no shutdown', ' no switchport', ' exit', ]))
def test_vxlan_interface(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') intf1 = Interface(name='Ethernet0/0/1', device=dev1) # Defining attributes section intf1.evpn_multisite_fabric_tracking = True intf1.evpn_multisite_dci_tracking = True intf1.fabric_forwarding_mode = 'anycast-gateway' intf1.ip_forward = True intf1.ipv6_addr_use_link_local_only = True cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface Ethernet0/0/1', ' evpn multisite dci-tracking', ' evpn multisite fabric-tracking', ' fabric forwarding mode anycast-gateway', ' ip forward', ' ipv6 address use-link-local-only', ' exit', ])) partial_uncfg = intf1.build_unconfig( apply=False, attributes={ "evpn_multisite_fabric_tracking": True, "evpn_multisite_dci_tracking": True, "ip_forward": True }) self.assertMultiLineEqual( str(partial_uncfg), '\n'.join([ 'interface Ethernet0/0/1', ' no evpn multisite dci-tracking', ' no evpn multisite fabric-tracking', ' no ip forward', ' exit', ]))
def test_EthernetInterface(self): Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1') intf1.ipv4 = '1.2.3.4/32' intf1.auto_negotiation = True cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' ip address 1.2.3.4 255.255.255.255', ' negotiation auto', ' exit', ])) uncfg = intf1.build_unconfig(apply=False) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'default interface GigabitEthernet0/0/1', 'interface GigabitEthernet0/0/1', 'shutdown', ])) partial_uncfg1 = intf1.build_unconfig(apply=False, attributes="auto_negotiation") self.assertMultiLineEqual( str(partial_uncfg1), '\n'.join([ 'interface GigabitEthernet0/0/1', ' default negotiation auto', ' exit', ])) partial_uncfg2 = intf1.build_unconfig(apply=False, attributes="ipv4") self.assertMultiLineEqual( str(partial_uncfg2), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no ip address 1.2.3.4 255.255.255.255', ' exit', ]))
def test_disable_no_instance(self): tb = Genie.testbed = Testbed() dev = Device(testbed=tb, name='PE1', os='nxos') rip = Rip(instance_id=1) rip.add_force_vrf(None) dev.add_feature(rip) # Default configuration, let's make sure it works output = rip.build_unconfig(unconfig_feature=True, apply=False) self.assertMultiLineDictEqual(output, {'PE1': 'no feature rip'}) # Set a mock dev.cli = Mock() dev.configure = Mock() output = rip.build_unconfig(unconfig_feature=True, apply=True) expected_output = None self.assertEqual(output, expected_output)
def test_static_routing_ipv6_with_interface_cfg(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') static_routing = StaticRouting() interface = 'GigabitEthernet0/1' vrf = 'VRF1' af = 'ipv6' route = '{}'.format('2001:2:2:2::2/128') static_routing.device_attr[dev1].vrf_attr[vrf].address_family_attr[ af].route_attr[route].interface_attr[ interface].if_nexthop = '2001:20:1:2::2' self.assertIs(static_routing.testbed, testbed) dev1.add_feature(static_routing) cfgs = static_routing.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.maxDiff = None self.assertEqual( str(cfgs[dev1.name]), '\n'.join([ 'ipv6 route vrf VRF1 2001:2:2:2::2/128 GigabitEthernet0/1 2001:20:1:2::2' ])) static_routing_2 = StaticRouting() static_routing_2.device_attr[dev1].vrf_attr[ 'default'].address_family_attr['ipv6'].route_attr[ '2001:2:2:2::2/128'].interface_attr['Null0'].if_preference = 5 self.assertIs(static_routing_2.testbed, testbed) dev1.add_feature(static_routing_2) cfgs = static_routing_2.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.maxDiff = None self.assertEqual(str(cfgs[dev1.name]), '\n'.join(['ipv6 route 2001:2:2:2::2/128 Null0 5']))
def test_static_routing_with_interface_cfg(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') static_routing = StaticRouting() static_routing.device_attr[dev1].vrf_attr['VRF1'].address_family_attr[ 'ipv4'].route_attr['10.2.1.0/24'].interface_attr[ 'GigabitEthernet0/1'].if_nexthop = '192.168.1.2' static_routing.device_attr[dev1].vrf_attr['VRF1'].address_family_attr[ 'ipv4'].route_attr['10.2.1.0/24'].interface_attr[ 'GigabitEthernet0/1'].if_preference = 2 self.assertIs(static_routing.testbed, testbed) dev1.add_feature(static_routing) cfgs = static_routing.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.maxDiff = None self.assertEqual( str(cfgs[dev1.name]), '\n'.join([ 'ip route vrf VRF1 10.2.1.0 255.255.255.0 GigabitEthernet0/1 192.168.1.2 2' ])) static_routing_4 = StaticRouting() static_routing_4.device_attr[dev1].vrf_attr[ 'default'].address_family_attr['ipv4'].route_attr[ '3.3.3.3/32'].interface_attr['GigabitEthernet0/3'] self.assertIs(static_routing_4.testbed, testbed) dev1.add_feature(static_routing_4) cfgs = static_routing_4.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.maxDiff = None self.assertEqual( str(cfgs[dev1.name]), '\n'.join(['ip route 3.3.3.3 255.255.255.255 GigabitEthernet0/3']))
def test_basic_uncfg(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') rpl1 = RoutePolicy(policy_definition='rpl1') dev1.add_feature(rpl1) rpl1.device_attr[dev1].statement_attr['10'] rpl1.device_attr[dev1].statement_attr['10'].match_med_eq = 5 rpl1.device_attr[dev1].statement_attr['10'].match_nexthop_in = 'hop' rpl1.device_attr[dev1].statement_attr['10'].actions = 'pass' # Unconfig testing # Set a mock dev1.configure = Mock() dev1.add_feature(rpl1) # Mock config uncfg1 = rpl1.build_unconfig(apply=False) self.assertCountEqual(uncfg1.keys(), ['PE1']) self.assertMultiLineEqual(str(uncfg1['PE1']), '\n'.join( ['no route-policy rpl1' ]))
def test_uncfg(self): tb = Genie.testbed = Testbed() dev = Device(testbed=tb, name='PE1', os='nxos') rip = Rip(instance_id=1) rip.add_force_vrf(None) # Default configuration, let's make sure it works output = rip.build_unconfig(apply=False) # There was nothing to unconfigure self.assertMultiLineDictEqual(output, {}) dev.add_feature(rip) output = rip.build_unconfig(apply=False) self.assertMultiLineDictEqual(output, {'PE1': 'feature rip\nno router rip 1'}) # Set a mock dev.cli = Mock() dev.configure = Mock() output = rip.build_unconfig(apply=True) expected_output = None self.assertEqual(output, expected_output)
def test_EthernetInterface(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') dev2 = Device(testbed=testbed, name='P1', os='nxos') intf1 = Interface(name='Ethernet0/0/1', device=dev1) intf2 = Interface(name='Ethernet0/0/2', device=dev2) # Defining attributes section intf1.ipv4 = '201.0.12.1' intf1.ipv4.netmask = '255.255.255.0' intf1.speed = 1000 intf1.shutdown = False # make intf1 as L3 interface intf1.switchport_enable = False intf1.mtu = 500 intf1.ipv6 = '2001::12:1' cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface Ethernet0/0/1', ' mtu 500', ' no shutdown', ' no switchport', ' ip address 201.0.12.1 255.255.255.0', ' ipv6 address 2001::12:1/128', ' speed 1000', ' exit', ])) uncfg = intf1.build_unconfig(apply=False, attributes={ 'ipv6': True, 'ipv4': True }) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface Ethernet0/0/1', ' no ip address', ' no ipv6 address', ' exit', ])) partial_uncfg = intf1.build_unconfig(apply=False, attributes="mtu") self.assertMultiLineEqual( str(partial_uncfg), '\n'.join([ 'interface Ethernet0/0/1', ' no mtu', ' exit', ])) # make intf2 as L2 interface intf2.switchport_enable = True intf2.switchport_mode = L2_type.TRUNK intf2.sw_trunk_allowed_vlan = '200-201' cfg2 = intf2.build_config(apply=False) self.assertMultiLineEqual( str(cfg2), '\n'.join([ 'interface Ethernet0/0/2', ' switchport', ' switchport mode trunk', ' switchport trunk allowed vlan 200-201', ' exit', ]))
def test_init(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/2') dev2 = Device(testbed=testbed, name='PE2', os='iosxe') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/3') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/4') link1 = Link(testbed=testbed, name='link1', interfaces=(intf1, intf3)) link2 = Link(testbed=testbed, name='link2', interfaces=(intf2, intf4)) with self.assertRaises(TypeError): xc1 = Xconnect() xc1 = Xconnect(name='xc1') self.assertIs(xc1.xconnect_type, Xconnect.Type.p2p) self.assertEqual(xc1.name, 'xc1') self.assertCountEqual(xc1.devices, []) self.assertCountEqual(xc1.interfaces, []) self.assertCountEqual(xc1.segments, []) self.assertCountEqual(xc1.link.interfaces, []) dev1.add_feature(xc1) self.assertCountEqual(xc1.devices, [dev1]) self.assertCountEqual(xc1.interfaces, []) self.assertCountEqual(xc1.segments, []) self.assertCountEqual(xc1.link.interfaces, []) cfgs = xc1.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'l2vpn xconnect context xc1', ' exit', ])) efp = Interface(device=dev1, name='GigabitEthernet0/0/1.20', service_instance=20) efp.encapsulation = 'dot1q' efp.rewrite_ingress = 'pop 1 symmetric' xc1.add_segment(efp) self.assertCountEqual(xc1.interfaces, [efp]) self.assertCountEqual(xc1.devices, [dev1]) self.assertCountEqual(xc1.segments, [efp]) self.assertCountEqual(xc1.device_attr[dev1].interfaces, [efp]) self.assertCountEqual(xc1.device_attr[dev2].interfaces, []) self.assertCountEqual(xc1.device_attr[dev1].segments, [efp]) self.assertCountEqual(xc1.device_attr[dev2].segments, []) cfgs = xc1.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'l2vpn xconnect context xc1', ' member GigabitEthernet0/0/1 service-instance 20', ' exit', ]))
def test_single_line_config(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='nxos') intf1 = Interface(name='Ethernet3/7', device=dev1, aliases=['PE1_1']) intf2 = Interface(name='Ethernet3/9', device=dev1, aliases=['PE1_2']) subif1 = Interface(name='Ethernet3/6.10', device=dev1, aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'test' intf1.enabled = False # intf1.shutdown = False intf1.link_up_down_trap_enable = True intf1.mtu = 1492 intf1.vrf = vrf intf1.mac_address = 'aabb.ccdd.eeff' intf1.bandwidth = 8192 intf1.link_status = True intf1.load_interval = 33 intf1.dhcp = True intf1.unnumbered_intf_ref = 'Ethernet3/6.10' intf1.ipv6_autoconf = True intf1.switchport_mode = 'access' intf1.medium = 'p2p' intf1.delay = 11 intf1.access_vlan = '19' intf1.auto_negotiate = False # make intf2 as L2 interface intf1.switchport_enable = True intf2.enabled = True intf2.switchport_enable = True intf2.switchport_mode = 'trunk' intf2.trunk_add_vlans = '1,2,3' # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/7', ' medium p2p', ' bandwidth 8192', ' delay 11', ' description test', ' mtu 1492', ' shutdown', ' snmp trap link-status', ' vrf member test', ' logging event port link-status', ' ip address dhcp', ' ip unnumbered Ethernet3/6.10', ' ipv6 address autoconfig', ' switchport', ' switchport mode access', ' load-interval 33', ' mac-address aabb.ccdd.eeff', ' switchport access vlan 19', ' no speed', ' no duplex', ' exit' ])) cfgs = intf2.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/9', ' no shutdown', ' switchport', ' switchport mode trunk', ' switchport trunk allowed vlan add 1,2,3', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={ 'mtu': True, 'enabled': True }) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join( ['interface Ethernet3/7', ' no mtu', ' no shutdown', ' exit'])) uncfgs = intf2.build_unconfig(apply=False, attributes={'trunk_add_vlans': True}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface Ethernet3/9', ' switchport trunk allowed vlan remove 1,2,3', ' exit' ]))
def test_ospfv3_non_default_vrf_config(self): # For failures self.maxDiff = None # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') # Create VRF objects vrf1 = Vrf('VRF1') # Create Interface object intf1 = Interface(name='Ethernet1/1', device=dev1) # Create OSPF object ospfv3_1 = Ospfv3() ospfv3_1.device_attr[dev1].enabled = True # Add OSPF configuration to vrf VRF1 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].instance = '30' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].inst_shutdown = False ospfv3_1.device_attr[dev1].vrf_attr[vrf1].router_id = '3.3.3.3' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].passive_interface = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].log_adjacency_changes = True ospfv3_1.device_attr[dev1].vrf_attr[ vrf1].log_adjacency_changes_detail = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_arrival = 30 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_group_pacing = 40 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_start_time = 50 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_hold_time = 60 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_max_time = 70 # Add graceful restart configuration to vrf default gr1 = GracefulRestart(device=dev1) gr1.gr_enable = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr1) # Add graceful restart configuration to vrf default gr2 = GracefulRestart(device=dev1) gr2.gr_enable = True gr2.gr_restart_interval = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr2) # # Add graceful restart configuration to vrf default gr3 = GracefulRestart(device=dev1) gr3.gr_enable = True gr3.gr_helper_enable = False ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr3) # # Add graceful restart configuration to vrf default gr4 = GracefulRestart(device=dev1) gr4.gr_enable = True gr4.gr_planned_only = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr4) # Add area configuration to vrf default ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].area_type = 'stub' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].nosummary = False # Add area configuration to vrf default ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].area_type = 'nssa' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nosummary = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nssa_default_info_originate = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nssa_route_map = 'test_route_map' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nssa_translate_always = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nssa_translate_supressfa = True # address_family attributes ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].default_metric = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_bgp_id = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_bgp_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_rip_id = 'rip-nxos' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_rip_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_direct = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_direct_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_static = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_static_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_isis_id = 'ABC' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_isis_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].default_originate = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].default_originate_routemap = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_max_prefix = 12 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_max_prefix_thld = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_max_prefix_warn_only = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].spf_start_time = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].spf_hold_time = 200 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].spf_max_time = 300 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].table_map = 'test' # Add area default cost configuration to vrf default ad1 = AreaDefaultCost(device=dev1) ad1.af_area_id = '2' ad1.area_def_cost = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_areacost_key(ad1) # # Add area routemap direction to vrf default arm1 = AreaRouteMap(device=dev1) arm1.routemap_area_id = '2' arm1.ar_route_map_in = 'test_in' arm1.ar_route_map_out = 'test_out' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_arearoutemap_key(arm1) # Add summary address configuration to vrf default sa1 = SummaryAddress(device=dev1) sa1.summary_address_prefix = '2001:db1:1::1/64' sa1.summary_address_not_advertise = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_sumadd_key(sa1) # Add summary address configuration to vrf default sa2 = SummaryAddress(device=dev1) sa2.summary_address_prefix = '2001:db2:2::2/64' sa2.summary_address_tag = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_sumadd_key(sa2) # Add area range configuration to vrf default ar1 = AreaRange(device=dev1) ar1.range_area_id = '2' ar1.area_range_prefix = '2001:bd12:2::2/64' ar1.area_range_not_advertise = True ar1.area_range_cost = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_arearange_key(ar1) # virtual link attributes ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_router_id = '7.7.7.7' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_hello_interval = 55 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_dead_interval = 65 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_retransmit_interval = 75 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_transmit_delay = 85 # Add interface configuration to VRF default ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_admin_control = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_secondaries = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_cost = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_type = 'point-to-point' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_passive = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_priority = 110 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_hello_interval = 50 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_dead_interval = 60 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_retransmit_interval = 70 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_transmit_delay = 70 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_mtu_ignore = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_instance = 60 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_protocol_shutdown = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_multi_area = 10 dev1.add_feature(ospfv3_1) # Build config cfgs = ospfv3_1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'feature ospfv3', 'router ospfv3 30', ' vrf VRF1', ' router-id 3.3.3.3', ' passive-interface default', ' log-adjacency-changes detail', ' timers lsa-arrival 30', ' timers lsa-group-pacing 40', ' timers throttle lsa 50 60 70', ' graceful-restart', ' graceful-restart grace-period 100', ' graceful-restart helper-disable', ' graceful-restart planned-only', ' address-family ipv6 unicast', ' default-information originate True route-map test', ' default-metric 100', ' redistribute bgp 100 route-map test', ' redistribute direct route-map test', ' redistribute static route-map test', ' redistribute isis ABC route-map test', ' redistribute rip rip-nxos route-map test', ' redistribute maximum-prefix 12 10 warning-only', ' table-map test', ' timers throttle lsa 100 200 300', ' area 2 default-cost 10', ' area 2 filter-list route-map test_in in', ' area 2 filter-list route-map test_out out', ' summary-address 2001:db1:1::1/64 not-advertise', ' summary-address 2001:db2:2::2/64 tag 10', ' area 2 range 2001:bd12:2::2/64 not-advertise cost 10', ' exit', ' area 1 stub', ' area 2 nssa no-summary default-information-originate route-map test_route_map', ' area 2 nssa translate type7 always suppress-fa', ' area 7 virtual-link 7.7.7.7', ' hello-interval 55', ' dead-interval 65', ' retransmit-interval 75', ' transmit-delay 85', ' exit', ' exit', ' exit', 'interface Ethernet1/1', ' ipv6 router ospfv3 30 area 0', ' ospfv3 cost 10', ' ospfv3 network point-to-point', ' ospfv3 passive-interface', ' ospfv3 priority 110', ' ospfv3 hello-interval 50', ' ospfv3 dead-interval 60', ' ospfv3 retransmit-interval 70', ' ospfv3 mtu-ignore', ' ospfv3 instance 60', ' ospfv3 shutdown', ' ospfv3 transmit-delay 70', ' ipv6 router ospfv3 30 multi-area 10', ' exit' ])) # Unconfig ospfv3_uncfg = ospfv3_1.build_unconfig(apply=False) # Check unconfig strings built correctly self.assertMultiLineEqual(str(ospfv3_uncfg[dev1.name]), '\n'.join([ 'no feature ospfv3', ]))
def test_ospfv3_partial_config_unconfig(self): # For failures self.maxDiff = None # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') # Create VRF objects vrf1 = Vrf('VRF1') # Create Interface object intf1 = Interface(name='Ethernet1/1', device=dev1) # Create OSPF object ospfv3_1 = Ospfv3() ospfv3_1.device_attr[dev1].enabled = True # Add OSPF configuration to vrf default ospfv3_1.device_attr[dev1].vrf_attr[vrf1].instance = '30' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].inst_shutdown = False ospfv3_1.device_attr[dev1].vrf_attr[vrf1].router_id = '3.3.3.3' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].passive_interface = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].log_adjacency_changes = True ospfv3_1.device_attr[dev1].vrf_attr[ vrf1].log_adjacency_changes_detail = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_arrival = 30 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_group_pacing = 40 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_start_time = 50 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_hold_time = 60 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_max_time = 70 # Add graceful restart configuration to vrf vrf1 gr1 = GracefulRestart(device=dev1) gr1.gr_enable = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr1) # Add graceful restart configuration to vrf vrf1 gr2 = GracefulRestart(device=dev1) gr2.gr_enable = True gr2.gr_restart_interval = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr2) # # Add graceful restart configuration to vrf vrf1 gr3 = GracefulRestart(device=dev1) gr3.gr_enable = True gr3.gr_helper_enable = False ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr3) # # Add graceful restart configuration to vrf vrf1 gr4 = GracefulRestart(device=dev1) gr4.gr_enable = True gr4.gr_planned_only = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr4) # Add area configuration to vrf vrf1 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].area_type = 'stub' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].nosummary = True # Add summary address configuration to vrf vrf1 sa2 = SummaryAddress(device=dev1) sa2.summary_address_prefix = '2001:db2:2::2/64' sa2.summary_address_tag = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_sumadd_key(sa2) dev1.add_feature(ospfv3_1) # Build config cfgs = ospfv3_1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'feature ospfv3', 'router ospfv3 30', ' vrf VRF1', ' router-id 3.3.3.3', ' passive-interface default', ' log-adjacency-changes detail', ' timers lsa-arrival 30', ' timers lsa-group-pacing 40', ' timers throttle lsa 50 60 70', ' graceful-restart', ' graceful-restart grace-period 100', ' graceful-restart helper-disable', ' graceful-restart planned-only', ' address-family ipv6 unicast', ' summary-address 2001:db2:2::2/64 tag 10', ' exit', ' area 1 stub no-summary', ' exit', ' exit' ])) # change partial config - router_id ospfv3_1.device_attr[dev1].vrf_attr[vrf1].router_id = '7.7.7.7' partial_cfg1 = ospfv3_1.build_config(apply=False, attributes={ 'device_attr': { '*': { 'vrf_attr': { '*': "router_id" } } } }) self.assertCountEqual(partial_cfg1.keys(), [dev1.name]) self.assertMultiLineEqual( str(partial_cfg1[dev1.name]), '\n'.join([ 'router ospfv3 30', ' vrf VRF1', ' router-id 7.7.7.7', ' exit', ' exit', ])) # remove cfg - area 1 stub partial_uncfg1 = ospfv3_1.build_unconfig(apply=False, attributes={ 'device_attr': { '*': { 'vrf_attr': { '*': "lsa_arrival" } } } }) self.assertMultiLineEqual( str(partial_uncfg1[dev1.name]), '\n'.join([ 'router ospfv3 30', ' vrf VRF1', ' no timers lsa-arrival 30', ' exit', ' exit', ])) # # remove a single attribute from a specific gr key partial_uncfg2 = ospfv3_1.build_unconfig( apply=False, attributes={ 'device_attr': { '*': { 'vrf_attr': { '*': { 'gr_keys': { gr4: { 'gr_enable': None } } } } } } }) self.assertMultiLineEqual( str(partial_uncfg2[dev1.name]), '\n'.join([ 'router ospfv3 30', ' vrf VRF1', ' no graceful-restart', ' exit', ' exit', ])) # remove all grace full restart multiline configs partial_uncfg3 = ospfv3_1.build_unconfig( apply=False, attributes={'device_attr': { '*': { 'vrf_attr': { '*': 'gr_keys' } } }}) self.assertMultiLineEqual( str(partial_uncfg3[dev1.name]), '\n'.join([ 'router ospfv3 30', ' vrf VRF1', ' no graceful-restart', ' no graceful-restart grace-period 100', ' no graceful-restart helper-disable', ' no graceful-restart planned-only', ' exit', ' exit', ]))
def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='nxos')
class test_prefix_list(TestCase): def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='nxos') def test_cli_config_v4(self): # prefix-list conf prefix_conf = PrefixList(prefix_set_name='test') self.dev1.add_feature(prefix_conf) # Apply configuration prefix_conf.device_attr[self.dev1].prefix_attr['35.0.0.0/8'].\ maxlength_range_attr['8..8'].protocol = 'ipv4' prefix_conf.device_attr[self.dev1].prefix_attr['35.0.0.0/8'].\ maxlength_range_attr['8..16'].protocol = 'ipv4' prefix_conf.device_attr[self.dev1].prefix_attr['37.0.0.0/8'].\ maxlength_range_attr['16..24'].protocol = 'ipv4' prefix_conf.device_attr[self.dev1].prefix_attr['38.0.0.0/8'].\ maxlength_range_attr['16..32'].protocol = 'ipv4' prefix_conf.device_attr[self.dev1].prefix_attr['2001:DB8:4::/64']\ .maxlength_range_attr['65..98'].protocol = 'ipv6' # Build config cfgs = prefix_conf.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'ipv6 prefix-list test permit 2001:DB8:4::/64 ge 65 le 98', 'ip prefix-list test permit 35.0.0.0/8 le 16', 'ip prefix-list test permit 35.0.0.0/8', 'ip prefix-list test permit 37.0.0.0/8 ge 16 le 24', 'ip prefix-list test permit 38.0.0.0/8 ge 16', ])) # Build unconfig cfgs = prefix_conf.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no ipv6 prefix-list test permit 2001:DB8:4::/64 ge 65 le 98', 'no ip prefix-list test permit 35.0.0.0/8 le 16', 'no ip prefix-list test permit 35.0.0.0/8', 'no ip prefix-list test permit 37.0.0.0/8 ge 16 le 24', 'no ip prefix-list test permit 38.0.0.0/8 ge 16', ])) def test_cli_config_v6(self): # prefix-list conf prefix_conf_v6 = PrefixList(prefix_set_name='test6') prefix_conf_v6.device_attr[self.dev1].prefix_attr['2001:DB8:1::/64']\ .maxlength_range_attr['64..64'].protocol = 'ipv6' prefix_conf_v6.device_attr[self.dev1].prefix_attr['2001:DB8:2::/64']\ .maxlength_range_attr['65..128'].protocol = 'ipv6' prefix_conf_v6.device_attr[self.dev1].prefix_attr['2001:DB8:3::/64']\ .maxlength_range_attr['64..128'].protocol = 'ipv6' prefix_conf_v6.device_attr[self.dev1].prefix_attr['2001:DB8:4::/64']\ .maxlength_range_attr['65..98'].protocol = 'ipv6' # Build config cfgs = prefix_conf_v6.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'ipv6 prefix-list test6 permit 2001:DB8:1::/64', 'ipv6 prefix-list test6 permit 2001:DB8:2::/64 ge 65', 'ipv6 prefix-list test6 permit 2001:DB8:3::/64 le 128', 'ipv6 prefix-list test6 permit 2001:DB8:4::/64 ge 65 le 98', ])) # Build unconfig cfgs = prefix_conf_v6.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no ipv6 prefix-list test6 permit 2001:DB8:1::/64', 'no ipv6 prefix-list test6 permit 2001:DB8:2::/64 ge 65', 'no ipv6 prefix-list test6 permit 2001:DB8:3::/64 le 128', 'no ipv6 prefix-list test6 permit 2001:DB8:4::/64 ge 65 le 98', ]))
def test_learn_config(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') dev1.custom = {'abstraction':{'order':['os'], 'context':'cli'}} dev2 = Device(testbed=testbed, name='PE2', os='nxos') golden_output = {'return_value': ''' pinxdt-n9kv-3# show run bgp !Command: show running-config bgp !Time: Wed Jun 28 06:23:27 2017 version 7.0(3)I7(1) feature bgp router bgp 333 dynamic-med-interval 70 shutdown cluster-id 3 no graceful-restart flush-routes isolate disable-policy-batching ipv4 prefix-list s no enforce-first-as event-history objstore size large address-family ipv4 multicast dampening 1 10 30 2 redistribute static route-map PERMIT_ALL_RM address-family ipv6 multicast dampening 1 10 30 2 redistribute static route-map PERMIT_ALL_RM address-family ipv6 unicast dampening 1 10 30 2 redistribute static route-map PERMIT_ALL_RM inject-map ORIGINATE_IPV6 exist-map INJECTED_IPV6 copy-attributes nexthop route-map test address-family vpnv4 unicast dampening route-map PASS-ALL nexthop trigger-delay critical 4 non-critical 5 address-family vpnv6 unicast dampening 1 10 30 2 address-family ipv4 labeled-unicast template peer-session PEER-SESSION ebgp-multihop 3 neighbor fec1::1002 remote-as 333 address-family ipv4 unicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always neighbor fec1::2002 remote-as 888 address-family ipv4 unicast send-community send-community extended soft-reconfiguration inbound always address-family ipv6 multicast send-community send-community extended soft-reconfiguration inbound always address-family ipv6 unicast send-community send-community extended soft-reconfiguration inbound always neighbor 4.4.4.4 capability suppress 4-byte-as address-family vpnv6 unicast send-community send-community extended soft-reconfiguration inbound always maximum-prefix 300000 neighbor 21.0.101.1 remote-as 333 address-family ipv4 multicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always address-family ipv4 unicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always address-family ipv6 multicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always address-family ipv6 unicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always address-family vpnv4 unicast send-community send-community extended route-reflector-client address-family vpnv6 unicast send-community send-community extended route-reflector-client neighbor 21.0.102.1 remote-as 333 update-source loopback0 address-family ipv4 multicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always address-family ipv4 unicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always address-family ipv6 multicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always address-family ipv6 unicast send-community send-community extended route-reflector-client soft-reconfiguration inbound always address-family vpnv4 unicast send-community send-community extended address-family vpnv6 unicast send-community send-community extended route-reflector-client neighbor 21.0.201.1 remote-as 888 address-family ipv4 multicast send-community send-community extended soft-reconfiguration inbound always address-family ipv4 unicast send-community send-community extended soft-reconfiguration inbound always address-family ipv6 multicast send-community send-community extended soft-reconfiguration inbound always address-family ipv6 unicast send-community send-community extended soft-reconfiguration inbound always address-family vpnv4 unicast send-community send-community extended address-family vpnv6 unicast send-community send-community extended vrf ac bestpath always-compare-med address-family ipv4 unicast neighbor 2.2.2.2 bfd local-as 222 description ja remove-private-as disable-connected-check capability suppress 4-byte-as address-family ipv4 unicast allowas-in 3 send-community send-community extended maximum-prefix 2 vrf management neighbor 5.5.5.5 password 3 386c0565965f89de vrf vpn1 address-family ipv4 multicast redistribute static route-map PERMIT_ALL_RM address-family ipv4 unicast dampening 1 10 30 2 redistribute static route-map PERMIT_ALL_RM address-family ipv6 multicast dampening 1 10 30 2 redistribute static route-map PERMIT_ALL_RM address-family ipv6 unicast dampening 1 10 30 2 redistribute static route-map PERMIT_ALL_RM vrf context vpn1 rd 1:100 address-family ipv4 unicast route-target import 100:1 route-target export 100:1 route-target export 400:400 export map PERMIT_ALL_RM import map PERMIT_ALL_RM import vrf default map PERMIT_ALL_RM export vrf default map PERMIT_ALL_RM address-family ipv6 unicast route-target import 1:100 route-target export 1:100 route-target export 600:600 export map PERMIT_ALL_RM import map PERMIT_ALL_RM import vrf default map PERMIT_ALL_RM export vrf default map PERMIT_ALL_RM vrf context vpn2 rd 2:100 address-family ipv4 unicast route-target import 400:400 address-family ipv6 unicast route-target import 600:600 '''} bgp = Bgp(asn=333, bgp_id=333) dev1.execute = Mock(**golden_output) bgp.device_attr[dev1] bgp.device_attr[dev1].enabled = True bgp.device_attr[dev1].vrf_attr[None].cluster_id = '3' af_name = 'ipv6 unicast' bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name] bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_nexthop_route_map = 'test' neighbor_id = '4.4.4.4' bgp.device_attr[dev1].vrf_attr[None].add_neighbor(neighbor_id) bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ nbr_suppress_four_byte_as_capability = True nbr_af_name = 'vpnv6 unicast' bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name] bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name].\ nbr_af_maximum_prefix_max_prefix_no = 300000 cfgs = bgp.build_config(apply=False) # List of BGP conf objects representing the different instances # For NXOS, it is only one. learn = Bgp.learn_config(device=dev1) # Testing cluster_id self.assertEqual(learn[0].device_attr[dev1].vrf_attr['default'].\ cluster_id,bgp.device_attr[dev1].vrf_attr['default'].cluster_id) # Testing af_nexthop_route_map self.assertEqual(learn[0].device_attr[dev1].vrf_attr['default'].\ address_family_attr['ipv6 unicast'].af_nexthop_route_map, bgp.device_attr[dev1].vrf_attr['default'].address_family_attr\ ['ipv6 unicast'].af_nexthop_route_map) # Testing nbr_suppress_four_byte_as_capability self.assertEqual(learn[0].device_attr[dev1].vrf_attr['default'].\ neighbor_attr['4.4.4.4'].nbr_suppress_four_byte_as_capability, bgp.device_attr[dev1].vrf_attr['default'].neighbor_attr['4.4.4.4']\ .nbr_suppress_four_byte_as_capability) # Testing nbr_af_maximum_prefix_max_prefix_no self.assertEqual(learn[0].device_attr[dev1].vrf_attr['default'].\ neighbor_attr['4.4.4.4'].address_family_attr[nbr_af_name].\ nbr_af_maximum_prefix_max_prefix_no, bgp.device_attr[dev1].\ vrf_attr['default'].neighbor_attr['4.4.4.4'].address_family_attr\ [nbr_af_name].nbr_af_maximum_prefix_max_prefix_no)
def test_uncfg(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') intf1 = Interface(device=dev1, name='Ethernet0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='Ethernet0/0/2', ipv4='10.2.0.1/24') dev2 = Device(testbed=testbed, name='PE2', os='nxos') intf3 = Interface(device=dev2, name='Ethernet0/0/3', ipv4='10.1.0.2/24', ipv6='2001:111:222::/64') intf4 = Interface(device=dev2, name='Ethernet0/0/4', ipv4='10.2.0.2/24') with self.assertNoWarnings(): Genie.testbed = None with self.assertRaises(TypeError): bgp = Bgp() with self.assertRaises(TypeError): bgp = Bgp(testbed=testbed) Genie.testbed = testbed with self.assertRaises(TypeError): bgp = Bgp() bgp = Bgp(asn=100,bgp_id=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(asn=100,bgp_id=100) self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) dev1.add_feature(bgp) bgp.device_attr[dev1].enabled = True uncfgs = bgp.build_unconfig(apply=False) self.assertCountEqual(uncfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(uncfgs[dev1.name]), '\n'.join([ 'no feature bgp', ])) # Defining attributes af_name = 'vpnv4 unicast' af_name2 = 'link-state' vrf_id = 'vrf1' vrf1 = Vrf(vrf_id) bgp.device_attr[dev1] bgp.device_attr[dev1].vrf_attr[None].always_compare_med = True bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name] bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name2] bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_retain_rt_all = True bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening = True bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening_half_life_time = 1 bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening_reuse_time = 10 bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening_suppress_time = 30 bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening_max_suppress_time = 2 neighbor_id = intf4.ipv4 bgp.device_attr[dev1].vrf_attr[vrf1].add_neighbor(neighbor_id) bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[neighbor_id] bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ nbr_fall_over_bfd = True nbr_af_name = 'ipv4 unicast' bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name] bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name].nbr_af_allowas_in = True partial_uncfg1 = bgp.build_unconfig( apply=False, attributes={'device_attr':\ {'*':{'vrf_attr':\ {'*':"always_compare_med"}}}}) self.assertCountEqual(partial_uncfg1.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg1[dev1.name]), '\n'.\ join([ 'router bgp 100', ' no bestpath always-compare-med', ' exit', ])) partial_uncfg2 = bgp.build_unconfig(\ apply=False, attributes={'device_attr':\ {'*':{'vrf_attr':'*'}}}) self.assertCountEqual(partial_uncfg2.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg2[dev1.name]), '\n'.\ join([ 'router bgp 100', ' no bestpath always-compare-med', ' no address-family link-state', ' no address-family vpnv4 unicast', ' no vrf vrf1', ' exit', ])) partial_uncfg3 = bgp.build_unconfig( apply=False, attributes={'device_attr': {'*': {'vrf_attr': {'*': {'neighbor_attr':\ {'*': {'address_family_attr':\ {'*':"nbr_af_allowas_in"}}}}}}}}) self.assertCountEqual(partial_uncfg3.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg3[dev1.name]), '\n'.\ join([ 'router bgp 100', ' vrf vrf1', ' neighbor 10.2.0.2', ' address-family ipv4 unicast', ' no allowas-in', ' exit', ' exit', ' exit', ' exit', ])) bgp.device_attr[dev1].protocol_shutdown = True partial_uncfg4 = bgp.build_unconfig( apply=False, attributes={'device_attr':\ {'*':"protocol_shutdown"}}) self.assertCountEqual(partial_uncfg4.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg4[dev1.name]), '\n'.\ join([ 'router bgp 100', ' no shutdown', ' exit', ])) partial_uncfg5 = bgp.build_unconfig(\ apply=False, attributes={'device_attr':\ {'*':\ {'vrf_attr':\ {'*':\ {'address_family_attr':\ {'*':\ "af_dampening"}}}}}}) self.assertCountEqual(partial_uncfg5.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg5[dev1.name]), '\n'.\ join([ 'router bgp 100', ' address-family vpnv4 unicast', ' no dampening', ' exit', ' exit', ])) bgp.device_attr[dev1].enabled = False uncfgs = bgp.build_unconfig(apply=False) self.assertCountEqual(uncfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(uncfgs[dev1.name]), '\n'.join([ 'no router bgp 100', ])) bgp.device_attr[dev1].enabled = True uncfgs = bgp.build_unconfig(apply=False) self.assertCountEqual(uncfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(uncfgs[dev1.name]), '\n'.join([ 'no feature bgp', ]))
def test_cfg2(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') intf1 = Interface(device=dev1, name='Ethernet0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='Ethernet0/0/2', ipv4='10.2.0.1/24') dev2 = Device(testbed=testbed, name='PE2', os='nxos') intf3 = Interface(device=dev2, name='Ethernet0/0/3', ipv4='10.1.0.2/24', ipv6='2001:111:222::/64') intf4 = Interface(device=dev2, name='Ethernet0/0/4', ipv4='10.2.0.2/24') with self.assertNoWarnings(): Genie.testbed = None with self.assertRaises(TypeError): bgp = Bgp() with self.assertRaises(TypeError): bgp = Bgp(testbed=testbed) Genie.testbed = testbed with self.assertRaises(TypeError): bgp = Bgp() bgp = Bgp(asn=100,bgp_id=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(asn=100,bgp_id=100) self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) # Defining attributes vrf_id = 'vrf1' vrf1 = Vrf(vrf_id) pp_name = 'PEER-POLICY' ps_name = 'PEER-SESSION' bgp.device_attr[dev2].enabled = True bgp.device_attr[dev2].peer_policy_attr[pp_name].pp_allowas_in =\ True bgp.device_attr[dev2].peer_session_attr[ps_name].ps_fall_over_bfd=\ True bgp.device_attr[dev2].vrf_attr[None].cluster_id = '150' af_name = 'ipv6 unicast' bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name] bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_nexthop_route_map = 'test' bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening = True bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening_half_life_time = 1 bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening_reuse_time = 10 bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening_suppress_time = 30 bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening_max_suppress_time = 2 neighbor_id = intf2.ipv4 bgp.device_attr[dev2].vrf_attr[vrf1].add_neighbor(neighbor_id) bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ nbr_suppress_four_byte_as_capability = True nbr_af_name = 'vpnv6 unicast' bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name] bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name].\ nbr_af_maximum_prefix_max_prefix_no = 300000 bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name].nbr_af_default_originate = True dev2.add_feature(bgp) cfgs = bgp.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev2.name]) self.maxDiff = None self.assertEqual(str(cfgs[dev2.name]), '\n'.join( ['feature bgp', 'router bgp 100', ' cluster-id 150', ' address-family ipv6 unicast', ' dampening 1 10 30 2', ' nexthop route-map test', ' exit', ' vrf vrf1', ' neighbor 10.2.0.1', ' capability suppress 4-byte-as', ' address-family vpnv6 unicast', ' maximum-prefix 300000', ' default-originate', ' exit', ' exit', ' exit', ' template peer-session PEER-SESSION', ' bfd', ' exit', ' template peer-policy PEER-POLICY', ' allowas-in', ' exit', ' exit', ])) partial_uncfg1 = bgp.build_unconfig(apply=False, attributes={\ 'device_attr':\ {dev2.name:\ {'vrf_attr':\ {'vrf1':\ {'neighbor_attr':\ {'10.2.0.1':\ {'address_family_attr':\ {'vpnv6 unicast':\ {'nbr_af_default_originate': None}}}}}}}}}) self.assertCountEqual(partial_uncfg1.keys(), [dev2.name]) self.assertMultiLineEqual(str(partial_uncfg1[dev2.name]), '\n'.\ join([ 'router bgp 100', ' vrf vrf1', ' neighbor 10.2.0.1', ' address-family vpnv6 unicast', ' no default-originate', ' exit', ' exit', ' exit', ' exit', ]))