Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
def testVal_object_group_service_01():
## This can only be configured as protocol object-group
conf = ['!',
'object-group service APP01_svc',
' service-object tcp destination smtp',
' service-object tcp destination https',
'!',]
cfg_factory = CiscoConfParse(conf, factory=True, syntax='asa')
obj = cfg_factory.find_objects(r'object-group\sservice')[0]
result_correct = [L4Object(protocol='tcp', port_spec='eq 25',
syntax='asa'), L4Object(protocol='tcp', port_spec='eq 443',
syntax='asa')]
assert (obj.name=='APP01_svc')
assert (obj.ports==result_correct)
assert (obj.L4Objects_are_directional is True)
assert (obj.protocol_type=='')
def testVal_IOSIntfLine_trunk_vlan_allowed_04():
lines = ['!',
'interface GigabitEthernet 1/1',
' switchport mode trunk',
' switchport trunk allowed vlan all',
' switchport trunk allowed vlan remove 2-4094',
' switchport trunk native vlan 911',
'!',
]
cfg = CiscoConfParse(lines, factory=True)
intf_obj = cfg.find_objects('^interface')[0]
assert intf_obj.trunk_vlans_allowed.as_list==[1]
def testVal_IOSRouteLine_09():
line = 'ip route vrf mgmtVrf 0.0.0.0 0.0.0.0 FastEthernet0/0 254 name foobarme tag 20'
cfg = CiscoConfParse([line], factory=True)
obj = cfg.ConfigObjs[0]
assert 'ip'==obj.address_family
assert 'mgmtVrf'==obj.vrf
assert '0.0.0.0'==obj.network
assert '0.0.0.0'==obj.netmask
assert 0==obj.masklen
assert 'FastEthernet0/0'==obj.next_hop_interface
assert ''==obj.next_hop_addr
assert obj.multicast is False
assert ''==obj.tracking_object_name
assert 'foobarme'==obj.route_name
assert obj.permanent is False
assert obj.global_next_hop is False # TODO: Figure out if False is right
assert 254==obj.admin_distance
assert '20'==obj.tag