Skip to content

Commit

Permalink
Merge pull request #29 from mmensuali/vlan-dashed-list-bug
Browse files Browse the repository at this point in the history
VLAN dashed list bug
  • Loading branch information
alliedtelesis committed Sep 11, 2014
2 parents 7a41b6a + da4f331 commit 75513a2
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pynetworking/features/ats_vlan_config_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ def run(self, data):
for tok in self.lexer:
if tok.type == 'VLANLIST':
for vid in tok.value.split(','):
result[vid] = {'name': vid}
if '-' in vid:
a = int(vid.split('-')[0])
b = int(vid.split('-')[1]) + 1
for c in range(a, b):
d = "{0}".format(c)
result[d] = {'name': d}
continue
else:
result[vid] = {'name': vid}
continue
if tok.type == 'name':
result[tok.value[0]]['name'] = tok.value[1]

return result

1 change: 1 addition & 0 deletions pynetworking/features/awp_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def _update_license(self):
if m:
key = m.group('name')
fflist = line.split(': ')[-1]
fflist = fflist.split('\r\n\r\n')[0]
fflist = fflist.replace(' ', '')
fflist = fflist.replace('\n', '')
fflist = fflist.replace('\r', '')
Expand Down
98 changes: 98 additions & 0 deletions tests/test_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,104 @@ def test_get_vlan(dut, log_level):
d.close()


def test_vlan_dashed_list(dut, log_level):
output_show_rcfg = ["""
!
interface port1.0.1-1.0.50
switchport
switchport mode access
!
vlan database
vlan 21-23,25,30-33
exit
interface vlan 21
name "twentyone"
exit
interface vlan 22
name "zweiundzwanzig"
exit
interface vlan 23
name "vingttrois"
exit
interface vlan 25
name "venticinque"
exit
interface vlan 32
name "telnet vlan"
exit
interface vlan 1
ip address 10.17.39.253 255.255.255.0
name default
exit
!
end
"""]
output_show_vlan = ["""
VLAN ID Name Type State Member ports
(u)-Untagged, (t)-Tagged
======= ================ ======= ======= ====================================
1 default STATIC ACTIVE port1.0.1(u) port1.0.2(u) port1.0.3(u)
port1.0.4(u) port1.0.5(u) port1.0.6(u)
port1.0.7(u) port1.0.8(u) port1.0.9(u)
port1.0.10(u) port1.0.11(u)
port1.0.12(t) port1.0.13(u)
port1.0.14(u) port1.0.15(u)
port1.0.16(u) port1.0.17(u)
port1.0.18(u) port1.0.19(u)
port1.0.20(t) port1.0.21(u)
port1.0.22(u) port1.0.23(u)
port1.0.24(u) port1.0.25(u)
port1.0.26(u) port1.0.27(u)
port1.0.28(u) port1.0.29(u)
port1.0.30(u) port1.0.31(u)
port1.0.32(u) port1.0.33(u)
port1.0.34(u) port1.0.35(u)
port1.0.36(u) port1.0.37(u)
port1.0.38(u) port1.0.39(u)
port1.0.40(u) port1.0.41(u)
port1.0.44(u) port1.0.45(u)
port1.0.46(u) port1.0.47(u)
port1.0.48(u) port1.0.49(u)
port1.0.50(u)
21 twentyone STATIC ACTIVE port1.0.42(t) port1.0.43(t)
22 zweiundzwanzig STATIC ACTIVE port1.0.42(t) port1.0.43(t)
23 vingttrois STATIC ACTIVE port1.0.42(t) port1.0.43(t)
25 venticinque STATIC ACTIVE port1.0.42(t) port1.0.43(t)
30 VLAN0030 STATIC SUSPEND
31 VLAN0031 STATIC SUSPEND
32 "telnet vlan" STATIC SUSPEND
33 VLAN0033 STATIC SUSPEND
"""]

setup_dut(dut)
dut.add_cmd({'cmd': 'show running-config', 'state':0 , 'action':'PRINT' ,'args': output_show_rcfg})
dut.add_cmd({'cmd': 'show vlan all' , 'state':0 , 'action':'PRINT' ,'args': output_show_vlan})
d=Device(host=dut.host,port=dut.port,protocol=dut.protocol, log_level=log_level)
d.open()
assert '21' in d.vlan
assert d.vlan[21]['name'] == 'twentyone'
assert ('22', {'current state': 'ACTIVE', 'name': 'zweiundzwanzig', 'untagged': (), 'tagged': ('1.0.42', '1.0.43'), 'type': 'STATIC'}) in d.vlan.items()
with pytest.raises(TypeError) as excinfo:
d.vlan[d.vlan]
str(d.vlan)
assert '23' in d.vlan
assert d.vlan[23]['name'] == 'vingttrois'
assert '24' not in d.vlan
assert '25' in d.vlan
assert d.vlan[25]['name'] == 'venticinque'
assert '26' not in d.vlan
assert '27' not in d.vlan
assert '28' not in d.vlan
assert '29' not in d.vlan
assert '30' in d.vlan
assert d.vlan[30]['name'] == 'VLAN0030'
assert '31' in d.vlan
assert '32' in d.vlan
assert d.vlan[32]['name'] == 'telnet vlan'
assert '33' in d.vlan
d.close()


def test_create_vlan_1(dut, log_level):
setup_dut(dut)
dut.add_cmd({'cmd':'show running-config', 'state':0, 'action': 'PRINT','args':["""
Expand Down
70 changes: 70 additions & 0 deletions tests/test_vlan_ats.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,76 @@ def test_get_vlan(dut, log_level):
d.close()


def test_vlan_dashed_list(dut, log_level):
output_show_rcfg = ["""
vlan database
vlan 21-23,25,30-33
exit
interface vlan 21
name twentyone
exit
interface vlan 22
name zweiundzwanzig
exit
interface vlan 23
name vingttrois
exit
interface vlan 25
name venticinque
exit
interface vlan 1
ip address 10.17.39.252 255.255.255.0
name default_vlan
exit
hostname nac_dev
ip ssh server
"""]
output_show_vlan = ["""
Vlan Name Ports Type Authorization
---- ----------------- --------------------------- ------------ -------------
1 default_vlan 1/e(1-48),1/g(1-4), other Required
2/e(1-48),2/g(1-4),
3/e(1-48),3/g(1-4),
4/e(1-48),4/g(1-4),
5/e(1-48),5/g(1-4),
6/e(1-48),6/g(1-4),ch(1-8)
21 twentyone permanent Required
22 zweiundzwanzig permanent Required
23 vingttrois permanent Required
25 venticinque permanent Required
30 30 permanent Required
31 31 permanent Required
32 32 permanent Required
33 33 permanent Required
"""]

setup_dut(dut)
dut.add_cmd({'cmd': 'show running-config', 'state':0 , 'action':'PRINT' ,'args': output_show_rcfg})
dut.add_cmd({'cmd': 'show vlan' , 'state':0 , 'action':'PRINT' ,'args': output_show_vlan})
d=Device(host=dut.host,port=dut.port,protocol=dut.protocol, log_level=log_level)
d.open()
with pytest.raises(TypeError) as excinfo:
d.vlan[d.vlan]
assert d.vlan[21]['name'] == 'twentyone'
assert ('22', {'name': 'zweiundzwanzig', 'tagged': [], 'type': 'permanent', 'untagged': []}) in d.vlan.items()
assert '23' in d.vlan
assert d.vlan[23]['name'] == 'vingttrois'
assert '24' not in d.vlan
assert '25' in d.vlan
assert d.vlan[25]['name'] == 'venticinque'
assert '26' not in d.vlan
assert '27' not in d.vlan
assert '28' not in d.vlan
assert '29' not in d.vlan
assert '30' in d.vlan
assert d.vlan[30]['name'] == '30'
assert '31' in d.vlan
assert '32' in d.vlan
assert '33' in d.vlan
d.close()


def test_create1(dut, log_level):
setup_dut(dut)
dut.add_cmd({'cmd':'show vlan', 'state':0, 'action':'PRINT','args':["""
Expand Down

0 comments on commit 75513a2

Please sign in to comment.