Skip to content

Commit

Permalink
Add pmon daemons python3 build support (#6176)
Browse files Browse the repository at this point in the history
**- Why I did it**

python2 is end of life and SONiC is going to support python3. This PR is going to support:

1. Build pmon daemons with python3
2. Install and run python3 version pmon daemons

**- How I did it**

1. Change pmon daemons make files to build bothe python2 and python3 whl
2. Change docker-platform-monitor make files to install both python2 and python3 whl
3. Change pmon docker startup files to start pmon daemons according to the supported platform API version
  • Loading branch information
Junchao-Mellanox authored Dec 28, 2020
1 parent 721c68c commit 51f896b
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 179 deletions.
2 changes: 1 addition & 1 deletion dockers/docker-platform-monitor/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RUN apt-get purge -y \
/python-wheels \
~/.cache
COPY ["docker_init.sh", "lm-sensors.sh", "start.sh", "/usr/bin/"]
COPY ["docker_init.sh", "lm-sensors.sh", "/usr/bin/"]
COPY ["docker-pmon.supervisord.conf.j2", "/usr/share/sonic/templates/"]
COPY ["ssd_tools/*", "/usr/bin/"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
Expand Down
37 changes: 13 additions & 24 deletions dockers/docker-platform-monitor/docker-pmon.supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true

[program:start]
command=/usr/bin/start.sh
priority=2
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
startsecs=0
dependent_startup=true
dependent_startup_wait_for=rsyslogd:running

{% if not skip_chassisd and IS_MODULAR_CHASSIS == 1 %}
[program:chassisd]
command=/usr/local/bin/chassisd
Expand All @@ -61,7 +50,7 @@ stdout_logfile=syslog
stderr_logfile=syslog
startsecs=0
dependent_startup=true
dependent_startup_wait_for=start:exited
dependent_startup_wait_for=rsyslogd:running
{% endif %}

{% if not skip_fancontrol and HAVE_FANCONTROL_CONF == 1 %}
Expand All @@ -74,7 +63,7 @@ stdout_logfile=syslog
stderr_logfile=syslog
startsecs=10
dependent_startup=true
dependent_startup_wait_for=start:exited
dependent_startup_wait_for=rsyslogd:running
{% endif %}

{% if not skip_ledd %}
Expand All @@ -87,15 +76,15 @@ stdout_logfile=syslog
stderr_logfile=syslog
startsecs=0
dependent_startup=true
dependent_startup_wait_for=start:exited
dependent_startup_wait_for=rsyslogd:running
{% endif %}

{% if not skip_xcvrd %}
[program:xcvrd]
{% if delay_xcvrd %}
command=bash -c "sleep 30 && /usr/local/bin/xcvrd"
command=bash -c "sleep 30 && {% if API_VERSION == 3 and 'xcvrd' not in python2_daemons %}python3 {% else %} python2 {% endif %}/usr/local/bin/xcvrd"
{% else %}
command=/usr/local/bin/xcvrd
command={% if API_VERSION == 3 and 'xcvrd' not in python2_daemons %}python3 {% else %} python2 {% endif %}/usr/local/bin/xcvrd
{% endif %}
priority=6
autostart=false
Expand All @@ -104,38 +93,38 @@ stdout_logfile=syslog
stderr_logfile=syslog
startsecs=0
dependent_startup=true
dependent_startup_wait_for=start:exited
dependent_startup_wait_for=rsyslogd:running
{% endif %}

{% if not skip_psud %}
[program:psud]
command=/usr/local/bin/psud
command={% if API_VERSION == 3 and 'psud' not in python2_daemons %}python3 {% else %} python2 {% endif %}/usr/local/bin/psud
priority=7
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
startsecs=0
dependent_startup=true
dependent_startup_wait_for=start:exited
dependent_startup_wait_for=rsyslogd:running
{% endif %}

{% if not skip_syseepromd %}
[program:syseepromd]
command=/usr/local/bin/syseepromd
command={% if API_VERSION == 3 and 'syseepromd' not in python2_daemons %}python3 {% else %} python2 {% endif %}/usr/local/bin/syseepromd
priority=8
autostart=false
autorestart=unexpected
stdout_logfile=syslog
stderr_logfile=syslog
startsecs=10
dependent_startup=true
dependent_startup_wait_for=start:exited
dependent_startup_wait_for=rsyslogd:running
{% endif %}

{% if not skip_thermalctld %}
[program:thermalctld]
command=/usr/local/bin/thermalctld
command={% if API_VERSION == 3 and 'thermalctld' not in python2_daemons %}python3 {% else %} python2 {% endif %}/usr/local/bin/thermalctld
priority=9
autostart=false
autorestart=unexpected
Expand All @@ -144,7 +133,7 @@ stderr_logfile=syslog
startsecs=10
startretries=50
dependent_startup=true
dependent_startup_wait_for=start:exited
dependent_startup_wait_for=rsyslogd:running
{% endif %}

{% if not skip_pcied %}
Expand All @@ -157,5 +146,5 @@ stdout_logfile=syslog
stderr_logfile=syslog
startsecs=10
dependent_startup=true
dependent_startup_wait_for=start:exited
dependent_startup_wait_for=rsyslogd:running
{% endif %}
91 changes: 74 additions & 17 deletions dockers/docker-platform-monitor/docker_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,102 @@ mkdir -p /etc/supervisor/conf.d/

SENSORS_CONF_FILE="/usr/share/sonic/platform/sensors.conf"
FANCONTROL_CONF_FILE="/usr/share/sonic/platform/fancontrol"

SUPERVISOR_CONF_TEMPLATE="/usr/share/sonic/templates/docker-pmon.supervisord.conf.j2"
SUPERVISOR_CONF_FILE="/etc/supervisor/conf.d/supervisord.conf"
PMON_DAEMON_CONTROL_FILE="/usr/share/sonic/platform/pmon_daemon_control.json"
MODULAR_CHASSISDB_CONF_FILE="/usr/share/sonic/platform/chassisdb.conf"

HAVE_SENSORS_CONF=0
HAVE_FANCONTROL_CONF=0
IS_MODULAR_CHASSIS=0
# Default use python2 version
SONIC_PLATFORM_API_PYTHON_VERSION=2

if [ -e $SENSORS_CONF_FILE ]; then
HAVE_SENSORS_CONF=1
declare -r EXIT_SUCCESS="0"

if [ "${RUNTIME_OWNER}" == "" ]; then
RUNTIME_OWNER="kube"
fi

if [ -e $FANCONTROL_CONF_FILE ]; then
HAVE_FANCONTROL_CONF=1
CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py"
if test -f ${CTR_SCRIPT}
then
${CTR_SCRIPT} -f pmon -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION}
fi

if [ -e $MODULAR_CHASSISDB_CONF_FILE ]; then
IS_MODULAR_CHASSIS=1
mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status

# If this platform has synchronization script, run it
if [ -e /usr/share/sonic/platform/platform_wait ]; then
/usr/share/sonic/platform/platform_wait
EXIT_CODE="$?"
if [ "${EXIT_CODE}" != "${EXIT_SUCCESS}" ]; then
exit "${EXIT_CODE}"
fi
fi

confvar="{\"HAVE_SENSORS_CONF\":$HAVE_SENSORS_CONF, \"HAVE_FANCONTROL_CONF\":$HAVE_FANCONTROL_CONF, \"IS_MODULAR_CHASSIS\":$IS_MODULAR_CHASSIS}"
# If the Python 2 sonic-platform package is not installed, try to install it
python2 -c "import sonic_platform" > /dev/null 2>&1 || pip2 show sonic-platform > /dev/null 2>&1
if [ $? -ne 0 ]; then
SONIC_PLATFORM_WHEEL="/usr/share/sonic/platform/sonic_platform-1.0-py2-none-any.whl"
echo "sonic-platform package not installed, attempting to install..."
if [ -e ${SONIC_PLATFORM_WHEEL} ]; then
pip2 install ${SONIC_PLATFORM_WHEEL}
if [ $? -eq 0 ]; then
echo "Successfully installed ${SONIC_PLATFORM_WHEEL}"
else
echo "Error: Failed to install ${SONIC_PLATFORM_WHEEL}"
fi
else
echo "Error: Unable to locate ${SONIC_PLATFORM_WHEEL}"
fi
fi

if [ -e /usr/share/sonic/platform/pmon_daemon_control.json ];
then
sonic-cfggen -j /usr/share/sonic/platform/pmon_daemon_control.json -a "$confvar" -t /usr/share/sonic/templates/docker-pmon.supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
# If the Python 3 sonic-platform package is not installed, try to install it
python3 -c "import sonic_platform" > /dev/null 2>&1 || pip3 show sonic-platform > /dev/null 2>&1
if [ $? -ne 0 ]; then
SONIC_PLATFORM_WHEEL="/usr/share/sonic/platform/sonic_platform-1.0-py3-none-any.whl"
echo "sonic-platform package not installed, attempting to install..."
if [ -e ${SONIC_PLATFORM_WHEEL} ]; then
pip3 install ${SONIC_PLATFORM_WHEEL}
if [ $? -eq 0 ]; then
echo "Successfully installed ${SONIC_PLATFORM_WHEEL}"
SONIC_PLATFORM_API_PYTHON_VERSION=3
else
echo "Error: Failed to install ${SONIC_PLATFORM_WHEEL}"
fi
else
echo "Error: Unable to locate ${SONIC_PLATFORM_WHEEL}"
fi
else
sonic-cfggen -a "$confvar" -t /usr/share/sonic/templates/docker-pmon.supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
SONIC_PLATFORM_API_PYTHON_VERSION=3
fi

# If this platform has an lm-sensors config file, copy it to its proper place
if [ $HAVE_SENSORS_CONF -eq 1 ]; then
if [ -e $SENSORS_CONF_FILE ]; then
HAVE_SENSORS_CONF=1
mkdir -p /etc/sensors.d
/bin/cp -f $SENSORS_CONF_FILE /etc/sensors.d/
fi

# If this platform has a fancontrol config file, copy it to its proper place
if [ $HAVE_FANCONTROL_CONF -eq 1 ]; then
# Remove stale pid file if it exists
if [ -e $FANCONTROL_CONF_FILE ]; then
HAVE_FANCONTROL_CONF=1
rm -f /var/run/fancontrol.pid

/bin/cp -f $FANCONTROL_CONF_FILE /etc/
fi

if [ -e $MODULAR_CHASSISDB_CONF_FILE ]; then
IS_MODULAR_CHASSIS=1
fi

confvar="{\"HAVE_SENSORS_CONF\":$HAVE_SENSORS_CONF, \"HAVE_FANCONTROL_CONF\":$HAVE_FANCONTROL_CONF, \"API_VERSION\":$SONIC_PLATFORM_API_PYTHON_VERSION, \"IS_MODULAR_CHASSIS\":$IS_MODULAR_CHASSIS}"

if [ -e $PMON_DAEMON_CONTROL_FILE ];
then
sonic-cfggen -j $PMON_DAEMON_CONTROL_FILE -a "$confvar" -t $SUPERVISOR_CONF_TEMPLATE > $SUPERVISOR_CONF_FILE
else
sonic-cfggen -a "$confvar" -t $SUPERVISOR_CONF_TEMPLATE > $SUPERVISOR_CONF_FILE
fi

exec /usr/local/bin/supervisord
60 changes: 0 additions & 60 deletions dockers/docker-platform-monitor/start.sh

This file was deleted.

18 changes: 12 additions & 6 deletions rules/docker-platform-monitor.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_LEDD)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PCIED)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PSUD)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_SYSEEPROMD)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_THERMALCTLD)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_XCVRD)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_LEDD_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PCIED_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PSUD_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_SYSEEPROMD_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_THERMALCTLD_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_XCVRD_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_LEDD_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PCIED_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PSUD_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_SYSEEPROMD_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_THERMALCTLD_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_XCVRD_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_CHASSISD_PY3)

ifeq ($(PDDF_SUPPORT),y)
Expand Down
18 changes: 12 additions & 6 deletions rules/sonic-ledd.dep
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
SPATH := $($(SONIC_LEDD)_SRC_PATH)
SPATH := $($(SONIC_LEDD_PY2)_SRC_PATH)
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-ledd.mk rules/sonic-ledd.dep
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files))

$(SONIC_LEDD)_CACHE_MODE := GIT_CONTENT_SHA
$(SONIC_LEDD)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_LEDD)_DEP_FILES := $(DEP_FILES)
$(SONIC_LEDD)_SMDEP_FILES := $(SMDEP_FILES)
$(SONIC_LEDD)_SMDEP_PATHS := $(SPATH)
$(SONIC_LEDD_PY2)_CACHE_MODE := GIT_CONTENT_SHA
$(SONIC_LEDD_PY2)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_LEDD_PY2)_DEP_FILES := $(DEP_FILES)
$(SONIC_LEDD_PY2)_SMDEP_FILES := $(SMDEP_FILES)
$(SONIC_LEDD_PY2)_SMDEP_PATHS := $(SPATH)

$(SONIC_LEDD_PY3)_CACHE_MODE := GIT_CONTENT_SHA
$(SONIC_LEDD_PY3)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_LEDD_PY3)_DEP_FILES := $(DEP_FILES)
$(SONIC_LEDD_PY3)_SMDEP_FILES := $(SMDEP_FILES)
$(SONIC_LEDD_PY3)_SMDEP_PATHS := $(SPATH)
23 changes: 17 additions & 6 deletions rules/sonic-ledd.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# sonic-ledd (SONiC Front-panel LED control daemon) Debian package

SONIC_LEDD = sonic_ledd-1.1-py2-none-any.whl
$(SONIC_LEDD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-ledd
$(SONIC_LEDD)_DEPENDS = $(SONIC_PY_COMMON_PY2)
$(SONIC_LEDD)_DEBS_DEPENDS = $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON) $(PYTHON3_SWSSCOMMON)
$(SONIC_LEDD)_PYTHON_VERSION = 2
SONIC_PYTHON_WHEELS += $(SONIC_LEDD)
# SONIC_LEDD_PY2 package

SONIC_LEDD_PY2 = sonic_ledd-1.1-py2-none-any.whl
$(SONIC_LEDD_PY2)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-ledd
$(SONIC_LEDD_PY2)_DEPENDS = $(SONIC_PY_COMMON_PY2)
$(SONIC_LEDD_PY2)_DEBS_DEPENDS = $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON)
$(SONIC_LEDD_PY2)_PYTHON_VERSION = 2
SONIC_PYTHON_WHEELS += $(SONIC_LEDD_PY2)

# SONIC_LEDD_PY3 package

SONIC_LEDD_PY3 = sonic_ledd-1.1-py3-none-any.whl
$(SONIC_LEDD_PY3)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-ledd
$(SONIC_LEDD_PY3)_DEPENDS = $(SONIC_PY_COMMON_PY3) $(SONIC_LEDD_PY2)
$(SONIC_LEDD_PY3)_DEBS_DEPENDS = $(LIBSWSSCOMMON) $(PYTHON3_SWSSCOMMON)
$(SONIC_LEDD_PY3)_PYTHON_VERSION = 3
SONIC_PYTHON_WHEELS += $(SONIC_LEDD_PY3)
Loading

0 comments on commit 51f896b

Please sign in to comment.