Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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='iosxr')
intf1 = Interface(name='GigabitEthernet0/0/0/0', device=dev1, aliases=['PE1_1'])
subif1 = Interface(name='GigabitEthernet0/0/0/1.10', device=dev1, aliases=['PE1_1'])
vrf = Vrf(name='test', testbed=testbed)
dev1.add_feature(vrf)
# Apply configuration
intf1.description = 'test'
intf1.enabled = True
intf1.mtu = 1492
intf1.vrf = vrf
intf1.mac_address = 'aabb.ccdd.eeff'
intf1.bandwidth = 8192
intf1.load_interval = 33
intf1.unnumbered_intf_ref = 'GigabitEthernet0/0/0/1.10'
intf1.ipv6_autoconf = True
intf1.medium = 'p2p'
# Build config
def setUp(self):
self.maxDiff = None
tb = Genie.testbed = Testbed()
self.dev1 = Device(testbed=tb, name='PE1', os='iosxe')
self.dev2 = Device(testbed=tb, name='PE2', os='iosxe')
self.i1 = Interface(name='GigabitEthernet0/0/1', device=self.dev1)
self.i2 = Interface(name='GigabitEthernet0/0/2', device=self.dev2)
self.i3 = Interface(name='GigabitEthernet0/0/3', device=self.dev1)
self.i4 = Interface(name='GigabitEthernet0/0/4', device=self.dev2)
self.i5 = Interface(name='GigabitEthernet0/0/5', device=self.dev1)
self.i6 = Interface(name='GigabitEthernet0/0/6', device=self.dev2)
self.i7 = Interface(name='GigabitEthernet0/0/7', device=self.dev1)
self.i8 = Interface(name='GigabitEthernet0/0/8', device=self.dev2)
self.link = Link(name='1_2_1')
self.link.connect_interface(interface=self.i1)
self.link.connect_interface(interface=self.i2)
self.link2 = Link(name='1_2_2')
self.link2.connect_interface(interface=self.i3)
self.link2.connect_interface(interface=self.i4)
self.link3 = Link(name='1_2_3')
self.link3.connect_interface(interface=self.i5)
self.link3.connect_interface(interface=self.i6)
self.link4 = Link(name='1_2_4')
self.link4.connect_interface(interface=self.i7)
self.link4.connect_interface(interface=self.i8)
self.assertSetEqual(
set(self.link.find_interfaces()),
set([self.i1, self.i2]))
def test_ipv6_multiple_lines_confg(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'])
vrf = Vrf(name='test', testbed=testbed)
dev1.add_feature(vrf)
# Apply configuration
intf1.description = 'multiple lines config'
ipv6a = IPv6Addr(device=dev1)
ipv6a.ipv6 = IPv6Address('2001:db1:1::1')
ipv6a.ipv6_prefix_length = '64'
intf1.add_ipv6addr(ipv6a)
ipv6b = IPv6Addr(device=dev1)
ipv6b.ipv6 = IPv6Address('2001:db1:2::2')
ipv6b.ipv6_prefix_length = '64'
intf1.add_ipv6addr(ipv6b)
intf1.shutdown = False
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',
def setUp(self):
self.tb = Genie.testbed = Testbed()
self.dev1 = Device(testbed=self.tb, name='PE1', os='iosxr')
self.dev2 = Device(testbed=self.tb, name='PE2', os='iosxr')
self.i1 = Interface(name='GigabitEthernet0/0/0/1',device=self.dev1)
self.i2 = Interface(name='GigabitEthernet0/0/0/2',device=self.dev2)
self.i3 = Interface(name='GigabitEthernet0/0/0/3',device=self.dev1)
self.i4 = Interface(name='GigabitEthernet0/0/0/4',device=self.dev2)
self.i5 = Interface(name='GigabitEthernet0/0/0/5',device=self.dev1)
self.i6 = Interface(name='GigabitEthernet0/0/0/6',device=self.dev2)
self.i7 = Interface(name='GigabitEthernet0/0/0/7',device=self.dev1)
self.i8 = Interface(name='GigabitEthernet0/0/0/8',device=self.dev2)
self.link = Link(name='1_2_1',testbed=self.tb)
self.link.connect_interface(interface=self.i1)
self.link.connect_interface(interface=self.i2)
self.link2 = Link(name='1_2_2',testbed=self.tb)
self.link2.connect_interface(interface=self.i3)
self.link2.connect_interface(interface=self.i4)
self.link3 = Link(name='1_2_3',testbed=self.tb)
self.link3.connect_interface(interface=self.i5)
self.link3.connect_interface(interface=self.i6)
self.link4 = Link(name='1_2_4',testbed=self.tb)
self.link4.connect_interface(interface=self.i7)
self.link4.connect_interface(interface=self.i8)
self.assertSetEqual(
set(self.link.find_interfaces()),
set([self.i1, self.i2]))
self.assertSetEqual(
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'
]))
def setUp(self):
self.tb = Genie.testbed = Testbed()
self.dev1 = Device(testbed=self.tb, name='PE1', os='iosxe')
self.dev2 = Device(testbed=self.tb, name='PE2', os='iosxe')
self.i1 = Interface(name='GigabitEthernet0/0/1',device=self.dev1)
self.i2 = Interface(name='GigabitEthernet0/0/2',device=self.dev2)
self.i3 = Interface(name='GigabitEthernet0/0/3',device=self.dev1)
self.i4 = Interface(name='GigabitEthernet0/0/4',device=self.dev2)
self.i5 = Interface(name='GigabitEthernet0/0/5',device=self.dev1)
self.i6 = Interface(name='GigabitEthernet0/0/6',device=self.dev2)
self.i7 = Interface(name='GigabitEthernet0/0/7',device=self.dev1)
self.i8 = Interface(name='GigabitEthernet0/0/8',device=self.dev2)
self.link = Link(name='1_2_1',testbed=self.tb)
self.link.connect_interface(interface=self.i1)
self.link.connect_interface(interface=self.i2)
self.link2 = Link(name='1_2_2',testbed=self.tb)
self.link2.connect_interface(interface=self.i3)
self.link2.connect_interface(interface=self.i4)
self.link3 = Link(name='1_2_3',testbed=self.tb)
self.link3.connect_interface(interface=self.i5)
self.link3.connect_interface(interface=self.i6)
self.link4 = Link(name='1_2_4',testbed=self.tb)
self.link4.connect_interface(interface=self.i7)
self.link4.connect_interface(interface=self.i8)
def remove_interface(self, interface):
assert isinstance(interface, genie.conf.base.Interface)
self._interfaces.remove(interface)
# enaDestructor -id on_resolve_fail -cancel
active_xos_interfaces = []
# enaTbSetDefaultTopologyLayer [keylget kltopo params.topolayer]
for object_name, object_value in r.best_objects.items():
if object_name in ('RESOLVE', 'SOLUTION'):
continue
if object_value is None:
continue
self.assign(object_name, object_value)
if isinstance(object_value, genie.conf.base.Device):
# if { [enaTbGetTestDeviceParam $object_value -type] eq "router" } {
# lappend lvActiveIntfs [enaTbFindInterface -router $object_value -interface "Loopback0" -create]
# }
# enaTbSetTestDevice $object_value -label [linsert [keylget kltopo objects.$object_name.params.labels] 0 $object_name]
pass
elif isinstance(object_value, genie.conf.base.Interface):
active_xos_interfaces.append(object_value)
# enaTbSetInterface $object_value -topolayer [keylget kltopo params.topolayer]
elif isinstance(object_value, genie.conf.base.Link):
# enaTbSetLink $object_value -topolayer [keylget kltopo params.topolayer]
pass
else:
raise ValueError(object_value)
Genie.testbed.set_active_interfaces(active_xos_interfaces)
# enaTbSetDefaultTopologyLayer test
self.resolved_subset = subset
return
# if { $_trace(dump_fail) } {
# xscale::dyntopo dump
# if { ![lcontain [xscale::dyntopo names] $::env(TESTBED)] } {
# set orig_current_dyntopo_name $current_dyntopo_name
return osInterface.clean_interface_name(interface_name)
def short_interface_name(self, interface_name):
osInterface = self.get_os_specific_Interface_class()
return osInterface.short_interface_name(interface_name)
class EmulatedDevice(Device):
role = Device.role.copy(
default=Device.Role.emulated)
tgen_interface = managedattribute(
name='tgen_interface',
type=managedattribute.test_auto_ref(
managedattribute.test_isinstance(Interface)),
gettype=managedattribute.auto_unref)
@property
def tgen_device(self):
return self.tgen_interface.device
tgen_handle = managedattribute(
name='tgen_handle',
default=None,
type=(None, managedattribute.test_istype(str)),
doc='''The emulated device handle, as understood by HLTAPI/low-level vendor APIs.''')
emulated_loopback = managedattribute(
name='emulated_loopback',
default=None,
#type=(None, managedattribute.test_isinstance(EmulatedLoopbackInterface)),