Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pmon daemons python3 build support #44

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dockers/docker-platform-monitor/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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_sensors and HAVE_SENSORS_CONF == 1 %}
[program:lm-sensors]
command=/usr/bin/lm-sensors.sh
Expand All @@ -48,7 +37,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 @@ -61,7 +50,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 @@ -74,15 +63,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' in python3_daemons %}python3 {% else %} python2 {% endif %}/usr/local/bin/xcvrd"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is no need for this python3_daemons variable. I think it is enough to check if API_VERSION == 3. What do we gain from python3_daemons? I feel like it is redundant and it will result in extra cleanup once we completely remove Python 2.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your concern. In Mellanox platform, some sfp related API depend on a python lib provided by SDK. That lib only supports python2 now (There is plan to migrate it to python3). In that case, xcvrd needs to be run as python2 for now on Mellanox platform. That's the reason I added python3_daemons here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I would like to prevent the need for all vendors to temporarily add this info, as Python 3 will be the default moving forward. Maybe it would be better to name the variable python2_daemons and invert the check here (e.g., and 'xcvrd' not in python2_daemons)? This way it is less work to switch to Python 3?

{% else %}
command=/usr/local/bin/xcvrd
command={% if API_VERSION == 3 and 'xcvrd' in python3_daemons %}python3 {% else %} python2 {% endif %}/usr/local/bin/xcvrd
{% endif %}
priority=6
autostart=false
Expand All @@ -91,38 +80,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' in python3_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' in python3_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' in python3_daemons %}python3 {% else %} python2 {% endif %}/usr/local/bin/thermalctld
priority=9
autostart=false
autorestart=unexpected
Expand All @@ -131,7 +120,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 @@ -144,5 +133,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 %}
78 changes: 62 additions & 16 deletions dockers/docker-platform-monitor/docker_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,85 @@ 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"

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

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

if [ -e $FANCONTROL_CONF_FILE ]; then
HAVE_FANCONTROL_CONF=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}"
# 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

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

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
50 changes: 0 additions & 50 deletions dockers/docker-platform-monitor/start.sh

This file was deleted.

20 changes: 13 additions & 7 deletions rules/docker-platform-monitor.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@ DOCKER_PLATFORM_MONITOR_DBG = $(DOCKER_PLATFORM_MONITOR_STEM)-$(DBG_IMAGE_MARK).

$(DOCKER_PLATFORM_MONITOR)_PATH = $(DOCKERS_PATH)/$(DOCKER_PLATFORM_MONITOR_STEM)

$(DOCKER_PLATFORM_MONITOR)_DEPENDS += $(LIBSENSORS) $(LM_SENSORS) $(FANCONTROL) $(SENSORD) $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON) $(SMARTMONTOOLS)
$(DOCKER_PLATFORM_MONITOR)_DEPENDS += $(LIBSENSORS) $(LM_SENSORS) $(FANCONTROL) $(SENSORD) $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON) $(PYTHON3_SWSSCOMMON) $(SMARTMONTOOLS)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_COMMON_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_COMMON_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
$(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)
ifeq ($(PDDF_SUPPORT),y)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(PDDF_PLATFORM_API_BASE_PY2)
endif
$(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)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS)
$(DOCKER_PLATFORM_MONITOR)_DBG_DEPENDS += $(LIBSWSSCOMMON_DBG) $(LIBSENSORS_DBG)
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)
18 changes: 12 additions & 6 deletions rules/sonic-pcied.dep
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
SPATH:= $($(SONIC_PCIED)_SRC_PATH)
SPATH:= $($(SONIC_PCIED_PY2)_SRC_PATH)
DEP_FILES:= $(SONIC_COMMON_FILES_LIST) rules/sonic-pcied.mk rules/sonic-pcied.dep
DEP_FILES+= $(SONIC_COMMON_BASE_FILES_LIST)
SMDEP_FILES:= $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files))

$(SONIC_PCIED)_CACHE_MODE:= GIT_CONTENT_SHA
$(SONIC_PCIED)_DEP_FLAGS:= $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_PCIED)_DEP_FILES:= $(DEP_FILES)
$(SONIC_PCIED)_SMDEP_FILES:= $(SMDEP_FILES)
$(SONIC_PCIED)_SMDEP_PATHS:= $(SPATH)
$(SONIC_PCIED_PY2)_CACHE_MODE:= GIT_CONTENT_SHA
$(SONIC_PCIED_PY2)_DEP_FLAGS:= $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_PCIED_PY2)_DEP_FILES:= $(DEP_FILES)
$(SONIC_PCIED_PY2)_SMDEP_FILES:= $(SMDEP_FILES)
$(SONIC_PCIED_PY2)_SMDEP_PATHS:= $(SPATH)

$(SONIC_PCIED_PY3)_CACHE_MODE:= GIT_CONTENT_SHA
$(SONIC_PCIED_PY3)_DEP_FLAGS:= $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_PCIED_PY3)_DEP_FILES:= $(DEP_FILES)
$(SONIC_PCIED_PY3)_SMDEP_FILES:= $(SMDEP_FILES)
$(SONIC_PCIED_PY3)_SMDEP_PATHS:= $(SPATH)
Loading