Skip to content

Commit f01539d

Browse files
committed
[ppi]: Improve code coverage.
Signed-off-by: Nazarii Hnydyn <[email protected]>
1 parent e084923 commit f01539d

File tree

4 files changed

+361
-4
lines changed

4 files changed

+361
-4
lines changed

tests/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ def vct(request):
18581858
@pytest.fixture
18591859
def testlog(request, dvs):
18601860
dvs.runcmd(f"logger -t pytest === start test {request.node.nodeid} ===")
1861-
yield testlog
1861+
yield
18621862
dvs.runcmd(f"logger -t pytest === finish test {request.node.nodeid} ===")
18631863

18641864
################# DVSLIB module manager fixtures #############################
@@ -1903,6 +1903,7 @@ def dvs_vlan_manager(request, dvs):
19031903
@pytest.fixture(scope="class")
19041904
def dvs_port_manager(request, dvs):
19051905
request.cls.dvs_port = dvs_port.DVSPort(dvs.get_asic_db(),
1906+
dvs.get_app_db(),
19061907
dvs.get_config_db())
19071908

19081909

tests/dvslib/dvs_database.py

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
from typing import Dict, List
88
from swsscommon import swsscommon
9+
from swsscommon.swsscommon import SonicDBConfig
910
from dvslib.dvs_common import wait_for_result, PollingConfig
1011

1112

@@ -21,6 +22,12 @@ def __init__(self, db_id: int, connector: str):
2122
redis (e.g. UNIX socket, TCP socket, etc.).
2223
"""
2324
self.db_connection = swsscommon.DBConnector(db_id, connector, 0)
25+
self._separator = SonicDBConfig.getSeparator(self.db_connection)
26+
27+
@property
28+
def separator(self) -> str:
29+
"""Get DB separator."""
30+
return self._separator
2431

2532
def create_entry(self, table_name: str, key: str, entry: Dict[str, str]) -> None:
2633
"""Add the mapping {`key` -> `entry`} to the specified table.

tests/dvslib/dvs_port.py

+78-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1+
"""Utilities for interacting with PORT objects when writing VS tests."""
2+
from typing import Dict, List
3+
from swsscommon import swsscommon
4+
15

26
class DVSPort(object):
3-
def __init__(self, adb, cdb):
4-
self.asic_db = adb
5-
self.config_db = cdb
7+
"""Manage PORT objects on the virtual switch."""
8+
ASIC_DB = swsscommon.ASIC_DB
9+
APPL_DB = swsscommon.APPL_DB
10+
11+
CFGDB_PORT = "PORT"
12+
APPDB_PORT = "PORT_TABLE"
13+
ASICDB_PORT = "ASIC_STATE:SAI_OBJECT_TYPE_PORT"
14+
15+
def __init__(self, asicdb, appdb, cfgdb):
16+
self.asic_db = asicdb
17+
self.app_db = appdb
18+
self.config_db = cfgdb
19+
20+
def create_port_generic(
21+
self,
22+
port_name: str,
23+
lanes: str,
24+
speed: str,
25+
qualifiers: Dict[str, str] = {}
26+
) -> None:
27+
"""Create PORT in Config DB."""
28+
attr_dict = {
29+
"lanes": lanes,
30+
"speed": speed,
31+
**qualifiers
32+
}
33+
34+
self.config_db.create_entry(self.CFGDB_PORT, port_name, attr_dict)
35+
36+
def remove_port_generic(
37+
self,
38+
port_name: str
39+
)-> None:
40+
"""Remove PORT from Config DB."""
41+
self.config_db.delete_entry(self.CFGDB_PORT, port_name)
642

743
def remove_port(self, port_name):
844
self.config_db.delete_field("CABLE_LENGTH", "AZURE", port_name)
@@ -18,3 +54,42 @@ def remove_port(self, port_name):
1854
self.config_db.delete_entry("BREAKOUT_CFG|%s" % port_name, "")
1955
self.config_db.delete_entry("INTERFACE|%s" % port_name, "")
2056
self.config_db.delete_entry("PORT", port_name)
57+
58+
def update_port(
59+
self,
60+
port_name: str,
61+
attr_dict: Dict[str, str]
62+
) -> None:
63+
"""Update PORT in Config DB."""
64+
self.config_db.update_entry(self.CFGDB_PORT, port_name, attr_dict)
65+
66+
def get_port_ids(
67+
self,
68+
expected: int = None,
69+
dbid: int = swsscommon.ASIC_DB
70+
) -> List[str]:
71+
"""Get all of the PORT objects in ASIC/APP DB."""
72+
conn = None
73+
table = None
74+
75+
if dbid == swsscommon.ASIC_DB:
76+
conn = self.asic_db
77+
table = self.ASICDB_PORT
78+
elif dbid == swsscommon.APPL_DB:
79+
conn = self.app_db
80+
table = self.APPDB_PORT
81+
else:
82+
raise RuntimeError("Interface not implemented")
83+
84+
if expected is None:
85+
return conn.get_keys(table)
86+
87+
return conn.wait_for_n_keys(table, expected)
88+
89+
def verify_port_count(
90+
self,
91+
expected: int,
92+
dbid: int = swsscommon.ASIC_DB
93+
) -> None:
94+
"""Verify that there are N PORT objects in ASIC/APP DB."""
95+
self.get_port_ids(expected, dbid)

0 commit comments

Comments
 (0)