diff --git a/.gitignore b/.gitignore index 481363b1e00a..2222458d1026 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ dockers/docker-fpm-gobgp/Dockerfile dockers/docker-fpm-quagga/Dockerfile dockers/docker-lldp-sv2/Dockerfile dockers/docker-orchagent/Dockerfile +dockers/docker-platform-monitor/Dockerfile dockers/docker-snmp-sv2/Dockerfile dockers/docker-teamd/Dockerfile platform/*/docker-syncd-*/Dockerfile diff --git a/.gitmodules b/.gitmodules index c35e478ae43f..99938c4abaca 100644 --- a/.gitmodules +++ b/.gitmodules @@ -60,3 +60,6 @@ path = src/SAI url = https://github.com/opencomputeproject/SAI branch = v0.9.4 +[submodule "src/sonic-platform-daemons"] + path = src/sonic-platform-daemons + url = https://github.com/Azure/sonic-platform-daemons diff --git a/device/arista/x86_64-arista_7050_qx32/plugins/led_control.py b/device/arista/x86_64-arista_7050_qx32/plugins/led_control.py new file mode 100644 index 000000000000..e246a2e61581 --- /dev/null +++ b/device/arista/x86_64-arista_7050_qx32/plugins/led_control.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# +# led_control.py +# +# Platform-specific LED control functionality for SONiC +# + +try: + from sonic_led.led_control_base import LedControlBase +except ImportError, e: + raise ImportError (str(e) + " - required module not found") + + +class LedControl(LedControlBase): + """Platform specific LED control class""" + + SONIC_PORT_NAME_PREFIX = "Ethernet" + + LED_SYSFS_PATH_BREAKOUT_CAPABLE = "/sys/class/leds/qsfp{0}_{1}/brightness" + LED_SYSFS_PATH_NO_BREAKOUT = "/sys/class/leds/qsfp{0}/brightness" + + QSFP_BREAKOUT_START_IDX = 1 + QSFP_BREAKOUT_END_IDX = 24 + QSFP_NO_BREAKOUT_START_IDX = 25 + QSFP_NO_BREAKOUT_END_IDX = 32 + + LED_COLOR_OFF = 0 + LED_COLOR_GREEN = 1 + LED_COLOR_YELLOW = 2 + + # Helper method to map SONiC port name to Arista QSFP index + def _port_name_to_qsfp_index(self, port_name): + # Strip "Ethernet" off port name + if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): + return -1 + + sonic_port_num = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):]) + + # SONiC port nums are 0-based and increment by 4 + # Arista QSFP indices are 1-based and increment by 1 + return ((sonic_port_num/4) + 1) + + # Concrete implementation of port_link_state_change() method + def port_link_state_change(self, port, state): + qsfp_index = self._port_name_to_qsfp_index(port) + + # Ignore invalid QSFP indices + if qsfp_index <= 0: + return + + # QSFP indices 1-24 are breakout-capable and have four LEDs, + # whereas indices 25-32 are not breakout-capable, and only have one + if qsfp_index <= self.QSFP_BREAKOUT_END_IDX: + led_sysfs_path = self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, 1) + else: + led_sysfs_path = self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) + + led_file = open(led_sysfs_path, "w") + + if state == "up": + led_file.write("%d" % self.LED_COLOR_GREEN) + else: + led_file.write("%d" % self.LED_COLOR_OFF) + + led_file.close() + + # Constructor + def __init__(self): + # Initialize: Turn all front panel QSFP LEDs off + for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1): + for lane in range(1, 5): + led_sysfs_path = self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, lane) + with open(led_sysfs_path, 'w') as led_file: + led_file.write("%d" % self.LED_COLOR_OFF) + + for qsfp_index in range(self.QSFP_NO_BREAKOUT_START_IDX, self.QSFP_NO_BREAKOUT_END_IDX + 1): + led_sysfs_path = self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) + with open(led_sysfs_path, 'w') as led_file: + led_file.write("%d" % self.LED_COLOR_OFF) + diff --git a/dockers/docker-platform-monitor/Dockerfile b/dockers/docker-platform-monitor/Dockerfile deleted file mode 100755 index 22eb4144cec5..000000000000 --- a/dockers/docker-platform-monitor/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM docker-config-engine - -## Make apt-get non-interactive -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt-get update - -RUN apt-get install -y sensord - -## Clean up -RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y -RUN rm -rf /debs - -COPY ["start.sh", "lm-sensors.sh", "/usr/bin/"] -COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] - -ENTRYPOINT ["/usr/bin/supervisord"] - diff --git a/dockers/docker-platform-monitor/Dockerfile.j2 b/dockers/docker-platform-monitor/Dockerfile.j2 new file mode 100755 index 000000000000..9b407bdef6bc --- /dev/null +++ b/dockers/docker-platform-monitor/Dockerfile.j2 @@ -0,0 +1,61 @@ +FROM docker-config-engine + +# Make apt-get non-interactive +ENV DEBIAN_FRONTEND=noninteractive + +# Update apt's package index files +RUN apt-get update + +RUN apt-get install -y python-pip sensord + +{% if docker_platform_monitor_debs.strip() %} +# Copy built Debian packages +COPY \ +{% for deb in docker_platform_monitor_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor -%} +debs/ +{%- endif %} + +{% if docker_platform_monitor_debs.strip() %} +# Install built Debian packages +RUN dpkg -i \ +{% for deb in docker_platform_monitor_debs.split(' ') -%} +debs/{{ deb }}{{' '}} +{%- endfor %} +{%- endif %} + +{% if docker_platform_monitor_whls.strip() %} +# Copy built Python wheels +COPY \ +{% for whl in docker_platform_monitor_whls.split(' ') -%} +python-wheels/{{ whl }}{{' '}} +{%- endfor -%} +python-wheels/ +{%- endif %} + +{% if docker_platform_monitor_whls.strip() %} +# Install built Python wheels +RUN pip install \ +{% for whl in docker_platform_monitor_whls.split(' ') -%} +python-wheels/{{ whl }}{{' '}} +{%- endfor %} +{%- endif %} + +COPY python-wheels /python-wheels + +# Install Python SwSS SDK (dependency of sonic-ledd) +RUN pip install /python-wheels/swsssdk-2.0.1-py2-none-any.whl + +# Clean up +RUN apt-get remove -y python-pip +RUN apt-get clean -y +RUN apt-get autoclean -y +RUN apt-get autoremove -y +RUN rm -rf /debs /python-wheels ~/.cache + +COPY ["start.sh", "lm-sensors.sh", "/usr/bin/"] +COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] + +ENTRYPOINT ["/usr/bin/supervisord"] + diff --git a/dockers/docker-platform-monitor/start.sh b/dockers/docker-platform-monitor/start.sh index 0e8a6dd32760..b550cc037a5d 100755 --- a/dockers/docker-platform-monitor/start.sh +++ b/dockers/docker-platform-monitor/start.sh @@ -2,7 +2,7 @@ mkdir -p /etc/sensors.d if [ -e /usr/share/sonic/platform/sensors.conf ]; then - /bin/cp -rf /usr/share/sonic/platform/sensors.conf /etc/sensors.d/ + /bin/cp -rf /usr/share/sonic/platform/sensors.conf /etc/sensors.d/ fi mkdir -p /var/sonic @@ -12,4 +12,5 @@ rm -f /var/run/rsyslogd.pid supervisorctl start rsyslogd supervisorctl start lm-sensors +supervisorctl start ledd diff --git a/dockers/docker-platform-monitor/supervisord.conf b/dockers/docker-platform-monitor/supervisord.conf index d4f21cf609fa..051829eae65f 100644 --- a/dockers/docker-platform-monitor/supervisord.conf +++ b/dockers/docker-platform-monitor/supervisord.conf @@ -27,3 +27,10 @@ autorestart=false stdout_logfile=syslog stderr_logfile=syslog +[program:ledd] +command=/usr/bin/ledd +priority=6 +autostart=false +stdout_logfile=syslog +stderr_logfile=syslog + diff --git a/rules/docker-platform-monitor.mk b/rules/docker-platform-monitor.mk index 09bec7125c08..39f8cdd3f297 100644 --- a/rules/docker-platform-monitor.mk +++ b/rules/docker-platform-monitor.mk @@ -1,10 +1,11 @@ -# docker platform monitor image +# Docker image for SONiC platform monitoring tools DOCKER_PLATFORM_MONITOR = docker-platform-monitor.gz $(DOCKER_PLATFORM_MONITOR)_PATH = $(DOCKERS_PATH)/docker-platform-monitor +$(DOCKER_PLATFORM_MONITOR)_DEPENDS += $(SONIC_LEDD) $(DOCKER_PLATFORM_MONITOR)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE) -SONIC_SIMPLE_DOCKER_IMAGES += $(DOCKER_PLATFORM_MONITOR) +SONIC_DOCKER_IMAGES += $(DOCKER_PLATFORM_MONITOR) SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_PLATFORM_MONITOR) $(DOCKER_PLATFORM_MONITOR)_CONTAINER_NAME = pmon diff --git a/rules/sonic-ledd.mk b/rules/sonic-ledd.mk new file mode 100644 index 000000000000..aa95b46cf478 --- /dev/null +++ b/rules/sonic-ledd.mk @@ -0,0 +1,5 @@ +# sonic-ledd (SONiC Front-panel LED control daemon) Debian package + +SONIC_LEDD = python-sonic-ledd_1.0-1_all.deb +$(SONIC_LEDD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-ledd +SONIC_PYTHON_STDEB_DEBS += $(SONIC_LEDD) diff --git a/src/sonic-platform-daemons b/src/sonic-platform-daemons new file mode 160000 index 000000000000..bd7c31075765 --- /dev/null +++ b/src/sonic-platform-daemons @@ -0,0 +1 @@ +Subproject commit bd7c310757658396ccfaaf653ede4a931b3d4154