Skip to content

Commit

Permalink
Refactor the test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Zhenggen Xu <zxu@linkedin.com>
  • Loading branch information
zhenggen-xu committed Dec 12, 2019
1 parent 2681ab5 commit 6cf38f0
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 124 deletions.
103 changes: 100 additions & 3 deletions tests/port_dpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, dvs, name = None):
self._app_db_ptbl = swsscommon.Table(self._app_db, swsscommon.APP_PORT_TABLE_NAME)
self._asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
self._asic_db_ptbl = swsscommon.Table(self._asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT")
self._counters_db = redis.Redis(unix_socket_path=self._dvs.redis_sock, db=swsscommon.COUNTERS_DB)

def set_name(self, name):
self._name = name
Expand All @@ -51,6 +52,9 @@ def set_lanes(self, lanes):
def set_index(self, index):
self._index = index

def set_oid(self, oid = None):
self._oid = oid

def get_speed(self):
return self._speed

Expand Down Expand Up @@ -129,6 +133,7 @@ def port_split(self, child_ports):
def delete_from_config_db(self):
self._cfg_db_ptbl._del(self.get_name())
self._oid = None
time.sleep(2)

def sync_from_config_db(self):
(status, fvs) = self._cfg_db_ptbl.get(self.get_name())
Expand All @@ -149,6 +154,7 @@ def write_to_config_db(self):
("speed", speed_str),
("index", index_str)])
self._cfg_db_ptbl.set(self.get_name(), fvs)
time.sleep(1)

def get_fvs_dict(self, fvs):
fvs_dict = {}
Expand All @@ -165,9 +171,7 @@ def exists_in_app_db(self):
return status

def sync_oid(self):
if self._oid is None:
counter_redis_conn = redis.Redis(unix_socket_path=self._dvs.redis_sock, db=swsscommon.COUNTERS_DB)
self._oid = counter_redis_conn.hget("COUNTERS_PORT_NAME_MAP", self.get_name())
self._oid = self._counters_db.hget("COUNTERS_PORT_NAME_MAP", self.get_name())

def exists_in_asic_db(self):
self.sync_oid()
Expand Down Expand Up @@ -203,3 +207,96 @@ def verify_asic_db(self):
assert(fvs_dict['SAI_PORT_ATTR_HW_LANE_LIST'] == self.get_lanes_asic_db_str())
assert(fvs_dict['SAI_PORT_ATTR_SPEED'] == str(self.get_speed()))

class DPB():
def breakin(self, dvs, port_names):
child_ports = []
for pname in port_names:
cp = Port(dvs, pname)
cp.sync_from_config_db()
child_ports.append(cp)

for cp in child_ports:
cp.delete_from_config_db()
# TBD, need vs lib to support removing hostif
#dvs.runcmd("ip link delete " + cp.get_name())
#print "Deleted child ports:%s from config DB"%port_names

time.sleep(6)

for cp in child_ports:
assert(cp.exists_in_config_db() == False)
for cp in child_ports:
assert(cp.exists_in_app_db() == False)
for cp in child_ports:
assert(cp.exists_in_asic_db() == False)
#print "Verified child ports are deleted from all DBs"

p = Port(dvs)
p.port_merge(child_ports)
p.write_to_config_db()
#print "Added port:%s to config DB"%p.get_name()
time.sleep(2)

p.verify_config_db()
#print "Config DB verification passed!"

p.verify_app_db()
#print "Application DB verification passed!"

p.verify_asic_db()
#print "ASIC DB verification passed!"

def create_child_ports(self, dvs, p, num_child_ports):
# Create child ports and write to config DB
child_ports = p.port_split(num_child_ports)
child_port_names = []
for cp in child_ports:
cp.write_to_config_db()
child_port_names.append(cp.get_name())
#print "Added child ports:%s to config DB"%child_port_names
time.sleep(6)

for cp in child_ports:
assert(cp.exists_in_config_db() == True)
cp.verify_config_db()
#print "Config DB verification passed"
for cp in child_ports:
assert(cp.exists_in_app_db() == True)
cp.verify_app_db()
#print "APP DB verification passed"
for cp in child_ports:
assert(cp.exists_in_asic_db() == True)
cp.verify_asic_db()
#print "ASIC DB verification passed"

def breakout(self, dvs, port_name, num_child_ports):

p = Port(dvs, port_name)
p.sync_from_config_db()

# Delete port from config DB and kernel
p.delete_from_config_db()
# TBD, need vs lib to support hostif removal
#dvs.runcmd("ip link delete " + p.get_name())
#print "Deleted port:%s from config DB"%port_name
time.sleep(6)

# Verify port is deleted from all DBs
assert(p.exists_in_config_db() == False)
assert(p.exists_in_app_db() == False)
assert(p.exists_in_asic_db() == False)

self.create_child_ports(dvs, p, num_child_ports)


def change_speed_and_verify(self, dvs, port_names, speed = 100000):
for port_name in port_names:
p = Port(dvs, port_name)
p.sync_from_config_db()
p.set_speed(speed)
p.write_to_config_db()
p.verify_config_db()
time.sleep(1)
p.verify_app_db()
time.sleep(1)
p.verify_asic_db()
158 changes: 37 additions & 121 deletions tests/test_port_dpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,11 @@
from pytest import *
import json
import re
from port_dpb import Port
from port_dpb import DPB

@pytest.mark.usefixtures('dpb_setup_fixture')
class TestPortDPB(object):

def breakin(self, dvs, port_names):
child_ports = []
for pname in port_names:
cp = Port(dvs, pname)
cp.sync_from_config_db()
child_ports.append(cp)

for cp in child_ports:
cp.delete_from_config_db()
# TBD, need vs lib to support removing hostif
#dvs.runcmd("ip link delete " + cp.get_name())
print "Deleted child ports:%s from config DB"%port_names

time.sleep(6)

for cp in child_ports:
assert(cp.exists_in_config_db() == False)
for cp in child_ports:
assert(cp.exists_in_app_db() == False)
for cp in child_ports:
assert(cp.exists_in_asic_db() == False)
print "Verified child ports are deleted from all DBs"

p = Port(dvs)
p.port_merge(child_ports)
p.write_to_config_db()
print "Added port:%s to config DB"%p.get_name()
time.sleep(2)

p.verify_config_db()
print "Config DB verification passed!"

p.verify_app_db()
print "Application DB verification passed!"

p.verify_asic_db()
print "ASIC DB verification passed!"

def breakout(self, dvs, port_name, num_child_ports):

p = Port(dvs, port_name)
p.sync_from_config_db()

# Delete port from config DB and kernel
p.delete_from_config_db()
# TBD, need vs lib to support hostif removal
#dvs.runcmd("ip link delete " + p.get_name())
print "Deleted port:%s from config DB"%port_name
time.sleep(6)

# Verify port is deleted from all DBs
assert(p.exists_in_config_db() == False)
assert(p.exists_in_app_db() == False)
assert(p.exists_in_asic_db() == False)

# Create child ports and write to config DB
child_ports = p.port_split(num_child_ports)
child_port_names = []
for cp in child_ports:
cp.write_to_config_db()
child_port_names.append(cp.get_name())
print "Added child ports:%s to config DB"%child_port_names
time.sleep(6)

for cp in child_ports:
assert(cp.exists_in_config_db() == True)
cp.verify_config_db()
print "Config DB verification passed"
for cp in child_ports:
assert(cp.exists_in_app_db() == True)
cp.verify_app_db()
print "APP DB verification passed"
for cp in child_ports:
assert(cp.exists_in_asic_db() == True)
cp.verify_asic_db()
print "ASIC DB verification passed"

def change_speed_and_verify(self, dvs, port_names, speed = 100000):
for port_name in port_names:
p = Port(dvs, port_name)
p.sync_from_config_db()
p.set_speed(speed)
p.write_to_config_db()
p.verify_config_db()
time.sleep(1)
p.verify_app_db()
time.sleep(1)
p.verify_asic_db()

'''
|--------------------------------------------------
| | 1X100G | 1X40G | 4X10G | 4X25G | 2X50G |
Expand All @@ -124,52 +35,57 @@ def change_speed_and_verify(self, dvs, port_names, speed = 100000):
@pytest.mark.skip()
'''
def test_port_breakout_one(self, dvs):
self.breakout(dvs, "Ethernet0", 4)
print "**** 1X40G --> 4X10G passed ****"
self.change_speed_and_verify(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"], 25000)
print "**** 4X10G --> 4X25G passed ****"
self.change_speed_and_verify(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"], 10000)
print "**** 4X25G --> 4X10G passed ****"
self.breakin(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"])
print "**** 4X10G --> 1X40G passed ****"
self.change_speed_and_verify(dvs, ["Ethernet0"], 100000)
print "**** 1X40G --> 1X100G passed ****"
self.breakout(dvs, "Ethernet0", 4)
print "**** 1X100G --> 4X25G passed ****"
self.change_speed_and_verify(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"], 10000)
print "**** 4X25G --> 4X10G passed ****"
self.change_speed_and_verify(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"], 25000)
print "**** 4X10G --> 4X25G passed ****"
self.breakin(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"])
print "**** 4X25G --> 1X100G passed ****"
self.breakout(dvs, "Ethernet0", 2)
print "**** 1X100G --> 2X50G passed ****"
self.breakin(dvs, ["Ethernet0", "Ethernet2"])
print "**** 2X50G --> 1X100G passed ****"
self.change_speed_and_verify(dvs, ["Ethernet0"], 40000)
print "**** 1X100G --> 1X40G passed ****"
dpb = DPB()
dpb.breakout(dvs, "Ethernet0", 4)
#print "**** 1X40G --> 4X10G passed ****"
dpb.change_speed_and_verify(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"], 25000)
#print "**** 4X10G --> 4X25G passed ****"
dpb.change_speed_and_verify(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"], 10000)
#print "**** 4X25G --> 4X10G passed ****"
dpb.breakin(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"])
#print "**** 4X10G --> 1X40G passed ****"
dpb.change_speed_and_verify(dvs, ["Ethernet0"], 100000)
#print "**** 1X40G --> 1X100G passed ****"
dpb.breakout(dvs, "Ethernet0", 4)
#print "**** 1X100G --> 4X25G passed ****"
dpb.change_speed_and_verify(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"], 10000)
#print "**** 4X25G --> 4X10G passed ****"
dpb.change_speed_and_verify(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"], 25000)
#print "**** 4X10G --> 4X25G passed ****"
dpb.breakin(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"])
#print "**** 4X25G --> 1X100G passed ****"
dpb.breakout(dvs, "Ethernet0", 2)
#print "**** 1X100G --> 2X50G passed ****"
dpb.breakin(dvs, ["Ethernet0", "Ethernet2"])
#print "**** 2X50G --> 1X100G passed ****"
dpb.change_speed_and_verify(dvs, ["Ethernet0"], 40000)
#print "**** 1X100G --> 1X40G passed ****"

'''
@pytest.mark.skip()
'''
def test_port_breakout_multiple(self, dvs):
dpb = DPB()
port_names = ["Ethernet0", "Ethernet12", "Ethernet64", "Ethernet112"]
for pname in port_names:
self.breakout(dvs, pname, 4)
self.breakin(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"])
self.breakin(dvs, ["Ethernet12", "Ethernet13", "Ethernet14", "Ethernet15"])
self.breakin(dvs, ["Ethernet64", "Ethernet65", "Ethernet66", "Ethernet67"])
self.breakin(dvs, ["Ethernet112", "Ethernet113", "Ethernet114", "Ethernet115"])
dpb.breakout(dvs, pname, 4)
dpb.breakin(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"])
dpb.breakin(dvs, ["Ethernet12", "Ethernet13", "Ethernet14", "Ethernet15"])
dpb.breakin(dvs, ["Ethernet64", "Ethernet65", "Ethernet66", "Ethernet67"])
dpb.breakin(dvs, ["Ethernet112", "Ethernet113", "Ethernet114", "Ethernet115"])

'''
@pytest.mark.skip()
'''
def test_port_breakout_all(self, dvs):
dpb = DPB()
port_names = []
for i in range(32):
pname = "Ethernet" + str(i*4)
port_names.append(pname)

for pname in port_names:
self.breakout(dvs, pname, 4)
dpb.breakout(dvs, pname, 4)

child_port_names = []
for i in range(128):
Expand All @@ -179,4 +95,4 @@ def test_port_breakout_all(self, dvs):
for i in range(32):
start = i*4
end = start+4
self.breakin(dvs, child_port_names[start:end])
dpb.breakin(dvs, child_port_names[start:end])

0 comments on commit 6cf38f0

Please sign in to comment.