Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform daemon changes for multi asic platform #64

Merged
merged 9 commits into from
Aug 25, 2020
45 changes: 31 additions & 14 deletions sonic-ledd/scripts/ledd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ try:
import sys

from sonic_py_common import daemon_base
from sonic_py_common import multi_asic
from sonic_py_common.interface import backplane_prefix
from swsscommon import swsscommon
except ImportError as e:
raise ImportError (str(e) + " - required module not found")
Expand All @@ -35,6 +37,9 @@ SELECT_TIMEOUT = 1000

LEDUTIL_LOAD_ERROR = 1

# The empty namespace refers to linux host namespace.
EMPTY_NAMESPACE = ''

class DaemonLedd(daemon_base.DaemonBase):

# Run daemon
Expand Down Expand Up @@ -65,15 +70,24 @@ class DaemonLedd(daemon_base.DaemonBase):
self.log_error("Failed to load ledutil: %s" % (str(e)), True)
sys.exit(LEDUTIL_LOAD_ERROR)

# Open a handle to the Application database
appl_db = daemon_base.db_connect("APPL_DB")
# Load the namespace details first from the database_global.json file.
swsscommon.SonicDBConfig.initializeGlobalConfig()

# Get the namespaces in the platform. For multi-asic devices we get the namespaces
# of front-end ascis which have front-panel interfaces.
namespaces = multi_asic.get_front_end_namespaces()

# Subscribe to PORT table notifications in the Application DB
appl_db, sst = {}, {}
sel = swsscommon.Select()
sst = swsscommon.SubscriberStateTable(appl_db, swsscommon.APP_PORT_TABLE_NAME)
sel.addSelectable(sst)

# Listen indefinitely for changes to the PORT table in the Application DB
for namespace in namespaces:
# Open a handle to the Application database, in all namespaces
appl_db[namespace] = daemon_base.db_connect("APPL_DB", namespace=namespace)
sst[namespace] = swsscommon.SubscriberStateTable(appl_db[namespace], swsscommon.APP_PORT_TABLE_NAME)
sel.addSelectable(sst[namespace])

# Listen indefinitely for changes to the PORT table in the Application DB's
while True:
# Use timeout to prevent ignoring the signals we want to handle
# in signal_handler() (e.g. SIGTERM for graceful shutdown)
Expand All @@ -86,17 +100,20 @@ class DaemonLedd(daemon_base.DaemonBase):
self.log_warning("sel.select() did not return swsscommon.Select.OBJECT")
continue

(key, op, fvp) = sst.pop()

# TODO: Once these flag entries have been removed from the DB,
# we can remove this check
if key in ["PortConfigDone", "PortInitDone"]:
continue
# Get the namespace from the selectable object and use it to index the SubscriberStateTable handle.
ns=c.getDbNamespace()
(key, op, fvp) = sst[ns].pop()
if fvp:
# TODO: Once these flag entries have been removed from the DB,
# we can remove this check
if key in ["PortConfigDone", "PortInitDone"]:
continue

fvp_dict = dict(fvp)
fvp_dict = dict(fvp)

if op == "SET" and "oper_status" in fvp_dict:
led_control.port_link_state_change(key, fvp_dict["oper_status"])
if op == "SET" and "oper_status" in fvp_dict:
if not key.startswith(backplane_prefix()):
led_control.port_link_state_change(key, fvp_dict["oper_status"])

return 1

Expand Down
Loading