Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testValues_insert_before_atomic_01(self):
inputs = ['interface GigabitEthernet4/1',
'interface GigabitEthernet4/2',
'interface GigabitEthernet4/3',
'interface GigabitEthernet4/4',
'interface GigabitEthernet4/5',
'interface GigabitEthernet4/6',
'interface GigabitEthernet4/7',
'interface GigabitEthernet4/8',
]
cfg = CiscoConfParse(self.c01, factory=False)
for idx, linespec in enumerate(inputs):
test_result = cfg.insert_before(linespec, 'default '+linespec,
exactmatch=True, atomic=True)
result_correct = [inputs[idx]]
self.assertEqual(result_correct, test_result)
def testVal_IOSIntfLine_ipv4_masklength(self):
cfg = CiscoConfParse(self.c01, factory=True)
result_correct = {
'interface Serial 1/0': 30,
'interface Serial 1/1': 31,
'interface GigabitEthernet4/1': 0,
'interface GigabitEthernet4/2': 0,
'interface GigabitEthernet4/3': 0,
'interface GigabitEthernet4/4': 0,
'interface GigabitEthernet4/5': 0,
'interface GigabitEthernet4/6': 0,
'interface GigabitEthernet4/7': 0,
'interface GigabitEthernet4/8.120': 24,
'interface ATM5/0/0': 0,
'interface ATM5/0/0.32 point-to-point': 30,
'interface ATM5/0/1': 0,
}
test_result = dict()
def testVal_object_group_network(self):
conf = ['!',
'name 1.1.2.20 loghost01',
'!',
'object-group network INSIDE_addrs',
' network-object host loghost01',
' network-object host 1.1.2.1',
' network-object 1.1.2.2 255.255.255.255',
' network-object 1.1.2.0 255.255.255.0',
'!',]
cfg_factory = CiscoConfParse(conf, factory=True, syntax='asa')
obj = cfg_factory.find_objects(r'object-group\snetwork')[0]
# Ensure obj.name is set correctly
self.assertEqual(obj.name, "INSIDE_addrs")
result_correct = [IPv4Obj('1.1.2.20/32'), IPv4Obj('1.1.2.1/32'),
IPv4Obj('1.1.2.2/32'), IPv4Obj('1.1.2.0/24')]
self.assertEqual(obj.networks, result_correct)
def testVal_IOSRouteLine_10():
line = 'ipv6 route ::/0 2001:DEAD:BEEF::1'
cfg = CiscoConfParse([line], factory=True)
obj = cfg.ConfigObjs[0]
assert 'ipv6'==obj.address_family
assert ''==obj.vrf
assert '::'==obj.network
assert '::'==obj.netmask
assert 0==obj.masklen
assert ''==obj.next_hop_interface
assert '2001:DEAD:BEEF::1'==obj.next_hop_addr
assert obj.multicast is False
#assert ''==obj.tracking_object_name
#assert ''==obj.route_name
#assert obj.permanent is False
#assert obj.global_next_hop is True # All non-vrf routes have global NHs
assert 1==obj.admin_distance
assert ''==obj.tag
def testVal_IOSAaaCommandsAuthorizationLine():
line = 'aaa authorization commands 15 default group tacacs+ local'
cfg = CiscoConfParse([line], factory=True)
obj = cfg.ConfigObjs[0]
assert 15==obj.level
assert 'tacacs+'==obj.group
assert 'default'==obj.list_name
assert ['local']==obj.methods
def testVal_IOSIntfLine_portchannel_number_01():
lines = ['!',
'interface GigabitEthernet 1/1',
' switchport mode trunk',
' switchport trunk native vlan 911',
' channel-group 25 mode active',
'!',
]
cfg = CiscoConfParse(lines, factory=True)
intf_obj = cfg.find_objects('^interface')[0]
assert intf_obj.portchannel_number==25
def testValues_aaa_authfailmsg_delimiter_01():
# Test auth fail-message delimiter on the same line...
CONFIG = ['!', 'aaa authentication fail-message ^ trivial banner here ^', 'end']
parse = CiscoConfParse(CONFIG)
bannerobj = parse.find_objects(r'^aaa\sauthentication\sfail-message')[0]
BANNER_LINE_NUMBER = 1
assert bannerobj.linenum == BANNER_LINE_NUMBER
for obj in bannerobj.children:
assert obj.parent.linenum == BANNER_LINE_NUMBER
assert len(bannerobj.children)==0
CONFIG = ['thing1',
' foo',
' bar',
' 100',
' 200',
' 300',
' 400',
'thing2',]
RESULT_CORRECT = ['thing1',
' foo',
' bar',
' 100',
' 200',
' 300',
' 400',]
cfg = CiscoConfParse(CONFIG)
test_result = cfg.find_all_children('^thing1')
assert RESULT_CORRECT==test_result
]
required_config = ['!',
'vlan 51',
' name SOME-VLAN',
' state active',
'vlan 52',
' name BLAH',
' state active',
'!',]
result_correct = ['no vlan 53', 'vlan 51', ' name SOME-VLAN', 'vlan 52',
' name BLAH', ' state active']
linespec = r'vlan\s+\S+|name\s+\S+|state.+'
parse = CiscoConfParse(config_01)
test_result = parse.sync_diff(required_config, linespec, linespec)
assert result_correct==test_result
'!']
required_config = ['!',
'vlan 51',
' name SOME-VLAN',
' state active',
'vlan 52',
' name BLAH',
' state active',
'!',]
result_correct = ['no vlan 53', 'vlan 51', ' name SOME-VLAN', 'vlan 52',
' name BLAH', ' state active']
linespec = r'vlan\s+\S+|name\s+\S+|state.+'
parse = CiscoConfParse(config_01)
test_result = parse.sync_diff(required_config, linespec, linespec)
assert result_correct==test_result