1
+ """Utilities for interacting with PORT objects when writing VS tests."""
2
+ from typing import Dict , List
3
+ from swsscommon import swsscommon
4
+
1
5
2
6
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 )
6
42
7
43
def remove_port (self , port_name ):
8
44
self .config_db .delete_field ("CABLE_LENGTH" , "AZURE" , port_name )
@@ -18,3 +54,42 @@ def remove_port(self, port_name):
18
54
self .config_db .delete_entry ("BREAKOUT_CFG|%s" % port_name , "" )
19
55
self .config_db .delete_entry ("INTERFACE|%s" % port_name , "" )
20
56
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