Skip to content

Commit

Permalink
Update test to use dvs
Browse files Browse the repository at this point in the history
  • Loading branch information
Myron Sosyak committed Jul 5, 2022
1 parent 30ba381 commit 1a64d22
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 42 deletions.
7 changes: 4 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def create_servers(self):
for i in range(NUM_PORTS):
server = VirtualServer(self.ctn_sw.name, self.ctn_sw_pid, i)
self.servers.append(server)

def reset_dbs(self):
# DB wrappers are declared here, lazy-loaded in the tests
self.app_db = None
Expand Down Expand Up @@ -1853,7 +1853,8 @@ def dvs_route(request, dvs) -> DVSRoute:
@pytest.yield_fixture(scope="class")
def dvs_lag_manager(request, dvs):
request.cls.dvs_lag = dvs_lag.DVSLag(dvs.get_asic_db(),
dvs.get_config_db())
dvs.get_config_db(),
dvs)


@pytest.yield_fixture(scope="class")
Expand All @@ -1868,7 +1869,7 @@ def dvs_vlan_manager(request, dvs):
def dvs_port_manager(request, dvs):
request.cls.dvs_port = dvs_port.DVSPort(dvs.get_asic_db(),
dvs.get_config_db())

@pytest.yield_fixture(scope="class")
def dvs_mirror_manager(request, dvs):
request.cls.dvs_mirror = dvs_mirror.DVSMirror(dvs.get_asic_db(),
Expand Down
18 changes: 15 additions & 3 deletions tests/dvslib/dvs_lag.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import json

class DVSLag(object):
def __init__(self, adb, cdb):
def __init__(self, adb, cdb, dvs):
self.asic_db = adb
self.config_db = cdb
self.dvs = dvs

def create_port_channel(self, lag_id, admin_status="up", mtu="1500"):
def create_port_channel(self, lag_id, admin_status="up", mtu="1500", fast_rate=False):
lag = "PortChannel{}".format(lag_id)
lag_entry = {"admin_status": admin_status, "mtu": mtu}
lag_entry = {"admin_status": admin_status, "mtu": mtu, "fast_rate": str(fast_rate)}
self.config_db.create_entry("PORTCHANNEL", lag, lag_entry)

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

def dump_portchannel(self, lag_id):
lag = "PortChannel{}".format(lag_id)
output = self.dvs.runcmd("teamdctl {} state dump".format(lag))[1]
port_state_dump = json.loads(output)
return port_state_dump

def get_and_verify_port_channel_fast_rate(self, lag_id, fast_rate):
assert self.dump_portchannel(lag_id)["runner"]["fast_rate"] == fast_rate

51 changes: 15 additions & 36 deletions tests/test_portchannel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import time
import re
import json
Expand All @@ -6,6 +7,7 @@
from swsscommon import swsscommon


@pytest.mark.usefixtures('dvs_lag_manager')
class TestPortchannel(object):
def test_Portchannel(self, dvs, testlog):

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

def test_Portchannel_fast_rate(self, dvs, testlog):
portchannel_slow = ("PortChannel0003", "Ethernet16", 0)
portchannel_fast = ("PortChannel0004", "Ethernet20", 0)

self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0)
portchannels = [("0003", "Ethernet16", False),
("0004", "Ethernet20", True)]

# Create PortChannels
tbl = swsscommon.Table(self.cdb, "PORTCHANNEL")
fvs_base = [("admin_status", "up"), ("mtu", "9100"), ("oper_status", "up"), ("lacp_key", "auto")]

fvs_slow = swsscommon.FieldValuePairs(fvs_base + [("fast_rate", "false")])
tbl.set(portchannel_slow[0], fvs_slow)

fvs_fast = swsscommon.FieldValuePairs(fvs_base + [("fast_rate", "true")])
tbl.set(portchannel_fast[0], fvs_fast)
time.sleep(1)
for portchannel in portchannels:
self.dvs_lag.create_port_channel(portchannel[0], fast_rate=portchannel[2])
self.dvs_lag.get_and_verify_port_channel(len(portchannels))

# Add members to PortChannels
tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER")
fvs = swsscommon.FieldValuePairs([("NULL", "NULL")])

for portchannel in portchannel_slow, portchannel_fast:
tbl.set(portchannel[0] + "|" + portchannel[1], fvs)
time.sleep(1)
for portchannel in portchannels:
self.dvs_lag.create_port_channel_member(portchannel[0], portchannel[1])
self.dvs_lag.get_and_verify_port_channel_members(len(portchannels))

# test fast rate was not set on portchannel_slow
output = dvs.runcmd("teamdctl {} state dump".format(portchannel_slow[0]))[1]
port_state_dump = json.loads(output)
assert not port_state_dump["runner"]["fast_rate"]

# test fast rate was set on portchannel_fast
output = dvs.runcmd("teamdctl {} state dump".format(portchannel_fast[0]))[1]
port_state_dump = json.loads(output)
assert port_state_dump["runner"]["fast_rate"]
for portchannel in portchannels:
self.dvs_lag.get_and_verify_port_channel_fast_rate(portchannel[0], portchannel[2])

# remove PortChannel members
tbl = swsscommon.Table(self.cdb, "PORTCHANNEL_MEMBER")
for portchannel in portchannel_slow, portchannel_fast:
tbl._del(portchannel[0] + "|" + portchannel[1])
time.sleep(1)
for portchannel in portchannels:
self.dvs_lag.remove_port_channel(portchannel[0])
self.dvs_lag.get_and_verify_port_channel(0)

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

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

0 comments on commit 1a64d22

Please sign in to comment.