def test_learn_config(self): testbed = Testbed() dev = Device(testbed=testbed, name='PE1', os='nxos') dev.custom = {'abstraction': {'order': ['os'], 'context': 'cli'}} golden_output = { 'return_value': ''' R2# show run vrf vni_10100 | sec '^vrf' vrf context vni_10100 vni 10100 rd auto address-family ipv4 unicast route-target both auto route-target both auto mvpn route-target both auto evpn ''' } vrf = Vrf('vni_10100') # Return outputs above as inputs to parser when called dev.execute = Mock(**golden_output) vrf.device_attr[dev] learn = Vrf.learn_config(device=dev) if learn: self.assertEqual(learn[0].device_attr[dev].address_family_attr['ipv4 unicast'].\ route_target_attr['auto'].protocol_attr['mvpn'].rt_mvpn, True)
def test_cli_config_vni(self): vrf_conf = Vrf('VRF1') self.dev1.add_feature(vrf_conf) vrf_conf.device_attr[self.dev1].vni = 4092 cfgs = vrf_conf.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf context VRF1', ' vni 4092', ' exit', ])) # Build unconfig for vni attribute cfgs = vrf_conf.build_unconfig( apply=False, attributes={'device_attr': { self.dev1: { 'vni': None, } }}) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf context VRF1', ' no vni 4092', ' exit', ]))
def test_cli_vxlan_evpn_config(self): vrf_conf = Vrf('VRF1') self.dev1.add_feature(vrf_conf) # Apply configuration vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast']. \ route_target_attr['200:1'].rt_type = 'both' vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast']. \ route_target_attr['200:1'].protocol_attr['evpn'].rt_evpn = True # Build config cfgs = vrf_conf.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf context VRF1', ' address-family ipv4 unicast', ' route-target import 200:1', ' route-target export 200:1', ' route-target both 200:1 evpn', ' exit', ' exit', ])) # Build unconfig for selected attributes uncfgs = vrf_conf.build_unconfig( apply=False, attributes={ 'device_attr': { self.dev1: { 'address_family_attr': { 'ipv4 unicast': { 'route_target_attr': { '200:1': { 'rt_type': 'both', 'protocol_attr': { 'evpn': { 'rt_evpn': None, } } } } } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(uncfgs[self.dev1.name]), '\n'.join([ 'vrf context VRF1', ' address-family ipv4 unicast', ' route-target import 200:1', ' route-target export 200:1', ' no route-target both 200:1 evpn', ' exit', ' exit', ]))
def test_cli_config(self): # prefix-list conf vrf_conf = Vrf('VRF1') self.dev1.add_feature(vrf_conf) # Apply configuration vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast'].\ route_target_attr['200:1'].rt_type = 'both' vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast'].\ route_target_attr['100:1'].rt_type = 'import' # Build config cfgs = vrf_conf.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf VRF1', ' address-family ipv4 unicast', ' import route-target 100:1', ' import route-target 200:1', ' export route-target 200:1', ' exit', ' exit', ])) # Build unconfig cfgs = vrf_conf.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no vrf VRF1', ])) # Build unconfig for selected attributes cfgs = vrf_conf.build_unconfig(apply=False, attributes={'device_attr': { self.dev1: { 'address_family_attr': { 'ipv4 unicast': { 'route_target_attr': None } }}}}) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf VRF1', ' address-family ipv4 unicast', ' no import route-target 100:1', ' no import route-target 200:1', ' no export route-target 200:1', ' exit', ' exit', ])) # Build unconfig for selected attributes cfgs = vrf_conf.build_unconfig(apply=False, attributes={'device_attr': { self.dev1: { 'address_family_attr': { 'ipv4 unicast': { 'route_target_attr': { '200:1': { 'rt_type': None} }}}}}}) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf VRF1', ' address-family ipv4 unicast', ' no import route-target 200:1', ' no export route-target 200:1', ' exit', ' exit', ]))
def test_cli_config_v4(self): # prefix-list conf vrf_conf = Vrf('VRF1') self.dev1.add_feature(vrf_conf) # Apply configuration vrf_conf.device_attr[self.dev1].rd = '100:1' vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast'].\ import_from_global_map = 'import_from_global_map' vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast'].\ export_to_global_map = 'export_to_global_map' vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast'].\ routing_table_limit_number = 10000 vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast'].\ simple_alert = True vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast'].\ route_target_attr['200:1'].rt_type = 'both' vrf_conf.device_attr[self.dev1].address_family_attr['ipv4 unicast'].\ route_target_attr['100:1'].rt_type = 'import' # Build config cfgs = vrf_conf.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf definition VRF1', ' rd 100:1', ' address-family ipv4 unicast', ' import ipv4 unicast map import_from_global_map', ' export ipv4 unicast map export_to_global_map', ' maximum routes 10000 warning-only', ' route-target import 100:1', ' route-target import 200:1', ' route-target export 200:1', ' exit', ' exit', ])) # Build unconfig cfgs = vrf_conf.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual(str(cfgs[self.dev1.name]), '\n'.join([ 'no vrf definition VRF1', ])) # Build unconfig for selected attributes cfgs = vrf_conf.build_unconfig( apply=False, attributes={ 'device_attr': { self.dev1: { 'rd': None, 'address_family_attr': { 'ipv4 unicast': { 'export_to_global_map': None } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf definition VRF1', ' no rd 100:1', ' address-family ipv4 unicast', ' no export ipv4 unicast map export_to_global_map', ' exit', ' exit', ])) # Build unconfig for selected attributes cfgs = vrf_conf.build_unconfig(apply=False, attributes={ 'device_attr': { self.dev1: { 'address_family_attr': { 'ipv4 unicast': { 'route_target_attr': { '200:1': { 'rt_type': None } } } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf definition VRF1', ' address-family ipv4 unicast', ' no route-target import 200:1', ' no route-target export 200:1', ' exit', ' exit', ]))
def configure_ospf(self, testbed, testscript, uut, helper, steps): '''Configure a bigger Ospf configuration''' # To configure Ospf, we are doing the following: # # We want to configure it on two devices interconnected, so we are # asking to find us a link which reach the 'uut' and the 'helper' # device. We are taking the second ones, as the first one was used # for the previous subsection. # # Then we create a 'Ospf' Object with a name (to represent the Ospf # name) and add this Ospf to the link, and add configuration to it. # # Then we create a 'Vrf' object, which is added to the vrf. # # Lastly, we want to configure an ip address on the interface of this # link, and do a 'no shut'. This is done with Genie ipv4 and ipv6 # generator. It is also done for the loopback interfaces. # # And we configure each interface, the vrf and the Ospf. with steps.start('Find a link between uut and helper device and ' 'configure ospf with ' 'pid {pro} on it'.format(pro=self.ospf_2)): link = testbed.find_links(R(interfaces__device__name=uut.name), R(interfaces__device__name=helper.name), R(interfaces__type='ethernet')) # We are taking the second link link = link[1] # passing this link to testscript parameters # so we can be used in other subsections testscript.parameters['link_2'] = link with steps.start('Find a loopback link between uut and helper device ' 'and configure ospf with pid 200 on it'): loopback_link = testbed.find_links\ (R(interfaces__device__name=uut.name), R(interfaces__device__name=helper.name), R(interfaces__type = 'loopback'),count=1)[0] # Take this link and configure Ospf on it with steps.start('Configure ospf with pid {pro} on the ' 'link'.format(pro=self.ospf_2)): # Create a ospf object ospf = Ospf(ospf_name=self.ospf_2) ospf.instance = self.ospf_2 # Adding ospf to the link and loopback_link link.add_feature(ospf) loopback_link.add_feature(ospf) # Add attributes to the ospf object ospf.log_adjacency_changes = self.log_adjacency_changes ospf.nsf = self.nsf ospf.nsr = self.nsr ospf.auto_cost_ref_bw = self.auto_cost_ref_bw with steps.start("Configure vrf '{vrf}' under " "ospf process id {pro} on " "the link".format(pro=self.ospf_2, vrf=self.vrf_name)): # Create vrf Object vrf = Vrf(name=self.vrf_name) # Add the address_family attributes to vrf vrf.device_attr[uut].address_family_attr['ipv4 unicast'] vrf.device_attr[helper].address_family_attr['ipv4 unicast'] vrf.device_attr[uut].address_family_attr['ipv6 unicast'] vrf.device_attr[helper].address_family_attr['ipv6 unicast'] # Adding area to the vrf attribute ospf.device_attr[uut].vrf_attr[vrf].area_attr[self.area_id] ospf.device_attr[helper].vrf_attr[vrf].area_attr[self.area_id] for dev in testbed.devices.values(): dev.add_feature(vrf) vrf.device_attr[dev].build_config() with steps.start('Building the interface configuration with Ospf ' 'process id {pro}'.format(pro=self.ospf_2)): # Initiating ipv4 and ipv6 addresses ipv4s = [] ipv6s = [] # Generate ipv4 and ipv6 addresses, depending on the length of the # interfaces ipv4rng = iter( testbed.ipv4_cache.reserve(count=len(link.interfaces))) ipv6rng = iter( testbed.ipv6_cache.reserve(count=len(link.interfaces))) for intf in link.interfaces: # Adding vrf to the interface intf.vrf = vrf # Configuring interface with its attributes intf.shutdown = False intf.layer = interface.Layer.L3 # Assigning Ipv4 and ipv6 addresses to the interface intf.ipv4 = next(ipv4rng) ipv4s.append(intf.ipv4.ip) intf.ipv6 = next(ipv6rng) ipv6s.append(intf.ipv6.ip) # Adding interface to the area attribute ospf.device_attr[intf.device].vrf_attr[vrf]\ .area_attr[self.area_id].interface_attr[intf].if_admin_control = True # Build interface config and apply it to the device intf.build_config() with steps.start('Building the loopback interface configuration with ' 'Ospf process id {pro}'.format(pro=self.ospf_2)): for intf in loopback_link.interfaces: # Add vrf to the loopback interface object intf.vrf = vrf intf.layer = interface.Layer.L3 # Assigning ipv4 and ipv6 addresses to the loopback interface intf.ipv4 = testbed.ipv4_cache.reserve(prefixlen=32)[0] ipv4s.append(intf.ipv4.ip) intf.ipv6 = testbed.ipv6_cache.reserve(prefixlen=128)[0] ipv6s.append(intf.ipv6.ip) # Adding the Loopback interface to the ospf object ospf.device_attr[intf.device].vrf_attr[vrf]\ .area_attr[self.area_id].interface_attr[intf].if_admin_control = True # Assigning the Loopback address as the OSPF router-id if intf.device.name == uut.name: ospf.device_attr[uut].vrf_attr[vrf]\ .router_id = intf.ipv4.ip.exploded elif intf.device.name == helper.name: ospf.device_attr[helper].vrf_attr[vrf]\ .router_id = intf.ipv4.ip.exploded # Building loopback interface configuration intf.build_config() with steps.start('Building the ospf configuration with ' 'Ospf process id {pro}'.format(pro=self.ospf_2)): # Building OSPF configuration ospf.build_config() # adding vrf, ospf and loopback to parameters testscript.parameters['vrf'] = vrf testscript.parameters['ospf'] = ospf testscript.parameters['loopback_link_2'] = loopback_link # Adding information for the ping test aetest.loop.mark( ping.test, destination=ipv4s, vrf=[vrf.name] * (len(link.interfaces) + len(loopback_link.interfaces)))
def test_cli_config_v6(self): # prefix-list conf vrf_conf = Vrf('VRF2') self.dev1.add_feature(vrf_conf) # Apply configuration vrf_conf.device_attr[self.dev1].rd = '100:1' vrf_conf.device_attr[self.dev1].address_family_attr['ipv6 unicast'].\ import_from_global_map = 'test_import' vrf_conf.device_attr[self.dev1].address_family_attr['ipv6 unicast'].\ export_to_global_map = 'test_export' vrf_conf.device_attr[self.dev1].address_family_attr['ipv6 unicast'].\ routing_table_limit_number = 10000 vrf_conf.device_attr[self.dev1].address_family_attr['ipv6 unicast'].\ alert_percent_value = 50 vrf_conf.device_attr[self.dev1].address_family_attr['ipv6 unicast'].\ route_target_attr['100:1'].rt_type = 'export' vrf_conf.device_attr[self.dev1].address_family_attr['ipv6 unicast'].\ route_target_attr['200:1'].rt_type = 'export' vrf_conf.device_attr[self.dev1].address_family_attr['ipv6 unicast'].\ route_target_attr['300:1'].rt_type = 'import' vrf_conf.device_attr[self.dev1].address_family_attr['ipv6 unicast'].\ route_target_attr['400:1'].rt_type = 'import' # Build config cfgs = vrf_conf.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf context VRF2', ' rd 100:1', ' address-family ipv6 unicast', ' import vrf default map test_import', ' maximum routes 10000 50', ' route-target export 100:1', ' route-target export 200:1', ' route-target import 300:1', ' route-target import 400:1', ' exit', ' exit', ])) # Build unconfig cfgs = vrf_conf.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual(str(cfgs[self.dev1.name]), '\n'.join([ 'no vrf context VRF2', ])) # Build unconfig for selected attributes cfgs = vrf_conf.build_unconfig( apply=False, attributes={ 'device_attr': { self.dev1: { 'rd': None, 'address_family_attr': { 'ipv6 unicast': { 'routing_table_limit_number': None, 'alert_percent_value': None, } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf context VRF2', ' no rd 100:1', ' address-family ipv6 unicast', ' no maximum routes 10000 50', ' exit', ' exit', ])) # Build unconfig for selected attributes cfgs = vrf_conf.build_unconfig(apply=False, attributes={ 'device_attr': { self.dev1: { 'address_family_attr': { 'ipv6 unicast': { 'route_target_attr': { '200:1': { 'rt_type': None } } } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'vrf context VRF2', ' address-family ipv6 unicast', ' no route-target import 200:1', ' no route-target export 200:1', ' exit', ' exit', ]))