From d219d4a4d2a6b41e4145c5228fd26e8702491914 Mon Sep 17 00:00:00 2001 From: Changrong Wu Date: Mon, 23 Dec 2024 15:35:37 -0800 Subject: [PATCH] [Bug Fix] docker_image_ctl.j2: remove the logic that recreates database containers on VS platform (#21089) Why I did it To support the emulation of VS chassis, we need to remove the existing critical service containers before transforming the HwSKU of the VS device. A previous PR #18512 introduced a change to the docker_image_ctl.j2 that forces VS images to recreate database containers every time the OS is cold started while the behaviors of other containers(swss/bgp/teamd/syncd) remained unchanged. As a consequence, when the VS device is rebooted without proper human intervention, the database containers will be recreated while the other services will reuse existing containers. That can cause the swss/bgp/syncd containers to become invalid if the database containers get recreated with a different container ID, because swss/bgp/syncd containers are configured to use the database containers as the underlying networking stack. By further investigation, we have found that it is not necessary to recreate the database containers in /usr/bin/database.sh to perform HwSKU transformation. So, we should remove this logic. --- files/build_templates/docker_image_ctl.j2 | 39 ++++++++++------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index c1cd8e94c8fa..c3a5f2048ae6 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -445,33 +445,28 @@ start() { DOCKERCHECK=`docker inspect --type container ${DOCKERNAME} 2>/dev/null` if [ "$?" -eq "0" ]; then - {%- if docker_container_name == "database" and sonic_asic_platform == "vs" %} - echo "Removing existing ${DOCKERNAME} container" - docker rm -f ${DOCKERNAME} + {%- if docker_container_name == "database" %} + DOCKERMOUNT="" {%- else %} + DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"` + {%- endif %} + if [ x"$DOCKERMOUNT" == x"$MOUNTPATH" ]; then + CONTAINER_EXISTS="yes" + preStartAction {%- if docker_container_name == "database" %} - DOCKERMOUNT="" + echo "Starting existing ${DOCKERNAME} container" + docker start ${DOCKERNAME} {%- else %} - DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"` + echo "Starting existing ${DOCKERNAME} container with HWSKU $HWSKU" + /usr/local/bin/container start ${DOCKERNAME} {%- endif %} - if [ x"$DOCKERMOUNT" == x"$MOUNTPATH" ]; then - CONTAINER_EXISTS="yes" - preStartAction - {%- if docker_container_name == "database" %} - echo "Starting existing ${DOCKERNAME} container" - docker start ${DOCKERNAME} - {%- else %} - echo "Starting existing ${DOCKERNAME} container with HWSKU $HWSKU" - /usr/local/bin/container start ${DOCKERNAME} - {%- endif %} - postStartAction - exit $? - fi + postStartAction + exit $? + fi - # docker created with a different HWSKU, remove and recreate - echo "Removing obsolete ${DOCKERNAME} container with HWSKU $DOCKERMOUNT" - docker rm -f ${DOCKERNAME} - {%- endif %} + # docker created with a different HWSKU, remove and recreate + echo "Removing obsolete ${DOCKERNAME} container with HWSKU $DOCKERMOUNT" + docker rm -f ${DOCKERNAME} fi {%- if docker_container_name == "database" %}