Skip to content

Commit

Permalink
Merge branch 'master' into phy-mibs
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox authored Oct 16, 2020
2 parents ca414df + 8507085 commit a11bf5c
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 99 deletions.
48 changes: 34 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,19 +70,28 @@ 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)
(state, c) = sel.select(SELECT_TIMEOUT)
(state, selectableObj) = sel.select(SELECT_TIMEOUT)

if state == swsscommon.Select.TIMEOUT:
# Do not flood log when select times out
Expand All @@ -86,17 +100,23 @@ class DaemonLedd(daemon_base.DaemonBase):
self.log_warning("sel.select() did not return swsscommon.Select.OBJECT")
continue

(key, op, fvp) = sst.pop()
# Get the redisselect object from selectable object
redisSelectObj = swsscommon.CastSelectableToRedisSelectObj(selectableObj)
# Get the corresponding namespace from redisselect db connector object
namespace = redisSelectObj.getDbConnector().getNamespace()

# TODO: Once these flag entries have been removed from the DB,
# we can remove this check
if key in ["PortConfigDone", "PortInitDone"]:
continue
(key, op, fvp) = sst[namespace].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
3 changes: 3 additions & 0 deletions sonic-ledd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
scripts=[
'scripts/ledd',
],
setup_requires= [
'wheel'
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: No Input/Output (Daemon)',
Expand Down
42 changes: 29 additions & 13 deletions sonic-pcied/scripts/pcied
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,36 @@ class DaemonPcied(DaemonBase):
self.state_db = swsssdk.SonicV2Connector(host=REDIS_HOSTIP)
self.state_db.connect("STATE_DB")

# Check the PCIe devices
def check_pcie_devices(self):
cmd = [ 'sudo', 'pcieutil', 'pcie-check' ]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
resultInfo, err = p.communicate()
pcie_db_state = self.read_state_db("PCIE_STATUS|", "PCIE_DEVICES")

for line in resultInfo.splitlines():
if PCIE_RESULT_REGEX in line:
if "PASSED" in line and "PASSED" not in pcie_db_state:
self.update_state_db("PCIE_STATUS|", "PCIE_DEVICES", "PASSED")
self.log_info("PCIe device status check : PASSED")
elif "FAILED" in line and "PASSED" in pcie_db_state:
self.update_state_db("PCIE_STATUS|", "PCIE_DEVICES", "FAILED")
self.log_info("PCIe device status check : FAILED")
try:
platform_path, _ = device_info.get_paths_to_platform_and_hwsku_dirs()
platform_plugins_path = os.path.join(platform_path, "plugins")
sys.path.append(os.path.abspath(platform_plugins_path))
from pcieutil import PcieUtil
except ImportError as e:
self.log_warning("Failed to load platform-specific PcieUtil module. Falling back to the common implementation")
try:
from sonic_platform_base.sonic_pcie.pcie_common import PcieUtil
platform_pcieutil = PcieUtil(platform_plugins_path)
except ImportError as e:
self.log_error("Failed to load default PcieUtil module. Error : {}".format(str(e)), True)
raise e

resultInfo = platform_pcieutil.get_pcie_check()
err = 0

for item in resultInfo:
if item["result"] == "Failed":
self.log_warning("PCIe Device: " + item["name"] + " Not Found")
err += 1

if err:
self.update_state_db("PCIE_DEVICES", "status", "FAILED")
self.log_error("PCIe device status check : FAILED")
else:
self.update_state_db("PCIE_DEVICES", "status", "PASSED")
self.log_info("PCIe device status check : PASSED")

def read_state_db(self, key1, key2):
return self.state_db.get('STATE_DB', key1, key2)
Expand Down
3 changes: 3 additions & 0 deletions sonic-pcied/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
scripts=[
'scripts/pcied',
],
setup_requires= [
'wheel'
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: No Input/Output (Daemon)',
Expand Down
12 changes: 6 additions & 6 deletions sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ def log_on_status_changed(logger, normal_status, normal_log, abnormal_log):
#
# PSU status ===================================================================
#
class PsuStatus(object):
def __init__(self, logger, psu):

class PsuStatus(logger.Logger):
def __init__(self, psu, log_identifier):
super(PsuStatus, self).__init__(log_identifier)
self.psu = psu
self.presence = True
self.power_good = True
self.voltage_good = True
self.temperature_good = True
self.logger = logger

def set_presence(self, presence):
"""
Expand Down Expand Up @@ -186,7 +186,7 @@ class PsuStatus(logger.Logger):
def set_voltage(self, voltage, high_threshold, low_threshold):
if not voltage or not high_threshold or not low_threshold:
if self.voltage_good is not True:
self.log_warning('PSU voltage or high_threshold or low_threshold become unavailable, '
self.logger.log_warning('PSU voltage or high_threshold or low_threshold become unavailable, '
'voltage={}, high_threshold={}, low_threshold={}'.format(voltage, high_threshold, low_threshold))
self.voltage_good = True
return False
Expand All @@ -201,7 +201,7 @@ class PsuStatus(logger.Logger):
def set_temperature(self, temperature, high_threshold):
if not temperature or not high_threshold:
if self.temperature_good is not True:
self.log_warning('PSU temperature or high_threshold become unavailable, '
self.logger.log_warning('PSU temperature or high_threshold become unavailable, '
'temperature={}, high_threshold={}'.format(temperature, high_threshold))
self.temperature_good = True
return False
Expand Down Expand Up @@ -328,7 +328,7 @@ class DaemonPsud(daemon_base.DaemonBase):
power = try_get(psu.get_power)

if index not in self.psu_status_dict:
self.psu_status_dict[index] = PsuStatus(psu, SYSLOG_IDENTIFIER)
self.psu_status_dict[index] = PsuStatus(self, psu)

psu_status = self.psu_status_dict[index]
set_led = False
Expand Down
3 changes: 3 additions & 0 deletions sonic-psud/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
scripts=[
'scripts/psud',
],
setup_requires= [
'wheel'
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: No Input/Output (Daemon)',
Expand Down
3 changes: 3 additions & 0 deletions sonic-syseepromd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
scripts=[
'scripts/syseepromd',
],
setup_requires= [
'wheel'
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: No Input/Output (Daemon)',
Expand Down
21 changes: 14 additions & 7 deletions sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,15 @@ class FanUpdater(logger.Logger):
if not is_psu_fan:
self._set_fan_led(parent, fan, fan_name, fan_status)

if fan_fault_status != NOT_AVAILABLE:
fan_fault_status = fan_status.is_ok()

fvs = swsscommon.FieldValuePairs(
[('presence', str(presence)),
('drawer_name', drawer_name),
('model', str(try_get(fan.get_model))),
('serial', str(try_get(fan.get_serial))),
('status', str(fan_fault_status and not(fan_status.under_speed or fan_status.over_speed))),
('status', str(fan_fault_status)),
('direction', str(fan_direction)),
('speed', str(speed)),
('speed_tolerance', str(speed_tolerance)),
Expand Down Expand Up @@ -697,6 +700,11 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
super(ThermalControlDaemon, self).__init__(log_identifier)
self.stop_event = threading.Event()

# Thermal control daemon is designed to never exit, it must always
# return non zero exit code when exiting and so that supervisord will
# restart it automatically.
self.exit_code = 1

# Signal handler
def signal_handler(self, sig, frame):
"""
Expand All @@ -707,11 +715,9 @@ class ThermalControlDaemon(daemon_base.DaemonBase):
"""
if sig == signal.SIGHUP:
self.log_info("Caught SIGHUP - ignoring...")
elif sig == signal.SIGINT:
self.log_info("Caught SIGINT - exiting...")
self.stop_event.set()
elif sig == signal.SIGTERM:
self.log_info("Caught SIGTERM - exiting...")
elif sig == signal.SIGINT or sig == signal.SIGTERM:
self.log_info("Caught signal {} - exiting...".format(sig))
self.exit_code = sig + 128
self.stop_event.set()
else:
self.log_warning("Caught unhandled signal '" + sig + "'")
Expand Down Expand Up @@ -765,7 +771,8 @@ class ThermalControlDaemon(daemon_base.DaemonBase):

thermal_monitor.task_stop()

self.log_info("Shutdown...")
self.log_info("Shutdown with exit code {}...".format(self.exit_code))
exit(self.exit_code)


#
Expand Down
3 changes: 2 additions & 1 deletion sonic-thermalctld/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'scripts/thermalctld',
],
setup_requires= [
'pytest-runner'
'pytest-runner',
'wheel'
],
tests_require = [
'pytest',
Expand Down
Loading

0 comments on commit a11bf5c

Please sign in to comment.