Skip to content

Commit e0ba9f6

Browse files
author
Myron Sosyak
committed
Update test to use dvs
1 parent c8e406a commit e0ba9f6

File tree

3 files changed

+34
-42
lines changed

3 files changed

+34
-42
lines changed

tests/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def create_servers(self):
412412
for i in range(NUM_PORTS):
413413
server = VirtualServer(self.ctn_sw.name, self.ctn_sw_pid, i)
414414
self.servers.append(server)
415-
415+
416416
def reset_dbs(self):
417417
# DB wrappers are declared here, lazy-loaded in the tests
418418
self.app_db = None
@@ -1853,7 +1853,8 @@ def dvs_route(request, dvs) -> DVSRoute:
18531853
@pytest.yield_fixture(scope="class")
18541854
def dvs_lag_manager(request, dvs):
18551855
request.cls.dvs_lag = dvs_lag.DVSLag(dvs.get_asic_db(),
1856-
dvs.get_config_db())
1856+
dvs.get_config_db(),
1857+
dvs)
18571858

18581859

18591860
@pytest.yield_fixture(scope="class")
@@ -1868,7 +1869,7 @@ def dvs_vlan_manager(request, dvs):
18681869
def dvs_port_manager(request, dvs):
18691870
request.cls.dvs_port = dvs_port.DVSPort(dvs.get_asic_db(),
18701871
dvs.get_config_db())
1871-
1872+
18721873
@pytest.yield_fixture(scope="class")
18731874
def dvs_mirror_manager(request, dvs):
18741875
request.cls.dvs_mirror = dvs_mirror.DVSMirror(dvs.get_asic_db(),

tests/dvslib/dvs_lag.py

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

6-
def create_port_channel(self, lag_id, admin_status="up", mtu="1500"):
9+
def create_port_channel(self, lag_id, admin_status="up", mtu="1500", fast_rate=False):
710
lag = "PortChannel{}".format(lag_id)
8-
lag_entry = {"admin_status": admin_status, "mtu": mtu}
11+
lag_entry = {"admin_status": admin_status, "mtu": mtu, "fast_rate": str(fast_rate)}
912
self.config_db.create_entry("PORTCHANNEL", lag, lag_entry)
1013

1114
def remove_port_channel(self, lag_id):
@@ -27,3 +30,12 @@ def get_and_verify_port_channel_members(self, expected_num):
2730
def get_and_verify_port_channel(self, expected_num):
2831
return self.asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_LAG", expected_num)
2932

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

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)