19
19
from enum import Enum
20
20
from sonic_py_common import daemon_base , device_info , logger
21
21
from swsscommon import swsscommon
22
+ from sonic_py_common import multi_asic
22
23
except ImportError , e :
23
24
raise ImportError (str (e ) + " - required module not found" )
24
25
@@ -95,13 +96,32 @@ platform_chassis = None
95
96
# by DaemonXcvrd
96
97
helper_logger = logger .Logger (SYSLOG_IDENTIFIER )
97
98
98
- # MultiAsic class instance
99
- multi_asic = MultiAsic ()
99
+ # The empty namespace refers to linux host namespace.
100
+ EMPTY_NAMESPACE = ''
100
101
101
102
#
102
103
# Helper functions =============================================================
103
104
#
104
105
106
+ # Get namespaces, for single ASIC platform namespace is EMPTY_NAMESPACE
107
+ def get_front_end_namesapces ():
108
+ # Get the namespaces in the platform. For multi-asic devices we get the namespaces
109
+ # of front-end ascis which have front-panel interfaces.
110
+ namespaces = [EMPTY_NAMESPACE ]
111
+ if multi_asic .is_multi_asic ():
112
+ ns_list = multi_asic .get_all_namespaces ()
113
+ namespaces = ns_list ['front_ns' ]
114
+
115
+ return namespaces
116
+
117
+ # Get asic index from the namespace name
118
+ # With single ASIC platform, namespace is EMPTY_NAMESPACE, return index 0
119
+ def get_asic_id_from_namespace (namespace ):
120
+ if namespace == EMPTY_NAMESPACE :
121
+ return 0
122
+ else :
123
+ return multi_asic .get_asic_id_from_name (namespace )
124
+
105
125
# Find out the underneath physical port list by logical name
106
126
def logical_port_name_to_physical_port_list (port_name ):
107
127
if port_name .startswith ("Ethernet" ):
@@ -427,9 +447,9 @@ def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()):
427
447
transceiver_dict , state_db , appl_db , int_tbl , dom_tbl , app_port_tbl = {}, {}, {}, {}, {}, {}
428
448
429
449
# Get the namespaces in the platform
430
- namespaces = multi_asic . get_namespaces ()
450
+ namespaces = get_front_end_namesapces ()
431
451
for namespace in namespaces :
432
- asic_id = multi_asic . get_asic_id_from_namespace (namespace )
452
+ asic_id = get_asic_id_from_namespace (namespace )
433
453
state_db [asic_id ] = daemon_base .db_connect ("STATE_DB" , namespace )
434
454
appl_db [asic_id ] = daemon_base .db_connect ("APPL_DB" , namespace )
435
455
int_tbl [asic_id ] = swsscommon .Table (state_db [asic_id ], TRANSCEIVER_INFO_TABLE )
@@ -740,9 +760,9 @@ def init_port_sfp_status_tbl(stop_event=threading.Event()):
740
760
state_db , status_tbl = {},{}
741
761
742
762
# Get the namespaces in the platform
743
- namespaces = multi_asic . get_namespaces ()
763
+ namespaces = get_front_end_namesapces ()
744
764
for namespace in namespaces :
745
- asic_id = multi_asic . get_asic_id_from_namespace (namespace )
765
+ asic_id = get_asic_id_from_namespace (namespace )
746
766
state_db [asic_id ] = daemon_base .db_connect ("STATE_DB" , namespace )
747
767
status_tbl [asic_id ] = swsscommon .Table (state_db [asic_id ], TRANSCEIVER_STATUS_TABLE )
748
768
@@ -789,9 +809,9 @@ class DomInfoUpdateTask(object):
789
809
state_db , dom_tbl , status_tbl = {}, {}, {}
790
810
791
811
# Get the namespaces in the platform
792
- namespaces = multi_asic . get_namespaces ()
812
+ namespaces = get_front_end_namesapces ()
793
813
for namespace in namespaces :
794
- asic_id = multi_asic . get_asic_id_from_namespace (namespace )
814
+ asic_id = get_asic_id_from_namespace (namespace )
795
815
state_db [asic_id ] = daemon_base .db_connect ("STATE_DB" , namespace )
796
816
dom_tbl [asic_id ] = swsscommon .Table (state_db [asic_id ], TRANSCEIVER_DOM_SENSOR_TABLE )
797
817
status_tbl [asic_id ] = swsscommon .Table (state_db [asic_id ], TRANSCEIVER_STATUS_TABLE )
@@ -861,9 +881,9 @@ class SfpStateUpdateTask(object):
861
881
state_db , appl_db , int_tbl , dom_tbl , status_tbl , app_port_tbl = {}, {}, {}, {}, {}, {}
862
882
863
883
# Get the namespaces in the platform
864
- namespaces = multi_asic . get_namespaces ()
884
+ namespaces = get_front_end_namesapces ()
865
885
for namespace in namespaces :
866
- asic_id = multi_asic . get_asic_id_from_namespace (namespace )
886
+ asic_id = get_asic_id_from_namespace (namespace )
867
887
state_db [asic_id ] = daemon_base .db_connect ("STATE_DB" , namespace )
868
888
int_tbl [asic_id ] = swsscommon .Table (state_db [asic_id ], TRANSCEIVER_INFO_TABLE )
869
889
dom_tbl [asic_id ] = swsscommon .Table (state_db [asic_id ], TRANSCEIVER_DOM_SENSOR_TABLE )
@@ -1179,6 +1199,9 @@ class DaemonXcvrd(daemon_base.DaemonBase):
1179
1199
self .log_error ("Failed to load sfputil: %s" % (str (e )), True )
1180
1200
sys .exit (SFPUTIL_LOAD_ERROR )
1181
1201
1202
+ # Load the namespace details first from the database_global.json file.
1203
+ swsscommon .SonicDBConfig .initializeGlobalConfig ()
1204
+
1182
1205
# Load port info
1183
1206
try :
1184
1207
if multi_asic .is_multi_asic ():
@@ -1197,9 +1220,9 @@ class DaemonXcvrd(daemon_base.DaemonBase):
1197
1220
state_db , self .int_tbl , self .dom_tbl , self .status_tbl = {}, {}, {}, {}
1198
1221
1199
1222
# Get the namespaces in the platform
1200
- namespaces = multi_asic . get_namespaces ()
1223
+ namespaces = get_front_end_namesapces ()
1201
1224
for namespace in namespaces :
1202
- asic_id = multi_asic . get_asic_id_from_namespace (namespace )
1225
+ asic_id = get_asic_id_from_namespace (namespace )
1203
1226
state_db [asic_id ] = daemon_base .db_connect ("STATE_DB" , namespace )
1204
1227
self .int_tbl [asic_id ] = swsscommon .Table (state_db [asic_id ], TRANSCEIVER_INFO_TABLE )
1205
1228
self .dom_tbl [asic_id ] = swsscommon .Table (state_db [asic_id ], TRANSCEIVER_DOM_SENSOR_TABLE )
0 commit comments