From 09212110097db3104cf4848205ef48100b7db5be Mon Sep 17 00:00:00 2001 From: stepanblyschak <38952541+stepanblyschak@users.noreply.github.com> Date: Fri, 18 Jan 2019 00:41:32 +0200 Subject: [PATCH] [mellanox|ffb] ISSU version check (#2437) * Revert "[mellanox]: Integrate CRIU tool to SYNCD docker container (#2061)" This reverts commit 514b38f348f396737901c51e8b6d2f5b32d05ab6. Conflicts: platform/mellanox/docker-syncd-mlnx.mk sonic-slave/Dockerfile * [mellanox|ffb] remove unused scripts Signed-off-by: Stepan Blyschak * [mellanox|ffb] ISSU version check Signed-off-by: Stepan Blyschak * [mlnx|ffb] remove extra ';' Signed-off-by: Stepan Blyschak --- .../build_templates/sonic_debian_extension.j2 | 2 +- platform/mellanox/criu.mk | 8 - platform/mellanox/criu/Makefile | 14 -- platform/mellanox/docker-syncd-mlnx-rpc.mk | 2 +- platform/mellanox/docker-syncd-mlnx.mk | 4 +- .../mellanox/docker-syncd-mlnx/Dockerfile.j2 | 2 +- platform/mellanox/issu-version.mk | 9 + platform/mellanox/issu-version/Makefile | 12 ++ platform/mellanox/mlnx-ffb.sh | 52 ++---- platform/mellanox/mlnx-issu.mk | 5 - platform/mellanox/mlnx-issu/scripts/issu | 176 ------------------ platform/mellanox/mlnx-issu/setup.py | 14 -- platform/mellanox/one-image.mk | 2 +- platform/mellanox/rules.mk | 2 +- platform/mellanox/sdk-version.j2 | 1 - platform/mellanox/sdk.mk | 1 - sonic-slave/Dockerfile | 13 -- 17 files changed, 47 insertions(+), 272 deletions(-) delete mode 100644 platform/mellanox/criu.mk delete mode 100644 platform/mellanox/criu/Makefile create mode 100644 platform/mellanox/issu-version.mk create mode 100644 platform/mellanox/issu-version/Makefile delete mode 100755 platform/mellanox/mlnx-issu.mk delete mode 100755 platform/mellanox/mlnx-issu/scripts/issu delete mode 100755 platform/mellanox/mlnx-issu/setup.py delete mode 100755 platform/mellanox/sdk-version.j2 diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index ed8df864cd..4ef014a30e 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -319,9 +319,9 @@ sudo cp {{src}} $FILESYSTEM_ROOT/{{dst}} {% if sonic_asic_platform == "mellanox" %} sudo mkdir -p $FILESYSTEM_ROOT/etc/mlnx/ sudo cp target/files/$MLNX_FW_FILE $FILESYSTEM_ROOT/etc/mlnx/fw-SPC.mfa +sudo cp target/files/$ISSU_VERSION_FILE $FILESYSTEM_ROOT/etc/mlnx/issu-version sudo cp target/files/$MLNX_FFB_SCRIPT $FILESYSTEM_ROOT/usr/bin/mlnx-ffb.sh j2 platform/mellanox/mlnx-fw-upgrade.j2 | sudo tee $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh -j2 platform/mellanox/sdk-version.j2 | sudo tee $FILESYSTEM_ROOT/etc/mlnx/sdk-version sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh {% endif %} diff --git a/platform/mellanox/criu.mk b/platform/mellanox/criu.mk deleted file mode 100644 index 01a425bb2a..0000000000 --- a/platform/mellanox/criu.mk +++ /dev/null @@ -1,8 +0,0 @@ -CRIU_VERSION = 3.10 - -export CRIU_VERSION - -CRIU = criu_$(CRIU_VERSION)-1_amd64.deb -$(CRIU)_SRC_PATH = $(PLATFORM_PATH)/criu -$(CRIU)_DEPENDS += $(LIBNL3_DEV) -SONIC_MAKE_DEBS += $(CRIU) diff --git a/platform/mellanox/criu/Makefile b/platform/mellanox/criu/Makefile deleted file mode 100644 index e9d49b5690..0000000000 --- a/platform/mellanox/criu/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -.ONESHELL: -SHELL = /bin/bash -.SHELLFLAGS += -e - -MAIN_TARGET = criu_$(CRIU_VERSION)-1_amd64.deb - -CRIU_DEPS = iptables,protobuf-c-compiler,protobuf-compiler,python-protobuf,libprotobuf-c1,python-future,python-ipaddr,libnet1,pkg-config,asciidoc,xmlto - -$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% : - rm -rf criu - git clone -b v$(CRIU_VERSION) https://github.com/checkpoint-restore/criu.git - pushd criu - RUNDIR=/run/criu make - sudo checkinstall --default --install=no --fstrans=no --pkgversion=$(CRIU_VERSION) --maintainer='@' --requires=$(CRIU_DEPS) --pakdir=$(DEST) diff --git a/platform/mellanox/docker-syncd-mlnx-rpc.mk b/platform/mellanox/docker-syncd-mlnx-rpc.mk index b11c5a8c0d..fc0f6239d5 100644 --- a/platform/mellanox/docker-syncd-mlnx-rpc.mk +++ b/platform/mellanox/docker-syncd-mlnx-rpc.mk @@ -2,7 +2,7 @@ DOCKER_SYNCD_MLNX_RPC = docker-syncd-mlnx-rpc.gz $(DOCKER_SYNCD_MLNX_RPC)_PATH = $(PLATFORM_PATH)/docker-syncd-mlnx-rpc -$(DOCKER_SYNCD_MLNX_RPC)_DEPENDS += $(SYNCD_RPC) $(LIBTHRIFT) $(MLNX_SFPD) $(MLNX_ISSU) +$(DOCKER_SYNCD_MLNX_RPC)_DEPENDS += $(SYNCD_RPC) $(LIBTHRIFT) $(MLNX_SFPD) $(DOCKER_SYNCD_MLNX_RPC)_LOAD_DOCKERS += $(DOCKER_SYNCD_MLNX) SONIC_DOCKER_IMAGES += $(DOCKER_SYNCD_MLNX_RPC) ifeq ($(ENABLE_SYNCD_RPC),y) diff --git a/platform/mellanox/docker-syncd-mlnx.mk b/platform/mellanox/docker-syncd-mlnx.mk index dd11f32f71..da217492d4 100644 --- a/platform/mellanox/docker-syncd-mlnx.mk +++ b/platform/mellanox/docker-syncd-mlnx.mk @@ -2,7 +2,7 @@ DOCKER_SYNCD_MLNX = docker-syncd-mlnx.gz $(DOCKER_SYNCD_MLNX)_PATH = $(PLATFORM_PATH)/docker-syncd-mlnx -$(DOCKER_SYNCD_MLNX)_DEPENDS += $(SYNCD) $(PYTHON_SDK_API) $(MLNX_SFPD) $(CRIU) $(MLNX_ISSU) +$(DOCKER_SYNCD_MLNX)_DEPENDS += $(SYNCD) $(PYTHON_SDK_API) $(MLNX_SFPD) $(DOCKER_SYNCD_MLNX)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE) SONIC_DOCKER_IMAGES += $(DOCKER_SYNCD_MLNX) ifneq ($(ENABLE_SYNCD_RPC),y) @@ -14,4 +14,4 @@ $(DOCKER_SYNCD_MLNX)_RUN_OPT += --net=host --privileged -t $(DOCKER_SYNCD_MLNX)_RUN_OPT += -v /host/machine.conf:/etc/machine.conf $(DOCKER_SYNCD_MLNX)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro $(DOCKER_SYNCD_MLNX)_RUN_OPT += -v /host/warmboot:/var/warmboot -$(DOCKER_SYNCD_MLNX)_RUN_OPT += --tmpfs /run/criu + diff --git a/platform/mellanox/docker-syncd-mlnx/Dockerfile.j2 b/platform/mellanox/docker-syncd-mlnx/Dockerfile.j2 index bf301f179a..971602a212 100755 --- a/platform/mellanox/docker-syncd-mlnx/Dockerfile.j2 +++ b/platform/mellanox/docker-syncd-mlnx/Dockerfile.j2 @@ -14,7 +14,7 @@ debs/{{ deb }}{{' '}} {%- endfor -%} debs/ -RUN apt-get install -y --no-install-recommends libxml2 iptables libbsd0 protobuf-c-compiler protobuf-compiler python-protobuf libprotobuf-c1 python-future python-ipaddr libnet1 pkg-config asciidoc xmlto +RUN apt-get install -y libxml2 RUN dpkg -i \ {% for deb in docker_syncd_mlnx_debs.split(' ') -%} diff --git a/platform/mellanox/issu-version.mk b/platform/mellanox/issu-version.mk new file mode 100644 index 0000000000..c7ae4296ab --- /dev/null +++ b/platform/mellanox/issu-version.mk @@ -0,0 +1,9 @@ +# ISSU version + +ISSU_VERSION_FILE = issu-version +$(ISSU_VERSION_FILE)_SRC_PATH = $(PLATFORM_PATH)/issu-version +$(ISSU_VERSION_FILE)_DEPENDS += $(APPLIBS) +SONIC_MAKE_FILES += $(ISSU_VERSION_FILE) + +export ISSU_VERSION_FILE + diff --git a/platform/mellanox/issu-version/Makefile b/platform/mellanox/issu-version/Makefile new file mode 100644 index 0000000000..1f7d7fba3a --- /dev/null +++ b/platform/mellanox/issu-version/Makefile @@ -0,0 +1,12 @@ +.ONESHELL: +SHELL = /bin/bash +.SHELLFLAGS += -e + +MAIN_TARGET = issu-version + +$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% : + sx_sdk --version | egrep -o 'ISSU [0-9]+' > $(DEST)/$(MAIN_TARGET) || { + echo "ISSU version is undefined: $(sx_sdk --version)" + rm $(DEST)/$(MAIN_TARGET) + exit 1 + } diff --git a/platform/mellanox/mlnx-ffb.sh b/platform/mellanox/mlnx-ffb.sh index c87ea56f08..72187b94f8 100755 --- a/platform/mellanox/mlnx-ffb.sh +++ b/platform/mellanox/mlnx-ffb.sh @@ -37,21 +37,26 @@ check_sdk_upgrade() mkdir -p "${FS_MOUNTPOINT}" mount -t squashfs "${FS_PATH}" "${FS_MOUNTPOINT}" || { >&2 echo "Failed to mount next SONiC image" - break; + break } - SDK_VERSION_FILE_PATH="${FS_MOUNTPOINT}/etc/mlnx/sdk-version" + ISSU_VERSION_FILE_PATH="/etc/mlnx/issu-version" - [ -f "${SDK_VERSION_FILE_PATH}" ] && { - NEXT_SDK_VERSION="$(cat ${FS_MOUNTPOINT}/etc/mlnx/sdk-version)" - } || { - >&2 echo "No SDK version file ${SDK_VERSION_FILE_PATH}" - break; + [ -f "${SDK_VERSION_FILE_PATH}" ] || { + >&2 echo "No ISSU version file found ${ISSU_VERSION_FILE_PATH}" + break } - ISSU_CHECK_CMD="docker exec -t syncd issu --check ${NEXT_SDK_VERSION}" + CURRENT_ISSU_VERSION="$(cat ${ISSU_VERSION_FILE_PATH})" + NEXT_ISSU_VERSION="$(cat ${FS_MOUNTPOINT}/${ISSU_VERSION_FILE_PATH})" - ${ISS_CHECK_CMD} > /dev/null && CHECK_RESULT="${FFB_SUCCESS}" + if [[ "${CURRENT_ISSU_VERSION}" == "${NEXT_ISSU_VERSION}" ]]; then + CHECK_RESULT="${FFB_SUCCESS}" + else + >&2 echo "Current and next ISSU version do not match:" + >&2 echo "Current ISSU version: ${CURRENT_ISSU_VERSION}" + >&2 echo "Next ISSU version: ${NEXT_ISSU_VERSION}" + fi break done @@ -65,34 +70,15 @@ check_sdk_upgrade() check_ffb() { check_issu_enabled || { - echo "ISSU is not enabled on this HWSKU" + >&2 echo "ISSU is not enabled on this HWSKU" return "${FFB_FAILURE}" } + check_sdk_upgrade || { - echo "SDK upgrade check failued" + >&2 echo "SDK upgrade check failued" return "${FFB_FAILURE}" } - return "${FFB_SUCCESS}"; + + return "${FFB_SUCCESS}" } -# Perform ISSU start -issu_start() -{ - ISSU_START_CMD="docker exec -t syncd issu --start" - ${ISSU_START_CMD} > /dev/null - - EXIT_CODE=$? - - return $EXIT_CODE -} - -# Perform ISSU end -issu_end() -{ - ISSU_END_CMD="docker exec -t syncd issu --end" - ${ISSU_END_CMD} > /dev/null - - EXIT_CODE=$? - - return $EXIT_CODE -} diff --git a/platform/mellanox/mlnx-issu.mk b/platform/mellanox/mlnx-issu.mk deleted file mode 100755 index f0e3b47050..0000000000 --- a/platform/mellanox/mlnx-issu.mk +++ /dev/null @@ -1,5 +0,0 @@ -# issu (SONiC MLNX platform ISSU tool) Debian package - -MLNX_ISSU = python-mlnx-issu_1.0-1_all.deb -$(MLNX_ISSU)_SRC_PATH = $(PLATFORM_PATH)/mlnx-issu -SONIC_PYTHON_STDEB_DEBS += $(MLNX_ISSU) diff --git a/platform/mellanox/mlnx-issu/scripts/issu b/platform/mellanox/mlnx-issu/scripts/issu deleted file mode 100755 index 45c0f50436..0000000000 --- a/platform/mellanox/mlnx-issu/scripts/issu +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/env python -''' -This code is for a mlnx platform specific tool, issu. -This tool provides an CLI interface to interact with SDK ISSU module -''' - -from __future__ import print_function - -import sys -import os -import re -import errno -import syslog -import argparse - -from functools import wraps - -from python_sdk_api import sx_api - -# ========================== Constants =============================== -SDK_VERSION_PATTERN = r'(\d+)\.(\d+)\.(.*)' -SYSLOG_IDENTIFIER = "ISSU" - - -# Flag that indicates whether to print logs to stdout -verbose = False - - -# ========================== Syslog wrappers ========================== -def log_info(msg): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_INFO, msg) - syslog.closelog() - - if verbose: - print(msg) - -def log_warning(msg): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_WARNING, msg) - syslog.closelog() - - if verbose: - print(msg) - -def log_error(msg): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - print(msg, file=sys.stderr) - - -# ========================== Global functions ========================= -def with_sdk_handle(func): - """ A decorator for @func that use sx api - that gets a SDK handler, calls func(handler, *args, **kwargs) - and then closes the handler regardless of func failure""" - - @wraps(func) - def wrapped(*args, **kwargs): - log_info("opening sdk") - rc, handle = sx_api.sx_api_open(None) - log_info("sx_api_open handle: 0x%x , rc %d " % ( handle, rc) ) - - if rc != sx_api.SX_STATUS_SUCCESS: - log_error("failed to open api handle. Please check that SDK is running") - sys.exit(errno.EACCES) - - try: - res = func(handle, *args, **kwargs) - finally: - log_info("closing sdk handle") - rc = sx_api.sx_api_close(handle) - - if rc != sx_api.SX_STATUS_SUCCESS: - log_error("failed to close api handle") - - return res - - return wrapped - - -def check_sdk_version_pattern(sdk_version): - """Checker for @sdk_version""" - - if not re.match(SDK_VERSION_PATTERN, sdk_version): - raise argparse.ArgumentTypeError("{} is an invalid SDK version string".format(sdk_version)) - - return sdk_version - - -@with_sdk_handle -def check_issu_upgrade_to_sdk_version(handle, new_sdk): - """This function checks whether ISSU upgrade to @new_sdk version is posible""" - - version = sx_api.new_sx_api_sx_sdk_versions_t_p() - rc = sx_api.sx_api_sx_sdk_version_get(handle, version) - - if rc != sx_api.SX_STATUS_SUCCESS: - log_error("failed to get current SDK version") - sys.exit(errno.EACCES) - - current_sdk = version.sx_sdk - - succeed = True - - log_info('check ISSU upgrade: current SDK: {}, new SDK: {}, check succeed: {}'.format(current_sdk, new_sdk, succeed)) - - return succeed - - -@with_sdk_handle -def issu_start(handle): - """This function calls ISSU start API""" - - log_info("call ISSU start") - rc = sx_api.sx_api_issu_start_set(handle) - - if rc != sx_api.SX_STATUS_SUCCESS: - log_error("failed to execute ISSU start API") - sys.exit(errno.EACCES) - -@with_sdk_handle -def issu_end(handle): - """This function calls ISSU end API""" - - log_info("call ISSU end") - rc = sx_api.sx_api_issu_end_set(handle) - - if rc != sx_api.SX_STATUS_SUCCESS: - log_error("failed to execute ISSU end API") - sys.exit(errno.EACCES) - - -def get_parser(): - """This function creates an argument parser""" - - parser = argparse.ArgumentParser() - parser.add_argument('-c', '--check', nargs=1, action='store', default=None, type=check_sdk_version_pattern, - help='Check if ISSU upgrade is supported to new SDK version') - parser.add_argument('-s', '--start', action='store_true', help='Call ISSU start API') - parser.add_argument('-e', '--end', action='store_true', help='Call ISSU end API') - parser.add_argument('-v', '--verbose', action='store_true', default=False) - - return parser - - -def main(): - - global verbose - - parser = get_parser() - args = parser.parse_args() - - verbose = args.verbose - - if args.check is not None: - new_sdk = args.check[0] - is_supported = check_issu_upgrade_to_sdk_version(new_sdk) - - if verbose: - print('SDK upgrade is{}supported'.format(' ' if is_supported else ' not ')) - - if not is_supported: - sys.exit(1) - elif args.start: - issu_start() - elif args.end: - issu_end() - else: - parser.parse_args(['-h']) - - -if __name__ == '__main__': - main() diff --git a/platform/mellanox/mlnx-issu/setup.py b/platform/mellanox/mlnx-issu/setup.py deleted file mode 100755 index 614c9a0bbe..0000000000 --- a/platform/mellanox/mlnx-issu/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -from setuptools import setup - -setup( - name='mlnx-issu', - version='1.0', - description='MLNX ISSU tool for SONiC on mellanox platform', - author='SONiC Community', - url='https://github.com/Azure/sonic-buildimage/', - maintainer='Stepan Blyschak', - maintainer_email='stepanb@mellanox.com', - scripts=[ - 'scripts/issu', - ] -) diff --git a/platform/mellanox/one-image.mk b/platform/mellanox/one-image.mk index 3a99f1c66c..6fd5af1932 100644 --- a/platform/mellanox/one-image.mk +++ b/platform/mellanox/one-image.mk @@ -5,5 +5,5 @@ $(SONIC_ONE_IMAGE)_MACHINE = mellanox $(SONIC_ONE_IMAGE)_IMAGE_TYPE = onie $(SONIC_ONE_IMAGE)_INSTALLS += $(SX_KERNEL) $(KERNEL_MFT) $(MFT_OEM) $(MFT) $(MLNX_HW_MANAGEMENT) $(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_IMAGES) -$(SONIC_ONE_IMAGE)_FILES += $(MLNX_FW_FILE) $(MLNX_FFB_SCRIPT) +$(SONIC_ONE_IMAGE)_FILES += $(MLNX_FW_FILE) $(MLNX_FFB_SCRIPT) $(ISSU_VERSION_FILE) SONIC_INSTALLERS += $(SONIC_ONE_IMAGE) diff --git a/platform/mellanox/rules.mk b/platform/mellanox/rules.mk index 28414b7f9d..1c0072bec3 100644 --- a/platform/mellanox/rules.mk +++ b/platform/mellanox/rules.mk @@ -12,7 +12,7 @@ include $(PLATFORM_PATH)/libsaithrift-dev.mk include $(PLATFORM_PATH)/docker-ptf-mlnx.mk include $(PLATFORM_PATH)/mlnx-sfpd.mk include $(PLATFORM_PATH)/mlnx-ffb.mk -include $(PLATFORM_PATH)/mlnx-issu.mk +include $(PLATFORM_PATH)/issu-version.mk SONIC_ALL += $(SONIC_ONE_IMAGE) \ $(DOCKER_FPM) diff --git a/platform/mellanox/sdk-version.j2 b/platform/mellanox/sdk-version.j2 deleted file mode 100755 index 5bba188430..0000000000 --- a/platform/mellanox/sdk-version.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ MLNX_SDK_VERSION }} \ No newline at end of file diff --git a/platform/mellanox/sdk.mk b/platform/mellanox/sdk.mk index aba429cd7d..3d5d949fa7 100644 --- a/platform/mellanox/sdk.mk +++ b/platform/mellanox/sdk.mk @@ -56,4 +56,3 @@ $(eval $(foreach deb,$(PYTHON_SDK_API) $(SX_KERNEL) $(SX_KERNEL_DEV),$(call make SONIC_ONLINE_DEBS += $(MLNX_SDK_RDEBS) $(PYTHON_SDK_API) $(SX_KERNEL) -export MLNX_SDK_VERSION diff --git a/sonic-slave/Dockerfile b/sonic-slave/Dockerfile index 08a7c6bf05..291a2fefb7 100644 --- a/sonic-slave/Dockerfile +++ b/sonic-slave/Dockerfile @@ -232,19 +232,6 @@ RUN apt-get update && apt-get install -y \ texi2html \ # For initramfs bash-completion \ -# For Mellanox CRIU build - libprotobuf-dev \ - libprotobuf-c0-dev \ - protobuf-c-compiler \ - protobuf-compiler \ - python-protobuf \ - pkg-config \ - libnet1-dev \ - libnet-dev \ - libaio-dev \ - asciidoc \ - xmlto \ - checkinstall \ # For sonic vs image build dosfstools \ qemu-kvm \