Skip to content

Commit d094cee

Browse files
jlevequelguohan
authored andcommitted
[docker-platform-monitor]: Add LED control daemon and plugin for x86_64-arista_7050_qx32 platform (#691)
* Add files for building ledd package; add ledd to docker-platform-monitor; Control platform monitor docker using supervisord * Add sonic-platform-daemons submodule * Rename ledd.mk -> sonic-ledd.mk * Add led_control.py plugin for x86_64-arista_7050_qx32 platform * Rename Dockerfile -> Dockerfile.j2 * Fix build * Remove blank line
1 parent 390591d commit d094cee

File tree

10 files changed

+163
-21
lines changed

10 files changed

+163
-21
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dockers/docker-fpm-gobgp/Dockerfile
3434
dockers/docker-fpm-quagga/Dockerfile
3535
dockers/docker-lldp-sv2/Dockerfile
3636
dockers/docker-orchagent/Dockerfile
37+
dockers/docker-platform-monitor/Dockerfile
3738
dockers/docker-snmp-sv2/Dockerfile
3839
dockers/docker-teamd/Dockerfile
3940
platform/*/docker-syncd-*/Dockerfile

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@
6060
path = src/SAI
6161
url = https://github.com/opencomputeproject/SAI
6262
branch = v0.9.4
63+
[submodule "src/sonic-platform-daemons"]
64+
path = src/sonic-platform-daemons
65+
url = https://github.com/Azure/sonic-platform-daemons
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
#
3+
# led_control.py
4+
#
5+
# Platform-specific LED control functionality for SONiC
6+
#
7+
8+
try:
9+
from sonic_led.led_control_base import LedControlBase
10+
except ImportError, e:
11+
raise ImportError (str(e) + " - required module not found")
12+
13+
14+
class LedControl(LedControlBase):
15+
"""Platform specific LED control class"""
16+
17+
SONIC_PORT_NAME_PREFIX = "Ethernet"
18+
19+
LED_SYSFS_PATH_BREAKOUT_CAPABLE = "/sys/class/leds/qsfp{0}_{1}/brightness"
20+
LED_SYSFS_PATH_NO_BREAKOUT = "/sys/class/leds/qsfp{0}/brightness"
21+
22+
QSFP_BREAKOUT_START_IDX = 1
23+
QSFP_BREAKOUT_END_IDX = 24
24+
QSFP_NO_BREAKOUT_START_IDX = 25
25+
QSFP_NO_BREAKOUT_END_IDX = 32
26+
27+
LED_COLOR_OFF = 0
28+
LED_COLOR_GREEN = 1
29+
LED_COLOR_YELLOW = 2
30+
31+
# Helper method to map SONiC port name to Arista QSFP index
32+
def _port_name_to_qsfp_index(self, port_name):
33+
# Strip "Ethernet" off port name
34+
if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX):
35+
return -1
36+
37+
sonic_port_num = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):])
38+
39+
# SONiC port nums are 0-based and increment by 4
40+
# Arista QSFP indices are 1-based and increment by 1
41+
return ((sonic_port_num/4) + 1)
42+
43+
# Concrete implementation of port_link_state_change() method
44+
def port_link_state_change(self, port, state):
45+
qsfp_index = self._port_name_to_qsfp_index(port)
46+
47+
# Ignore invalid QSFP indices
48+
if qsfp_index <= 0:
49+
return
50+
51+
# QSFP indices 1-24 are breakout-capable and have four LEDs,
52+
# whereas indices 25-32 are not breakout-capable, and only have one
53+
if qsfp_index <= self.QSFP_BREAKOUT_END_IDX:
54+
led_sysfs_path = self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, 1)
55+
else:
56+
led_sysfs_path = self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)
57+
58+
led_file = open(led_sysfs_path, "w")
59+
60+
if state == "up":
61+
led_file.write("%d" % self.LED_COLOR_GREEN)
62+
else:
63+
led_file.write("%d" % self.LED_COLOR_OFF)
64+
65+
led_file.close()
66+
67+
# Constructor
68+
def __init__(self):
69+
# Initialize: Turn all front panel QSFP LEDs off
70+
for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1):
71+
for lane in range(1, 5):
72+
led_sysfs_path = self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, lane)
73+
with open(led_sysfs_path, 'w') as led_file:
74+
led_file.write("%d" % self.LED_COLOR_OFF)
75+
76+
for qsfp_index in range(self.QSFP_NO_BREAKOUT_START_IDX, self.QSFP_NO_BREAKOUT_END_IDX + 1):
77+
led_sysfs_path = self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)
78+
with open(led_sysfs_path, 'w') as led_file:
79+
led_file.write("%d" % self.LED_COLOR_OFF)
80+

dockers/docker-platform-monitor/Dockerfile

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM docker-config-engine
2+
3+
# Make apt-get non-interactive
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# Update apt's package index files
7+
RUN apt-get update
8+
9+
RUN apt-get install -y python-pip sensord
10+
11+
{% if docker_platform_monitor_debs.strip() %}
12+
# Copy built Debian packages
13+
COPY \
14+
{% for deb in docker_platform_monitor_debs.split(' ') -%}
15+
debs/{{ deb }}{{' '}}
16+
{%- endfor -%}
17+
debs/
18+
{%- endif %}
19+
20+
{% if docker_platform_monitor_debs.strip() %}
21+
# Install built Debian packages
22+
RUN dpkg -i \
23+
{% for deb in docker_platform_monitor_debs.split(' ') -%}
24+
debs/{{ deb }}{{' '}}
25+
{%- endfor %}
26+
{%- endif %}
27+
28+
{% if docker_platform_monitor_whls.strip() %}
29+
# Copy built Python wheels
30+
COPY \
31+
{% for whl in docker_platform_monitor_whls.split(' ') -%}
32+
python-wheels/{{ whl }}{{' '}}
33+
{%- endfor -%}
34+
python-wheels/
35+
{%- endif %}
36+
37+
{% if docker_platform_monitor_whls.strip() %}
38+
# Install built Python wheels
39+
RUN pip install \
40+
{% for whl in docker_platform_monitor_whls.split(' ') -%}
41+
python-wheels/{{ whl }}{{' '}}
42+
{%- endfor %}
43+
{%- endif %}
44+
45+
COPY python-wheels /python-wheels
46+
47+
# Install Python SwSS SDK (dependency of sonic-ledd)
48+
RUN pip install /python-wheels/swsssdk-2.0.1-py2-none-any.whl
49+
50+
# Clean up
51+
RUN apt-get remove -y python-pip
52+
RUN apt-get clean -y
53+
RUN apt-get autoclean -y
54+
RUN apt-get autoremove -y
55+
RUN rm -rf /debs /python-wheels ~/.cache
56+
57+
COPY ["start.sh", "lm-sensors.sh", "/usr/bin/"]
58+
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
59+
60+
ENTRYPOINT ["/usr/bin/supervisord"]
61+

dockers/docker-platform-monitor/start.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mkdir -p /etc/sensors.d
44
if [ -e /usr/share/sonic/platform/sensors.conf ]; then
5-
/bin/cp -rf /usr/share/sonic/platform/sensors.conf /etc/sensors.d/
5+
/bin/cp -rf /usr/share/sonic/platform/sensors.conf /etc/sensors.d/
66
fi
77

88
mkdir -p /var/sonic
@@ -12,4 +12,5 @@ rm -f /var/run/rsyslogd.pid
1212

1313
supervisorctl start rsyslogd
1414
supervisorctl start lm-sensors
15+
supervisorctl start ledd
1516

dockers/docker-platform-monitor/supervisord.conf

+7
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ autorestart=false
2727
stdout_logfile=syslog
2828
stderr_logfile=syslog
2929

30+
[program:ledd]
31+
command=/usr/bin/ledd
32+
priority=6
33+
autostart=false
34+
stdout_logfile=syslog
35+
stderr_logfile=syslog
36+

rules/docker-platform-monitor.mk

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# docker platform monitor image
1+
# Docker image for SONiC platform monitoring tools
22

33
DOCKER_PLATFORM_MONITOR = docker-platform-monitor.gz
44
$(DOCKER_PLATFORM_MONITOR)_PATH = $(DOCKERS_PATH)/docker-platform-monitor
5+
$(DOCKER_PLATFORM_MONITOR)_DEPENDS += $(SONIC_LEDD)
56
$(DOCKER_PLATFORM_MONITOR)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE)
67

7-
SONIC_SIMPLE_DOCKER_IMAGES += $(DOCKER_PLATFORM_MONITOR)
8+
SONIC_DOCKER_IMAGES += $(DOCKER_PLATFORM_MONITOR)
89
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_PLATFORM_MONITOR)
910

1011
$(DOCKER_PLATFORM_MONITOR)_CONTAINER_NAME = pmon

rules/sonic-ledd.mk

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# sonic-ledd (SONiC Front-panel LED control daemon) Debian package
2+
3+
SONIC_LEDD = python-sonic-ledd_1.0-1_all.deb
4+
$(SONIC_LEDD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-ledd
5+
SONIC_PYTHON_STDEB_DEBS += $(SONIC_LEDD)

src/sonic-platform-daemons

Submodule sonic-platform-daemons added at bd7c310

0 commit comments

Comments
 (0)