Skip to content

Commit 5c122bc

Browse files
committed
Updated based on sonic-py-common
1 parent c52c5c1 commit 5c122bc

File tree

2 files changed

+50
-15
lines changed
  • sonic-ledd/scripts
  • sonic-xcvrd/scripts

2 files changed

+50
-15
lines changed

sonic-ledd/scripts/ledd

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ try:
1010
import sys
1111

1212
from sonic_py_common import daemon_base
13+
from sonic_py_common import multi_asic
14+
from sonic_py_common.interface import backplane_prefix
1315
from swsscommon import swsscommon
1416
except ImportError, e:
1517
raise ImportError (str(e) + " - required module not found")
@@ -35,6 +37,9 @@ SELECT_TIMEOUT = 1000
3537

3638
LEDUTIL_LOAD_ERROR = 1
3739

40+
# The empty namespace refers to linux host namespace.
41+
EMPTY_NAMESPACE = ''
42+
3843
class DaemonLedd(daemon_base.DaemonBase):
3944

4045
# Run daemon
@@ -65,8 +70,15 @@ class DaemonLedd(daemon_base.DaemonBase):
6570
self.log_error("Failed to load ledutil: %s" % (str(e)), True)
6671
sys.exit(LEDUTIL_LOAD_ERROR)
6772

68-
# Get the namespaces in the platform
69-
namespaces = multi_asic.get_namespaces()
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 = [EMPTY_NAMESPACE]
79+
if multi_asic.is_multi_asic():
80+
ns_list = multi_asic.get_all_namespaces()
81+
namespaces = ns_list['front_ns']
7082

7183
# Subscribe to PORT table notifications in the Application DB
7284
appl_db, sst = {}, {}
@@ -103,7 +115,7 @@ class DaemonLedd(daemon_base.DaemonBase):
103115
fvp_dict = dict(fvp)
104116

105117
if op == "SET" and "oper_status" in fvp_dict:
106-
if not key.startswith(daemon_base.get_internal_interface_prefix()):
118+
if not key.startswith(backplane_prefix()):
107119
led_control.port_link_state_change(key, fvp_dict["oper_status"])
108120

109121
return 1

sonic-xcvrd/scripts/xcvrd

+35-12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ try:
1919
from enum import Enum
2020
from sonic_py_common import daemon_base, device_info, logger
2121
from swsscommon import swsscommon
22+
from sonic_py_common import multi_asic
2223
except ImportError, e:
2324
raise ImportError (str(e) + " - required module not found")
2425

@@ -95,13 +96,32 @@ platform_chassis = None
9596
# by DaemonXcvrd
9697
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)
9798

98-
# MultiAsic class instance
99-
multi_asic = MultiAsic()
99+
# The empty namespace refers to linux host namespace.
100+
EMPTY_NAMESPACE = ''
100101

101102
#
102103
# Helper functions =============================================================
103104
#
104105

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+
105125
# Find out the underneath physical port list by logical name
106126
def logical_port_name_to_physical_port_list(port_name):
107127
if port_name.startswith("Ethernet"):
@@ -427,9 +447,9 @@ def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()):
427447
transceiver_dict, state_db, appl_db, int_tbl, dom_tbl, app_port_tbl = {}, {}, {}, {}, {}, {}
428448

429449
# Get the namespaces in the platform
430-
namespaces = multi_asic.get_namespaces()
450+
namespaces = get_front_end_namesapces()
431451
for namespace in namespaces:
432-
asic_id = multi_asic.get_asic_id_from_namespace(namespace)
452+
asic_id = get_asic_id_from_namespace(namespace)
433453
state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
434454
appl_db[asic_id] = daemon_base.db_connect("APPL_DB", namespace)
435455
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()):
740760
state_db, status_tbl = {},{}
741761

742762
# Get the namespaces in the platform
743-
namespaces = multi_asic.get_namespaces()
763+
namespaces = get_front_end_namesapces()
744764
for namespace in namespaces:
745-
asic_id = multi_asic.get_asic_id_from_namespace(namespace)
765+
asic_id = get_asic_id_from_namespace(namespace)
746766
state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
747767
status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE)
748768

@@ -789,9 +809,9 @@ class DomInfoUpdateTask(object):
789809
state_db, dom_tbl, status_tbl = {}, {}, {}
790810

791811
# Get the namespaces in the platform
792-
namespaces = multi_asic.get_namespaces()
812+
namespaces = get_front_end_namesapces()
793813
for namespace in namespaces:
794-
asic_id = multi_asic.get_asic_id_from_namespace(namespace)
814+
asic_id = get_asic_id_from_namespace(namespace)
795815
state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
796816
dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE)
797817
status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE)
@@ -861,9 +881,9 @@ class SfpStateUpdateTask(object):
861881
state_db, appl_db, int_tbl, dom_tbl, status_tbl, app_port_tbl = {}, {}, {}, {}, {}, {}
862882

863883
# Get the namespaces in the platform
864-
namespaces = multi_asic.get_namespaces()
884+
namespaces = get_front_end_namesapces()
865885
for namespace in namespaces:
866-
asic_id = multi_asic.get_asic_id_from_namespace(namespace)
886+
asic_id = get_asic_id_from_namespace(namespace)
867887
state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
868888
int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE)
869889
dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE)
@@ -1179,6 +1199,9 @@ class DaemonXcvrd(daemon_base.DaemonBase):
11791199
self.log_error("Failed to load sfputil: %s" % (str(e)), True)
11801200
sys.exit(SFPUTIL_LOAD_ERROR)
11811201

1202+
# Load the namespace details first from the database_global.json file.
1203+
swsscommon.SonicDBConfig.initializeGlobalConfig()
1204+
11821205
# Load port info
11831206
try:
11841207
if multi_asic.is_multi_asic():
@@ -1197,9 +1220,9 @@ class DaemonXcvrd(daemon_base.DaemonBase):
11971220
state_db, self.int_tbl, self.dom_tbl, self.status_tbl = {}, {}, {}, {}
11981221

11991222
# Get the namespaces in the platform
1200-
namespaces = multi_asic.get_namespaces()
1223+
namespaces = get_front_end_namesapces()
12011224
for namespace in namespaces:
1202-
asic_id = multi_asic.get_asic_id_from_namespace(namespace)
1225+
asic_id = get_asic_id_from_namespace(namespace)
12031226
state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
12041227
self.int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE)
12051228
self.dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE)

0 commit comments

Comments
 (0)