From c684acf7df52ad03fcd94fd6d598cde630a6f918 Mon Sep 17 00:00:00 2001 From: Kavitha Ramalingam Date: Sun, 6 Oct 2024 12:55:07 +0530 Subject: [PATCH] GNOI Cold Reboot --- .gitmodules | 6 - dockers/docker-framework/Dockerfile.j2 | 1 + dockers/docker-framework/framework.sh | 1 + dockers/docker-framework/start.sh | 1 + dockers/docker-framework/supervisord.conf | 10 - .../docker-framework/versions-deb-bullseye | 4 +- .../dockers/docker-framework/versions-mirror | 2 +- .../dockers/docker-framework/versions-py3 | 2 +- .../versions-deb-bullseye | 7 +- .../versions-deb-bullseye | 10 +- files/build_templates/framework.service.j2 | 2 + files/build_templates/init_cfg.json.j2 | 2 +- gnoi | 1 - platform/vs/docker-sonic-vs.mk | 6 +- platform/vs/docker-sonic-vs/start.sh | 2 + rules/docker-framework.mk | 4 +- rules/framework.dep | 2 +- rules/framework.mk | 5 +- rules/ipmitool.mk | 2 +- sonic-slave-bullseye/Dockerfile.j2 | 247 ++- sonic-slave-bullseye/Dockerfile.j2.orig | 706 -------- src/sonic-framework/.gitignore | 45 - src/sonic-framework/Makefile.am | 18 +- src/sonic-framework/autogen.sh | 2 +- src/sonic-framework/debian/changelog | 2 +- src/sonic-framework/debian/compat | 2 +- src/sonic-framework/debian/control | 2 +- src/sonic-framework/debian/rules | 2 +- src/sonic-framework/gnoi/.bazelversion | 1 - .../gnoi/.github/dependabot.yml | 15 - .../gnoi/.github/protolint.yaml | 6 - .../.github/workflows/ci-cpp-build-gnoi.yml | 38 - .../gnoi/.github/workflows/go.yml | 12 - .../gnoi/.github/workflows/linter.yml | 24 - src/sonic-framework/gnoi/.gitignore | 1 - src/sonic-framework/gnoi/common/common.proto | 1 - src/sonic-framework/package.cfg | 15 + src/sonic-framework/rebootbackend/Makefile.am | 9 +- .../rebootbackend/container_stop.pb.cc | 1337 --------------- .../rebootbackend/container_stop.pb.h | 1441 ----------------- .../rebootbackend/container_stop.proto | 30 - .../rebootbackend/gnoi_container_shutdown.xml | 31 - .../gnoi_container_shutdown_dbus.h | 75 - .../rebootbackend/gnoi_reboot.xml | 2 +- .../rebootbackend/init_thread.cpp | 534 ------ .../rebootbackend/init_thread.h | 127 -- .../rebootbackend/interfaces.cpp | 61 - .../rebootbackend/interfaces.h | 24 - .../rebootbackend/reboot_common.cpp | 2 +- .../rebootbackend/reboot_common.h | 2 +- .../rebootbackend/reboot_interfaces.h | 67 - .../rebootbackend/reboot_thread.cpp | 711 +------- .../rebootbackend/reboot_thread.h | 204 +-- .../rebootbackend/rebootbackend.cpp | 6 +- .../rebootbackend/rebootbe.cpp | 84 +- src/sonic-framework/rebootbackend/rebootbe.h | 25 +- .../rebootbackend/redis_utils.cpp | 396 ----- .../rebootbackend/redis_utils.h | 250 --- .../rebootbackend/telemetry_helper.cpp | 120 -- .../rebootbackend/telemetry_helper.h | 49 - src/sonic-framework/tests/Makefile.am | 16 +- .../tests/init_thread_test.cpp | 769 --------- .../tests/mock_reboot_interfaces.h | 35 +- .../tests/reboot_thread_test.cpp | 1233 +------------- src/sonic-framework/tests/rebootbe_test.cpp | 920 +---------- .../tests/redis_utils_test.cpp | 762 --------- .../tests/telemetry_helper_test.cpp | 394 ----- .../tests/test_utils_common.cpp | 115 +- src/sonic-framework/tests/test_utils_common.h | 10 +- 69 files changed, 354 insertions(+), 10696 deletions(-) delete mode 160000 gnoi delete mode 100644 sonic-slave-bullseye/Dockerfile.j2.orig delete mode 100644 src/sonic-framework/.gitignore delete mode 100644 src/sonic-framework/gnoi/.bazelversion delete mode 100644 src/sonic-framework/gnoi/.github/dependabot.yml delete mode 100644 src/sonic-framework/gnoi/.github/protolint.yaml delete mode 100644 src/sonic-framework/gnoi/.github/workflows/ci-cpp-build-gnoi.yml delete mode 100644 src/sonic-framework/gnoi/.github/workflows/go.yml delete mode 100644 src/sonic-framework/gnoi/.github/workflows/linter.yml delete mode 100644 src/sonic-framework/gnoi/.gitignore create mode 100644 src/sonic-framework/package.cfg delete mode 100644 src/sonic-framework/rebootbackend/container_stop.pb.cc delete mode 100644 src/sonic-framework/rebootbackend/container_stop.pb.h delete mode 100644 src/sonic-framework/rebootbackend/container_stop.proto delete mode 100644 src/sonic-framework/rebootbackend/gnoi_container_shutdown.xml delete mode 100644 src/sonic-framework/rebootbackend/gnoi_container_shutdown_dbus.h delete mode 100644 src/sonic-framework/rebootbackend/init_thread.cpp delete mode 100644 src/sonic-framework/rebootbackend/telemetry_helper.cpp delete mode 100644 src/sonic-framework/rebootbackend/telemetry_helper.h delete mode 100644 src/sonic-framework/tests/telemetry_helper_test.cpp diff --git a/.gitmodules b/.gitmodules index e21c5aa8bf42..9013bdb67021 100644 --- a/.gitmodules +++ b/.gitmodules @@ -124,9 +124,3 @@ [submodule "platform/innovium/sonic-platform-marvell"] path = platform/innovium/sonic-platform-marvell url = https://github.com/Marvell-switching/sonic-platform-marvell -[submodule "src/sonic-framework/gnoi"] - path = src/sonic-framework/gnoi - url = https://github.com/openconfig/gnoi -[submodule "gnoi"] - path = gnoi - url = https://github.com/openconfig/gnoi diff --git a/dockers/docker-framework/Dockerfile.j2 b/dockers/docker-framework/Dockerfile.j2 index 9b80d028ba20..c9c71d402e84 100644 --- a/dockers/docker-framework/Dockerfile.j2 +++ b/dockers/docker-framework/Dockerfile.j2 @@ -30,4 +30,5 @@ COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] # COPY ["git_commits", "/usr"] + ENTRYPOINT ["/usr/local/bin/supervisord"] diff --git a/dockers/docker-framework/framework.sh b/dockers/docker-framework/framework.sh index 2d2e4c2c6fa5..68e72417fd2a 100755 --- a/dockers/docker-framework/framework.sh +++ b/dockers/docker-framework/framework.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash + exec /usr/local/bin/framework --logtostderr diff --git a/dockers/docker-framework/start.sh b/dockers/docker-framework/start.sh index d6722a27fc77..1235a4e5a671 100755 --- a/dockers/docker-framework/start.sh +++ b/dockers/docker-framework/start.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash + mkdir -p /var/sonic echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status diff --git a/dockers/docker-framework/supervisord.conf b/dockers/docker-framework/supervisord.conf index 306e612ab7cd..05ca0f4bc272 100644 --- a/dockers/docker-framework/supervisord.conf +++ b/dockers/docker-framework/supervisord.conf @@ -43,16 +43,6 @@ stderr_logfile=syslog dependent_startup=true dependent_startup_wait_for=rsyslogd:running -[program:stateverificationd] -command=/usr/bin/stateverificationd -priority=3 -autostart=false -autorestart=true -stdout_logfile=syslog -stderr_logfile=syslog -dependent_startup=true -dependent_startup_wait_for=start:exited - [program:rebootbackend] command=/usr/bin/rebootbackend priority=3 diff --git a/files/build/versions/dockers/docker-framework/versions-deb-bullseye b/files/build/versions/dockers/docker-framework/versions-deb-bullseye index 6d3e221b421e..d3c4068c849f 100644 --- a/files/build/versions/dockers/docker-framework/versions-deb-bullseye +++ b/files/build/versions/dockers/docker-framework/versions-deb-bullseye @@ -1,4 +1,4 @@ -adduser==3.118+deb11u1 +adduser==4.118+deb11u1 apt==2.2.4 apt-utils==2.2.4 base-files==11.1+deb11u9 @@ -226,4 +226,4 @@ vim-common==2:8.2.2434-3+deb11u1 vim-runtime==2:8.2.2434-3+deb11u1 vim-tiny==2:8.2.2434-3+deb11u1 xxd==2:8.2.2434-3+deb11u1 -zlib1g==1:1.2.11.dfsg-2+deb11u2 +zlib1g==1:1.2.11.dfsg-2+deb11u2 diff --git a/files/build/versions/dockers/docker-framework/versions-mirror b/files/build/versions/dockers/docker-framework/versions-mirror index 1cc5fd8352b0..82426ebf9828 100644 --- a/files/build/versions/dockers/docker-framework/versions-mirror +++ b/files/build/versions/dockers/docker-framework/versions-mirror @@ -1,3 +1,3 @@ -debian-archive.trafficmanager.net_debian-security_dists_bullseye-security==2024-05-10T08:02:59Z +debian-archive.trafficmanager.net_debian-security_dists_bullseye-security==2024-05-10T08:02:59Z debian-archive.trafficmanager.net_debian_dists_bullseye-backports==2024-05-10T02:16:16Z debian-archive.trafficmanager.net_debian_dists_bullseye-updates==2024-05-10T02:16:16Z diff --git a/files/build/versions/dockers/docker-framework/versions-py3 b/files/build/versions/dockers/docker-framework/versions-py3 index 3388288851dc..d326d329b6ef 100644 --- a/files/build/versions/dockers/docker-framework/versions-py3 +++ b/files/build/versions/dockers/docker-framework/versions-py3 @@ -23,4 +23,4 @@ supervisord-dependent-startup==1.4.0 tabulate==0.8.2 toposort==1.10 wheel==0.40.0 -xmltodict==0.12.0 +xmltodict==0.12.0 diff --git a/files/build/versions/dockers/docker-gbsyncd-broncos/versions-deb-bullseye b/files/build/versions/dockers/docker-gbsyncd-broncos/versions-deb-bullseye index 4d6e23e85f0e..1b81a742370b 100644 --- a/files/build/versions/dockers/docker-gbsyncd-broncos/versions-deb-bullseye +++ b/files/build/versions/dockers/docker-gbsyncd-broncos/versions-deb-bullseye @@ -17,10 +17,9 @@ libicu67==67.1-7 libipt2==2.0.3-1 libmpfr6==4.1.0-3 libnsl-dev==1.3.0-2 -libprotobuf-dev==3.21.12-3 -libprotobuf-lite32==3.21.12-3 -libprotobuf32==3.21.12-3 -libprotoc32==3.21.12-3 +libprotobuf-dev==3.12.4-1+deb11u1 +libprotobuf-lite23==3.12.4-1+deb11u1 +libprotobuf23==3.12.4-1+deb11u1 libsaibroncos==3.11 libsaimetadata==1.0.0 libsairedis==1.0.0 diff --git a/files/build/versions/dockers/docker-syncd-pensando/versions-deb-bullseye b/files/build/versions/dockers/docker-syncd-pensando/versions-deb-bullseye index e8a796ae282e..d79c3934e176 100644 --- a/files/build/versions/dockers/docker-syncd-pensando/versions-deb-bullseye +++ b/files/build/versions/dockers/docker-syncd-pensando/versions-deb-bullseye @@ -6,12 +6,12 @@ libgrpc++1==1.30.2-3 libgrpc-dev==1.30.2-3 libgrpc10==1.30.2-3 libkmod2==28-1 -libprotobuf-dev==3.21.12-3 -libprotobuf-lite32==3.21.12-3 -libprotobuf32==3.21.12-3 -libprotoc32==3.21.12-3 +libprotobuf-dev==3.12.4-1+deb11u1 +libprotobuf-lite23==3.12.4-1+deb11u1 +libprotobuf23==3.12.4-1+deb11u1 +libprotoc23==3.12.4-1+deb11u1 libsai==1.10.1-0 libsaimetadata==1.0.0 libsairedis==1.0.0 -protobuf-compiler==3.21.12-3 +protobuf-compiler==3.12.4-1+deb11u1 syncd==1.0.0 diff --git a/files/build_templates/framework.service.j2 b/files/build_templates/framework.service.j2 index c6273a3c4bc9..eb2bf3225e16 100644 --- a/files/build_templates/framework.service.j2 +++ b/files/build_templates/framework.service.j2 @@ -8,6 +8,7 @@ Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 + [Service] User={{ sonicadmin_user }} ExecStartPre=/usr/bin/{{docker_container_name}}.sh start @@ -16,5 +17,6 @@ ExecStop=/usr/bin/{{docker_container_name}}.sh stop Restart=always RestartSec=30 + [Install] WantedBy=sonic.target diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index ad36673f53fe..48b3610b7cf6 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -67,7 +67,7 @@ {%- elif include_system_eventd == "y" %} {% do features.append(("eventd", "enabled", false, "enabled")) %} {%- endif %} - "FEATURE": { + "FEATURE": { {# delayed field if set, will start the feature systemd .timer unit instead of .service unit #} {%- for feature, state, delayed, autorestart in features %} "{{feature}}": { diff --git a/gnoi b/gnoi deleted file mode 160000 index 8e23e5d63965..000000000000 --- a/gnoi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8e23e5d63965c3787a5331e330b3a9450a302130 diff --git a/platform/vs/docker-sonic-vs.mk b/platform/vs/docker-sonic-vs.mk index 53735eb980cf..6daf146da77a 100644 --- a/platform/vs/docker-sonic-vs.mk +++ b/platform/vs/docker-sonic-vs.mk @@ -11,7 +11,8 @@ $(DOCKER_SONIC_VS)_DEPENDS += $(SYNCD_VS) \ $(LIBYANG_CPP) \ $(LIBYANG_PY3) \ $(SONIC_UTILITIES_DATA) \ - $(SONIC_HOST_SERVICES_DATA) + $(SONIC_HOST_SERVICES_DATA) \ + $(FRAMEWORK) $(DOCKER_SONIC_VS)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3) \ $(SONIC_PLATFORM_COMMON_PY3) \ @@ -24,7 +25,8 @@ ifeq ($(INSTALL_DEBUG_TOOLS), y) $(DOCKER_SONIC_VS)_DEPENDS += $(LIBSWSSCOMMON_DBG) \ $(LIBSAIREDIS_DBG) \ $(LIBSAIVS_DBG) \ - $(SYNCD_VS_DBG) + $(SYNCD_VS_DBG) \ + $(FRAMEWORK_DBG) endif ifeq ($(SONIC_ROUTING_STACK), frr) diff --git a/platform/vs/docker-sonic-vs/start.sh b/platform/vs/docker-sonic-vs/start.sh index f28f05f3707d..50402011de4d 100755 --- a/platform/vs/docker-sonic-vs/start.sh +++ b/platform/vs/docker-sonic-vs/start.sh @@ -178,6 +178,8 @@ supervisorctl start tunnelmgrd supervisorctl start fabricmgrd +supervisorctl start rebootbackend + # Start arp_update when VLAN exists VLAN=`sonic-cfggen -d -v 'VLAN.keys() | join(" ") if VLAN'` if [ "$VLAN" != "" ]; then diff --git a/rules/docker-framework.mk b/rules/docker-framework.mk index df9a2b0b104a..9b3fda63a2df 100644 --- a/rules/docker-framework.mk +++ b/rules/docker-framework.mk @@ -24,8 +24,8 @@ SONIC_DOCKER_DBG_IMAGES += $(DOCKER_FRAMEWORK_DBG) SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_FRAMEWORK_DBG) $(DOCKER_FRAMEWORK)_CONTAINER_NAME = framework -$(DOCKER_FRAMEWORK)_RUN_OPT += --privileged -t -$(DOCKER_FRAMEWORK)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro +$(DOCKER_FRAMEWORK)_RUN_OPT += -v /var/run/dbus:/var/run/dbus:rw +$(DOCKER_FRAMEWORK)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro $(DOCKER_FRAMEWORK)_GIT_REPOSITORIES += "sonic-swss" $(DOCKER_FRAMEWORK)_GIT_REPOSITORIES += "sonic-swss-common" diff --git a/rules/framework.dep b/rules/framework.dep index fab64e430136..76aa6d2aff2b 100644 --- a/rules/framework.dep +++ b/rules/framework.dep @@ -10,4 +10,4 @@ $(FRAMEWORK)_CACHE_MODE := GIT_CONTENT_SHA $(FRAMEWORK)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) $(ENABLE_ASAN) $(FRAMEWORK)_DEP_FILES := $(DEP_FILES) $(FRAMEWORK)_SMDEP_FILES := $(foreach path, $(SMDEP_PATHS), $($(path))) -$(FRAMEWORK)_SMDEP_PATHS := $(SPATH) +$(FRAMEWORK)_SMDEP_PATHS := $(SPATH) diff --git a/rules/framework.mk b/rules/framework.mk index 9526ebcc20a7..8c9bb19826f0 100644 --- a/rules/framework.mk +++ b/rules/framework.mk @@ -2,9 +2,10 @@ FRAMEWORK = framework_1.0.0_$(CONFIGURED_ARCH).deb $(FRAMEWORK)_SRC_PATH = $(SRC_PATH)/sonic-framework -$(FRAMEWORK)_DEPENDS += $(LIBSWSSCOMMON_DEV) +$(FRAMEWORK)_DEPENDS += $(LIBSWSSCOMMON_DEV) \ + $(PROTOBUF) $(PROTOBUF_LITE) $(PROTOBUF_DEV) $(PROTOBUF_COMPILER) -$(FRAMEWORK)_RDEPENDS += $(LIBSWSSCOMMON) +$(FRAMEWORK)_RDEPENDS += $(LIBSWSSCOMMON) $(PROTOBUF) SONIC_DPKG_DEBS += $(FRAMEWORK) FRAMEWORK_DBG = framework-dbg_1.0.0_$(CONFIGURED_ARCH).deb diff --git a/rules/ipmitool.mk b/rules/ipmitool.mk index aad6fea3a86f..84cb248253ad 100644 --- a/rules/ipmitool.mk +++ b/rules/ipmitool.mk @@ -1,7 +1,7 @@ # ipmitool packages IPMITOOL_VERSION = 1.8.19 IPMITOOL_VERSION_SUFFIX = 4 -IPMITOOL_VERSION_FULL = $(IPMITOOL_VERSION)-$(IPMITOOL_VERSION_SUFFIX) +IPMITOOL_VERSION_FULL = $(IPMITOOL_VERSION)-$(IPMITOOL_VERSION_SUFFIX)+deb12u1 IPMITOOL = ipmitool_$(IPMITOOL_VERSION_FULL)_$(CONFIGURED_ARCH).deb $(IPMITOOL)_SRC_PATH = $(SRC_PATH)/ipmitool SONIC_MAKE_DEBS += $(IPMITOOL) diff --git a/sonic-slave-bullseye/Dockerfile.j2 b/sonic-slave-bullseye/Dockerfile.j2 index ef1e97d8aee9..484d75d0cb56 100644 --- a/sonic-slave-bullseye/Dockerfile.j2 +++ b/sonic-slave-bullseye/Dockerfile.j2 @@ -1,29 +1,93 @@ -FROM debian:bullseye +{% set prefix = DEFAULT_CONTAINER_REGISTRY %} +{%- if CONFIGURED_ARCH == "armhf" and MULTIARCH_QEMU_ENVIRON == "y" %} +FROM {{ prefix }}multiarch/qemu-user-static:x86_64-arm-6.1.0-8 as qemu +FROM {{ prefix }}multiarch/debian-debootstrap:armhf-bullseye +COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin +{%- elif CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} +FROM {{ prefix }}multiarch/qemu-user-static:x86_64-aarch64-6.1.0-8 as qemu +FROM {{ prefix }}multiarch/debian-debootstrap:arm64-bullseye +COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin +{%- elif CONFIGURED_ARCH == "armhf" and CROSS_BUILD_ENVIRON == "y" %} +FROM {{ prefix }}multiarch/qemu-user-static:x86_64-arm-6.1.0-8 as qemu +FROM {{ prefix }}debian:bullseye +COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin +{%- elif CONFIGURED_ARCH == "arm64" and CROSS_BUILD_ENVIRON == "y" %} +FROM {{ prefix }}multiarch/qemu-user-static:x86_64-aarch64-6.1.0-8 as qemu +FROM {{ prefix }}debian:bullseye +COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin +{%- else -%} +FROM {{ prefix }}debian:bullseye +{%- endif %} MAINTAINER gulv@microsoft.com COPY ["no-check-valid-until", "/etc/apt/apt.conf.d/"] COPY ["apt-retries-count", "/etc/apt/apt.conf.d"] + +{%- if CROSS_BUILD_ENVIRON != "y" %} +COPY ["sources.list.{{ CONFIGURED_ARCH }}", "/etc/apt/sources.list"] +{%- else %} COPY ["sources.list.amd64", "/etc/apt/sources.list"] +{%- if CONFIGURED_ARCH == "armhf" %} +ARG arch=armhf +ARG gcc_arch=arm-linux-gnueabihf +ARG PYTHON_CROSS_PLATFORM=linux_armv7l +{%- elif CONFIGURED_ARCH == "arm64" %} +ARG arch=arm64 +ARG gcc_arch=aarch64-linux-gnu +ARG PYTHON_CROSS_PLATFORM=linux_aarch64 +{%- endif %} + +RUN dpkg --add-architecture $arch +RUN apt-get update && apt-get install -y eatmydata +RUN eatmydata apt-get install -y crossbuild-essential-$arch +RUN eatmydata apt-get install -y gcc-$gcc_arch + +RUN apt-mark hold g++-$gcc_arch +RUN apt-mark hold g++-10-$gcc_arch +RUN apt-mark hold gcc-$gcc_arch +RUN apt-mark hold gcc-10-$gcc_arch + +ARG CROSS_CC=${gcc_arch}-gcc +ARG CROSS_CXX=${gcc_arch}-g++ +{%- endif %} ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive -# Auto-Generated for buildinfo -ARG SONIC_VERSION_CACHE -ARG SONIC_VERSION_CONTROL_COMPONENTS -COPY ["buildinfo", "/usr/local/share/buildinfo"] -COPY vcache/ /sonic/target/vcache/sonic-slave-bullseye -RUN dpkg -i /usr/local/share/buildinfo/sonic-build-hooks_1.0_all.deb -ENV IMAGENAME=sonic-slave-bullseye -ENV DISTRO=bullseye -RUN pre_run_buildinfo sonic-slave-bullseye - -RUN echo "========== BEGIN: CHECK IF PROTOBUF COMPILER EXISTS ALREADY AND UNINSTALL IT ===========" -RUN dpkg -r protobuf-compiler protobuf-compiler-grpc -RUN echo "========== END: CHECK IF PROTOBUF COMPILER EXISTS ALREADY AND UNINSTALL IT ============" - -RUN echo "======== BEGIN: PART-1 BUILD =============" +{%- if CROSS_BUILD_ENVIRON == "y" %} +RUN eatmydata apt-get install -y python3 python3-pip +RUN apt-get install -y python3-minimal:$arch python3.9:$arch python3:$arch python3-dev:$arch python3-setuptools:$arch +RUN apt-get download python3-distutils && eatmydata dpkg --force-all -i python3-distutils* +RUN apt-get download python3-pip && eatmydata dpkg --force-all -i python3-pip* +RUN which pip3 && pip3 install enum34 +RUN pip3 install virtualenv + +# Create target arm python3 virtual environments with all required packages installed +RUN mkdir /python_virtualenv +RUN cd /python_virtualenv && python3 -m virtualenv --copies -p /usr/bin/python3 env3 + +RUN PATH=/python_virtualenv/env3/bin/:$PATH pip3 install setuptools==49.6.00 wheel==0.35.1 fastentrypoints pytest pytest-cov pytest-runner==5.2 nose==1.3.7 mockredispy==2.9.3 mock==3.0.5 PyYAML==5.4.1 redis==3.5.3 pexpect==4.8.0 Pympler==0.8 parameterized natsort==6.2.1 MarkupSafe==2.0.1 Jinja2==3.0.3 click tabulate netaddr netifaces pyroute2 pyfakefs sphinx && ln -s /python_virtualenv/env3/bin/pytest /python_virtualenv/env3/bin/pytest-3 + +RUN eatmydata apt-get --fix-broken install -y +RUN LIBPYTHON3_DEPS="`apt-cache depends libpython3-dev:$arch |grep Depends|awk {'print \$2;'}|tr "\n" " "`" && eatmydata apt-get install -y libpython2.7-dev:$arch $LIBPYTHON3_DEPS libxml2-dev:$arch libxslt-dev:$arch libssl-dev:$arch libz-dev:$arch + +RUN eatmydata apt-get install -y swig libssl-dev + +RUN PATH=/python_virtualenv/env3/bin/:$PATH python3 -m pip install pyang==2.4.0 +RUN PATH=/python_virtualenv/env3/bin/:$PATH python3 -m pip install pyangbind==0.8.1 +RUN PATH=/python_virtualenv/env3/bin/:$PATH python3 -m pip uninstall -y enum34 +RUN PATH=/python_virtualenv/env3/bin/:$PATH pip3 install --force-reinstall --no-cache-dir coverage +{%- endif %} + +{%- if CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} +# multiarch/debian-debootstrap:arm64-bullseye is too old. It needs to install keys +RUN apt-get update || apt-get install -y gnupg +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0E98404D386FA1D9 +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6ED0E7B82643E131 +{%- endif %} + + RUN apt-get update && apt-get install -y eatmydata && eatmydata apt-get install -y \ apt-utils \ default-jre-headless \ @@ -53,12 +117,7 @@ RUN apt-get update && apt-get install -y eatmydata && eatmydata apt-get install dh-autoreconf \ doxygen \ devscripts \ - git-buildpackage - -RUN echo "======== END: PART-1 BUILD =============" -RUN echo "======== BEGIN: PART-2 BUILD =============" - -RUN apt-get install -y \ + git-buildpackage \ perl-modules \ libclass-accessor-perl \ libswitch-perl \ @@ -69,17 +128,6 @@ RUN apt-get install -y \ cron \ # For sonic-swss-common nlohmann-json3-dev \ -# For protobuf and gRPC - libprotobuf-dev=3.21.12-3 \ - libgrpc++-dev \ - protobuf-compiler=3.21.12-3 \ - protobuf-compiler-grpc -# For protobuf - -RUN echo "======== END: PART-2 BUILD =============" - -RUN echo "======== BEGIN: PART-3 BUILD =============" -RUN apt-get install -y \ # For quagga build libreadline-dev \ texlive-latex-base \ @@ -101,10 +149,10 @@ RUN apt-get install -y \ libsystemd-dev \ python3-ipaddr \ libcmocka-dev \ -# +#{%- if CROSS_BUILD_ENVIRON != "y" %} python3-all-dev \ python3-all-dbg \ -# +#{%- endif %} install-info \ logrotate \ # For libnl3 (local) build @@ -134,9 +182,9 @@ RUN apt-get install -y \ gem2deb \ libevent-dev \ libglib2.0-dev \ -# +#{%- if CROSS_BUILD_ENVIRON != "y" %} python3-all-dev \ -# +#{%- endif %} python3-twisted \ phpunit \ libbit-vector-perl \ @@ -177,7 +225,12 @@ RUN apt-get install -y \ squashfs-tools \ zip \ # For broadcom sdk build +{%- if CONFIGURED_ARCH == "amd64" %} linux-compiler-gcc-10-x86 \ +{%- endif %} +{%- if CONFIGURED_ARCH == "armhf" and CROSS_BUILD_ENVIRON != "y" %} + linux-compiler-gcc-10-arm \ +{%- endif %} linux-kbuild-5.10 \ # teamd build libdaemon-dev \ @@ -244,7 +297,12 @@ RUN apt-get install -y \ sphinx-common \ python3-sphinx \ # For sonic config engine testing +{%- if CROSS_BUILD_ENVIRON != "y" %} python3-dev \ +{%- endif %} +{%- if CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" %} + libxslt-dev \ +{%- endif %} # For lockfile procmail \ # For gtest @@ -277,10 +335,12 @@ RUN apt-get install -y \ # For initramfs shellcheck \ bash-completion \ +{%- if CONFIGURED_ARCH == "amd64" %} # For sonic vs image build dosfstools \ qemu-kvm \ libvirt-clients \ +{%- endif %} # For ntp autogen \ libopts25-dev \ @@ -368,6 +428,7 @@ RUN apt-get install -y \ rake-compiler \ default-jdk \ libgoogle-gson-java +{%- if CONFIGURED_ARCH != "arm64" and CONFIGURED_ARCH != "armhf" %} # For DASH BMv2 RUN eatmydata apt install -y \ # For grpc @@ -396,14 +457,44 @@ RUN eatmydata apt install -y \ python3-scapy \ python3-thrift \ libabsl20200923 libc-ares2 python3-six libboost-thread1.74.0 libboost-dev libboost-system-dev libboost-thread-dev libboost-filesystem1.74.0 libboost-program-options1.74.0 libboost-thread1.74.0 libnanomsg5 libpcap0.8 libthrift-0.13.0 libboost-dev libboost-filesystem-dev libboost-program-options-dev libgmp-dev libnanomsg-dev libpcap-dev libtool pkg-config libthrift-dev python3-thrift thrift-compiler libboost-iostreams1.74.0 libgc1 cpp libboost-dev libboost-all-dev libboost-graph-dev libboost-iostreams-dev libfl-dev libgc-dev libgmp-dev libbpf-dev tcpdump libelf-dev llvm clang python3-pyroute2 python3-ply python3-scapy python3-setuptools python3-thrift libthrift-0.13.0 +{%- endif %} -RUN echo "======== END: PART-3 BUILD =============" +{%- if CROSS_BUILD_ENVIRON == "y" %} +# Arm vs. amd64 versions conflict - remove amd64 packages +RUN apt-get remove -y libnl-3-200 +RUN eatmydata apt-get install -y libpcre3:$arch +{%- endif %} RUN eatmydata apt-get -y build-dep openssh # Build fix for ARM64 and ARMHF /etc/debian_version +{%- if CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" %} +RUN eatmydata apt upgrade -y base-files libc-bin=$(dpkg-query -W -f '${Version}' libc-bin) +{%- endif %} # Build fix for ARMHF bullseye libsairedis +{%- if CONFIGURED_ARCH == "armhf" and MULTIARCH_QEMU_ENVIRON == "y" %} + # Install doxygen build dependency packages + RUN eatmydata apt install -y libxapian-dev yui-compressor texlive-extra-utils \ + texlive-font-utils rdfind llvm-11-dev libclang-11-dev sassc faketime mat2 + + # Update doxygen with 64bit file offset patch + RUN dget -u http://deb.debian.org/debian/pool/main/d/doxygen/doxygen_1.9.1-2.dsc && \ + cd doxygen-1.9.1 && \ + sed -i '56 a add_definitions(-D_FILE_OFFSET_BITS=64)' CMakeLists.txt && \ + DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -us -uc -b && \ + cd .. && \ + eatmydata dpkg -i ./doxygen_1.9.1-2_armhf.deb && \ + rm -fr doxygen* + + # Aspell is unable to locate the language dictionaries. + # Re-installing aspell-en dictionary to fix it. + RUN eatmydata apt-get install --reinstall -y aspell-en + + # workaround because of https://bugs.launchpad.net/qemu/+bug/1805913, just disable aspell + # Issue now being tracked here - https://gitlab.com/qemu-project/qemu/-/issues/263 + RUN cp /bin/true /usr/bin/aspell +{%- endif %} ## Config dpkg ## install the configuration file if it’s currently missing @@ -412,16 +503,23 @@ RUN sudo augtool --autosave "set /files/etc/dpkg/dpkg.cfg/force-confmiss" RUN sudo augtool --autosave "set /files/etc/dpkg/dpkg.cfg/force-confdef" ## do not modify the current configuration file, the new version is installed with a .dpkg-dist suffix RUN sudo augtool --autosave "set /files/etc/dpkg/dpkg.cfg/force-confold" + +{%- if CROSS_BUILD_ENVIRON != "y" %} # For linux build RUN eatmydata apt-get -y build-dep linux +{%- else %} +RUN eatmydata apt-get install -y kernel-wedge +{%- endif %} # For gobgp and telemetry build RUN eatmydata apt-get install -y golang-1.15 && ln -s /usr/lib/go-1.15 /usr/local/go -RUN wget -O golang-go.deb 'https://sonicstorage.blob.core.windows.net/public/fips/bullseye/0.13/amd64/golang-1.15-go_1.15.15-1~deb11u4+fips_amd64.deb' \ - && wget -O golang-src.deb 'https://sonicstorage.blob.core.windows.net/public/fips/bullseye/0.13/amd64/golang-1.15-src_1.15.15-1~deb11u4+fips_amd64.deb' \ +{%- if INCLUDE_FIPS == "y" %} +RUN wget -O golang-go.deb 'https://sonicstorage.blob.core.windows.net/public/fips/bullseye/{{ FIPS_VERSION }}/{{ CONFIGURED_ARCH }}/golang-1.15-go_{{ FIPS_GOLANG_VERSION }}_{{ CONFIGURED_ARCH }}.deb' \ + && wget -O golang-src.deb 'https://sonicstorage.blob.core.windows.net/public/fips/bullseye/{{ FIPS_VERSION }}/{{ CONFIGURED_ARCH }}/golang-1.15-src_{{ FIPS_GOLANG_VERSION }}_{{ CONFIGURED_ARCH }}.deb' \ && eatmydata dpkg -i golang-go.deb golang-src.deb \ && ln -sf /usr/lib/go-1.15 /usr/local/go \ && rm golang-go.deb golang-src.deb +{%- endif %} RUN pip3 install --upgrade pip==24.2 RUN apt-get purge -y python3-pip python3-yaml @@ -430,6 +528,16 @@ RUN apt-get purge -y python3-pip python3-yaml RUN pip3 install setuptools==49.6.00 RUN pip3 install wheel==0.38.1 +{%- if CONFIGURED_ARCH == "armhf" %} +# Allow only manylinux wheels on armhf, to ensure that binaries/libraries work correctly on armhf +COPY ["disable-non-manylinux.patch", "/"] +{%- if CROSS_BUILD_ENVIRON == "y" %} +RUN patch -p1 -i /disable-non-manylinux.patch /python_virtualenv/env3/lib/python3.9/site-packages/pip/_vendor/packaging/tags.py +{%- else %} +RUN patch -p1 -i /disable-non-manylinux.patch /usr/local/lib/python3.9/dist-packages/pip/_vendor/packaging/tags.py +{%- endif %} +{%- endif %} + # For building sonic-utilities RUN pip3 install fastentrypoints mock @@ -444,6 +552,16 @@ RUN pip3 install nose==1.3.7 RUN pip3 install mockredispy==2.9.3 # Fix CVE-2021-23437, need to build and install libjpeg-dev for armhf for pillow 9.4.0 +{%- if CONFIGURED_ARCH == "armhf" %} +RUN TMP_DIR=$(mktemp -d) && \ + cd $TMP_DIR && \ + eatmydata apt-get install -y nasm && \ + apt-get source libjpeg-turbo && \ + cd $(ls -d libjpeg-turbo*/) && \ + dpkg-buildpackage -rfakeroot -b -us -uc > $TMP_DIR/libjpeg-dev.log && \ + eatmydata dpkg -i $TMP_DIR/libjpeg*-dev*.deb && \ + rm -rf $TMP_DIR +{%- endif %} RUN pip3 install pillow==9.4.0 # For p4 build @@ -464,7 +582,9 @@ RUN pip3 install j2cli==0.3.10 # For sonic-mgmt-framework # The option --no-build-isolation can be removed when upgrading PyYAML to 6.0.1 RUN pip3 install "PyYAML==5.4.1" --no-build-isolation +{%- if CROSS_BUILD_ENVIRON != "y" %} RUN pip3 install "lxml==4.9.1" +{%- endif %} # For sonic-platform-common testing RUN pip3 install redis @@ -498,7 +618,12 @@ RUN eatmydata apt-get install -y vim # Install rsyslog RUN eatmydata apt-get install -y rsyslog + +{%- if CROSS_BUILD_ENVIRON == "y" %} +RUN cd /usr/src/gtest && CXX=$CROSS_CXX CC=$CROSS_CC cmake . && make -C /usr/src/gtest +{%- else %} RUN cd /usr/src/gtest && cmake . && make -C /usr/src/gtest +{%- endif %} RUN mkdir /var/run/sshd EXPOSE 22 @@ -515,14 +640,21 @@ RUN eatmydata apt-get install -y \ curl \ gnupg2 \ software-properties-common +{%- if CONFIGURED_ARCH == "armhf" %} + RUN update-ca-certificates --fresh +{%- endif %} RUN curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - RUN add-apt-repository \ - "deb [arch=amd64] https://download.docker.com/linux/debian \ +{%- if CROSS_BUILD_ENVIRON == "y" %} + "deb https://download.docker.com/linux/debian \ +{%- else %} + "deb [arch={{ CONFIGURED_ARCH }}] https://download.docker.com/linux/debian \ +{%- endif %} $(lsb_release -cs) \ stable" RUN apt-get update RUN eatmydata apt-get install -y docker-ce=5:24.0.2-1~debian.11~bullseye docker-ce-cli=5:24.0.2-1~debian.11~bullseye containerd.io=1.6.21-1 docker-buildx-plugin=0.10.5-1~debian.11~bullseye docker-compose-plugin=2.18.1-1~debian.11~bullseye -RUN echo "DOCKER_OPTS=\"--experimental --storage-driver=vfs \"" >> /etc/default/docker +RUN echo "DOCKER_OPTS=\"--experimental --storage-driver=vfs {{ DOCKER_EXTRA_OPTS }}\"" >> /etc/default/docker RUN update-alternatives --set iptables /usr/sbin/iptables-legacy # Install m2crypto package, needed by SWI tools @@ -531,14 +663,35 @@ RUN pip3 install m2crypto==0.36.0 # Install swi tools RUN pip3 install git+https://github.com/aristanetworks/swi-tools.git@bead66bf261770237f7dd21ace3774ba04a017e9 +{% if CONFIGURED_ARCH != "amd64" -%} +# Install node.js for azure pipeline +RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - +RUN eatmydata apt-get install -y nodejs + +{%- if CROSS_BUILD_ENVIRON == "y" %} +RUN eatmydata apt-get install -y rsync dh-python + +RUN eatmydata apt-get install -y libelf-dev:$arch libdw-dev:$arch libbz2-dev:$arch liblzo2-dev:$arch libedit-dev:$arch libevent-dev:$arch libopts25-dev:$arch libssl-dev:$arch pps-tools:$arch libpam-cap:$arch libcap-dev:$arch libpam0g-dev:$arch libaudit-dev:$arch libgtk-3-dev:$arch libkrb5-dev:$arch libsystemd-dev:$arch libwrap0-dev:$arch libkrb5-dev:$arch libboost1.74-dev:$arch libboost-dev:$arch libzmq5:$arch libzmq3-dev:$arch libdaemon-dev:$arch libjansson-dev:$arch libmnl-dev:$arch libsensors5:$arch libsensors4-dev:$arch libperl-dev:$arch libmariadb-dev:$arch libmariadb-dev-compat:$arch libpci-dev:$arch libjson-c-dev:$arch libreadline-dev:$arch librtr-dev:$arch librrd-dev:$arch libnetfilter-conntrack-dev:$arch libnetfilter-conntrack3:$arch libnfnetlink-dev:$arch libnftnl-dev:$arch libldap2-dev:$arch libbind-export-dev:$arch check:$arch libboost-atomic-dev:$arch libboost-test-dev:$arch libglib2.0-dev:$arch libexplain-dev:$arch libc-ares-dev:$arch libiptc0:$arch libxtables12:$arch libatm1-dev:$arch libbpf-dev:$arch libdb-dev:$arch pkg-config:$arch libnghttp2-14:$arch librtmp1:$arch libssh2-1:$arch libcjson1:$arch libcjson-dev:$arch libcurl4-openssl-dev:$arch libboost-thread1.74-dev:$arch libboost-thread-dev:$arch libboost-system1.74-dev:$arch libboost-system-dev:$arch libgtest-dev:$arch libgmock-dev:$arch libfido2-dev:$arch libcunit1:$arch libcunit1-dev:$arch libauparse-dev:$arch libnetsnmptrapd40:$arch qtbase5-dev:$arch libboost-log-dev:$arch libboost-filesystem-dev:$arch libboost-program-options-dev:$arch + +RUN apt-get download libgirepository1.0-dev:$arch && eatmydata dpkg --force-all -i libgirepository1.0-dev* +RUN PATH=/python_virtualenv/env3/bin/:$PATH pip3 install pycairo + +# Install libpcsclite-dev for wpasupplicant using download because regular install removes amd64 python package +RUN apt-get download libpcsclite1:$arch && eatmydata dpkg --force-all -i libpcsclite1* && apt-get download libpcsclite-dev:$arch && eatmydata dpkg --force-all -i libpcsclite-dev* +# Install python3-dev for frr (/usr/bin/python3-config for $arch) using download because regular install removes amd64 python package +RUN apt-get download python3.9-dev:$arch && apt-get download python3-dev:$arch && eatmydata dpkg --force-all -i python3*-dev* +{% endif %} + +# Tell azure pipeline to use node.js in the docker +LABEL "com.azure.dev.pipelines.agent.handler.node.path"="/usr/bin/node" +{% endif -%} + # Install Bazel build system (amd64 and arm64 architectures are supported using this method) # TODO(PINS): Remove once pre-build Bazel binaries are available for armhf (armv7l) -ARG bazelisk_url=https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64 +{%- if CONFIGURED_ARCH == "amd64" or CONFIGURED_ARCH == "arm64" %} +ARG bazelisk_url=https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-{{ CONFIGURED_ARCH }} RUN curl -fsSL -o /usr/local/bin/bazel ${bazelisk_url} && chmod 755 /usr/local/bin/bazel # Bazel requires "python" # TODO(PINS): remove when Bazel is okay with "python3" binary name RUN eatmydata apt install -y python-is-python3 - -RUN post_run_buildinfo sonic-slave-bullseye - -RUN post_run_cleanup sonic-slave-bullseye +{% endif -%} diff --git a/sonic-slave-bullseye/Dockerfile.j2.orig b/sonic-slave-bullseye/Dockerfile.j2.orig deleted file mode 100644 index 72e23af4b5f4..000000000000 --- a/sonic-slave-bullseye/Dockerfile.j2.orig +++ /dev/null @@ -1,706 +0,0 @@ -{% set prefix = DEFAULT_CONTAINER_REGISTRY %} -{%- if CONFIGURED_ARCH == "armhf" and MULTIARCH_QEMU_ENVIRON == "y" %} -FROM {{ prefix }}multiarch/qemu-user-static:x86_64-arm-6.1.0-8 as qemu -FROM {{ prefix }}multiarch/debian-debootstrap:armhf-bullseye -COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin -{%- elif CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} -FROM {{ prefix }}multiarch/qemu-user-static:x86_64-aarch64-6.1.0-8 as qemu -FROM {{ prefix }}multiarch/debian-debootstrap:arm64-bullseye -COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin -{%- elif CONFIGURED_ARCH == "armhf" and CROSS_BUILD_ENVIRON == "y" %} -FROM {{ prefix }}multiarch/qemu-user-static:x86_64-arm-6.1.0-8 as qemu -FROM {{ prefix }}debian:bullseye -COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin -{%- elif CONFIGURED_ARCH == "arm64" and CROSS_BUILD_ENVIRON == "y" %} -FROM {{ prefix }}multiarch/qemu-user-static:x86_64-aarch64-6.1.0-8 as qemu -FROM {{ prefix }}debian:bullseye -COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin -{%- else -%} -FROM {{ prefix }}debian:bullseye -{%- endif %} - -MAINTAINER gulv@microsoft.com - -COPY ["no-check-valid-until", "/etc/apt/apt.conf.d/"] -COPY ["apt-retries-count", "/etc/apt/apt.conf.d"] - -{%- if CROSS_BUILD_ENVIRON != "y" %} -COPY ["sources.list.{{ CONFIGURED_ARCH }}", "/etc/apt/sources.list"] -{%- else %} -COPY ["sources.list.amd64", "/etc/apt/sources.list"] -{%- if CONFIGURED_ARCH == "armhf" %} -ARG arch=armhf -ARG gcc_arch=arm-linux-gnueabihf -ARG PYTHON_CROSS_PLATFORM=linux_armv7l -{%- elif CONFIGURED_ARCH == "arm64" %} -ARG arch=arm64 -ARG gcc_arch=aarch64-linux-gnu -ARG PYTHON_CROSS_PLATFORM=linux_aarch64 -{%- endif %} - -RUN dpkg --add-architecture $arch -RUN apt-get update && apt-get install -y eatmydata -RUN eatmydata apt-get install -y crossbuild-essential-$arch -RUN eatmydata apt-get install -y gcc-$gcc_arch - -RUN apt-mark hold g++-$gcc_arch -RUN apt-mark hold g++-10-$gcc_arch -RUN apt-mark hold gcc-$gcc_arch -RUN apt-mark hold gcc-10-$gcc_arch - -ARG CROSS_CC=${gcc_arch}-gcc -ARG CROSS_CXX=${gcc_arch}-g++ -{%- endif %} - -## Make apt-get non-interactive -ENV DEBIAN_FRONTEND=noninteractive - -{%- if CROSS_BUILD_ENVIRON == "y" %} -RUN eatmydata apt-get install -y python3 python3-pip -RUN apt-get install -y python3-minimal:$arch python3.9:$arch python3:$arch python3-dev:$arch python3-setuptools:$arch -RUN apt-get download python3-distutils && eatmydata dpkg --force-all -i python3-distutils* -RUN apt-get download python3-pip && eatmydata dpkg --force-all -i python3-pip* -RUN which pip3 && pip3 install enum34 -RUN pip3 install virtualenv - -# Create target arm python3 virtual environments with all required packages installed -RUN mkdir /python_virtualenv -RUN cd /python_virtualenv && python3 -m virtualenv --copies -p /usr/bin/python3 env3 - -RUN PATH=/python_virtualenv/env3/bin/:$PATH pip3 install setuptools==49.6.00 wheel==0.35.1 fastentrypoints pytest pytest-cov pytest-runner==5.2 nose==1.3.7 mockredispy==2.9.3 mock==3.0.5 PyYAML==5.4.1 redis==3.5.3 pexpect==4.8.0 Pympler==0.8 parameterized natsort==6.2.1 MarkupSafe==2.0.1 Jinja2==3.0.3 click tabulate netaddr netifaces pyroute2 pyfakefs sphinx && ln -s /python_virtualenv/env3/bin/pytest /python_virtualenv/env3/bin/pytest-3 - -RUN eatmydata apt-get --fix-broken install -y -RUN LIBPYTHON3_DEPS="`apt-cache depends libpython3-dev:$arch |grep Depends|awk {'print \$2;'}|tr "\n" " "`" && eatmydata apt-get install -y libpython2.7-dev:$arch $LIBPYTHON3_DEPS libxml2-dev:$arch libxslt-dev:$arch libssl-dev:$arch libz-dev:$arch - -RUN eatmydata apt-get install -y swig libssl-dev - -RUN PATH=/python_virtualenv/env3/bin/:$PATH python3 -m pip install pyang==2.4.0 -RUN PATH=/python_virtualenv/env3/bin/:$PATH python3 -m pip install pyangbind==0.8.1 -RUN PATH=/python_virtualenv/env3/bin/:$PATH python3 -m pip uninstall -y enum34 -RUN PATH=/python_virtualenv/env3/bin/:$PATH pip3 install --force-reinstall --no-cache-dir coverage -{%- endif %} - -{%- if CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} -# multiarch/debian-debootstrap:arm64-bullseye is too old. It needs to install keys -RUN apt-get update || apt-get install -y gnupg -RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0E98404D386FA1D9 -RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6ED0E7B82643E131 -{%- endif %} - -RUN echo "========== BEGIN: CHECK IF PROTOBUF COMPILER EXISTS ALREADY AND UNINSTALL IT ===========" -RUN dpkg -r protobuf-compiler protobuf-compiler-grpc -RUN echo "========== END: CHECK IF PROTOBUF COMPILER EXISTS ALREADY AND UNINSTALL IT ============" - -RUN apt-get update && apt-get install -y eatmydata && eatmydata apt-get install -y \ - apt-utils \ - default-jre-headless \ - openssh-server \ - curl \ - wget \ - unzip \ - gzip \ - pigz \ - git \ - build-essential \ - remake \ - libtool \ - lintian \ - sudo \ - dh-make \ - dh-exec \ - kmod \ - libtinyxml2-dev \ - python-all \ - python-dev \ - python-setuptools \ - python3 \ - python3-pip \ - libncurses5-dev \ - texinfo \ - dh-autoreconf \ - doxygen \ - devscripts \ - git-buildpackage \ - perl-modules \ - libclass-accessor-perl \ - libswitch-perl \ - libzmq5 \ - libzmq3-dev \ - uuid-dev \ - jq \ - cron \ -# For sonic-swss-common - nlohmann-json3-dev \ -# For protobuf and gRPC - libprotobuf-dev \ - libgrpc++-dev \ - protobuf-compiler \ - protobuf-compiler-grpc \ -# For protobuf -# For quagga build - libreadline-dev \ - texlive-latex-base \ - texlive-plain-generic \ - texlive-fonts-recommended \ - libpam0g-dev \ - libpam-dev \ - libcap-dev \ - imagemagick \ - ghostscript \ - groff \ - libpcre3-dev \ - gawk \ - chrpath \ -# For frr build - libc-ares-dev \ - libsnmp-dev \ - libjson-c-dev \ - libsystemd-dev \ - python3-ipaddr \ - libcmocka-dev \ -#{%- if CROSS_BUILD_ENVIRON != "y" %} - python3-all-dev \ - python3-all-dbg \ -#{%- endif %} - install-info \ - logrotate \ -# For libnl3 (local) build - cdbs \ -# For SAI meta build - libxml-simple-perl \ - graphviz \ - aspell \ -# For SAI meta rpc build - make rpc - libgetopt-long-descriptive-perl \ - libconst-fast-perl \ - libtemplate-perl \ - libnamespace-autoclean-perl \ - libmoose-perl \ - libmoosex-aliases-perl \ -# For linux build - bc \ - fakeroot \ - build-essential \ - devscripts \ - quilt \ - stgit \ - sbsigntool \ -# For platform-modules build - module-assistant \ -# For thrift build\ - gem2deb \ - libevent-dev \ - libglib2.0-dev \ -#{%- if CROSS_BUILD_ENVIRON != "y" %} - python3-all-dev \ -#{%- endif %} - python3-twisted \ - phpunit \ - libbit-vector-perl \ - openjdk-11-jdk \ - javahelper \ - maven-debian-helper \ - ant \ - libhttpclient-java \ - libslf4j-java \ - libservlet3.1-java \ - pkg-php-tools \ -# For mellanox sdk build - libpcre3 \ - libpcre3-dev \ - byacc \ - flex \ - libglib2.0-dev \ - bison \ - expat \ - libexpat1-dev \ - dpatch \ - libdb-dev \ - libiptc-dev \ - libxtables-dev \ - libbpf-dev \ -# For mellanox sai build - libtool-bin \ - libxml2-dev \ -# For BFN sdk build - libusb-1.0-0-dev \ - libcurl4-openssl-dev \ - libunwind8-dev \ - telnet \ - libc-ares2 \ - libgoogle-perftools4 \ -# For build image - cpio \ - squashfs-tools \ - zip \ -# For broadcom sdk build -{%- if CONFIGURED_ARCH == "amd64" %} - linux-compiler-gcc-10-x86 \ -{%- endif %} -{%- if CONFIGURED_ARCH == "armhf" and CROSS_BUILD_ENVIRON != "y" %} - linux-compiler-gcc-10-arm \ -{%- endif %} - linux-kbuild-5.10 \ -# teamd build - libdaemon-dev \ - libdbus-1-dev \ - libjansson-dev \ -# For cavium sdk build - libpcap-dev \ - dnsutils \ - libusb-dev \ -# For cisco sdk build - libgrpc++1 \ - libabsl-dev \ -# For debian image reconfiguration - augeas-tools \ -# For p4 build - libyaml-dev \ - libevent-dev \ - libjudy-dev \ - libedit-dev \ - libnanomsg-dev \ - python3-stdeb \ -# For redis build - libjemalloc-dev \ - liblua5.1-0-dev \ - lua-bitop-dev \ - lua-cjson-dev \ -# For mft kernel module build - dkms \ -# For Jenkins static analysis, unit testing and code coverage - cppcheck \ - clang \ - pylint \ - python3-pytest \ - python3-venv \ - gcovr \ - python3-pytest-cov \ - python3-pytest-cov \ - python3-parse \ -# For snmpd - default-libmysqlclient-dev \ - libssl-dev \ - libperl-dev \ - libpci-dev \ - libpci3 \ - libsensors5 \ - libsensors4-dev \ - libwrap0-dev \ -# For lldpd - debhelper \ - autotools-dev \ - libbsd-dev \ - pkg-config \ - check \ -# For mpdecimal - docutils-common \ - libjs-sphinxdoc \ - libjs-underscore \ - python3-docutils \ - python3-jinja2 \ - python3-markupsafe \ - python3-pygments \ - python3-roman \ - python3-sphinx \ - sphinx-common \ - python3-sphinx \ -# For sonic config engine testing -{%- if CROSS_BUILD_ENVIRON != "y" %} - python3-dev \ -{%- endif %} -{%- if CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" %} - libxslt-dev \ -{%- endif %} -# For lockfile - procmail \ -# For gtest - libgtest-dev \ - cmake \ -# For gmock - libgmock-dev \ -# For pam_tacplus build - autoconf-archive \ -# For iproute2 - cm-super-minimal \ - libatm1-dev \ - libbpf-dev \ - libelf-dev \ - libmnl-dev \ - libselinux1-dev \ - linuxdoc-tools \ - lynx \ - texlive-latex-extra \ - texlive-latex-recommended \ - iproute2 \ -# For bash - texi2html \ - sharutils \ - locales \ - time \ - man2html-base \ - libcunit1 \ - libcunit1-dev \ -# For initramfs - shellcheck \ - bash-completion \ -{%- if CONFIGURED_ARCH == "amd64" %} -# For sonic vs image build - dosfstools \ - qemu-kvm \ - libvirt-clients \ -{%- endif %} -# For ntp - autogen \ - libopts25-dev \ - pps-tools \ - dh-apparmor \ -# For lm-sensors - librrd8 \ - librrd-dev \ - rrdtool \ -# For kdump-tools - liblzo2-dev \ -# For iptables - libnetfilter-conntrack-dev \ - libnftnl-dev \ -# For SAI3.7 - xxd \ -# For DHCP Monitor tool - libexplain-dev \ - libevent-dev \ -# For libyang - swig \ -# For build dtb - device-tree-compiler \ -# For sonic-mgmt-framework - autoconf \ - m4 \ - libxml2-utils \ - xsltproc \ - python3-lxml \ - libexpat1-dev \ - libcurl4 \ - libcjson-dev \ -# For WPA supplication - qtbase5-dev \ - aspell-en \ - libssl-dev \ - dbus \ - libdbus-1-dev \ - libdbus-glib-1-2 \ - libdbus-glib-1-dev \ - libreadline-dev \ - libncurses5-dev \ - libpcsclite-dev \ - docbook-to-man \ - docbook-utils \ -# For kdump-tools - libbz2-dev \ -# For linkmgrd - libboost-dev \ - libboost-program-options-dev \ - libboost-system-dev \ - libboost-serialization1.74-dev \ - libboost-thread-dev \ - libboost-atomic-dev \ - libboost-chrono-dev \ - libboost-container-dev \ - libboost-context-dev \ - libboost-contract-dev \ - libboost-coroutine-dev \ - libboost-date-time-dev \ - libboost-fiber-dev \ - libboost-filesystem-dev \ - libboost-graph-parallel-dev \ - libboost-log-dev \ - libboost-regex-dev \ - googletest \ - libgtest-dev \ - libgmock-dev \ - libgcc-10-dev \ -# For sonic-host-services build - libcairo2-dev \ - libdbus-1-dev \ - libgirepository1.0-dev \ - libsystemd-dev \ - pkg-config \ -# For sonic-swss-common build - libhiredis-dev \ -# For audisp-tacplus - libauparse-dev \ - auditd \ -# For framework container build - libdbus-c++-dev \ - dh-elpa \ - xmlto \ - rake-compiler \ - default-jdk \ - libgoogle-gson-java -{%- if CONFIGURED_ARCH != "arm64" and CONFIGURED_ARCH != "armhf" %} -# For DASH BMv2 -RUN eatmydata apt install -y \ -# For grpc - libgflags-dev \ - libgoogle-perftools-dev \ - ruby-googleauth \ - ruby-googleapis-common-protos-types \ - ruby-simplecov \ - cython3 \ -# For p4 libraries - valgrind \ - thrift-compiler \ - gfortran \ - libopenmpi-dev \ - libthrift-0.13.0 \ - libthrift-dev \ - libboost-all-dev \ - libboost-graph-dev \ - libboost-iostreams-dev \ - libgc-dev \ - tcpdump \ - llvm \ - net-tools \ - python3-pyroute2 \ - python3-ply \ - python3-scapy \ - python3-thrift \ - libabsl20200923 libc-ares2 python3-six libboost-thread1.74.0 libboost-dev libboost-system-dev libboost-thread-dev libboost-filesystem1.74.0 libboost-program-options1.74.0 libboost-thread1.74.0 libnanomsg5 libpcap0.8 libthrift-0.13.0 libboost-dev libboost-filesystem-dev libboost-program-options-dev libgmp-dev libnanomsg-dev libpcap-dev libtool pkg-config libthrift-dev python3-thrift thrift-compiler libboost-iostreams1.74.0 libgc1 cpp libboost-dev libboost-all-dev libboost-graph-dev libboost-iostreams-dev libfl-dev libgc-dev libgmp-dev libbpf-dev tcpdump libelf-dev llvm clang python3-pyroute2 python3-ply python3-scapy python3-setuptools python3-thrift libthrift-0.13.0 -{%- endif %} - -{%- if CROSS_BUILD_ENVIRON == "y" %} -# Arm vs. amd64 versions conflict - remove amd64 packages -RUN apt-get remove -y libnl-3-200 -RUN eatmydata apt-get install -y libpcre3:$arch -{%- endif %} - -RUN eatmydata apt-get -y build-dep openssh - -# Build fix for ARM64 and ARMHF /etc/debian_version -{%- if CONFIGURED_ARCH == "armhf" or CONFIGURED_ARCH == "arm64" %} -RUN eatmydata apt upgrade -y base-files libc-bin=$(dpkg-query -W -f '${Version}' libc-bin) -{%- endif %} - -# Build fix for ARMHF bullseye libsairedis -{%- if CONFIGURED_ARCH == "armhf" and MULTIARCH_QEMU_ENVIRON == "y" %} - # Install doxygen build dependency packages - RUN eatmydata apt install -y libxapian-dev yui-compressor texlive-extra-utils \ - texlive-font-utils rdfind llvm-11-dev libclang-11-dev sassc faketime mat2 - - # Update doxygen with 64bit file offset patch - RUN dget -u http://deb.debian.org/debian/pool/main/d/doxygen/doxygen_1.9.1-2.dsc && \ - cd doxygen-1.9.1 && \ - sed -i '56 a add_definitions(-D_FILE_OFFSET_BITS=64)' CMakeLists.txt && \ - DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -us -uc -b && \ - cd .. && \ - eatmydata dpkg -i ./doxygen_1.9.1-2_armhf.deb && \ - rm -fr doxygen* - - # Aspell is unable to locate the language dictionaries. - # Re-installing aspell-en dictionary to fix it. - RUN eatmydata apt-get install --reinstall -y aspell-en - - # workaround because of https://bugs.launchpad.net/qemu/+bug/1805913, just disable aspell - # Issue now being tracked here - https://gitlab.com/qemu-project/qemu/-/issues/263 - RUN cp /bin/true /usr/bin/aspell -{%- endif %} - -## Config dpkg -## install the configuration file if it’s currently missing -RUN sudo augtool --autosave "set /files/etc/dpkg/dpkg.cfg/force-confmiss" -## combined with confold: overwrite configuration files that you have not modified -RUN sudo augtool --autosave "set /files/etc/dpkg/dpkg.cfg/force-confdef" -## do not modify the current configuration file, the new version is installed with a .dpkg-dist suffix -RUN sudo augtool --autosave "set /files/etc/dpkg/dpkg.cfg/force-confold" - -{%- if CROSS_BUILD_ENVIRON != "y" %} -# For linux build -RUN eatmydata apt-get -y build-dep linux -{%- else %} -RUN eatmydata apt-get install -y kernel-wedge -{%- endif %} - -# For gobgp and telemetry build -RUN eatmydata apt-get install -y golang-1.15 && ln -s /usr/lib/go-1.15 /usr/local/go -{%- if INCLUDE_FIPS == "y" %} -RUN wget -O golang-go.deb 'https://sonicstorage.blob.core.windows.net/public/fips/bullseye/{{ FIPS_VERSION }}/{{ CONFIGURED_ARCH }}/golang-1.15-go_{{ FIPS_GOLANG_VERSION }}_{{ CONFIGURED_ARCH }}.deb' \ - && wget -O golang-src.deb 'https://sonicstorage.blob.core.windows.net/public/fips/bullseye/{{ FIPS_VERSION }}/{{ CONFIGURED_ARCH }}/golang-1.15-src_{{ FIPS_GOLANG_VERSION }}_{{ CONFIGURED_ARCH }}.deb' \ - && eatmydata dpkg -i golang-go.deb golang-src.deb \ - && ln -sf /usr/lib/go-1.15 /usr/local/go \ - && rm golang-go.deb golang-src.deb -{%- endif %} - -RUN pip3 install --upgrade pip==24.2 -RUN apt-get purge -y python3-pip python3-yaml - -# For building Python packages -RUN pip3 install setuptools==49.6.00 -RUN pip3 install wheel==0.38.1 - -{%- if CONFIGURED_ARCH == "armhf" %} -# Allow only manylinux wheels on armhf, to ensure that binaries/libraries work correctly on armhf -COPY ["disable-non-manylinux.patch", "/"] -{%- if CROSS_BUILD_ENVIRON == "y" %} -RUN patch -p1 -i /disable-non-manylinux.patch /python_virtualenv/env3/lib/python3.9/site-packages/pip/_vendor/packaging/tags.py -{%- else %} -RUN patch -p1 -i /disable-non-manylinux.patch /usr/local/lib/python3.9/dist-packages/pip/_vendor/packaging/tags.py -{%- endif %} -{%- endif %} - -# For building sonic-utilities -RUN pip3 install fastentrypoints mock - -# For building sonic_ycabled -# Note: upstream build breaks with old version of setuptools -# ref: https://github.com/grpc/grpc/issues/34569 -RUN pip3 install grpcio==1.58.0 grpcio-tools==1.58.0 - -# For running Python unit tests -RUN pip3 install pytest-runner==5.2 -RUN pip3 install nose==1.3.7 -RUN pip3 install mockredispy==2.9.3 - -# Fix CVE-2021-23437, need to build and install libjpeg-dev for armhf for pillow 9.4.0 -{%- if CONFIGURED_ARCH == "armhf" %} -RUN TMP_DIR=$(mktemp -d) && \ - cd $TMP_DIR && \ - eatmydata apt-get install -y nasm && \ - apt-get source libjpeg-turbo && \ - cd $(ls -d libjpeg-turbo*/) && \ - dpkg-buildpackage -rfakeroot -b -us -uc > $TMP_DIR/libjpeg-dev.log && \ - eatmydata dpkg -i $TMP_DIR/libjpeg*-dev*.deb && \ - rm -rf $TMP_DIR -{%- endif %} -RUN pip3 install pillow==9.4.0 - -# For p4 build -RUN pip3 install \ - ctypesgen==1.0.2 \ - crc16 - -# For sonic config engine testing -# Install pyangbind here, outside sonic-config-engine dependencies, as pyangbind causes enum34 to be installed. -# enum34 causes Python 're' package to not work properly as it redefines an incompatible enum.py module -# https://github.com/robshakir/pyangbind/issues/232 -RUN pip3 install pyangbind==0.8.1 -RUN pip3 uninstall -y enum34 - -# For templating -RUN pip3 install j2cli==0.3.10 - -# For sonic-mgmt-framework -# The option --no-build-isolation can be removed when upgrading PyYAML to 6.0.1 -RUN pip3 install "PyYAML==5.4.1" --no-build-isolation -{%- if CROSS_BUILD_ENVIRON != "y" %} -RUN pip3 install "lxml==4.9.1" -{%- endif %} - -# For sonic-platform-common testing -RUN pip3 install redis -RUN pip3 install psutil -RUN pip3 install blkinfo - -# For vs image build -RUN pip3 install pexpect==4.8.0 - -# For sonic-swss-common testing -RUN pip3 install Pympler==0.8 - -# For sonic_yang_model build -RUN pip3 install pyang==2.4.0 - -# For mgmt-framework build -RUN pip3 install mmh3==2.5.1 - -RUN pip3 install parameterized==0.8.1 - -# For DASH BMv2 -RUN pip3 install jsonpath_ng - -RUN eatmydata apt-get install -y xsltproc - -# Install dependencies for isc-dhcp-relay build -RUN eatmydata apt-get -y build-dep isc-dhcp - -# Install vim -RUN eatmydata apt-get install -y vim - -# Install rsyslog -RUN eatmydata apt-get install -y rsyslog - -{%- if CROSS_BUILD_ENVIRON == "y" %} -RUN cd /usr/src/gtest && CXX=$CROSS_CXX CC=$CROSS_CC cmake . && make -C /usr/src/gtest -{%- else %} -RUN cd /usr/src/gtest && cmake . && make -C /usr/src/gtest -{%- endif %} - -RUN mkdir /var/run/sshd -EXPOSE 22 - -# Install dependencies for dhcp relay test -RUN pip3 install parameterized==0.8.1 -RUN pip3 install pyfakefs - -# Install docker engine 24 inside docker and enable experimental feature -RUN apt-get update -RUN eatmydata apt-get install -y \ - apt-transport-https \ - ca-certificates \ - curl \ - gnupg2 \ - software-properties-common -{%- if CONFIGURED_ARCH == "armhf" %} - RUN update-ca-certificates --fresh -{%- endif %} -RUN curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - -RUN add-apt-repository \ -{%- if CROSS_BUILD_ENVIRON == "y" %} - "deb https://download.docker.com/linux/debian \ -{%- else %} - "deb [arch={{ CONFIGURED_ARCH }}] https://download.docker.com/linux/debian \ -{%- endif %} - $(lsb_release -cs) \ - stable" -RUN apt-get update -RUN eatmydata apt-get install -y docker-ce=5:24.0.2-1~debian.11~bullseye docker-ce-cli=5:24.0.2-1~debian.11~bullseye containerd.io=1.6.21-1 docker-buildx-plugin=0.10.5-1~debian.11~bullseye docker-compose-plugin=2.18.1-1~debian.11~bullseye -RUN echo "DOCKER_OPTS=\"--experimental --storage-driver=vfs {{ DOCKER_EXTRA_OPTS }}\"" >> /etc/default/docker -RUN update-alternatives --set iptables /usr/sbin/iptables-legacy - -# Install m2crypto package, needed by SWI tools -RUN pip3 install m2crypto==0.36.0 - -# Install swi tools -RUN pip3 install git+https://github.com/aristanetworks/swi-tools.git@bead66bf261770237f7dd21ace3774ba04a017e9 - -{% if CONFIGURED_ARCH != "amd64" -%} -# Install node.js for azure pipeline -RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - -RUN eatmydata apt-get install -y nodejs - -{%- if CROSS_BUILD_ENVIRON == "y" %} -RUN eatmydata apt-get install -y rsync dh-python - -RUN eatmydata apt-get install -y libelf-dev:$arch libdw-dev:$arch libbz2-dev:$arch liblzo2-dev:$arch libedit-dev:$arch libevent-dev:$arch libopts25-dev:$arch libssl-dev:$arch pps-tools:$arch libpam-cap:$arch libcap-dev:$arch libpam0g-dev:$arch libaudit-dev:$arch libgtk-3-dev:$arch libkrb5-dev:$arch libsystemd-dev:$arch libwrap0-dev:$arch libkrb5-dev:$arch libboost1.74-dev:$arch libboost-dev:$arch libzmq5:$arch libzmq3-dev:$arch libdaemon-dev:$arch libjansson-dev:$arch libmnl-dev:$arch libsensors5:$arch libsensors4-dev:$arch libperl-dev:$arch libmariadb-dev:$arch libmariadb-dev-compat:$arch libpci-dev:$arch libjson-c-dev:$arch libreadline-dev:$arch librtr-dev:$arch librrd-dev:$arch libnetfilter-conntrack-dev:$arch libnetfilter-conntrack3:$arch libnfnetlink-dev:$arch libnftnl-dev:$arch libldap2-dev:$arch libbind-export-dev:$arch check:$arch libboost-atomic-dev:$arch libboost-test-dev:$arch libglib2.0-dev:$arch libexplain-dev:$arch libc-ares-dev:$arch libiptc0:$arch libxtables12:$arch libatm1-dev:$arch libbpf-dev:$arch libdb-dev:$arch pkg-config:$arch libnghttp2-14:$arch librtmp1:$arch libssh2-1:$arch libcjson1:$arch libcjson-dev:$arch libcurl4-openssl-dev:$arch libboost-thread1.74-dev:$arch libboost-thread-dev:$arch libboost-system1.74-dev:$arch libboost-system-dev:$arch libgtest-dev:$arch libgmock-dev:$arch libfido2-dev:$arch libcunit1:$arch libcunit1-dev:$arch libauparse-dev:$arch libnetsnmptrapd40:$arch qtbase5-dev:$arch libboost-log-dev:$arch libboost-filesystem-dev:$arch libboost-program-options-dev:$arch - -RUN apt-get download libgirepository1.0-dev:$arch && eatmydata dpkg --force-all -i libgirepository1.0-dev* -RUN PATH=/python_virtualenv/env3/bin/:$PATH pip3 install pycairo - -# Install libpcsclite-dev for wpasupplicant using download because regular install removes amd64 python package -RUN apt-get download libpcsclite1:$arch && eatmydata dpkg --force-all -i libpcsclite1* && apt-get download libpcsclite-dev:$arch && eatmydata dpkg --force-all -i libpcsclite-dev* -# Install python3-dev for frr (/usr/bin/python3-config for $arch) using download because regular install removes amd64 python package -RUN apt-get download python3.9-dev:$arch && apt-get download python3-dev:$arch && eatmydata dpkg --force-all -i python3*-dev* -{% endif %} - -# Tell azure pipeline to use node.js in the docker -LABEL "com.azure.dev.pipelines.agent.handler.node.path"="/usr/bin/node" -{% endif -%} - -# Install Bazel build system (amd64 and arm64 architectures are supported using this method) -# TODO(PINS): Remove once pre-build Bazel binaries are available for armhf (armv7l) -{%- if CONFIGURED_ARCH == "amd64" or CONFIGURED_ARCH == "arm64" %} -ARG bazelisk_url=https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-{{ CONFIGURED_ARCH }} -RUN curl -fsSL -o /usr/local/bin/bazel ${bazelisk_url} && chmod 755 /usr/local/bin/bazel -# Bazel requires "python" -# TODO(PINS): remove when Bazel is okay with "python3" binary name -RUN eatmydata apt install -y python-is-python3 -{% endif -%} diff --git a/src/sonic-framework/.gitignore b/src/sonic-framework/.gitignore deleted file mode 100644 index b3c79bc051f0..000000000000 --- a/src/sonic-framework/.gitignore +++ /dev/null @@ -1,45 +0,0 @@ -# Compiled Source # -################### -*.la -*.lo -*.o -*.pyc - -# Packaging Files # -################### -**/Makefile -Makefile.in -aclocal.m4 -autom4te.cache/ -config -config.h -config.h.in -config.h.in~ -config.log -config.status -configure -libtool -stamp-h1 - -debian/.debhelper/ -debian/autoreconf.after -debian/autoreconf.before -debian/debhelper-build-stamp -debian/files -debian/*.debhelper.log -debian/*.substvars - -debian/framework -debian/framework-dbg - -# Prebuilt Source -############### -rebootbackend/common -rebootbackend/system -rebootbackend/types - -# Executables # -############### -rebootbackend/rebootbackend -stateverificationd/stateverificationd - diff --git a/src/sonic-framework/Makefile.am b/src/sonic-framework/Makefile.am index 37ad5a41dc7c..23051da40f3c 100644 --- a/src/sonic-framework/Makefile.am +++ b/src/sonic-framework/Makefile.am @@ -1,21 +1,19 @@ .PHONY: compile_protobufs +AUTOMAKE_OPTIONS = subdir-objects +INCLUDES = -I ../sonic-swss-common/common BUILT_SOURCES = rebootbackend_protobuf_compilation rebootbackend_dbus_compilation -# compile_protobufs target needed by: -# gpins-cicd/scripts/sonic-framework/build_and_test_in_docker.sh compile_protobufs: rebootbackend_protobuf_compilation rebootbackend_dbus_compilation -rebootbackend_protobuf_compilation: - /usr/bin/protoc --cpp_out=rebootbackend --proto_path=./gnoi \ - ./gnoi/types/types.proto \ - ./gnoi/common/common.proto \ - ./gnoi/system/system.proto - /usr/bin/protoc --experimental_allow_proto3_optional --cpp_out=. rebootbackend/container_stop.proto +rebootbackend_protobuf_compilation: + /usr/bin/protoc --cpp_out=rebootbackend \ + --proto_path=gnoi \ + gnoi/types/types.proto \ + gnoi/common/common.proto \ + gnoi/system/system.proto rebootbackend_dbus_compilation: /usr/bin/dbusxx-xml2cpp rebootbackend/gnoi_reboot.xml \ --proxy=rebootbackend/gnoi_reboot_dbus.h - /usr/bin/dbusxx-xml2cpp rebootbackend/gnoi_container_shutdown.xml \ - --proxy=rebootbackend/gnoi_container_shutdown_dbus.h SUBDIRS = rebootbackend diff --git a/src/sonic-framework/autogen.sh b/src/sonic-framework/autogen.sh index c282a898f1c1..4a5ffda82dde 100755 --- a/src/sonic-framework/autogen.sh +++ b/src/sonic-framework/autogen.sh @@ -1,5 +1,5 @@ #!/bin/bash - + libtoolize --force --copy && autoreconf --force --install -I m4 rm -Rf autom4te.cache diff --git a/src/sonic-framework/debian/changelog b/src/sonic-framework/debian/changelog index 04ec2aecab85..93dae9ae8a70 100644 --- a/src/sonic-framework/debian/changelog +++ b/src/sonic-framework/debian/changelog @@ -2,5 +2,5 @@ sonic (1.0.0) stable; urgency=medium * Initial release. - -- Runming Wu Wed, 20 Sep 2023 12:00:00 -0800 + -- Runming Wu Wed, 20 Sep 2023 12:00:00 -0800 diff --git a/src/sonic-framework/debian/compat b/src/sonic-framework/debian/compat index f599e28b8ab0..52a8c6d10ce8 100644 --- a/src/sonic-framework/debian/compat +++ b/src/sonic-framework/debian/compat @@ -1 +1 @@ -10 +10 diff --git a/src/sonic-framework/debian/control b/src/sonic-framework/debian/control index d1c19f4ad296..cb588a8ce73c 100644 --- a/src/sonic-framework/debian/control +++ b/src/sonic-framework/debian/control @@ -8,7 +8,7 @@ Standards-Version: 1.0.0 Package: framework Architecture: any Depends: ${shlibs:Depends} -Description: This package contains framework service for GPINs project. +Description: This package contains framework service. Package: framework-dbg Architecture: any diff --git a/src/sonic-framework/debian/rules b/src/sonic-framework/debian/rules index a1a2957b9fec..5d0fe39d9c98 100755 --- a/src/sonic-framework/debian/rules +++ b/src/sonic-framework/debian/rules @@ -33,6 +33,6 @@ override_dh_auto_configure: override_dh_auto_install: dh_auto_install --destdir=debian/framework -override_dh_strip: +override_dh_strip: dh_strip -pframework --dbg-package=framework-dbg diff --git a/src/sonic-framework/gnoi/.bazelversion b/src/sonic-framework/gnoi/.bazelversion deleted file mode 100644 index 19b860c1872d..000000000000 --- a/src/sonic-framework/gnoi/.bazelversion +++ /dev/null @@ -1 +0,0 @@ -6.4.0 diff --git a/src/sonic-framework/gnoi/.github/dependabot.yml b/src/sonic-framework/gnoi/.github/dependabot.yml deleted file mode 100644 index a2a66d097fb4..000000000000 --- a/src/sonic-framework/gnoi/.github/dependabot.yml +++ /dev/null @@ -1,15 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - package-ecosystem: "gomod" # See documentation for possible values - directory: "/" # Location of package manifests - schedule: - interval: "weekly" - - package-ecosystem: "github-actions" # See documentation for possible values - directory: "/" # Location of package manifests - schedule: - interval: "weekly" diff --git a/src/sonic-framework/gnoi/.github/protolint.yaml b/src/sonic-framework/gnoi/.github/protolint.yaml deleted file mode 100644 index a4aba2e48227..000000000000 --- a/src/sonic-framework/gnoi/.github/protolint.yaml +++ /dev/null @@ -1,6 +0,0 @@ -lint: - rules: - remove: - - ENUM_FIELD_NAMES_PREFIX - - ENUM_FIELD_NAMES_ZERO_VALUE_END_WITH - - REPEATED_FIELD_NAMES_PLURALIZED diff --git a/src/sonic-framework/gnoi/.github/workflows/ci-cpp-build-gnoi.yml b/src/sonic-framework/gnoi/.github/workflows/ci-cpp-build-gnoi.yml deleted file mode 100644 index e293c6498660..000000000000 --- a/src/sonic-framework/gnoi/.github/workflows/ci-cpp-build-gnoi.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: "bazel build" - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - schedule: - - cron: "0 0 * * *" - -jobs: - build: - runs-on: ubuntu-latest - env: - BAZEL: bazelisk-linux-amd64 - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Mount bazel cache - uses: actions/cache@v4 - with: - # See https://docs.bazel.build/versions/master/output_directories.html - path: "~/.cache/bazel" - # Create a new cache entry whenever Bazel files change. - # See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows - key: bazel-${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }} - restore-keys: | - bazel-${{ runner.os }}-build- - - name: Install bazelisk - run: | - curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.8.1/$BAZEL" - chmod +x $BAZEL - sudo mv $BAZEL /usr/local/bin/bazel - - - name: Build - run: bazel build //... diff --git a/src/sonic-framework/gnoi/.github/workflows/go.yml b/src/sonic-framework/gnoi/.github/workflows/go.yml deleted file mode 100644 index 66814b3c6ebf..000000000000 --- a/src/sonic-framework/gnoi/.github/workflows/go.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Go - -on: - push: - branches: [ main ] - pull_request: - schedule: - - cron: "0 0 * * *" - -jobs: - go: - uses: openconfig/common-ci/.github/workflows/basic_go.yml@66c8f8f6a58d5f9c9e84efe89f542b08cb6a0a33 diff --git a/src/sonic-framework/gnoi/.github/workflows/linter.yml b/src/sonic-framework/gnoi/.github/workflows/linter.yml deleted file mode 100644 index 2320d4051128..000000000000 --- a/src/sonic-framework/gnoi/.github/workflows/linter.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Lint Code Base - -on: - push: - branches-ignore: [main] - # Remove the line above to run when pushing to master - pull_request: - branches: [main] - -jobs: - build: - name: Lint Code Base - runs-on: ubuntu-latest - - steps: - - name: Checkout Code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Lint protobuf - uses: plexsystems/protolint-action@v0.7.0 - with: - configDirectory: .github diff --git a/src/sonic-framework/gnoi/.gitignore b/src/sonic-framework/gnoi/.gitignore deleted file mode 100644 index ac51a054d2da..000000000000 --- a/src/sonic-framework/gnoi/.gitignore +++ /dev/null @@ -1 +0,0 @@ -bazel-* diff --git a/src/sonic-framework/gnoi/common/common.proto b/src/sonic-framework/gnoi/common/common.proto index 35a88c69711f..913c9fc6163d 100644 --- a/src/sonic-framework/gnoi/common/common.proto +++ b/src/sonic-framework/gnoi/common/common.proto @@ -18,7 +18,6 @@ syntax = "proto3"; package gnoi.common; -//import "github.com/openconfig/gnoi/types/types.proto"; import "types/types.proto"; option go_package = "github.com/openconfig/gnoi/common"; diff --git a/src/sonic-framework/package.cfg b/src/sonic-framework/package.cfg new file mode 100644 index 000000000000..e80d873ab346 --- /dev/null +++ b/src/sonic-framework/package.cfg @@ -0,0 +1,15 @@ +{ + "description": "This package contains SONiC framework.", + "version": "1.0.0", + "maintainer": "Runming Wu ", + "build_depends": [ ], + "packages": [ + { + "name": "sonic-framework", + "dependencies": [ + ], + "files": [ + ] + } + ] +} diff --git a/src/sonic-framework/rebootbackend/Makefile.am b/src/sonic-framework/rebootbackend/Makefile.am index afd3de9d0b74..205c879802f2 100644 --- a/src/sonic-framework/rebootbackend/Makefile.am +++ b/src/sonic-framework/rebootbackend/Makefile.am @@ -1,4 +1,5 @@ -INCLUDES = -I $(top_srcdir) -I/usr/include/dbus-c++-1/ -I $(top_srcdir)/system +AUTOMAKE_OPTIONS = subdir-objects +INCLUDES = -I $(top_srcdir) -I/usr/include/dbus-c++-1/ -I $(top_srcdir)/system -I ../../sonic-swss-common/common bin_PROGRAMS = rebootbackend @@ -9,10 +10,10 @@ DBGFLAGS = -g endif rebootbackend_SOURCES = rebootbackend.cpp rebootbe.cpp interfaces.cpp \ - reboot_thread.cpp init_thread.cpp redis_utils.cpp \ - reboot_common.cpp telemetry_helper.cpp \ + reboot_thread.cpp redis_utils.cpp \ + reboot_common.cpp \ system/system.pb.cc types/types.pb.cc \ - common/common.pb.cc container_stop.pb.cc + common/common.pb.cc rebootbackend_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) rebootbackend_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) diff --git a/src/sonic-framework/rebootbackend/container_stop.pb.cc b/src/sonic-framework/rebootbackend/container_stop.pb.cc deleted file mode 100644 index e32df4f1353c..000000000000 --- a/src/sonic-framework/rebootbackend/container_stop.pb.cc +++ /dev/null @@ -1,1337 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: rebootbackend/container_stop.proto - -#include "rebootbackend/container_stop.pb.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) -#include -extern PROTOBUF_INTERNAL_EXPORT_rebootbackend_2fcontainer_5fstop_2eproto ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_ContainerStatus_rebootbackend_2fcontainer_5fstop_2eproto; -extern PROTOBUF_INTERNAL_EXPORT_rebootbackend_2fcontainer_5fstop_2eproto ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<1> scc_info_StopContainersResponse_ContainerStatusEntry_DoNotUse_rebootbackend_2fcontainer_5fstop_2eproto; -class StopContainersRequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _StopContainersRequest_default_instance_; -class ContainerStatusDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _ContainerStatus_default_instance_; -class StopContainersStatusRequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _StopContainersStatusRequest_default_instance_; -class StopContainersResponse_ContainerStatusEntry_DoNotUseDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _StopContainersResponse_ContainerStatusEntry_DoNotUse_default_instance_; -class StopContainersResponseDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _StopContainersResponse_default_instance_; -static void InitDefaultsscc_info_ContainerStatus_rebootbackend_2fcontainer_5fstop_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::_ContainerStatus_default_instance_; - new (ptr) ::ContainerStatus(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::ContainerStatus::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_ContainerStatus_rebootbackend_2fcontainer_5fstop_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_ContainerStatus_rebootbackend_2fcontainer_5fstop_2eproto}, {}}; - -static void InitDefaultsscc_info_StopContainersRequest_rebootbackend_2fcontainer_5fstop_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::_StopContainersRequest_default_instance_; - new (ptr) ::StopContainersRequest(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::StopContainersRequest::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_StopContainersRequest_rebootbackend_2fcontainer_5fstop_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_StopContainersRequest_rebootbackend_2fcontainer_5fstop_2eproto}, {}}; - -static void InitDefaultsscc_info_StopContainersResponse_rebootbackend_2fcontainer_5fstop_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::_StopContainersResponse_default_instance_; - new (ptr) ::StopContainersResponse(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::StopContainersResponse::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<1> scc_info_StopContainersResponse_rebootbackend_2fcontainer_5fstop_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 1, 0, InitDefaultsscc_info_StopContainersResponse_rebootbackend_2fcontainer_5fstop_2eproto}, { - &scc_info_StopContainersResponse_ContainerStatusEntry_DoNotUse_rebootbackend_2fcontainer_5fstop_2eproto.base,}}; - -static void InitDefaultsscc_info_StopContainersResponse_ContainerStatusEntry_DoNotUse_rebootbackend_2fcontainer_5fstop_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::_StopContainersResponse_ContainerStatusEntry_DoNotUse_default_instance_; - new (ptr) ::StopContainersResponse_ContainerStatusEntry_DoNotUse(); - } - ::StopContainersResponse_ContainerStatusEntry_DoNotUse::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<1> scc_info_StopContainersResponse_ContainerStatusEntry_DoNotUse_rebootbackend_2fcontainer_5fstop_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 1, 0, InitDefaultsscc_info_StopContainersResponse_ContainerStatusEntry_DoNotUse_rebootbackend_2fcontainer_5fstop_2eproto}, { - &scc_info_ContainerStatus_rebootbackend_2fcontainer_5fstop_2eproto.base,}}; - -static void InitDefaultsscc_info_StopContainersStatusRequest_rebootbackend_2fcontainer_5fstop_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::_StopContainersStatusRequest_default_instance_; - new (ptr) ::StopContainersStatusRequest(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::StopContainersStatusRequest::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_StopContainersStatusRequest_rebootbackend_2fcontainer_5fstop_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_StopContainersStatusRequest_rebootbackend_2fcontainer_5fstop_2eproto}, {}}; - -static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_rebootbackend_2fcontainer_5fstop_2eproto[5]; -static const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* file_level_enum_descriptors_rebootbackend_2fcontainer_5fstop_2eproto[1]; -static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_rebootbackend_2fcontainer_5fstop_2eproto = nullptr; - -const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_rebootbackend_2fcontainer_5fstop_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - PROTOBUF_FIELD_OFFSET(::StopContainersRequest, _has_bits_), - PROTOBUF_FIELD_OFFSET(::StopContainersRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::StopContainersRequest, request_id_), - PROTOBUF_FIELD_OFFSET(::StopContainersRequest, container_names_), - 0, - ~0u, - PROTOBUF_FIELD_OFFSET(::ContainerStatus, _has_bits_), - PROTOBUF_FIELD_OFFSET(::ContainerStatus, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::ContainerStatus, status_), - PROTOBUF_FIELD_OFFSET(::ContainerStatus, error_message_), - 1, - 0, - PROTOBUF_FIELD_OFFSET(::StopContainersStatusRequest, _has_bits_), - PROTOBUF_FIELD_OFFSET(::StopContainersStatusRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::StopContainersStatusRequest, request_id_), - 0, - PROTOBUF_FIELD_OFFSET(::StopContainersResponse_ContainerStatusEntry_DoNotUse, _has_bits_), - PROTOBUF_FIELD_OFFSET(::StopContainersResponse_ContainerStatusEntry_DoNotUse, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::StopContainersResponse_ContainerStatusEntry_DoNotUse, key_), - PROTOBUF_FIELD_OFFSET(::StopContainersResponse_ContainerStatusEntry_DoNotUse, value_), - 0, - 1, - PROTOBUF_FIELD_OFFSET(::StopContainersResponse, _has_bits_), - PROTOBUF_FIELD_OFFSET(::StopContainersResponse, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::StopContainersResponse, status_), - PROTOBUF_FIELD_OFFSET(::StopContainersResponse, error_message_), - PROTOBUF_FIELD_OFFSET(::StopContainersResponse, container_status_), - 1, - 0, - ~0u, -}; -static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, 7, sizeof(::StopContainersRequest)}, - { 9, 16, sizeof(::ContainerStatus)}, - { 18, 24, sizeof(::StopContainersStatusRequest)}, - { 25, 32, sizeof(::StopContainersResponse_ContainerStatusEntry_DoNotUse)}, - { 34, 42, sizeof(::StopContainersResponse)}, -}; - -static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = { - reinterpret_cast(&::_StopContainersRequest_default_instance_), - reinterpret_cast(&::_ContainerStatus_default_instance_), - reinterpret_cast(&::_StopContainersStatusRequest_default_instance_), - reinterpret_cast(&::_StopContainersResponse_ContainerStatusEntry_DoNotUse_default_instance_), - reinterpret_cast(&::_StopContainersResponse_default_instance_), -}; - -const char descriptor_table_protodef_rebootbackend_2fcontainer_5fstop_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = - "\n\"rebootbackend/container_stop.proto\"X\n\025" - "StopContainersRequest\022\027\n\nrequest_id\030\001 \001(" - "\tH\000\210\001\001\022\027\n\017container_names\030\002 \003(\tB\r\n\013_requ" - "est_id\"p\n\017ContainerStatus\022$\n\006status\030\001 \001(" - "\0162\017.ShutdownStatusH\000\210\001\001\022\032\n\rerror_message" - "\030\002 \001(\tH\001\210\001\001B\t\n\007_statusB\020\n\016_error_message" - "\"E\n\033StopContainersStatusRequest\022\027\n\nreque" - "st_id\030\001 \001(\tH\000\210\001\001B\r\n\013_request_id\"\211\002\n\026Stop" - "ContainersResponse\022$\n\006status\030\001 \001(\0162\017.Shu" - "tdownStatusH\000\210\001\001\022\032\n\rerror_message\030\002 \001(\tH" - "\001\210\001\001\022F\n\020container_status\030\003 \003(\0132,.StopCon" - "tainersResponse.ContainerStatusEntry\032H\n\024" - "ContainerStatusEntry\022\013\n\003key\030\001 \001(\t\022\037\n\005val" - "ue\030\002 \001(\0132\020.ContainerStatus:\0028\001B\t\n\007_statu" - "sB\020\n\016_error_message*u\n\016ShutdownStatus\022\017\n" - "\013NOT_STARTED\020\000\022\035\n\031WAITING_FOR_NICE_SHUTD" - "OWN\020\001\022\036\n\032WAITING_FOR_FORCE_SHUTDOWN\020\002\022\010\n" - "\004DONE\020\003\022\t\n\005ERROR\020\004b\006proto3" - ; -static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto_deps[1] = { -}; -static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto_sccs[5] = { - &scc_info_ContainerStatus_rebootbackend_2fcontainer_5fstop_2eproto.base, - &scc_info_StopContainersRequest_rebootbackend_2fcontainer_5fstop_2eproto.base, - &scc_info_StopContainersResponse_rebootbackend_2fcontainer_5fstop_2eproto.base, - &scc_info_StopContainersResponse_ContainerStatusEntry_DoNotUse_rebootbackend_2fcontainer_5fstop_2eproto.base, - &scc_info_StopContainersStatusRequest_rebootbackend_2fcontainer_5fstop_2eproto.base, -}; -static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto_once; -const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto = { - false, false, descriptor_table_protodef_rebootbackend_2fcontainer_5fstop_2eproto, "rebootbackend/container_stop.proto", 706, - &descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto_once, descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto_sccs, descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto_deps, 5, 0, - schemas, file_default_instances, TableStruct_rebootbackend_2fcontainer_5fstop_2eproto::offsets, - file_level_metadata_rebootbackend_2fcontainer_5fstop_2eproto, 5, file_level_enum_descriptors_rebootbackend_2fcontainer_5fstop_2eproto, file_level_service_descriptors_rebootbackend_2fcontainer_5fstop_2eproto, -}; - -// Force running AddDescriptors() at dynamic initialization time. -static bool dynamic_init_dummy_rebootbackend_2fcontainer_5fstop_2eproto = (static_cast(::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto)), true); -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* ShutdownStatus_descriptor() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto); - return file_level_enum_descriptors_rebootbackend_2fcontainer_5fstop_2eproto[0]; -} -bool ShutdownStatus_IsValid(int value) { - switch (value) { - case 0: - case 1: - case 2: - case 3: - case 4: - return true; - default: - return false; - } -} - - -// =================================================================== - -void StopContainersRequest::InitAsDefaultInstance() { -} -class StopContainersRequest::_Internal { - public: - using HasBits = decltype(std::declval()._has_bits_); - static void set_has_request_id(HasBits* has_bits) { - (*has_bits)[0] |= 1u; - } -}; - -StopContainersRequest::StopContainersRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena), - container_names_(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:StopContainersRequest) -} -StopContainersRequest::StopContainersRequest(const StopContainersRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), - _has_bits_(from._has_bits_), - container_names_(from.container_names_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - request_id_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from._internal_has_request_id()) { - request_id_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_request_id(), - GetArena()); - } - // @@protoc_insertion_point(copy_constructor:StopContainersRequest) -} - -void StopContainersRequest::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_StopContainersRequest_rebootbackend_2fcontainer_5fstop_2eproto.base); - request_id_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -StopContainersRequest::~StopContainersRequest() { - // @@protoc_insertion_point(destructor:StopContainersRequest) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void StopContainersRequest::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - request_id_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void StopContainersRequest::ArenaDtor(void* object) { - StopContainersRequest* _this = reinterpret_cast< StopContainersRequest* >(object); - (void)_this; -} -void StopContainersRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void StopContainersRequest::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const StopContainersRequest& StopContainersRequest::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_StopContainersRequest_rebootbackend_2fcontainer_5fstop_2eproto.base); - return *internal_default_instance(); -} - - -void StopContainersRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:StopContainersRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - container_names_.Clear(); - cached_has_bits = _has_bits_[0]; - if (cached_has_bits & 0x00000001u) { - request_id_.ClearNonDefaultToEmpty(); - } - _has_bits_.Clear(); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* StopContainersRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - _Internal::HasBits has_bits{}; - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // string request_id = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - auto str = _internal_mutable_request_id(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "StopContainersRequest.request_id")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // repeated string container_names = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr -= 1; - do { - ptr += 1; - auto str = _internal_add_container_names(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "StopContainersRequest.container_names")); - CHK_(ptr); - if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - _has_bits_.Or(has_bits); - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* StopContainersRequest::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:StopContainersRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // string request_id = 1; - if (_internal_has_request_id()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_request_id().data(), static_cast(this->_internal_request_id().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "StopContainersRequest.request_id"); - target = stream->WriteStringMaybeAliased( - 1, this->_internal_request_id(), target); - } - - // repeated string container_names = 2; - for (int i = 0, n = this->_internal_container_names_size(); i < n; i++) { - const auto& s = this->_internal_container_names(i); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - s.data(), static_cast(s.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "StopContainersRequest.container_names"); - target = stream->WriteString(2, s, target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:StopContainersRequest) - return target; -} - -size_t StopContainersRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:StopContainersRequest) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // repeated string container_names = 2; - total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(container_names_.size()); - for (int i = 0, n = container_names_.size(); i < n; i++) { - total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - container_names_.Get(i)); - } - - // string request_id = 1; - cached_has_bits = _has_bits_[0]; - if (cached_has_bits & 0x00000001u) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_request_id()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void StopContainersRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:StopContainersRequest) - GOOGLE_DCHECK_NE(&from, this); - const StopContainersRequest* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:StopContainersRequest) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:StopContainersRequest) - MergeFrom(*source); - } -} - -void StopContainersRequest::MergeFrom(const StopContainersRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:StopContainersRequest) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - container_names_.MergeFrom(from.container_names_); - if (from._internal_has_request_id()) { - _internal_set_request_id(from._internal_request_id()); - } -} - -void StopContainersRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:StopContainersRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void StopContainersRequest::CopyFrom(const StopContainersRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:StopContainersRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool StopContainersRequest::IsInitialized() const { - return true; -} - -void StopContainersRequest::InternalSwap(StopContainersRequest* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - swap(_has_bits_[0], other->_has_bits_[0]); - container_names_.InternalSwap(&other->container_names_); - request_id_.Swap(&other->request_id_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} - -::PROTOBUF_NAMESPACE_ID::Metadata StopContainersRequest::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void ContainerStatus::InitAsDefaultInstance() { -} -class ContainerStatus::_Internal { - public: - using HasBits = decltype(std::declval()._has_bits_); - static void set_has_status(HasBits* has_bits) { - (*has_bits)[0] |= 2u; - } - static void set_has_error_message(HasBits* has_bits) { - (*has_bits)[0] |= 1u; - } -}; - -ContainerStatus::ContainerStatus(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:ContainerStatus) -} -ContainerStatus::ContainerStatus(const ContainerStatus& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), - _has_bits_(from._has_bits_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - error_message_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from._internal_has_error_message()) { - error_message_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_message(), - GetArena()); - } - status_ = from.status_; - // @@protoc_insertion_point(copy_constructor:ContainerStatus) -} - -void ContainerStatus::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_ContainerStatus_rebootbackend_2fcontainer_5fstop_2eproto.base); - error_message_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - status_ = 0; -} - -ContainerStatus::~ContainerStatus() { - // @@protoc_insertion_point(destructor:ContainerStatus) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void ContainerStatus::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - error_message_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void ContainerStatus::ArenaDtor(void* object) { - ContainerStatus* _this = reinterpret_cast< ContainerStatus* >(object); - (void)_this; -} -void ContainerStatus::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void ContainerStatus::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const ContainerStatus& ContainerStatus::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_ContainerStatus_rebootbackend_2fcontainer_5fstop_2eproto.base); - return *internal_default_instance(); -} - - -void ContainerStatus::Clear() { -// @@protoc_insertion_point(message_clear_start:ContainerStatus) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - cached_has_bits = _has_bits_[0]; - if (cached_has_bits & 0x00000001u) { - error_message_.ClearNonDefaultToEmpty(); - } - status_ = 0; - _has_bits_.Clear(); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* ContainerStatus::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - _Internal::HasBits has_bits{}; - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // .ShutdownStatus status = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - ::PROTOBUF_NAMESPACE_ID::uint64 val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - _internal_set_status(static_cast<::ShutdownStatus>(val)); - } else goto handle_unusual; - continue; - // string error_message = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - auto str = _internal_mutable_error_message(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "ContainerStatus.error_message")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - _has_bits_.Or(has_bits); - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* ContainerStatus::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:ContainerStatus) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // .ShutdownStatus status = 1; - if (_internal_has_status()) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteEnumToArray( - 1, this->_internal_status(), target); - } - - // string error_message = 2; - if (_internal_has_error_message()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_message().data(), static_cast(this->_internal_error_message().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "ContainerStatus.error_message"); - target = stream->WriteStringMaybeAliased( - 2, this->_internal_error_message(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:ContainerStatus) - return target; -} - -size_t ContainerStatus::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:ContainerStatus) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - cached_has_bits = _has_bits_[0]; - if (cached_has_bits & 0x00000003u) { - // string error_message = 2; - if (cached_has_bits & 0x00000001u) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_message()); - } - - // .ShutdownStatus status = 1; - if (cached_has_bits & 0x00000002u) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::EnumSize(this->_internal_status()); - } - - } - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void ContainerStatus::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:ContainerStatus) - GOOGLE_DCHECK_NE(&from, this); - const ContainerStatus* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:ContainerStatus) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:ContainerStatus) - MergeFrom(*source); - } -} - -void ContainerStatus::MergeFrom(const ContainerStatus& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:ContainerStatus) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - cached_has_bits = from._has_bits_[0]; - if (cached_has_bits & 0x00000003u) { - if (cached_has_bits & 0x00000001u) { - _internal_set_error_message(from._internal_error_message()); - } - if (cached_has_bits & 0x00000002u) { - status_ = from.status_; - } - _has_bits_[0] |= cached_has_bits; - } -} - -void ContainerStatus::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:ContainerStatus) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void ContainerStatus::CopyFrom(const ContainerStatus& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:ContainerStatus) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool ContainerStatus::IsInitialized() const { - return true; -} - -void ContainerStatus::InternalSwap(ContainerStatus* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - swap(_has_bits_[0], other->_has_bits_[0]); - error_message_.Swap(&other->error_message_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - swap(status_, other->status_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata ContainerStatus::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void StopContainersStatusRequest::InitAsDefaultInstance() { -} -class StopContainersStatusRequest::_Internal { - public: - using HasBits = decltype(std::declval()._has_bits_); - static void set_has_request_id(HasBits* has_bits) { - (*has_bits)[0] |= 1u; - } -}; - -StopContainersStatusRequest::StopContainersStatusRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:StopContainersStatusRequest) -} -StopContainersStatusRequest::StopContainersStatusRequest(const StopContainersStatusRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), - _has_bits_(from._has_bits_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - request_id_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from._internal_has_request_id()) { - request_id_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_request_id(), - GetArena()); - } - // @@protoc_insertion_point(copy_constructor:StopContainersStatusRequest) -} - -void StopContainersStatusRequest::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_StopContainersStatusRequest_rebootbackend_2fcontainer_5fstop_2eproto.base); - request_id_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -StopContainersStatusRequest::~StopContainersStatusRequest() { - // @@protoc_insertion_point(destructor:StopContainersStatusRequest) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void StopContainersStatusRequest::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - request_id_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void StopContainersStatusRequest::ArenaDtor(void* object) { - StopContainersStatusRequest* _this = reinterpret_cast< StopContainersStatusRequest* >(object); - (void)_this; -} -void StopContainersStatusRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void StopContainersStatusRequest::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const StopContainersStatusRequest& StopContainersStatusRequest::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_StopContainersStatusRequest_rebootbackend_2fcontainer_5fstop_2eproto.base); - return *internal_default_instance(); -} - - -void StopContainersStatusRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:StopContainersStatusRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - cached_has_bits = _has_bits_[0]; - if (cached_has_bits & 0x00000001u) { - request_id_.ClearNonDefaultToEmpty(); - } - _has_bits_.Clear(); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* StopContainersStatusRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - _Internal::HasBits has_bits{}; - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // string request_id = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - auto str = _internal_mutable_request_id(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "StopContainersStatusRequest.request_id")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - _has_bits_.Or(has_bits); - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* StopContainersStatusRequest::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:StopContainersStatusRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // string request_id = 1; - if (_internal_has_request_id()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_request_id().data(), static_cast(this->_internal_request_id().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "StopContainersStatusRequest.request_id"); - target = stream->WriteStringMaybeAliased( - 1, this->_internal_request_id(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:StopContainersStatusRequest) - return target; -} - -size_t StopContainersStatusRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:StopContainersStatusRequest) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string request_id = 1; - cached_has_bits = _has_bits_[0]; - if (cached_has_bits & 0x00000001u) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_request_id()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void StopContainersStatusRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:StopContainersStatusRequest) - GOOGLE_DCHECK_NE(&from, this); - const StopContainersStatusRequest* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:StopContainersStatusRequest) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:StopContainersStatusRequest) - MergeFrom(*source); - } -} - -void StopContainersStatusRequest::MergeFrom(const StopContainersStatusRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:StopContainersStatusRequest) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from._internal_has_request_id()) { - _internal_set_request_id(from._internal_request_id()); - } -} - -void StopContainersStatusRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:StopContainersStatusRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void StopContainersStatusRequest::CopyFrom(const StopContainersStatusRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:StopContainersStatusRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool StopContainersStatusRequest::IsInitialized() const { - return true; -} - -void StopContainersStatusRequest::InternalSwap(StopContainersStatusRequest* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - swap(_has_bits_[0], other->_has_bits_[0]); - request_id_.Swap(&other->request_id_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} - -::PROTOBUF_NAMESPACE_ID::Metadata StopContainersStatusRequest::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -StopContainersResponse_ContainerStatusEntry_DoNotUse::StopContainersResponse_ContainerStatusEntry_DoNotUse() {} -StopContainersResponse_ContainerStatusEntry_DoNotUse::StopContainersResponse_ContainerStatusEntry_DoNotUse(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : SuperType(arena) {} -void StopContainersResponse_ContainerStatusEntry_DoNotUse::MergeFrom(const StopContainersResponse_ContainerStatusEntry_DoNotUse& other) { - MergeFromInternal(other); -} -::PROTOBUF_NAMESPACE_ID::Metadata StopContainersResponse_ContainerStatusEntry_DoNotUse::GetMetadata() const { - return GetMetadataStatic(); -} -void StopContainersResponse_ContainerStatusEntry_DoNotUse::MergeFrom( - const ::PROTOBUF_NAMESPACE_ID::Message& other) { - ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom(other); -} - - -// =================================================================== - -void StopContainersResponse::InitAsDefaultInstance() { -} -class StopContainersResponse::_Internal { - public: - using HasBits = decltype(std::declval()._has_bits_); - static void set_has_status(HasBits* has_bits) { - (*has_bits)[0] |= 2u; - } - static void set_has_error_message(HasBits* has_bits) { - (*has_bits)[0] |= 1u; - } -}; - -StopContainersResponse::StopContainersResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena), - container_status_(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:StopContainersResponse) -} -StopContainersResponse::StopContainersResponse(const StopContainersResponse& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), - _has_bits_(from._has_bits_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - container_status_.MergeFrom(from.container_status_); - error_message_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from._internal_has_error_message()) { - error_message_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_message(), - GetArena()); - } - status_ = from.status_; - // @@protoc_insertion_point(copy_constructor:StopContainersResponse) -} - -void StopContainersResponse::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_StopContainersResponse_rebootbackend_2fcontainer_5fstop_2eproto.base); - error_message_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - status_ = 0; -} - -StopContainersResponse::~StopContainersResponse() { - // @@protoc_insertion_point(destructor:StopContainersResponse) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void StopContainersResponse::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - error_message_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void StopContainersResponse::ArenaDtor(void* object) { - StopContainersResponse* _this = reinterpret_cast< StopContainersResponse* >(object); - (void)_this; -} -void StopContainersResponse::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void StopContainersResponse::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const StopContainersResponse& StopContainersResponse::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_StopContainersResponse_rebootbackend_2fcontainer_5fstop_2eproto.base); - return *internal_default_instance(); -} - - -void StopContainersResponse::Clear() { -// @@protoc_insertion_point(message_clear_start:StopContainersResponse) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - container_status_.Clear(); - cached_has_bits = _has_bits_[0]; - if (cached_has_bits & 0x00000001u) { - error_message_.ClearNonDefaultToEmpty(); - } - status_ = 0; - _has_bits_.Clear(); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* StopContainersResponse::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - _Internal::HasBits has_bits{}; - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // .ShutdownStatus status = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - ::PROTOBUF_NAMESPACE_ID::uint64 val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - _internal_set_status(static_cast<::ShutdownStatus>(val)); - } else goto handle_unusual; - continue; - // string error_message = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - auto str = _internal_mutable_error_message(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "StopContainersResponse.error_message")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // map container_status = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - ptr -= 1; - do { - ptr += 1; - ptr = ctx->ParseMessage(&container_status_, ptr); - CHK_(ptr); - if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - _has_bits_.Or(has_bits); - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* StopContainersResponse::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:StopContainersResponse) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // .ShutdownStatus status = 1; - if (_internal_has_status()) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteEnumToArray( - 1, this->_internal_status(), target); - } - - // string error_message = 2; - if (_internal_has_error_message()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_message().data(), static_cast(this->_internal_error_message().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "StopContainersResponse.error_message"); - target = stream->WriteStringMaybeAliased( - 2, this->_internal_error_message(), target); - } - - // map container_status = 3; - if (!this->_internal_container_status().empty()) { - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >::const_pointer - ConstPtr; - typedef ConstPtr SortItem; - typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByDerefFirst Less; - struct Utf8Check { - static void Check(ConstPtr p) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - p->first.data(), static_cast(p->first.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "StopContainersResponse.ContainerStatusEntry.key"); - } - }; - - if (stream->IsSerializationDeterministic() && - this->_internal_container_status().size() > 1) { - ::std::unique_ptr items( - new SortItem[this->_internal_container_status().size()]); - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >::size_type size_type; - size_type n = 0; - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >::const_iterator - it = this->_internal_container_status().begin(); - it != this->_internal_container_status().end(); ++it, ++n) { - items[static_cast(n)] = SortItem(&*it); - } - ::std::sort(&items[0], &items[static_cast(n)], Less()); - for (size_type i = 0; i < n; i++) { - target = StopContainersResponse_ContainerStatusEntry_DoNotUse::Funcs::InternalSerialize(3, items[static_cast(i)]->first, items[static_cast(i)]->second, target, stream); - Utf8Check::Check(&(*items[static_cast(i)])); - } - } else { - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >::const_iterator - it = this->_internal_container_status().begin(); - it != this->_internal_container_status().end(); ++it) { - target = StopContainersResponse_ContainerStatusEntry_DoNotUse::Funcs::InternalSerialize(3, it->first, it->second, target, stream); - Utf8Check::Check(&(*it)); - } - } - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:StopContainersResponse) - return target; -} - -size_t StopContainersResponse::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:StopContainersResponse) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // map container_status = 3; - total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_container_status_size()); - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >::const_iterator - it = this->_internal_container_status().begin(); - it != this->_internal_container_status().end(); ++it) { - total_size += StopContainersResponse_ContainerStatusEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second); - } - - cached_has_bits = _has_bits_[0]; - if (cached_has_bits & 0x00000003u) { - // string error_message = 2; - if (cached_has_bits & 0x00000001u) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_message()); - } - - // .ShutdownStatus status = 1; - if (cached_has_bits & 0x00000002u) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::EnumSize(this->_internal_status()); - } - - } - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void StopContainersResponse::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:StopContainersResponse) - GOOGLE_DCHECK_NE(&from, this); - const StopContainersResponse* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:StopContainersResponse) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:StopContainersResponse) - MergeFrom(*source); - } -} - -void StopContainersResponse::MergeFrom(const StopContainersResponse& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:StopContainersResponse) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - container_status_.MergeFrom(from.container_status_); - cached_has_bits = from._has_bits_[0]; - if (cached_has_bits & 0x00000003u) { - if (cached_has_bits & 0x00000001u) { - _internal_set_error_message(from._internal_error_message()); - } - if (cached_has_bits & 0x00000002u) { - status_ = from.status_; - } - _has_bits_[0] |= cached_has_bits; - } -} - -void StopContainersResponse::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:StopContainersResponse) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void StopContainersResponse::CopyFrom(const StopContainersResponse& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:StopContainersResponse) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool StopContainersResponse::IsInitialized() const { - return true; -} - -void StopContainersResponse::InternalSwap(StopContainersResponse* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - swap(_has_bits_[0], other->_has_bits_[0]); - container_status_.Swap(&other->container_status_); - error_message_.Swap(&other->error_message_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - swap(status_, other->status_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata StopContainersResponse::GetMetadata() const { - return GetMetadataStatic(); -} - - -// @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_OPEN -template<> PROTOBUF_NOINLINE ::StopContainersRequest* Arena::CreateMaybeMessage< ::StopContainersRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::StopContainersRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::ContainerStatus* Arena::CreateMaybeMessage< ::ContainerStatus >(Arena* arena) { - return Arena::CreateMessageInternal< ::ContainerStatus >(arena); -} -template<> PROTOBUF_NOINLINE ::StopContainersStatusRequest* Arena::CreateMaybeMessage< ::StopContainersStatusRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::StopContainersStatusRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::StopContainersResponse_ContainerStatusEntry_DoNotUse* Arena::CreateMaybeMessage< ::StopContainersResponse_ContainerStatusEntry_DoNotUse >(Arena* arena) { - return Arena::CreateMessageInternal< ::StopContainersResponse_ContainerStatusEntry_DoNotUse >(arena); -} -template<> PROTOBUF_NOINLINE ::StopContainersResponse* Arena::CreateMaybeMessage< ::StopContainersResponse >(Arena* arena) { - return Arena::CreateMessageInternal< ::StopContainersResponse >(arena); -} -PROTOBUF_NAMESPACE_CLOSE - -// @@protoc_insertion_point(global_scope) -#include diff --git a/src/sonic-framework/rebootbackend/container_stop.pb.h b/src/sonic-framework/rebootbackend/container_stop.pb.h deleted file mode 100644 index 961cc1f0c2f2..000000000000 --- a/src/sonic-framework/rebootbackend/container_stop.pb.h +++ /dev/null @@ -1,1441 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: rebootbackend/container_stop.proto - -#ifndef GOOGLE_PROTOBUF_INCLUDED_rebootbackend_2fcontainer_5fstop_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_rebootbackend_2fcontainer_5fstop_2eproto - -#include -#include - -#include -#if PROTOBUF_VERSION < 3012000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3012004 < PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -#include -#include -#include -// @@protoc_insertion_point(includes) -#include -#define PROTOBUF_INTERNAL_EXPORT_rebootbackend_2fcontainer_5fstop_2eproto -PROTOBUF_NAMESPACE_OPEN -namespace internal { -class AnyMetadata; -} // namespace internal -PROTOBUF_NAMESPACE_CLOSE - -// Internal implementation detail -- do not use these members. -struct TableStruct_rebootbackend_2fcontainer_5fstop_2eproto { - static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] - PROTOBUF_SECTION_VARIABLE(protodesc_cold); - static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[] - PROTOBUF_SECTION_VARIABLE(protodesc_cold); - static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[5] - PROTOBUF_SECTION_VARIABLE(protodesc_cold); - static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[]; - static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[]; - static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[]; -}; -extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto; -class ContainerStatus; -class ContainerStatusDefaultTypeInternal; -extern ContainerStatusDefaultTypeInternal _ContainerStatus_default_instance_; -class StopContainersRequest; -class StopContainersRequestDefaultTypeInternal; -extern StopContainersRequestDefaultTypeInternal _StopContainersRequest_default_instance_; -class StopContainersResponse; -class StopContainersResponseDefaultTypeInternal; -extern StopContainersResponseDefaultTypeInternal _StopContainersResponse_default_instance_; -class StopContainersResponse_ContainerStatusEntry_DoNotUse; -class StopContainersResponse_ContainerStatusEntry_DoNotUseDefaultTypeInternal; -extern StopContainersResponse_ContainerStatusEntry_DoNotUseDefaultTypeInternal _StopContainersResponse_ContainerStatusEntry_DoNotUse_default_instance_; -class StopContainersStatusRequest; -class StopContainersStatusRequestDefaultTypeInternal; -extern StopContainersStatusRequestDefaultTypeInternal _StopContainersStatusRequest_default_instance_; -PROTOBUF_NAMESPACE_OPEN -template<> ::ContainerStatus* Arena::CreateMaybeMessage<::ContainerStatus>(Arena*); -template<> ::StopContainersRequest* Arena::CreateMaybeMessage<::StopContainersRequest>(Arena*); -template<> ::StopContainersResponse* Arena::CreateMaybeMessage<::StopContainersResponse>(Arena*); -template<> ::StopContainersResponse_ContainerStatusEntry_DoNotUse* Arena::CreateMaybeMessage<::StopContainersResponse_ContainerStatusEntry_DoNotUse>(Arena*); -template<> ::StopContainersStatusRequest* Arena::CreateMaybeMessage<::StopContainersStatusRequest>(Arena*); -PROTOBUF_NAMESPACE_CLOSE - -enum ShutdownStatus : int { - NOT_STARTED = 0, - WAITING_FOR_NICE_SHUTDOWN = 1, - WAITING_FOR_FORCE_SHUTDOWN = 2, - DONE = 3, - ERROR = 4, - ShutdownStatus_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::PROTOBUF_NAMESPACE_ID::int32>::min(), - ShutdownStatus_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::PROTOBUF_NAMESPACE_ID::int32>::max() -}; -bool ShutdownStatus_IsValid(int value); -constexpr ShutdownStatus ShutdownStatus_MIN = NOT_STARTED; -constexpr ShutdownStatus ShutdownStatus_MAX = ERROR; -constexpr int ShutdownStatus_ARRAYSIZE = ShutdownStatus_MAX + 1; - -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* ShutdownStatus_descriptor(); -template -inline const std::string& ShutdownStatus_Name(T enum_t_value) { - static_assert(::std::is_same::value || - ::std::is_integral::value, - "Incorrect type passed to function ShutdownStatus_Name."); - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( - ShutdownStatus_descriptor(), enum_t_value); -} -inline bool ShutdownStatus_Parse( - const std::string& name, ShutdownStatus* value) { - return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - ShutdownStatus_descriptor(), name, value); -} -// =================================================================== - -class StopContainersRequest PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:StopContainersRequest) */ { - public: - inline StopContainersRequest() : StopContainersRequest(nullptr) {}; - virtual ~StopContainersRequest(); - - StopContainersRequest(const StopContainersRequest& from); - StopContainersRequest(StopContainersRequest&& from) noexcept - : StopContainersRequest() { - *this = ::std::move(from); - } - - inline StopContainersRequest& operator=(const StopContainersRequest& from) { - CopyFrom(from); - return *this; - } - inline StopContainersRequest& operator=(StopContainersRequest&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const StopContainersRequest& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const StopContainersRequest* internal_default_instance() { - return reinterpret_cast( - &_StopContainersRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 0; - - friend void swap(StopContainersRequest& a, StopContainersRequest& b) { - a.Swap(&b); - } - inline void Swap(StopContainersRequest* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(StopContainersRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline StopContainersRequest* New() const final { - return CreateMaybeMessage(nullptr); - } - - StopContainersRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const StopContainersRequest& from); - void MergeFrom(const StopContainersRequest& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(StopContainersRequest* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "StopContainersRequest"; - } - protected: - explicit StopContainersRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto); - return ::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kContainerNamesFieldNumber = 2, - kRequestIdFieldNumber = 1, - }; - // repeated string container_names = 2; - int container_names_size() const; - private: - int _internal_container_names_size() const; - public: - void clear_container_names(); - const std::string& container_names(int index) const; - std::string* mutable_container_names(int index); - void set_container_names(int index, const std::string& value); - void set_container_names(int index, std::string&& value); - void set_container_names(int index, const char* value); - void set_container_names(int index, const char* value, size_t size); - std::string* add_container_names(); - void add_container_names(const std::string& value); - void add_container_names(std::string&& value); - void add_container_names(const char* value); - void add_container_names(const char* value, size_t size); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& container_names() const; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_container_names(); - private: - const std::string& _internal_container_names(int index) const; - std::string* _internal_add_container_names(); - public: - - // string request_id = 1; - bool has_request_id() const; - private: - bool _internal_has_request_id() const; - public: - void clear_request_id(); - const std::string& request_id() const; - void set_request_id(const std::string& value); - void set_request_id(std::string&& value); - void set_request_id(const char* value); - void set_request_id(const char* value, size_t size); - std::string* mutable_request_id(); - std::string* release_request_id(); - void set_allocated_request_id(std::string* request_id); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - std::string* unsafe_arena_release_request_id(); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - void unsafe_arena_set_allocated_request_id( - std::string* request_id); - private: - const std::string& _internal_request_id() const; - void _internal_set_request_id(const std::string& value); - std::string* _internal_mutable_request_id(); - public: - - // @@protoc_insertion_point(class_scope:StopContainersRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField container_names_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_id_; - friend struct ::TableStruct_rebootbackend_2fcontainer_5fstop_2eproto; -}; -// ------------------------------------------------------------------- - -class ContainerStatus PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:ContainerStatus) */ { - public: - inline ContainerStatus() : ContainerStatus(nullptr) {}; - virtual ~ContainerStatus(); - - ContainerStatus(const ContainerStatus& from); - ContainerStatus(ContainerStatus&& from) noexcept - : ContainerStatus() { - *this = ::std::move(from); - } - - inline ContainerStatus& operator=(const ContainerStatus& from) { - CopyFrom(from); - return *this; - } - inline ContainerStatus& operator=(ContainerStatus&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const ContainerStatus& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const ContainerStatus* internal_default_instance() { - return reinterpret_cast( - &_ContainerStatus_default_instance_); - } - static constexpr int kIndexInFileMessages = - 1; - - friend void swap(ContainerStatus& a, ContainerStatus& b) { - a.Swap(&b); - } - inline void Swap(ContainerStatus* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(ContainerStatus* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline ContainerStatus* New() const final { - return CreateMaybeMessage(nullptr); - } - - ContainerStatus* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const ContainerStatus& from); - void MergeFrom(const ContainerStatus& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(ContainerStatus* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "ContainerStatus"; - } - protected: - explicit ContainerStatus(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto); - return ::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kErrorMessageFieldNumber = 2, - kStatusFieldNumber = 1, - }; - // string error_message = 2; - bool has_error_message() const; - private: - bool _internal_has_error_message() const; - public: - void clear_error_message(); - const std::string& error_message() const; - void set_error_message(const std::string& value); - void set_error_message(std::string&& value); - void set_error_message(const char* value); - void set_error_message(const char* value, size_t size); - std::string* mutable_error_message(); - std::string* release_error_message(); - void set_allocated_error_message(std::string* error_message); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - std::string* unsafe_arena_release_error_message(); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - void unsafe_arena_set_allocated_error_message( - std::string* error_message); - private: - const std::string& _internal_error_message() const; - void _internal_set_error_message(const std::string& value); - std::string* _internal_mutable_error_message(); - public: - - // .ShutdownStatus status = 1; - bool has_status() const; - private: - bool _internal_has_status() const; - public: - void clear_status(); - ::ShutdownStatus status() const; - void set_status(::ShutdownStatus value); - private: - ::ShutdownStatus _internal_status() const; - void _internal_set_status(::ShutdownStatus value); - public: - - // @@protoc_insertion_point(class_scope:ContainerStatus) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_message_; - int status_; - friend struct ::TableStruct_rebootbackend_2fcontainer_5fstop_2eproto; -}; -// ------------------------------------------------------------------- - -class StopContainersStatusRequest PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:StopContainersStatusRequest) */ { - public: - inline StopContainersStatusRequest() : StopContainersStatusRequest(nullptr) {}; - virtual ~StopContainersStatusRequest(); - - StopContainersStatusRequest(const StopContainersStatusRequest& from); - StopContainersStatusRequest(StopContainersStatusRequest&& from) noexcept - : StopContainersStatusRequest() { - *this = ::std::move(from); - } - - inline StopContainersStatusRequest& operator=(const StopContainersStatusRequest& from) { - CopyFrom(from); - return *this; - } - inline StopContainersStatusRequest& operator=(StopContainersStatusRequest&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const StopContainersStatusRequest& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const StopContainersStatusRequest* internal_default_instance() { - return reinterpret_cast( - &_StopContainersStatusRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 2; - - friend void swap(StopContainersStatusRequest& a, StopContainersStatusRequest& b) { - a.Swap(&b); - } - inline void Swap(StopContainersStatusRequest* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(StopContainersStatusRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline StopContainersStatusRequest* New() const final { - return CreateMaybeMessage(nullptr); - } - - StopContainersStatusRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const StopContainersStatusRequest& from); - void MergeFrom(const StopContainersStatusRequest& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(StopContainersStatusRequest* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "StopContainersStatusRequest"; - } - protected: - explicit StopContainersStatusRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto); - return ::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kRequestIdFieldNumber = 1, - }; - // string request_id = 1; - bool has_request_id() const; - private: - bool _internal_has_request_id() const; - public: - void clear_request_id(); - const std::string& request_id() const; - void set_request_id(const std::string& value); - void set_request_id(std::string&& value); - void set_request_id(const char* value); - void set_request_id(const char* value, size_t size); - std::string* mutable_request_id(); - std::string* release_request_id(); - void set_allocated_request_id(std::string* request_id); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - std::string* unsafe_arena_release_request_id(); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - void unsafe_arena_set_allocated_request_id( - std::string* request_id); - private: - const std::string& _internal_request_id() const; - void _internal_set_request_id(const std::string& value); - std::string* _internal_mutable_request_id(); - public: - - // @@protoc_insertion_point(class_scope:StopContainersStatusRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_id_; - friend struct ::TableStruct_rebootbackend_2fcontainer_5fstop_2eproto; -}; -// ------------------------------------------------------------------- - -class StopContainersResponse_ContainerStatusEntry_DoNotUse : public ::PROTOBUF_NAMESPACE_ID::internal::MapEntry { -public: - typedef ::PROTOBUF_NAMESPACE_ID::internal::MapEntry SuperType; - StopContainersResponse_ContainerStatusEntry_DoNotUse(); - StopContainersResponse_ContainerStatusEntry_DoNotUse(::PROTOBUF_NAMESPACE_ID::Arena* arena); - void MergeFrom(const StopContainersResponse_ContainerStatusEntry_DoNotUse& other); - static const StopContainersResponse_ContainerStatusEntry_DoNotUse* internal_default_instance() { return reinterpret_cast(&_StopContainersResponse_ContainerStatusEntry_DoNotUse_default_instance_); } - static bool ValidateKey(std::string* s) { - return ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(s->data(), static_cast(s->size()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::PARSE, "StopContainersResponse.ContainerStatusEntry.key"); - } - static bool ValidateValue(void*) { return true; } - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& other) final; - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto); - return ::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto.file_level_metadata[3]; - } - - public: -}; - -// ------------------------------------------------------------------- - -class StopContainersResponse PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:StopContainersResponse) */ { - public: - inline StopContainersResponse() : StopContainersResponse(nullptr) {}; - virtual ~StopContainersResponse(); - - StopContainersResponse(const StopContainersResponse& from); - StopContainersResponse(StopContainersResponse&& from) noexcept - : StopContainersResponse() { - *this = ::std::move(from); - } - - inline StopContainersResponse& operator=(const StopContainersResponse& from) { - CopyFrom(from); - return *this; - } - inline StopContainersResponse& operator=(StopContainersResponse&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const StopContainersResponse& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const StopContainersResponse* internal_default_instance() { - return reinterpret_cast( - &_StopContainersResponse_default_instance_); - } - static constexpr int kIndexInFileMessages = - 4; - - friend void swap(StopContainersResponse& a, StopContainersResponse& b) { - a.Swap(&b); - } - inline void Swap(StopContainersResponse* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(StopContainersResponse* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline StopContainersResponse* New() const final { - return CreateMaybeMessage(nullptr); - } - - StopContainersResponse* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const StopContainersResponse& from); - void MergeFrom(const StopContainersResponse& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(StopContainersResponse* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "StopContainersResponse"; - } - protected: - explicit StopContainersResponse(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto); - return ::descriptor_table_rebootbackend_2fcontainer_5fstop_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - - // accessors ------------------------------------------------------- - - enum : int { - kContainerStatusFieldNumber = 3, - kErrorMessageFieldNumber = 2, - kStatusFieldNumber = 1, - }; - // map container_status = 3; - int container_status_size() const; - private: - int _internal_container_status_size() const; - public: - void clear_container_status(); - private: - const ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >& - _internal_container_status() const; - ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >* - _internal_mutable_container_status(); - public: - const ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >& - container_status() const; - ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >* - mutable_container_status(); - - // string error_message = 2; - bool has_error_message() const; - private: - bool _internal_has_error_message() const; - public: - void clear_error_message(); - const std::string& error_message() const; - void set_error_message(const std::string& value); - void set_error_message(std::string&& value); - void set_error_message(const char* value); - void set_error_message(const char* value, size_t size); - std::string* mutable_error_message(); - std::string* release_error_message(); - void set_allocated_error_message(std::string* error_message); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - std::string* unsafe_arena_release_error_message(); - GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" - " string fields are deprecated and will be removed in a" - " future release.") - void unsafe_arena_set_allocated_error_message( - std::string* error_message); - private: - const std::string& _internal_error_message() const; - void _internal_set_error_message(const std::string& value); - std::string* _internal_mutable_error_message(); - public: - - // .ShutdownStatus status = 1; - bool has_status() const; - private: - bool _internal_has_status() const; - public: - void clear_status(); - ::ShutdownStatus status() const; - void set_status(::ShutdownStatus value); - private: - ::ShutdownStatus _internal_status() const; - void _internal_set_status(::ShutdownStatus value); - public: - - // @@protoc_insertion_point(class_scope:StopContainersResponse) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - ::PROTOBUF_NAMESPACE_ID::internal::MapField< - StopContainersResponse_ContainerStatusEntry_DoNotUse, - std::string, ::ContainerStatus, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_MESSAGE, - 0 > container_status_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_message_; - int status_; - friend struct ::TableStruct_rebootbackend_2fcontainer_5fstop_2eproto; -}; -// =================================================================== - - -// =================================================================== - -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif // __GNUC__ -// StopContainersRequest - -// string request_id = 1; -inline bool StopContainersRequest::_internal_has_request_id() const { - bool value = (_has_bits_[0] & 0x00000001u) != 0; - return value; -} -inline bool StopContainersRequest::has_request_id() const { - return _internal_has_request_id(); -} -inline void StopContainersRequest::clear_request_id() { - request_id_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - _has_bits_[0] &= ~0x00000001u; -} -inline const std::string& StopContainersRequest::request_id() const { - // @@protoc_insertion_point(field_get:StopContainersRequest.request_id) - return _internal_request_id(); -} -inline void StopContainersRequest::set_request_id(const std::string& value) { - _internal_set_request_id(value); - // @@protoc_insertion_point(field_set:StopContainersRequest.request_id) -} -inline std::string* StopContainersRequest::mutable_request_id() { - // @@protoc_insertion_point(field_mutable:StopContainersRequest.request_id) - return _internal_mutable_request_id(); -} -inline const std::string& StopContainersRequest::_internal_request_id() const { - return request_id_.Get(); -} -inline void StopContainersRequest::_internal_set_request_id(const std::string& value) { - _has_bits_[0] |= 0x00000001u; - request_id_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void StopContainersRequest::set_request_id(std::string&& value) { - _has_bits_[0] |= 0x00000001u; - request_id_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:StopContainersRequest.request_id) -} -inline void StopContainersRequest::set_request_id(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _has_bits_[0] |= 0x00000001u; - request_id_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:StopContainersRequest.request_id) -} -inline void StopContainersRequest::set_request_id(const char* value, - size_t size) { - _has_bits_[0] |= 0x00000001u; - request_id_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:StopContainersRequest.request_id) -} -inline std::string* StopContainersRequest::_internal_mutable_request_id() { - _has_bits_[0] |= 0x00000001u; - return request_id_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* StopContainersRequest::release_request_id() { - // @@protoc_insertion_point(field_release:StopContainersRequest.request_id) - if (!_internal_has_request_id()) { - return nullptr; - } - _has_bits_[0] &= ~0x00000001u; - return request_id_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void StopContainersRequest::set_allocated_request_id(std::string* request_id) { - if (request_id != nullptr) { - _has_bits_[0] |= 0x00000001u; - } else { - _has_bits_[0] &= ~0x00000001u; - } - request_id_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_id, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:StopContainersRequest.request_id) -} -inline std::string* StopContainersRequest::unsafe_arena_release_request_id() { - // @@protoc_insertion_point(field_unsafe_arena_release:StopContainersRequest.request_id) - GOOGLE_DCHECK(GetArena() != nullptr); - _has_bits_[0] &= ~0x00000001u; - return request_id_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - GetArena()); -} -inline void StopContainersRequest::unsafe_arena_set_allocated_request_id( - std::string* request_id) { - GOOGLE_DCHECK(GetArena() != nullptr); - if (request_id != nullptr) { - _has_bits_[0] |= 0x00000001u; - } else { - _has_bits_[0] &= ~0x00000001u; - } - request_id_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - request_id, GetArena()); - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:StopContainersRequest.request_id) -} - -// repeated string container_names = 2; -inline int StopContainersRequest::_internal_container_names_size() const { - return container_names_.size(); -} -inline int StopContainersRequest::container_names_size() const { - return _internal_container_names_size(); -} -inline void StopContainersRequest::clear_container_names() { - container_names_.Clear(); -} -inline std::string* StopContainersRequest::add_container_names() { - // @@protoc_insertion_point(field_add_mutable:StopContainersRequest.container_names) - return _internal_add_container_names(); -} -inline const std::string& StopContainersRequest::_internal_container_names(int index) const { - return container_names_.Get(index); -} -inline const std::string& StopContainersRequest::container_names(int index) const { - // @@protoc_insertion_point(field_get:StopContainersRequest.container_names) - return _internal_container_names(index); -} -inline std::string* StopContainersRequest::mutable_container_names(int index) { - // @@protoc_insertion_point(field_mutable:StopContainersRequest.container_names) - return container_names_.Mutable(index); -} -inline void StopContainersRequest::set_container_names(int index, const std::string& value) { - // @@protoc_insertion_point(field_set:StopContainersRequest.container_names) - container_names_.Mutable(index)->assign(value); -} -inline void StopContainersRequest::set_container_names(int index, std::string&& value) { - // @@protoc_insertion_point(field_set:StopContainersRequest.container_names) - container_names_.Mutable(index)->assign(std::move(value)); -} -inline void StopContainersRequest::set_container_names(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); - container_names_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:StopContainersRequest.container_names) -} -inline void StopContainersRequest::set_container_names(int index, const char* value, size_t size) { - container_names_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:StopContainersRequest.container_names) -} -inline std::string* StopContainersRequest::_internal_add_container_names() { - return container_names_.Add(); -} -inline void StopContainersRequest::add_container_names(const std::string& value) { - container_names_.Add()->assign(value); - // @@protoc_insertion_point(field_add:StopContainersRequest.container_names) -} -inline void StopContainersRequest::add_container_names(std::string&& value) { - container_names_.Add(std::move(value)); - // @@protoc_insertion_point(field_add:StopContainersRequest.container_names) -} -inline void StopContainersRequest::add_container_names(const char* value) { - GOOGLE_DCHECK(value != nullptr); - container_names_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:StopContainersRequest.container_names) -} -inline void StopContainersRequest::add_container_names(const char* value, size_t size) { - container_names_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:StopContainersRequest.container_names) -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& -StopContainersRequest::container_names() const { - // @@protoc_insertion_point(field_list:StopContainersRequest.container_names) - return container_names_; -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* -StopContainersRequest::mutable_container_names() { - // @@protoc_insertion_point(field_mutable_list:StopContainersRequest.container_names) - return &container_names_; -} - -// ------------------------------------------------------------------- - -// ContainerStatus - -// .ShutdownStatus status = 1; -inline bool ContainerStatus::_internal_has_status() const { - bool value = (_has_bits_[0] & 0x00000002u) != 0; - return value; -} -inline bool ContainerStatus::has_status() const { - return _internal_has_status(); -} -inline void ContainerStatus::clear_status() { - status_ = 0; - _has_bits_[0] &= ~0x00000002u; -} -inline ::ShutdownStatus ContainerStatus::_internal_status() const { - return static_cast< ::ShutdownStatus >(status_); -} -inline ::ShutdownStatus ContainerStatus::status() const { - // @@protoc_insertion_point(field_get:ContainerStatus.status) - return _internal_status(); -} -inline void ContainerStatus::_internal_set_status(::ShutdownStatus value) { - _has_bits_[0] |= 0x00000002u; - status_ = value; -} -inline void ContainerStatus::set_status(::ShutdownStatus value) { - _internal_set_status(value); - // @@protoc_insertion_point(field_set:ContainerStatus.status) -} - -// string error_message = 2; -inline bool ContainerStatus::_internal_has_error_message() const { - bool value = (_has_bits_[0] & 0x00000001u) != 0; - return value; -} -inline bool ContainerStatus::has_error_message() const { - return _internal_has_error_message(); -} -inline void ContainerStatus::clear_error_message() { - error_message_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - _has_bits_[0] &= ~0x00000001u; -} -inline const std::string& ContainerStatus::error_message() const { - // @@protoc_insertion_point(field_get:ContainerStatus.error_message) - return _internal_error_message(); -} -inline void ContainerStatus::set_error_message(const std::string& value) { - _internal_set_error_message(value); - // @@protoc_insertion_point(field_set:ContainerStatus.error_message) -} -inline std::string* ContainerStatus::mutable_error_message() { - // @@protoc_insertion_point(field_mutable:ContainerStatus.error_message) - return _internal_mutable_error_message(); -} -inline const std::string& ContainerStatus::_internal_error_message() const { - return error_message_.Get(); -} -inline void ContainerStatus::_internal_set_error_message(const std::string& value) { - _has_bits_[0] |= 0x00000001u; - error_message_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void ContainerStatus::set_error_message(std::string&& value) { - _has_bits_[0] |= 0x00000001u; - error_message_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:ContainerStatus.error_message) -} -inline void ContainerStatus::set_error_message(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _has_bits_[0] |= 0x00000001u; - error_message_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:ContainerStatus.error_message) -} -inline void ContainerStatus::set_error_message(const char* value, - size_t size) { - _has_bits_[0] |= 0x00000001u; - error_message_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:ContainerStatus.error_message) -} -inline std::string* ContainerStatus::_internal_mutable_error_message() { - _has_bits_[0] |= 0x00000001u; - return error_message_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* ContainerStatus::release_error_message() { - // @@protoc_insertion_point(field_release:ContainerStatus.error_message) - if (!_internal_has_error_message()) { - return nullptr; - } - _has_bits_[0] &= ~0x00000001u; - return error_message_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void ContainerStatus::set_allocated_error_message(std::string* error_message) { - if (error_message != nullptr) { - _has_bits_[0] |= 0x00000001u; - } else { - _has_bits_[0] &= ~0x00000001u; - } - error_message_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_message, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:ContainerStatus.error_message) -} -inline std::string* ContainerStatus::unsafe_arena_release_error_message() { - // @@protoc_insertion_point(field_unsafe_arena_release:ContainerStatus.error_message) - GOOGLE_DCHECK(GetArena() != nullptr); - _has_bits_[0] &= ~0x00000001u; - return error_message_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - GetArena()); -} -inline void ContainerStatus::unsafe_arena_set_allocated_error_message( - std::string* error_message) { - GOOGLE_DCHECK(GetArena() != nullptr); - if (error_message != nullptr) { - _has_bits_[0] |= 0x00000001u; - } else { - _has_bits_[0] &= ~0x00000001u; - } - error_message_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - error_message, GetArena()); - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:ContainerStatus.error_message) -} - -// ------------------------------------------------------------------- - -// StopContainersStatusRequest - -// string request_id = 1; -inline bool StopContainersStatusRequest::_internal_has_request_id() const { - bool value = (_has_bits_[0] & 0x00000001u) != 0; - return value; -} -inline bool StopContainersStatusRequest::has_request_id() const { - return _internal_has_request_id(); -} -inline void StopContainersStatusRequest::clear_request_id() { - request_id_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - _has_bits_[0] &= ~0x00000001u; -} -inline const std::string& StopContainersStatusRequest::request_id() const { - // @@protoc_insertion_point(field_get:StopContainersStatusRequest.request_id) - return _internal_request_id(); -} -inline void StopContainersStatusRequest::set_request_id(const std::string& value) { - _internal_set_request_id(value); - // @@protoc_insertion_point(field_set:StopContainersStatusRequest.request_id) -} -inline std::string* StopContainersStatusRequest::mutable_request_id() { - // @@protoc_insertion_point(field_mutable:StopContainersStatusRequest.request_id) - return _internal_mutable_request_id(); -} -inline const std::string& StopContainersStatusRequest::_internal_request_id() const { - return request_id_.Get(); -} -inline void StopContainersStatusRequest::_internal_set_request_id(const std::string& value) { - _has_bits_[0] |= 0x00000001u; - request_id_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void StopContainersStatusRequest::set_request_id(std::string&& value) { - _has_bits_[0] |= 0x00000001u; - request_id_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:StopContainersStatusRequest.request_id) -} -inline void StopContainersStatusRequest::set_request_id(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _has_bits_[0] |= 0x00000001u; - request_id_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:StopContainersStatusRequest.request_id) -} -inline void StopContainersStatusRequest::set_request_id(const char* value, - size_t size) { - _has_bits_[0] |= 0x00000001u; - request_id_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:StopContainersStatusRequest.request_id) -} -inline std::string* StopContainersStatusRequest::_internal_mutable_request_id() { - _has_bits_[0] |= 0x00000001u; - return request_id_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* StopContainersStatusRequest::release_request_id() { - // @@protoc_insertion_point(field_release:StopContainersStatusRequest.request_id) - if (!_internal_has_request_id()) { - return nullptr; - } - _has_bits_[0] &= ~0x00000001u; - return request_id_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void StopContainersStatusRequest::set_allocated_request_id(std::string* request_id) { - if (request_id != nullptr) { - _has_bits_[0] |= 0x00000001u; - } else { - _has_bits_[0] &= ~0x00000001u; - } - request_id_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_id, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:StopContainersStatusRequest.request_id) -} -inline std::string* StopContainersStatusRequest::unsafe_arena_release_request_id() { - // @@protoc_insertion_point(field_unsafe_arena_release:StopContainersStatusRequest.request_id) - GOOGLE_DCHECK(GetArena() != nullptr); - _has_bits_[0] &= ~0x00000001u; - return request_id_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - GetArena()); -} -inline void StopContainersStatusRequest::unsafe_arena_set_allocated_request_id( - std::string* request_id) { - GOOGLE_DCHECK(GetArena() != nullptr); - if (request_id != nullptr) { - _has_bits_[0] |= 0x00000001u; - } else { - _has_bits_[0] &= ~0x00000001u; - } - request_id_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - request_id, GetArena()); - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:StopContainersStatusRequest.request_id) -} - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// StopContainersResponse - -// .ShutdownStatus status = 1; -inline bool StopContainersResponse::_internal_has_status() const { - bool value = (_has_bits_[0] & 0x00000002u) != 0; - return value; -} -inline bool StopContainersResponse::has_status() const { - return _internal_has_status(); -} -inline void StopContainersResponse::clear_status() { - status_ = 0; - _has_bits_[0] &= ~0x00000002u; -} -inline ::ShutdownStatus StopContainersResponse::_internal_status() const { - return static_cast< ::ShutdownStatus >(status_); -} -inline ::ShutdownStatus StopContainersResponse::status() const { - // @@protoc_insertion_point(field_get:StopContainersResponse.status) - return _internal_status(); -} -inline void StopContainersResponse::_internal_set_status(::ShutdownStatus value) { - _has_bits_[0] |= 0x00000002u; - status_ = value; -} -inline void StopContainersResponse::set_status(::ShutdownStatus value) { - _internal_set_status(value); - // @@protoc_insertion_point(field_set:StopContainersResponse.status) -} - -// string error_message = 2; -inline bool StopContainersResponse::_internal_has_error_message() const { - bool value = (_has_bits_[0] & 0x00000001u) != 0; - return value; -} -inline bool StopContainersResponse::has_error_message() const { - return _internal_has_error_message(); -} -inline void StopContainersResponse::clear_error_message() { - error_message_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - _has_bits_[0] &= ~0x00000001u; -} -inline const std::string& StopContainersResponse::error_message() const { - // @@protoc_insertion_point(field_get:StopContainersResponse.error_message) - return _internal_error_message(); -} -inline void StopContainersResponse::set_error_message(const std::string& value) { - _internal_set_error_message(value); - // @@protoc_insertion_point(field_set:StopContainersResponse.error_message) -} -inline std::string* StopContainersResponse::mutable_error_message() { - // @@protoc_insertion_point(field_mutable:StopContainersResponse.error_message) - return _internal_mutable_error_message(); -} -inline const std::string& StopContainersResponse::_internal_error_message() const { - return error_message_.Get(); -} -inline void StopContainersResponse::_internal_set_error_message(const std::string& value) { - _has_bits_[0] |= 0x00000001u; - error_message_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void StopContainersResponse::set_error_message(std::string&& value) { - _has_bits_[0] |= 0x00000001u; - error_message_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:StopContainersResponse.error_message) -} -inline void StopContainersResponse::set_error_message(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _has_bits_[0] |= 0x00000001u; - error_message_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:StopContainersResponse.error_message) -} -inline void StopContainersResponse::set_error_message(const char* value, - size_t size) { - _has_bits_[0] |= 0x00000001u; - error_message_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:StopContainersResponse.error_message) -} -inline std::string* StopContainersResponse::_internal_mutable_error_message() { - _has_bits_[0] |= 0x00000001u; - return error_message_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* StopContainersResponse::release_error_message() { - // @@protoc_insertion_point(field_release:StopContainersResponse.error_message) - if (!_internal_has_error_message()) { - return nullptr; - } - _has_bits_[0] &= ~0x00000001u; - return error_message_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void StopContainersResponse::set_allocated_error_message(std::string* error_message) { - if (error_message != nullptr) { - _has_bits_[0] |= 0x00000001u; - } else { - _has_bits_[0] &= ~0x00000001u; - } - error_message_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_message, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:StopContainersResponse.error_message) -} -inline std::string* StopContainersResponse::unsafe_arena_release_error_message() { - // @@protoc_insertion_point(field_unsafe_arena_release:StopContainersResponse.error_message) - GOOGLE_DCHECK(GetArena() != nullptr); - _has_bits_[0] &= ~0x00000001u; - return error_message_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - GetArena()); -} -inline void StopContainersResponse::unsafe_arena_set_allocated_error_message( - std::string* error_message) { - GOOGLE_DCHECK(GetArena() != nullptr); - if (error_message != nullptr) { - _has_bits_[0] |= 0x00000001u; - } else { - _has_bits_[0] &= ~0x00000001u; - } - error_message_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), - error_message, GetArena()); - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:StopContainersResponse.error_message) -} - -// map container_status = 3; -inline int StopContainersResponse::_internal_container_status_size() const { - return container_status_.size(); -} -inline int StopContainersResponse::container_status_size() const { - return _internal_container_status_size(); -} -inline void StopContainersResponse::clear_container_status() { - container_status_.Clear(); -} -inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >& -StopContainersResponse::_internal_container_status() const { - return container_status_.GetMap(); -} -inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >& -StopContainersResponse::container_status() const { - // @@protoc_insertion_point(field_map:StopContainersResponse.container_status) - return _internal_container_status(); -} -inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >* -StopContainersResponse::_internal_mutable_container_status() { - return container_status_.MutableMap(); -} -inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, ::ContainerStatus >* -StopContainersResponse::mutable_container_status() { - // @@protoc_insertion_point(field_mutable_map:StopContainersResponse.container_status) - return _internal_mutable_container_status(); -} - -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif // __GNUC__ -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - - -PROTOBUF_NAMESPACE_OPEN - -template <> struct is_proto_enum< ::ShutdownStatus> : ::std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::ShutdownStatus>() { - return ::ShutdownStatus_descriptor(); -} - -PROTOBUF_NAMESPACE_CLOSE - -// @@protoc_insertion_point(global_scope) - -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_rebootbackend_2fcontainer_5fstop_2eproto diff --git a/src/sonic-framework/rebootbackend/container_stop.proto b/src/sonic-framework/rebootbackend/container_stop.proto deleted file mode 100644 index a748c29638ea..000000000000 --- a/src/sonic-framework/rebootbackend/container_stop.proto +++ /dev/null @@ -1,30 +0,0 @@ -syntax = "proto3"; - -message StopContainersRequest { - optional string request_id = 1; - repeated string container_names = 2; -} - -enum ShutdownStatus { - NOT_STARTED = 0; // The thread has not been started - WAITING_FOR_NICE_SHUTDOWN = 1; // Nice ("kill") shutdown has been initiated - WAITING_FOR_FORCE_SHUTDOWN = - 2; // Force shutdown ("kill -9") has been initiated - DONE = 3; // Shutdown is complete - ERROR = 4; // An error was encountered -} - -message ContainerStatus { - optional ShutdownStatus status = 1; - optional string error_message = 2; -} - -message StopContainersStatusRequest { - optional string request_id = 1; -} - -message StopContainersResponse { - optional ShutdownStatus status = 1; - optional string error_message = 2; - map container_status = 3; -} diff --git a/src/sonic-framework/rebootbackend/gnoi_container_shutdown.xml b/src/sonic-framework/rebootbackend/gnoi_container_shutdown.xml deleted file mode 100644 index fb134889d0a8..000000000000 --- a/src/sonic-framework/rebootbackend/gnoi_container_shutdown.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/src/sonic-framework/rebootbackend/gnoi_container_shutdown_dbus.h b/src/sonic-framework/rebootbackend/gnoi_container_shutdown_dbus.h deleted file mode 100644 index 727f42bb842d..000000000000 --- a/src/sonic-framework/rebootbackend/gnoi_container_shutdown_dbus.h +++ /dev/null @@ -1,75 +0,0 @@ - -/* - * This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT! - */ - -#ifndef __dbusxx__rebootbackend_gnoi_container_shutdown_dbus_h__PROXY_MARSHAL_H -#define __dbusxx__rebootbackend_gnoi_container_shutdown_dbus_h__PROXY_MARSHAL_H - -#include -#include - -namespace org { -namespace SONiC { -namespace HostService { - -class gnoi_container_shutdown_proxy -: public ::DBus::InterfaceProxy -{ -public: - - gnoi_container_shutdown_proxy() - : ::DBus::InterfaceProxy("org.SONiC.HostService.gnoi_container_shutdown") - { - } - -public: - - /* properties exported by this interface */ -public: - - /* methods exported by this interface, - * this functions will invoke the corresponding methods on the remote objects - */ - void stop_container(const std::vector< std::string >& options, int32_t& argout0, std::string& argout1) - { - ::DBus::CallMessage call; - ::DBus::MessageIter wi = call.writer(); - - wi << options; - call.member("stop_container"); - ::DBus::Message ret = invoke_method (call); - ::DBus::MessageIter ri = ret.reader(); - - ri >> argout0; - ri >> argout1; - } - - void stop_container_status(const std::vector< std::string >& options, int32_t& argout0, std::string& argout1) - { - ::DBus::CallMessage call; - ::DBus::MessageIter wi = call.writer(); - - wi << options; - call.member("stop_container_status"); - ::DBus::Message ret = invoke_method (call); - ::DBus::MessageIter ri = ret.reader(); - - ri >> argout0; - ri >> argout1; - } - - -public: - - /* signal handlers for this interface - */ - -private: - - /* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ -}; - -} } } -#endif //__dbusxx__rebootbackend_gnoi_container_shutdown_dbus_h__PROXY_MARSHAL_H diff --git a/src/sonic-framework/rebootbackend/gnoi_reboot.xml b/src/sonic-framework/rebootbackend/gnoi_reboot.xml index 1f785a3745cd..63af1963db4b 100644 --- a/src/sonic-framework/rebootbackend/gnoi_reboot.xml +++ b/src/sonic-framework/rebootbackend/gnoi_reboot.xml @@ -8,7 +8,7 @@ C++ header file generated by: sudo apt-get install libdbus-c++-dev dbusxx-xml2cpp ./gnoi_reboot.xml --proxy=gnoi_reboot_dbus.h ?> - + diff --git a/src/sonic-framework/rebootbackend/init_thread.cpp b/src/sonic-framework/rebootbackend/init_thread.cpp deleted file mode 100644 index 27775cf84d2d..000000000000 --- a/src/sonic-framework/rebootbackend/init_thread.cpp +++ /dev/null @@ -1,534 +0,0 @@ -#include "init_thread.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -//#include "component_state_helper.h" -#include "dbconnector.h" -#include "logger.h" -#include "notificationproducer.h" -#include "reboot_interfaces.h" -#include "rebootbe.h" -#include "redis_utils.h" -#include "redisselect.h" -#include "select.h" -#include "selectableevent.h" -#include "selectabletimer.h" -//#include "stateverification.h" -#include "status_code_util.h" -#include "subscriberstatetable.h" -#include "warm_restart.h" - -namespace rebootbackend { - -using WarmStartState = ::swss::WarmStart::WarmStartState; -//using WarmBootStage = ::swss::WarmStart::WarmBootStage; - -InitThread::InitThread( -// CriticalStateInterface &critical_interface, - TelemetryInterface &telemetry_interface, - swss::SelectableEvent &m_finished, - swss::SelectableEvent &m_stack_unfrozen) - : m_db("STATE_DB", 0), - m_finished(m_finished), - m_stack_unfrozen(m_stack_unfrozen), -// m_critical_interface(critical_interface), - m_telemetry(telemetry_interface) {} - -swss::StatusCode InitThread::Start() { - swss::StatusCode result = internal_start(); - if (result != swss::StatusCode::SWSS_RC_SUCCESS) { - do_final_failed_actions(); - m_status.set_inactive(); - } - return result; -} - -swss::StatusCode InitThread::internal_start() { - SWSS_LOG_ENTER(); - - /* if (m_critical_interface.is_system_critical()) { - const std::string error_string = - "InitThread: in critical state, not starting stack."; - SWSS_LOG_ERROR("%s", error_string.c_str()); - m_status.set_start_status(); - m_status.set_error( - InitThreadStatus::ErrorCondition::DETECTED_CRITICAL_STATE, - error_string); - return swss::StatusCode::SWSS_RC_FAILED_PRECONDITION; - } */ - - m_status.set_start_status(); - - try { - m_thread = std::thread(&InitThread::init_thread, this); - } catch (const std::system_error &e) { - std::string error_string = "Exception launching init thread: "; - error_string += e.what(); - SWSS_LOG_ERROR("%s", error_string.c_str()); - - m_status.set_error(InitThreadStatus::ErrorCondition::INTERNAL_ERROR, - error_string); - - return swss::StatusCode::SWSS_RC_INTERNAL; - } - return swss::StatusCode::SWSS_RC_SUCCESS; -} - -void InitThread::init_thread(void) { - SWSS_LOG_ENTER(); - - // Check if stop was requested before m_stop was constructed. If m_stop has - // been signaled already, this will be caught in later Select's. - if (sigterm_requested) { - const std::string error_string = "sigterm_requested was raised, exiting"; - SWSS_LOG_ERROR("%s", error_string.c_str()); - m_status.set_error(InitThreadStatus::ErrorCondition::INTERNAL_ERROR, - error_string); - do_final_failed_actions(); - m_finished.notify(); - return; - } - - swss::SelectableTimer registration_reconciliation_timer( - timespec{.tv_sec = m_reconciliation_timeout, .tv_nsec = 0}); - registration_reconciliation_timer.start(); - - m_status.set_detailed_thread_status( - InitThreadStatus::ThreadStatus::WAITING_FOR_REGISTRATION); - swss::StatusCode result = - handle_registration_step(registration_reconciliation_timer); - if (result != swss::StatusCode::SWSS_RC_SUCCESS) { - m_status.set_error(InitThreadStatus::ErrorCondition::REGISTRATION_FAILED, - "Registration failed with error"); - do_final_failed_actions(); - m_finished.notify(); - return; - } - - m_status.set_detailed_thread_status( - InitThreadStatus::ThreadStatus::WAITING_FOR_RECONCILIATION); - // Reconciliation start time is recorded by the platform layer when the - // database is started. - - /* result = handle_reconciliation_step(registration_reconciliation_timer); - if (result == swss::StatusCode::SWSS_RC_SUCCESS) { - m_telemetry.record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - true); - } else { - m_status.set_error(InitThreadStatus::ErrorCondition::RECONCILIATION_FAILED, - "Reconciliation failed with error"); - m_telemetry.record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - false); - do_final_failed_actions(); - m_finished.notify(); - return; - } */ - - registration_reconciliation_timer.stop(); - -/* bool state_verification_enabled = - swss::WarmStart::isStateVerificationBootupEnabled(); - if (state_verification_enabled) { - m_status.set_detailed_thread_status( - InitThreadStatus::ThreadStatus::WAITING_FOR_STATE_VERIFICATION); - result = handle_state_verification_step(); - if (result != swss::StatusCode::SWSS_RC_SUCCESS) { - m_status.set_error( - InitThreadStatus::ErrorCondition::STATE_VERIFICATION_FAILED, - "State verification failed with error"); - do_final_failed_actions(); - m_finished.notify(); - return; - } - - m_telemetry.record_stage_start(WarmBootStage::STAGE_UNFREEZE); - send_nsf_manager_notification( - m_db, swss::WarmStart::WarmBootNotification::kUnfreeze); - m_stack_unfrozen.notify(); - - m_status.set_detailed_thread_status( - InitThreadStatus::ThreadStatus::WAITING_FOR_UNFREEZE); - - result = handle_unfreeze_step(); - if (result == swss::StatusCode::SWSS_RC_SUCCESS) { - m_telemetry.record_stage_end(WarmBootStage::STAGE_UNFREEZE, - true); - } else { - m_status.set_error(InitThreadStatus::ErrorCondition::UNFREEZE_FAILED, - "Unfreeze failed with error"); - m_telemetry.record_stage_end(WarmBootStage::STAGE_UNFREEZE, - false); - do_final_failed_actions(); - m_finished.notify(); - return; - } - } else { - SWSS_LOG_NOTICE("Skipping state verification and unfreeze polling"); - } */ - - m_telemetry.record_overall_end(/*success=*/true); - // We've completed warm restart: clear the flag - set_warm_restart_enable(m_db, false); - m_status.set_success(); - // Notify calling thread that init thread has exited. - // Calling thread MUST call Join() to join and set thread status to inactive. - m_finished.notify(); - SWSS_LOG_NOTICE( - "InitThread done post-boot steps. System unblocked for future warmboots"); -} - -void InitThread::Stop(void) { - SWSS_LOG_ENTER(); - m_stop.notify(); -} - -bool InitThread::Join(void) { - SWSS_LOG_ENTER(); - - if (!m_thread.joinable()) { - SWSS_LOG_ERROR("InitThread::Join called, but not joinable"); - return false; - } - - bool ret = true; - try { - m_thread.join(); - m_status.set_inactive(); - } catch (const std::system_error &e) { - SWSS_LOG_ERROR("Exception calling join: %s", e.what()); - ret = false; - } - return ret; -} - -InitThreadStatus::DetailedStatus InitThread::GetDetailedStatus() { - return m_status.get_detailed_thread_status(); -} - -gnoi::system::RebootStatusResponse InitThread::GetResponse() { - return m_status.get_response(); -} - -InitThread::SelectStatus InitThread::ToSelectStatus( - Registration::Response result) { - switch (result.status) { - case Registration::Status::COMPLETED: { - return SelectStatus::SUCCESS; - } - case Registration::Status::FAILURE: { - return SelectStatus::FAILURE; - } - case Registration::Status::IN_PROCESS: { - return SelectStatus::KEEP_WAITING; - } - } - return SelectStatus::FAILURE; -} - -InitThread::SelectStatus InitThread::ToSelectStatus( - InitRegistration::Status status) { - switch (status) { - case InitRegistration::Status::COMPLETED: { - return SelectStatus::SUCCESS; - } - case InitRegistration::Status::IN_PROGRESS: { - return SelectStatus::KEEP_WAITING; - } - } - return SelectStatus::FAILURE; -} - -swss::StatusCode InitThread::ToStatusCode(SelectStatus select_status) { - switch (select_status) { - case SelectStatus::SUCCESS: { - return swss::StatusCode::SWSS_RC_SUCCESS; - } - case SelectStatus::FAILURE: { - return swss::StatusCode::SWSS_RC_INTERNAL; - } - case SelectStatus::KEEP_WAITING: { - return swss::StatusCode::SWSS_RC_INTERNAL; - } - } - return swss::StatusCode::SWSS_RC_INTERNAL; -} - -void InitThread::do_final_failed_actions() { - SWSS_LOG_ENTER(); - InitThreadStatus::DetailedStatus detailed_status = - m_status.get_detailed_thread_status(); - if (detailed_status.detailed_thread_status == - InitThreadStatus::ThreadStatus::ERROR && - detailed_status.detailed_thread_error_condition == - InitThreadStatus::ErrorCondition::UNFREEZE_FAILED) { - SWSS_LOG_NOTICE( - "Error occurred after sending unfreeze, raising minor alarm"); - } -/* m_critical_interface.report_minor_alarm( - "Encountered error during unfreeze"); - } else if (!m_critical_interface.is_system_critical()) { - SWSS_LOG_NOTICE( - "Error occured and system is not already critical, raising critical " - "state"); - m_critical_interface.report_critical_state( - "Encountered error with InitThread in state: " + - std::to_string(detailed_status.detailed_thread_error_condition)); - } */ - set_warm_restart_enable(m_db, false); - m_telemetry.record_overall_end(/*success=*/false); -} - -swss::StatusCode InitThread::handle_registration_step( - swss::SelectableTimer &timer_select) { - SWSS_LOG_ENTER(); - SWSS_LOG_NOTICE("Starting InitThread Registration step"); - - // TODO(b/322034421): Improve critical state detection. -/* if (m_critical_interface.is_system_critical()) { - SWSS_LOG_ERROR("InitThread: in critical state, not unfreezing stack."); - return swss::StatusCode::SWSS_RC_FAILED_PRECONDITION; - } */ - -/* swss::SubscriberStateTable table_sub( - &m_db, STATE_WARM_RESTART_REGISTRATION_TABLE_NAME); */ - - InitRegistration init_registration; - init_registration.fetch_init_app_info(); - SWSS_LOG_NOTICE("Waiting for apps to reregister: %s", - init_registration.join_pending_apps().c_str()); - /* auto initial_check_lambda = [&]() { - return InitThread::ToSelectStatus( - init_registration.check_reregistration_status()); - }; - auto handle_table_event_lambda = - [&](const swss::KeyOpFieldsValuesTuple &kco) { - return InitThread::ToSelectStatus( - init_registration.handle_registration_event(kco)); - }; */ - - /* swss::StatusCode result = select_loop( - // timer_select, table_sub, initial_check_lambda, handle_table_event_lambda); - timer_select, initial_check_lambda, handle_table_event_lambda); - if (result == swss::StatusCode::SWSS_RC_SUCCESS) { - SWSS_LOG_NOTICE("InitThread Registration step reported success"); - } else { - SWSS_LOG_ERROR( - "Error while waiting for re-registration: missing apps: %s Error " - "text: %s", - init_registration.join_pending_apps().c_str(), - swss::statusCodeToStr(result).c_str()); - } - return result; */ - return swss::StatusCode::SWSS_RC_SUCCESS; -} - -/* swss::StatusCode InitThread::handle_reconciliation_step( - swss::SelectableTimer &timer_select) { - SWSS_LOG_ENTER(); - SWSS_LOG_NOTICE("Starting InitThread Reconciliation step"); - - // TODO(b/322034421): Improve critical state detection. - if (m_critical_interface.is_system_critical()) { - SWSS_LOG_ERROR("InitThread: in critical state, not unfreezing stack."); - return swss::StatusCode::SWSS_RC_FAILED_PRECONDITION; - } - - // Precise error logged within. - swss::StatusCode result = - wait_for_state(WarmBootStage::STAGE_RECONCILIATION, timer_select); - SWSS_LOG_NOTICE("InitThread Reconciliation step finished with status: %s", - swss::statusCodeToStr(result).c_str()); - return result; -} */ - -/* swss::StatusCode InitThread::handle_unfreeze_step() { - SWSS_LOG_ENTER(); - SWSS_LOG_NOTICE("Starting InitThread Unfreeze step"); - - // TODO(b/322034421): Improve critical state detection. - if (m_critical_interface.is_system_critical()) { - SWSS_LOG_ERROR( - "InitThread: in critical state, not monitoring for stack unfreeze"); - return swss::StatusCode::SWSS_RC_FAILED_PRECONDITION; - } - - swss::SelectableTimer timer_select( - timespec{.tv_sec = m_unfreeze_timeout, .tv_nsec = 0}); - timer_select.start(); - - // Precise error logged within. - swss::StatusCode result = - wait_for_state(WarmBootStage::STAGE_UNFREEZE, timer_select); - SWSS_LOG_NOTICE("InitThread Unfreeze step finished with status: %s", - swss::statusCodeToStr(result).c_str()); - return result; -} */ - -/* swss::StatusCode InitThread::wait_for_state( - WarmBootStage nsf_stage, - swss::SelectableTimer &timer_select) { - swss::SubscriberStateTable table_sub(&m_db, STATE_WARM_RESTART_TABLE_NAME); - - const std::string stage_name = - Registration::get_warm_boot_stage_name(nsf_stage); - Registration registration; - registration.fetch_registration_info(); - SWSS_LOG_NOTICE("Waiting for apps: %s to reach state: %s", - registration.join_pending_apps(nsf_stage).c_str(), - stage_name.c_str()); - auto initial_check_lambda = [&]() { - return InitThread::ToSelectStatus(registration.check_stage(nsf_stage)); - }; - auto handle_table_event_lambda = - [&](const swss::KeyOpFieldsValuesTuple &kco) { - return InitThread::ToSelectStatus( - registration.handle_state_event(nsf_stage, kco)); - }; - - swss::StatusCode result = select_loop( - timer_select, table_sub, initial_check_lambda, handle_table_event_lambda); - if (result == swss::StatusCode::SWSS_RC_SUCCESS) { - SWSS_LOG_NOTICE("All apps reached state: %s", stage_name.c_str()); - } else { - SWSS_LOG_ERROR( - "Error while waiting for state: %s missing apps: %s Error " - "text: %s", - stage_name.c_str(), registration.join_pending_apps(nsf_stage).c_str(), - swss::statusCodeToStr(result).c_str()); - } - return result; -} */ - -/* swss::StatusCode InitThread::handle_state_verification_step() { - SWSS_LOG_ENTER(); - SWSS_LOG_NOTICE("Starting InitThread State Verfication step"); - - // TODO(b/322034421): Improve critical state detection. - if (m_critical_interface.is_system_critical()) { - SWSS_LOG_ERROR("InitThread: in critical state, not unfreezing stack."); - return swss::StatusCode::SWSS_RC_FAILED_PRECONDITION; - } - - swss::SubscriberStateTable table_sub(&m_db, STATE_VERIFICATION_RESP_TABLE); - swss::SelectableTimer timer_select( - timespec{.tv_sec = m_state_verification_timeout, .tv_nsec = 0}); - timer_select.start(); - - std::string timestamp = - send_state_verification_notification(m_db, true); - SWSS_LOG_NOTICE("State verification triggered, waiting for result"); - - auto initial_check_lambda = [&]() -> SelectStatus { - return SelectStatus::KEEP_WAITING; - }; - auto handle_verification_event_lambda = - [&](const swss::KeyOpFieldsValuesTuple &kco) -> SelectStatus { - if (kfvKey(kco) != ALL_COMPONENT) { - return SelectStatus::KEEP_WAITING; - } - - std::string status; - std::string ts; - for (const auto &fv : kfvFieldsValues(kco)) { - if (fvField(fv) == TIMESTAMP_FIELD) { - ts = fvValue(fv); - } else if (fvField(fv) == STATUS_FIELD) { - status = fvValue(fv); - } - } - - if (ts != timestamp) { - return SelectStatus::KEEP_WAITING; - } - - if (status == SV_PASS) { - SWSS_LOG_NOTICE("State verification reported success"); - return SelectStatus::SUCCESS; - } else if (status == SV_NOT_RUN) { - const std::string message = - "State verification did not run. Treating as success for NSF"; - SWSS_LOG_WARN("%s", message.c_str()); - m_critical_interface.report_minor_alarm(message); - return SelectStatus::SUCCESS; - } else if (status == SV_FAIL) { - SWSS_LOG_ERROR("State verification reported failure"); - return SelectStatus::FAILURE; - } - return SelectStatus::KEEP_WAITING; - }; - - swss::StatusCode result = - select_loop(timer_select, table_sub, initial_check_lambda, - handle_verification_event_lambda); - if (result == swss::StatusCode::SWSS_RC_DEADLINE_EXCEEDED) { - SWSS_LOG_WARN("State verification timed out, raising minor alarm: %s", - swss::statusCodeToStr(result).c_str()); - m_critical_interface.report_minor_alarm( - "State verification timed out. Treating as success for NSF"); - return swss::StatusCode::SWSS_RC_SUCCESS; - } else if (result != swss::StatusCode::SWSS_RC_SUCCESS) { - SWSS_LOG_ERROR("Error while waiting for state verification: %s", - swss::statusCodeToStr(result).c_str()); - } - return result; -} */ - -/* swss::StatusCode InitThread::select_loop( - swss::Selectable &timer_select, swss::SubscriberStateTable &table_sub, - const std::function &initial_check, - const std::function &table_event_callback) { - SWSS_LOG_ENTER(); - - swss::Select s; - s.addSelectable(&m_stop); - s.addSelectable(&table_sub); - s.addSelectable(&timer_select); - - SelectStatus select_status = initial_check(); - if (select_status != SelectStatus::KEEP_WAITING) { - return ToStatusCode(select_status); - } - - while (true) { - swss::Selectable *sel; - int select_result; - select_result = s.select(&sel); - - if (select_result == swss::Select::ERROR) { - SWSS_LOG_ERROR("Error in select loop: %s", strerror(errno)); - continue; - } else if (select_result != swss::Select::OBJECT) { - SWSS_LOG_NOTICE("Got unexpected non-object from select: %d", - select_result); - continue; - } - - if (sel == &m_stop) { - SWSS_LOG_ERROR("m_stop rx'd (SIGTERM) in select loop"); - return swss::StatusCode::SWSS_RC_INTERNAL; - } else if (sel == &timer_select) { - SWSS_LOG_ERROR("Timed out in select loop"); - return swss::StatusCode::SWSS_RC_DEADLINE_EXCEEDED; - } else if (sel == &table_sub) { - swss::KeyOpFieldsValuesTuple kco; - table_sub.pop(kco); - select_status = table_event_callback(kco); - if (select_status != SelectStatus::KEEP_WAITING) { - return ToStatusCode(select_status); - } - } else { - SWSS_LOG_ERROR("Got unexpected object event in select loop"); - } - } -} */ - -} // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/init_thread.h b/src/sonic-framework/rebootbackend/init_thread.h index ca57307a297d..50c27d6c8c34 100644 --- a/src/sonic-framework/rebootbackend/init_thread.h +++ b/src/sonic-framework/rebootbackend/init_thread.h @@ -15,7 +15,6 @@ #include "selectabletimer.h" #include "subscriberstatetable.h" #include "system/system.pb.h" -#include "warm_restart.h" namespace rebootbackend { @@ -133,131 +132,5 @@ class InitThreadStatus { DetailedStatus m_status; }; -class InitThread { - public: - InitThread( -// CriticalStateInterface &critical_interface, - TelemetryInterface &telemetry_interface, - swss::SelectableEvent &m_finished, - swss::SelectableEvent &m_stack_unfrozen); - virtual ~InitThread() = default; - - // Starts running the init thread tasks. Returns SWSS_RC_SUCCESS if the - // internal thread was started successfully, and an error otherwise. If an - // error is returned, this call may safely be retried, but will likely - // continue to return errors. - virtual swss::StatusCode Start(); - - // Request InitThread stop/exit. Notifies the internal thread that it must - // exit. Only used when platform is shutting down all containers/processes. - virtual void Stop(void); - - // Must be called by launching task after notification is sent to m_finished. - virtual bool Join(void); - - // Return Status of last reboot attempt. - virtual gnoi::system::RebootStatusResponse GetResponse(); - - // Returns a representation of the detailed thread status. - virtual InitThreadStatus::DetailedStatus GetDetailedStatus(); - - private: - enum class SelectStatus { SUCCESS, FAILURE, KEEP_WAITING }; - - static SelectStatus ToSelectStatus(Registration::Response result); - static SelectStatus ToSelectStatus(InitRegistration::Status status); - static swss::StatusCode ToStatusCode(SelectStatus select_status); - - // Internal implementation of Start(). Returns SWSS_RC_SUCCESS if the init - // thread was started successfully, and an error otherwise. If an error is - // returned, final cleanup actions must be taken. - swss::StatusCode internal_start(); - - // Function containing the core logic. Invoked as a separate thread. Runs - // through the steps required for reconciliation monitoring. - void init_thread(void); - - // Perform the final required actions before exiting: - // 1. Clear the NSF flag. - // 2. Record final stats (if able) - void do_final_failed_actions(); - - // Helper function for the registration step. Waits for all applications that - // had registered warmboot intent before the warmboot to re-register warmboot - // intent after the warmboot. The provided timer must already have been - // started prior to this function call. - // Returns SWSS_RC_SUCCESS if re-registration is successful, and an error - // otherwise. - swss::StatusCode handle_registration_step( - swss::SelectableTimer &timer_select); - - // Helper function for the reconciliation step. Wait for all apps to reach - // the reconcilied state. The provided timer must already have been started - // prior to this function call. - // Returns SWSS_RC_SUCCESS if waiting for reconciliation is successful, and an - // error otherwise. - swss::StatusCode handle_reconciliation_step( - swss::SelectableTimer &timer_select); - - // Helper function for the unfreeze step. Wait for all apps to reach - // the completed state. - // Returns SWSS_RC_SUCCESS if waiting for unfreeze is successful, and an - // error otherwise. - swss::StatusCode handle_unfreeze_step(); - - // Wait until all apps reach a target state, or until the provided timer - // expires. The timer must already have been started prior to this function - // call. - swss::StatusCode wait_for_state( - // swss::WarmStart::WarmBootStage nsf_stage, - swss::SelectableTimer &timer_select); - - // Helper function for the state verification step. Trigger state verification - // then wait for all apps to report successful state verification. - // Returns SWSS_RC_SUCCESS if waiting for state verification is successful, - // and an error otherwise. - swss::StatusCode handle_state_verification_step(); - - // Helper function for select loops. Sets up events for m_done, timer_select, - // and table_sub, checks if already done with initial_check, then enters - // an event handling loop, forwarding events to table_event_callback until - // the callback indicates operation is complete. - swss::StatusCode select_loop( - swss::Selectable &timer_select, - // swss::SubscriberStateTable &table_sub, - const std::function &initial_check, - const std::function - &table_event_callback); - - // Thread and internal status. - std::thread m_thread; - InitThreadStatus m_status; - - // Event handles used to notify the caller when InitThread is finished, when - // the stack is unfrozen, and pass Stop events through to the dependent - // thread to stop operation prematurely. - swss::SelectableEvent &m_finished; - swss::SelectableEvent &m_stack_unfrozen; - swss::SelectableEvent m_stop; - - // Interfaces to external systems: the Redis database and critical state - // system. - swss::DBConnector m_db; - //CriticalStateInterface &m_critical_interface; - TelemetryInterface &m_telemetry; - - // Various operation timeouts in seconds: allow unit test to shorten. - static constexpr uint32_t kReconciliationTimeout = 300; - uint32_t m_reconciliation_timeout = kReconciliationTimeout; - - // Various operation timeouts in seconds: allow unit test to shorten. - static constexpr uint32_t kStateVerificationTimeout = 180; - uint32_t m_state_verification_timeout = kStateVerificationTimeout; - - static constexpr uint32_t kUnfreezeTimeout = 60; - uint32_t m_unfreeze_timeout = kUnfreezeTimeout; - - friend class InitThreadTest; -}; } // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/interfaces.cpp b/src/sonic-framework/rebootbackend/interfaces.cpp index 6faec95d2f93..5674a33358e1 100644 --- a/src/sonic-framework/rebootbackend/interfaces.cpp +++ b/src/sonic-framework/rebootbackend/interfaces.cpp @@ -70,64 +70,3 @@ DbusInterface::DbusResponse HostServiceDbus::RebootStatus( return DbusResponse{DbusStatus::DBUS_FAIL, ret_string}; } -DbusInterface::DbusResponse HostServiceDbus::StopContainers( - const std::string& json_stop_request) { - int32_t status; - std::string ret_string; - std::vector options; - options.push_back(json_stop_request); - - GnoiDbusContainerShutdown container_client(getConnection(), kContainerShutdownBusName, - kContainerShutdownPath); - try { - container_client.stop_container(options, status, ret_string); - } catch (DBus::Error& ex) { - return DbusResponse{DbusStatus::DBUS_FAIL, - "HostServiceDbus::StopContainer: failed to call stop " - "container host service"}; - } - - // gnoi_container_shutdown.py returns 0 for success, 1 for failure - if (status == 0) { - return DbusResponse{DbusStatus::DBUS_SUCCESS, ""}; - } - return DbusResponse{DbusStatus::DBUS_FAIL, ret_string}; -} - -DbusInterface::DbusResponse HostServiceDbus::StopContainerStatus( - const std::string& json_status_request) { - int32_t status; - std::string ret_string; - std::vector options; - options.push_back(json_status_request); - - GnoiDbusContainerShutdown container_client(getConnection(), kContainerShutdownBusName, - kContainerShutdownPath); - try { - container_client.stop_container_status(options, status, ret_string); - } catch (DBus::Error& ex) { - return DbusResponse{DbusStatus::DBUS_FAIL, - "HostServiceDbus::StopContainerStatus: failed to call " - "stop container status host service"}; - } - - // gnoi_container_shutdown.py returns 0 for success, 1 for failure - if (status == 0) { - return DbusResponse{DbusStatus::DBUS_SUCCESS, ret_string}; - } - return DbusResponse{DbusStatus::DBUS_FAIL, ret_string}; -} - -/* bool CriticalState::is_system_critical() { - return swss::StateHelperManager::SystemSingleton().IsSystemCritical(); -} */ - -/* void CriticalState::report_minor_alarm(const std::string& reason) { - swss::StateHelperManager::ComponentSingleton(swss::SystemComponent::kHost) - .ReportComponentState(swss::ComponentState::kMinor, reason); -} */ - -/* void CriticalState::report_critical_state(const std::string& reason) { - swss::StateHelperManager::ComponentSingleton(swss::SystemComponent::kHost) - .ReportComponentState(swss::ComponentState::kError, reason); -} */ diff --git a/src/sonic-framework/rebootbackend/interfaces.h b/src/sonic-framework/rebootbackend/interfaces.h index e93037929224..977d3518ead0 100644 --- a/src/sonic-framework/rebootbackend/interfaces.h +++ b/src/sonic-framework/rebootbackend/interfaces.h @@ -3,22 +3,9 @@ #include -#include "gnoi_container_shutdown_dbus.h" // auto generated - // gnoi_container_shutdown_proxy #include "gnoi_reboot_dbus.h" // auto generated gnoi_reboot_proxy #include "reboot_interfaces.h" -class GnoiDbusContainerShutdown - : public org::SONiC::HostService::gnoi_container_shutdown_proxy, - public DBus::IntrospectableProxy, - public DBus::ObjectProxy { - public: - GnoiDbusContainerShutdown(DBus::Connection& connection, - const char* dbus_bus_name_p, - const char* dbus_obj_name_p) - : DBus::ObjectProxy(connection, dbus_obj_name_p, dbus_bus_name_p) {} -}; - class GnoiDbusReboot : public org::SONiC::HostService::gnoi_reboot_proxy, public DBus::IntrospectableProxy, public DBus::ObjectProxy { @@ -34,18 +21,7 @@ class HostServiceDbus : public DbusInterface { const std::string& json_reboot_request) override; DbusInterface::DbusResponse RebootStatus( const std::string& json_status_request) override; - DbusInterface::DbusResponse StopContainers( - const std::string& json_stop_request) override; - DbusInterface::DbusResponse StopContainerStatus( - const std::string& json_status_request) override; private: static DBus::Connection& getConnection(void); }; - -class CriticalState : public CriticalStateInterface { - public: - bool is_system_critical() override; - void report_minor_alarm(const std::string& reason) override; - void report_critical_state(const std::string& reason) override; -}; diff --git a/src/sonic-framework/rebootbackend/reboot_common.cpp b/src/sonic-framework/rebootbackend/reboot_common.cpp index e79021302bc7..65672ae67841 100644 --- a/src/sonic-framework/rebootbackend/reboot_common.cpp +++ b/src/sonic-framework/rebootbackend/reboot_common.cpp @@ -8,7 +8,7 @@ timespec milliseconds_to_timespec(uint64_t time_ms) { timespec l_timespec; l_timespec.tv_sec = time_ms / ONE_THOUSAND; l_timespec.tv_nsec = (time_ms % ONE_THOUSAND) * ONE_THOUSAND * ONE_THOUSAND; - return l_timespec; + return l_timespec; } } // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/reboot_common.h b/src/sonic-framework/rebootbackend/reboot_common.h index 9a6795376534..564b893232f7 100644 --- a/src/sonic-framework/rebootbackend/reboot_common.h +++ b/src/sonic-framework/rebootbackend/reboot_common.h @@ -15,6 +15,6 @@ extern timespec milliseconds_to_timespec(uint64_t time_ms); struct NotificationResponse { swss::StatusCode status; std::string json_string; -}; +}; } // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/reboot_interfaces.h b/src/sonic-framework/rebootbackend/reboot_interfaces.h index 591d2c5b23be..20f641e3f189 100644 --- a/src/sonic-framework/rebootbackend/reboot_interfaces.h +++ b/src/sonic-framework/rebootbackend/reboot_interfaces.h @@ -2,8 +2,6 @@ #include -#include "warm_restart.h" - class DbusInterface { public: enum class DbusStatus { @@ -19,70 +17,5 @@ class DbusInterface { virtual ~DbusInterface() = default; virtual DbusResponse Reboot(const std::string& json_reboot_request) = 0; virtual DbusResponse RebootStatus(const std::string& json_status_request) = 0; - virtual DbusResponse StopContainers(const std::string& json_stop_request) = 0; - virtual DbusResponse StopContainerStatus( - const std::string& json_status_request) = 0; -}; - -class CriticalStateInterface { - public: - virtual ~CriticalStateInterface() = default; - virtual bool is_system_critical() = 0; - virtual void report_minor_alarm(const std::string& reason) = 0; - virtual void report_critical_state(const std::string& reason) = 0; -}; - -namespace rebootbackend { - -// Class to help interfacing with the telemetry tables in Redis. Not thread -// safe. -class TelemetryInterface { - public: - virtual ~TelemetryInterface() = default; - - // Records the warmboot start time. Also increments the warmboot counter. - // Writes entries: - // WARM_RESTART_PERFORMANCE_TABLE|system, fields: status, start-timestamp - // WARM_RESTART_PERFORMANCE_HISTORY||system - // fields: status, start-timestamp - // to the state DB. - // Must be called before snapshot_stage_start or the warmboot counter may be - // corrupted. - virtual void record_overall_start() = 0; - - // Records the warmboot end time, when all operations in the NSF boot have - // been completed. Writes to both the performance and history tables. - // Writes entries: - // WARM_RESTART_PERFORMANCE_TABLE|system, fields: status, finish-timestamp - // WARM_RESTART_PERFORMANCE_HISTORY||system - // fields: status, finish-timestamp - // to the state DB. - virtual void record_overall_end(bool success) = 0; - - // Records the start time of a particular warmboot stage. - // Writes entries: - // WARM_RESTART_PERFORMANCE_TABLE|, fields: status, start-timestamp - // WARM_RESTART_PERFORMANCE_TABLE|| - // fields: status, start-timestamp - // WARM_RESTART_PERFORMANCE_HISTORY||, - // fields: status, start-timestamp - // WARM_RESTART_PERFORMANCE_HISTORY||| - // fields: status, start-timestamp - // to the state DB. - // virtual void record_stage_start(swss::WarmStart::WarmBootStage nsf_stage) = 0; - // Records the end time of a particular warmboot stage. - // Writes entries: - // WARM_RESTART_PERFORMANCE_TABLE| - // fields: status, finish-timestamp - // WARM_RESTART_PERFORMANCE_TABLE|| - // fields: status, finish-timestamp - // WARM_RESTART_PERFORMANCE_HISTORY||, - // fields: status, finish-timestamp - // WARM_RESTART_PERFORMANCE_HISTORY||| - // fields: status, finish-timestamp - // to the state DB. - //virtual void record_stage_end(swss::WarmStart::WarmBootStage nsf_stage, - // bool success) = 0; }; -} // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/reboot_thread.cpp b/src/sonic-framework/rebootbackend/reboot_thread.cpp index 4f90d36fbfdd..a57a241e302f 100644 --- a/src/sonic-framework/rebootbackend/reboot_thread.cpp +++ b/src/sonic-framework/rebootbackend/reboot_thread.cpp @@ -1,11 +1,6 @@ #include "reboot_thread.h" - #include - #include - -//#include "component_state_helper.h" -#include "container_stop.pb.h" #include "dbconnector.h" #include "logger.h" #include "notificationproducer.h" @@ -15,11 +10,9 @@ #include "select.h" #include "selectableevent.h" #include "selectabletimer.h" -//#include "stateverification.h" #include "subscriberstatetable.h" #include "system/system.pb.h" #include "timestamp.h" -#include "warm_restart.h" namespace rebootbackend { @@ -31,15 +24,10 @@ using WarmStartState = ::swss::WarmStart::WarmStartState; namespace gpu = ::google::protobuf::util; RebootThread::RebootThread(DbusInterface &dbus_interface, -// CriticalStateInterface &critical_interface, - TelemetryInterface &telemetry_interface, swss::SelectableEvent &m_finished) : m_db("STATE_DB", 0), m_finished(m_finished), - m_dbus_interface(dbus_interface), -// m_critical_interface(critical_interface), - m_telemetry(telemetry_interface) , - m_registration() {} + m_dbus_interface(dbus_interface) {} void RebootThread::Stop(void) { SWSS_LOG_ENTER(); @@ -98,11 +86,6 @@ Progress RebootThread::platform_reboot_select(swss::Select &s, Progress RebootThread::wait_for_platform_reboot(swss::Select &s) { SWSS_LOG_ENTER(); - /* if (check_and_log_critical_state( - "system entered critical state after platfrom reboot request")) { - return Progress::EXIT_EARLY; - } */ - // Sleep for a long time: 260 seconds. // During this time platform should kill us as part of reboot. swss::SelectableTimer l_timer( @@ -132,8 +115,6 @@ void RebootThread::do_reboot(void) { if (m_request.method() == RebootMethod::COLD) { do_cold_reboot(s); - } else if (m_request.method() == RebootMethod::NSF) { - do_nsf_reboot(s); } else { // This shouldn't be possible. Reference check_start_preconditions() SWSS_LOG_ERROR("Received unrecognized method type = %s", @@ -165,82 +146,6 @@ RebootThread::Progress RebootThread::send_dbus_reboot_request() { return Progress::PROCEED; } -/* RebootThread::Progress RebootThread::nsf_reboot_helper(swss::Select &s) { - SWSS_LOG_ENTER(); - - SWSS_LOG_NOTICE("starting state verification: if enabled"); - if (Progress::EXIT_EARLY == perform_state_verification(s)) { - SWSS_LOG_ERROR("state verification returned EXIT_EARLY"); - return Progress::EXIT_EARLY; - } - - SWSS_LOG_NOTICE("starting freeze and container stop"); - m_telemetry.record_stage_start(WarmBootStage::STAGE_FREEZE); - if (Progress::EXIT_EARLY == perform_freeze_w_container_stop(s)) { - SWSS_LOG_ERROR("perform_freeze_w_container_stop: returned EXIT_EARLY"); - m_telemetry.record_stage_end(WarmBootStage::STAGE_FREEZE, - false); - return Progress::EXIT_EARLY; - } - m_telemetry.record_stage_end(WarmBootStage::STAGE_FREEZE, true); - - SWSS_LOG_NOTICE("starting checkpoint"); - m_telemetry.record_stage_start(WarmBootStage::STAGE_CHECKPOINT); - if (Progress::EXIT_EARLY == perform_checkpoint(s)) { - SWSS_LOG_ERROR("perform_checkpoint: returned EXIT_EARLY"); - m_telemetry.record_stage_end(WarmBootStage::STAGE_CHECKPOINT, - false); - return Progress::EXIT_EARLY; - } - m_telemetry.record_stage_end(WarmBootStage::STAGE_CHECKPOINT, - true); - - SWSS_LOG_NOTICE( - "done all pre-reboot steps, sending reboot request to platform"); - if (send_dbus_reboot_request() == Progress::EXIT_EARLY) { - return Progress::EXIT_EARLY; - } - - // Wait for platform to reboot. If we return, reboot failed. - // Logging, error status and monitoring for critical state are handled within. - return wait_for_platform_reboot(s); -} */ - -void RebootThread::do_nsf_reboot(swss::Select &s) { - SWSS_LOG_ENTER(); - SWSS_LOG_NOTICE("Starting NSF reboot"); - - // Delete the warm restart state and timestamp for all application - init_warm_reboot_states(m_db); - - //m_registration.fetch_registration_info(); - - // Save the list of registered apps. - // m_registration.clear_all_init_apps(); - // m_registration.save_all_init_apps(); - - m_telemetry.record_overall_start(); - - // Enable system warm restart: WARM_RESTART_ENABLE_TABLE|system - set_warm_restart_enable(m_db, true); - - /* RebootThread::Progress progress = nsf_reboot_helper(s); - if (progress == Progress::PROCEED) { - // We shouldn't be here. No errors (EXIT_EARLY) occurred during - // reboot process under our control. Platform reboot should've killed us. - log_error_and_set_non_retry_failure("platform failed to reboot"); - - // Set critical state - //m_critical_interface.report_critical_state("platform failed to reboot"); - } */ - - // NSF has failed. Either an error (EXIT_EARLY from nsf_reboot_helper) - // or platform failed to kill us after waiting m_reboot_timeout. - // Clear warm restart flag, close out telemetry. - m_telemetry.record_overall_end(/*success=*/false); - set_warm_restart_enable(m_db, false); -} - void RebootThread::do_cold_reboot(swss::Select &s) { SWSS_LOG_ENTER(); SWSS_LOG_NOTICE("Sending cold reboot request to platform"); @@ -249,7 +154,6 @@ void RebootThread::do_cold_reboot(swss::Select &s) { } // Wait for platform to reboot. If we return, reboot failed. - // Logging, error status and monitoring for critical state are handled within. if (wait_for_platform_reboot(s) == Progress::EXIT_EARLY) { return; } @@ -272,6 +176,7 @@ void RebootThread::reboot_thread(void) { m_finished.notify(); } + bool RebootThread::check_start_preconditions(const RebootRequest &request, NotificationResponse &response) { // We have to join a previous executing thread before restarting. @@ -280,32 +185,19 @@ bool RebootThread::check_start_preconditions(const RebootRequest &request, response.json_string = "RebootThread: can't Start while active"; response.status = swss::StatusCode::SWSS_RC_IN_USE; } else if (request.method() != RebootMethod::COLD && - request.method() != RebootMethod::NSF) { + request.method() != RebootMethod::WARM) { response.json_string = "RebootThread: Start rx'd unsupported method"; response.status = swss::StatusCode::SWSS_RC_INVALID_PARAM; } else if (request.delay() != 0) { response.json_string = "RebootThread: delayed start not supported"; response.status = swss::StatusCode::SWSS_RC_INVALID_PARAM; - } else if (request.method() == RebootMethod::NSF) { - if (m_status.get_last_reboot_status() == - RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE) { - // If the last reboot failed with a non-retriable failure, don't retry. - // But, we will allow a cold boot to recover. - response.json_string = - "RebootThread: last NSF failed with non-retriable failure"; - response.status = swss::StatusCode::SWSS_RC_FAILED_PRECONDITION; - } /* else if (m_critical_interface.is_system_critical()) { - response.json_string = "RebootThread: in critical state, NSF not allowed"; - response.status = swss::StatusCode::SWSS_RC_FAILED_PRECONDITION; - } */ - } + } if (response.status == swss::StatusCode::SWSS_RC_SUCCESS) { return true; } SWSS_LOG_ERROR("%s", response.json_string.c_str()); - // Log the reboot request contents. gpu::Status status; std::string json_request; @@ -320,6 +212,7 @@ bool RebootThread::check_start_preconditions(const RebootRequest &request, return false; } + NotificationResponse RebootThread::Start(const RebootRequest &request) { SWSS_LOG_ENTER(); @@ -351,17 +244,6 @@ NotificationResponse RebootThread::Start(const RebootRequest &request) { return response; } -/* bool RebootThread::check_and_log_critical_state( - const std::string error_string) { - SWSS_LOG_ENTER(); - if (m_critical_interface.is_system_critical()) { - // Critical state isn't retriable. - log_error_and_set_non_retry_failure(error_string); - return true; - } - return false; -} */ - void RebootThread::log_error_and_set_non_retry_failure( const std::string error_string) { SWSS_LOG_ENTER(); @@ -379,587 +261,4 @@ void RebootThread::log_error_and_set_failure_as_retriable( error_string); } -RebootThread::Status RebootThread::handle_state_verification_event( - swss::SubscriberStateTable &sub, std::string ×tamp) { - swss::KeyOpFieldsValuesTuple kco; - sub.pop(kco); - - std::string key = kfvKey(kco); - - /* if (key != ALL_COMPONENT) { - // we only care about updates to the "all" key - return Status::KEEP_WAITING; - } */ - - std::vector fvs = kfvFieldsValues(kco); - std::string status; - std::string ts; - - /* for (const auto &fv : fvs) { - if (fvField(fv) == TIMESTAMP_FIELD) { - ts = fvValue(fv); - } else if (fvField(fv) == STATUS_FIELD) { - status = fvValue(fv); - } - } */ - - if (ts != timestamp) { - // if this wasn't our state verification request - return Status::KEEP_WAITING; - } - - // We've received a valid state verification update - // key was ALL_COMPONENT and timestamp matched our - // last request. - - /* if (status == SV_NOT_RUN) { - // restart state verification - timestamp = send_state_verification_notification(m_db, false); - return Status::KEEP_WAITING; - } */ - - /* if (status == SV_PASS) { - return Status::SUCCESS; - } else if (status == SV_FAIL) { - // Hard failure is not retriable: not_run as final status - // is retriable. - log_error_and_set_non_retry_failure( - "state verification failed during reboot"); - return Status::FAILURE; - } */ - - return Status::KEEP_WAITING; -} - -Progress RebootThread::state_verification_select( - swss::Select &s, swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub, std::string ×tamp) { - SWSS_LOG_ENTER(); - - while (true) { - swss::Selectable *sel; - int select_ret; - select_ret = s.select(&sel); - - if (select_ret == swss::Select::ERROR) { - SWSS_LOG_NOTICE("Error: %s!", strerror(errno)); - continue; - } - if (select_ret != swss::Select::OBJECT) { - SWSS_LOG_NOTICE("select returned unexpedted non-OBJECT"); - continue; - } - - if (sel == &m_stop) { - SWSS_LOG_ERROR("m_stop (sigterm) rx'd during reboot state verification"); - return Progress::EXIT_EARLY; - } else if (sel == &l_timer) { - // Timeout during state verification is a retriable error. - log_error_and_set_failure_as_retriable( - "timeout occurred during reboot state verification: retriable error"); - return Progress::EXIT_EARLY; - } else if (sel == &sub) { - Status status = handle_state_verification_event(sub, timestamp); - - if (status == Status::SUCCESS) { - SWSS_LOG_NOTICE("state verification reported success"); - return Progress::PROCEED; - } else if (status == Status::FAILURE) { - // error is logged and error string set in - // handle_state_verification_event. - return Progress::EXIT_EARLY; - } else { - continue; - } - } - } -} - -/* Progress RebootThread::perform_state_verification(swss::Select &s) { - if (check_and_log_critical_state( - "system entered critical state before reboot state verification")) { - return Progress::EXIT_EARLY; - } - - if (!swss::WarmStart::isStateVerificationShutdownEnabled()) { - if state verification isn't enabled in CONFIG_DB: skip state verification - SWSS_LOG_NOTICE("State verification not enabled"); - return Progress::PROCEED; - } - - swss::SelectableTimer l_timer( - timespec{.tv_sec = m_state_verification_timeout, .tv_nsec = 0}); - s.addSelectable(&l_timer); - - swss::SubscriberStateTable sub(&m_db, STATE_VERIFICATION_RESP_TABLE); - s.addSelectable(&sub); - - l_timer.start(); - - // Send a non-frozen state verifiation request. - std::string timestamp = send_state_verification_notification(m_db, false); - SWSS_LOG_NOTICE("State verification triggered, waiting for result"); - - Progress progress = state_verification_select(s, l_timer, sub, timestamp); - - l_timer.stop(); - s.removeSelectable(&l_timer); - s.removeSelectable(&sub); - return progress; -} */ - -// -// Stop On Freeze Support -// - -// Perform quiescence and container stop in parallel. -// First we request container stop. -// Freeze is sent to all containers. -// We wait for containers to quiesce (or checkpoint). -// We wait for containers to stop. -Progress RebootThread::perform_freeze_w_container_stop(swss::Select &s) { - SWSS_LOG_ENTER(); - std::string request_id; - - SWSS_LOG_NOTICE("Requesting container stop on freeze"); - if (Progress::EXIT_EARLY == request_stop_on_freeze(request_id)) { - SWSS_LOG_ERROR("request_stop_on_freeze: returned EXIT_EARLY"); - return Progress::EXIT_EARLY; - } - SWSS_LOG_NOTICE("Stop on freeze request sent."); - - swss::SelectableTimer l_timer( - milliseconds_to_timespec(m_quiescence_timeout_ms)); - s.addSelectable(&l_timer); - l_timer.start(); - - Progress progress = - wait_for_container_stop_and_quiescence(s, l_timer, request_id); - - s.removeSelectable(&l_timer); - return progress; -} - -Progress RebootThread::wait_for_container_stop_and_quiescence( - swss::Select &s, swss::SelectableTimer &l_timer, - const std::string &request_id) { - SWSS_LOG_NOTICE("waiting for containers to stop"); - if (Progress::EXIT_EARLY == wait_for_container_stop(s, request_id, l_timer)) { - SWSS_LOG_ERROR("wait_for_container_stop: returned EXIT_EARLY"); - return Progress::EXIT_EARLY; - } - - SWSS_LOG_NOTICE("starting freeze quiescence"); - /* if (Progress::EXIT_EARLY == perform_freeze_quiescence(s, l_timer)) { - SWSS_LOG_ERROR( - "perform_freeze_quiescence: returned EXIT_EARLY. Outstanding apps: %s", - m_registration - .join_pending_apps(swss::WarmStart::WarmBootStage::STAGE_FREEZE) - .c_str()); - return Progress::EXIT_EARLY; - } */ - - return Progress::PROCEED; -} - -Progress RebootThread::build_stop_container_request(std::string &json_request, - std::string &request_id) { - SWSS_LOG_ENTER(); - - request_id = swss::getTimestamp(); - StopContainersRequest request; - request.set_request_id(request_id); - - // Get the list of apps that need to be stopped - Registration::RegistrationSet stop_set = - m_registration.get_stop_on_freeze_set(); - - for (const std::string &app : stop_set) { - request.add_container_names(app); - } - - gpu::Status status = gpu::MessageToJsonString(request, &json_request); - - if (!status.ok()) { - std::string error_string = - "unable to convert StopContainersRequest protobuf to json: " + - status.message().as_string(); - log_error_and_set_non_retry_failure(error_string); - return Progress::EXIT_EARLY; - } - return Progress::PROCEED; -} - -Progress RebootThread::request_stop_on_freeze(std::string &request_id) { - SWSS_LOG_ENTER(); - - // Get the list of apps that need to be stopped - Registration::RegistrationSet stop_set = - m_registration.get_stop_on_freeze_set(); - - if (stop_set.empty()) { - return Progress::PROCEED; - } - - std::string json_request; - if (build_stop_container_request(json_request, request_id) == - Progress::EXIT_EARLY) { - return Progress::EXIT_EARLY; - } - - // Send the stop containers request to the stop container host service via - // dbus. - DbusInterface::DbusResponse dbus_response = - m_dbus_interface.StopContainers(json_request); - - if (dbus_response.status == DbusInterface::DbusStatus::DBUS_FAIL) { - log_error_and_set_non_retry_failure(dbus_response.json_string); - return Progress::EXIT_EARLY; - } - return Progress::PROCEED; -} - -RebootThread::Status RebootThread::check_container_stop( - const std::string &request_id) { - SWSS_LOG_ENTER(); - StopContainersStatusRequest request; - request.set_request_id(request_id); - - std::string json_request; - gpu::Status status = gpu::MessageToJsonString(request, &json_request); - - if (!status.ok()) { - SWSS_LOG_ERROR( - "unable to convert StopContainersStatusRequest protobuf to json: %s", - status.message().as_string().c_str()); - return Status::FAILURE; - } - - // Send the stop containers request to the stop container host service via - // dbus. - DbusInterface::DbusResponse dbus_response = - m_dbus_interface.StopContainerStatus(json_request); - - if (dbus_response.status == DbusInterface::DbusStatus::DBUS_FAIL) { - SWSS_LOG_ERROR("StopContainersStatus returned ERROR: %s", - dbus_response.json_string.c_str()); - return Status::FAILURE; - } - - StopContainersResponse response; - status = gpu::JsonStringToMessage(dbus_response.json_string, &response); - if (!status.ok()) { - SWSS_LOG_ERROR( - "unable to convert StopContainersStatus json |%s| to prototobuf: |%s|", - dbus_response.json_string.c_str(), - status.message().as_string().c_str()); - return Status::FAILURE; - } - - if (response.status() == ShutdownStatus::DONE) { - return Status::SUCCESS; - } else if (response.status() == ShutdownStatus::ERROR) { - SWSS_LOG_ERROR( - "Container stop service reported error shutting down containers: %s", - response.DebugString().c_str()); - } - return Status::KEEP_WAITING; -} - -RebootThread::Status RebootThread::precheck_wait_for_container_stop( - const std::string &request_id) { - // Get the list of apps that need to be stopped - Registration::RegistrationSet stop_set = - m_registration.get_stop_on_freeze_set(); - - if (stop_set.empty()) { - return Status::SUCCESS; - } - if (check_container_stop(request_id) == Status::SUCCESS) { - return Status::SUCCESS; - } - return Status::KEEP_WAITING; -} - -Progress RebootThread::wait_for_container_stop(swss::Select &s, - const std::string &request_id, - swss::SelectableTimer &l_timer) { - SWSS_LOG_ENTER(); - - // Have containers stopped? Are there no containers to stop? - if (Status::SUCCESS == precheck_wait_for_container_stop(request_id)) { - return Progress::PROCEED; - } - - /* if (check_and_log_critical_state("system entered critical state while " - "waiting for containers to stop")) { - return Progress::EXIT_EARLY; - } */ - - while (true) { - swss::Selectable *sel; - int select_ret; - select_ret = s.select(&sel, SELECT_TIMEOUT_500_MS); - - if (Status::SUCCESS == check_container_stop(request_id)) { - return Progress::PROCEED; - } - - if (select_ret == swss::Select::ERROR) { - SWSS_LOG_NOTICE("Error: %s!", strerror(errno)); - continue; - } - - if (select_ret == swss::Select::TIMEOUT) { - // Don't flood logs on timeout. - continue; - } - - if (select_ret != swss::Select::OBJECT) { - SWSS_LOG_NOTICE("select returned unexpected non-OBJECT"); - continue; - } - - if (sel == &m_stop) { - SWSS_LOG_NOTICE( - "m_stop (sigterm) rx'd while waiting for containers to stop"); - return Progress::EXIT_EARLY; - } else if (sel == &l_timer) { - log_error_and_set_non_retry_failure( - "timeout occurred waiting for containers to stop"); - return Progress::EXIT_EARLY; - } - } -} - -// -// Freeze Quiescence Support -// -/* Progress RebootThread::perform_freeze_quiescence( - swss::Select &s, swss::SelectableTimer &l_timer) { - SWSS_LOG_ENTER(); - if (check_and_log_critical_state( - "system entered critical state before freezing")) { - return Progress::EXIT_EARLY; - } - - swss::SubscriberStateTable sub(&m_db, STATE_WARM_RESTART_TABLE_NAME); - s.addSelectable(&sub); - - send_nsf_manager_notification(m_db, - swss::WarmStart::WarmBootNotification::kFreeze); - SWSS_LOG_NOTICE( - "freeze signal sent, waiting for apps to reach frozen state: %s", - m_registration - .join_pending_apps(swss::WarmStart::WarmBootStage::STAGE_FREEZE) - .c_str()); - - Progress progress = freeze_quiescence_select(s, l_timer, sub); - - s.removeSelectable(&sub); - return progress; -} */ - -/* Progress RebootThread::freeze_quiescence_select( - swss::Select &s, swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub) { - SWSS_LOG_ENTER(); - - steady_clock::time_point start_time; - bool quiesced = false; - - // Check the current status of all registered apps. - Registration::Response response = m_registration.check_quiesced(); - - if (response.status == Registration::Status::FAILURE) { - log_error_and_set_non_retry_failure(response.error_string); - return Progress::EXIT_EARLY; - } - - if (response.status == Registration::Status::COMPLETED) { - // We're quiesced: set start time for 10 second quiescence hold timer - quiesced = true; - start_time = steady_clock::now(); - } - - while (true) { - swss::Selectable *sel; - int select_ret; - - // Set timeout to 250 milli-seconds. We'll wake up at least every - // quarter second and can check if quiescence hold time has passed. - select_ret = s.select(&sel, SELECT_TIMEOUT_250_MS); - - if (quiesced) { - if (steady_clock::now() - start_time > - std::chrono::milliseconds(m_quiescence_hold_time_ms)) { - // We've been quiesced for 10 seconds: we're ready to PROCEED. - return Progress::PROCEED; - } - } - - if (select_ret == swss::Select::TIMEOUT) { - // Don't flood logs on timeout. - continue; - } - - if (select_ret == swss::Select::ERROR) { - SWSS_LOG_NOTICE("Error: %s!", strerror(errno)); - continue; - } - if (select_ret != swss::Select::OBJECT) { - SWSS_LOG_NOTICE("select returned unexpected non-OBJECT"); - continue; - } - - if (sel == &m_stop) { - std::string error_string = - "m_stop (sigterm) rx'd during reboot " + - Registration::get_warm_boot_stage_name(WarmBootStage::STAGE_FREEZE); - "m_stop (sigterm) rx'd during reboot " + - Registration::get_warm_boot_stage_name(WarmBootStage::STAGE_FREEZE); - SWSS_LOG_ERROR("%s\n", error_string.c_str()); - return Progress::EXIT_EARLY; - } else if (sel == &l_timer) { - // TODO: use getWarmBootStageFromState() or warmBootStateToStageMap() - // to get warm restart stage rather state - std::string error_string = - "timeout occurred during reboot stage " + - Registration::get_warm_boot_stage_name(WarmBootStage::STAGE_FREEZE); - "timeout occurred during reboot stage " + - Registration::get_warm_boot_stage_name(WarmBootStage::STAGE_FREEZE); - log_error_and_set_non_retry_failure(error_string); - return Progress::EXIT_EARLY; - } else if (sel == &sub) { - swss::KeyOpFieldsValuesTuple kco; - sub.pop(kco); - - Registration::Response response = - m_registration.handle_state_event(WarmBootStage::STAGE_FREEZE, kco); - - if (response.status == Registration::Status::FAILURE) { - log_error_and_set_non_retry_failure(response.error_string); - return Progress::EXIT_EARLY; - } else if (response.status == Registration::Status::COMPLETED) { - // We're quiesced: set start time for 10 second quiescence hold timer - quiesced = true; - start_time = steady_clock::now(); - } else { - // Registration::Status::IN_PROCESS - quiesced = false; - } - } - } -} */ - -// -// Checkpoint support. -// -/* Progress RebootThread::perform_checkpoint(swss::Select &s) { - SWSS_LOG_ENTER(); - if (check_and_log_critical_state( - "system entered critical state before checkpointing")) { - return Progress::EXIT_EARLY; - } - - swss::SelectableTimer l_timer( - timespec{.tv_sec = m_checkpoint_timeout, .tv_nsec = 0}); - s.addSelectable(&l_timer); - - swss::SubscriberStateTable sub(&m_db, STATE_WARM_RESTART_TABLE_NAME); - s.addSelectable(&sub); - - l_timer.start(); - - send_nsf_manager_notification( - m_db, swss::WarmStart::WarmBootNotification::kCheckpoint); - SWSS_LOG_NOTICE( - "checkpoint signal sent, waiting for apps to reach checkpointed state: " - "%s", - m_registration - .join_pending_apps(swss::WarmStart::WarmBootStage::STAGE_CHECKPOINT) - .c_str()); - - Progress progress = checkpoint_select_stage_one(s, l_timer, sub); - - l_timer.stop(); - s.removeSelectable(&l_timer); - s.removeSelectable(&sub); - return progress; -} */ - -/* Progress RebootThread::checkpoint_select_stage_one( - swss::Select &s, swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub) { - SWSS_LOG_ENTER(); - - // We're subscribed: so we wont miss any events. - // Check the current status of all registered apps. - Registration::Response response = m_registration.check_checkpointed(); - if (response.status == Registration::Status::COMPLETED) { - return Progress::PROCEED; - } - if (response.status == Registration::Status::FAILURE) { - log_error_and_set_non_retry_failure( - "check_checkpointed returned error: " + response.error_string + - ". Outstanding apps: " + - m_registration.join_pending_apps( - swss::WarmStart::WarmBootStage::STAGE_CHECKPOINT)); - return Progress::EXIT_EARLY; - } - return checkpoint_stage_two(s, l_timer, sub); -} */ - -/* Progress RebootThread::checkpoint_stage_two(swss::Select &s, - swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub) { - while (true) { - swss::Selectable *sel; - int select_ret; - select_ret = s.select(&sel); - - if (select_ret == swss::Select::ERROR) { - SWSS_LOG_NOTICE("Error: %s!", strerror(errno)); - continue; - } - if (select_ret != swss::Select::OBJECT) { - SWSS_LOG_NOTICE("select returned unexpected non-OBJECT"); - continue; - } - - if (sel == &m_stop) { - std::string error_string = "m_stop (sigterm) rx'd during reboot " + - Registration::get_warm_boot_stage_name( - WarmBootStage::STAGE_CHECKPOINT); - SWSS_LOG_ERROR("%s\n", error_string.c_str()); - return Progress::EXIT_EARLY; - } else if (sel == &l_timer) { - // TODO: use getWarmBootStageFromState() or warmBootStateToStageMap() - // to get warm restart stage rather state - std::string error_string = - "timeout occurred during reboot stage " + - Registration::get_warm_boot_stage_name( - WarmBootStage::STAGE_CHECKPOINT) + - ". Outstanding apps: " + - m_registration.join_pending_apps( - swss::WarmStart::WarmBootStage::STAGE_CHECKPOINT); - log_error_and_set_non_retry_failure(error_string); - return Progress::EXIT_EARLY; - } else if (sel == &sub) { - swss::KeyOpFieldsValuesTuple kco; - sub.pop(kco); - Registration::Response response = m_registration.handle_state_event( - WarmBootStage::STAGE_CHECKPOINT, kco); - if (response.status == Registration::Status::COMPLETED) { - return Progress::PROCEED; - } else if (response.status == Registration::Status::FAILURE) { - log_error_and_set_non_retry_failure(response.error_string); - return Progress::EXIT_EARLY; - } else { - continue; - } - } - } -} */ - } // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/reboot_thread.h b/src/sonic-framework/rebootbackend/reboot_thread.h index 3b9d42852dca..bd0b54aed2a2 100644 --- a/src/sonic-framework/rebootbackend/reboot_thread.h +++ b/src/sonic-framework/rebootbackend/reboot_thread.h @@ -36,7 +36,7 @@ class ThreadStatus { // Number of reboots since active. m_proto_status.set_count(0); - // RebootMethod is type of of reboot: cold, nsf, warm, fast from a + // RebootMethod is type of of reboot: cold, warm, fast from a // RebootRequest m_proto_status.set_method(gnoi::system::RebootMethod::UNKNOWN); @@ -142,8 +142,6 @@ class RebootThread { // interface: dbus reboot host service access // m_finished: let launching task know thread has finished RebootThread(DbusInterface &dbus_interface, - // CriticalStateInterface &critical_interface, - TelemetryInterface &telemetry_interface, swss::SelectableEvent &m_finished); NotificationResponse Start(const gnoi::system::RebootRequest &request); @@ -166,31 +164,23 @@ class RebootThread { void reboot_thread(void); void do_reboot(void); Progress send_dbus_reboot_request(); - Progress nsf_reboot_helper(swss::Select &s); - void do_nsf_reboot(swss::Select &s); void do_cold_reboot(swss::Select &s); // Inner loop select handler to wait for platform reboot. // wait for timeout // wait for a stop request (sigterm) // Returns: - // EXIT_EARLY: an issue occurred that stops NSF + // EXIT_EARLY: an issue occurred that stops WARM // PROCEED: if reboot timeout expired Progress platform_reboot_select(swss::Select &s, swss::SelectableTimer &l_timer); // Wait for platform to reboot while waiting for possible stop // Returns: - // EXIT_EARLY: an issue occurred that stops NSF + // EXIT_EARLY: an issue occurred that stops WARM // PROCEED: if reboot timeout expired Progress wait_for_platform_reboot(swss::Select &s); - // Check for critical state: log error and update status. - // Returns: - // true: if system is in critical state - // false: all is well - bool check_and_log_critical_state(const std::string error_string); - // Log error string, set status to RebootStatus_Status_STATUS_FAILURE // Set status message to error_string. void log_error_and_set_non_retry_failure(const std::string error_string); @@ -200,182 +190,12 @@ class RebootThread { // error_string. void log_error_and_set_failure_as_retriable(const std::string error_string); - // Handle a database subscription update to STATE_VERIFICATION_RESP_TABLE - // Confirm update is for the "all" component with correct timestamp. - // if update is not_run: then restart - // Args: - // sub: [input] selectable subscription to STATE_VERIFICATION_RESP_TABLE - // data is pending - // timestamp: [input && output] the timestamp sent to state verification - // with the state verification request - // Returns: - // KEEP_WAITING: keep waiting for success, fail or timeout - // SUCCESS: state verification passed, procced - // FAILURE: state verification failed - Status handle_state_verification_event(swss::SubscriberStateTable &sub, - std::string ×tamp); - - // Infinite lop select for state verification - // Listen for a stop, timer expiration or database update - // Args: - // s: select to be monitored (stop, timer, subscription) events - // l_timer: timeout expiration selectable - // sub: subscription to STATE_VERIFICATION_RESP_TABLE - // timestamp: [input] the timestamp sent with the state verification - // request. Used to match response with request. - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress state_verification_select(swss::Select &s, - swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub, - std::string ×tamp); - - // If enabled: perform non-frozen state verification - // Check for critical state, listen for stop, handle a timeout - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress perform_state_verification(swss::Select &s); - - // Perform freeze/quiescence with container stop support. - // Request platform stop (stop on freeze) containers. - // Request applications freeze and wait for registered apps - // to quiesce or checkpoint. - // Poll platform till containers have stopped. - // Check for critical state, listen for stop, handle a timeout - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress perform_freeze_w_container_stop(swss::Select &s); - - // Wait for stop_on_freeze containers to exit, then - // wait for freeze containers to quiesce (or checkpoint). - // Check for critical state, listen for stop, handle a timeout - // Args: - // s: select to be monitored (stop, timer, subscription) events - // l_timer: timeout expiration selectable, running at function - // start - // request_id: [input] request_id populated in StopContainersRequest. - // This is used/needed when sending StopContainersStatusRequest. - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress wait_for_container_stop_and_quiescence( - swss::Select &s, swss::SelectableTimer &l_timer, - const std::string &request_id); - - // Build a json formatted stop container request proto message. - // Message populated with containers that registered stop on freeze. - // Args: - // json_request: [output] json formatted StopContainersRequest - // message - // request_id: [output] request_id populated in StopContainersRequest. - // This is used/needed when sending StopContainersStatusRequest. - Progress build_stop_container_request(std::string &json_request, - std::string &request_id); - - // Send a StopContainersRequest message to the gnoi_stop_container - // sonic host service requesting list of containres be stopped. - // Args: - // request_id: [output] request_id populated in StopContainersRequest. - // This is used/needed when sending StopContainersStatusRequest. - Progress request_stop_on_freeze(std::string &request_id); - - // Send a StopContainersStatusRequest message to the gnoi_stop_container - // sonic host service to check if all containers have stopped. - // Args: - // request_id: [input] request_id populated in StopContainersRequest. - // This is used/needed when sending StopContainersStatusRequest. - // Returns: - // SUCCESS: containers have stopped, we're done. - // KEEP_WAITING: containers haven't stopped - // FAILURE: dbus error or protobuf conversion error - // suggest retry till timeout - Status check_container_stop(const std::string &request_id); - - // Check if containers have stopped, or there are no containers to stop - // Args: - // request_id: [input] request_id populated in StopContainersRequest. - // This is used/needed when sending StopContainersStatusRequest. - // Returns: - // SUCCESS: containers have stopped, we're done. - // KEEP_WAITING: containers haven't stopped - // FAILURE: dbus error or protobuf conversion error - // suggest retry till timeout - Status precheck_wait_for_container_stop(const std::string &request_id); - - // Poll the gnoi_stop_container host service to determine if requested - // set of containers have exited. - // Check for critical state, listen for stop, handle a timeout - // Args: - // s: [input] select statement that has m_stop as a selectable - // request_id: [input] request_id populated in StopContainersRequest. - // This is used/needed when sending StopContainersStatusRequest. - // l_timer: timeout expiration selectable, running at function - // start - Progress wait_for_container_stop(swss::Select &s, - const std::string &request_id, - swss::SelectableTimer &l_timer); - - // Perform freeze/quiescence. - // Request applications freeze and wait for registered apps - // to quiesce or checkpoint. - // Check for critical state, listen for stop, handle a timeout - // Args: - // s: [input] select statement that has m_stop as a selectable - // l_timer: [inpu] timeout expiration selectable, running at function start - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress perform_freeze_quiescence(swss::Select &s, - swss::SelectableTimer &l_timer); - - // Helper function for freeze quiescence stage: - // Check current database status before waiting for subscriptions updates. - // infinite loop select for checkpoint - // Listen for a stop, timer expiration or database update - // We must be quiescent for 10 seconds before PROCEED. - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress freeze_quiescence_select(swss::Select &s, - swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub); - - // Perform checkpointing - // Request applications checkpoint and wait for registered apps - // to checkpoint. - // Check for critical state, listen for stop, handle a timeout - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress perform_checkpoint(swss::Select &s); - - // Hepler function for checkpoint: Check initial checkpoint - // status before entering select loop. - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress checkpoint_select_stage_one(swss::Select &s, - swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub); - - // Helper function for checkpoint stage: - // infinite loop select for checkpoint - // Listen for a stop, timer expiration or database update - // Returns: - // EXIT_EARLY: an issue occurred that stops NSF - // PROCEED: if reboot timeout expired - Progress checkpoint_stage_two(swss::Select &s, swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub); // Request is input only. // Response is ouput only. // Return true if preconditions met, false otherwise. bool check_start_preconditions(const gnoi::system::RebootRequest &request, NotificationResponse &response); - std::thread m_thread; // Signal m_finished to let main thread know weve completed. @@ -385,31 +205,15 @@ class RebootThread { // m_stop signalled by main thread on sigterm: cleanup and exit. swss::SelectableEvent m_stop; DbusInterface &m_dbus_interface; - //CriticalStateInterface &m_critical_interface; - TelemetryInterface &m_telemetry; swss::DBConnector m_db; ThreadStatus m_status; gnoi::system::RebootRequest m_request; - Registration m_registration; // Wait for system to reboot: allow unit test to shorten. // TODO: there is a plan to make these timer values // available in CONFIG_DB static constexpr uint32_t kRebootTime = 260; - uint32_t m_reboot_timeout = kRebootTime; - - static constexpr uint32_t kStateVerificationTime = 180; - uint32_t m_state_verification_timeout = kStateVerificationTime; - - static constexpr uint32_t kQuiescenceTimeMs = 60 * ONE_THOUSAND; - uint32_t m_quiescence_timeout_ms = kQuiescenceTimeMs; - - // We must remain quiescent for 5 seconds. - static constexpr uint32_t kQuiescenceHoldTimeMs = 5 * ONE_THOUSAND; - uint32_t m_quiescence_hold_time_ms = kQuiescenceHoldTimeMs; - - static constexpr uint32_t kCheckpointTime = 30; - uint32_t m_checkpoint_timeout = kCheckpointTime; + long m_reboot_timeout = kRebootTime; friend class RebootBETestWithoutStop; friend class RebootThreadTest; diff --git a/src/sonic-framework/rebootbackend/rebootbackend.cpp b/src/sonic-framework/rebootbackend/rebootbackend.cpp index f02f209fdedd..5b48d182f87f 100644 --- a/src/sonic-framework/rebootbackend/rebootbackend.cpp +++ b/src/sonic-framework/rebootbackend/rebootbackend.cpp @@ -1,16 +1,12 @@ #include "interfaces.h" #include "reboot_interfaces.h" #include "rebootbe.h" -#include "telemetry_helper.h" using namespace ::rebootbackend; int main(int argc, char** argv) { HostServiceDbus dbus_interface; - //CriticalState critical_interface; - TelemetryHelper telemetry_helper; - //RebootBE rebootbe(dbus_interface, critical_interface, telemetry_helper); - RebootBE rebootbe(dbus_interface, telemetry_helper); + RebootBE rebootbe(dbus_interface); rebootbe.Start(); return 0; } diff --git a/src/sonic-framework/rebootbackend/rebootbe.cpp b/src/sonic-framework/rebootbackend/rebootbe.cpp index b4f03c8c6962..4e24a2dd47d6 100644 --- a/src/sonic-framework/rebootbackend/rebootbe.cpp +++ b/src/sonic-framework/rebootbackend/rebootbe.cpp @@ -1,5 +1,4 @@ #include "rebootbe.h" - #include #include @@ -15,7 +14,6 @@ #include "reboot_interfaces.h" #include "select.h" #include "status_code_util.h" -#include "warm_restart.h" namespace rebootbackend { @@ -23,31 +21,22 @@ namespace gpu = ::google::protobuf::util; bool sigterm_requested = false; -RebootBE::RebootBE(DbusInterface &dbus_interface, -// CriticalStateInterface &critical_interface, - TelemetryInterface &telemetry_interface) +RebootBE::RebootBE(DbusInterface &dbus_interface) : m_db("STATE_DB", 0), m_rebootResponse(&m_db, REBOOT_RESPONSE_NOTIFICATION_CHANNEL), m_notificationConsumer(&m_db, REBOOT_REQUEST_NOTIFICATION_CHANNEL), m_dbus(dbus_interface), - //m_critical(critical_interface), - m_telemetry(telemetry_interface), - m_init_thread( - //std::make_unique(critical_interface, telemetry_interface, - std::make_unique(telemetry_interface, - m_init_thread_done, m_stack_unfrozen)), - //m_reboot_thread(dbus_interface, critical_interface, telemetry_interface, - m_reboot_thread(dbus_interface, telemetry_interface, + m_reboot_thread(dbus_interface, m_reboot_thread_finished) { swss::Logger::linkToDbNative("rebootbackend"); } -RebootBE::NsfManagerStatus RebootBE::GetCurrentStatus() { +RebootBE::RebManagerStatus RebootBE::GetCurrentStatus() { const std::lock_guard lock(m_status_mutex); return m_current_status; } -void RebootBE::SetCurrentStatus(NsfManagerStatus new_status) { +void RebootBE::SetCurrentStatus(RebManagerStatus new_status) { const std::lock_guard lock(m_status_mutex); m_current_status = new_status; } @@ -64,22 +53,8 @@ void RebootBE::Start() { s.addSelectable(&m_notificationConsumer); s.addSelectable(&m_done); s.addSelectable(&m_init_thread_done); - s.addSelectable(&m_stack_unfrozen); s.addSelectable(&m_reboot_thread_finished); - if (swss::WarmStart::isWarmStart()) { - SWSS_LOG_NOTICE("Launching init thread for warm start"); - SetCurrentStatus(NsfManagerStatus::NSF_INIT_WAIT); - swss::StatusCode result = m_init_thread->Start(); - if (result != swss::StatusCode::SWSS_RC_SUCCESS) { - SetCurrentStatus(NsfManagerStatus::IDLE); - SWSS_LOG_ERROR("Error launching init thread: %s", - swss::statusCodeToStr(result).c_str()); - } - } else { - SWSS_LOG_NOTICE("Warm restart not enabled, not starting init thread"); - } - SWSS_LOG_NOTICE("RebootBE entering operational loop"); while (true) { swss::Selectable *sel; @@ -91,8 +66,6 @@ void RebootBE::Start() { } else if (ret == swss::Select::OBJECT) { if (sel == &m_notificationConsumer) { do_task(m_notificationConsumer); - } else if (sel == &m_stack_unfrozen) { - handle_unfreeze(); } else if (sel == &m_init_thread_done) { handle_init_finish(); } else if (sel == &m_reboot_thread_finished) { @@ -178,7 +151,7 @@ NotificationResponse RebootBE::handle_reboot_request( response.status = swss::StatusCode::SWSS_RC_IN_USE; response.json_string = "Reboot not allowed at this time. Reboot or " - "post-warmboot NSF in progress"; + "post-warmboot in progress"; SWSS_LOG_WARN("%s", response.json_string.c_str()); return response; } @@ -188,25 +161,25 @@ NotificationResponse RebootBE::handle_reboot_request( response = m_reboot_thread.Start(request); if (response.status == swss::StatusCode::SWSS_RC_SUCCESS) { if (request.method() == gnoi::system::RebootMethod::COLD) { - SetCurrentStatus(NsfManagerStatus::COLD_REBOOT_IN_PROGRESS); - } else if (request.method() == gnoi::system::RebootMethod::NSF) { - SetCurrentStatus(NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); + SetCurrentStatus(RebManagerStatus::COLD_REBOOT_IN_PROGRESS); + } else if (request.method() == gnoi::system::RebootMethod::WARM) { + SetCurrentStatus(RebManagerStatus::WARM_REBOOT_IN_PROGRESS); } } return response; } bool RebootBE::reboot_allowed(const gnoi::system::RebootMethod reboot_method) { - NsfManagerStatus current_status = GetCurrentStatus(); + RebManagerStatus current_status = GetCurrentStatus(); switch (current_status) { - case NsfManagerStatus::COLD_REBOOT_IN_PROGRESS: - case NsfManagerStatus::NSF_REBOOT_IN_PROGRESS: { + case RebManagerStatus::COLD_REBOOT_IN_PROGRESS: + case RebManagerStatus::WARM_REBOOT_IN_PROGRESS: { return false; } - case NsfManagerStatus::NSF_INIT_WAIT: { + case RebManagerStatus::WARM_INIT_WAIT: { return reboot_method == gnoi::system::RebootMethod::COLD; } - case NsfManagerStatus::IDLE: { + case RebManagerStatus::IDLE: { return true; } default: { @@ -220,9 +193,8 @@ NotificationResponse RebootBE::handle_status_request( SWSS_LOG_ENTER(); gnoi::system::RebootStatusResponse reboot_response = - m_reboot_thread.HasRun() ? m_reboot_thread.GetResponse() - : m_init_thread->GetResponse(); - + m_reboot_thread.GetResponse(); + std::string json_reboot_response_string; google::protobuf::util::Status status = gpu::MessageToJsonString(reboot_response, &json_reboot_response_string); @@ -286,23 +258,12 @@ void RebootBE::do_task(swss::NotificationConsumer &consumer) { send_notification_response(request.op, response.status, response.json_string); } -void RebootBE::handle_unfreeze() { - SWSS_LOG_ENTER(); - SWSS_LOG_NOTICE("Receieved notification that UNFREEZE signal has been sent"); -} - void RebootBE::handle_init_finish() { SWSS_LOG_ENTER(); SWSS_LOG_NOTICE("Receieved notification that InitThread is done"); - NsfManagerStatus current_status = GetCurrentStatus(); - if (current_status == NsfManagerStatus::NSF_INIT_WAIT) { - SetCurrentStatus(NsfManagerStatus::IDLE); - } - if (m_init_thread->GetResponse().active()) { - bool result = m_init_thread->Join(); - if (!result) { - SWSS_LOG_ERROR("Encountered error trying to join init thread"); - } + RebManagerStatus current_status = GetCurrentStatus(); + if (current_status == RebManagerStatus::WARM_INIT_WAIT) { + SetCurrentStatus(RebManagerStatus::IDLE); } } @@ -312,17 +273,12 @@ void RebootBE::handle_reboot_finish() { "Receieved notification that reboot has finished. This probably means " "something is wrong"); m_reboot_thread.Join(); - SetCurrentStatus(m_init_thread->GetResponse().active() - ? NsfManagerStatus::NSF_INIT_WAIT - : NsfManagerStatus::IDLE); + SetCurrentStatus(RebManagerStatus::IDLE); } void RebootBE::handle_done() { SWSS_LOG_INFO("RebootBE received signal to stop"); - if (m_init_thread->GetResponse().active()) { - m_init_thread->Stop(); - m_init_thread->Join(); - } + if (m_reboot_thread.GetResponse().active()) { m_reboot_thread.Stop(); m_reboot_thread.Join(); diff --git a/src/sonic-framework/rebootbackend/rebootbe.h b/src/sonic-framework/rebootbackend/rebootbe.h index 3fa562ceb558..f17c06cbbf45 100644 --- a/src/sonic-framework/rebootbackend/rebootbe.h +++ b/src/sonic-framework/rebootbackend/rebootbe.h @@ -25,25 +25,23 @@ class RebootBE { std::string ret_string; }; - enum class NsfManagerStatus { - NSF_INIT_WAIT, + enum class RebManagerStatus { + WARM_INIT_WAIT, IDLE, COLD_REBOOT_IN_PROGRESS, - NSF_REBOOT_IN_PROGRESS + WARM_REBOOT_IN_PROGRESS }; - RebootBE(DbusInterface &interface, - // CriticalStateInterface &critical_interface, - TelemetryInterface &telemetry_interface); + RebootBE(DbusInterface &interface); - NsfManagerStatus GetCurrentStatus(); + RebManagerStatus GetCurrentStatus(); void Start(); void Stop(); private: std::mutex m_status_mutex; - NsfManagerStatus m_current_status = NsfManagerStatus::IDLE; + RebManagerStatus m_current_status = RebManagerStatus::IDLE; swss::SelectableEvent m_done; swss::DBConnector m_db; @@ -51,19 +49,15 @@ class RebootBE { swss::NotificationConsumer m_notificationConsumer; DbusInterface &m_dbus; - //CriticalStateInterface &m_critical; - TelemetryInterface &m_telemetry; // Signals for init thread. swss::SelectableEvent m_init_thread_done; - swss::SelectableEvent m_stack_unfrozen; - std::unique_ptr m_init_thread; // Signalled by reboot thread when thread completes. swss::SelectableEvent m_reboot_thread_finished; RebootThread m_reboot_thread; - void SetCurrentStatus(NsfManagerStatus new_status); + void SetCurrentStatus(RebManagerStatus new_status); // Reboot_Request_Channel notifications should all contain {"MESSAGE" : Data} // in the notification Data field. @@ -84,13 +78,12 @@ class RebootBE { const swss::StatusCode code, const std::string message); - // Returns true if a reboot is allowed at this time given the current NSF - // manager state and reboot type, and false otherwise. + // Returns true if a reboot is allowed at this time given the current + // warm manager state and reboot type, and false otherwise. bool reboot_allowed(const gnoi::system::RebootMethod reboot_method); void do_task(swss::NotificationConsumer &consumer); - void handle_unfreeze(); void handle_init_finish(); void handle_reboot_finish(); void handle_done(); diff --git a/src/sonic-framework/rebootbackend/redis_utils.cpp b/src/sonic-framework/rebootbackend/redis_utils.cpp index 18a3b9d69720..4010e99d423a 100644 --- a/src/sonic-framework/rebootbackend/redis_utils.cpp +++ b/src/sonic-framework/rebootbackend/redis_utils.cpp @@ -16,44 +16,6 @@ namespace rebootbackend { using WarmStartState = ::swss::WarmStart::WarmStartState; -/* const std::unordered_map> - Registration::kStageToTargetStates = { - {swss::WarmStart::WarmBootStage::STAGE_FREEZE, - {get_warm_start_state_name(WarmStartState::QUIESCENT), - get_warm_start_state_name(WarmStartState::CHECKPOINTED)}}, - {swss::WarmStart::WarmBootStage::STAGE_CHECKPOINT, - {get_warm_start_state_name(WarmStartState::CHECKPOINTED)}}, - {swss::WarmStart::WarmBootStage::STAGE_RECONCILIATION, - {get_warm_start_state_name(WarmStartState::RECONCILED)}}, - {swss::WarmStart::WarmBootStage::STAGE_UNFREEZE, - {get_warm_start_state_name(WarmStartState::COMPLETED)}}, -}; */ - -/*void send_nsf_manager_notification( - swss::DBConnector &db, swss::WarmStart::WarmBootNotification notification) { - swss::NotificationProducer producer( - &db, swss::WarmStart::kNsfManagerNotificationChannel); - - std::vector values; - std::string notification_string = - swss::WarmStart::warmBootNotificationNameMap()->at(notification); - - producer.send(notification_string, "", values); -} */ - -/* std::string send_state_verification_notification(swss::DBConnector &ldb, - const bool freeze) { - swss::NotificationProducer producer(&ldb, STATE_VERIFICATION_REQ_CHANNEL); - - std::vector values; - values.push_back( - swss::FieldValueTuple(FREEZE_FIELD, freeze ? "true" : "false")); - - std::string timestamp = swss::getTimestamp(); - producer.send(ALL_COMPONENT, timestamp, values); - return timestamp; -} */ void init_warm_reboot_states(const swss::DBConnector &db) { swss::Table table(&db, STATE_WARM_RESTART_TABLE_NAME); @@ -115,362 +77,4 @@ bool get_docker_app_from_key(const std::string &key, return true; } -/* std::string get_warm_start_state_name(swss::WarmStart::WarmStartState state) { - return swss::WarmStart::warmStartStateNameMap()->at(state).c_str(); -} */ - -void set_warm_restart_counter(swss::DBConnector &db, int count) { - swss::Table table(&db, "BOOT_INFO"); - table.hset("system", "warmboot-count", std::to_string(count)); -} - -std::string get_warm_restart_counter(swss::DBConnector &db) { - swss::Table warmRestartTable(&db, "BOOT_INFO"); - std::string counter; - warmRestartTable.hget("system", "warmboot-count", counter); - return counter; -} - -Registration::Registration() - : m_db("STATE_DB", 0), - m_separator(swss::TableBase::getTableSeparator(m_db.getDbId())) - {} -/* m_remaining_apps( - {{swss::WarmStart::WarmBootStage::STAGE_FREEZE, {}}, - {swss::WarmStart::WarmBootStage::STAGE_CHECKPOINT, {}}, - {swss::WarmStart::WarmBootStage::STAGE_RECONCILIATION, {}}, - {swss::WarmStart::WarmBootStage::STAGE_UNFREEZE, {}}}) {} - -std::string Registration::get_warm_boot_stage_name( - swss::WarmStart::WarmBootStage stage) { - { - return swss::WarmStart::warmBootStageToNameMap()->at(stage); -} */ - -/* void Registration::clear_contents() { - m_registered.clear(); - m_stop.clear(); - for (auto &stage_set_pair : m_remaining_apps) { - stage_set_pair.second.clear(); - } -}*/ - -Registration::RegistrationSet Registration::get_stop_on_freeze_set() { - return m_stop; -} - -Registration::RegistrationSet Registration::get_registered_app_set() { - return m_registered; -} - -/* void Registration::fetch_registration_info() { - SWSS_LOG_ENTER(); - - clear_contents(); - - swss::Table table(&m_db, STATE_WARM_RESTART_REGISTRATION_TABLE_NAME); - std::vector keys; - - table.getKeys(keys); - for (auto &key : keys) { - std::string docker, app; - if (!get_docker_app_from_key(key, m_separator, docker, app)) { - SWSS_LOG_ERROR("skipping registration for key = %s", key.c_str()); - continue; - } - - m_registered.insert(key); - - std::vector values; - table.get(key, values); - for (auto &v : values) { - // We only care about this field if value is "true". - // Skip this key if value is false. - if ("false" == fvValue(v)) continue; - - if (swss::WarmStart::kRegistrationStopOnFreezeKey == fvField(v)) { - m_stop.insert(docker); - } - if (swss::WarmStart::kRegistrationFreezeKey == fvField(v)) { - m_ro_quiescent_list.insert(app); - m_remaining_apps.at(swss::WarmStart::WarmBootStage::STAGE_FREEZE) - .insert(app); - m_remaining_apps.at(swss::WarmStart::WarmBootStage::STAGE_UNFREEZE) - .insert(app); - } - if (swss::WarmStart::kRegistrationCheckpointKey == fvField(v)) { - m_remaining_apps.at(swss::WarmStart::WarmBootStage::STAGE_CHECKPOINT) - .insert(app); - } - if (swss::WarmStart::kRegistrationReconciliationKey == fvField(v)) { - m_remaining_apps - .at(swss::WarmStart::WarmBootStage::STAGE_RECONCILIATION) - .insert(app); - } - } - } -} */ - -/* Registration::Response Registration::check_quiesced() { - return check_stage(swss::WarmStart::WarmBootStage::STAGE_FREEZE); -} - -Registration::Response Registration::check_checkpointed() { - return check_stage(swss::WarmStart::WarmBootStage::STAGE_CHECKPOINT); -} - -Registration::Response Registration::check_reconciled() { - return check_stage(swss::WarmStart::WarmBootStage::STAGE_RECONCILIATION); -} - -Registration::Response Registration::check_unfrozen() { - return check_stage(swss::WarmStart::WarmBootStage::STAGE_UNFREEZE); -} - -Registration::Response Registration::check_stage( - swss::WarmStart::WarmBootStage nsf_stage) { - Registration::Response response = check_states_are( - m_remaining_apps.at(nsf_stage), kStageToTargetStates.at(nsf_stage)); - if (response.status == Registration::Status::FAILURE) { - response.error_string = - "check_stage: app: " + response.error_string + - " reported FAILED during stage: " + get_warm_boot_stage_name(nsf_stage); - } - return response; -} */ - -Registration::Response Registration::check_states_are( - RegistrationSet &set_to_check, - const std::unordered_set &state_names) { - Registration::Response response; - - swss::Table warmRestartTable(&m_db, STATE_WARM_RESTART_TABLE_NAME); - for (auto key = set_to_check.begin(); key != set_to_check.end();) { - std::string state; - - warmRestartTable.hget(*key, "state", state); - -/* if (state == get_warm_start_state_name(WarmStartState::FAILED)) { - response.status = Registration::Status::FAILURE; - response.error_string = *key; - return response; - } */ - - if (state_names.find(state) != std::end(state_names)) { - key = set_to_check.erase(key); - } else { - ++key; - } - } - - if (set_to_check.empty()) { - response.status = Registration::Status::COMPLETED; - return response; - } - - response.status = Registration::Status::IN_PROCESS; - return response; -} - -/* Registration::Response Registration::handle_state_event( - swss::WarmStart::WarmBootStage monitored_stage, - const swss::KeyOpFieldsValuesTuple &kco) { - SWSS_LOG_ENTER(); - - RegistrationSet &set_to_check = m_remaining_apps.at(monitored_stage); - - std::string op = kfvOp(kco); - if (op != "SET") { - SWSS_LOG_ERROR("ignoring non-SET event: %s", op.c_str()); - return {set_to_check.empty() ? Registration::Status::COMPLETED - : Registration::Status::IN_PROCESS, - ""}; - } - - Registration::Response response = - filter_app_list(set_to_check, kfvKey(kco), monitored_stage, kco, - kStageToTargetStates.at(monitored_stage)); - - if (response.status == Registration::Status::FAILURE) { - return response; - } - - if (monitored_stage == swss::WarmStart::WarmBootStage::STAGE_FREEZE) { - response = handle_quiescence_event(kco); - } - return response; -} */ - -// Helper for handle_state_event. -// Pre-condition: caller verifies that operation is a set. -// Caller handles apps entering FAILED state. -/* Registration::Response Registration::handle_quiescence_event( - const swss::KeyOpFieldsValuesTuple &kco) { - SWSS_LOG_ENTER(); - - RegistrationSet &set_to_check = - m_remaining_apps.at(swss::WarmStart::WarmBootStage::STAGE_FREEZE); ` - - std::string app_name = kfvKey(kco); - std::string new_state = extract_event_state(kco); - - std::unordered_set state_names = - kStageToTargetStates.at(swss::WarmStart::WarmBootStage::STAGE_FREEZE); - - if (state_names.find(new_state) == std::end(state_names)) { - // the new_state is not QUIESCENT or CHECKPOINTED, the app isn't quiescent - if (m_ro_quiescent_list.find(app_name) != std::end(m_ro_quiescent_list)) { - // We are monitoring quiescence for this app: app isn't quiescent - // readd app to monitoring list (it might already be there ...) - set_to_check.insert(app_name); - } - } - return {set_to_check.empty() ? Registration::Status::COMPLETED - : Registration::Status::IN_PROCESS, - ""}; -} */ - -Registration::Response Registration::filter_app_list( - RegistrationSet &set_to_filter, const std::string app_name, -// const swss::WarmStart::WarmBootStage monitored_stage, - const swss::KeyOpFieldsValuesTuple &kco, - const std::unordered_set &state_names) { - std::string new_state = extract_event_state(kco); - - /*if (new_state == get_warm_start_state_name(WarmStartState::FAILED)) { - return {Registration::Status::FAILURE, - "handle_state_event: app: " + app_name + - " reported FAILED when looking for state: " + - get_warm_boot_stage_name(monitored_stage)}; - }*/ - - if (state_names.find(new_state) != std::end(state_names)) { - set_to_filter.erase(app_name); - } - - Registration::Response response; - response.status = set_to_filter.empty() ? Registration::Status::COMPLETED - : Registration::Status::IN_PROCESS; - - return response; -} - -std::string Registration::extract_event_state( - const swss::KeyOpFieldsValuesTuple &kco) { - for (const auto &field_value : kfvFieldsValues(kco)) { - if (fvField(field_value) == "state") { - return fvValue(field_value); - } - } - return ""; -} - -/* void Registration::clear_all_init_apps() { - swss::Table table(&m_db, STATE_WARM_RESTART_INIT_TABLE_NAME); - std::vector keys; - table.getKeys(keys); - for (auto &key : keys) { - table.del(key); - } -} - -void Registration::save_all_init_apps() { - SWSS_LOG_ENTER(); - std::ostringstream stream; - std::copy(m_registered.begin(), m_registered.end(), - std::ostream_iterator(stream, ",")); - SWSS_LOG_NOTICE("Saving registered apps to init table: %s", - stream.str().c_str()); - - swss::Table table(&m_db, STATE_WARM_RESTART_INIT_TABLE_NAME); - std::string separator = swss::TableBase::getTableSeparator(m_db.getDbId()); - for (const auto &key : m_registered) { - if (is_valid_key(key, separator)) { - table.hset(key, "timestamp", swss::getTimestamp()); - } else { - SWSS_LOG_ERROR("skipping saving key = %s", key.c_str()); - } - } -} */ - -/* std::string Registration::join_pending_apps( - swss::WarmStart::WarmBootStage target_stage) { - std::ostringstream stream; - std::copy(m_remaining_apps.at(target_stage).begin(), - m_remaining_apps.at(target_stage).end(), - std::ostream_iterator(stream, ",")); - return stream.str(); -} */ - -InitRegistration::InitRegistration() - : m_db("STATE_DB", 0), - m_separator(swss::TableBase::getTableSeparator(m_db.getDbId())) {} - -void InitRegistration::fetch_init_app_info() { - m_missing_registrations.clear(); - - //swss::Table table(&m_db, STATE_WARM_RESTART_INIT_TABLE_NAME); - std::vector keys; - -// table.getKeys(keys); - for (auto &key : keys) { - if (!is_valid_key(key, m_separator)) { - SWSS_LOG_ERROR("Could not parse init app name from key = %s", - key.c_str()); - continue; - } - - m_missing_registrations.insert(key); - } -} - -InitRegistration::Status InitRegistration::get_reregistration_status() { - return m_missing_registrations.empty() - ? InitRegistration::Status::COMPLETED - : InitRegistration::Status::IN_PROGRESS; -} - -InitRegistration::Status InitRegistration::check_reregistration_status() { - SWSS_LOG_ENTER(); - - // swss::Table table(&m_db, STATE_WARM_RESTART_REGISTRATION_TABLE_NAME); - std::vector keys; - - // table.getKeys(keys); - for (auto &key : keys) { - remove_pending_app(key); - } - - return get_reregistration_status(); -} - -InitRegistration::Status InitRegistration::handle_registration_event( - const swss::KeyOpFieldsValuesTuple &kco) { - remove_pending_app(kfvKey(kco)); - return get_reregistration_status(); -} - -const InitRegistration::RegistrationSet &InitRegistration::get_pending_apps() - const { - return m_missing_registrations; -} - -void InitRegistration::remove_pending_app(const std::string &key) { - SWSS_LOG_ENTER(); - if (!is_valid_key(key, m_separator)) { - SWSS_LOG_ERROR("ignoring invalid key for reregistration = %s", key.c_str()); - return; - } - if (m_missing_registrations.find(key) != std::end(m_missing_registrations)) { - m_missing_registrations.erase(key); - } -} - -std::string InitRegistration::join_pending_apps() { - std::ostringstream stream; - std::copy(m_missing_registrations.begin(), m_missing_registrations.end(), - std::ostream_iterator(stream, ",")); - return stream.str(); -} - } // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/redis_utils.h b/src/sonic-framework/rebootbackend/redis_utils.h index 73e76eb321cf..05d87c2aef1c 100644 --- a/src/sonic-framework/rebootbackend/redis_utils.h +++ b/src/sonic-framework/rebootbackend/redis_utils.h @@ -16,17 +16,6 @@ namespace rebootbackend { std::string get_warm_start_state_name( const swss::WarmStart::WarmStartState state); -// Send Freeze, Checkpoint or Unfreeze notifications to all subscribed -// apps on NSF_MANAGER_COMMON_NOTIFICATION_CHANNEL -void send_nsf_manager_notification( - swss::DBConnector &db ); -// swss::WarmStart::WarmBootNotification notification); - -// For all keys in STATE_WARM_RESTART_TABLE_NAME: delete state field -// This is executed at the beginning of nsf/warm restart to clear out -// existing states. -// From: -// https://github.com/sonic-net/sonic-utilities/blob/20d1495b6f7e82c4d9aa377c3c281d8d0d9d8594/scripts/fast-reboot#L167 void init_warm_reboot_states(const swss::DBConnector &db); // Set the system warm start state to a new enabled/disabled state. @@ -34,15 +23,6 @@ void init_warm_reboot_states(const swss::DBConnector &db); // key = system, field = enable, value = "true"/"false" void set_warm_restart_enable(const swss::DBConnector &db, bool enabled); -// Send a request to state verifiation daemon to perform state -// verification. -// Set freeze == true if system is frozen (i.e. after reboot -// before reconciliation and unfreeze have occurred. -// timestamp is used to verify that a state update is a response -// to our request, and not someone else's. -std::string send_state_verification_notification(swss::DBConnector &db, - const bool freeze); - // Returns true if key is in the formm "texttext", and false // otherwise. bool is_valid_key(const std::string &key, const std::string &separator); @@ -57,234 +37,4 @@ bool get_docker_app_from_key(const std::string &key, const std::string &separator, std::string &docker, std::string &app); -std::string get_warm_start_state_name(swss::WarmStart::WarmStartState state); - -// Sets the warm restart count in the database. -void set_warm_restart_counter(swss::DBConnector &db, int count); - -// Returns the current warm restart count from the database. Returns an empty -// string if the warm restart count is not set, and a string representation -// of an integer otherwise. -std::string get_warm_restart_counter(swss::DBConnector &db); - -// This class is meant to handle registration information in the -// STATE_WARM_RESTART_REGISTRATION_TABLE_NAME. -// - we maintain the list of registered applications -// used after to reboot to wait for all to register -// - the list of apps we will wait to quiesce -// - the list of apps we will wait to checkpoint -// - the list of apps we will wait reconcile -// - the list of containers that have requested stop on freeze. -// Not thread safe. -class Registration { - public: - enum class Status { COMPLETED, FAILURE, IN_PROCESS }; - - struct Response { - Status status = Status::IN_PROCESS; - std::string error_string = ""; - }; - - typedef std::unordered_set RegistrationSet; - - Registration(); - - //static std::string get_warm_boot_stage_name( - // swss::WarmStart::WarmBootStage stage); - - // Populate this class with contents of - // STATE_WARM_RESTART_REGISTRATION_TABLE_NAME. - void fetch_registration_info(); - - // Return the set of containers that have requested stop on freeze. - RegistrationSet get_stop_on_freeze_set(); - - // Return the set of applications that have registered. - RegistrationSet get_registered_app_set(); - - // Check application states in warm restart table. - // Pop applications that are quiesced or checkpointed. - // Returns: - // IN_PROCESS: not all apps have quiesced. - // COMPLETED: all registered apps have quiesced. - // FAILURE: an application set its state to failed. - // error_string in response is populated - Response check_quiesced(); - - // Check application states in warm restart table. - // Pop applications that are checkpointed. - // Returns: - // IN_PROCESS: not all apps have checkpointed. - // COMPLETED: all registered apps have checkpointed. - // FAILURE: an application set its state to failed. - // error_string in response is populated - Response check_checkpointed(); - - // Check application states in warm restart table. - // Pop applications that are checkpointed. - // Returns: - // IN_PROCESS: not all apps have checkpointed. - // COMPLETED: all registered apps have checkpointed. - // FAILURE: an application set its state to failed. - // error_string in response is populated - Response check_reconciled(); - - // Check application states in warm restart table. - // Pop applications that are unfrozen. - // Returns: - // IN_PROCESS: not all apps have unfrozen. - // COMPLETED: all registered apps have unfrozen. - // FAILURE: an application set its state to failed. - // error_string in response is populated - Response check_unfrozen(); - - // Check application states in warm restart table. - // Pop applications that have reached the target state. - // Returns: - // IN_PROCESS: not all apps have reached the target state. - // COMPLETED: all registered apps have reached the target state. - // FAILURE: an application set its state to failed. - // error_string in response is populated - // Response check_stage(swss::WarmStart::WarmBootStage nsf_stage); - - // Handle an application state change, and update the tracked progress - // towards that state. - // Pop applications that have reached the monitored state. - // FAILURE statuses are sticky, and subsequent calls to handle_state_event - // will return the FAILURE status. - // Returns: - // IN_PROCESS: not all apps have reached monitored_stage. - // COMPLETED: all registered apps have monitored_stage. - // FAILURE: an application set its state to failed. - // error_string in response is populated - // Response handle_state_event(swss::WarmStart::WarmBootStage monitored_stage, - // const swss::KeyOpFieldsValuesTuple &kco); - - // Clear all registered app names in the WARM_RESTART_INIT_TABLE. - void clear_all_init_apps(); - - // Saves all registered app names to the WARM_RESTART_INIT_TABLE. - void save_all_init_apps(); - - // Returns a string representation of the current apps that have not - // reached the target state For debug and logging only. - //std::string join_pending_apps(swss::WarmStart::WarmBootStage target_stage); - - private: - // Helper function for check_ functions. - // Pop applications that have reached one of the target state names. - // Returns: - // IN_PROCESS: not all apps have reached the correct state. - // COMPLETED: all registered apps have reached the correct state. - // FAILURE: an application set its state to failed. - // error_string in response is populated - Response check_states_are(RegistrationSet &set_to_check, - const std::unordered_set &state_names); - - // Helper for handle_state_event: specific handling for FREZE stage. - // Pre-condition: caller verifies that operation is a set. - // caller handles apps entering FAILED state. - // Push applications that report a state other than quiescence/checkpointed. - // -- applications may exit/enter quiescence state. - // Returns: - // IN_PROCESS: not all apps have reached monitored_stage. - // COMPLETED: all registered apps have monitored_stage. - Response handle_quiescence_event(const swss::KeyOpFieldsValuesTuple &kco); - - // Filter a specified app list based on an application state change event. - // Pop applications that have reached one of the target states. - // IN_PROCESS: not all apps have reached the correct state. - // COMPLETED: all registered apps have reached the correct state. - // FAILURE: an application set its state to failed. - // error_string in response is populated - Response filter_app_list(RegistrationSet &set_to_filter, - const std::string app_name, -// const swss::WarmStart::WarmBootStage monitored_state, - const swss::KeyOpFieldsValuesTuple &kco, - const std::unordered_set &state_names); - - // Extracts a "status" field from the event, and returns the value of it. - // Returns an empty string if the "status" field is not present. - std::string extract_event_state(const swss::KeyOpFieldsValuesTuple &kco); - - // Clear contents of all sets. - void clear_contents(); - -// const static std::unordered_map> -// kStageToTargetStates; - - RegistrationSet m_registered; - RegistrationSet m_stop; - RegistrationSet m_ro_quiescent_list; -// std::unordered_map -// m_remaining_apps; - - swss::DBConnector m_db; - - std::string m_separator; - - friend class RebootThreadTest; - friend class RedisTest; -}; - -// This class handles the monitoring of applications re-registered warmboot -// requirements after a warmboot. In general, data from -// WARM_RESTART_INIT_TABLE is used to generate a list of apps that must -// re-register, and the provided API functions monitor -// WARM_RESTART_REGISTRATION_TABLE to determine if all of these apps -// have registered again. -class InitRegistration { - public: - enum class Status { COMPLETED, IN_PROGRESS }; - - typedef std::unordered_set RegistrationSet; - - InitRegistration(); - - // Reads the list of apps that must reregister from the - // WARM_RESTART_INIT_TABLE. - void fetch_init_app_info(); - - // Returns the current state of re-registration. - // Returns: - // COMPLETED: all apps that were registered before the warmboot have - // re-registered. This is a requirement for warmboot. - // IN_PROGRESS: not all apps have re-registered. - Status get_reregistration_status(); - - // Polls the WARM_RESTART_REGISTRATION_TABLE to retermine if re-registration - // is complete. Pops elements from the internal set. - // Returns: - // COMPLETED: all apps that were registered before the warmboot have - // re-registered. This is a requirement for warmboot. - // IN_PROGRESS: not all apps have re-registered. - Status check_reregistration_status(); - - // Handles an registration event in the WARM_RESTART_REGISTRATION_TABLE. Pops - // elements from the internal set, and returns the current re-registration - // status. - // Returns: - // COMPLETED: all apps that were registered before the warmboot have - // re-registered. This is a requirement for warmboot. - // IN_PROGRESS: not all apps have re-registered. - Status handle_registration_event(const swss::KeyOpFieldsValuesTuple &kco); - - const RegistrationSet &get_pending_apps() const; - - // Returns a string representation of the current apps that have not - // re-registered. For debug and logging only. - std::string join_pending_apps(); - - private: - // Pops the app name in key from the internal set, if it exists. - void remove_pending_app(const std::string &key); - - RegistrationSet m_missing_registrations; - swss::DBConnector m_db; - std::string m_separator; - - friend class RedisTest; -}; - } // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/telemetry_helper.cpp b/src/sonic-framework/rebootbackend/telemetry_helper.cpp deleted file mode 100644 index c4d9591c22bb..000000000000 --- a/src/sonic-framework/rebootbackend/telemetry_helper.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "telemetry_helper.h" - -#include -#include -#include - -#include "dbconnector.h" -#include "reboot_interfaces.h" -#include "redis_utils.h" -#include "table.h" -#include "warm_restart.h" - -namespace rebootbackend { - -TelemetryHelper::TelemetryHelper() - : m_db("STATE_DB", 0), - m_separator(swss::TableBase::getTableSeparator(m_db.getDbId())) {} - -void TelemetryHelper::record_overall_start() { - //clear_performance_table(); - - //swss::WarmStart::updateSystemWarmBootStart(); - - initialize_warmboot_count(); - //backup_overall_values(m_reboot_count); -} - -void TelemetryHelper::record_overall_end(bool success) { - //swss::WarmStart::updateSystemWarmBootEnd(success ? "success" : "failure"); - - //backup_overall_values(get_reboot_count()); -} - -/* void TelemetryHelper::record_stage_start( - swss::WarmStart::WarmBootStage nsf_stage) { - swss::WarmStart::updateWarmBootStageStart(nsf_stage); - - backup_stage_values(nsf_stage); -} */ - -/* void TelemetryHelper::record_stage_end(swss::WarmStart::WarmBootStage nsf_stage, - bool success) { - swss::WarmStart::updateWarmBootStageEnd(nsf_stage, - success ? "success" : "failure"); - - backup_stage_values(nsf_stage); -} */ - -// Called at start of an nsf reboot: at least one nsf reboot (the one in -// progress) has occurred -void TelemetryHelper::initialize_warmboot_count() { - std::string warmboot_counter_str = get_warm_restart_counter(m_db); - if (warmboot_counter_str.empty()) { - m_reboot_count = 1; - } - try { - m_reboot_count = std::stoi(warmboot_counter_str) + 1; - } catch (const std::logic_error &e) { - m_reboot_count = 1; - } - set_warm_restart_counter(m_db, m_reboot_count); - m_fetched_count = true; -} - -/* void TelemetryHelper::backup_overall_values(int count) { - swss::Table perf_table(&m_db, STATE_WARM_RESTART_PERF_TABLE_NAME); - std::vector values; - if (!perf_table.get("system", values)) { - return; - } - - swss::Table hist_table(&m_db, STATE_WARM_RESTART_PERF_HISTORY_TABLE_NAME); - hist_table.set(std::to_string(count) + m_separator + "system", values); -} */ - -/* void TelemetryHelper::backup_stage_values( - swss::WarmStart::WarmBootStage nsf_stage) { - std::string stage_name = - swss::WarmStart::warmBootStageToNameMap()->at(nsf_stage); - int count = get_reboot_count(); - - swss::Table perf_table(&m_db, STATE_WARM_RESTART_PERF_TABLE_NAME); - swss::Table hist_table(&m_db, STATE_WARM_RESTART_PERF_HISTORY_TABLE_NAME); - - std::vector perf_keys; - perf_table.getKeys(perf_keys); - for (const auto &key : perf_keys) { - if (key.rfind(stage_name, 0) == 0) { - std::vector values; - if (!perf_table.get(key, values)) { - continue; - } - - hist_table.set(std::to_string(count) + m_separator + key, values); - } - } -} */ - -int TelemetryHelper::get_reboot_count() { - if (!m_fetched_count) { - try { - m_reboot_count = std::stoi(get_warm_restart_counter(m_db)); - } catch (const std::logic_error &e) { - m_reboot_count = 0; - } - m_fetched_count = true; - } - return m_reboot_count; -} - -/*void TelemetryHelper::clear_performance_table() { - swss::Table perf_table(&m_db, STATE_WARM_RESTART_PERF_TABLE_NAME); - std::vector perf_keys; - perf_table.getKeys(perf_keys); - for (const auto &key : perf_keys) { - perf_table.del(key); - } -} */ - -} // namespace rebootbackend diff --git a/src/sonic-framework/rebootbackend/telemetry_helper.h b/src/sonic-framework/rebootbackend/telemetry_helper.h deleted file mode 100644 index 12de453a6ed7..000000000000 --- a/src/sonic-framework/rebootbackend/telemetry_helper.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "dbconnector.h" -#include "reboot_interfaces.h" -#include "warm_restart.h" - -namespace rebootbackend { - -class TelemetryHelper : public TelemetryInterface { - public: - TelemetryHelper(); - ~TelemetryHelper() override = default; - - void record_overall_start() override; - void record_overall_end(bool success) override; - -// void record_stage_start(swss::WarmStart::WarmBootStage nsf_stage) override; -// void record_stage_end(swss::WarmStart::WarmBootStage nsf_stage, -// bool success) override; - - private: - // Initialize the warmboot count in Redis for a new reboot. Sets the count to - // 0 if it is not populated, and increment the value otherwise. - void initialize_warmboot_count(); - - // Backup the performance entries for the overall NSF reboot from - // WARM_RESTART_PERFORMANCE_TABLE to WARM_RESTART_PERFORMANCE_HISTORY_TABLE. - void backup_overall_values(int count); - - // Backup the performance entries for a particular stage of the NSF reboot - // from WARM_RESTART_PERFORMANCE_TABLE to - // WARM_RESTART_PERFORMANCE_HISTORY_TABLE. - //void backup_stage_values(swss::WarmStart::WarmBootStage nsf_stage); - - // Fetch the reboot warmboot count value, or return the cached - // value for the appropriate value if it has already been fetched. - int get_reboot_count(); - - // Clears all keys from the performance table in preparation for a new reboot. - void clear_performance_table(); - - swss::DBConnector m_db; - std::string m_separator; - - bool m_fetched_count = false; - int m_reboot_count = 0; -}; - -} // namespace rebootbackend diff --git a/src/sonic-framework/tests/Makefile.am b/src/sonic-framework/tests/Makefile.am index a61aaadd4886..7ff27a79ca33 100644 --- a/src/sonic-framework/tests/Makefile.am +++ b/src/sonic-framework/tests/Makefile.am @@ -1,4 +1,5 @@ -INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/rebootbackend -I $(top_srcdir)/rebootbackend/system +AUTOMAKE_OPTIONS = subdir-objects +INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/rebootbackend -I $(top_srcdir)/rebootbackend/system -I ../../sonic-swss-common/common TESTS = tests tests_asan tests_tsan tests_usan @@ -18,23 +19,20 @@ CFLAGS_ASAN = -fsanitize=address CFLAGS_TSAN = -fsanitize=thread CFLAGS_USAN = -fsanitize=undefined +testsdir = /usr/include + +tests_HEADERS = /usr/include/gmock/gmock.h + tests_SOURCES = test_utils_common.cpp \ - $(top_srcdir)/rebootbackend/telemetry_helper.cpp \ - telemetry_helper_test.cpp \ - rebootbe_test.cpp \ + rebootbe_test.cpp \ $(top_srcdir)/rebootbackend/rebootbe.cpp \ reboot_thread_test.cpp \ $(top_srcdir)/rebootbackend/reboot_thread.cpp \ - init_thread_test.cpp \ - $(top_srcdir)/rebootbackend/init_thread.cpp \ $(top_srcdir)/rebootbackend/system/system.pb.cc \ $(top_srcdir)/rebootbackend/types/types.pb.cc \ $(top_srcdir)/rebootbackend/common/common.pb.cc \ - $(top_srcdir)/rebootbackend/container_stop.pb.cc \ redis_utils_test.cpp \ $(top_srcdir)/rebootbackend/redis_utils.cpp \ - reboot_common_test.cpp \ - $(top_srcdir)/rebootbackend/reboot_common.cpp \ test_main.cpp tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_COVERAGE) $(CFLAGS_SAI) diff --git a/src/sonic-framework/tests/init_thread_test.cpp b/src/sonic-framework/tests/init_thread_test.cpp index 482170b76d6b..208fecee9550 100644 --- a/src/sonic-framework/tests/init_thread_test.cpp +++ b/src/sonic-framework/tests/init_thread_test.cpp @@ -19,12 +19,9 @@ #include "table.h" #include "test_utils_common.h" #include "timestamp.h" -#include "warm_restart.h" namespace rebootbackend { -using WarmBootStage = ::swss::WarmStart::WarmBootStage; - using ::testing::_; using ::testing::AtLeast; using ::testing::ExplainMatchResult; @@ -48,10 +45,6 @@ MATCHER(IsDoneStatus, "") { << status.detailed_thread_status; return false; } - if (status.thread_state.method() != gnoi::system::RebootMethod::NSF) { - *result_listener << "Proto method was not NSF: " - << status.thread_state.status().status(); - } if (status.thread_state.status().status() != gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS) { *result_listener << "Proto status was not SUCCESS: " @@ -88,10 +81,6 @@ MATCHER_P(IsErrorStatus, error_condition_matcher, "") { << status.detailed_thread_status; return false; } - if (status.thread_state.method() != gnoi::system::RebootMethod::NSF) { - *result_listener << "Proto method was not NSF: " - << status.thread_state.status().status(); - } if (status.thread_state.status().status() != gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE) { *result_listener << "Proto status was not FAILURE: " @@ -109,80 +98,16 @@ class InitThreadTest : public ::testing::Test { : m_db("STATE_DB", 0), m_config_db("CONFIG_DB", 0), m_critical_interface(), - m_nsf_channel(&m_db, swss::WarmStart::kNsfManagerNotificationChannel), m_init_thread(m_critical_interface, m_telemetry, m_finished, m_stack_unfrozen) { - swss::WarmStart::initialize("fake_app", "fake_docker"); // sigterm_requested and the Redis tables have global state that is // maintained across tests. sigterm_requested = false; TestUtils::clear_tables(m_db); init_redis_defaults(); - overwrite_reconciliation_timeout(5); - } - - void init_redis_defaults() { - set_warm_restart_enable(m_db, true); - TestUtils::set_state_verification_enable(m_config_db, /*bootup=*/true, - /*enabled=*/true); - } - - void set_default_success_expects() { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_telemetry, record_overall_end(true)).Times(1); - } - - void check_final_success_expects(bool state_verification_enabled) { - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); - if (state_verification_enabled) { - check_nsf_manager_notification_sent( - swss::WarmStart::WarmBootNotification::kUnfreeze); - } - } - - void check_final_failure_expects() { - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); - } - - void check_nsf_manager_notification_sent( - swss::WarmStart::WarmBootNotification notification_type) { - swss::Select s; - s.addSelectable(&m_nsf_channel); - - swss::Selectable *sel; - int select_result = s.select(&sel, 2000); - EXPECT_EQ(select_result, swss::Select::OBJECT); - - if (sel == &m_nsf_channel) { - std::string op, data; - std::vector values; - m_nsf_channel.pop(op, data, values); - EXPECT_EQ(op, swss::WarmStart::warmBootNotificationNameMap()->at( - notification_type)); - } - } - - void set_telemetry_stage_expects(WarmBootStage nsf_stage, bool success) { - EXPECT_CALL(m_telemetry, record_stage_start(nsf_stage)).Times(1); - EXPECT_CALL(m_telemetry, record_stage_end(nsf_stage, success)).Times(1); - } - - void overwrite_reconciliation_timeout(uint32_t timeout_seconds) { - m_init_thread.m_reconciliation_timeout = timeout_seconds; - } - - void overwrite_state_verification_timeout(uint32_t timeout_seconds) { - m_init_thread.m_state_verification_timeout = timeout_seconds; - } - - void overwrite_unfreeze_timeout(uint32_t timeout_seconds) { - m_init_thread.m_unfreeze_timeout = timeout_seconds; } void populate_default_init_table() { - swss::Table initTable(&m_db, STATE_WARM_RESTART_INIT_TABLE_NAME); initTable.hset("docker1|app1", "timestamp", ""); initTable.hset("docker2|app2", "timestamp", ""); initTable.hset("docker3|app3", "timestamp", ""); @@ -206,56 +131,6 @@ class InitThreadTest : public ::testing::Test { TestUtils::populate_restart_table_state(m_db, "app3", state); } - void advance_through_reconciliation() { - EXPECT_CALL(m_telemetry, - record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/true)) - .Times(1); - advance_through_registration(); - set_apps_to_state("reconciled"); - } - - // Must be run in a separate thread. - void advance_through_state_verification() { - swss::NotificationConsumer nc(&m_db, STATE_VERIFICATION_REQ_CHANNEL); - - advance_through_reconciliation(); - - std::string timestamp = TestUtils::wait_for_state_verification_trigger( - nc, kSelectTimeoutSeconds, /*freeze=*/true); - EXPECT_THAT(timestamp, Not(IsEmpty())); - - if (timestamp.empty()) { - return; - } - - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_PASS, - timestamp); - } - - // Must be run in a separate thread. - void advance_through_unfreeze_with_state(std::string final_state) { - set_telemetry_stage_expects(WarmBootStage::STAGE_UNFREEZE, - final_state == "completed"); - - swss::NotificationConsumer nc(&m_db, STATE_VERIFICATION_REQ_CHANNEL); - - advance_through_reconciliation(); - - std::string timestamp = TestUtils::wait_for_state_verification_trigger( - nc, kSelectTimeoutSeconds, /*freeze=*/true); - EXPECT_THAT(timestamp, Not(IsEmpty())); - if (timestamp.empty()) { - return; - } - - // Set apps to their final state before unfreeze runs. - set_apps_to_state(final_state); - - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_PASS, - timestamp); - } - protected: swss::DBConnector m_db; swss::DBConnector m_config_db; @@ -271,653 +146,9 @@ TEST_F(InitThreadTest, TestJoinWithoutStart) { EXPECT_FALSE(m_init_thread.Join()); } -TEST_F(InitThreadTest, NoNsfIfCritical) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(true)); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - EXPECT_EQ(m_init_thread.Start(), - swss::StatusCode::SWSS_RC_FAILED_PRECONDITION); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::DETECTED_CRITICAL_STATE)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, RegistrationCancelsForCritical) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(2)) - .WillOnce(Return(false)) - .WillRepeatedly(Return(true)); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - populate_default_init_table(); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - m_init_thread.Join(); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::REGISTRATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, SigtermRequestedBeforeRun) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - populate_default_init_table(); - sigterm_requested = true; - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - m_init_thread.Join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), IsErrorStatus(_)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, RegistrationStopped) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - populate_default_init_table(); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - // This will stop the thread in the registration loop. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - m_init_thread.Stop(); - m_init_thread.Join(); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::REGISTRATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, RegistrationTimeout) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - populate_default_init_table(); - overwrite_reconciliation_timeout(1); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - m_init_thread.Join(); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::REGISTRATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, ReconciliationStopped) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - EXPECT_CALL(m_telemetry, record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/false)) - .Times(1); - - advance_through_registration(); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - // Registration is done, so this will stop the thread in the reconciliation - // loop. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - m_init_thread.Stop(); - m_init_thread.Join(); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::RECONCILIATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, ReconciliationCritical) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(3)) - .WillOnce(Return(false)) - .WillOnce(Return(false)) - .WillRepeatedly(Return(true)); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - EXPECT_CALL(m_telemetry, record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/false)) - .Times(1); - - advance_through_registration(); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - m_init_thread.Join(); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::RECONCILIATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, ReconciliationTimeout) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - EXPECT_CALL(m_telemetry, record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/false)) - .Times(1); - - advance_through_registration(); - - overwrite_reconciliation_timeout(1); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - m_init_thread.Join(); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::RECONCILIATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, ReconciliationAlreadyFailed) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - EXPECT_CALL(m_telemetry, record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/false)) - .Times(1); - - advance_through_registration(); - TestUtils::populate_restart_table_state(m_db, "app1", "failed"); - - swss::Select s; - s.addSelectable(&m_finished); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - m_init_thread.Join(); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::RECONCILIATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, ReconciliationAlreadyDone) { - TestUtils::set_state_verification_enable(m_config_db, /*bootup=*/true, - /*enabled=*/false); - set_default_success_expects(); - EXPECT_CALL(m_telemetry, record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/true)) - .Times(1); - - advance_through_registration(); - TestUtils::populate_restart_table_state(m_db, "app1", "reconciled"); - TestUtils::populate_restart_table_state(m_db, "app2", "reconciled"); - TestUtils::populate_restart_table_state(m_db, "app3", "reconciled"); - - swss::Select s; - s.addSelectable(&m_finished); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - TestUtils::wait_for_finish(s, m_finished, kSelectTimeoutSeconds); - m_init_thread.Join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), IsDoneStatus()); - check_final_success_expects(/*state_verification_enabled=*/false); -} - -TEST_F(InitThreadTest, ReconciliationFails) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - EXPECT_CALL(m_telemetry, record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/false)) - .Times(1); - - advance_through_registration(); - - // Apps register one-by-one. - auto test_sequence = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_restart_table_state(m_db, "app1", "failed"); - }; - std::thread test_thread = std::thread(test_sequence); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - swss::Select s; - s.addSelectable(&m_finished); - TestUtils::wait_for_finish(s, m_finished, kSelectTimeoutSeconds); - m_init_thread.Join(); - - test_thread.join(); - - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::RECONCILIATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, StateVerificationStopped) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - advance_through_reconciliation(); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - // Registration and reconciliation are done, so this will stop the thread in - // the state verification loop. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - m_init_thread.Stop(); - m_init_thread.Join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), - IsErrorStatus( - InitThreadStatus::ErrorCondition::STATE_VERIFICATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, StateVerificationCritical) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(4)) - .WillOnce(Return(false)) - .WillOnce(Return(false)) - .WillOnce(Return(false)) - .WillRepeatedly(Return(true)); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - advance_through_reconciliation(); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - m_init_thread.Join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), - IsErrorStatus( - InitThreadStatus::ErrorCondition::STATE_VERIFICATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, StateVerificationFails) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_critical_state(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - advance_through_reconciliation(); - - overwrite_state_verification_timeout(1); - - std::string timestamp; - auto test_sequence = [&] { - swss::NotificationConsumer nc(&m_db, STATE_VERIFICATION_REQ_CHANNEL); - timestamp = TestUtils::wait_for_state_verification_trigger( - nc, kSelectTimeoutSeconds, /*freeze=*/true); - - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_FAIL, - timestamp); - }; - std::thread test_thread = std::thread(test_sequence); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - m_init_thread.Join(); - - test_thread.join(); - - EXPECT_THAT(timestamp, Not(IsEmpty())); - EXPECT_THAT(m_init_thread.GetDetailedStatus(), - IsErrorStatus( - InitThreadStatus::ErrorCondition::STATE_VERIFICATION_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, UnfreezeStopped) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_minor_alarm(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - set_telemetry_stage_expects(WarmBootStage::STAGE_UNFREEZE, - /*success=*/false); - - swss::Select s; - s.addSelectable(&m_stack_unfrozen); - std::thread test_thread = - std::thread(&InitThreadTest::advance_through_state_verification, this); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - TestUtils::wait_for_finish(s, m_stack_unfrozen, kSelectTimeoutSeconds); - // Registration, reconciliation, and state verification are done, so this - // will stop the thread in the unfreeze loop. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - m_init_thread.Stop(); - m_init_thread.Join(); - - test_thread.join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::UNFREEZE_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, UnfreezeCritical) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(5)) - .WillOnce(Return(false)) - .WillOnce(Return(false)) - .WillOnce(Return(false)) - .WillOnce(Return(false)) - .WillRepeatedly(Return(true)); - EXPECT_CALL(m_critical_interface, report_minor_alarm(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - set_telemetry_stage_expects(WarmBootStage::STAGE_UNFREEZE, - /*success=*/false); - - swss::Select s; - s.addSelectable(&m_stack_unfrozen); - std::thread test_thread = - std::thread(&InitThreadTest::advance_through_state_verification, this); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - TestUtils::wait_for_finish(s, m_stack_unfrozen, kSelectTimeoutSeconds); - m_init_thread.Join(); - - test_thread.join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::UNFREEZE_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, UnfreezeTimeout) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_minor_alarm(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - set_telemetry_stage_expects(WarmBootStage::STAGE_UNFREEZE, - /*success=*/false); - - swss::Select s; - s.addSelectable(&m_stack_unfrozen); - std::thread test_thread = - std::thread(&InitThreadTest::advance_through_state_verification, this); - - overwrite_unfreeze_timeout(1); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - TestUtils::wait_for_finish(s, m_stack_unfrozen, kSelectTimeoutSeconds); - m_init_thread.Join(); - - test_thread.join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::UNFREEZE_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, UnfreezeAlreadyFailed) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_minor_alarm(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(false)).Times(1); - - swss::Select s; - s.addSelectable(&m_stack_unfrozen); - std::thread test_thread = std::thread( - &InitThreadTest::advance_through_unfreeze_with_state, this, "failed"); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - TestUtils::wait_for_finish(s, m_stack_unfrozen, kSelectTimeoutSeconds); - m_init_thread.Join(); - - test_thread.join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), - IsErrorStatus(InitThreadStatus::ErrorCondition::UNFREEZE_FAILED)); - check_final_failure_expects(); -} - -TEST_F(InitThreadTest, UnfreezeAlreadyDone) { - set_default_success_expects(); - - swss::Select s; - s.addSelectable(&m_stack_unfrozen); - std::thread test_thread = std::thread( - &InitThreadTest::advance_through_unfreeze_with_state, this, "completed"); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - TestUtils::wait_for_finish(s, m_stack_unfrozen, kSelectTimeoutSeconds); - m_init_thread.Join(); - - test_thread.join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), IsDoneStatus()); - check_final_success_expects(/*state_verification_enabled=*/true); -} - class InitThreadTestWithSvResult : public InitThreadTest, public testing::WithParamInterface {}; -TEST_P(InitThreadTestWithSvResult, FullPassWorks) { - set_default_success_expects(); - if (GetParam() == SV_NOT_RUN) { - EXPECT_CALL(m_critical_interface, report_minor_alarm(_)).Times(1); - } - EXPECT_CALL(m_telemetry, record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/true)) - .Times(1); - set_telemetry_stage_expects(WarmBootStage::STAGE_UNFREEZE, - /*success=*/true); - - populate_default_init_table(); - - // Apps register one-by-one. - auto test_sequence = [&] { - // Registration step. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_THAT(m_init_thread.GetDetailedStatus(), - IsActiveStatus( - InitThreadStatus::ThreadStatus::WAITING_FOR_REGISTRATION)); - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - true, true); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - true, true); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, true, - true, true); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - - // Reconciliation step. - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsActiveStatus( - InitThreadStatus::ThreadStatus::WAITING_FOR_RECONCILIATION)); - TestUtils::populate_restart_table_state(m_db, "app1", "reconciled"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_restart_table_state(m_db, "app2", "reconciled"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - // Start listening for the verfication request just before completing - // reconciliation. - swss::NotificationConsumer nc(&m_db, STATE_VERIFICATION_REQ_CHANNEL); - TestUtils::populate_restart_table_state(m_db, "app3", "reconciled"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - - // State verification step. - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsActiveStatus( - InitThreadStatus::ThreadStatus::WAITING_FOR_STATE_VERIFICATION)); - std::string timestamp = TestUtils::wait_for_state_verification_trigger( - nc, kSelectTimeoutSeconds, /*freeze=*/true); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, GetParam(), - "wrong_timestamp"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::write_state_verification_result(m_db, "fake_component", - GetParam(), "timestamp"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - swss::Select unfreeze_select; - unfreeze_select.addSelectable(&m_stack_unfrozen); - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, GetParam(), - timestamp); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - - // Unfreeze step. - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsActiveStatus(InitThreadStatus::ThreadStatus::WAITING_FOR_UNFREEZE)); - TestUtils::wait_for_finish(unfreeze_select, m_stack_unfrozen, - kSelectTimeoutSeconds); - TestUtils::populate_restart_table_state(m_db, "app1", "completed"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_restart_table_state(m_db, "app2", "completed"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_restart_table_state(m_db, "app3", "completed"); - }; - std::thread test_thread = std::thread(test_sequence); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - - swss::Select s; - s.addSelectable(&m_finished); - TestUtils::wait_for_finish(s, m_finished, kSelectTimeoutSeconds); - - test_thread.join(); - m_init_thread.Join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), IsDoneStatus()); - check_final_success_expects(/*state_verification_enabled=*/true); -} - -INSTANTIATE_TEST_SUITE_P(FullPassSuite, InitThreadTestWithSvResult, - testing::Values(SV_PASS, SV_NOT_RUN)); - -TEST_F(InitThreadTest, StateVerificationTimeoutIsSuccess) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); - EXPECT_CALL(m_critical_interface, report_minor_alarm(_)).Times(1); - EXPECT_CALL(m_telemetry, record_overall_end(true)).Times(1); - - advance_through_reconciliation(); - set_telemetry_stage_expects(WarmBootStage::STAGE_UNFREEZE, - /*success=*/true); - - overwrite_state_verification_timeout(1); - - std::string timestamp; - auto test_sequence = [&] { - swss::Select unfreeze_select; - unfreeze_select.addSelectable(&m_stack_unfrozen); - - // State verification step. State Verification daemon reports no results - // and times out. - swss::NotificationConsumer nc(&m_db, STATE_VERIFICATION_REQ_CHANNEL); - timestamp = TestUtils::wait_for_state_verification_trigger( - nc, kSelectTimeoutSeconds, /*freeze=*/true); - - // Unfreeze step. - TestUtils::wait_for_finish(unfreeze_select, m_stack_unfrozen, - kSelectTimeoutSeconds); - EXPECT_THAT( - m_init_thread.GetDetailedStatus(), - IsActiveStatus(InitThreadStatus::ThreadStatus::WAITING_FOR_UNFREEZE)); - TestUtils::populate_restart_table_state(m_db, "app1", "completed"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_restart_table_state(m_db, "app2", "completed"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_restart_table_state(m_db, "app3", "completed"); - }; - std::thread test_thread = std::thread(test_sequence); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - - swss::Select s; - s.addSelectable(&m_finished); - TestUtils::wait_for_finish(s, m_finished, kSelectTimeoutSeconds); - - test_thread.join(); - m_init_thread.Join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), IsDoneStatus()); - check_final_success_expects(/*state_verification_enabled=*/true); -} - -TEST_F(InitThreadTest, FullPassNoStateVerification) { - TestUtils::set_state_verification_enable(m_config_db, /*bootup=*/true, - /*enabled=*/false); - - set_default_success_expects(); - EXPECT_CALL(m_telemetry, record_stage_end(WarmBootStage::STAGE_RECONCILIATION, - /*success=*/true)) - .Times(1); - - populate_default_init_table(); - - // Apps register one-by-one. - auto test_sequence = [&] { - // Registration step. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - true, true); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - true, true); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, true, - true, true); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - - // Reconciliation step. - TestUtils::populate_restart_table_state(m_db, "app1", "reconciled"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - TestUtils::populate_restart_table_state(m_db, "app2", "reconciled"); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - // Start listening for the verfication request just before completing - // reconciliation. - swss::Select unfreeze_select; - unfreeze_select.addSelectable(&m_stack_unfrozen); - swss::NotificationConsumer nc(&m_db, STATE_VERIFICATION_REQ_CHANNEL); - TestUtils::populate_restart_table_state(m_db, "app3", "reconciled"); - - // No state verification signal. - TestUtils::confirm_no_state_verification_trigger( - nc, kShortSelectTimeoutSeconds); - }; - std::thread test_thread = std::thread(test_sequence); - - EXPECT_EQ(m_init_thread.Start(), swss::StatusCode::SWSS_RC_SUCCESS); - swss::Select s; - s.addSelectable(&m_finished); - TestUtils::wait_for_finish(s, m_finished, kSelectTimeoutSeconds); - - m_init_thread.Join(); - test_thread.join(); - - EXPECT_THAT(m_init_thread.GetDetailedStatus(), IsDoneStatus()); - check_final_success_expects(/*state_verification_enabled=*/false); -} } // namespace rebootbackend diff --git a/src/sonic-framework/tests/mock_reboot_interfaces.h b/src/sonic-framework/tests/mock_reboot_interfaces.h index 58a34792cff2..37b7492db371 100644 --- a/src/sonic-framework/tests/mock_reboot_interfaces.h +++ b/src/sonic-framework/tests/mock_reboot_interfaces.h @@ -1,7 +1,6 @@ #pragma once #include -#include "init_thread.h" #include "reboot_interfaces.h" #include "selectableevent.h" #include "system/system.pb.h" @@ -14,36 +13,12 @@ class MockDbusInterface : public DbusInterface { (override)); MOCK_METHOD(DbusInterface::DbusResponse, RebootStatus, (const std::string &), (override)); - MOCK_METHOD(DbusInterface::DbusResponse, StopContainers, (const std::string&), - (override)); - MOCK_METHOD(DbusInterface::DbusResponse, StopContainerStatus, - (const std::string&), (override)); -}; - -class MockCriticalStateInterface : public CriticalStateInterface { - public: - MOCK_METHOD(bool, is_system_critical, (), (override)); - MOCK_METHOD(void, report_minor_alarm, (const std::string &), (override)); - MOCK_METHOD(void, report_critical_state, (const std::string &), (override)); -}; - -class MockTelemetryInterface : public TelemetryInterface { - public: - ~MockTelemetryInterface() override = default; - - MOCK_METHOD(void, record_overall_start, (), (override)); - MOCK_METHOD(void, record_overall_end, (bool success), (override)); - MOCK_METHOD(void, record_stage_start, - (swss::WarmStart::WarmBootStage nsf_stage), (override)); - MOCK_METHOD(void, record_stage_end, - (swss::WarmStart::WarmBootStage nsf_stage, bool success), - (override)); }; -class MockInitThread : public InitThread { +/*class MockInitThread : public InitThread { public: MockInitThread() - : InitThread(m_unused_critical_state, m_unused_telemetry, m_unused_event, + : InitThread(m_unused_event, m_unused_event) {} MOCK_METHOD(swss::StatusCode, Start, (), (override)); @@ -54,9 +29,7 @@ class MockInitThread : public InitThread { (override)); private: - MockCriticalStateInterface m_unused_critical_state; - MockTelemetryInterface m_unused_telemetry; swss::SelectableEvent m_unused_event; -}; +};*/ -} // namespace rebootbackend \ No newline at end of file +} // namespace rebootbackend diff --git a/src/sonic-framework/tests/reboot_thread_test.cpp b/src/sonic-framework/tests/reboot_thread_test.cpp index 1bdfa4ea6c88..35778ff864a1 100644 --- a/src/sonic-framework/tests/reboot_thread_test.cpp +++ b/src/sonic-framework/tests/reboot_thread_test.cpp @@ -9,19 +9,16 @@ #include #include -#include "container_stop.pb.h" #include "mock_reboot_interfaces.h" #include "reboot_common.h" #include "reboot_interfaces.h" #include "redis_utils.h" #include "select.h" #include "selectableevent.h" -#include "stateverification.h" #include "status_code_util.h" #include "system/system.pb.h" #include "test_utils_common.h" #include "timestamp.h" -#include "warm_restart.h" namespace rebootbackend { @@ -29,7 +26,6 @@ namespace rebootbackend { using namespace gnoi::system; namespace gpu = ::google::protobuf::util; -using WarmStartState = ::swss::WarmStart::WarmStartState; using Progress = ::rebootbackend::RebootThread::Progress; using RebootThread = ::rebootbackend::RebootThread; using ::testing::_; @@ -64,48 +60,6 @@ TEST_F(RebootStatusTest, TestInit) { EXPECT_FALSE(m_status.get_active()); } -TEST_F(RebootStatusTest, TestStartStatus) { - m_status.set_start_status(RebootMethod::NSF, "reboot because"); - - RebootStatusResponse response = m_status.get_response(); - - EXPECT_TRUE(response.active()); - EXPECT_THAT(response.reason(), StrEq("reboot because")); - EXPECT_EQ(response.count(), 1); - EXPECT_EQ(response.method(), RebootMethod::NSF); - EXPECT_THAT(response.status().message(), StrEq("")); - - EXPECT_TRUE(m_status.get_active()); -} - -TEST_F(RebootStatusTest, TestSets) { - m_status.set_start_status(RebootMethod::NSF, "reboot because"); - - RebootStatus_Status reboot_status = m_status.get_last_reboot_status(); - EXPECT_EQ(reboot_status, - RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN); - - m_status.set_completed_status( - RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, "timeout"); - - // Have to be inactive to read the status - m_status.set_inactive(); - EXPECT_FALSE(m_status.get_active()); - - RebootStatusResponse response = m_status.get_response(); - EXPECT_THAT(response.status().message(), StrEq("timeout")); - EXPECT_EQ(response.status().status(), - RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE); - - // Can't set message status while inactive - m_status.set_completed_status( - RebootStatus_Status::RebootStatus_Status_STATUS_RETRIABLE_FAILURE, - "anything"); - response = m_status.get_response(); - EXPECT_THAT(response.status().message(), StrEq("timeout")); - EXPECT_EQ(response.status().status(), - RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE); -} TEST_F(RebootStatusTest, TestGetStatus) { std::chrono::nanoseconds curr_ns = std::chrono::high_resolution_clock::now().time_since_epoch(); @@ -139,13 +93,11 @@ class RebootThreadTest : public ::testing::Test { protected: RebootThreadTest() : m_dbus_interface(), - m_critical_interface(), m_db("STATE_DB", 0), m_config_db("CONFIG_DB", 0), - m_reboot_thread(m_dbus_interface, m_critical_interface, m_telemetry, + m_reboot_thread(m_dbus_interface, m_finished) { swss::WarmStart::initialize("app1", "docker1"); - TestUtils::clear_tables(m_db); sigterm_requested = false; } @@ -153,22 +105,6 @@ class RebootThreadTest : public ::testing::Test { m_reboot_thread.m_reboot_timeout = timeout_seconds; } - void overwrite_state_verification_timeout(uint32_t timeout_seconds) { - m_reboot_thread.m_state_verification_timeout = timeout_seconds; - } - - void overwrite_quiescence_timeout_ms(uint32_t timeout_ms) { - m_reboot_thread.m_quiescence_timeout_ms = timeout_ms; - } - - void overwrite_quiescence_hold_time_ms(uint32_t timeout_ms) { - m_reboot_thread.m_quiescence_hold_time_ms = timeout_ms; - } - - void overwrite_checkpoint_timeout(uint32_t timeout_seconds) { - m_reboot_thread.m_checkpoint_timeout = timeout_seconds; - } - RebootStatusResponse get_response(void) { return m_reboot_thread.m_status.get_response(); } @@ -192,85 +128,6 @@ class RebootThreadTest : public ::testing::Test { return m_reboot_thread.wait_for_platform_reboot(s); } - Progress perform_state_verification(swss::Select &s) { - return m_reboot_thread.perform_state_verification(s); - } - - Progress perform_state_verification_select(swss::Select &s, - swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub, - std::string ×tamp) { - return m_reboot_thread.state_verification_select(s, l_timer, sub, - timestamp); - } - - RebootThread::Status handle_state_verification_event( - swss::SubscriberStateTable &sub, std::string ×tamp) { - return m_reboot_thread.handle_state_verification_event(sub, timestamp); - } - - // stop: set to true if calling m_reboot_thread.Stop() is desired. - // timeout_ms: replaces m_quiescence_timout_ms if > 0 - Progress perform_freeze_quiescence_w_stop(bool stop, int timeout_ms = -1) { - timespec l_timespec; - if (timeout_ms >= 0) { - l_timespec = milliseconds_to_timespec(timeout_ms); - } else { - l_timespec = - milliseconds_to_timespec(m_reboot_thread.m_quiescence_timeout_ms); - } - - swss::SelectableTimer l_timer(l_timespec); - - swss::Select s; - s.addSelectable(&l_timer); - l_timer.start(); - s.addSelectable(&(return_m_stop_reference())); - - if (stop) { - m_reboot_thread.Stop(); - } - return m_reboot_thread.perform_freeze_quiescence(s, l_timer); - } - - Progress checkpoint_stage_two(swss::Select &s, swss::SelectableTimer &l_timer, - swss::SubscriberStateTable &sub) { - return m_reboot_thread.checkpoint_stage_two(s, l_timer, sub); - } - - Progress perform_checkpoint(swss::Select &s) { - return m_reboot_thread.perform_checkpoint(s); - } - - RebootThread::Status check_container_stop(const std::string &request_id) { - return m_reboot_thread.check_container_stop(request_id); - } - - Progress wait_for_container_stop(int timeout_ms = -1) { - timespec l_timespec; - if (timeout_ms >= 0) { - l_timespec = milliseconds_to_timespec(timeout_ms); - } else { - l_timespec = - milliseconds_to_timespec(m_reboot_thread.m_quiescence_timeout_ms); - } - - swss::SelectableTimer l_timer(l_timespec); - - swss::Select s; - s.addSelectable(&l_timer); - l_timer.start(); - s.addSelectable(&(return_m_stop_reference())); - - m_reboot_thread.Stop(); - - return m_reboot_thread.wait_for_container_stop(s, "reqA", l_timer); - } - - void fetch_registration_info() { - m_reboot_thread.m_registration.fetch_registration_info(); - } - swss::SelectableEvent &return_m_stop_reference() { return m_reboot_thread.m_stop; } @@ -278,8 +135,6 @@ class RebootThreadTest : public ::testing::Test { swss::DBConnector m_db; swss::DBConnector m_config_db; NiceMock m_dbus_interface; - NiceMock m_critical_interface; - StrictMock m_telemetry; swss::SelectableEvent m_finished; RebootThread m_reboot_thread; }; @@ -293,12 +148,6 @@ TEST_F(RebootThreadTest, TestStop) { .Times(1) .WillOnce(Return(DbusInterface::DbusResponse{ DbusInterface::DbusStatus::DBUS_SUCCESS, ""})); - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - EXPECT_CALL(m_critical_interface, - report_critical_state("platform failed to reboot")) - .Times(0); RebootRequest request; request.set_method(RebootMethod::COLD); overwrite_reboot_timeout(2); @@ -309,6 +158,7 @@ TEST_F(RebootThreadTest, TestStop) { EXPECT_THAT( response, IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); +// EXPECT_THAT(response.status().message(), StrEq("platform failed to reboot")); } TEST_F(RebootThreadTest, TestCleanExit) { @@ -316,12 +166,7 @@ TEST_F(RebootThreadTest, TestCleanExit) { .Times(1) .WillOnce(Return(DbusInterface::DbusResponse{ DbusInterface::DbusStatus::DBUS_SUCCESS, ""})); - EXPECT_CALL(m_critical_interface, - report_critical_state(("platform failed to reboot"))) - .Times(1); - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); + overwrite_reboot_timeout(1); swss::Select s; @@ -333,6 +178,7 @@ TEST_F(RebootThreadTest, TestCleanExit) { m_reboot_thread.Start(request); TestUtils::wait_for_finish(s, m_finished, 5); + // Status should be active until we call join RebootStatusResponse response = get_response(); EXPECT_TRUE(response.active()); @@ -354,17 +200,12 @@ TEST_F(RebootThreadTest, TestJoinWithoutStart) { } // Call Start a second time while first thread is still executing. -TEST_F(RebootThreadTest, TestStartWhileRunning) { + TEST_F(RebootThreadTest, TestStartWhileRunning) { EXPECT_CALL(m_dbus_interface, Reboot(_)) .Times(1) .WillOnce(Return(DbusInterface::DbusResponse{ DbusInterface::DbusStatus::DBUS_SUCCESS, ""})); - EXPECT_CALL(m_critical_interface, - report_critical_state("platform failed to reboot")) - .Times(1); - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); + overwrite_reboot_timeout(2); RebootRequest request; @@ -380,22 +221,17 @@ TEST_F(RebootThreadTest, TestStartWhileRunning) { bool ret = m_reboot_thread.Join(); EXPECT_TRUE(ret); -} +} // Call Start a second time after first thread completed // but before first thread was joined. // Second start should fail. -TEST_F(RebootThreadTest, TestStartWithoutJoin) { + TEST_F(RebootThreadTest, TestStartWithoutJoin) { EXPECT_CALL(m_dbus_interface, Reboot(_)) .Times(1) .WillOnce(Return(DbusInterface::DbusResponse{ DbusInterface::DbusStatus::DBUS_SUCCESS, ""})); - EXPECT_CALL(m_critical_interface, - report_critical_state("platform failed to reboot")) - .Times(1); - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); + overwrite_reboot_timeout(1); swss::Select s; @@ -415,7 +251,7 @@ TEST_F(RebootThreadTest, TestStartWithoutJoin) { // This should join the first start. bool ret = m_reboot_thread.Join(); EXPECT_TRUE(ret); -} +} TEST_F(RebootThreadTest, TestUnsupportedRebootType) { RebootRequest request; @@ -427,60 +263,6 @@ TEST_F(RebootThreadTest, TestUnsupportedRebootType) { "RebootThread: Start rx'd unsupported method"); } -TEST_F(RebootThreadTest, TestDelayedStartUnsupported) { - RebootRequest request; - request.set_method(RebootMethod::NSF); - request.set_delay(1); - - NotificationResponse response = m_reboot_thread.Start(request); - EXPECT_EQ(response.status, swss::StatusCode::SWSS_RC_INVALID_PARAM); - EXPECT_THAT(response.json_string, - StrEq("RebootThread: delayed start not supported")); -} - -TEST_F(RebootThreadTest, TestNoNSFIfNonRetriableFailure) { - set_start_status(RebootMethod::NSF, "time to reboot"); - set_completed_status(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "platform failed to reboot"); - force_inactive(); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - - NotificationResponse response = m_reboot_thread.Start(request); - EXPECT_EQ(response.status, swss::StatusCode::SWSS_RC_FAILED_PRECONDITION); - EXPECT_EQ(response.json_string, - "RebootThread: last NSF failed with non-retriable failure"); -} - -TEST_F(RebootThreadTest, TestNoNSFIfSystemCritical) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(true)); - set_start_status(RebootMethod::NSF, "time to reboot"); - - force_inactive(); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - - NotificationResponse response = m_reboot_thread.Start(request); - EXPECT_EQ(response.status, swss::StatusCode::SWSS_RC_FAILED_PRECONDITION); - EXPECT_EQ(response.json_string, - "RebootThread: in critical state, NSF not allowed"); -} - -TEST_F(RebootThreadTest, TestSigTermStartofDoReboot) { - sigterm_requested = true; - set_start_status(RebootMethod::NSF, "time to reboot"); - do_reboot(); - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); -} - TEST_F(RebootThreadTest, TestInvalidMethodfDoReboot) { set_start_status(RebootMethod::POWERUP, "time to reboot"); do_reboot(); @@ -491,999 +273,4 @@ TEST_F(RebootThreadTest, TestInvalidMethodfDoReboot) { IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); } -TEST_F(RebootThreadTest, TestWaitForRebootPositive) { - overwrite_reboot_timeout(1); - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - set_start_status(RebootMethod::NSF, "time to reboot"); - swss::Select s; - swss::SelectableEvent m_stop; - s.addSelectable(&m_stop); - RebootThread::Progress progress = wait_for_platform_reboot(s); - EXPECT_EQ(progress, RebootThread::Progress::PROCEED); - // EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); -} - -TEST_F(RebootThreadTest, TestWaitForRebootCriticalState) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(true)); - set_start_status(RebootMethod::NSF, "time to reboot"); - swss::Select s; - swss::SelectableEvent m_stop; - s.addSelectable(&m_stop); - RebootThread::Progress progress = wait_for_platform_reboot(s); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "system entered critical state after platfrom reboot request")); -} - -TEST_F(RebootThreadTest, TestWaitForRebootRxStop) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - m_reboot_thread.Stop(); - RebootThread::Progress progress = wait_for_platform_reboot(s); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); -} - -// -// State Verification Tests -// - -TEST_F(RebootThreadTest, TestStateVerificationCriticalState) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(true)); - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - RebootThread::Progress progress = perform_state_verification(s); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus( - RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "system entered critical state before reboot state verification")); -} - -TEST_F(RebootThreadTest, TestStateVerificationDisabled) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Table warmRestartTable(&m_config_db, CFG_WARM_RESTART_TABLE_NAME); - warmRestartTable.hset("system", "state_verification_shutdown", "false"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - RebootThread::Progress progress = perform_state_verification(s); - EXPECT_EQ(progress, RebootThread::Progress::PROCEED); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); -} - -TEST_F(RebootThreadTest, TestStateVerificationTimeout) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - overwrite_state_verification_timeout(1); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Table warmRestartTable(&m_config_db, CFG_WARM_RESTART_TABLE_NAME); - warmRestartTable.hset("system", "state_verification_shutdown", "true"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - RebootThread::Progress progress = perform_state_verification(s); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus( - RebootStatus_Status::RebootStatus_Status_STATUS_RETRIABLE_FAILURE, - "timeout occurred during reboot state verification: retriable " - "error")); -} - -TEST_F(RebootThreadTest, TestStateVerificationStop) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - overwrite_state_verification_timeout(1); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Table warmRestartTable(&m_config_db, CFG_WARM_RESTART_TABLE_NAME); - warmRestartTable.hset("system", "state_verification_shutdown", "true"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - m_reboot_thread.Stop(); - - RebootThread::Progress progress = perform_state_verification(s); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); -} - -TEST_F(RebootThreadTest, TestStateVerificationSelectTimeout) { - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - swss::SelectableTimer l_timer(timespec{.tv_sec = 1, .tv_nsec = 0}); - s.addSelectable(&l_timer); - - swss::SubscriberStateTable sub(&m_db, STATE_VERIFICATION_RESP_TABLE); - s.addSelectable(&sub); - - l_timer.start(); - - std::string timestamp = "timestamp-b"; - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_PASS, - "wrong-timestamp"); - - RebootThread::Progress progress = - perform_state_verification_select(s, l_timer, sub, timestamp); - - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus( - RebootStatus_Status::RebootStatus_Status_STATUS_RETRIABLE_FAILURE, - "timeout occurred during reboot state verification: retriable " - "error")); -} - -TEST_F(RebootThreadTest, TestStateVerificationSelectTimeoutNotRun) { - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - swss::SelectableTimer l_timer(timespec{.tv_sec = 1, .tv_nsec = 0}); - s.addSelectable(&l_timer); - - swss::SubscriberStateTable sub(&m_db, STATE_VERIFICATION_RESP_TABLE); - s.addSelectable(&sub); - - l_timer.start(); - - std::string timestamp = "timestamp-b"; - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_NOT_RUN, - timestamp); - - RebootThread::Progress progress = - perform_state_verification_select(s, l_timer, sub, timestamp); - - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - EXPECT_NE("timestamp-b", timestamp); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus( - RebootStatus_Status::RebootStatus_Status_STATUS_RETRIABLE_FAILURE, - "timeout occurred during reboot state verification: retriable " - "error")); -} - -TEST_F(RebootThreadTest, TestHandleStateVerificationKeepWaiting) { - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - swss::SubscriberStateTable sub(&m_db, STATE_VERIFICATION_RESP_TABLE); - s.addSelectable(&sub); - swss::Selectable *sel; - - // Unrecognized component returns KEEP_WAITING - std::string timestamp = "timestamp-a"; - TestUtils::write_state_verification_result(m_db, "not-all-component", - "dont care", timestamp); - s.select(&sel); - RebootThread::Status status = handle_state_verification_event(sub, timestamp); - EXPECT_EQ(status, RebootThread::Status::KEEP_WAITING); - - // Wrong timestamp returns KEEP_WAITING - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_PASS, - "wrong-timestamp"); - s.select(&sel); - status = handle_state_verification_event(sub, timestamp); - EXPECT_EQ(status, RebootThread::Status::KEEP_WAITING); - - // Unrecognized status + correct timestamp = KEEP_WAITING - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, - "undefined-status", timestamp); - s.select(&sel); - status = handle_state_verification_event(sub, timestamp); - EXPECT_EQ(status, RebootThread::Status::KEEP_WAITING); - - // If we receive NOT_RUN as a status: we KEEP_WAITING - // timestamp should be updated with new value after re-request of state - // verification - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_NOT_RUN, - timestamp); - s.select(&sel); - status = handle_state_verification_event(sub, timestamp); - EXPECT_EQ(status, RebootThread::Status::KEEP_WAITING); - EXPECT_NE(timestamp, "timestamp-a"); -} - -TEST_F(RebootThreadTest, TestHandleStateVerificationSuccess) { - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - swss::SubscriberStateTable sub(&m_db, STATE_VERIFICATION_RESP_TABLE); - s.addSelectable(&sub); - swss::Selectable *sel; - - // Pass + Correct timestamp == SUCCESS - std::string timestamp = "timestamp-b"; - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_PASS, - timestamp); - int select_ret = s.select(&sel); - EXPECT_EQ(select_ret, swss::Select::OBJECT); - EXPECT_EQ(sel, &sub); - RebootThread::Status status = handle_state_verification_event(sub, timestamp); - EXPECT_EQ(status, RebootThread::Status::SUCCESS); -} - -TEST_F(RebootThreadTest, TestHandleStateVerificationFail) { - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - swss::SubscriberStateTable sub(&m_db, STATE_VERIFICATION_RESP_TABLE); - s.addSelectable(&sub); - swss::Selectable *sel; - - // Fail with correct timestampe = FAILURE - // status and message are updated - std::string timestamp = "timestamp-b"; - TestUtils::write_state_verification_result(m_db, ALL_COMPONENT, SV_FAIL, - timestamp); - s.select(&sel); - RebootThread::Status status = handle_state_verification_event(sub, timestamp); - EXPECT_EQ(status, RebootThread::Status::FAILURE); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "state verification failed during reboot")); -} - -// -// Quiescence Tests -// - -TEST_F(RebootThreadTest, TestPerformFreezeQuiescenceCriticalState) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(true)); - set_start_status(RebootMethod::NSF, "time to reboot"); - - Progress progress = perform_freeze_quiescence_w_stop(false); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "system entered critical state before freezing")); -} - -TEST_F(RebootThreadTest, TestPerformFreezeQuiescenceTimeout) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - fetch_registration_info(); - - overwrite_quiescence_timeout_ms(300); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - Progress progress = perform_freeze_quiescence_w_stop(false); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "timeout occurred during reboot stage freeze")); -} - -TEST_F(RebootThreadTest, TestPerformFreezeQuiescenceStop) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - fetch_registration_info(); - overwrite_quiescence_timeout_ms(1000); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - Progress progress = perform_freeze_quiescence_w_stop(true); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - - // No error on request to stop, just log. - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); -} - -TEST_F(RebootThreadTest, TestPerformFreezeQuiescenceStartCompleted) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::QUIESCENT)); - fetch_registration_info(); - overwrite_quiescence_hold_time_ms(100); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - Progress progress = perform_freeze_quiescence_w_stop(false, 1000); - EXPECT_EQ(progress, RebootThread::Progress::PROCEED); -} - -TEST_F(RebootThreadTest, - TestPerformFreezeQuiescenceUninterestingStatesAtStart) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::RECONCILED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::INITIALIZED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::FROZEN)); - fetch_registration_info(); - overwrite_quiescence_timeout_ms(1000); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - Progress progress = perform_freeze_quiescence_w_stop(false); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "timeout occurred during reboot stage freeze")); -} - -TEST_F(RebootThreadTest, TestPerformFreezeQuiescenceStartFailed) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::FAILED)); - fetch_registration_info(); - overwrite_quiescence_timeout_ms(500); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - Progress progress = perform_freeze_quiescence_w_stop(true); - EXPECT_EQ(progress, RebootThread::Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "check_stage: app: app2 reported FAILED during stage: freeze")); -} - -TEST_F(RebootThreadTest, TestPerformFreezeQuiescenceCompleted) { - overwrite_quiescence_hold_time_ms(100); - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - fetch_registration_info(); - - set_start_status(RebootMethod::NSF, "time to reboot"); - auto test_sequence = [&] { - // We want to skip past the initial completed check at start of - // freeze_quiescence_select and process below as subscriptions updates - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - }; - - std::thread test_thread = std::thread(test_sequence); - - Progress progress = perform_freeze_quiescence_w_stop(false); - EXPECT_EQ(progress, Progress::PROCEED); - test_thread.join(); -} - -TEST_F(RebootThreadTest, - TestPerformFreezeQuiescenceUninterestingStatesViaSubscription) { - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - fetch_registration_info(); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - auto test_sequence = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::RECONCILED)); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::WSDISABLED)); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::WSUNKNOWN)); - }; - - std::thread test_thread = std::thread(test_sequence); - - Progress progress = perform_freeze_quiescence_w_stop(false, 300); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "timeout occurred during reboot stage freeze")); - test_thread.join(); -} - -TEST_F(RebootThreadTest, TestPerformFreezeQuiescenceFailed) { - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - fetch_registration_info(); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - auto test_sequence = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::FAILED)); - }; - - std::thread test_thread = std::thread(test_sequence); - - Progress progress = perform_freeze_quiescence_w_stop(false, 500); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "handle_state_event: app: app2 reported FAILED when " - "looking for state: freeze")); - test_thread.join(); -} - -TEST_F(RebootThreadTest, TestQuiescenceTimeoutDuringHoldTime) { - overwrite_quiescence_hold_time_ms(2000); - - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - fetch_registration_info(); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - auto test_sequence = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::QUIESCENT)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::INITIALIZED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - }; - - std::thread test_thread = std::thread(test_sequence); - - Progress progress = perform_freeze_quiescence_w_stop(false, 500); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "timeout occurred during reboot stage freeze")); - test_thread.join(); -} - -// Same as previous test with shorter hold_time. -TEST_F(RebootThreadTest, TestQuiescenceSuccessAfterHoldTime) { - overwrite_quiescence_hold_time_ms(100); - - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - fetch_registration_info(); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - auto test_sequence = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::QUIESCENT)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::INITIALIZED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - }; - - std::thread test_thread = std::thread(test_sequence); - - Progress progress = perform_freeze_quiescence_w_stop(false, 500); - EXPECT_EQ(progress, Progress::PROCEED); - test_thread.join(); -} - -TEST_F(RebootThreadTest, TestFailWhenExitQuiescence) { - overwrite_quiescence_hold_time_ms(200); - - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - fetch_registration_info(); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - auto test_sequence = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - // Enter quiescent state - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::QUIESCENT)); - // Exit quiescent state during hold time. - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::INITIALIZED)); - }; - - std::thread test_thread = std::thread(test_sequence); - - Progress progress = perform_freeze_quiescence_w_stop(false, 500); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "timeout occurred during reboot stage freeze")); - test_thread.join(); -} - -// -// Checkpoint -// - -TEST_F(RebootThreadTest, TestPerformCheckpointCriticalState) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(true)); - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - Progress progress = perform_checkpoint(s); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "system entered critical state before checkpointing")); -} - -TEST_F(RebootThreadTest, TestPerformCheckpointTimeout) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, false, - true, false); - fetch_registration_info(); - - overwrite_checkpoint_timeout(1); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - Progress progress = perform_checkpoint(s); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - HasSubstr("timeout occurred during reboot stage checkpoint"))); -} - -TEST_F(RebootThreadTest, TestPerformCheckpointStop) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, false, - true, false); - fetch_registration_info(); - overwrite_quiescence_timeout_ms(1000); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - m_reboot_thread.Stop(); - - Progress progress = perform_checkpoint(s); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - - // No error on request to stop, just log. - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); -} - -TEST_F(RebootThreadTest, TestPerformCheckpointStartCompleted) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, false, - true, false); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - fetch_registration_info(); - overwrite_quiescence_timeout_ms(1000); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - m_reboot_thread.Stop(); - - Progress progress = perform_checkpoint(s); - EXPECT_EQ(progress, Progress::PROCEED); -} - -TEST_F(RebootThreadTest, TestPerformCheckpointStartFailed) { - EXPECT_CALL(m_critical_interface, is_system_critical()) - .Times(1) - .WillOnce(Return(false)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, false, - true, false); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::FAILED)); - fetch_registration_info(); - overwrite_quiescence_timeout_ms(1000); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - m_reboot_thread.Stop(); - - Progress progress = perform_checkpoint(s); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - HasSubstr("check_stage: app: app2 reported FAILED " - "during stage: checkpoint"))); -} - -TEST_F(RebootThreadTest, TestPerformCheckpointCompleted) { - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, false, - true, false); - fetch_registration_info(); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - swss::SelectableTimer l_timer(timespec{.tv_sec = 1, .tv_nsec = 0}); - s.addSelectable(&l_timer); - - swss::SubscriberStateTable sub(&m_db, STATE_WARM_RESTART_TABLE_NAME); - s.addSelectable(&sub); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - - l_timer.start(); - - Progress progress = checkpoint_stage_two(s, l_timer, sub); - EXPECT_EQ(progress, Progress::PROCEED); -} - -TEST_F(RebootThreadTest, TestPerformCheckpointUninterestingStatesIgnored) { - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - fetch_registration_info(); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - swss::SelectableTimer l_timer(timespec{.tv_sec = 1, .tv_nsec = 0}); - s.addSelectable(&l_timer); - - swss::SubscriberStateTable sub(&m_db, STATE_WARM_RESTART_TABLE_NAME); - s.addSelectable(&sub); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - // Confirm a non checkpoint state isn't treated as CHECKPOINTED - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::RECONCILED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::INITIALIZED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::FROZEN)); - - l_timer.start(); - - Progress progress = checkpoint_stage_two(s, l_timer, sub); - EXPECT_EQ(progress, Progress::EXIT_EARLY); - - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - HasSubstr("timeout occurred during reboot stage checkpoint"))); -} - -TEST_F(RebootThreadTest, TestPerformCheckpointFailed) { - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, false, - true, false); - fetch_registration_info(); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - swss::SelectableTimer l_timer(timespec{.tv_sec = 1, .tv_nsec = 0}); - s.addSelectable(&l_timer); - - swss::SubscriberStateTable sub(&m_db, STATE_WARM_RESTART_TABLE_NAME); - s.addSelectable(&sub); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::FAILED)); - - l_timer.start(); - - Progress progress = checkpoint_stage_two(s, l_timer, sub); - - EXPECT_EQ(progress, Progress::EXIT_EARLY); - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "handle_state_event: app: app2 reported FAILED when looking for " - "state: checkpoint")); -} - -TEST_F(RebootThreadTest, TestPerformCheckpointUnexpectedStatesViaSubscription) { - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - fetch_registration_info(); - - swss::Select s; - s.addSelectable(&(return_m_stop_reference())); - - swss::SelectableTimer l_timer(timespec{.tv_sec = 1, .tv_nsec = 0}); - s.addSelectable(&l_timer); - - swss::SubscriberStateTable sub(&m_db, STATE_WARM_RESTART_TABLE_NAME); - s.addSelectable(&sub); - - set_start_status(RebootMethod::NSF, "time to reboot"); - - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::INITIALIZED)); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::RESTORED)); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::REPLAYED)); - - l_timer.start(); - - Progress progress = checkpoint_stage_two(s, l_timer, sub); - - EXPECT_EQ(progress, Progress::EXIT_EARLY); - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - HasSubstr("timeout occurred during reboot stage checkpoint"))); -} - -// -// Stop On Freeze Tests -// - -TEST_F(RebootThreadTest, TestCheckContainerStopDbusFail) { - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_FAIL, "dbus reboot failed"}; - EXPECT_CALL(m_dbus_interface, StopContainerStatus(_)) - .Times(1) - .WillOnce(Return(dbus_response)); - - RebootThread::Status status = check_container_stop("requestA"); - EXPECT_EQ(status, RebootThread::Status::FAILURE); -} - -TEST_F(RebootThreadTest, TestCheckContainerStopJsonParseFailure) { - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_SUCCESS, "dbus reboot failed"}; - EXPECT_CALL(m_dbus_interface, StopContainerStatus(_)) - .Times(1) - .WillOnce(Return(dbus_response)); - - RebootThread::Status status = check_container_stop("requestA"); - EXPECT_EQ(status, RebootThread::Status::FAILURE); -} - -TEST_F(RebootThreadTest, TestCheckContainerStopSuccess) { - StopContainersResponse response; - response.set_status(ShutdownStatus::DONE); - - std::string json_response; - gpu::MessageToJsonString(response, &json_response); - - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_SUCCESS, json_response.c_str()}; - EXPECT_CALL(m_dbus_interface, StopContainerStatus(_)) - .Times(1) - .WillOnce(Return(dbus_response)); - - RebootThread::Status status = check_container_stop("requestA"); - EXPECT_EQ(status, RebootThread::Status::SUCCESS); -} - -TEST_F(RebootThreadTest, TestWaitForContainerStopMStopSignal) { - TestUtils::populate_registration_table(m_db, "docker1|app1", true, false, - false, false); - fetch_registration_info(); - set_start_status(RebootMethod::NSF, "time to reboot"); - - Progress progress = wait_for_container_stop(300); - - EXPECT_EQ(progress, Progress::EXIT_EARLY); - force_inactive(); - RebootStatusResponse response = m_reboot_thread.GetResponse(); - - // No error on request to stop, just log. - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); -} - -TEST_F(RebootThreadTest, TestWaitForContainerStopDbusReturnsStopped) { - StopContainersResponse response; - response.set_status(ShutdownStatus::DONE); - - std::string json_response; - gpu::MessageToJsonString(response, &json_response); - - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_SUCCESS, json_response.c_str()}; - EXPECT_CALL(m_dbus_interface, StopContainerStatus(_)) - .Times(1) - .WillOnce(Return(dbus_response)); - - TestUtils::populate_registration_table(m_db, "docker1|app1", true, false, - false, false); - fetch_registration_info(); - set_start_status(RebootMethod::NSF, "time to reboot"); - - Progress progress = wait_for_container_stop(300); - - EXPECT_EQ(progress, Progress::PROCEED); -} - } // namespace rebootbackend diff --git a/src/sonic-framework/tests/rebootbe_test.cpp b/src/sonic-framework/tests/rebootbe_test.cpp index 6effce3029be..7c23f996bad3 100644 --- a/src/sonic-framework/tests/rebootbe_test.cpp +++ b/src/sonic-framework/tests/rebootbe_test.cpp @@ -8,12 +8,11 @@ #include #include #include +#include -#include "container_stop.pb.h" #include "mock_reboot_interfaces.h" #include "reboot_common.h" #include "select.h" -#include "stateverification.h" #include "status_code_util.h" #include "system/system.pb.h" #include "test_utils_common.h" @@ -31,8 +30,6 @@ namespace rebootbackend { namespace gpu = ::google::protobuf::util; using namespace gnoi::system; -using WarmStartState = ::swss::WarmStart::WarmStartState; -using WarmBootStage = ::swss::WarmStart::WarmBootStage; using ::testing::_; using ::testing::AllOf; @@ -60,18 +57,14 @@ class RebootBETestWithoutStop : public ::testing::Test { protected: RebootBETestWithoutStop() : m_dbus_interface(), - m_critical_interface(), m_db("STATE_DB", 0), m_config_db("CONFIG_DB", 0), m_rebootbeRequestChannel(&m_db, REBOOT_REQUEST_NOTIFICATION_CHANNEL), m_rebootbeReponseChannel(&m_db, REBOOT_RESPONSE_NOTIFICATION_CHANNEL), - m_rebootbe(m_dbus_interface, m_critical_interface, m_telemetry) { + m_rebootbe(m_dbus_interface) { sigterm_requested = false; - TestUtils::clear_tables(m_db); +// TestUtils::clear_tables(m_db); - auto mock_init_thread = std::make_unique>(); - m_init_thread = mock_init_thread.get(); - m_rebootbe.m_init_thread = std::move(mock_init_thread); m_s.addSelectable(&m_rebootbeReponseChannel); @@ -82,15 +75,6 @@ class RebootBETestWithoutStop : public ::testing::Test { } virtual ~RebootBETestWithoutStop() = default; - void force_warm_start_state(bool enabled) { - swss::Table enable_table(&m_db, STATE_WARM_RESTART_ENABLE_TABLE_NAME); - enable_table.hset("system", "enable", enabled ? "true" : "false"); - enable_table.hset("sonic-framework", "enable", enabled ? "true" : "false"); - - swss::Table restart_table(&m_db, STATE_WARM_RESTART_TABLE_NAME); - restart_table.hset("rebootbackend", "restore_count", enabled ? "0" : ""); - } - gnoi::system::RebootStatusResponse default_not_started_status() { InitThreadStatus status; return status.get_response(); @@ -105,21 +89,6 @@ class RebootBETestWithoutStop : public ::testing::Test { return status.get_response(); } - gnoi::system::RebootStatusResponse default_running_status() { - InitThreadStatus status; - status.set_start_status(); - status.set_detailed_thread_status( - InitThreadStatus::ThreadStatus::WAITING_FOR_RECONCILIATION); - return status.get_response(); - } - - gnoi::system::RebootStatusResponse default_error_status() { - InitThreadStatus status; - status.set_start_status(); - status.set_error(InitThreadStatus::ErrorCondition::RECONCILIATION_FAILED, - "Fake reconciliation failed"); - return status.get_response(); - } void start_rebootbe() { m_rebootbe_thread = @@ -136,21 +105,6 @@ class RebootBETestWithoutStop : public ::testing::Test { m_rebootbe.m_reboot_thread.m_reboot_timeout = timeout_seconds; } - void overwrite_state_verification_timeout(uint32_t timeout_seconds) { - m_rebootbe.m_reboot_thread.m_state_verification_timeout = timeout_seconds; - } - - void overwrite_quiescent_timeout_ms(uint64_t timeout_ms) { - m_rebootbe.m_reboot_thread.m_quiescence_timeout_ms = timeout_ms; - } - - void overwrite_quiescent_hold_time_ms(uint64_t timeout_ms) { - m_rebootbe.m_reboot_thread.m_quiescence_hold_time_ms = timeout_ms; - } - - void overwrite_checkpoint_timeout(uint32_t timeout_seconds) { - m_rebootbe.m_reboot_thread.m_checkpoint_timeout = timeout_seconds; - } void send_stop_reboot_thread() { m_rebootbe.m_reboot_thread.Stop(); } @@ -181,7 +135,7 @@ class RebootBETestWithoutStop : public ::testing::Test { while (true) { int ret; swss::Selectable *sel; - ret = m_s.select(&sel, SELECT_TIMEOUT_MS); + ret = m_s.select(&sel, SELECT_TIMEOUT_250_MS); if (ret != swss::Select::OBJECT) continue; if (sel != &m_rebootbeReponseChannel) continue; break; @@ -199,7 +153,7 @@ class RebootBETestWithoutStop : public ::testing::Test { while (true) { int ret; swss::Selectable *sel; - ret = m_s.select(&sel, SELECT_TIMEOUT_MS); + ret = m_s.select(&sel, SELECT_TIMEOUT_250_MS); if (ret != swss::Select::OBJECT) continue; if (sel != &m_rebootbeReponseChannel) continue; break; @@ -228,7 +182,7 @@ class RebootBETestWithoutStop : public ::testing::Test { swss::Select s; s.addSelectable(&consumer); swss::Selectable *sel; - s.select(&sel, SELECT_TIMEOUT_MS); + s.select(&sel, SELECT_TIMEOUT_250_MS); consumer.pop(op, data, values); } @@ -237,40 +191,9 @@ class RebootBETestWithoutStop : public ::testing::Test { return m_rebootbe.handle_reboot_request(json_request); } - void set_all_telemetry_expects(bool freeze_status = true, - bool checkpoint_status = true) { - set_telemetry_overall_expects(freeze_status && checkpoint_status); - set_telemetry_stage_expects(WarmBootStage::STAGE_FREEZE, freeze_status); - if (freeze_status) { - set_telemetry_stage_expects(WarmBootStage::STAGE_CHECKPOINT, - checkpoint_status); - } - } - - void set_telemetry_overall_expects(bool success) { - EXPECT_CALL(m_telemetry, record_overall_start()).Times(1); - if (!success) { - EXPECT_CALL(m_telemetry, record_overall_end(success)).Times(1); - } - } - - void set_telemetry_stage_expects(WarmBootStage nsf_stage, bool success) { - EXPECT_CALL(m_telemetry, record_stage_start(nsf_stage)).Times(1); - EXPECT_CALL(m_telemetry, record_stage_end(nsf_stage, success)).Times(1); - } - - swss::SelectableEvent &get_stack_unfrozen_select() { - return m_rebootbe.m_stack_unfrozen; - } - - swss::SelectableEvent &get_init_done_select() { - return m_rebootbe.m_init_thread_done; - } // Mock interfaces. NiceMock m_dbus_interface; - NiceMock m_critical_interface; - StrictMock m_telemetry; // DB connectors swss::DBConnector m_db; @@ -285,8 +208,6 @@ class RebootBETestWithoutStop : public ::testing::Test { std::unique_ptr m_rebootbe_thread; RebootBE m_rebootbe; - // Not owned by test. - StrictMock *m_init_thread; }; class RebootBETest : public RebootBETestWithoutStop { @@ -297,263 +218,6 @@ class RebootBETest : public RebootBETestWithoutStop { } }; -// Init sequence testing. -TEST_F(RebootBETest, ColdbootInitWorks) { - force_warm_start_state(false); - - EXPECT_CALL(*m_init_thread, GetResponse()) - .Times(2) - .WillRepeatedly(Return(default_not_started_status())); - - start_rebootbe(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 0, RebootMethod::COLD)); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS, "")); -} - -TEST_F(RebootBETest, WarmbootInitWorks) { - force_warm_start_state(true); - - { - InSequence seq; - EXPECT_CALL(*m_init_thread, Start()) - .WillOnce(Return(swss::StatusCode::SWSS_RC_SUCCESS)); - - // Status request during warmboot init, then during Join sequence. - EXPECT_CALL(*m_init_thread, GetResponse()) - .Times(2) - .WillRepeatedly(Return(default_running_status())) - .RetiresOnSaturation(); - - // Normal Join sequence when reaching COMPLETED. - EXPECT_CALL(*m_init_thread, Join()).WillOnce(Return(true)); - - // Status request after warmboot init, then cleanup sequence. - EXPECT_CALL(*m_init_thread, GetResponse()) - .Times(2) - .WillRepeatedly(Return(default_done_status())); - } - - start_rebootbe(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); - - // Check status during init. - EXPECT_THAT( - do_reboot_status_rpc(), - AllOf(ActiveCountMethod(true, 0, RebootMethod::NSF), - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, - ""))); - - get_stack_unfrozen_select().notify(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); - - get_init_done_select().notify(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - - // Check that NSF status is sticky after init, before a new coldboot starts. - EXPECT_THAT( - do_reboot_status_rpc(), - AllOf(ActiveCountMethod(false, 0, RebootMethod::NSF), - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS, - ""))); -} - -TEST_F(RebootBETest, InitThreadFailsToStart) { - force_warm_start_state(true); - - { - InSequence seq; - EXPECT_CALL(*m_init_thread, Start()) - .WillOnce(Return(swss::StatusCode::SWSS_RC_INTERNAL)); - - // Cleanup sequence. - EXPECT_CALL(*m_init_thread, GetResponse()) - .WillOnce(Return(default_not_started_status())); - } - - start_rebootbe(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); -} - -TEST_F(RebootBETest, WarmbootInProgressBlocksNewWarmboot) { - force_warm_start_state(true); - - // Start InitThread, but do not run to completion. - { - InSequence seq; - EXPECT_CALL(*m_init_thread, Start()) - .WillOnce(Return(swss::StatusCode::SWSS_RC_SUCCESS)); - - // Cleanup sequence. - EXPECT_CALL(*m_init_thread, GetResponse()) - .WillOnce(Return(default_done_status())); - } - - start_rebootbe(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); - - // Send a warmboot request, confirm it fails. - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request, swss::StatusCode::SWSS_RC_IN_USE); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); -} - -TEST_F(RebootBETest, ColdbootWhileWarmbootInProgress) { - force_warm_start_state(true); - set_mock_defaults(); - - // Start InitThread, but do not run to completion. - { - InSequence seq; - EXPECT_CALL(*m_init_thread, Start()) - .WillOnce(Return(swss::StatusCode::SWSS_RC_SUCCESS)); - - // Cleanup sequence. - EXPECT_CALL(*m_init_thread, GetResponse()) - .WillOnce(Return(default_done_status())); - } - - start_rebootbe(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); - - // Send a coldboot request, confirm it starts. - RebootRequest request; - request.set_method(RebootMethod::COLD); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::COLD_REBOOT_IN_PROGRESS); - - // Cleanup without going through the whole reboot. - send_stop_reboot_thread(); -} - -TEST_F(RebootBETestWithoutStop, WarmbootStopDuringInit) { - force_warm_start_state(true); - - { - InSequence seq; - EXPECT_CALL(*m_init_thread, Start()) - .WillOnce(Return(swss::StatusCode::SWSS_RC_SUCCESS)); - - // Stop triggers the cleanup sequnce without either of the SelectableEvent's - // being triggered. - EXPECT_CALL(*m_init_thread, GetResponse()) - .WillOnce(Return(default_running_status())); - EXPECT_CALL(*m_init_thread, Stop()).Times(1); - EXPECT_CALL(*m_init_thread, Join()).WillOnce(Return(true)); - } - - start_rebootbe(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); - - // Manually join and verify state. - m_rebootbe.Stop(); - m_rebootbe_thread->join(); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); -} - -TEST_F(RebootBETestWithoutStop, WarmbootErrorBeforeUnfreeze) { - force_warm_start_state(true); - - { - InSequence seq; - // Immediately report an error from the InitThread after starting. - auto done_lambda = [&] { - get_init_done_select().notify(); - return swss::StatusCode::SWSS_RC_SUCCESS; - }; - EXPECT_CALL(*m_init_thread, Start()).WillOnce(Invoke(done_lambda)); - - // Normal Join sequence when reaching COMPLETED. - EXPECT_CALL(*m_init_thread, GetResponse()) - .WillOnce(Return(default_error_status())) - .RetiresOnSaturation(); - EXPECT_CALL(*m_init_thread, Join()).WillOnce(Return(false)); - - // Cleanup sequence. - EXPECT_CALL(*m_init_thread, GetResponse()) - .WillOnce(Return(default_done_status())); - } - - start_rebootbe(); - - // Immediately handle InitThread error and become IDLE. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - - // Manually join and verify state. - m_rebootbe.Stop(); - m_rebootbe_thread->join(); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); -} - -TEST_F(RebootBETestWithoutStop, WarmbootErrorBeforeComplete) { - force_warm_start_state(true); - - { - InSequence seq; - EXPECT_CALL(*m_init_thread, Start()) - .WillOnce(Return(swss::StatusCode::SWSS_RC_SUCCESS)); - - // Normal Join sequence when reaching COMPLETED. - EXPECT_CALL(*m_init_thread, GetResponse()) - .WillOnce(Return(default_error_status())) - .RetiresOnSaturation(); - EXPECT_CALL(*m_init_thread, Join()).WillOnce(Return(false)); - - // Cleanup sequnce. - EXPECT_CALL(*m_init_thread, GetResponse()) - .WillOnce(Return(default_error_status())); - EXPECT_CALL(*m_init_thread, Stop()).Times(1); - EXPECT_CALL(*m_init_thread, Join()).WillOnce(Return(false)); - } - - start_rebootbe(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); - - // Advance to waiting for unfreeze. - get_stack_unfrozen_select().notify(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_INIT_WAIT); - - // Triggered as part of InitThread error reporting. - get_init_done_select().notify(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - - // Manually join and verify state. - m_rebootbe.Stop(); - m_rebootbe_thread->join(); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); -} - // Test fixture to skip through the startup sequence into the main loop. // Param indicates if RebootBE should be initialized into a state where the // system came up in warmboot. @@ -561,9 +225,9 @@ class RebootBEAutoStartTest : public RebootBETest, public ::testing::WithParamInterface { protected: RebootBEAutoStartTest() { - force_warm_start_state(GetParam()); + //force_warm_start_state(GetParam()); - if (GetParam()) { + /* if (GetParam()) { EXPECT_CALL(*m_init_thread, Start()) .WillOnce(Return(swss::StatusCode::SWSS_RC_SUCCESS)); EXPECT_CALL(*m_init_thread, Join()).WillOnce(Return(true)); @@ -573,21 +237,23 @@ class RebootBEAutoStartTest : public RebootBETest, } else { EXPECT_CALL(*m_init_thread, GetResponse()) .WillRepeatedly(Return(default_not_started_status())); - } + } */ start_rebootbe(); - if (GetParam()) { +/* if (GetParam()) { get_stack_unfrozen_select().notify(); std::this_thread::sleep_for(std::chrono::milliseconds(50)); get_init_done_select().notify(); - } + } */ std::this_thread::sleep_for(std::chrono::milliseconds(50)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); + EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE); } }; + + // Normal operation testing. TEST_P(RebootBEAutoStartTest, NonExistentMessage) { swss::NotificationConsumer consumer(&m_db, @@ -595,7 +261,7 @@ TEST_P(RebootBEAutoStartTest, NonExistentMessage) { // No "MESSAGE" in field/values SendRebootRequest("Reboot", "StatusCode", "field1", "field1_value"); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); + EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE); std::string op, data; std::vector ret_values; @@ -613,7 +279,7 @@ TEST_P(RebootBEAutoStartTest, TestCancelReboot) { SendRebootRequest("CancelReboot", "StatusCode", DATA_TUPLE_KEY, "json cancelreboot request"); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); + EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE); std::string op, data; std::vector ret_values; @@ -630,7 +296,7 @@ TEST_P(RebootBEAutoStartTest, TestUnrecognizedOP) { REBOOT_RESPONSE_NOTIFICATION_CHANNEL); SendRebootRequest("NonOp", "StatusCode", DATA_TUPLE_KEY, "invalid op code"); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); + EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE); std::string op, data; std::vector ret_values; @@ -649,21 +315,17 @@ TEST_P(RebootBEAutoStartTest, TestColdRebootDbusToCompletion) { .Times(3) .WillRepeatedly(Return(dbus_response)); - EXPECT_CALL(m_critical_interface, - report_critical_state("platform failed to reboot")) - .Times(3); overwrite_reboot_timeout(1); - RebootRequest request; request.set_method(RebootMethod::COLD); start_reboot_via_rpc(request); std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::COLD_REBOOT_IN_PROGRESS); + RebootBE::RebManagerStatus::COLD_REBOOT_IN_PROGRESS); sleep(TWO_SECONDS); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); + EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE); gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::COLD)); EXPECT_THAT(response, @@ -695,7 +357,7 @@ TEST_P(RebootBEAutoStartTest, TestColdBootSigterm) { sleep(ONE_SECOND); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); + EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE); gnoi::system::RebootStatusResponse second_resp = do_reboot_status_rpc(); EXPECT_THAT(second_resp, ActiveCountMethod(false, 1, RebootMethod::COLD)); EXPECT_THAT( @@ -717,7 +379,7 @@ TEST_P(RebootBEAutoStartTest, TestColdBootDbusError) { sleep(TWO_SECONDS); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); + EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE); gnoi::system::RebootStatusResponse second_resp = do_reboot_status_rpc(); EXPECT_THAT(second_resp, ActiveCountMethod(false, 1, RebootMethod::COLD)); EXPECT_THAT(second_resp, @@ -733,11 +395,11 @@ TEST_P(RebootBEAutoStartTest, TestStopDuringColdBoot) { start_reboot_via_rpc(request); std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::COLD_REBOOT_IN_PROGRESS); + RebootBE::RebManagerStatus::COLD_REBOOT_IN_PROGRESS); send_stop_reboot_thread(); std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); + EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::RebManagerStatus::IDLE); gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::COLD)); @@ -746,548 +408,12 @@ TEST_P(RebootBEAutoStartTest, TestStopDuringColdBoot) { IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, "")); } -TEST_P(RebootBEAutoStartTest, TestNSFToCompletion) { - set_mock_defaults(); - - EXPECT_CALL(m_critical_interface, - report_critical_state("platform failed to reboot")) - .Times(1); - - set_telemetry_overall_expects(false); - set_telemetry_stage_expects(WarmBootStage::STAGE_FREEZE, true); - set_telemetry_stage_expects(WarmBootStage::STAGE_CHECKPOINT, true); - - overwrite_reboot_timeout(1); - overwrite_quiescent_hold_time_ms(100); - - // skip state verification - TestUtils::set_state_verification_enable(m_config_db, false, false); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - true, false); - - auto test_sequence = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - }; - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - // Warm start states are cleared at beginning of NSF boot. - std::thread test_thread = std::thread(test_sequence); - - // 1 second reboot timeout - // 1/10 second delay before warm state is written in test - // 1/10 second delay for quiescent hold time - std::this_thread::sleep_for(std::chrono::milliseconds(TWO_SECONDS_MS)); - - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - test_thread.join(); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "platform failed to reboot")); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - -TEST_P(RebootBEAutoStartTest, TestStateVerificationFailedTimeout) { - set_mock_defaults(); - - overwrite_state_verification_timeout(1); - set_telemetry_overall_expects(/*success=*/false); - - TestUtils::set_state_verification_enable(m_config_db, false, true); - - // Empty registration: if we fail, it should be because of - // state verification - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - - // We have to wait for the 1 second state verification timeout - std::this_thread::sleep_for(std::chrono::milliseconds(TWO_SECONDS_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT( - response, - IsStatus( - RebootStatus_Status::RebootStatus_Status_STATUS_RETRIABLE_FAILURE, - "timeout occurred during reboot state verification: retriable " - "error")); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - -TEST_P(RebootBEAutoStartTest, TestQuiescenceFailedTimeout) { - set_mock_defaults(); - - overwrite_quiescent_timeout_ms(400); - set_all_telemetry_expects(/*freeze_status=*/false, - /*checkpoint_status=*/false); - - TestUtils::set_state_verification_enable(m_config_db, false, false); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - - // We have to wait for the 1 second quiescence - std::this_thread::sleep_for(std::chrono::milliseconds(ONE_SECOND_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "timeout occurred during reboot stage freeze")); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - -TEST_P(RebootBEAutoStartTest, TestCheckpointFailedTimeout) { - set_mock_defaults(); - - overwrite_checkpoint_timeout(1); - overwrite_quiescent_hold_time_ms(100); - set_all_telemetry_expects(/*freeze_status=*/true, - /*checkpoint_status=*/false); - - TestUtils::set_state_verification_enable(m_config_db, false, false); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - - // 1/10 second for quiescence hold time - // 1 second for checkpoint timeout - std::this_thread::sleep_for(std::chrono::milliseconds(TWO_SECONDS_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - HasSubstr("timeout occurred during reboot stage checkpoint"))); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - -TEST_P(RebootBEAutoStartTest, TestNSFDbusRebootError) { - // Return FAIL from dbus reboot call. - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_FAIL, "dbus reboot failed"}; - EXPECT_CALL(m_dbus_interface, Reboot(_)) - .Times(1) - .WillOnce(Return(dbus_response)); - set_telemetry_overall_expects(/*status=*/false); - set_telemetry_stage_expects(WarmBootStage::STAGE_FREEZE, /*status=*/true); - set_telemetry_stage_expects(WarmBootStage::STAGE_CHECKPOINT, - /*status=*/true); - - overwrite_quiescent_hold_time_ms(100); - - TestUtils::set_state_verification_enable(m_config_db, false, false); - - // Empty registration. - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - // Short wait: there should be no state verification, checkpoint or - // or platform reboot delays - // 1/10 second for quiescent hold time - // the quiescent select timeout is 250ms - std::this_thread::sleep_for(std::chrono::milliseconds(HALF_SECOND_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "dbus reboot failed")); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - -// Test redis tables are cleared. -// - warm boot states should be cleared -// - existing apps in init table should be cleared -TEST_P(RebootBEAutoStartTest, TestRedisNSFSetup) { - set_mock_defaults(); - set_telemetry_overall_expects(/*success=*/false); - - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - - swss::Table warmRestartTable(&m_db, STATE_WARM_RESTART_TABLE_NAME); - std::string state = ""; - warmRestartTable.hget("app1", "state", state); - EXPECT_EQ(state, get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - - swss::Table initTable(&m_db, STATE_WARM_RESTART_INIT_TABLE_NAME); - initTable.hset("docker2|app2", "timestamp", "fake-timestamp"); - std::string timestamp = ""; - initTable.hget("docker2|app2", "timestamp", timestamp); - EXPECT_THAT(timestamp, StrEq("fake-timestamp")); - - overwrite_state_verification_timeout(1); - - TestUtils::set_state_verification_enable(m_config_db, false, true); - - // Empty registration: if we fail, it should be because of - // state verification - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - - // We have to wait for the 1 second state verification timeout - std::this_thread::sleep_for(std::chrono::milliseconds(TWO_SECONDS_MS)); - - state = ""; - warmRestartTable.hget("app1", "state", state); - EXPECT_NE(state, get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - - timestamp = ""; - initTable.hget("docker2|app2", "timestamp", timestamp); - EXPECT_NE(timestamp, "fake-timestamp"); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT( - response, - IsStatus( - RebootStatus_Status::RebootStatus_Status_STATUS_RETRIABLE_FAILURE, - HasSubstr("timeout occurred during reboot state verification: " - "retriable error"))); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - -TEST_P(RebootBEAutoStartTest, TestNSFFailureFollowedByColdBoot) { - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_SUCCESS, ""}; - EXPECT_CALL(m_dbus_interface, Reboot(_)) - .Times(1) - .WillRepeatedly(Return(dbus_response)); - - EXPECT_CALL(m_critical_interface, - report_critical_state("platform failed to reboot")) - .Times(1); - overwrite_reboot_timeout(1); - overwrite_checkpoint_timeout(1); - overwrite_quiescent_hold_time_ms(100); - - set_all_telemetry_expects(/*freeze_status=*/true, - /*checkpoint_status=*/false); - - TestUtils::set_state_verification_enable(m_config_db, false, false); - - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - - // 1/10 second quiescence hold time - // 1 second checkpoint timeout - std::this_thread::sleep_for(std::chrono::milliseconds(TWO_SECONDS_MS)); - - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT( - response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - HasSubstr("timeout occurred during reboot stage checkpoint"))); - - request.set_method(RebootMethod::COLD); - start_reboot_via_rpc(request); - - // We have to wait for the 1 second reboot Timeout - std::this_thread::sleep_for(std::chrono::milliseconds(TWO_SECONDS_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 2, RebootMethod::COLD)); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "platform failed to reboot")); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - TEST_P(RebootBEAutoStartTest, TestInvalidJsonRebootRequest) { std::string json_request = "abcd"; NotificationResponse response = handle_reboot_request(json_request); EXPECT_EQ(swss::StatusCode::SWSS_RC_INTERNAL, response.status); } -TEST_P(RebootBEAutoStartTest, TestStopDuringRebootStateVerification) { - set_telemetry_overall_expects(/*success=*/false); - - // Enable state verification with default 260 sec timeout) - TestUtils::set_state_verification_enable(m_config_db, false, true); - - // Empty registration. - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(true, 1, RebootMethod::NSF)); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/true); - - // Reboot thread is active: its waiting for state verification to complete - // TearDown will call rebootbe.Stop() which will Stop and Join the - // reboot thread -} - -TEST_P(RebootBEAutoStartTest, TestStopDuringRebootFreezeStage) { - set_all_telemetry_expects(/*freeze_status=*/false, - /*checkpoint_status=*/false); - - // Disable state verification - TestUtils::set_state_verification_enable(m_config_db, false, false); - - // Register for checkpoint monitoring - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(true, 1, RebootMethod::NSF)); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/true); - - // Reboot thread is active: its waiting for app1 to quiesce. - // TearDown will call rebootbe.Stop() which will Stop and Join the - // reboot thread -} - -TEST_P(RebootBEAutoStartTest, TestStopDuringRebootCheckpointStage) { - set_all_telemetry_expects(/*freeze_status=*/true, - /*checkpoint_status=*/false); - - // Disable state verification. - overwrite_quiescent_hold_time_ms(10); - TestUtils::set_state_verification_enable(m_config_db, false, false); - - // Register app1 for checkpointing. - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - // With the short hold time we need 250+ms to allow the quiescence hold - // time select timeout to fire. - std::this_thread::sleep_for(std::chrono::milliseconds(HALF_SECOND_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(true, 1, RebootMethod::NSF)); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/true); - - // Reboot thread is active: its waiting for app1 to checkpoint. - // TearDown will call rebootbe.Stop() which will Stop and Join the - // reboot thread -} - -TEST_P(RebootBEAutoStartTest, TestStopDuringWaitPlatformReboot) { - set_telemetry_overall_expects(/*status=*/false); - set_telemetry_stage_expects(WarmBootStage::STAGE_FREEZE, /*status=*/true); - set_telemetry_stage_expects(WarmBootStage::STAGE_CHECKPOINT, - /*status=*/true); - - // Disable state verification. - overwrite_quiescent_hold_time_ms(10); - TestUtils::set_state_verification_enable(m_config_db, false, false); - - // Empty registration. - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - // With the short hold time we need 250+ms to allow the quiescence hold - // time select timeout to fire. - std::this_thread::sleep_for(std::chrono::milliseconds(HALF_SECOND_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(true, 1, RebootMethod::NSF)); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/true); - - // Reboot thread is active: its waiting for the platform to reboot. - // TearDown will call rebootbe.Stop() which will Stop and Join the - // reboot thread -} - -// -// Stop On Freeze Tests -// -TEST_P(RebootBEAutoStartTest, TestStopDuringWaitForStopOnFreeze) { - set_all_telemetry_expects(false); - - overwrite_quiescent_hold_time_ms(50); - overwrite_quiescent_timeout_ms(1000); - - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_SUCCESS, ""}; - EXPECT_CALL(m_dbus_interface, StopContainerStatus(_)) - .Times(AtLeast(1)) - .WillRepeatedly(Return(dbus_response)); - - // Disable state verification. - TestUtils::set_state_verification_enable(m_config_db, false, false); - - // Register app1 for checkpointing. - TestUtils::populate_registration_table(m_db, "docker1|app1", true, false, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), - RebootBE::NsfManagerStatus::NSF_REBOOT_IN_PROGRESS); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(true, 1, RebootMethod::NSF)); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/true); - - // Reboot thread is active: its waiting for docker1 to exit/stop - // TearDown will call rebootbe.Stop() which will Stop and Join the - // reboot thread -} - -TEST_P(RebootBEAutoStartTest, TestStopOnFreezeTimeout) { - set_all_telemetry_expects(false); - - overwrite_quiescent_hold_time_ms(50); - overwrite_quiescent_timeout_ms(1000); - - // An empty string is not a valid json stop container status response - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_SUCCESS, ""}; - EXPECT_CALL(m_dbus_interface, StopContainerStatus(_)) - .Times(AtLeast(1)) - .WillRepeatedly(Return(dbus_response)); - - TestUtils::set_state_verification_enable(m_config_db, false, false); - - TestUtils::populate_registration_table(m_db, "docker1|app1", true, false, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - // Container stop status is checked every half second. - std::this_thread::sleep_for(std::chrono::milliseconds(FIFTEEN_HUNDRED_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "timeout occurred waiting for containers to stop")); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - -TEST_P(RebootBEAutoStartTest, TestDbusErrorRequestingContainerStop) { - set_all_telemetry_expects(false); - - // Return FAIL from dbus reboot call. - DbusInterface::DbusResponse dbus_response{ - DbusInterface::DbusStatus::DBUS_FAIL, - "dbus error calling StopContainers"}; - EXPECT_CALL(m_dbus_interface, StopContainers(_)) - .Times(1) - .WillOnce(Return(dbus_response)); - - TestUtils::set_state_verification_enable(m_config_db, false, false); - - TestUtils::populate_registration_table(m_db, "docker1|app1", true, false, - false, false); - - RebootRequest request; - request.set_method(RebootMethod::NSF); - start_reboot_via_rpc(request); - - // Container stop status is checked every half second. - std::this_thread::sleep_for(std::chrono::milliseconds(ONE_SECOND_MS)); - - EXPECT_EQ(m_rebootbe.GetCurrentStatus(), RebootBE::NsfManagerStatus::IDLE); - - gnoi::system::RebootStatusResponse response = do_reboot_status_rpc(); - EXPECT_THAT(response, ActiveCountMethod(false, 1, RebootMethod::NSF)); - EXPECT_THAT(response, - IsStatus(RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE, - "dbus error calling StopContainers")); - TestUtils::check_warmboot_enabled(m_db, /*expected_state=*/false); -} - INSTANTIATE_TEST_SUITE_P(TestWithStartupWarmbootEnabledState, RebootBEAutoStartTest, testing::Values(true, false)); diff --git a/src/sonic-framework/tests/redis_utils_test.cpp b/src/sonic-framework/tests/redis_utils_test.cpp index c42161691a22..00864059a21e 100644 --- a/src/sonic-framework/tests/redis_utils_test.cpp +++ b/src/sonic-framework/tests/redis_utils_test.cpp @@ -9,777 +9,15 @@ #include #include "select.h" -#include "stateverification.h" #include "table.h" #include "test_utils_common.h" #include "timestamp.h" -#include "warm_restart.h" namespace rebootbackend { -using WarmStartState = ::swss::WarmStart::WarmStartState; -using WarmBootStage = ::swss::WarmStart::WarmBootStage; -using WarmBootNotification = ::swss::WarmStart::WarmBootNotification; - using ::testing::AllOf; using ::testing::HasSubstr; using ::testing::StrEq; -class RedisTest : public ::testing::Test { - protected: - RedisTest() : m_db("STATE_DB", 0), m_reg(), m_init_reg() { - TestUtils::clear_tables(m_db); - } - - swss::DBConnector m_db; - Registration m_reg; - InitRegistration m_init_reg; - - void clear_contents() { return m_reg.clear_contents(); } - - size_t get_state_set_size(WarmBootStage nsf_stage) { - return m_reg.m_remaining_apps.at(nsf_stage).size(); - } - - size_t get_reregistration_set_size() { - return m_init_reg.m_missing_registrations.size(); - } - - // Special version of name mapping that is compatible with the DB values. - std::string warm_boot_stage_name(WarmBootStage stage) { - switch (stage) { - case (WarmBootStage::STAGE_FREEZE): { - return "quiescent"; - } - case (WarmBootStage::STAGE_CHECKPOINT): { - return "checkpointed"; - } - case (WarmBootStage::STAGE_RECONCILIATION): { - return "reconciled"; - } - case (WarmBootStage::STAGE_UNFREEZE): { - return "completed"; - } - default: { - return ""; - } - } - } - - void populate_default_init_table() { - swss::Table initTable(&m_db, STATE_WARM_RESTART_INIT_TABLE_NAME); - initTable.hset("docker1|app1", "timestamp", ""); - initTable.hset("docker2|app2", "timestamp", ""); - initTable.hset("docker3|app3", "timestamp", ""); - initTable.hset("docker4|app1", "timestamp", ""); - // The invalid entry should not end up in the list of apps. - initTable.hset("invalid", "timestamp", ""); - } - - friend class Registration; -}; - -TEST_F(RedisTest, testSendNsfManagerNotification) { - swss::NotificationConsumer nc( - &m_db, swss::WarmStart::kNsfManagerNotificationChannel); - swss::Select s; - s.addSelectable(&nc); - - send_nsf_manager_notification(m_db, WarmBootNotification::kFreeze); - - swss::Selectable *sel; - bool ret = s.select(&sel, 1); - EXPECT_EQ(ret, swss::Select::OBJECT); - - std::string op, data; - std::vector values; - nc.pop(op, data, values); - auto fv = values[0]; - - EXPECT_EQ(op, swss::WarmStart::warmBootNotificationNameMap()->at( - WarmBootNotification::kFreeze)); - - send_nsf_manager_notification(m_db, WarmBootNotification::kUnfreeze); - - ret = s.select(&sel, 1); - EXPECT_EQ(ret, swss::Select::OBJECT); - - nc.pop(op, data, values); - fv = values[0]; - - EXPECT_EQ(op, swss::WarmStart::warmBootNotificationNameMap()->at( - WarmBootNotification::kUnfreeze)); - - send_nsf_manager_notification(m_db, WarmBootNotification::kCheckpoint); - - ret = s.select(&sel, 1); - EXPECT_EQ(ret, swss::Select::OBJECT); - - nc.pop(op, data, values); - fv = values[0]; - - EXPECT_EQ(op, swss::WarmStart::warmBootNotificationNameMap()->at( - WarmBootNotification::kCheckpoint)); -} - -TEST_F(RedisTest, testSendStateVerification) { - swss::NotificationConsumer nc(&m_db, STATE_VERIFICATION_REQ_CHANNEL); - swss::Select s; - s.addSelectable(&nc); - - std::string timestamp = send_state_verification_notification(m_db, true); - - swss::Selectable *sel; - bool ret = s.select(&sel, 1); - EXPECT_EQ(ret, swss::Select::OBJECT); - - std::string op, data; - std::vector values; - nc.pop(op, data, values); - auto fv = values[0]; - - EXPECT_EQ(op, ALL_COMPONENT); - EXPECT_EQ(data, timestamp); - EXPECT_EQ(FREEZE_FIELD, fvField(fv)); - EXPECT_EQ("true", fvValue(fv)); - - std::string second_timestamp = - send_state_verification_notification(m_db, false); - - ret = s.select(&sel, 1); - EXPECT_EQ(ret, swss::Select::OBJECT); - - nc.pop(op, data, values); - fv = values[0]; - - EXPECT_EQ(op, ALL_COMPONENT); - EXPECT_EQ(data, second_timestamp); - EXPECT_EQ(FREEZE_FIELD, fvField(fv)); - EXPECT_EQ("false", fvValue(fv)); - EXPECT_NE(timestamp, second_timestamp); -} - -TEST_F(RedisTest, testInitWarmRebootStates) { - swss::Table warmRestartTable(&m_db, STATE_WARM_RESTART_TABLE_NAME); - - warmRestartTable.hset("app1", "state", "disabled"); - warmRestartTable.hset("app1", "timestamp", "abcdefg"); - warmRestartTable.hset("app2", "state", "reconciled"); - warmRestartTable.hset("app2", "timestamp", "zyxwvu"); - - std::string value; - bool ret = warmRestartTable.hget("app1", "state", value); - EXPECT_TRUE(ret); - - ret = warmRestartTable.hget("app1", "timestamp", value); - EXPECT_TRUE(ret); - - init_warm_reboot_states(m_db); - - ret = warmRestartTable.hget("app1", "state", value); - EXPECT_FALSE(ret); - - ret = warmRestartTable.hget("app1", "timestamp", value); - EXPECT_FALSE(ret); - - ret = warmRestartTable.hget("app2", "state", value); - EXPECT_FALSE(ret); - - ret = warmRestartTable.hget("app2", "timestamp", value); - EXPECT_FALSE(ret); -} - -TEST_F(RedisTest, testSetWarmRestartEnable) { - swss::Table warmRestartTable(&m_db, STATE_WARM_RESTART_ENABLE_TABLE_NAME); - - for (const auto &enabled : {true, false}) { - warmRestartTable.del("system"); - - set_warm_restart_enable(m_db, enabled); - - std::string value; - bool ret = warmRestartTable.hget("system", "enable", value); - EXPECT_TRUE(ret); - EXPECT_EQ(value, enabled ? "true" : "false"); - } -} - -TEST_F(RedisTest, TestIsValidKeyAndGetDockerAppFromKey) { - std::string key = "abc|def"; - std::string separator = "|"; - std::string docker, app; - - EXPECT_TRUE(is_valid_key(key, separator)); - EXPECT_TRUE(get_docker_app_from_key(key, separator, docker, app)); - EXPECT_EQ(docker, "abc"); - EXPECT_EQ(app, "def"); - - key = "abcd|"; - EXPECT_FALSE(is_valid_key(key, separator)); - EXPECT_FALSE(get_docker_app_from_key(key, separator, docker, app)); - - key = "|abcd"; - EXPECT_FALSE(is_valid_key(key, separator)); - EXPECT_FALSE(get_docker_app_from_key(key, separator, docker, app)); - - key = "abcd"; - EXPECT_FALSE(is_valid_key(key, separator)); - EXPECT_FALSE(get_docker_app_from_key(key, separator, docker, app)); - - separator = ""; - key = "abc|def"; - EXPECT_FALSE(is_valid_key(key, separator)); - EXPECT_FALSE(get_docker_app_from_key(key, separator, docker, app)); -} - -TEST_F(RedisTest, GetWarmRestartCounter) { - EXPECT_THAT(get_warm_restart_counter(m_db), StrEq("")); - for (int i = 0; i < 5; i++) { - set_warm_restart_counter(m_db, i); - EXPECT_THAT(get_warm_restart_counter(m_db), StrEq(std::to_string(i))); - } -} - -TEST_F(RedisTest, TestFetchRegistrationInfo) { - TestUtils::populate_registration_table(m_db, "invalid", false, false, false, - true); - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker2|app2", true, true, true, - false); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, false, - true, false); - - m_reg.fetch_registration_info(); - - Registration::RegistrationSet set = m_reg.get_registered_app_set(); - - EXPECT_TRUE(set.count("docker1|app1")); - EXPECT_TRUE(set.count("docker2|app2")); - EXPECT_TRUE(set.count("docker2|app2")); - EXPECT_EQ(set.size(), 3); -} - -TEST_F(RedisTest, TestStopOnFreezeList) { - TestUtils::populate_registration_table(m_db, "docker1|app1", true, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker2|app2", true, false, - false, false); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, false, - true, false); - - m_reg.fetch_registration_info(); - Registration::RegistrationSet set = m_reg.get_stop_on_freeze_set(); - EXPECT_EQ(2, set.size()); - EXPECT_EQ(1, set.count("docker1")); - EXPECT_EQ(1, set.count("docker2")); -} - -TEST_F(RedisTest, TestCheckQuiesced) { - // No apps registered. - m_reg.fetch_registration_info(); - Registration::Response response = m_reg.check_quiesced(); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - - // Apps registered, but have not reached the correct state. - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker4|app4", true, false, - false, false); - - m_reg.fetch_registration_info(); - EXPECT_EQ(3, get_state_set_size(WarmBootStage::STAGE_FREEZE)); - - // app1 and app2 reach the correct state. - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::QUIESCENT)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - - response = m_reg.check_quiesced(); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - EXPECT_EQ(1, get_state_set_size(WarmBootStage::STAGE_FREEZE)); - - // app3 reaches the correct state. - TestUtils::populate_restart_table_state( - m_db, "app3", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - - response = m_reg.check_quiesced(); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - EXPECT_EQ(0, get_state_set_size(WarmBootStage::STAGE_FREEZE)); - - // app3 reports an error. - m_reg.fetch_registration_info(); - TestUtils::populate_restart_table_state( - m_db, "app3", get_warm_start_state_name(WarmStartState::FAILED)); - - response = m_reg.check_quiesced(); - EXPECT_EQ(response.status, Registration::Status::FAILURE); - EXPECT_FALSE(response.error_string.empty()); -} - -TEST_F(RedisTest, TestCheckCheckpointed) { - // No apps registered. - m_reg.fetch_registration_info(); - Registration::Response response = m_reg.check_checkpointed(); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - - // Apps registered, but have not reached the correct state. - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, false, - true, false); - TestUtils::populate_registration_table(m_db, "docker4|app4", true, false, - false, false); - - m_reg.fetch_registration_info(); - EXPECT_EQ(3, get_state_set_size(WarmBootStage::STAGE_CHECKPOINT)); - - // app2 reaches the correct state. app1 has changed state, but is not yet - // checkpointed. - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::QUIESCENT)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - - response = m_reg.check_checkpointed(); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - EXPECT_EQ(2, get_state_set_size(WarmBootStage::STAGE_CHECKPOINT)); - - // app1 and app3 reach the correct state. - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - TestUtils::populate_restart_table_state( - m_db, "app3", get_warm_start_state_name(WarmStartState::CHECKPOINTED)); - - response = m_reg.check_checkpointed(); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - EXPECT_EQ(0, get_state_set_size(WarmBootStage::STAGE_CHECKPOINT)); - - // app3 reports an error. - m_reg.fetch_registration_info(); - TestUtils::populate_restart_table_state( - m_db, "app3", get_warm_start_state_name(WarmStartState::FAILED)); - - response = m_reg.check_checkpointed(); - EXPECT_EQ(response.status, Registration::Status::FAILURE); - EXPECT_FALSE(response.error_string.empty()); -} - -TEST_F(RedisTest, TestCheckReconciled) { - // No apps registered. - m_reg.fetch_registration_info(); - Registration::Response response = m_reg.check_reconciled(); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - - // Apps registered, but have not reached the correct state. - TestUtils::populate_registration_table(m_db, "docker1|app1", false, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker4|app4", true, false, - false, false); - - m_reg.fetch_registration_info(); - EXPECT_EQ(3, get_state_set_size(WarmBootStage::STAGE_RECONCILIATION)); - EXPECT_THAT(m_reg.join_pending_apps(WarmBootStage::STAGE_RECONCILIATION), - AllOf(HasSubstr("app1"), HasSubstr("app2"), HasSubstr("app3"))); - - // app1 and app2 reach the correct state. - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::RECONCILED)); - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::RECONCILED)); - - response = m_reg.check_reconciled(); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - EXPECT_EQ(1, get_state_set_size(WarmBootStage::STAGE_RECONCILIATION)); - EXPECT_THAT(m_reg.join_pending_apps(WarmBootStage::STAGE_RECONCILIATION), - HasSubstr("app3")); - - // app3 reaches the correct state. - TestUtils::populate_restart_table_state( - m_db, "app3", get_warm_start_state_name(WarmStartState::RECONCILED)); - - response = m_reg.check_reconciled(); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - EXPECT_EQ(0, get_state_set_size(WarmBootStage::STAGE_RECONCILIATION)); - EXPECT_THAT(m_init_reg.join_pending_apps(), StrEq("")); - - // app3 reports an error. - m_reg.fetch_registration_info(); - TestUtils::populate_restart_table_state( - m_db, "app3", get_warm_start_state_name(WarmStartState::FAILED)); - - response = m_reg.check_reconciled(); - EXPECT_EQ(response.status, Registration::Status::FAILURE); - EXPECT_FALSE(response.error_string.empty()); - EXPECT_THAT(m_reg.join_pending_apps(WarmBootStage::STAGE_RECONCILIATION), - HasSubstr("app3")); -} - -TEST_F(RedisTest, TestCheckUnfrozen) { - // No apps registered. - m_reg.fetch_registration_info(); - Registration::Response response = m_reg.check_unfrozen(); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - - // Apps registered. app4 reaches the correct state, but the others have not. - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker4|app4", true, false, - false, false); - TestUtils::populate_restart_table_state( - m_db, "app4", get_warm_start_state_name(WarmStartState::COMPLETED)); - - m_reg.fetch_registration_info(); - response = m_reg.check_unfrozen(); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - EXPECT_EQ(2, get_state_set_size(WarmBootStage::STAGE_UNFREEZE)); - EXPECT_THAT(m_reg.join_pending_apps(WarmBootStage::STAGE_UNFREEZE), - AllOf(HasSubstr("app1"), HasSubstr("app2"))); - - // app1 reaches the correct state. - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::COMPLETED)); - - response = m_reg.check_unfrozen(); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - EXPECT_EQ(1, get_state_set_size(WarmBootStage::STAGE_UNFREEZE)); - EXPECT_THAT(m_reg.join_pending_apps(WarmBootStage::STAGE_UNFREEZE), - HasSubstr("app2")); - - // app 2 reaches the correct state. We do not monitor app 3. - TestUtils::populate_restart_table_state( - m_db, "app2", get_warm_start_state_name(WarmStartState::COMPLETED)); - - response = m_reg.check_unfrozen(); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - EXPECT_EQ(0, get_state_set_size(WarmBootStage::STAGE_UNFREEZE)); - EXPECT_THAT(m_reg.join_pending_apps(WarmBootStage::STAGE_UNFREEZE), - StrEq("")); - - // app1 reports an error. - m_reg.fetch_registration_info(); - TestUtils::populate_restart_table_state( - m_db, "app1", get_warm_start_state_name(WarmStartState::FAILED)); - - response = m_reg.check_unfrozen(); - EXPECT_EQ(response.status, Registration::Status::FAILURE); - EXPECT_FALSE(response.error_string.empty()); - EXPECT_THAT(m_reg.join_pending_apps(WarmBootStage::STAGE_UNFREEZE), - AllOf(HasSubstr("app1"))); -} - -class RedisTestWithWarmStartState - : public RedisTest, - public ::testing::WithParamInterface {}; - -TEST_P(RedisTestWithWarmStartState, TestEventHandling) { - // Apps registered. No app has reported state. - const std::vector test_keys( - {"docker1|app1", "docker2|app2", "docker3|app3"}); - for (const auto &key : test_keys) { - TestUtils::populate_registration_table( - m_db, key, false, - GetParam() == WarmBootStage::STAGE_FREEZE || - GetParam() == WarmBootStage::STAGE_UNFREEZE, - GetParam() == WarmBootStage::STAGE_CHECKPOINT, - GetParam() == WarmBootStage::STAGE_RECONCILIATION); - } - TestUtils::populate_registration_table(m_db, "docker4|app4", true, false, - false, false); - m_reg.fetch_registration_info(); - - // Ignore invalid operation - swss::KeyOpFieldsValuesTuple state_event = {"app1", "DEL", {{"state", ""}}}; - Registration::Response response = - m_reg.handle_state_event(GetParam(), state_event); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - EXPECT_EQ(3, get_state_set_size(GetParam())); - - // app1 reaches its final state, but the others have not reported state. - state_event = {"app1", "SET", {{"state", warm_boot_stage_name(GetParam())}}}; - response = m_reg.handle_state_event(GetParam(), state_event); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - EXPECT_EQ(2, get_state_set_size(GetParam())); - - // All apps report final state one-by-one. - for (size_t i = 1; i < test_keys.size(); i++) { - std::string docker, app; - bool ret = get_docker_app_from_key(test_keys[i], "|", docker, app); - EXPECT_TRUE(ret); - - state_event = {app, "SET", {{"state", warm_boot_stage_name(GetParam())}}}; - response = m_reg.handle_state_event(GetParam(), state_event); - - if (i < test_keys.size() - 1) { - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - } else { - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - } - EXPECT_EQ(get_state_set_size(GetParam()), test_keys.size() - (i + 1)); - } - - // app3 reports an error. - m_reg.fetch_registration_info(); - state_event = {"app3", "SET", {{"state", "failed"}}}; - - response = m_reg.handle_state_event(GetParam(), state_event); - EXPECT_EQ(response.status, Registration::Status::FAILURE); - EXPECT_FALSE(response.error_string.empty()); -} - -TEST_P(RedisTestWithWarmStartState, HandleEventSkipInvalidKey) { - TestUtils::populate_registration_table( - m_db, "docker1|app1", false, - GetParam() == WarmBootStage::STAGE_FREEZE || - GetParam() == WarmBootStage::STAGE_UNFREEZE, - GetParam() == WarmBootStage::STAGE_CHECKPOINT, - GetParam() == WarmBootStage::STAGE_RECONCILIATION); - m_reg.fetch_registration_info(); - - swss::KeyOpFieldsValuesTuple state_event = { - "invalid", "SET", {{"state", "completed"}}}; - - Registration::Response response = - m_reg.handle_state_event(GetParam(), state_event); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - EXPECT_EQ(get_state_set_size(GetParam()), 1); -} - -INSTANTIATE_TEST_SUITE_P(TestOverWarmStateStates, RedisTestWithWarmStartState, - testing::Values(WarmBootStage::STAGE_FREEZE, - WarmBootStage::STAGE_CHECKPOINT, - WarmBootStage::STAGE_RECONCILIATION, - WarmBootStage::STAGE_UNFREEZE)); - -TEST_F(RedisTest, TestHandleQuiescenceEvent) { - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - m_reg.fetch_registration_info(); - - swss::KeyOpFieldsValuesTuple state_event = { - "app1", "DEL", {{"state", "checkpointed"}}}; - Registration::Response response = - m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - - state_event = {"app1", "SET", {{"state", "checkpointed"}}}; - response = m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - - state_event = {"app1", "DEL", {{"state", "completed"}}}; - response = m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - - state_event = {"app1", "SET", {{"state", "failed"}}}; - response = m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::FAILURE); -} - -TEST_F(RedisTest, TestHandleQuiescenceEnterExitCompleteState) { - TestUtils::populate_registration_table(m_db, "docker1|app1", false, true, - false, false); - TestUtils::populate_registration_table(m_db, "docker2|app2", false, true, - false, false); - m_reg.fetch_registration_info(); - - swss::KeyOpFieldsValuesTuple state_event = { - "app1", "SET", {{"state", "quiescent"}}}; - Registration::Response response = - m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - - state_event = {"app2", "SET", {{"state", "checkpointed"}}}; - response = m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - - state_event = {"app1", "SET", {{"state", "replayed"}}}; - response = m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - - state_event = {"app1", "SET", {{"state", "quiescent"}}}; - response = m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); - - state_event = {"app2", "SET", {{"state", "restored"}}}; - response = m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::IN_PROCESS); - - state_event = {"app2", "SET", {{"state", "checkpointed"}}}; - response = m_reg.handle_state_event(WarmBootStage::STAGE_FREEZE, state_event); - EXPECT_EQ(response.status, Registration::Status::COMPLETED); -} - -TEST_F(RedisTest, TestClearContents) { - TestUtils::populate_registration_table(m_db, "docker1|app1", true, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker2|app2", true, false, - false, false); - TestUtils::populate_registration_table(m_db, "docker3|app3", false, true, - true, false); - m_reg.fetch_registration_info(); - Registration::RegistrationSet set = m_reg.get_stop_on_freeze_set(); - EXPECT_EQ(2, set.size()); - EXPECT_EQ(1, get_state_set_size(WarmBootStage::STAGE_FREEZE)); - EXPECT_EQ(1, get_state_set_size(WarmBootStage::STAGE_CHECKPOINT)); - EXPECT_EQ(1, get_state_set_size(WarmBootStage::STAGE_RECONCILIATION)); - EXPECT_EQ(1, get_state_set_size(WarmBootStage::STAGE_UNFREEZE)); - - clear_contents(); - - set = m_reg.get_stop_on_freeze_set(); - EXPECT_TRUE(set.empty()); - - set = m_reg.get_registered_app_set(); - EXPECT_TRUE(set.empty()); - - EXPECT_EQ(0, get_state_set_size(WarmBootStage::STAGE_FREEZE)); - EXPECT_EQ(0, get_state_set_size(WarmBootStage::STAGE_CHECKPOINT)); - EXPECT_EQ(0, get_state_set_size(WarmBootStage::STAGE_RECONCILIATION)); - EXPECT_EQ(0, get_state_set_size(WarmBootStage::STAGE_UNFREEZE)); -} - -TEST_F(RedisTest, TestClearAllInitApps) { - const std::vector kTestKeys( - {"docker1|app1", "docker2|app2", "docker3|app3", "docker4|app1"}); - for (const auto &key : kTestKeys) { - TestUtils::populate_registration_table(m_db, key, false, false, false, - true); - } - - m_reg.fetch_registration_info(); - m_reg.save_all_init_apps(); - - swss::Table initTable(&m_db, STATE_WARM_RESTART_INIT_TABLE_NAME); - std::string value; - for (const auto &key : kTestKeys) { - EXPECT_TRUE(initTable.hget(key, "timestamp", value)); - } - - m_reg.clear_all_init_apps(); - - for (const auto &key : kTestKeys) { - EXPECT_FALSE(initTable.hget(key, "timestamp", value)); - } -} - -TEST_F(RedisTest, TestSaveInitApps) { - const std::vector kTestKeys( - {"docker1|app1", "docker2|app2", "docker3|app3", "docker4|app1"}); - for (const auto &key : kTestKeys) { - TestUtils::populate_registration_table(m_db, key, false, false, false, - true); - } - // The invalid entry should not end up in the table. - TestUtils::populate_registration_table(m_db, "invalid", false, false, false, - true); - - m_reg.fetch_registration_info(); - m_reg.save_all_init_apps(); - - swss::Table initTable(&m_db, STATE_WARM_RESTART_INIT_TABLE_NAME); - std::string value; - - for (const auto &key : kTestKeys) { - EXPECT_TRUE(initTable.hget(key, "timestamp", value)); - } -} - -TEST_F(RedisTest, TestInitTargetApps) { - // Contains 4 valid apps and 1 invalid app. - populate_default_init_table(); - - m_init_reg.fetch_init_app_info(); - - EXPECT_EQ(get_reregistration_set_size(), 4); -} - -TEST_F(RedisTest, TestCheckReregistration) { - populate_default_init_table(); - - // Before reading the init table, we do not know apps need to re-register. - EXPECT_EQ(m_init_reg.check_reregistration_status(), - InitRegistration::Status::COMPLETED); - EXPECT_EQ(get_reregistration_set_size(), 0); - EXPECT_THAT(m_init_reg.join_pending_apps(), StrEq("")); - - // No apps have re-registered. All valid apps are still pending. - m_init_reg.fetch_init_app_info(); - - EXPECT_EQ(m_init_reg.check_reregistration_status(), - InitRegistration::Status::IN_PROGRESS); - EXPECT_EQ(get_reregistration_set_size(), 4); - EXPECT_THAT(m_init_reg.join_pending_apps(), - AllOf(HasSubstr("docker1|app1"), HasSubstr("docker2|app2"), - HasSubstr("docker3|app3"), HasSubstr("docker4|app1"))); - - // app1 re-registers. Other apps remain outstanding. - TestUtils::populate_registration_table(m_db, "docker1|app1", true, false, - false, true); - - EXPECT_EQ(m_init_reg.check_reregistration_status(), - InitRegistration::Status::IN_PROGRESS); - EXPECT_EQ(get_reregistration_set_size(), 3); - EXPECT_THAT(m_init_reg.join_pending_apps(), - AllOf(HasSubstr("docker2|app2"), HasSubstr("docker3|app3"), - HasSubstr("docker4|app1"))); - - // Other outstanding apps re-register - TestUtils::populate_registration_table(m_db, "docker2|app2", true, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker3|app3", true, false, - false, true); - TestUtils::populate_registration_table(m_db, "docker4|app1", true, false, - false, true); - - EXPECT_EQ(m_init_reg.check_reregistration_status(), - InitRegistration::Status::COMPLETED); - EXPECT_EQ(get_reregistration_set_size(), 0); - EXPECT_THAT(m_init_reg.join_pending_apps(), StrEq("")); -} - -TEST_F(RedisTest, TestHandleRegistrationEvent) { - populate_default_init_table(); - - // No apps have re-registered. All valid apps are still pending. - m_init_reg.fetch_init_app_info(); - - EXPECT_EQ(m_init_reg.check_reregistration_status(), - InitRegistration::Status::IN_PROGRESS); - EXPECT_EQ(get_reregistration_set_size(), 4); - - // Trigger re-registration events for apps one-by-one. - const std::vector event_keys( - {"docker1|app1", "docker2|app2", "docker3|app3", "docker4|app1"}); - for (size_t i = 0; i < event_keys.size(); i++) { - const swss::KeyOpFieldsValuesTuple event = { - event_keys[i], "HSET", {{"timestamp", ""}}}; - - m_init_reg.handle_registration_event(event); - - if (i < event_keys.size() - 1) { - EXPECT_EQ(m_init_reg.check_reregistration_status(), - InitRegistration::Status::IN_PROGRESS); - } else { - EXPECT_EQ(m_init_reg.check_reregistration_status(), - InitRegistration::Status::COMPLETED); - } - EXPECT_EQ(get_reregistration_set_size(), event_keys.size() - (i + 1)); - } -} } // namespace rebootbackend diff --git a/src/sonic-framework/tests/telemetry_helper_test.cpp b/src/sonic-framework/tests/telemetry_helper_test.cpp deleted file mode 100644 index d4b14077d136..000000000000 --- a/src/sonic-framework/tests/telemetry_helper_test.cpp +++ /dev/null @@ -1,394 +0,0 @@ -#include "telemetry_helper.h" - -#include -#include - -#include -#include -#include - -#include "init_thread.h" -#include "reboot_interfaces.h" -#include "redis_utils.h" -#include "table.h" -#include "test_utils_common.h" -#include "warm_restart.h" - -namespace rebootbackend { - -using swss::WarmStart; -using ::testing::_; -using ::testing::Contains; -using ::testing::ExplainMatchResult; -using ::testing::IsEmpty; -using ::testing::StrEq; - -// A fake app class that has methods to trigger telemetry writes. Used to -// abstract some test logic out of the tests themselves. -class FakeApp { - public: - FakeApp(const std::string &app_name) : m_app_name(app_name) {} - - void record_start(WarmStart::WarmBootStage nsf_stage) const { - swss::WarmStart::updateAppWarmBootStageStart(nsf_stage, m_app_name); - } - - // There are two different API calls in warm_restart.cpp to report final - // status. - void record_end(WarmStart::WarmBootStage nsf_stage, bool success) const { - if (success) { - swss::WarmStart::updateAppWarmBootStageEnd(nsf_stage_to_state(nsf_stage), - m_app_name); - } else { - swss::WarmStart::updateAppWarmBootStageEndOnFailure(nsf_stage, - m_app_name); - } - } - - const std::string &get_name() const { return m_app_name; } - - private: - static WarmStart::WarmStartState nsf_stage_to_state( - WarmStart::WarmBootStage nsf_stage) { - switch (nsf_stage) { - case WarmStart::WarmBootStage::STAGE_FREEZE: { - return WarmStart::WarmStartState::QUIESCENT; - } - case WarmStart::WarmBootStage::STAGE_CHECKPOINT: { - return WarmStart::WarmStartState::CHECKPOINTED; - } - case WarmStart::WarmBootStage::STAGE_RECONCILIATION: { - return WarmStart::WarmStartState::RECONCILED; - } - case WarmStart::WarmBootStage::STAGE_UNFREEZE: { - return WarmStart::WarmStartState::COMPLETED; - } - default: { - return WarmStart::WarmStartState::COMPLETED; - } - } - } - - std::string m_app_name; -}; - -class TelemetryHelperTest : public ::testing::Test { - public: - TelemetryHelperTest() - : m_db("STATE_DB", 0), - m_separator(swss::TableBase::getTableSeparator(m_db.getDbId())), - m_telemetry_helper() { - swss::WarmStart::initialize("fake_app", "fake_docker"); - TestUtils::clear_tables(m_db); - - for (const auto &app : kFakeApps) { - TestUtils::populate_registration_table( - m_db, concat_key("docker1", app.get_name()), false, true, true, true); - } - } - - // Checks for DB entries in the form: - // WARM_RESTART_PERFORMANCE_TABLE|system - // WARM_RESTART_PERFORMANCE_HISTORY||system - void check_overall_entries(int count, const std::string &expected_status) { - check_overall_entries(count, expected_status, - default_fields_for_status(expected_status)); - } - - void check_overall_entries( - int count, const std::string &expected_status, - const std::unordered_set &expected_fields) { - check_table_entries(STATE_WARM_RESTART_PERF_TABLE_NAME, "system", - expected_status, expected_fields); - check_table_entries(STATE_WARM_RESTART_PERF_HISTORY_TABLE_NAME, - concat_key(std::to_string(count), "system"), - expected_status, expected_fields); - } - - // Checks for DB entries in the form: - // WARM_RESTART_PERFORMANCE_TABLE| - // WARM_RESTART_PERFORMANCE_TABLE|| - // WARM_RESTART_PERFORMANCE_HISTORY|| - // WARM_RESTART_PERFORMANCE_HISTORY||| - void check_stage_start_entries(int count, - WarmStart::WarmBootStage nsf_stage) { - fully_parameterized_stage_entries(count, nsf_stage, {}, "in-progress", "", - default_fields_for_status("in-progress")); - } - - void check_stage_end_entries(int count, WarmStart::WarmBootStage nsf_stage, - bool success) { - std::string expected_status = get_end_status_string(success); - fully_parameterized_stage_entries( - count, nsf_stage, kFakeApps, expected_status, - get_app_end_status_string(nsf_stage, success), - default_fields_for_status(expected_status)); - } - - void fully_parameterized_stage_entries( - int count, WarmStart::WarmBootStage nsf_stage, - const std::vector apps, const std::string &expected_status, - const std::string &expected_app_status, - const std::unordered_set &expected_fields) { - std::string stage_name = - swss::WarmStart::warmBootStageToNameMap()->at(nsf_stage); - check_table_entries(STATE_WARM_RESTART_PERF_TABLE_NAME, stage_name, - expected_status, expected_fields); - check_table_entries(STATE_WARM_RESTART_PERF_HISTORY_TABLE_NAME, - concat_key(std::to_string(count), stage_name), - expected_status, expected_fields); - - for (const auto &app : apps) { - std::string key_to_check = concat_key(stage_name, app.get_name()); - check_table_entries(STATE_WARM_RESTART_PERF_TABLE_NAME, key_to_check, - expected_app_status, expected_fields); - check_table_entries(STATE_WARM_RESTART_PERF_HISTORY_TABLE_NAME, - concat_key(std::to_string(count), key_to_check), - expected_app_status, expected_fields); - } - } - - // A filled out swss::FieldValueTuple with the specified values. - std::vector default_fvs( - const std::string &status, const std::string &start_timestamp, - const std::string &end_timestamp) { - std::vector field_values( - {{swss::WarmStart::kPerfTableStatusAttr, status}, - {swss::WarmStart::kPerfTableStartTimeAttr, start_timestamp}}); - if (!end_timestamp.empty()) { - field_values.push_back( - {swss::WarmStart::kPerfTableFinishTimeAttr, end_timestamp}); - } - return field_values; - } - - std::string get_end_status_string(bool success) { - return success ? "success" : "failure"; - } - - std::string get_app_end_status_string(WarmStart::WarmBootStage nsf_stage, - bool success) { - if (nsf_stage == WarmStart::WarmBootStage::STAGE_FREEZE) { - return success ? "quiescent" : "failure"; - } - return success ? "success" : "failure"; - } - - private: - // Not to be used directly. - void check_table_entries( - const std::string &table_name, const std::string &key, - const std::string &expected_status, - const std::unordered_set &expected_fields) { - // Check that we have the key. - swss::Table table(&m_db, table_name); - std::vector keys; - table.getKeys(keys); - EXPECT_THAT(keys, Contains(key)) - << "Table: " << table_name << " did not contain key: " << key; - - // Check that we have the right fields for those keys. - std::vector field_values; - bool result = table.get(key, field_values); - EXPECT_TRUE(result); - - std::unordered_set remaining_expected_fields(expected_fields); - for (const auto &field_value : field_values) { - remaining_expected_fields.erase(fvField(field_value)); - } - std::ostringstream stream; - std::copy(expected_fields.begin(), expected_fields.end(), - std::ostream_iterator(stream, ", ")); - EXPECT_THAT(remaining_expected_fields, IsEmpty()) - << "Table: " << table_name << " had incorrect fields for key: " << key - << ". Expected fields: " << stream.str(); - - // Check that the value of "status" is correct. - std::string actual_status; - result = - table.hget(key, swss::WarmStart::kPerfTableStatusAttr, actual_status); - EXPECT_THAT(actual_status, StrEq(expected_status)) - << "Table: " << table_name << " had incorrect status for key: " << key; - } - - std::string concat_key(const std::string &str1, const std::string &str2) { - return str1 + m_separator + str2; - } - - const std::unordered_set &default_fields_for_status( - std::string status) { - return status == "in-progress" ? kStartFields : kEndFields; - } - - protected: - const std::unordered_set kStartFields = { - swss::WarmStart::kPerfTableStatusAttr, - swss::WarmStart::kPerfTableStartTimeAttr}; - const std::unordered_set kEndFields = { - swss::WarmStart::kPerfTableStatusAttr, - swss::WarmStart::kPerfTableStartTimeAttr, - swss::WarmStart::kPerfTableFinishTimeAttr}; - const std::unordered_set kEndWithoutStartFields = { - swss::WarmStart::kPerfTableStatusAttr, - swss::WarmStart::kPerfTableFinishTimeAttr}; - const std::vector kStagesInOrder = { - WarmStart::WarmBootStage::STAGE_FREEZE, - WarmStart::WarmBootStage::STAGE_CHECKPOINT, - WarmStart::WarmBootStage::STAGE_RECONCILIATION, - WarmStart::WarmBootStage::STAGE_UNFREEZE}; - const std::vector kFakeApps = {FakeApp("app1"), FakeApp("app2"), - FakeApp("app3")}; - - swss::DBConnector m_db; - std::string m_separator; - TelemetryHelper m_telemetry_helper; -}; - -class TelemetryHelperWithResultTest - : public TelemetryHelperTest, - public ::testing::WithParamInterface {}; - -TEST_F(TelemetryHelperTest, OverallStartInitializesCounter) { - for (int i = 1; i < 6; i++) { - m_telemetry_helper.record_overall_start(); - - EXPECT_THAT(get_warm_restart_counter(m_db), StrEq(std::to_string(i))); - check_overall_entries(i, "in-progress"); - } -} - -TEST_F(TelemetryHelperTest, OverallStartIgnoresFakeCounter) { - swss::Table table(&m_db, "BOOT_INFO"); - table.hset("system", "warmboot-count", "fake_counter"); - - m_telemetry_helper.record_overall_start(); - - EXPECT_THAT(get_warm_restart_counter(m_db), StrEq("1")); - check_overall_entries(1, "in-progress"); -} - -TEST_F(TelemetryHelperTest, OverallStartClearsPerf) { - swss::Table table(&m_db, STATE_WARM_RESTART_PERF_TABLE_NAME); - table.set("system", - default_fvs("fake_status", "fake_timestamp", "fake_timestamp2")); - table.set("freeze|fake_app", - default_fvs("fake_status", "fake_timestamp", "fake_timestamp2")); - - m_telemetry_helper.record_overall_start(); - - EXPECT_THAT(get_warm_restart_counter(m_db), StrEq("1")); - check_overall_entries(1, "in-progress"); - - std::vector unused; - EXPECT_FALSE(table.get("freeze|fake_app", unused)); -} - -TEST_P(TelemetryHelperWithResultTest, OverallEndWithoutStart) { - m_telemetry_helper.record_overall_end(GetParam()); - - check_overall_entries(0, get_end_status_string(GetParam()), - kEndWithoutStartFields); -} - -TEST_P(TelemetryHelperWithResultTest, OverallEndWorks) { - m_telemetry_helper.record_overall_start(); - - m_telemetry_helper.record_overall_end(GetParam()); - - check_overall_entries(1, get_end_status_string(GetParam())); -} - -TEST_F(TelemetryHelperTest, StageStartWithoutStart) { - for (const auto &nsf_stage : kStagesInOrder) { - m_telemetry_helper.record_stage_start(nsf_stage); - for (const auto &app : kFakeApps) { - app.record_start(nsf_stage); - } - check_stage_start_entries(0, nsf_stage); - } -} - -TEST_F(TelemetryHelperTest, StageStartWorks) { - m_telemetry_helper.record_overall_start(); - - for (const auto &nsf_stage : kStagesInOrder) { - m_telemetry_helper.record_stage_start(nsf_stage); - for (const auto &app : kFakeApps) { - app.record_start(nsf_stage); - } - check_stage_start_entries(1, nsf_stage); - } -} - -TEST_P(TelemetryHelperWithResultTest, StageEndWithoutStart) { - for (const auto &nsf_stage : kStagesInOrder) { - m_telemetry_helper.record_stage_start(nsf_stage); - for (const auto &app : kFakeApps) { - app.record_start(nsf_stage); - app.record_end(nsf_stage, GetParam()); - } - m_telemetry_helper.record_stage_end(nsf_stage, GetParam()); - check_stage_end_entries(0, nsf_stage, GetParam()); - } -} - -TEST_P(TelemetryHelperWithResultTest, StageEndWithoutStageStart) { - m_telemetry_helper.record_overall_start(); - - std::string expected_status = get_end_status_string(GetParam()); - - for (const auto &nsf_stage : kStagesInOrder) { - for (const auto &app : kFakeApps) { - app.record_start(nsf_stage); - app.record_end(nsf_stage, GetParam()); - } - m_telemetry_helper.record_stage_end(nsf_stage, GetParam()); - - std::string expected_app_status = - get_app_end_status_string(nsf_stage, GetParam()); - fully_parameterized_stage_entries(1, nsf_stage, kFakeApps, expected_status, - expected_app_status, - kEndWithoutStartFields); - } -} - -TEST_P(TelemetryHelperWithResultTest, StageEndWorks) { - m_telemetry_helper.record_overall_start(); - - for (const auto &nsf_stage : kStagesInOrder) { - m_telemetry_helper.record_stage_start(nsf_stage); - for (const auto &app : kFakeApps) { - app.record_start(nsf_stage); - app.record_end(nsf_stage, GetParam()); - } - m_telemetry_helper.record_stage_end(nsf_stage, GetParam()); - check_stage_end_entries(1, nsf_stage, GetParam()); - } -} - -TEST_P(TelemetryHelperWithResultTest, EndToEndWorks) { - m_telemetry_helper.record_overall_start(); - check_overall_entries(1, "in-progress"); - - for (const auto &nsf_stage : kStagesInOrder) { - m_telemetry_helper.record_stage_start(nsf_stage); - for (const auto &app : kFakeApps) { - app.record_start(nsf_stage); - } - check_stage_start_entries(1, nsf_stage); - - for (const auto &app : kFakeApps) { - app.record_end(nsf_stage, GetParam()); - } - m_telemetry_helper.record_stage_end(nsf_stage, GetParam()); - check_stage_end_entries(1, nsf_stage, GetParam()); - } - - m_telemetry_helper.record_overall_end(GetParam()); - check_overall_entries(1, get_end_status_string(GetParam())); -} - -INSTANTIATE_TEST_SUITE_P(TestWithResultSuite, TelemetryHelperWithResultTest, - testing::Values(true, false)); - -} // namespace rebootbackend diff --git a/src/sonic-framework/tests/test_utils_common.cpp b/src/sonic-framework/tests/test_utils_common.cpp index 6b5448c41395..ef0088b7bf05 100644 --- a/src/sonic-framework/tests/test_utils_common.cpp +++ b/src/sonic-framework/tests/test_utils_common.cpp @@ -11,16 +11,14 @@ #include "redis_utils.h" #include "select.h" #include "selectableevent.h" -#include "stateverification.h" #include "table.h" #include "timestamp.h" -#include "warm_restart.h" namespace rebootbackend { void TestUtils::wait_for_finish(swss::Select &s, swss::SelectableEvent &finished, - uint32_t timeout_seconds) { + long timeout_seconds) { swss::Selectable *sel; int ret; @@ -29,115 +27,4 @@ void TestUtils::wait_for_finish(swss::Select &s, EXPECT_EQ(sel, &finished); } -std::string TestUtils::wait_for_state_verification_trigger( - swss::NotificationConsumer &nc, uint32_t timeout_seconds, bool freeze) { - swss::Select s; - s.addSelectable(&nc); - - swss::Selectable *sel; - int ret; - ret = s.select(&sel, timeout_seconds * 1000); - EXPECT_EQ(ret, swss::Select::OBJECT); - if (ret != swss::Select::OBJECT) { - return ""; - } - - std::string op, timestamp_data; - std::vector values; - nc.pop(op, timestamp_data, values); - auto fv = values[0]; - EXPECT_EQ(op, ALL_COMPONENT); - EXPECT_EQ(fvField(fv), FREEZE_FIELD); - EXPECT_EQ(fvValue(fv), freeze ? "true" : "false"); - return timestamp_data; -} - -void TestUtils::confirm_no_state_verification_trigger( - swss::NotificationConsumer &nc, uint32_t timeout_seconds) { - swss::Select s; - s.addSelectable(&nc); - - swss::Selectable *sel; - int ret; - ret = s.select(&sel, timeout_seconds * 1000); - EXPECT_NE(ret, swss::Select::OBJECT); -} - -void TestUtils::populate_registration_table( - swss::DBConnector &db, const std::string &key, const bool &stop_on_freeze, - const bool &freeze, const bool &checkpoint, const bool &reconciliation) { - swss::Table registrationTable(&db, - STATE_WARM_RESTART_REGISTRATION_TABLE_NAME); - - std::string tableName = key; - std::vector values; - - values.push_back(swss::FieldValueTuple("stop_on_freeze", - stop_on_freeze ? "true" : "false")); - values.push_back(swss::FieldValueTuple("freeze", freeze ? "true" : "false")); - values.push_back( - swss::FieldValueTuple("checkpoint", checkpoint ? "true" : "false")); - values.push_back(swss::FieldValueTuple("reconciliation", - reconciliation ? "true" : "false")); - values.push_back(swss::FieldValueTuple("timestamp", swss::getTimestamp())); - - registrationTable.set(tableName, values); -} - -void TestUtils::populate_restart_table_state(swss::DBConnector &db, - const std::string &app_name, - const std::string &state) { - swss::Table warmRestartTable(&db, STATE_WARM_RESTART_TABLE_NAME); - warmRestartTable.hset(app_name, "state", state); -} - -void TestUtils::write_state_verification_result(swss::DBConnector &db, - const std::string &key, - const std::string &status, - const std::string ×tamp) { - swss::Table state_verification_table(&db, STATE_VERIFICATION_RESP_TABLE); - std::vector fvs; - fvs.push_back(swss::FieldValueTuple(TIMESTAMP_FIELD, timestamp)); - fvs.push_back(swss::FieldValueTuple(STATUS_FIELD, status)); - state_verification_table.set(key, fvs); -} - -void TestUtils::clear_tables(swss::DBConnector &db) { - const std::vector kTablesToClear = { - "BOOT_INFO", - STATE_WARM_RESTART_TABLE_NAME, - STATE_WARM_RESTART_REGISTRATION_TABLE_NAME, - STATE_WARM_RESTART_INIT_TABLE_NAME, - STATE_VERIFICATION_RESP_TABLE, - STATE_WARM_RESTART_ENABLE_TABLE_NAME, - STATE_WARM_RESTART_PERF_TABLE_NAME, - STATE_WARM_RESTART_PERF_HISTORY_TABLE_NAME}; - - for (const auto &table_name : kTablesToClear) { - swss::Table table(&db, table_name); - std::vector keys; - table.getKeys(keys); - for (const auto &key : keys) { - table.del(key); - } - } -} - -void TestUtils::check_warmboot_enabled(swss::DBConnector &db, - bool expected_state) { - swss::Table warmRestartTable(&db, STATE_WARM_RESTART_ENABLE_TABLE_NAME); - std::string actual_state; - warmRestartTable.hget("system", "enable", actual_state); - EXPECT_EQ(actual_state, expected_state ? "true" : "false"); -} - -void TestUtils::set_state_verification_enable(swss::DBConnector &config_db, - bool bootup, bool enabled) { - swss::Table warmRestartTable(&config_db, CFG_WARM_RESTART_TABLE_NAME); - warmRestartTable.hset( - "system", - bootup ? "state_verification_bootup" : "state_verification_shutdown", - enabled ? "true" : "false"); -} - } // namespace rebootbackend diff --git a/src/sonic-framework/tests/test_utils_common.h b/src/sonic-framework/tests/test_utils_common.h index 150762e50ad4..fbb7c373acd7 100644 --- a/src/sonic-framework/tests/test_utils_common.h +++ b/src/sonic-framework/tests/test_utils_common.h @@ -15,13 +15,13 @@ namespace rebootbackend { class TestUtils { public: static void wait_for_finish(swss::Select &s, swss::SelectableEvent &finished, - uint32_t timeout_seconds); + long timeout_seconds); static std::string wait_for_state_verification_trigger( - swss::NotificationConsumer &nc, uint32_t timeout_seconds, bool freeze); + swss::NotificationConsumer &nc, long timeout_seconds, bool freeze); static void confirm_no_state_verification_trigger( - swss::NotificationConsumer &nc, uint32_t timeout_seconds); + swss::NotificationConsumer &nc, long timeout_seconds); static void populate_registration_table( swss::DBConnector &db, const std::string &key, const bool &stop_on_freeze, @@ -38,11 +38,7 @@ class TestUtils { static void clear_tables(swss::DBConnector &db); - static void check_warmboot_enabled(swss::DBConnector &db, - bool expected_state); - static void set_state_verification_enable(swss::DBConnector &db, bool bootup, - bool enabled); }; } // namespace rebootbackend