From 3a2b8c6ba5d6e05630b0897b32d862d3cb64aa4a Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Sun, 11 Jul 2021 16:58:05 +0300 Subject: [PATCH] [SONiC Application Extension] support warm/fast reboot for extension packages (#7286) #### Why I did it I made this change to support warm/fast reboot for SONiC extension packages as per HLD Azure/SONiC#682. #### How I did it I extended manifest.json.j2 with new warm/fast reboot related fields and also extended sonic_debian_extension.j2 script template to generate the shutdown order files for warm and fast reboot. --- files/build_templates/manifest.json.j2 | 10 +++++++++- files/build_templates/sonic_debian_extension.j2 | 3 +++ .../warmboot-finalizer/finalize-warmboot.sh | 7 +++++++ rules/docker-fpm-frr.mk | 4 ++++ rules/docker-lldp.mk | 2 ++ rules/docker-nat.mk | 2 ++ rules/docker-orchagent.mk | 2 ++ rules/docker-router-advertiser.mk | 2 ++ rules/docker-sflow.mk | 2 ++ rules/docker-teamd.mk | 3 +++ rules/functions | 4 ++++ 11 files changed, 40 insertions(+), 1 deletion(-) diff --git a/files/build_templates/manifest.json.j2 b/files/build_templates/manifest.json.j2 index 5b09e1d987..9f3e872d2e 100644 --- a/files/build_templates/manifest.json.j2 +++ b/files/build_templates/manifest.json.j2 @@ -12,7 +12,15 @@ "before": {{ before.split()|json if before is defined else [] }}, "dependent-of": {{ dependent_of.split()|json if dependent_of is defined else [] }}, "asic-service": {{ asic_service }}, - "host-service": {{ host_service }} + "host-service": {{ host_service }}, + "warm-shutdown": { + "after": {{ warm_shutdown_after.split()|json if warm_shutdown_after is defined else [] }}, + "before": {{ warm_shutdown_before.split()|json if warm_shutdown_before is defined else [] }} + }, + "fast-shutdown": { + "after": {{ fast_shutdown_after.split()|json if fast_shutdown_after is defined else [] }}, + "before": {{ fast_shutdown_before.split()|json if fast_shutdown_before is defined else [] }} + } }, "container": { "privileged": {{ privileged if privileged else 'false' }}, diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 702e4a712d..03fa16d260 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -676,6 +676,9 @@ fi # Copy docker_image_ctl.j2 for SONiC Package Manager sudo cp $BUILD_TEMPLATES/docker_image_ctl.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/docker_image_ctl.j2 +# Generate shutdown order +sudo LANG=C chroot $FILESYSTEM_ROOT /usr/local/bin/generate_shutdown_order.py + {% if include_kubernetes == "y" %} ## Pull in kubernetes docker images echo "pulling universal k8s images ..." diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 172fd95ab2..2649e51b0d 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -11,6 +11,13 @@ declare -A RECONCILE_COMPONENTS=( \ ["bgp"]="bgp" \ ["nat"]="natsyncd" \ ) + +for reconcile_file in $(find /etc/sonic/ -iname '*_reconcile' -type f); do + file_basename=$(basename $reconcile_file) + docker_container_name=${file_basename%_reconcile} + RECONCILE_COMPONENTS[$docker_container_name]=$(cat $reconcile_file) +done + EXP_STATE="reconciled" ASSISTANT_SCRIPT="/usr/local/bin/neighbor_advertiser" diff --git a/rules/docker-fpm-frr.mk b/rules/docker-fpm-frr.mk index d7b38405cb..37c3a62f18 100644 --- a/rules/docker-fpm-frr.mk +++ b/rules/docker-fpm-frr.mk @@ -18,6 +18,10 @@ $(DOCKER_FPM_FRR)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) $(DOCKER_FPM_FRR)_VERSION = 1.0.0 $(DOCKER_FPM_FRR)_PACKAGE_NAME = fpm-frr +$(DOCKER_FPM_FRR)_WARM_SHUTDOWN_BEFORE = swss +$(DOCKER_FPM_FRR)_WARM_SHUTDOWN_AFTER = radv +$(DOCKER_FPM_FRR)_FAST_SHUTDOWN_BEFORE = swss +$(DOCKER_FPM_FRR)_FAST_SHUTDOWN_AFTER = radv SONIC_DOCKER_IMAGES += $(DOCKER_FPM_FRR) diff --git a/rules/docker-lldp.mk b/rules/docker-lldp.mk index f2432ab633..2c3d41a46d 100644 --- a/rules/docker-lldp.mk +++ b/rules/docker-lldp.mk @@ -18,6 +18,8 @@ $(DOCKER_LLDP)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) $(DOCKER_LLDP)_VERSION = 1.0.0 $(DOCKER_LLDP)_PACKAGE_NAME = lldp +$(DOCKER_LLDP)_WARM_SHUTDOWN_BEFORE = swss +$(DOCKER_LLDP)_FAST_SHUTDOWN_BEFORE = swss SONIC_DOCKER_IMAGES += $(DOCKER_LLDP) SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_LLDP) diff --git a/rules/docker-nat.mk b/rules/docker-nat.mk index 6c958bb8ec..b5ead85d19 100644 --- a/rules/docker-nat.mk +++ b/rules/docker-nat.mk @@ -15,6 +15,8 @@ $(DOCKER_NAT)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) $(DOCKER_NAT)_VERSION = 1.0.0 $(DOCKER_NAT)_PACKAGE_NAME = nat +$(DOCKER_NAT)_WARM_SHUTDOWN_BEFORE = swss +$(DOCKER_NAT)_FAST_SHUTDOWN_BEFORE = swss ifeq ($(INCLUDE_NAT), y) SONIC_DOCKER_IMAGES += $(DOCKER_NAT) diff --git a/rules/docker-orchagent.mk b/rules/docker-orchagent.mk index f545a64cb9..3273b67590 100644 --- a/rules/docker-orchagent.mk +++ b/rules/docker-orchagent.mk @@ -19,6 +19,8 @@ $(DOCKER_ORCHAGENT)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) $(DOCKER_ORCHAGENT)_VERSION = 1.0.0 $(DOCKER_ORCHAGENT)_PACKAGE_NAME = swss +$(DOCKER_ORCHAGENT)_WARM_SHUTDOWN_BEFORE = syncd +$(DOCKER_ORCHAGENT)_FAST_SHUTDOWN_BEFORE = syncd SONIC_DOCKER_IMAGES += $(DOCKER_ORCHAGENT) SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_ORCHAGENT) diff --git a/rules/docker-router-advertiser.mk b/rules/docker-router-advertiser.mk index 083c83dbb6..14c896d820 100644 --- a/rules/docker-router-advertiser.mk +++ b/rules/docker-router-advertiser.mk @@ -15,6 +15,8 @@ $(DOCKER_ROUTER_ADVERTISER)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE_BUSTER) $(DOCKER_ROUTER_ADVERTISER)_VERSION = 1.0.0 $(DOCKER_ROUTER_ADVERTISER)_PACKAGE_NAME = radv +$(DOCKER_ROUTER_ADVERTISER)_WARM_SHUTDOWN_BEFORE = swss +$(DOCKER_ROUTER_ADVERTISER)_FAST_SHUTDOWN_BEFORE = swss SONIC_DOCKER_IMAGES += $(DOCKER_ROUTER_ADVERTISER) SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_ROUTER_ADVERTISER) diff --git a/rules/docker-sflow.mk b/rules/docker-sflow.mk index 7291e5d216..5762dd869a 100644 --- a/rules/docker-sflow.mk +++ b/rules/docker-sflow.mk @@ -15,6 +15,8 @@ $(DOCKER_SFLOW)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) $(DOCKER_SFLOW)_VERSION = 1.0.0 $(DOCKER_SFLOW)_PACKAGE_NAME = sflow +$(DOCKER_SFLOW)_WARM_SHUTDOWN_BEFORE = swss +$(DOCKER_SFLOW)_FAST_SHUTDOWN_BEFORE = swss SONIC_DOCKER_IMAGES += $(DOCKER_SFLOW) ifeq ($(INCLUDE_SFLOW), y) diff --git a/rules/docker-teamd.mk b/rules/docker-teamd.mk index c6955bea5c..9135c45aea 100644 --- a/rules/docker-teamd.mk +++ b/rules/docker-teamd.mk @@ -17,6 +17,9 @@ $(DOCKER_TEAMD)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) $(DOCKER_TEAMD)_VERSION = 1.0.0 $(DOCKER_TEAMD)_PACKAGE_NAME = teamd +$(DOCKER_TEAMD)_WARM_SHUTDOWN_BEFORE = syncd +$(DOCKER_TEAMD)_WARM_SHUTDOWN_AFTER = swss +$(DOCKER_TEAMD)_FAST_SHUTDOWN_BEFORE = swss SONIC_DOCKER_IMAGES += $(DOCKER_TEAMD) SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_TEAMD) diff --git a/rules/functions b/rules/functions index 84f548218a..5873b2db1b 100644 --- a/rules/functions +++ b/rules/functions @@ -187,6 +187,10 @@ define generate_manifest $(eval export after=$($(1).gz_SERVICE_AFTER)) $(eval export before=$($(1).gz_SERVICE_BEFORE)) $(eval export dependent_of=$($(1).gz_SERVICE_DEPENDENT_OF)) + $(eval export warm_shutdown_after=$($*.gz_WARM_SHUTDOWN_AFTER)) + $(eval export warm_shutdown_before=$($*.gz_WARM_SHUTDOWN_BEFORE)) + $(eval export fast_shutdown_after=$($*.gz_FAST_SHUTDOWN_AFTER)) + $(eval export fast_shutdown_before=$($*.gz_FAST_SHUTDOWN_BEFORE)) $(eval export privileged=$($(1).gz_CONTAINER_PRIVILEGED)) $(eval export volumes=$($(1).gz_CONTAINER_VOLUMES)) $(eval export tmpfs=$($(1).gz_CONTAINER_TMPFS))