From a7affe7d012e9e5845dffad488be17e7be38fee3 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Verma Date: Thu, 14 Nov 2024 08:15:44 -0800 Subject: [PATCH] Bind ASIC database instances to midplane IPs --- files/build_templates/docker_image_ctl.j2 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 67add27cea53..0eeff3b5f4b5 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -157,6 +157,7 @@ function waitForAllInstanceDatabaseConfigJsonFilesReady() function postStartAction() { {%- if docker_container_name == "database" %} + midplane_ip="" CHASSISDB_CONF="/usr/share/sonic/device/$PLATFORM/chassisdb.conf" [ -f $CHASSISDB_CONF ] && source $CHASSISDB_CONF if [[ "$DEV" && $DATABASE_TYPE != "dpudb" ]]; then @@ -198,6 +199,11 @@ function postStartAction() ip netns exec "$NET_NS" ip addr add $slot_ip_address/$slot_subnet_mask dev eth1 ip netns exec "$NET_NS" ip link set dev eth1 up + # Don't run for supervisor + if [[ "${slot_id}" != "${supervisor_slot_id}" ]]; then + midplane_ip=$slot_ip_address + fi + # Allow localnet routing on the new interfaces if midplane is using a # subnet in the 127/8 range. if [[ "${midplane_subnet#127}" != "$midplane_subnet" ]]; then @@ -300,6 +306,14 @@ function postStartAction() REDIS_BMP_SOCK="/var/run/redis/redis_bmp.sock" chgrp -f redis $REDIS_SOCK && chmod -f 0760 $REDIS_SOCK chgrp -f redis $REDIS_BMP_SOCK && chmod -f 0760 $REDIS_BMP_SOCK + + if [[ $DEV && $midplane_ip ]]; then + IFS=_ read ip port < <(jq -r '.INSTANCES | [.redis.hostname, .redis.port] | join("_")' /var/run/redis$DEV/sonic-db/database_config.json) + bound_ips=$(redis-cli --raw -h $ip -p $port config get bind | sed -n '2,2 p') + redis-cli -h $ip -p $port config set bind "$bound_ips $midplane_ip" + redis-cli -h $ip -p $port config rewrite + fi + {%- elif docker_container_name == "swss" %} # Wait until swss container state is Running until [[ ($(docker inspect -f {{"'{{.State.Running}}'"}} swss$DEV) == "true") ]]; do