Skip to content

Commit de2d6d3

Browse files
author
Myron Sosyak
committed
Update test to use dvs
1 parent 30ba381 commit de2d6d3

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

tests/dvslib/dvs_lag.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import json
2+
13
class DVSLag(object):
24
def __init__(self, adb, cdb):
35
self.asic_db = adb
46
self.config_db = cdb
57

6-
def create_port_channel(self, lag_id, admin_status="up", mtu="1500"):
8+
def create_port_channel(self, lag_id, admin_status="up", mtu="1500", fast_rate=False):
79
lag = "PortChannel{}".format(lag_id)
8-
lag_entry = {"admin_status": admin_status, "mtu": mtu}
10+
lag_entry = {"admin_status": admin_status, "mtu": mtu, "fast_rate": str(fast_rate)}
911
self.config_db.create_entry("PORTCHANNEL", lag, lag_entry)
1012

1113
def remove_port_channel(self, lag_id):
@@ -27,3 +29,12 @@ def get_and_verify_port_channel_members(self, expected_num):
2729
def get_and_verify_port_channel(self, expected_num):
2830
return self.asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_LAG", expected_num)
2931

32+
def dump_portchannel(self, lag_id):
33+
lag = "PortChannel{}".format(lag_id)
34+
output = dvs.runcmd("teamdctl {} state dump".format(lag))[1]
35+
port_state_dump = json.loads(output)
36+
return port_state_dump
37+
38+
def get_and_verify_port_channel_fast_rate(self, lag_id, fast_rate):
39+
assert self.dump_portchannel(lag_id)["runner"]["fast_rate"] == fast_rate
40+

tests/test_portchannel.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
import time
23
import re
34
import json
@@ -6,6 +7,7 @@
67
from swsscommon import swsscommon
78

89

10+
@pytest.mark.usefixtures('dvs_lag_manager')
911
class TestPortchannel(object):
1012
def test_Portchannel(self, dvs, testlog):
1113

@@ -90,51 +92,28 @@ def test_Portchannel(self, dvs, testlog):
9092
assert len(lagms) == 0
9193

9294
def test_Portchannel_fast_rate(self, dvs, testlog):
93-
portchannel_slow = ("PortChannel0003", "Ethernet16", 0)
94-
portchannel_fast = ("PortChannel0004", "Ethernet20", 0)
95-
96-
self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0)
95+
portchannels = [("0003", "Ethernet16", False),
96+
("0004", "Ethernet20", True)]
9797

9898
# Create PortChannels
99-
tbl = swsscommon.Table(self.cdb, "PORTCHANNEL")
100-
fvs_base = [("admin_status", "up"), ("mtu", "9100"), ("oper_status", "up"), ("lacp_key", "auto")]
101-
102-
fvs_slow = swsscommon.FieldValuePairs(fvs_base + [("fast_rate", "false")])
103-
tbl.set(portchannel_slow[0], fvs_slow)
104-
105-
fvs_fast = swsscommon.FieldValuePairs(fvs_base + [("fast_rate", "true")])
106-
tbl.set(portchannel_fast[0], fvs_fast)
107-
time.sleep(1)
99+
for portchannel in portchannels:
100+
self.dvs_lag.create_port_channel(portchannel[0], fast_rate=portchannel[2])
101+
self.dvs_lag.get_and_verify_port_channel(len(portchannels))
108102

109103
# Add members to PortChannels
110-
tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER")
111-
fvs = swsscommon.FieldValuePairs([("NULL", "NULL")])
112-
113-
for portchannel in portchannel_slow, portchannel_fast:
114-
tbl.set(portchannel[0] + "|" + portchannel[1], fvs)
115-
time.sleep(1)
104+
for portchannel in portchannels:
105+
self.dvs_lag.create_port_channel_member(portchannel[0], portchannel[1])
106+
self.dvs_lag.get_and_verify_port_channel_members(len(portchannels))
116107

117108
# test fast rate was not set on portchannel_slow
118-
output = dvs.runcmd("teamdctl {} state dump".format(portchannel_slow[0]))[1]
119-
port_state_dump = json.loads(output)
120-
assert not port_state_dump["runner"]["fast_rate"]
121-
122-
# test fast rate was set on portchannel_fast
123-
output = dvs.runcmd("teamdctl {} state dump".format(portchannel_fast[0]))[1]
124-
port_state_dump = json.loads(output)
125-
assert port_state_dump["runner"]["fast_rate"]
109+
for portchannel in portchannels:
110+
self.dvs_lag.get_and_verify_port_channel_fast_rate(portchannel[0], portchannel[2])
126111

127112
# remove PortChannel members
128-
tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER")
129-
for portchannel in portchannel_slow, portchannel_fast:
130-
tbl._del(portchannel[0] + "|" + portchannel[1])
131-
time.sleep(1)
113+
for portchannel in portchannels:
114+
self.dvs_lag.remove_port_channel(portchannel[0])
115+
self.dvs_lag.get_and_verify_port_channel(0)
132116

133-
# remove PortChannel
134-
tbl = swsscommon.Table(self.cdb, "PORTCHANNEL")
135-
for portchannel in portchannel_slow, portchannel_fast:
136-
tbl._del(portchannel[0])
137-
time.sleep(1)
138117

139118
def test_Portchannel_lacpkey(self, dvs, testlog):
140119
portchannelNamesAuto = [("PortChannel001", "Ethernet0", 1001),

0 commit comments

Comments
 (0)