10
10
import sys
11
11
12
12
from sonic_py_common import daemon_base
13
+ from sonic_py_common import multi_asic
14
+ from sonic_py_common .interface import backplane_prefix
13
15
from swsscommon import swsscommon
14
16
except ImportError as e :
15
17
raise ImportError (str (e ) + " - required module not found" )
@@ -35,6 +37,9 @@ SELECT_TIMEOUT = 1000
35
37
36
38
LEDUTIL_LOAD_ERROR = 1
37
39
40
+ # The empty namespace refers to linux host namespace.
41
+ EMPTY_NAMESPACE = ''
42
+
38
43
class DaemonLedd (daemon_base .DaemonBase ):
39
44
40
45
# Run daemon
@@ -65,15 +70,24 @@ class DaemonLedd(daemon_base.DaemonBase):
65
70
self .log_error ("Failed to load ledutil: %s" % (str (e )), True )
66
71
sys .exit (LEDUTIL_LOAD_ERROR )
67
72
68
- # Open a handle to the Application database
69
- appl_db = daemon_base .db_connect ("APPL_DB" )
73
+ # Load the namespace details first from the database_global.json file.
74
+ swsscommon .SonicDBConfig .initializeGlobalConfig ()
75
+
76
+ # Get the namespaces in the platform. For multi-asic devices we get the namespaces
77
+ # of front-end ascis which have front-panel interfaces.
78
+ namespaces = multi_asic .get_front_end_namespaces ()
70
79
71
80
# Subscribe to PORT table notifications in the Application DB
81
+ appl_db , sst = {}, {}
72
82
sel = swsscommon .Select ()
73
- sst = swsscommon .SubscriberStateTable (appl_db , swsscommon .APP_PORT_TABLE_NAME )
74
- sel .addSelectable (sst )
75
83
76
- # Listen indefinitely for changes to the PORT table in the Application DB
84
+ for namespace in namespaces :
85
+ # Open a handle to the Application database, in all namespaces
86
+ appl_db [namespace ] = daemon_base .db_connect ("APPL_DB" , namespace = namespace )
87
+ sst [namespace ] = swsscommon .SubscriberStateTable (appl_db [namespace ], swsscommon .APP_PORT_TABLE_NAME )
88
+ sel .addSelectable (sst [namespace ])
89
+
90
+ # Listen indefinitely for changes to the PORT table in the Application DB's
77
91
while True :
78
92
# Use timeout to prevent ignoring the signals we want to handle
79
93
# in signal_handler() (e.g. SIGTERM for graceful shutdown)
@@ -86,17 +100,20 @@ class DaemonLedd(daemon_base.DaemonBase):
86
100
self .log_warning ("sel.select() did not return swsscommon.Select.OBJECT" )
87
101
continue
88
102
89
- (key , op , fvp ) = sst .pop ()
90
-
91
- # TODO: Once these flag entries have been removed from the DB,
92
- # we can remove this check
93
- if key in ["PortConfigDone" , "PortInitDone" ]:
94
- continue
103
+ # Get the namespace from the selectable object and use it to index the SubscriberStateTable handle.
104
+ ns = c .getDbNamespace ()
105
+ (key , op , fvp ) = sst [ns ].pop ()
106
+ if fvp :
107
+ # TODO: Once these flag entries have been removed from the DB,
108
+ # we can remove this check
109
+ if key in ["PortConfigDone" , "PortInitDone" ]:
110
+ continue
95
111
96
- fvp_dict = dict (fvp )
112
+ fvp_dict = dict (fvp )
97
113
98
- if op == "SET" and "oper_status" in fvp_dict :
99
- led_control .port_link_state_change (key , fvp_dict ["oper_status" ])
114
+ if op == "SET" and "oper_status" in fvp_dict :
115
+ if not key .startswith (backplane_prefix ()):
116
+ led_control .port_link_state_change (key , fvp_dict ["oper_status" ])
100
117
101
118
return 1
102
119
0 commit comments