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