@@ -32,14 +32,18 @@ import sys
32
32
import os
33
33
import re
34
34
35
+ from utilities_common .general import load_db_config
36
+
35
37
# mock the redis for unit test purposes #
36
38
try : # pragma: no cover
37
- if os .environ ["UTILITIES_UNIT_TESTING" ] == "1" :
39
+ if os .environ ["UTILITIES_UNIT_TESTING" ] == "1" :
38
40
modules_path = os .path .join (os .path .dirname (__file__ ), ".." )
39
41
test_path = os .path .join (modules_path , "tests" )
40
42
sys .path .insert (0 , modules_path )
41
43
sys .path .insert (0 , test_path )
42
- import mock_tables .dbconnector
44
+ from tests .mock_tables import dbconnector
45
+
46
+ if os .environ ["FDBSHOW_UNIT_TESTING" ] == "1" :
43
47
mock_variants = { "1" : 'asic_db' ,
44
48
"2" : 'asic_db_def_vlan' ,
45
49
"3" : 'asic_db_no_fdb' ,
@@ -50,23 +54,38 @@ try: # pragma: no cover
50
54
mock_db_path = os .path .join (test_path , "fdbshow_input" )
51
55
file_name = mock_variants [os .environ ["FDBSHOW_MOCK" ]]
52
56
jsonfile_asic = os .path .join (mock_db_path , file_name )
53
- mock_tables . dbconnector .dedicated_dbs ['ASIC_DB' ] = jsonfile_asic
57
+ dbconnector .dedicated_dbs ['ASIC_DB' ] = jsonfile_asic
54
58
jsonfile_counters = os .path .join (mock_db_path , 'counters_db' )
55
- mock_tables .dbconnector .dedicated_dbs ['COUNTERS_DB' ] = jsonfile_counters
59
+ dbconnector .dedicated_dbs ['COUNTERS_DB' ] = jsonfile_counters
60
+
61
+ if os .environ ["UTILITIES_UNIT_TESTING_TOPOLOGY" ] == "multi_asic" :
62
+ import tests .mock_tables .mock_multi_asic
63
+ dbconnector .load_namespace_config ()
56
64
except KeyError : # pragma: no cover
57
65
pass
58
66
59
- from sonic_py_common import port_util
60
- from swsscommon .swsscommon import SonicV2Connector
67
+ from sonic_py_common import port_util , multi_asic
68
+ from swsscommon .swsscommon import SonicV2Connector , SonicDBConfig
61
69
from tabulate import tabulate
62
70
63
71
class FdbShow (object ):
64
72
65
73
HEADER = ['No.' , 'Vlan' , 'MacAddress' , 'Port' , 'Type' ]
66
74
67
- def __init__ (self ):
75
+ def __init__ (self , namespace = None ):
68
76
super (FdbShow ,self ).__init__ ()
69
- self .db = SonicV2Connector (host = "127.0.0.1" )
77
+ if namespace is not None :
78
+ if not multi_asic .is_multi_asic ():
79
+ print ("Error: Namespace is not supported in single asic" )
80
+ sys .exit (1 )
81
+
82
+ if not SonicDBConfig .isGlobalInit ():
83
+ SonicDBConfig .load_sonic_global_db_config ()
84
+
85
+ self .db = SonicV2Connector (use_unix_socket_path = True , namespace = namespace )
86
+ else :
87
+ self .db = SonicV2Connector (host = "127.0.0.1" )
88
+
70
89
self .if_name_map , \
71
90
self .if_oid_map = port_util .get_interface_oid_map (self .db )
72
91
self .if_br_oid_map = port_util .get_bridge_port_map (self .db )
@@ -169,7 +188,7 @@ class FdbShow(object):
169
188
170
189
print ("Total number of entries {0}" .format (len (self .bridge_mac_list )))
171
190
172
- def validate_params (self , vlan , port , address , entry_type ):
191
+ def validate_params (self , vlan , port , address , entry_type , namespace ):
173
192
if vlan is not None :
174
193
if not vlan .isnumeric ():
175
194
print ("Error: Invalid vlan id {0}" .format (vlan ))
@@ -205,11 +224,12 @@ def main():
205
224
parser .add_argument ('-a' , '--address' , type = str , help = 'FDB display based on specific mac address' , default = None )
206
225
parser .add_argument ('-t' , '--type' , type = str , help = 'FDB display of specific type of mac address' , default = None )
207
226
parser .add_argument ('-c' , '--count' , action = 'store_true' , help = 'FDB display count of mac address' )
227
+ parser .add_argument ('-n' , '--namespace' , type = str , help = 'Namespace name or all' , default = None )
208
228
args = parser .parse_args ()
209
229
210
230
try :
211
- fdb = FdbShow ()
212
- if not fdb .validate_params (args .vlan , args .port , args .address , args .type ):
231
+ fdb = FdbShow (namespace = args . namespace )
232
+ if not fdb .validate_params (args .vlan , args .port , args .address , args .type , args . namespace ):
213
233
sys .exit (1 )
214
234
215
235
fdb .display (args .vlan , args .port , args .address , args .type , args .count )
0 commit comments