From 504c632cc3ca724fefb52b4c30ac9534022da9f3 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 17 Jul 2019 16:37:36 -0700 Subject: [PATCH 01/57] [files]: add namespace synchronization target * create systemd target to start/stop all containers in a specific namespace at once Signed-off-by: Lawrence Lee --- files/build_templates/sonic_debian_extension.j2 | 4 ++++ files/image_config/namespace/namespace@.target | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 files/image_config/namespace/namespace@.target diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 4e81593298f6..d99a6144d0b4 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -387,6 +387,10 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh +# Copy namespace target +sudo cp $IMAGE_CONFIGS/namespace/namespace@.target $FILESYSTEM_ROOT/etc/systemd/system/ +echo "namespace@.target" | sudo tee -a $GENERATED_SERVICE_FILE + # Copy systemd timer configuration # It implements delayed start of services sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT/etc/systemd/system/ diff --git a/files/image_config/namespace/namespace@.target b/files/image_config/namespace/namespace@.target new file mode 100644 index 000000000000..58cef23bf87a --- /dev/null +++ b/files/image_config/namespace/namespace@.target @@ -0,0 +1,9 @@ +[Unit] +Description=Synchronization Target for Individual Namespace +Wants=topology.service +Requires=namespace@i.service +After=topology.service namespace@i.service +PartOf=namespace@%i.service + +[Install] +WantedBy=multi-user.target From 8571864bf6a880dcddc1993ca9c6974f4b6f459b Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 11 Jul 2019 16:58:23 -0700 Subject: [PATCH 02/57] [database docker]: add multi-instance support * add multi-instance option to redis-cli * create database template service * change docker_image_ctl to use new redis sockets * increase database service timeout duration to 120s Signed-off-by: Lawrence Lee --- .../base_image_files/redis-cli | 8 +++++- files/build_templates/docker_image_ctl.j2 | 27 ++++++++++++------- .../multi_instance/database@.service.j2 | 16 +++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 files/build_templates/multi_instance/database@.service.j2 diff --git a/dockers/docker-database/base_image_files/redis-cli b/dockers/docker-database/base_image_files/redis-cli index 6ce1951cd4b9..481cb4542807 100755 --- a/dockers/docker-database/base_image_files/redis-cli +++ b/dockers/docker-database/base_image_files/redis-cli @@ -7,4 +7,10 @@ if [ -t 1 ] ; then DOCKER_EXEC_FLAGS+="t" fi -docker exec -$DOCKER_EXEC_FLAGS database redis-cli "$@" +[ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number +if [ $? -eq 0 ]; then # if it's a number, set the database instance to operate on + DEV="$1" + shift +fi + +docker exec -$DOCKER_EXEC_FLAGS database$DEV redis-cli "$@" diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 167a392730e4..a41d8995b415 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -56,11 +56,11 @@ function preStartAction() WARM_DIR=/host/warmboot if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast") && -f $WARM_DIR/dump.rdb ]]; then # Load redis content from /host/warmboot/dump.rdb - docker cp $WARM_DIR/dump.rdb database:/var/lib/redis/dump.rdb + docker cp $WARM_DIR/dump.rdb database$DEV:/var/lib/redis/dump.rdb else # Create an emtpy file and overwrite any RDB if already there echo -n > /tmp/dump.rdb - docker cp /tmp/dump.rdb database:/var/lib/redis/ + docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/ fi {%- elif docker_container_name == "snmp" %} docker exec -i database redis-cli -n 6 HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) @@ -140,13 +140,15 @@ function postStartAction() { {%- if docker_container_name == "database" %} # Wait until redis starts - /usr/bin/docker exec database ping_pong_db_insts + /usr/bin/docker exec database$DEV ping_pong_db_insts + REDIS_SOCK="/var/run/redis/redis.sock" + EXT_REDIS_SOCK="/var/run/redis$DEV/redis.sock" # location of redis socket in the base image if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast") && -f $WARM_DIR/dump.rdb ]]; then rm -f $WARM_DIR/dump.rdb else # If there is a config db dump file, load it - if [ -r /etc/sonic/config_db.json ]; then - sonic-cfggen -j /etc/sonic/config_db.json --write-to-db + if [ -r /etc/sonic/config_db$DEV.json ]; then + sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db --redis-unix-sock-file $EXT_REDIS_SOCK fi if [[ "$BOOT_TYPE" == "fast" ]]; then @@ -154,12 +156,17 @@ function postStartAction() redis-cli -n 6 SET "FAST_REBOOT|system" "1" "EX" "180" fi - redis-cli -n 4 SET "CONFIG_DB_INITIALIZED" "1" + redis-cli $DEV -n 4 -s $REDIS_SOCK SET "CONFIG_DB_INITIALIZED" "1" fi if [[ -x /usr/bin/db_migrator.py ]]; then # Migrate the DB to the latest schema version if needed - /usr/bin/db_migrator.py -o migrate + /usr/bin/db_migrator.py -o migrate -s $EXT_REDIS_SOCK + + # Save in memory config_db to config_db.json for 2 reasons: + # 1. Persist the DB migration result. + # 2. Save in memory DB after warm reboot. + /usr/bin/config save -y fi {%- elif docker_container_name == "swss" %} docker exec swss rm -f /ready # remove cruft @@ -198,8 +205,8 @@ start() { HWSKU="" {%- else %} # Obtain our HWSKU as we will mount directories with these names in each docker - HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` - HOSTNAME=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hostname"]'` + HWSKU=`sonic-cfggen -d -s /var/run/redis$DEV/redis.sock -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + HOSTNAME=`sonic-cfggen -d -s /var/run/redis$DEV/redis.sock -v 'DEVICE_METADATA["localhost"]["hostname"]'` {%- endif %} if [ -z "$HOSTNAME" ] || ! [[ $HOSTNAME =~ ^[a-zA-Z0-9.\-]*$ ]]; then HOSTNAME=`hostname` @@ -266,7 +273,7 @@ start() { --tmpfs /tmp \ {%- endif %} {%- endif %} - -v /var/run/redis:/var/run/redis:rw \ + -v /var/run/redis$DEV:/var/run/redis:rw\ -v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \ {%- if docker_container_name != "database" %} -v /usr/share/sonic/device/$PLATFORM/$HWSKU:/usr/share/sonic/hwsku:ro \ diff --git a/files/build_templates/multi_instance/database@.service.j2 b/files/build_templates/multi_instance/database@.service.j2 new file mode 100644 index 000000000000..9a828e44c038 --- /dev/null +++ b/files/build_templates/multi_instance/database@.service.j2 @@ -0,0 +1,16 @@ +[Unit] +Description=Database container +Requires=docker.service namespace@%i.service +After=docker.service namespace@%i.service +PartOf=namespace@%i.target + +[Service] +User=root +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i +Restart=on-failure +TimeoutStartSec=120 + +[Install] +RequiredBy=namespace@%i.target From 2245ffe2a5643625e39d9f1ea03f7416beff0eb6 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 13 Jun 2019 10:32:02 -0700 Subject: [PATCH 03/57] [files]: add swss multi-instance support * add instance number option and unix socket option to docker_image_ctl for swss * change swss service to service template * add instance number option and unix socket option to swss.sh * force all redis-cli calls through redis-cli wrapper Signed-off-by: Lawrence Lee --- files/build_templates/docker_image_ctl.j2 | 39 +++++++----- .../multi_instance/swss@.service.j2 | 28 +++++++++ files/scripts/swss.sh | 59 ++++++++++++------- 3 files changed, 90 insertions(+), 36 deletions(-) create mode 100644 files/build_templates/multi_instance/swss@.service.j2 diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index a41d8995b415..04673fb42811 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -169,14 +169,14 @@ function postStartAction() /usr/bin/config save -y fi {%- elif docker_container_name == "swss" %} - docker exec swss rm -f /ready # remove cruft + docker exec swss$DEV rm -f /ready # remove cruft if [[ "$BOOT_TYPE" == "fast" ]] && [[ -d /host/fast-reboot ]]; then - test -e /host/fast-reboot/fdb.json && docker cp /host/fast-reboot/fdb.json swss:/ - test -e /host/fast-reboot/arp.json && docker cp /host/fast-reboot/arp.json swss:/ - test -e /host/fast-reboot/default_routes.json && docker cp /host/fast-reboot/default_routes.json swss:/ + test -e /host/fast-reboot/fdb.json && docker cp /host/fast-reboot/fdb.json swss$DEV:/ + test -e /host/fast-reboot/arp.json && docker cp /host/fast-reboot/arp.json swss$DEV:/ + test -e /host/fast-reboot/default_routes.json && docker cp /host/fast-reboot/default_routes.json swss$DEV:/ rm -fr /host/fast-reboot fi - docker exec swss touch /ready # signal swssconfig.sh to go + docker exec swss$DEV touch /ready # signal swssconfig.sh to go {%- elif docker_container_name == "pmon" %} DEVPATH="/usr/share/sonic/device" @@ -212,18 +212,19 @@ start() { HOSTNAME=`hostname` fi - DOCKERCHECK=`docker inspect --type container {{docker_container_name}} 2>/dev/null` - if [ "$?" -eq "0" ]; then - {%- if docker_container_name == "database" %} + + DOCKERCHECK=`docker inspect --type container {{docker_container_name}}$DEV 2>/dev/null` + if [ "$?" -eq "0" ]; then + {%- if docker_container_name == "database" %} DOCKERMOUNT="" - {%- else %} + {%- else %} DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"` - {%- endif %} - if [ x"$DOCKERMOUNT" == x"$HWSKU" ]; then - {%- if docker_container_name == "database" %} - echo "Starting existing {{docker_container_name}} container" - {%- else %} - echo "Starting existing {{docker_container_name}} container with HWSKU $HWSKU" + {%- endif %} + if [ x"$DOCKERMOUNT" == x"$HWSKU" ]; then + {%- if docker_container_name == "database" %} + echo "Starting existing {{docker_container_name}}$DEV container" + {%- else %} + echo "Starting existing {{docker_container_name}}$DEV container with HWSKU $HWSKU" {%- endif %} preStartAction docker start {{docker_container_name}} @@ -298,9 +299,15 @@ wait() { } stop() { - docker stop {{docker_container_name}} + docker stop {{docker_container_name}}$DEV + {%- if docker_container_name == "namespace" %} + ip netns delete "{{docker_container_name}}$DEV" + {%- endif %} } +OP=$1 # operation to perform (start/wait/stop) +DEV=$2 # namespace/device number to operate on + case "$1" in start|wait|stop|updateHostName) cmd=$1 diff --git a/files/build_templates/multi_instance/swss@.service.j2 b/files/build_templates/multi_instance/swss@.service.j2 new file mode 100644 index 000000000000..e65f09cd8f74 --- /dev/null +++ b/files/build_templates/multi_instance/swss@.service.j2 @@ -0,0 +1,28 @@ +[Unit] +Description=switch state service +Requires=database@%i.service +#updategraph.service +{% if sonic_asic_platform == 'broadcom' %} +Requires=opennsl-modules.service +{% elif sonic_asic_platform == 'nephos' %} +Requires=nps-modules-4.9.0-9-2-amd64.service +{% endif %} +After=database@%i.service +#updategraph.service +After=interfaces-config.service +Before=ntp-config.service +PartOf=namespace@%i.target +StartLimitIntervalSec=1200 +StartLimitBurst=3 + +[Service] +User=root +Environment=sonic_asic_platform={{ sonic_asic_platform }} +ExecStartPre=/usr/local/bin/swss.sh start %i +ExecStart=/usr/local/bin/swss.sh wait %i +ExecStop=/usr/local/bin/swss.sh stop %i +Restart=always +RestartSec=30 + +[Install] +RequiredBy=namespace@%i.target diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 7dde4aecb365..5ac9494672b4 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -1,10 +1,6 @@ #!/bin/bash -SERVICE="swss" -PEER="syncd" DEPENDENT="teamd radv dhcp_relay" -DEBUGLOG="/tmp/swss-syncd-debug.log" -LOCKFILE="/tmp/swss-syncd-lock" function debug() { @@ -31,8 +27,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`/usr/bin/redis-cli $DEV -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`/usr/bin/redis-cli $DEV -n 6 hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" else @@ -43,7 +39,7 @@ function check_warm_boot() function validate_restore_count() { if [[ x"$WARM_BOOT" == x"true" ]]; then - RESTORE_COUNT=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_TABLE|orchagent" restore_count` + RESTORE_COUNT=`/usr/bin/redis-cli $DEV -n 6 hget "WARM_RESTART_TABLE|orchagent" restore_count` # We have to make sure db data has not been flushed. if [[ -z "$RESTORE_COUNT" ]]; then WARM_BOOT="false" @@ -54,12 +50,12 @@ function validate_restore_count() function wait_for_database_service() { # Wait for redis server start before database clean - until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; + until [[ $(/usr/bin/redis-cli $DEV ping | grep -c PONG) -gt 0 ]]; do sleep 1; done # Wait for configDB initialization - until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(/usr/bin/redis-cli $DEV -n 4 GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -69,7 +65,7 @@ function wait_for_database_service() # $2 the string of a list of table prefixes function clean_up_tables() { - redis-cli -n $1 EVAL " + redis-cli $DEV -n $1 EVAL " local tables = {$2} for i = 1, table.getn(tables) do local matches = redis.call('KEYS', tables[i]) @@ -83,7 +79,11 @@ start_peer_and_dependent_services() { check_warm_boot if [[ x"$WARM_BOOT" != x"true" ]]; then - /bin/systemctl start ${PEER} + if [[ ! -z $DEV ]]; then + /bin/systemctl start ${PEER}@$DEV + else + /bin/systemctl start ${PEER} + fi for dep in ${DEPENDENT}; do /bin/systemctl start ${dep} done @@ -93,7 +93,11 @@ start_peer_and_dependent_services() { stop_peer_and_dependent_services() { # if warm start enabled or peer lock exists, don't stop peer service docker if [[ x"$WARM_BOOT" != x"true" ]]; then - /bin/systemctl stop ${PEER} + if [[ ! -z $DEV ]]; then + /bin/systemctl stop ${PEER}@$DEV + else + /bin/systemctl stop ${PEER} + fi for dep in ${DEPENDENT}; do /bin/systemctl stop ${dep} done @@ -114,15 +118,15 @@ start() { # Don't flush DB during warm boot if [[ x"$WARM_BOOT" != x"true" ]]; then debug "Flushing APP, ASIC, COUNTER, CONFIG, and partial STATE databases ..." - /usr/bin/docker exec database redis-cli -n 0 FLUSHDB - /usr/bin/docker exec database redis-cli -n 1 FLUSHDB - /usr/bin/docker exec database redis-cli -n 2 FLUSHDB - /usr/bin/docker exec database redis-cli -n 5 FLUSHDB + /usr/bin/redis-cli $DEV -n 0 FLUSHDB + /usr/bin/redis-cli $DEV -n 1 FLUSHDB + /usr/bin/redis-cli $DEV -n 2 FLUSHDB + /usr/bin/redis-cli $DEV -n 5 FLUSHDB clean_up_tables 6 "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*'" fi # start service docker - /usr/bin/${SERVICE}.sh start + /usr/bin/${SERVICE}.sh start $DEV debug "Started ${SERVICE} service..." # Unlock has to happen before reaching out to peer service @@ -136,7 +140,11 @@ wait() { # NOTE: This assumes Docker containers share the same names as their # corresponding services for SECS in {1..60}; do - RUNNING=$(docker inspect -f '{{.State.Running}}' ${PEER}) + if [[ ! -z $DEV ]]; then + RUNNING=$(docker inspect -f '{{.State.Running}}' ${PEER}@$DEV) + else + RUNNING=$(docker inspect -f '{{.State.Running}}' ${PEER}) + fi if [[ x"$RUNNING" == x"true" ]]; then break else @@ -146,7 +154,11 @@ wait() { # NOTE: This assumes Docker containers share the same names as their # corresponding services - /usr/bin/docker-wait-any ${SERVICE} ${PEER} + if [[ ! -z $DEV ]]; then + /usr/bin/docker-wait-any ${SERVICE} ${PEER}@$DEV + else + /usr/bin/docker-wait-any ${SERVICE} ${PEER} + fi } stop() { @@ -158,7 +170,7 @@ stop() { check_warm_boot debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." - /usr/bin/${SERVICE}.sh stop + /usr/bin/${SERVICE}.sh stop $DEV debug "Stopped ${SERVICE} service..." # Unlock has to happen before reaching out to peer service @@ -167,6 +179,13 @@ stop() { stop_peer_and_dependent_services } +DEV=$2 + +SERVICE="swss" +PEER="syncd" +DEBUGLOG="/tmp/swss-syncd-debug$DEV.log" +LOCKFILE="/tmp/swss-syncd-lock$DEV" + case "$1" in start|wait|stop) $1 From 193f182ae9295b02369c9c5be5165d8ab521b172 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 17 Jul 2019 13:29:08 -0700 Subject: [PATCH 04/57] [files]: add multi-instance support for syncd * add syncd service template * add instance number argument for syncd script --- .../multi_instance/syncd@.service.j2 | 32 +++++++++++++++++++ files/scripts/syncd.sh | 32 +++++++++++-------- 2 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 files/build_templates/multi_instance/syncd@.service.j2 diff --git a/files/build_templates/multi_instance/syncd@.service.j2 b/files/build_templates/multi_instance/syncd@.service.j2 new file mode 100644 index 000000000000..448f42c50682 --- /dev/null +++ b/files/build_templates/multi_instance/syncd@.service.j2 @@ -0,0 +1,32 @@ +[Unit] +Description=syncd service +Requires=database@%i.service +#updategraph.service +{% if sonic_asic_platform == 'broadcom' %} +Requires=opennsl-modules.service +{% elif sonic_asic_platform == 'nephos' %} +Requires=nps-modules-4.9.0-8-2-amd64.service +{% endif %} +After=database.service +#updategraph.service +After=interfaces-config.service +{% if sonic_asic_platform == 'broadcom' %} +After=opennsl-modules.service +{% elif sonic_asic_platform == 'nephos' %} +After=nps-modules-4.9.0-8-2-amd64.service +{% endif %} +After=swss@%i.service +Before=ntp-config.service + +[Service] +User=root +Environment=sonic_asic_platform={{ sonic_asic_platform }} +ExecStartPre=/usr/local/bin/syncd.sh start %i +ExecStart=/usr/local/bin/syncd.sh wait %i +ExecStop=/usr/local/bin/syncd.sh stop %i +{% if sonic_asic_platform == 'mellanox' %} +TimeoutStartSec=150 +{% endif %} + +[Install] +WantedBy=multi-user.target diff --git a/files/scripts/syncd.sh b/files/scripts/syncd.sh index 89f15f0f413f..c6dad77f9bfd 100755 --- a/files/scripts/syncd.sh +++ b/files/scripts/syncd.sh @@ -1,9 +1,5 @@ #!/bin/bash -SERVICE="syncd" -PEER="swss" -DEBUGLOG="/tmp/swss-syncd-debug.log" -LOCKFILE="/tmp/swss-syncd-lock" function debug() { @@ -30,8 +26,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`/usr/bin/redis-cli $DEV -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`/usr/bin/redis-cli $DEV -n 6 hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` # SYSTEM_WARM_START could be empty, always make WARM_BOOT meaningful. if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" @@ -43,12 +39,12 @@ function check_warm_boot() function wait_for_database_service() { # Wait for redis server start before database clean - until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; + until [[ $(/usr/bin/redis-cli $DEV ping | grep -c PONG) -gt 0 ]]; do sleep 1; done # Wait for configDB initialization - until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(/usr/bin/redis-cli $DEV -n 4 GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -130,7 +126,7 @@ start() { fi # start service docker - /usr/bin/${SERVICE}.sh start + /usr/bin/${SERVICE}.sh start $DEV debug "Started ${SERVICE} service..." unlock_service_state_change @@ -142,7 +138,7 @@ wait() { /bin/systemctl start pmon debug "Started pmon service" fi - /usr/bin/${SERVICE}.sh wait + /usr/bin/${SERVICE}.sh wait $DEV } stop() { @@ -166,18 +162,18 @@ stop() { if [[ x$sonic_asic_platform != x"mellanox" ]] || [[ x$TYPE != x"cold" ]]; then debug "${TYPE} shutdown syncd process ..." - /usr/bin/docker exec -i syncd /usr/bin/syncd_request_shutdown --${TYPE} + /usr/bin/docker exec -i syncd$DEV /usr/bin/syncd_request_shutdown --${TYPE} # wait until syncd quits gracefully - while docker top syncd | grep -q /usr/bin/syncd; do + while docker top syncd$DEV | grep -q /usr/bin/syncd; do sleep 0.1 done - /usr/bin/docker exec -i syncd /bin/sync + /usr/bin/docker exec -i syncd$DEV /bin/sync debug "Finished ${TYPE} shutdown syncd process ..." fi - /usr/bin/${SERVICE}.sh stop + /usr/bin/${SERVICE}.sh stop $DEV debug "Stopped ${SERVICE} service..." # platform specific tasks @@ -195,6 +191,14 @@ stop() { unlock_service_state_change } +OP=$1 +DEV=$2 + +SERVICE="syncd" +PEER="swss" +DEBUGLOG="/tmp/swss-syncd-debug$DEV.log" +LOCKFILE="/tmp/swss-syncd-lock$DEV" + case "$1" in start|wait|stop) $1 From aa44fdac5d6665193c15cf4a76bc977fe3d9ab8f Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Mon, 17 Jun 2019 13:18:06 -0700 Subject: [PATCH 05/57] [files]: add multi-instance support to logging * add rsyslog service template compatible with network namespaces * change rsyslog_config to use database instance unix socket Signed-off-by: Lawrence Lee (cherry picked from commit e871f11b1269ff929dfda11f5c6b6d7d9600b3ca) --- files/build_templates/sonic_debian_extension.j2 | 4 ++++ files/image_config/rsyslog/rsyslog-config.sh | 2 +- files/image_config/rsyslog/rsyslog-config@.service | 14 ++++++++++++++ files/image_config/rsyslog/rsyslog@.service | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 files/image_config/rsyslog/rsyslog-config@.service create mode 100644 files/image_config/rsyslog/rsyslog@.service diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index d99a6144d0b4..ebb63236f904 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -186,10 +186,14 @@ echo "warmboot-finalizer.service" | sudo tee -a $GENERATED_SERVICE_FILE # Copy rsyslog configuration files and templates sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.service $FILESYSTEM_ROOT/etc/systemd/system/ +sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config@.service $FILESYSTEM_ROOT/etc/systemd/system/ +sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog@.service $FILESYSTEM_ROOT/etc/systemd/system sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.d/* $FILESYSTEM_ROOT/etc/rsyslog.d/ echo "rsyslog-config.service" | sudo tee -a $GENERATED_SERVICE_FILE +echo "rsyslog-config@.service" | sudo tee -a $GENERATED_SERVICE_FILE +echo "rsyslog@.service" | sudo tee -a $GENERATED_SERVICE_FILE # Copy logrotate.d configuration files sudo cp -f $IMAGE_CONFIGS/logrotate/logrotate.d/* $FILESYSTEM_ROOT/etc/logrotate.d/ diff --git a/files/image_config/rsyslog/rsyslog-config.sh b/files/image_config/rsyslog/rsyslog-config.sh index c8ba7b99453c..83f556cee42b 100755 --- a/files/image_config/rsyslog/rsyslog-config.sh +++ b/files/image_config/rsyslog/rsyslog-config.sh @@ -1,4 +1,4 @@ #!/bin/bash -sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog.conf +sonic-cfggen -s /var/run/redis$1/redis.sock -d -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog$1.conf systemctl restart rsyslog diff --git a/files/image_config/rsyslog/rsyslog-config@.service b/files/image_config/rsyslog/rsyslog-config@.service new file mode 100644 index 000000000000..9f8d03345b8f --- /dev/null +++ b/files/image_config/rsyslog/rsyslog-config@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Update rsyslog configuration +Requires=database@%i.service +After=database@%i.service +#Requires=updategraph.service +#After=updategraph.service +PartOf=namespace@%i.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/rsyslog-config.sh %i + +[Install] +RequiredBy=namespace@%i.target diff --git a/files/image_config/rsyslog/rsyslog@.service b/files/image_config/rsyslog/rsyslog@.service new file mode 100644 index 000000000000..36841652026f --- /dev/null +++ b/files/image_config/rsyslog/rsyslog@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Network Namespace Compatible Logging Service +Requires=syslog.socket +After=rsyslog-config@%i.service + +[Service] +Type=notify +User=root +ExecStart=/bin/ip netns exec namespace%i /usr/sbin/rsyslogd -n -i /var/run/rsyslogd%i.pid -f /etc/rsyslog%i.conf +StandardOutput=null +Restart=on-failure + +[Install] +WantedBy=multi-user.target From f4844e80550c713fdbe095ce7011bb9e7415c943 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Tue, 18 Jun 2019 15:40:30 -0700 Subject: [PATCH 06/57] [files]: add namespace wrapper * add wrapper for 'sudo ip netns exec' command Signed-off-by: Lawrence Lee (cherry picked from commit 85745b7f01cccea23058d0eeaa943bd6f1ef538c) --- files/build_templates/sonic_debian_extension.j2 | 3 +++ files/scripts/namespace.sh | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100755 files/scripts/namespace.sh diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index ebb63236f904..d45a1acbb0da 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -391,6 +391,9 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh +# Copy network namespace wrapper script +sudo LANG=C cp $SCRIPTS_DIR/namespace.sh $FILESYSTEM_ROOT/usr/local/bin/namespace + # Copy namespace target sudo cp $IMAGE_CONFIGS/namespace/namespace@.target $FILESYSTEM_ROOT/etc/systemd/system/ echo "namespace@.target" | sudo tee -a $GENERATED_SERVICE_FILE diff --git a/files/scripts/namespace.sh b/files/scripts/namespace.sh new file mode 100755 index 000000000000..caf4dc57d729 --- /dev/null +++ b/files/scripts/namespace.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +NS=$1 +shift + +sudo ip netns exec namespace$NS $@ From a13a8d89d4c9cfe8507724dce47076d20a9c1ab4 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 17 Jul 2019 13:41:45 -0700 Subject: [PATCH 07/57] [platform/vs]: add memory to virtual switch * increase from 2GB to 8GB to prevent OOM crashes * necessary because multi-ASIC devices have increased memory requirements Signed-off-by: Lawrence Lee (cherry picked from commit 845778eaeca731f4cc9c2a22f45325cd43d67724) --- platform/vs/sonic.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platform/vs/sonic.xml b/platform/vs/sonic.xml index ebf9f542607f..9d72d0e91f74 100644 --- a/platform/vs/sonic.xml +++ b/platform/vs/sonic.xml @@ -1,8 +1,7 @@ sonic - 2048000 - 2048000 - 1 + 8 + 2 /machine From f99839b7d5ed8e6d6ad0b428740c5ca6189449b7 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 20 Jun 2019 14:33:19 -0700 Subject: [PATCH 08/57] [build_templates]: add multi-namespace spport to bgp * add bgp service template * create /etc/sonic/frr* for multiple instances of bgp docker container [frr docker]: add multi-ASIC support to bgpd.conf * add `redistribute connected` option to advertise routes to local interfaces * add `all` option to next-hop-self * add route-map to hide internal routes * add route-map to allow duplicate frontend router id Signed-off-by: Lawrence Lee (cherry picked from commit 4ea01b738510aa652f5b5a56b0f2c50f15b6c221) --- dockers/docker-fpm-frr/bgpd.conf.default.j2 | 20 +++++++++++++++++++ files/build_templates/docker_image_ctl.j2 | 5 ++++- .../multi_instance/bgp@.service.j2 | 17 ++++++++++++++++ .../build_templates/sonic_debian_extension.j2 | 8 ++++++++ rules/docker-fpm-frr.mk | 1 - 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 files/build_templates/multi_instance/bgp@.service.j2 diff --git a/dockers/docker-fpm-frr/bgpd.conf.default.j2 b/dockers/docker-fpm-frr/bgpd.conf.default.j2 index e12782b035aa..2bf80b80a787 100644 --- a/dockers/docker-fpm-frr/bgpd.conf.default.j2 +++ b/dockers/docker-fpm-frr/bgpd.conf.default.j2 @@ -23,6 +23,20 @@ route-map TO_BGP_PEER_V4 permit 100 ! route-map TO_BGP_PEER_V6 permit 100 ! +{% if DEVICE_METADATA['localhost']['type'] == 'InternalFrontend' %} +route-map HIDE_INTERNAL permit 10 + set community local-AS +! +{% endif %} +{% if DEVICE_METADATA['localhost']['type'] == 'InternalBackend' %} +route-map OVERRIDE_ORIGINATOR_ID permit 10 +{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %} +{% if prefix | ipv4 and name == 'Loopback0' %} + set originator-id {{ prefix | ip }} +{% endif %} +{% endfor %} +! +{% endif %} {% if BGP_MONITORS is defined and BGP_MONITORS|length > 0 %} route-map FROM_BGPMON deny 10 ! @@ -37,6 +51,9 @@ route-map set-next-hop-global-v6 permit 10 set ipv6 next-hop prefer-global ! router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} +{% if DEVICE_METADATA['localhost']['type'] == 'InternalFrontend' %} + redistribute connected route-map HIDE_INTERNAL +{% endif %} bgp log-neighbor-changes bgp bestpath as-path multipath-relax no bgp default ipv4-unicast @@ -151,6 +168,9 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} neighbor {{ neighbor_addr }} peer-group BGPMON neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }} neighbor {{ neighbor_addr }} activate +{% if DEVICE_METADATA['localhost']['type'] == 'InternalBackend' %} + neighbor {{ neighbor_addr }} route-map OVERRIDE_ORIGINATOR_ID in +{% endif %} address-family ipv6 neighbor {{ neighbor_addr }} activate exit-address-family diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 04673fb42811..90814c484e3d 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -274,7 +274,10 @@ start() { --tmpfs /tmp \ {%- endif %} {%- endif %} - -v /var/run/redis$DEV:/var/run/redis:rw\ +{%- if docker_container_name == "bgp" %} + -v /etc/sonic/frr$DEV:/etc/frr:rw \ +{%- endif %} + -v /var/run/redis$DEV:/var/run/redis:rw \ -v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \ {%- if docker_container_name != "database" %} -v /usr/share/sonic/device/$PLATFORM/$HWSKU:/usr/share/sonic/hwsku:ro \ diff --git a/files/build_templates/multi_instance/bgp@.service.j2 b/files/build_templates/multi_instance/bgp@.service.j2 new file mode 100644 index 000000000000..0d2ea1e7494a --- /dev/null +++ b/files/build_templates/multi_instance/bgp@.service.j2 @@ -0,0 +1,17 @@ +[Unit] +Description=BGP container +#Requires=updategraph.service +#After=updategraph.service +After=database@%i.service +Requires=database@%i.service +Before=ntp-config.service +PartOf=namespace@%i.target + +[Service] +User=root +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i + +[Install] +RequiredBy=namespace@%i.target diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index d45a1acbb0da..a9702c50d0e3 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -432,6 +432,14 @@ sudo rm -rf $FILESYSTEM_ROOT/$MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME {% endif %} {%- if SONIC_ROUTING_STACK == "frr" %} + {% for i in range(6) %} +sudo mkdir $FILESYSTEM_ROOT/etc/sonic/frr{{i}} +sudo touch $FILESYSTEM_ROOT/etc/sonic/frr{{i}}/frr.conf +sudo touch $FILESYSTEM_ROOT/etc/sonic/frr{{i}}/vtysh.conf +sudo chown -R $FRR_USER_UID:$FRR_USER_GID $FILESYSTEM_ROOT/etc/sonic/frr{{i}} +sudo chmod -R 640 $FILESYSTEM_ROOT/etc/sonic/frr{{i}}/ +sudo chmod 750 $FILESYSTEM_ROOT/etc/sonic/frr{{i}} + {%- endfor %} sudo mkdir $FILESYSTEM_ROOT/etc/sonic/frr sudo touch $FILESYSTEM_ROOT/etc/sonic/frr/frr.conf sudo touch $FILESYSTEM_ROOT/etc/sonic/frr/vtysh.conf diff --git a/rules/docker-fpm-frr.mk b/rules/docker-fpm-frr.mk index 1d158effe7ff..1651772fc53d 100644 --- a/rules/docker-fpm-frr.mk +++ b/rules/docker-fpm-frr.mk @@ -24,7 +24,6 @@ SONIC_STRETCH_DBG_DOCKERS += $(DOCKER_FPM_FRR_DBG) $(DOCKER_FPM_FRR)_CONTAINER_NAME = bgp $(DOCKER_FPM_FRR)_RUN_OPT += --net=host --privileged -t $(DOCKER_FPM_FRR)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro -$(DOCKER_FPM_FRR)_RUN_OPT += -v /etc/sonic/frr:/etc/frr:rw $(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += vtysh:/usr/bin/vtysh $(DOCKER_FPM_FRR)_BASE_IMAGE_FILES += TSA:/usr/bin/TSA From 9328339f412be816fd1aa094b10eb4322b98f9ab Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Thu, 20 Jun 2019 16:49:24 -0700 Subject: [PATCH 09/57] [build_templates]: add multi-instance support to teamd * change teamd service file to template * force teamd to restart when swss does Signed-off-by: Lawrence Lee (cherry picked from commit 0297279b50bb656e4a50a670d41364987da33f0f) --- .../multi_instance/teamd@.service.j2 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 files/build_templates/multi_instance/teamd@.service.j2 diff --git a/files/build_templates/multi_instance/teamd@.service.j2 b/files/build_templates/multi_instance/teamd@.service.j2 new file mode 100644 index 000000000000..6d9ea7f301ee --- /dev/null +++ b/files/build_templates/multi_instance/teamd@.service.j2 @@ -0,0 +1,18 @@ +[Unit] +Description=TEAMD container +#Requires=updategraph.service +Requires=swss@%i.service +#After=updategraph.service +After=swss@%i.service +Before=ntp-config.service +PartOf=namespace@%i.target + +[Service] +User=root +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i + +[Install] +WantedBy=swss@%i.service +RequiredBy=namespace@%i.target From 04b4887af46227286279acb56f2fbda7b4cfc65d Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 26 Jun 2019 12:08:04 -0700 Subject: [PATCH 10/57] [sonic-utilities]: update sonic-utilities * set submodule to point at newest commit Signed-off-by: Lawrence Lee (cherry picked from commit ebab66d8662c523c5402c3eea8631ce469461969) --- files/build_templates/docker_image_ctl.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 90814c484e3d..f2cdc851a769 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -293,7 +293,7 @@ start() { } preStartAction - docker start {{docker_container_name}} + docker start {{docker_container_name}}$DEV postStartAction } From f3c48d6c2ddd2c8e073f52cad60b24ae7ac556a6 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Wed, 26 Jun 2019 16:59:39 -0700 Subject: [PATCH 11/57] [interfaces-config]: enable multi-asic support * create service template * enable template instances in sonic_debian_extension * use iproute2 in interfaces-config script if working with network namespaces * make swss multi-instance dependent on multi-instance interfaces config Signed-off-by: Lawrence Lee (cherry picked from commit 08af0dbeb500dfcf6d86752d6254f2c9d1ef45e2) --- .../multi_instance/swss@.service.j2 | 2 +- files/build_templates/sonic_debian_extension.j2 | 2 ++ .../interfaces/interfaces-config.service | 2 +- .../interfaces/interfaces-config@.service | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 files/image_config/interfaces/interfaces-config@.service diff --git a/files/build_templates/multi_instance/swss@.service.j2 b/files/build_templates/multi_instance/swss@.service.j2 index e65f09cd8f74..64e3937426fc 100644 --- a/files/build_templates/multi_instance/swss@.service.j2 +++ b/files/build_templates/multi_instance/swss@.service.j2 @@ -9,7 +9,7 @@ Requires=nps-modules-4.9.0-9-2-amd64.service {% endif %} After=database@%i.service #updategraph.service -After=interfaces-config.service +After=interfaces-config@%i.service Before=ntp-config.service PartOf=namespace@%i.target StartLimitIntervalSec=1200 diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index a9702c50d0e3..4fe5a26d31fc 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -202,9 +202,11 @@ sudo cp -f $IMAGE_CONFIGS/logrotate/logrotate.d/* $FILESYSTEM_ROOT/etc/logrotate sudo cp -f $IMAGE_CONFIGS/systemd/journald.conf $FILESYSTEM_ROOT/etc/systemd/ # Copy interfaces configuration files and templates +sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config@.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ +echo "interfaces-config@.service" | sudo tee -a $GENERATED_SERVICE_FILE echo "interfaces-config.service" | sudo tee -a $GENERATED_SERVICE_FILE # Copy dhcp client configuration template and create an initial configuration diff --git a/files/image_config/interfaces/interfaces-config.service b/files/image_config/interfaces/interfaces-config.service index 71178affdee8..fa2077c4e496 100644 --- a/files/image_config/interfaces/interfaces-config.service +++ b/files/image_config/interfaces/interfaces-config.service @@ -8,4 +8,4 @@ Type=oneshot ExecStart=/usr/bin/interfaces-config.sh [Install] -WantedBy=multi-user.target +RequiredBy=multi-user.target diff --git a/files/image_config/interfaces/interfaces-config@.service b/files/image_config/interfaces/interfaces-config@.service new file mode 100644 index 000000000000..96335931ba4f --- /dev/null +++ b/files/image_config/interfaces/interfaces-config@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Update interfaces configuration +Requires=database@%i.service +After=database@%i.service +#Requires=updategraph.service +#After=updategraph.service +PartOf=namespace@%i.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/interfaces-config.sh %i + +[Install] +RequiredBy=namespace@%i.target From d5c4a0d6221ba6084bf7a837bdc8a5c3e36420c1 Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Fri, 2 Aug 2019 13:26:53 -0700 Subject: [PATCH 12/57] [files]: change namespace name * use 'asic' as namespace prefix instead of 'namespace' in accordance with PR #3269 Signed-off-by: Lawrence Lee (cherry picked from commit c1444e3018cadff9d1acf4cc522d1f015bc85cc3) --- files/scripts/namespace.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/scripts/namespace.sh b/files/scripts/namespace.sh index caf4dc57d729..439165448281 100755 --- a/files/scripts/namespace.sh +++ b/files/scripts/namespace.sh @@ -3,4 +3,4 @@ NS=$1 shift -sudo ip netns exec namespace$NS $@ +sudo ip netns exec asic$NS $@ From 83ca4ded4d3244a2e1e41a4606e193a9099cc379 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Thu, 12 Dec 2019 12:00:06 -0800 Subject: [PATCH 13/57] Remove namespace docker related files. --- files/build_templates/docker_image_ctl.j2 | 2 +- files/build_templates/multi_instance/bgp@.service.j2 | 3 +-- .../build_templates/multi_instance/database@.service.j2 | 3 +-- files/build_templates/multi_instance/swss@.service.j2 | 3 +-- files/build_templates/multi_instance/teamd@.service.j2 | 3 +-- files/build_templates/sonic_debian_extension.j2 | 4 ---- files/image_config/namespace/namespace@.target | 9 --------- files/image_config/rsyslog/rsyslog-config@.service | 3 +-- 8 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 files/image_config/namespace/namespace@.target diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index f2cdc851a769..cd4df64be745 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -303,7 +303,7 @@ wait() { stop() { docker stop {{docker_container_name}}$DEV - {%- if docker_container_name == "namespace" %} + {%- if docker_container_name == "database" %} ip netns delete "{{docker_container_name}}$DEV" {%- endif %} } diff --git a/files/build_templates/multi_instance/bgp@.service.j2 b/files/build_templates/multi_instance/bgp@.service.j2 index 0d2ea1e7494a..43042adf1ec7 100644 --- a/files/build_templates/multi_instance/bgp@.service.j2 +++ b/files/build_templates/multi_instance/bgp@.service.j2 @@ -5,7 +5,6 @@ Description=BGP container After=database@%i.service Requires=database@%i.service Before=ntp-config.service -PartOf=namespace@%i.target [Service] User=root @@ -14,4 +13,4 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i [Install] -RequiredBy=namespace@%i.target +WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/database@.service.j2 b/files/build_templates/multi_instance/database@.service.j2 index 9a828e44c038..e0113dcce0d9 100644 --- a/files/build_templates/multi_instance/database@.service.j2 +++ b/files/build_templates/multi_instance/database@.service.j2 @@ -2,7 +2,6 @@ Description=Database container Requires=docker.service namespace@%i.service After=docker.service namespace@%i.service -PartOf=namespace@%i.target [Service] User=root @@ -13,4 +12,4 @@ Restart=on-failure TimeoutStartSec=120 [Install] -RequiredBy=namespace@%i.target +WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/swss@.service.j2 b/files/build_templates/multi_instance/swss@.service.j2 index 64e3937426fc..80caf9f02cd7 100644 --- a/files/build_templates/multi_instance/swss@.service.j2 +++ b/files/build_templates/multi_instance/swss@.service.j2 @@ -11,7 +11,6 @@ After=database@%i.service #updategraph.service After=interfaces-config@%i.service Before=ntp-config.service -PartOf=namespace@%i.target StartLimitIntervalSec=1200 StartLimitBurst=3 @@ -25,4 +24,4 @@ Restart=always RestartSec=30 [Install] -RequiredBy=namespace@%i.target +WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/teamd@.service.j2 b/files/build_templates/multi_instance/teamd@.service.j2 index 6d9ea7f301ee..63fdbd21c46f 100644 --- a/files/build_templates/multi_instance/teamd@.service.j2 +++ b/files/build_templates/multi_instance/teamd@.service.j2 @@ -5,7 +5,6 @@ Requires=swss@%i.service #After=updategraph.service After=swss@%i.service Before=ntp-config.service -PartOf=namespace@%i.target [Service] User=root @@ -15,4 +14,4 @@ ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i [Install] WantedBy=swss@%i.service -RequiredBy=namespace@%i.target +RequiredBy=multi-user.target diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 4fe5a26d31fc..2c3bda879b71 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -396,10 +396,6 @@ sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh # Copy network namespace wrapper script sudo LANG=C cp $SCRIPTS_DIR/namespace.sh $FILESYSTEM_ROOT/usr/local/bin/namespace -# Copy namespace target -sudo cp $IMAGE_CONFIGS/namespace/namespace@.target $FILESYSTEM_ROOT/etc/systemd/system/ -echo "namespace@.target" | sudo tee -a $GENERATED_SERVICE_FILE - # Copy systemd timer configuration # It implements delayed start of services sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT/etc/systemd/system/ diff --git a/files/image_config/namespace/namespace@.target b/files/image_config/namespace/namespace@.target deleted file mode 100644 index 58cef23bf87a..000000000000 --- a/files/image_config/namespace/namespace@.target +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Synchronization Target for Individual Namespace -Wants=topology.service -Requires=namespace@i.service -After=topology.service namespace@i.service -PartOf=namespace@%i.service - -[Install] -WantedBy=multi-user.target diff --git a/files/image_config/rsyslog/rsyslog-config@.service b/files/image_config/rsyslog/rsyslog-config@.service index 9f8d03345b8f..5b18bfd75f18 100644 --- a/files/image_config/rsyslog/rsyslog-config@.service +++ b/files/image_config/rsyslog/rsyslog-config@.service @@ -4,11 +4,10 @@ Requires=database@%i.service After=database@%i.service #Requires=updategraph.service #After=updategraph.service -PartOf=namespace@%i.target [Service] Type=oneshot ExecStart=/usr/bin/rsyslog-config.sh %i [Install] -RequiredBy=namespace@%i.target +WantedBy=multi-user.target From 6e3b5199481dfdec474d76db7e0e8abb918fc2eb Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Wed, 15 Jan 2020 12:46:50 -0800 Subject: [PATCH 14/57] [build_templates]: remove namespace service dependency --- files/build_templates/multi_instance/database@.service.j2 | 4 ++-- files/build_templates/sonic_debian_extension.j2 | 3 --- files/image_config/interfaces/interfaces-config@.service | 5 +---- files/image_config/rsyslog/rsyslog@.service | 2 +- platform/vs/sonic.xml | 5 +++-- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/files/build_templates/multi_instance/database@.service.j2 b/files/build_templates/multi_instance/database@.service.j2 index e0113dcce0d9..81feceb690be 100644 --- a/files/build_templates/multi_instance/database@.service.j2 +++ b/files/build_templates/multi_instance/database@.service.j2 @@ -1,7 +1,7 @@ [Unit] Description=Database container -Requires=docker.service namespace@%i.service -After=docker.service namespace@%i.service +Requires=docker.service +After=docker.service [Service] User=root diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 2c3bda879b71..f880fb35ed68 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -393,9 +393,6 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh -# Copy network namespace wrapper script -sudo LANG=C cp $SCRIPTS_DIR/namespace.sh $FILESYSTEM_ROOT/usr/local/bin/namespace - # Copy systemd timer configuration # It implements delayed start of services sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT/etc/systemd/system/ diff --git a/files/image_config/interfaces/interfaces-config@.service b/files/image_config/interfaces/interfaces-config@.service index 96335931ba4f..3bbadbf1bd33 100644 --- a/files/image_config/interfaces/interfaces-config@.service +++ b/files/image_config/interfaces/interfaces-config@.service @@ -2,13 +2,10 @@ Description=Update interfaces configuration Requires=database@%i.service After=database@%i.service -#Requires=updategraph.service -#After=updategraph.service -PartOf=namespace@%i.target [Service] Type=oneshot ExecStart=/usr/bin/interfaces-config.sh %i [Install] -RequiredBy=namespace@%i.target +RequiredBy=multi-user.target diff --git a/files/image_config/rsyslog/rsyslog@.service b/files/image_config/rsyslog/rsyslog@.service index 36841652026f..300724e47164 100644 --- a/files/image_config/rsyslog/rsyslog@.service +++ b/files/image_config/rsyslog/rsyslog@.service @@ -6,7 +6,7 @@ After=rsyslog-config@%i.service [Service] Type=notify User=root -ExecStart=/bin/ip netns exec namespace%i /usr/sbin/rsyslogd -n -i /var/run/rsyslogd%i.pid -f /etc/rsyslog%i.conf +ExecStart=/bin/ip netns exec asic%i /usr/sbin/rsyslogd -n -i /var/run/rsyslogd%i.pid -f /etc/rsyslog%i.conf StandardOutput=null Restart=on-failure diff --git a/platform/vs/sonic.xml b/platform/vs/sonic.xml index 9d72d0e91f74..ebf9f542607f 100644 --- a/platform/vs/sonic.xml +++ b/platform/vs/sonic.xml @@ -1,7 +1,8 @@ sonic - 8 - 2 + 2048000 + 2048000 + 1 /machine From 81b024eef51cfae4e9aeb625f27c13dab845f462 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:16:18 -0800 Subject: [PATCH 15/57] [redis-cli/sonic-cfggen]: Add wrappers to talk to database instance in different namespaces. --- .../base_image_files/redis-cli | 23 +++++++++---------- .../build_templates/sonic_debian_extension.j2 | 1 + files/scripts/sonic-cfggen | 11 +++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 files/scripts/sonic-cfggen diff --git a/dockers/docker-database/base_image_files/redis-cli b/dockers/docker-database/base_image_files/redis-cli index 481cb4542807..112b85797d39 100755 --- a/dockers/docker-database/base_image_files/redis-cli +++ b/dockers/docker-database/base_image_files/redis-cli @@ -1,16 +1,15 @@ #!/bin/bash -DOCKER_EXEC_FLAGS="i" - -# Determine whether stdout is on a terminal -if [ -t 1 ] ; then - DOCKER_EXEC_FLAGS+="t" -fi - +NS="asic" #Network namespace [ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number -if [ $? -eq 0 ]; then # if it's a number, set the database instance to operate on - DEV="$1" - shift +# if it's a number, set the database instance to +#operate on that instance +if [ $? -eq 0 ]; then + DEV="$1" + shift +fi +if [ -z "$DEV" ]; then + sonic-db-cli "$@" +else + ip netns exec $NS$DEV sonic-db-cli "$@" fi - -docker exec -$DOCKER_EXEC_FLAGS database$DEV redis-cli "$@" diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 4f79b1a77df7..6ac2c517640d 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -435,6 +435,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys # Copy swss and syncd service script sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh +sudo LANG=C cp $SCRIPTS_DIR/sonic-cfggen $FILESYSTEM_ROOT/usr/bin/sonic-cfggen # Copy systemd timer configuration # It implements delayed start of services diff --git a/files/scripts/sonic-cfggen b/files/scripts/sonic-cfggen new file mode 100644 index 000000000000..a63935525ccb --- /dev/null +++ b/files/scripts/sonic-cfggen @@ -0,0 +1,11 @@ +NS="asic" #Network namespace +[ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number +if [ $? -eq 0 ]; then + DEV="$1" + shift +fi +if [ -z "$DEV" ]; then + /usr/local/bin/sonic-cfggen "$@" +else + ip netns exec $NS$DEV /usr/local/bin/sonic-cfggen "$@" +fi From 1875e6b6a5ab6573d061456448acb6524c1d4757 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:23:39 -0800 Subject: [PATCH 16/57] [swss.sh]: Modified to use redis-cli wrapper to talk to multiple database instances --- files/scripts/swss.sh | 58 +++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 1ca0f2409414..4e2bda030ffe 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -1,6 +1,7 @@ #!/bin/bash -DEPENDENT="teamd radv dhcp_relay" +DEPENDENT="radv dhcp_relay" +MULTI_INST_DEPENDENT="teamd" function debug() { @@ -10,25 +11,25 @@ function debug() function lock_service_state_change() { - debug "Locking ${LOCKFILE} from ${SERVICE} service" + debug "Locking ${LOCKFILE} from ${SERVICE}$DEV service" exec {LOCKFD}>${LOCKFILE} /usr/bin/flock -x ${LOCKFD} trap "/usr/bin/flock -u ${LOCKFD}" 0 2 3 15 - debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE} service" + debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE}$DEV service" } function unlock_service_state_change() { - debug "Unlocking ${LOCKFILE} (${LOCKFD}) from ${SERVICE} service" + debug "Unlocking ${LOCKFILE} (${LOCKFD}) from ${SERVICE}$DEV service" /usr/bin/flock -u ${LOCKFD} } function check_warm_boot() { - SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" else @@ -39,7 +40,7 @@ function check_warm_boot() function validate_restore_count() { if [[ x"$WARM_BOOT" == x"true" ]]; then - RESTORE_COUNT=`sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` + RESTORE_COUNT=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` # We have to make sure db data has not been flushed. if [[ -z "$RESTORE_COUNT" ]]; then WARM_BOOT="false" @@ -53,7 +54,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(/usr/bin/redis-cli $DEV CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -63,7 +64,7 @@ function wait_for_database_service() # $2 the string of a list of table prefixes function clean_up_tables() { - sonic-db-cli $1 EVAL " + /usr/bin/redis-cli $DEV $1 EVAL " local tables = {$2} for i = 1, table.getn(tables) do local matches = redis.call('KEYS', tables[i]) @@ -85,6 +86,13 @@ start_peer_and_dependent_services() { for dep in ${DEPENDENT}; do /bin/systemctl start ${dep} done + for dep in ${MULTI_INST_DEPENDENT}; do + if [[ ! -z $DEV ]]; then + /bin/systemctl start ${dep}@$DEV + else + /bin/systemctl start ${dep} + fi + done fi } @@ -99,11 +107,19 @@ stop_peer_and_dependent_services() { for dep in ${DEPENDENT}; do /bin/systemctl stop ${dep} done + for dep in ${MULTI_INST_DEPENDENT}; do + if [[ ! -z $DEV ]]; then + /bin/systemctl stop ${dep}@$DEV + else + /bin/systemctl stop ${dep} + fi + done + fi } start() { - debug "Starting ${SERVICE} service..." + debug "Starting ${SERVICE}$DEV service..." lock_service_state_change @@ -111,21 +127,21 @@ start() { check_warm_boot validate_restore_count - debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." + debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}." # Don't flush DB during warm boot if [[ x"$WARM_BOOT" != x"true" ]]; then debug "Flushing APP, ASIC, COUNTER, CONFIG, and partial STATE databases ..." - sonic-db-cli APPL_DB FLUSHDB - sonic-db-cli ASIC_DB FLUSHDB - sonic-db-cli COUNTERS_DB FLUSHDB - sonic-db-cli FLEX_COUNTER_DB FLUSHDB + /usr/bin/redis-cli $DEV APPL_DB FLUSHDB + /usr/bin/redis-cli $DEV ASIC_DB FLUSHDB + /usr/bin/redis-cli $DEV COUNTERS_DB FLUSHDB + /usr/bin/redis-cli $DEV FLEX_COUNTER_DB FLUSHDB clean_up_tables STATE_DB "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*'" fi # start service docker /usr/bin/${SERVICE}.sh start $DEV - debug "Started ${SERVICE} service..." + debug "Started ${SERVICE}$DEV service..." # Unlock has to happen before reaching out to peer service unlock_service_state_change @@ -139,7 +155,7 @@ wait() { # corresponding services for SECS in {1..60}; do if [[ ! -z $DEV ]]; then - RUNNING=$(docker inspect -f '{{.State.Running}}' ${PEER}@$DEV) + RUNNING=$(docker inspect -f '{{.State.Running}}' ${PEER}$DEV) else RUNNING=$(docker inspect -f '{{.State.Running}}' ${PEER}) fi @@ -153,23 +169,23 @@ wait() { # NOTE: This assumes Docker containers share the same names as their # corresponding services if [[ ! -z $DEV ]]; then - /usr/bin/docker-wait-any ${SERVICE} ${PEER}@$DEV + /usr/bin/docker-wait-any ${SERVICE}$DEV ${PEER}$DEV else /usr/bin/docker-wait-any ${SERVICE} ${PEER} fi } stop() { - debug "Stopping ${SERVICE} service..." + debug "Stopping ${SERVICE}$DEV service..." [[ -f ${LOCKFILE} ]] || /usr/bin/touch ${LOCKFILE} lock_service_state_change check_warm_boot - debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." + debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}." /usr/bin/${SERVICE}.sh stop $DEV - debug "Stopped ${SERVICE} service..." + debug "Stopped ${SERVICE}$DEV service..." # Flush FAST_REBOOT table when swss needs to stop. The only # time when this would take effect is when fast-reboot From 3363c0d038b6e3d368c16cd78cc8bfdd35af24be Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:27:44 -0800 Subject: [PATCH 17/57] [syncd.sh]: Updated to use redis-cli wrapper to talk to multiple database instances. --- files/scripts/syncd.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/files/scripts/syncd.sh b/files/scripts/syncd.sh index b64193fb6f6e..6201844cb509 100755 --- a/files/scripts/syncd.sh +++ b/files/scripts/syncd.sh @@ -9,25 +9,25 @@ function debug() function lock_service_state_change() { - debug "Locking ${LOCKFILE} from ${SERVICE} service" + debug "Locking ${LOCKFILE} from ${SERVICE}$DEV service" exec {LOCKFD}>${LOCKFILE} /usr/bin/flock -x ${LOCKFD} trap "/usr/bin/flock -u ${LOCKFD}" 0 2 3 15 - debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE} service" + debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE}$DEV service" } function unlock_service_state_change() { - debug "Unlocking ${LOCKFILE} (${LOCKFD}) from ${SERVICE} service" + debug "Unlocking ${LOCKFILE} (${LOCKFD}) from ${SERVICE}$DEV service" /usr/bin/flock -u ${LOCKFD} } function check_warm_boot() { - SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` # SYSTEM_WARM_START could be empty, always make WARM_BOOT meaningful. if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" @@ -42,7 +42,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(/usr/bin/redis-cli $DEV CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -59,7 +59,7 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - if [[ $(sonic-db-cli STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + if [[ $(/usr/bin/redis-cli $DEV STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then TYPE='fast' else TYPE='cold' @@ -72,7 +72,7 @@ function getBootType() } start() { - debug "Starting ${SERVICE} service..." + debug "Starting ${SERVICE}$DEV service..." lock_service_state_change @@ -81,7 +81,7 @@ start() { wait_for_database_service check_warm_boot - debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." + debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}." if [[ x"$WARM_BOOT" == x"true" ]]; then # Leave a mark for syncd scripts running inside docker. @@ -139,11 +139,11 @@ wait() { } stop() { - debug "Stopping ${SERVICE} service..." + debug "Stopping ${SERVICE}$DEV service..." lock_service_state_change check_warm_boot - debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." + debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}." if [[ x"$WARM_BOOT" == x"true" ]]; then TYPE=warm @@ -171,7 +171,7 @@ stop() { fi /usr/bin/${SERVICE}.sh stop $DEV - debug "Stopped ${SERVICE} service..." + debug "Stopped ${SERVICE}$DEV service..." # platform specific tasks From 95fb5f503cbeb573556798b43ed48120e0c094ab Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:36:36 -0800 Subject: [PATCH 18/57] [docker_img_ctl.j2]: Updated to use redis-cli/sonic-cfggen wrappers to talk to different database instances --- files/build_templates/docker_image_ctl.j2 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index e256fe5b40ee..ef4dbfc80ec3 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -14,11 +14,11 @@ link_namespace() { mkdir -p /var/run/netns PID="$(docker inspect -f {{"'{{.State.Pid}}'"}} "{{docker_container_name}}$DEV")" - if `ip netns | grep --quiet -w "{{docker_container_name}}$DEV"`; then # namespace exists + if `ip netns | grep --quiet -w "$NET_NS$DEV"`; then # namespace exists if [ $(readlink -f /var/run/netns/$NET_NS$DEV) = $(readlink -f /proc/$PID/ns/net) ]; then # namespace is correctly linked return 0 else # if it's incorrectly linked remove it - ip netns delete "{{docker_container_name}}$DEV" + ip netns delete $NET_NS$DEV fi fi @@ -89,7 +89,7 @@ function preStartAction() docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/ fi {%- elif docker_container_name == "snmp" %} - sonic-db-cli STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) + /usr/bin/redis-cli $DEV STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) {%- else %} : # nothing {%- endif %} @@ -110,15 +110,15 @@ function postStartAction() else # If there is a config db dump file, load it if [ -r /etc/sonic/config_db$DEV.json ]; then - sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db --redis-unix-sock-file $EXT_REDIS_SOCK + /usr/bin/sonic-cfggen $DEV -j /etc/sonic/config_db$DEV.json --write-to-db fi if [[ "$BOOT_TYPE" == "fast" ]]; then # set the key to expire in 3 minutes - sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" + /usr/bin/redis-cli $DEV STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" fi - sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" + /usr/bin/redis-cli $DEV CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" fi if [[ -x /usr/bin/db_migrator.py ]]; then @@ -160,15 +160,15 @@ start() { BOOT_TYPE=`getBootType` # Obtain our platform as we will mount directories with these names in each docker - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + PLATFORM=`/usr/bin/sonic-cfggen $DEV -H -v DEVICE_METADATA.localhost.platform` {%- if docker_container_name == "database" %} # Don't mount HWSKU in {{docker_container_name}} container. HWSKU="" {%- else %} # Obtain our HWSKU as we will mount directories with these names in each docker - HWSKU=`sonic-cfggen -d -s /var/run/redis$DEV/redis.sock -v 'DEVICE_METADATA["localhost"]["hwsku"]'` - HOSTNAME=`sonic-cfggen -d -s /var/run/redis$DEV/redis.sock -v 'DEVICE_METADATA["localhost"]["hostname"]'` + HWSKU=`/usr/bin/sonic-cfggen $DEV -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + HOSTNAME=`/usr/bin/sonic-cfggen $DEV -d -v 'DEVICE_METADATA["localhost"]["hostname"]'` {%- endif %} if [ -z "$HOSTNAME" ] || ! [[ $HOSTNAME =~ ^[a-zA-Z0-9.\-]*$ ]]; then HOSTNAME=`hostname` @@ -254,7 +254,7 @@ start() { -v /var/run/redis$DEV:/var/run/redis:rw \ -v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \ {%- if docker_container_name != "database" %} - -v /usr/share/sonic/device/$PLATFORM/$HWSKU:/usr/share/sonic/hwsku:ro \ + -v /usr/share/sonic/device/$PLATFORM/$HWSKU/$DEV:/usr/share/sonic/hwsku:ro \ {%- endif %} {%- if sonic_asic_platform != "mellanox" %} --tmpfs /tmp \ From 382f13e17d94b36fd20982d5b357f657d9b55051 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:50:46 -0800 Subject: [PATCH 19/57] [database service]: changes made to include global database service for multi-asic platform --- .../{single_instance => }/database.service.j2 | 0 .../build_templates/multi_instance/database@.service.j2 | 4 ++-- slave.mk | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) rename files/build_templates/{single_instance => }/database.service.j2 (100%) diff --git a/files/build_templates/single_instance/database.service.j2 b/files/build_templates/database.service.j2 similarity index 100% rename from files/build_templates/single_instance/database.service.j2 rename to files/build_templates/database.service.j2 diff --git a/files/build_templates/multi_instance/database@.service.j2 b/files/build_templates/multi_instance/database@.service.j2 index 81feceb690be..7e38e4b20c70 100644 --- a/files/build_templates/multi_instance/database@.service.j2 +++ b/files/build_templates/multi_instance/database@.service.j2 @@ -1,7 +1,7 @@ [Unit] Description=Database container -Requires=docker.service -After=docker.service +Requires=docker.service database.service +After=docker.service database.service [Service] User=root diff --git a/slave.mk b/slave.mk index cc118da7aa06..ba3f71ab81e6 100644 --- a/slave.mk +++ b/slave.mk @@ -670,6 +670,11 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ if [ -f files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then j2 files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service + + # Set the flag GLOBAL for all the global system-wide dockers. + $(if $(shell ls files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 2>/dev/null),\ + $(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes) + ) fi if [ -f files/build_templates/multi_instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service.j2 ]; then @@ -692,8 +697,12 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ # Marks template services with an "@" according to systemd convention # If the $($docker)_TEMPLATE) variable is set, the service will be treated as a template + # If the $($docker)_GLOBAL) and $($docker)_TEMPLATE) variables are set the service will be added both as a global and template service. $(foreach docker, $($*_DOCKERS),\ $(if $($(docker:-dbg.gz=.gz)_TEMPLATE),\ + $(if $($(docker:-dbg.gz=.gz)_GLOBAL),\ + $(eval SERVICES += "$(addsuffix .service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")\ + )\ $(eval SERVICES += "$(addsuffix @.service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))"),\ $(eval SERVICES += "$(addsuffix .service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))") ) From c20bf4318faef142d4bfdd0cd9d61cbf86e7fba6 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:51:43 -0800 Subject: [PATCH 20/57] [swss/syncd services]: Added dependency to topology.service for VS platform --- files/build_templates/multi_instance/swss@.service.j2 | 5 +++++ files/build_templates/multi_instance/syncd@.service.j2 | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/files/build_templates/multi_instance/swss@.service.j2 b/files/build_templates/multi_instance/swss@.service.j2 index 80caf9f02cd7..1ed9dc5da7b3 100644 --- a/files/build_templates/multi_instance/swss@.service.j2 +++ b/files/build_templates/multi_instance/swss@.service.j2 @@ -6,8 +6,13 @@ Requires=database@%i.service Requires=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} Requires=nps-modules-4.9.0-9-2-amd64.service +{% elif sonic_asic_platform == 'vs' %} +Requires=topology.service {% endif %} After=database@%i.service +{% if sonic_asic_platform == 'vs' %} +After=topology.service +{% endif %} #updategraph.service After=interfaces-config@%i.service Before=ntp-config.service diff --git a/files/build_templates/multi_instance/syncd@.service.j2 b/files/build_templates/multi_instance/syncd@.service.j2 index 448f42c50682..a9f108c2d30f 100644 --- a/files/build_templates/multi_instance/syncd@.service.j2 +++ b/files/build_templates/multi_instance/syncd@.service.j2 @@ -6,14 +6,18 @@ Requires=database@%i.service Requires=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} Requires=nps-modules-4.9.0-8-2-amd64.service +{% elif sonic_asic_platform == 'vs' %} +Requires=topology.service {% endif %} -After=database.service +After=database@%i.service #updategraph.service After=interfaces-config.service {% if sonic_asic_platform == 'broadcom' %} After=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} After=nps-modules-4.9.0-8-2-amd64.service +{% elif sonic_asic_platform == 'vs' %} +After=topology.service {% endif %} After=swss@%i.service Before=ntp-config.service From a76eb01d48bc1116fd514065b1bc4b80fda0fbe2 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:53:01 -0800 Subject: [PATCH 21/57] [interfaces-config.sh]: Made changes to support multi-asic platform --- .../interfaces/interfaces-config.sh | 84 +++++++++++-------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/files/image_config/interfaces/interfaces-config.sh b/files/image_config/interfaces/interfaces-config.sh index 8dddc215bbd9..d4d960d5655f 100755 --- a/files/image_config/interfaces/interfaces-config.sh +++ b/files/image_config/interfaces/interfaces-config.sh @@ -1,41 +1,51 @@ #!/bin/bash - -ifdown --force eth0 - -# Check if ZTP DHCP policy has been installed -if [ -e /etc/network/ifupdown2/policy.d/ztp_dhcp.json ]; then - # Obtain port operational state information - redis-dump -d 0 -k "PORT_TABLE:Ethernet*" -y > /tmp/ztp_port_data.json - - if [ $? -ne 0 ] || [ ! -e /tmp/ztp_port_data.json ] || [ "$(cat /tmp/ztp_port_data.json)" = "" ]; then - echo "{}" > /tmp/ztp_port_data.json +NS=$1 +if [ -z "$NS" ]; then + ifdown --force eth0 + + # Check if ZTP DHCP policy has been installed + if [ -e /etc/network/ifupdown2/policy.d/ztp_dhcp.json ]; then + # Obtain port operational state information + redis-dump -d 0 -k "PORT_TABLE:Ethernet*" -y > /tmp/ztp_port_data.json + + if [ $? -ne 0 ] || [ ! -e /tmp/ztp_port_data.json ] || [ "$(cat /tmp/ztp_port_data.json)" = "" ]; then + echo "{}" > /tmp/ztp_port_data.json + fi + + # Create an input file with ztp input information + echo "{ \"PORT_DATA\" : $(cat /tmp/ztp_port_data.json) }" > \ + /tmp/ztp_input.json + else + echo "{ \"ZTP_DHCP_DISABLED\" : \"true\" }" > /tmp/ztp_input.json fi - - # Create an input file with ztp input information - echo "{ \"PORT_DATA\" : $(cat /tmp/ztp_port_data.json) }" > \ - /tmp/ztp_input.json + + # Create /e/n/i file for existing and active interfaces + sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/interfaces.j2 > /etc/network/interfaces + + [ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid + [ -f /var/run/dhclient6.eth0.pid ] && kill `cat /var/run/dhclient6.eth0.pid` && rm -f /var/run/dhclient6.eth0.pid + + for intf_pid in $(ls -1 /var/run/dhclient*.Ethernet*.pid 2> /dev/null); do + [ -f ${intf_pid} ] && kill `cat ${intf_pid}` && rm -f ${intf_pid} + done + + sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/90-dhcp6-systcl.conf.j2 > /etc/sysctl.d/90-dhcp6-systcl.conf + # Read sysctl conf files again + sysctl -p /etc/sysctl.d/90-dhcp6-systcl.conf + + sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/dhclient.conf.j2 > /etc/dhcp/dhclient.conf + systemctl restart networking + + # Clean-up created files + rm -f /tmp/ztp_input.json /tmp/ztp_port_data.json + + ifdown lo && ifup lo else - echo "{ \"ZTP_DHCP_DISABLED\" : \"true\" }" > /tmp/ztp_input.json + INTF_LIST=`redis-cli $NS CONFIG_DB KEYS 'LOOPBACK_INTERFACE*'` + for ENTRY in $INTF_LIST; do + IFS='|' read -ra ADDR_ARRAY <<< "$ENTRY" + ADDR=${ADDR_ARRAY[2]} + ADDR=`echo $ADDR | tr -d \''[]'` + ip netns exec asic$NS ip addr add $ADDR dev lo + done fi - -# Create /e/n/i file for existing and active interfaces -sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/interfaces.j2 > /etc/network/interfaces - -[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid -[ -f /var/run/dhclient6.eth0.pid ] && kill `cat /var/run/dhclient6.eth0.pid` && rm -f /var/run/dhclient6.eth0.pid - -for intf_pid in $(ls -1 /var/run/dhclient*.Ethernet*.pid 2> /dev/null); do - [ -f ${intf_pid} ] && kill `cat ${intf_pid}` && rm -f ${intf_pid} -done - -sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/90-dhcp6-systcl.conf.j2 > /etc/sysctl.d/90-dhcp6-systcl.conf -# Read sysctl conf files again -sysctl -p /etc/sysctl.d/90-dhcp6-systcl.conf - -sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/dhclient.conf.j2 > /etc/dhcp/dhclient.conf -systemctl restart networking - -# Clean-up created files -rm -f /tmp/ztp_input.json /tmp/ztp_port_data.json - -ifdown lo && ifup lo From d7ab64bf7181f752154e0d7c50fdd9700db3f676 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:54:14 -0800 Subject: [PATCH 22/57] [topology.sh]: Updated to read Platform and SKU information from global DB --- files/image_config/topology/topology.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/files/image_config/topology/topology.sh b/files/image_config/topology/topology.sh index 7013920ec016..e1f278cadae1 100755 --- a/files/image_config/topology/topology.sh +++ b/files/image_config/topology/topology.sh @@ -6,17 +6,15 @@ # start() { - DB_FIRST_INSTANCE="/var/run/redis0/redis.sock" TOPOLOGY_SCRIPT="topology.sh" - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform -s $DB_FIRST_INSTANCE` - HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]' -s $DB_FIRST_INSTANCE` + PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` /usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT start } stop() { - DB_FIRST_INSTANCE="/var/run/redis0/redis.sock" TOPOLOGY_SCRIPT="topology.sh" - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform -s $DB_FIRST_INSTANCE` - HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]' -s $DB_FIRST_INSTANCE` + PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` /usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT stop } From 61971a7ebd3ee054403741dd229d43156b76d005 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 11 Feb 2020 18:55:21 -0800 Subject: [PATCH 23/57] [namespace.sh]: Remove namespace.sh as namespace docker is not used --- files/scripts/namespace.sh | 6 ------ 1 file changed, 6 deletions(-) delete mode 100755 files/scripts/namespace.sh diff --git a/files/scripts/namespace.sh b/files/scripts/namespace.sh deleted file mode 100755 index 439165448281..000000000000 --- a/files/scripts/namespace.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -NS=$1 -shift - -sudo ip netns exec asic$NS $@ From 81a8f74e4f9ac70d5e816121cfda402abb569ee8 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 19 Feb 2020 17:56:40 -0800 Subject: [PATCH 24/57] LLDP Multi-Asic Support. --- .../multi_instance/lldp@.service.j2 | 16 ++++++++++++++++ .../{ => single_instance}/lldp.service.j2 | 0 2 files changed, 16 insertions(+) create mode 100644 files/build_templates/multi_instance/lldp@.service.j2 rename files/build_templates/{ => single_instance}/lldp.service.j2 (100%) diff --git a/files/build_templates/multi_instance/lldp@.service.j2 b/files/build_templates/multi_instance/lldp@.service.j2 new file mode 100644 index 000000000000..9d128642e19e --- /dev/null +++ b/files/build_templates/multi_instance/lldp@.service.j2 @@ -0,0 +1,16 @@ +[Unit] +Description=LLDP container +#Requires=updategraph.service +#After=updategraph.service +After=database@%i.service +Requires=database@%i.service +Before=ntp-config.service + +[Service] +User={{ sonicadmin_user }} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i + +[Install] +WantedBy=multi-user.target diff --git a/files/build_templates/lldp.service.j2 b/files/build_templates/single_instance/lldp.service.j2 similarity index 100% rename from files/build_templates/lldp.service.j2 rename to files/build_templates/single_instance/lldp.service.j2 From 4beb4add9a3b29ccd77b445bce1d969e5ef4480a Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 21 Feb 2020 12:36:17 -0800 Subject: [PATCH 25/57] [sonic-cfggen wrapper]: Change mode to make the script executable. --- files/scripts/sonic-cfggen | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 files/scripts/sonic-cfggen diff --git a/files/scripts/sonic-cfggen b/files/scripts/sonic-cfggen old mode 100644 new mode 100755 From f93503600256fef2624f2cef08e58fa2358b5c15 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 21 Feb 2020 16:18:55 -0800 Subject: [PATCH 26/57] [sonic-db-cli wrapper]: Add a new wrapper script to accept a database instance number as argument and execute sonic-db-cli command in a spefic namespace to support multi-asic platform. --- .../base_image_files/redis-cli | 19 +++++++------------ files/build_templates/docker_image_ctl.j2 | 6 +++--- .../build_templates/sonic_debian_extension.j2 | 1 + files/scripts/sonic-db-cli | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 15 deletions(-) create mode 100755 files/scripts/sonic-db-cli diff --git a/dockers/docker-database/base_image_files/redis-cli b/dockers/docker-database/base_image_files/redis-cli index 112b85797d39..6ce1951cd4b9 100755 --- a/dockers/docker-database/base_image_files/redis-cli +++ b/dockers/docker-database/base_image_files/redis-cli @@ -1,15 +1,10 @@ #!/bin/bash -NS="asic" #Network namespace -[ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number -# if it's a number, set the database instance to -#operate on that instance -if [ $? -eq 0 ]; then - DEV="$1" - shift -fi -if [ -z "$DEV" ]; then - sonic-db-cli "$@" -else - ip netns exec $NS$DEV sonic-db-cli "$@" +DOCKER_EXEC_FLAGS="i" + +# Determine whether stdout is on a terminal +if [ -t 1 ] ; then + DOCKER_EXEC_FLAGS+="t" fi + +docker exec -$DOCKER_EXEC_FLAGS database redis-cli "$@" diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index ef4dbfc80ec3..bdbc667c40ed 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -89,7 +89,7 @@ function preStartAction() docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/ fi {%- elif docker_container_name == "snmp" %} - /usr/bin/redis-cli $DEV STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) + /usr/bin/sonic-db-cli $DEV STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) {%- else %} : # nothing {%- endif %} @@ -115,10 +115,10 @@ function postStartAction() if [[ "$BOOT_TYPE" == "fast" ]]; then # set the key to expire in 3 minutes - /usr/bin/redis-cli $DEV STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" + /usr/bin/sonic-db-cli $DEV STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" fi - /usr/bin/redis-cli $DEV CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" + /usr/bin/sonic-db-cli $DEV CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" fi if [[ -x /usr/bin/db_migrator.py ]]; then diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 6ac2c517640d..766316e9ffb4 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -436,6 +436,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh sudo LANG=C cp $SCRIPTS_DIR/sonic-cfggen $FILESYSTEM_ROOT/usr/bin/sonic-cfggen +sudo LANG=C cp $SCRIPTS_DIR/sonic-db-cli $FILESYSTEM_ROOT/usr/bin/sonic-db-cli # Copy systemd timer configuration # It implements delayed start of services diff --git a/files/scripts/sonic-db-cli b/files/scripts/sonic-db-cli new file mode 100755 index 000000000000..a8a005503309 --- /dev/null +++ b/files/scripts/sonic-db-cli @@ -0,0 +1,15 @@ +#!/bin/bash + ½ +NS="asic" #Network namespace +[ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number +# if it's a number, set the database instance to +#operate on that instance +if [ $? -eq 0 ]; then + DEV="$1" + shift +fi +if [ -z "$DEV" ]; then + /usr/local/bin/sonic-db-cli "$@" +else + ip netns exec $NS$DEV /usr/local/bin/sonic-db-cli "$@" +fi From 0dae0d88ba5b56675d221936437dd6723e84c807 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 21 Feb 2020 16:20:35 -0800 Subject: [PATCH 27/57] [msft_multi_asic_vs]: Add lanemap.ini and sai.profile to support multi asic VS image. Updates made in topology.sh. --- .../msft_multi_asic_vs/0/lanemap.ini | 32 +++++++++++++++++++ .../msft_multi_asic_vs/0/sai.profile | 7 ++-- .../msft_multi_asic_vs/1/lanemap.ini | 32 +++++++++++++++++++ .../msft_multi_asic_vs/1/sai.profile | 7 ++-- .../msft_multi_asic_vs/2/lanemap.ini | 32 +++++++++++++++++++ .../msft_multi_asic_vs/2/sai.profile | 7 ++-- .../msft_multi_asic_vs/3/lanemap.ini | 32 +++++++++++++++++++ .../msft_multi_asic_vs/3/sai.profile | 7 ++-- .../msft_multi_asic_vs/4/lanemap.ini | 32 +++++++++++++++++++ .../msft_multi_asic_vs/4/sai.profile | 7 ++-- .../msft_multi_asic_vs/5/lanemap.ini | 32 +++++++++++++++++++ .../msft_multi_asic_vs/5/sai.profile | 7 ++-- .../msft_multi_asic_vs/topology.sh | 14 +++++--- 13 files changed, 231 insertions(+), 17 deletions(-) create mode 100644 device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/0/lanemap.ini create mode 100644 device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/1/lanemap.ini create mode 100644 device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/2/lanemap.ini create mode 100644 device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/3/lanemap.ini create mode 100644 device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/4/lanemap.ini create mode 100644 device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/5/lanemap.ini diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/0/lanemap.ini b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/0/lanemap.ini new file mode 100644 index 000000000000..36278a01778c --- /dev/null +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/0/lanemap.ini @@ -0,0 +1,32 @@ +eth1:25,26,27,28 +eth2:29,30,31,32 +eth3:33,34,35,36 +eth4:37,38,39,40 +eth5:45,46,47,48 +eth6:41,42,43,44 +eth7:1,2,3,4 +eth8:5,6,7,8 +eth9:13,14,15,16 +eth10:9,10,11,12 +eth11:17,18,19,20 +eth12:21,22,23,24 +eth13:53,54,55,56 +eth14:49,50,51,52 +eth15:57,58,59,60 +eth16:61,62,63,64 +eth17:69,70,71,72 +eth18:65,66,67,68 +eth19:73,74,75,76 +eth20:77,78,79,80 +eth21:109,110,111,112 +eth22:105,106,107,108 +eth23:113,114,115,116 +eth24:117,118,119,120 +eth25:125,126,127,128 +eth26:121,122,123,124 +eth27:81,82,83,84 +eth28:85,86,87,88 +eth29:93,94,95,96 +eth30:89,90,91,92 +eth31:101,102,103,104 +eth32:97,98,99,100 diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/0/sai.profile b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/0/sai.profile index 52e2e289af60..bfc466f27e54 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/0/sai.profile +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/0/sai.profile @@ -1,2 +1,5 @@ -SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/td2-s6000-32x40G.config.bcm -SAI_NUM_ECMP_MEMBERS=32 +SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin +SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin +SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 +SAI_VS_HOSTIF_USE_TAP_DEVICE=true +SAI_VS_INTERFACE_LANE_MAP_FILE=/usr/share/sonic/hwsku/lanemap.ini diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/1/lanemap.ini b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/1/lanemap.ini new file mode 100644 index 000000000000..36278a01778c --- /dev/null +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/1/lanemap.ini @@ -0,0 +1,32 @@ +eth1:25,26,27,28 +eth2:29,30,31,32 +eth3:33,34,35,36 +eth4:37,38,39,40 +eth5:45,46,47,48 +eth6:41,42,43,44 +eth7:1,2,3,4 +eth8:5,6,7,8 +eth9:13,14,15,16 +eth10:9,10,11,12 +eth11:17,18,19,20 +eth12:21,22,23,24 +eth13:53,54,55,56 +eth14:49,50,51,52 +eth15:57,58,59,60 +eth16:61,62,63,64 +eth17:69,70,71,72 +eth18:65,66,67,68 +eth19:73,74,75,76 +eth20:77,78,79,80 +eth21:109,110,111,112 +eth22:105,106,107,108 +eth23:113,114,115,116 +eth24:117,118,119,120 +eth25:125,126,127,128 +eth26:121,122,123,124 +eth27:81,82,83,84 +eth28:85,86,87,88 +eth29:93,94,95,96 +eth30:89,90,91,92 +eth31:101,102,103,104 +eth32:97,98,99,100 diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/1/sai.profile b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/1/sai.profile index 52e2e289af60..bfc466f27e54 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/1/sai.profile +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/1/sai.profile @@ -1,2 +1,5 @@ -SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/td2-s6000-32x40G.config.bcm -SAI_NUM_ECMP_MEMBERS=32 +SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin +SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin +SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 +SAI_VS_HOSTIF_USE_TAP_DEVICE=true +SAI_VS_INTERFACE_LANE_MAP_FILE=/usr/share/sonic/hwsku/lanemap.ini diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/2/lanemap.ini b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/2/lanemap.ini new file mode 100644 index 000000000000..36278a01778c --- /dev/null +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/2/lanemap.ini @@ -0,0 +1,32 @@ +eth1:25,26,27,28 +eth2:29,30,31,32 +eth3:33,34,35,36 +eth4:37,38,39,40 +eth5:45,46,47,48 +eth6:41,42,43,44 +eth7:1,2,3,4 +eth8:5,6,7,8 +eth9:13,14,15,16 +eth10:9,10,11,12 +eth11:17,18,19,20 +eth12:21,22,23,24 +eth13:53,54,55,56 +eth14:49,50,51,52 +eth15:57,58,59,60 +eth16:61,62,63,64 +eth17:69,70,71,72 +eth18:65,66,67,68 +eth19:73,74,75,76 +eth20:77,78,79,80 +eth21:109,110,111,112 +eth22:105,106,107,108 +eth23:113,114,115,116 +eth24:117,118,119,120 +eth25:125,126,127,128 +eth26:121,122,123,124 +eth27:81,82,83,84 +eth28:85,86,87,88 +eth29:93,94,95,96 +eth30:89,90,91,92 +eth31:101,102,103,104 +eth32:97,98,99,100 diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/2/sai.profile b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/2/sai.profile index 52e2e289af60..bfc466f27e54 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/2/sai.profile +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/2/sai.profile @@ -1,2 +1,5 @@ -SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/td2-s6000-32x40G.config.bcm -SAI_NUM_ECMP_MEMBERS=32 +SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin +SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin +SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 +SAI_VS_HOSTIF_USE_TAP_DEVICE=true +SAI_VS_INTERFACE_LANE_MAP_FILE=/usr/share/sonic/hwsku/lanemap.ini diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/3/lanemap.ini b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/3/lanemap.ini new file mode 100644 index 000000000000..36278a01778c --- /dev/null +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/3/lanemap.ini @@ -0,0 +1,32 @@ +eth1:25,26,27,28 +eth2:29,30,31,32 +eth3:33,34,35,36 +eth4:37,38,39,40 +eth5:45,46,47,48 +eth6:41,42,43,44 +eth7:1,2,3,4 +eth8:5,6,7,8 +eth9:13,14,15,16 +eth10:9,10,11,12 +eth11:17,18,19,20 +eth12:21,22,23,24 +eth13:53,54,55,56 +eth14:49,50,51,52 +eth15:57,58,59,60 +eth16:61,62,63,64 +eth17:69,70,71,72 +eth18:65,66,67,68 +eth19:73,74,75,76 +eth20:77,78,79,80 +eth21:109,110,111,112 +eth22:105,106,107,108 +eth23:113,114,115,116 +eth24:117,118,119,120 +eth25:125,126,127,128 +eth26:121,122,123,124 +eth27:81,82,83,84 +eth28:85,86,87,88 +eth29:93,94,95,96 +eth30:89,90,91,92 +eth31:101,102,103,104 +eth32:97,98,99,100 diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/3/sai.profile b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/3/sai.profile index 52e2e289af60..bfc466f27e54 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/3/sai.profile +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/3/sai.profile @@ -1,2 +1,5 @@ -SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/td2-s6000-32x40G.config.bcm -SAI_NUM_ECMP_MEMBERS=32 +SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin +SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin +SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 +SAI_VS_HOSTIF_USE_TAP_DEVICE=true +SAI_VS_INTERFACE_LANE_MAP_FILE=/usr/share/sonic/hwsku/lanemap.ini diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/4/lanemap.ini b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/4/lanemap.ini new file mode 100644 index 000000000000..36278a01778c --- /dev/null +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/4/lanemap.ini @@ -0,0 +1,32 @@ +eth1:25,26,27,28 +eth2:29,30,31,32 +eth3:33,34,35,36 +eth4:37,38,39,40 +eth5:45,46,47,48 +eth6:41,42,43,44 +eth7:1,2,3,4 +eth8:5,6,7,8 +eth9:13,14,15,16 +eth10:9,10,11,12 +eth11:17,18,19,20 +eth12:21,22,23,24 +eth13:53,54,55,56 +eth14:49,50,51,52 +eth15:57,58,59,60 +eth16:61,62,63,64 +eth17:69,70,71,72 +eth18:65,66,67,68 +eth19:73,74,75,76 +eth20:77,78,79,80 +eth21:109,110,111,112 +eth22:105,106,107,108 +eth23:113,114,115,116 +eth24:117,118,119,120 +eth25:125,126,127,128 +eth26:121,122,123,124 +eth27:81,82,83,84 +eth28:85,86,87,88 +eth29:93,94,95,96 +eth30:89,90,91,92 +eth31:101,102,103,104 +eth32:97,98,99,100 diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/4/sai.profile b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/4/sai.profile index 52e2e289af60..bfc466f27e54 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/4/sai.profile +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/4/sai.profile @@ -1,2 +1,5 @@ -SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/td2-s6000-32x40G.config.bcm -SAI_NUM_ECMP_MEMBERS=32 +SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin +SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin +SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 +SAI_VS_HOSTIF_USE_TAP_DEVICE=true +SAI_VS_INTERFACE_LANE_MAP_FILE=/usr/share/sonic/hwsku/lanemap.ini diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/5/lanemap.ini b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/5/lanemap.ini new file mode 100644 index 000000000000..36278a01778c --- /dev/null +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/5/lanemap.ini @@ -0,0 +1,32 @@ +eth1:25,26,27,28 +eth2:29,30,31,32 +eth3:33,34,35,36 +eth4:37,38,39,40 +eth5:45,46,47,48 +eth6:41,42,43,44 +eth7:1,2,3,4 +eth8:5,6,7,8 +eth9:13,14,15,16 +eth10:9,10,11,12 +eth11:17,18,19,20 +eth12:21,22,23,24 +eth13:53,54,55,56 +eth14:49,50,51,52 +eth15:57,58,59,60 +eth16:61,62,63,64 +eth17:69,70,71,72 +eth18:65,66,67,68 +eth19:73,74,75,76 +eth20:77,78,79,80 +eth21:109,110,111,112 +eth22:105,106,107,108 +eth23:113,114,115,116 +eth24:117,118,119,120 +eth25:125,126,127,128 +eth26:121,122,123,124 +eth27:81,82,83,84 +eth28:85,86,87,88 +eth29:93,94,95,96 +eth30:89,90,91,92 +eth31:101,102,103,104 +eth32:97,98,99,100 diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/5/sai.profile b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/5/sai.profile index 52e2e289af60..bfc466f27e54 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/5/sai.profile +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/5/sai.profile @@ -1,2 +1,5 @@ -SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/td2-s6000-32x40G.config.bcm -SAI_NUM_ECMP_MEMBERS=32 +SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin +SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin +SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 +SAI_VS_HOSTIF_USE_TAP_DEVICE=true +SAI_VS_INTERFACE_LANE_MAP_FILE=/usr/share/sonic/hwsku/lanemap.ini diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh index 378f794190d4..6be348374019 100755 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh @@ -16,7 +16,9 @@ start () { for NUM in `seq 1 16`; do ORIG="eth$((16 * $ASIC + $NUM - 1))" TEMP="ethTemp999" - NEW="eth$(($NUM + 16))" + #NEW="eth$(($NUM + 16))" + NEW="eth$(($NUM))" + echo "$ASIC : $NEW old $ORIG" ip link set dev $ORIG down ip link set dev $ORIG name $TEMP # rename to prevent conflicts before renaming in new namespace ip link set dev $TEMP netns asic$ASIC @@ -29,8 +31,11 @@ start () { for BACKEND in `seq $FIRST_BACKEND_ASIC $LAST_BACKEND_ASIC`; do for FRONTEND in `seq $FIRST_FRONTEND_ASIC $LAST_FRONTEND_ASIC`; do for LINK in `seq 1 8`; do - BACK_NAME="eth$((8 * $FRONTEND + $LINK))" - FRONT_NAME="eth$((8 * $(($LAST_BACKEND_ASIC - $BACKEND)) + $LINK))" + #BACK_NAME="eth$((8 * $FRONTEND + $LINK))" + #FRONT_NAME="eth$((8 * $(($LAST_BACKEND_ASIC - $BACKEND)) + $LINK))" + FRONT_NAME="eth$((8 * $(($BACKEND - $FIRST_BACKEND_ASIC)) + $LINK + 16))" + BACK_NAME="eth$((8 * $FRONTEND + $LINK))" + echo "$FRONTEND:$FRONT_NAME - $BACKEND:$BACK_NAME" TEMP_BACK="ethBack999" TEMP_FRONT="ethFront999" @@ -52,7 +57,7 @@ stop() { for ASIC in `seq $FIRST_FRONTEND_ASIC $LAST_FRONTEND_ASIC`; do for NUM in `seq 1 16`; do TEMP="eth999" - OLD="eth$(($NUM + 16))" + OLD="eth$((16 * $ASIC + $NUM))" NAME="eth$((16 * $ASIC + $NUM - 1))" sudo ip netns exec asic$ASIC ip link set dev $OLD down sudo ip netns exec asic$ASIC ip link set dev $OLD name $TEMP @@ -78,4 +83,3 @@ case "$1" in echo "Usage: $0 {start|stop}" ;; esac - From 173ba4e407ce914e777486ca6170fdebc73c1ae0 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 21 Feb 2020 16:27:26 -0800 Subject: [PATCH 28/57] [syncd.sh/swss.sh]: Modify script to use sonic-db-cli wrapper. --- files/scripts/swss.sh | 32 ++++++++++++++++---------------- files/scripts/syncd.sh | 8 ++++---- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 4e2bda030ffe..38c19fe22fea 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -28,8 +28,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" else @@ -40,7 +40,7 @@ function check_warm_boot() function validate_restore_count() { if [[ x"$WARM_BOOT" == x"true" ]]; then - RESTORE_COUNT=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` + RESTORE_COUNT=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` # We have to make sure db data has not been flushed. if [[ -z "$RESTORE_COUNT" ]]; then WARM_BOOT="false" @@ -54,7 +54,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(/usr/bin/redis-cli $DEV CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(/usr/bin/sonic-db-cli $DEV CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -64,7 +64,7 @@ function wait_for_database_service() # $2 the string of a list of table prefixes function clean_up_tables() { - /usr/bin/redis-cli $DEV $1 EVAL " + /usr/bin/sonic-db-cli $DEV $1 EVAL " local tables = {$2} for i = 1, table.getn(tables) do local matches = redis.call('KEYS', tables[i]) @@ -79,9 +79,9 @@ start_peer_and_dependent_services() { if [[ x"$WARM_BOOT" != x"true" ]]; then if [[ ! -z $DEV ]]; then - /bin/systemctl start ${PEER}@$DEV + /bin/systemctl start ${PEER}@$DEV else - /bin/systemctl start ${PEER} + /bin/systemctl start ${PEER} fi for dep in ${DEPENDENT}; do /bin/systemctl start ${dep} @@ -99,11 +99,11 @@ start_peer_and_dependent_services() { stop_peer_and_dependent_services() { # if warm start enabled or peer lock exists, don't stop peer service docker if [[ x"$WARM_BOOT" != x"true" ]]; then - if [[ ! -z $DEV ]]; then - /bin/systemctl stop ${PEER}@$DEV - else - /bin/systemctl stop ${PEER} - fi + if [[ ! -z $DEV ]]; then + /bin/systemctl stop ${PEER}@$DEV + else + /bin/systemctl stop ${PEER} + fi for dep in ${DEPENDENT}; do /bin/systemctl stop ${dep} done @@ -132,10 +132,10 @@ start() { # Don't flush DB during warm boot if [[ x"$WARM_BOOT" != x"true" ]]; then debug "Flushing APP, ASIC, COUNTER, CONFIG, and partial STATE databases ..." - /usr/bin/redis-cli $DEV APPL_DB FLUSHDB - /usr/bin/redis-cli $DEV ASIC_DB FLUSHDB - /usr/bin/redis-cli $DEV COUNTERS_DB FLUSHDB - /usr/bin/redis-cli $DEV FLEX_COUNTER_DB FLUSHDB + /usr/bin/sonic-db-cli $DEV APPL_DB FLUSHDB + /usr/bin/sonic-db-cli $DEV ASIC_DB FLUSHDB + /usr/bin/sonic-db-cli $DEV COUNTERS_DB FLUSHDB + /usr/bin/sonic-db-cli $DEV FLEX_COUNTER_DB FLUSHDB clean_up_tables STATE_DB "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*'" fi diff --git a/files/scripts/syncd.sh b/files/scripts/syncd.sh index 6201844cb509..062a8b4f5750 100755 --- a/files/scripts/syncd.sh +++ b/files/scripts/syncd.sh @@ -26,8 +26,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`/usr/bin/redis-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` # SYSTEM_WARM_START could be empty, always make WARM_BOOT meaningful. if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" @@ -42,7 +42,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(/usr/bin/redis-cli $DEV CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(/usr/bin/sonic-db-cli $DEV CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -59,7 +59,7 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - if [[ $(/usr/bin/redis-cli $DEV STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + if [[ $(/usr/bin/sonic-db-cli $DEV STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then TYPE='fast' else TYPE='cold' From 3a8a68cd8b160fa390c6035d36126297ff38cfc7 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 21 Feb 2020 17:08:35 -0800 Subject: [PATCH 29/57] [docker_image_ctl.j2]: Minor fix --- .../x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh | 3 --- files/build_templates/docker_image_ctl.j2 | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh index 6be348374019..04b8498200b2 100755 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh @@ -16,7 +16,6 @@ start () { for NUM in `seq 1 16`; do ORIG="eth$((16 * $ASIC + $NUM - 1))" TEMP="ethTemp999" - #NEW="eth$(($NUM + 16))" NEW="eth$(($NUM))" echo "$ASIC : $NEW old $ORIG" ip link set dev $ORIG down @@ -31,8 +30,6 @@ start () { for BACKEND in `seq $FIRST_BACKEND_ASIC $LAST_BACKEND_ASIC`; do for FRONTEND in `seq $FIRST_FRONTEND_ASIC $LAST_FRONTEND_ASIC`; do for LINK in `seq 1 8`; do - #BACK_NAME="eth$((8 * $FRONTEND + $LINK))" - #FRONT_NAME="eth$((8 * $(($LAST_BACKEND_ASIC - $BACKEND)) + $LINK))" FRONT_NAME="eth$((8 * $(($BACKEND - $FIRST_BACKEND_ASIC)) + $LINK + 16))" BACK_NAME="eth$((8 * $FRONTEND + $LINK))" echo "$FRONTEND:$FRONT_NAME - $BACKEND:$BACK_NAME" diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index bdbc667c40ed..549fe8cb7583 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -278,7 +278,9 @@ wait() { stop() { docker stop {{docker_container_name}}$DEV {%- if docker_container_name == "database" %} - ip netns delete "$NET_NS$DEV" + if [ "$DEV" ]; then + ip netns delete "$NET_NS$DEV" + fi {%- endif %} } From f2d02bc8cb82859dc128da0a7a6e011e5e33137c Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Sun, 23 Feb 2020 20:00:51 -0800 Subject: [PATCH 30/57] Modified creation of multi-asic frr directories from build time to during bootup. --- files/build_templates/docker_image_ctl.j2 | 8 +++++++- files/build_templates/sonic_debian_extension.j2 | 8 -------- files/scripts/sonic-db-cli | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 549fe8cb7583..e25748a1f701 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -223,7 +223,13 @@ start() { NET="container:database$DEV" {%- endif %} fi - +{%- if docker_container_name == "bgp" %} + if [ "$DEV" ]; then + if [ ! -d "/etc/sonic/frr$DEV" ]; then + cp -r /etc/sonic/frr /etc/sonic/frr$DEV + fi + fi +{%- endif %} {%- if sonic_asic_platform == "mellanox" %} # TODO: Mellanox will remove the --tmpfs exception after SDK socket path changed in new SDK version {%- endif %} diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 766316e9ffb4..324260776ceb 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -477,14 +477,6 @@ sudo rm -rf $FILESYSTEM_ROOT/$MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME {% endif %} {%- if SONIC_ROUTING_STACK == "frr" %} - {% for i in range(6) %} -sudo mkdir $FILESYSTEM_ROOT/etc/sonic/frr{{i}} -sudo touch $FILESYSTEM_ROOT/etc/sonic/frr{{i}}/frr.conf -sudo touch $FILESYSTEM_ROOT/etc/sonic/frr{{i}}/vtysh.conf -sudo chown -R $FRR_USER_UID:$FRR_USER_GID $FILESYSTEM_ROOT/etc/sonic/frr{{i}} -sudo chmod -R 640 $FILESYSTEM_ROOT/etc/sonic/frr{{i}}/ -sudo chmod 750 $FILESYSTEM_ROOT/etc/sonic/frr{{i}} - {%- endfor %} sudo mkdir $FILESYSTEM_ROOT/etc/sonic/frr sudo touch $FILESYSTEM_ROOT/etc/sonic/frr/frr.conf sudo touch $FILESYSTEM_ROOT/etc/sonic/frr/vtysh.conf diff --git a/files/scripts/sonic-db-cli b/files/scripts/sonic-db-cli index a8a005503309..ff6f25ea5e13 100755 --- a/files/scripts/sonic-db-cli +++ b/files/scripts/sonic-db-cli @@ -1,5 +1,4 @@ #!/bin/bash - ½ NS="asic" #Network namespace [ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number # if it's a number, set the database instance to From d252a19e649cbf0bfcc4f4f8148e1d5059e16f4e Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Sun, 23 Feb 2020 20:15:52 -0800 Subject: [PATCH 31/57] [sonic_multiasic.xml]: Increased the number of vcpus to support multi-asic VS. --- platform/vs/sonic_multiasic.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/vs/sonic_multiasic.xml b/platform/vs/sonic_multiasic.xml index b406bfd40475..b571b5122a52 100644 --- a/platform/vs/sonic_multiasic.xml +++ b/platform/vs/sonic_multiasic.xml @@ -1,7 +1,7 @@ sonic 8 - 2 + 8 /machine From 5ba42dfbb6730791c07e6b9f4dea4800b2b7294b Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 25 Feb 2020 13:38:52 -0800 Subject: [PATCH 32/57] [sonic_debian_extension]: Add config-setup.service in generated_services.conf file --- files/build_templates/sonic_debian_extension.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 324260776ceb..cf8250a841f6 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -290,6 +290,7 @@ j2 files/build_templates/init_cfg.json.j2 | sudo tee $FILESYSTEM_ROOT/etc/sonic/ # Copy config-setup script and service file j2 files/build_templates/config-setup.service.j2 | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/config-setup.service sudo cp $IMAGE_CONFIGS/config-setup/config-setup $FILESYSTEM_ROOT/usr/bin/config-setup +echo "config-setup.service" | sudo tee -a $GENERATED_SERVICE_FILE sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable config-setup.service # Copy SNMP configuration files From 97d2643309fd137cc4730f5b99d5ddb45007e89d Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Wed, 26 Feb 2020 11:17:52 -0800 Subject: [PATCH 33/57] [sonic-netns-exec]: Added a new wrapper to execute any command in a specific namespace instance. - Modify docker_image_ctl and other scripts to use this new wrapper - Add config-setup.service in generated_services file --- files/build_templates/docker_image_ctl.j2 | 18 ++++++++---------- .../build_templates/sonic_debian_extension.j2 | 3 +-- files/scripts/sonic-cfggen | 11 ----------- .../scripts/{sonic-db-cli => sonic-netns-exec} | 11 ++++++++--- files/scripts/swss.sh | 18 +++++++++--------- files/scripts/syncd.sh | 8 ++++---- 6 files changed, 30 insertions(+), 39 deletions(-) delete mode 100755 files/scripts/sonic-cfggen rename files/scripts/{sonic-db-cli => sonic-netns-exec} (53%) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index e25748a1f701..a773f99ae829 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -89,7 +89,7 @@ function preStartAction() docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/ fi {%- elif docker_container_name == "snmp" %} - /usr/bin/sonic-db-cli $DEV STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) + sonic-netns-exec $DEV sonic-db-cli STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) {%- else %} : # nothing {%- endif %} @@ -103,27 +103,25 @@ function postStartAction() fi # Wait until redis starts /usr/bin/docker exec database$DEV ping_pong_db_insts - REDIS_SOCK="/var/run/redis/redis.sock" - EXT_REDIS_SOCK="/var/run/redis$DEV/redis.sock" # location of redis socket in the base image if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast") && -f $WARM_DIR/dump.rdb ]]; then rm -f $WARM_DIR/dump.rdb else # If there is a config db dump file, load it if [ -r /etc/sonic/config_db$DEV.json ]; then - /usr/bin/sonic-cfggen $DEV -j /etc/sonic/config_db$DEV.json --write-to-db + sonic-netns-exec $DEV sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db fi if [[ "$BOOT_TYPE" == "fast" ]]; then # set the key to expire in 3 minutes - /usr/bin/sonic-db-cli $DEV STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" + /usr/bin/sonic-netns-exec $DEV sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" fi - /usr/bin/sonic-db-cli $DEV CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" + /usr/bin/sonic-netns-exec $DEV sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" fi if [[ -x /usr/bin/db_migrator.py ]]; then # Migrate the DB to the latest schema version if needed - /usr/bin/db_migrator.py -o migrate -s $EXT_REDIS_SOCK + /usr/bin/db_migrator.py -o migrate # Save in memory config_db to config_db.json for 2 reasons: # 1. Persist the DB migration result. @@ -160,15 +158,15 @@ start() { BOOT_TYPE=`getBootType` # Obtain our platform as we will mount directories with these names in each docker - PLATFORM=`/usr/bin/sonic-cfggen $DEV -H -v DEVICE_METADATA.localhost.platform` + PLATFORM=`sonic-netns-exec $DEV sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` {%- if docker_container_name == "database" %} # Don't mount HWSKU in {{docker_container_name}} container. HWSKU="" {%- else %} # Obtain our HWSKU as we will mount directories with these names in each docker - HWSKU=`/usr/bin/sonic-cfggen $DEV -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` - HOSTNAME=`/usr/bin/sonic-cfggen $DEV -d -v 'DEVICE_METADATA["localhost"]["hostname"]'` + HWSKU=`sonic-netns-exec $DEV sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + HOSTNAME=`sonic-netns-exec $DEV sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hostname"]'` {%- endif %} if [ -z "$HOSTNAME" ] || ! [[ $HOSTNAME =~ ^[a-zA-Z0-9.\-]*$ ]]; then HOSTNAME=`hostname` diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index cf8250a841f6..38b93874b067 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -436,8 +436,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys # Copy swss and syncd service script sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh -sudo LANG=C cp $SCRIPTS_DIR/sonic-cfggen $FILESYSTEM_ROOT/usr/bin/sonic-cfggen -sudo LANG=C cp $SCRIPTS_DIR/sonic-db-cli $FILESYSTEM_ROOT/usr/bin/sonic-db-cli +sudo LANG=C cp $SCRIPTS_DIR/sonic-netns-exec $FILESYSTEM_ROOT/usr/bin/sonic-netns-exec # Copy systemd timer configuration # It implements delayed start of services diff --git a/files/scripts/sonic-cfggen b/files/scripts/sonic-cfggen deleted file mode 100755 index a63935525ccb..000000000000 --- a/files/scripts/sonic-cfggen +++ /dev/null @@ -1,11 +0,0 @@ -NS="asic" #Network namespace -[ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number -if [ $? -eq 0 ]; then - DEV="$1" - shift -fi -if [ -z "$DEV" ]; then - /usr/local/bin/sonic-cfggen "$@" -else - ip netns exec $NS$DEV /usr/local/bin/sonic-cfggen "$@" -fi diff --git a/files/scripts/sonic-db-cli b/files/scripts/sonic-netns-exec similarity index 53% rename from files/scripts/sonic-db-cli rename to files/scripts/sonic-netns-exec index ff6f25ea5e13..75618d502e4a 100755 --- a/files/scripts/sonic-db-cli +++ b/files/scripts/sonic-netns-exec @@ -1,14 +1,19 @@ #!/bin/bash +# Wrapper to execute any command in a specific +# network namespace. +# Usage: +# sonic-netns-exec + NS="asic" #Network namespace [ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number # if it's a number, set the database instance to -#operate on that instance +# operate on that instance if [ $? -eq 0 ]; then DEV="$1" shift fi if [ -z "$DEV" ]; then - /usr/local/bin/sonic-db-cli "$@" + "$@" else - ip netns exec $NS$DEV /usr/local/bin/sonic-db-cli "$@" + ip netns exec $NS$DEV "$@" fi diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 38c19fe22fea..a392178ee864 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -28,8 +28,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" else @@ -40,7 +40,7 @@ function check_warm_boot() function validate_restore_count() { if [[ x"$WARM_BOOT" == x"true" ]]; then - RESTORE_COUNT=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` + RESTORE_COUNT=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` # We have to make sure db data has not been flushed. if [[ -z "$RESTORE_COUNT" ]]; then WARM_BOOT="false" @@ -54,7 +54,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(/usr/bin/sonic-db-cli $DEV CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(sonic-netns-exec $DEV sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -64,7 +64,7 @@ function wait_for_database_service() # $2 the string of a list of table prefixes function clean_up_tables() { - /usr/bin/sonic-db-cli $DEV $1 EVAL " + sonic-netns-exec $DEV sonic-db-cli $1 EVAL " local tables = {$2} for i = 1, table.getn(tables) do local matches = redis.call('KEYS', tables[i]) @@ -132,10 +132,10 @@ start() { # Don't flush DB during warm boot if [[ x"$WARM_BOOT" != x"true" ]]; then debug "Flushing APP, ASIC, COUNTER, CONFIG, and partial STATE databases ..." - /usr/bin/sonic-db-cli $DEV APPL_DB FLUSHDB - /usr/bin/sonic-db-cli $DEV ASIC_DB FLUSHDB - /usr/bin/sonic-db-cli $DEV COUNTERS_DB FLUSHDB - /usr/bin/sonic-db-cli $DEV FLEX_COUNTER_DB FLUSHDB + sonic-netns-exec $DEV sonic-db-cli APPL_DB FLUSHDB + sonic-netns-exec $DEV sonic-db-cli ASIC_DB FLUSHDB + sonic-netns-exec $DEV sonic-db-cli COUNTERS_DB FLUSHDB + sonic-netns-exec $DEV sonic-db-cli FLEX_COUNTER_DB FLUSHDB clean_up_tables STATE_DB "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*'" fi diff --git a/files/scripts/syncd.sh b/files/scripts/syncd.sh index 062a8b4f5750..8fac92eff74f 100755 --- a/files/scripts/syncd.sh +++ b/files/scripts/syncd.sh @@ -26,8 +26,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`/usr/bin/sonic-db-cli $DEV STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` # SYSTEM_WARM_START could be empty, always make WARM_BOOT meaningful. if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" @@ -42,7 +42,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(/usr/bin/sonic-db-cli $DEV CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(sonic-netns-exec $DEV sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -59,7 +59,7 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - if [[ $(/usr/bin/sonic-db-cli $DEV STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + if [[ $(sonic-netns-exec $DEV sonic-db-cli STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then TYPE='fast' else TYPE='cold' From d83392a86491b1bae35be716c3cfc95a47dee314 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Wed, 26 Feb 2020 13:06:10 -0800 Subject: [PATCH 34/57] [rsyslog-service]: Remove multiple instance systemd service templates rsyslog-service@ and rsyslog@.service files. --- files/build_templates/sonic_debian_extension.j2 | 4 ---- files/image_config/rsyslog/rsyslog-config.sh | 2 +- files/image_config/rsyslog/rsyslog-config@.service | 13 ------------- files/image_config/rsyslog/rsyslog@.service | 14 -------------- 4 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 files/image_config/rsyslog/rsyslog-config@.service delete mode 100644 files/image_config/rsyslog/rsyslog@.service diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 38b93874b067..1095fc219d8d 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -202,14 +202,10 @@ echo "warmboot-finalizer.service" | sudo tee -a $GENERATED_SERVICE_FILE # Copy rsyslog configuration files and templates sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.service $FILESYSTEM_ROOT/etc/systemd/system/ -sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config@.service $FILESYSTEM_ROOT/etc/systemd/system/ -sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog@.service $FILESYSTEM_ROOT/etc/systemd/system sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.conf.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.d/* $FILESYSTEM_ROOT/etc/rsyslog.d/ echo "rsyslog-config.service" | sudo tee -a $GENERATED_SERVICE_FILE -echo "rsyslog-config@.service" | sudo tee -a $GENERATED_SERVICE_FILE -echo "rsyslog@.service" | sudo tee -a $GENERATED_SERVICE_FILE # Copy logrotate.d configuration files sudo cp -f $IMAGE_CONFIGS/logrotate/logrotate.d/* $FILESYSTEM_ROOT/etc/logrotate.d/ diff --git a/files/image_config/rsyslog/rsyslog-config.sh b/files/image_config/rsyslog/rsyslog-config.sh index 83f556cee42b..c8ba7b99453c 100755 --- a/files/image_config/rsyslog/rsyslog-config.sh +++ b/files/image_config/rsyslog/rsyslog-config.sh @@ -1,4 +1,4 @@ #!/bin/bash -sonic-cfggen -s /var/run/redis$1/redis.sock -d -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog$1.conf +sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog.conf systemctl restart rsyslog diff --git a/files/image_config/rsyslog/rsyslog-config@.service b/files/image_config/rsyslog/rsyslog-config@.service deleted file mode 100644 index 5b18bfd75f18..000000000000 --- a/files/image_config/rsyslog/rsyslog-config@.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Update rsyslog configuration -Requires=database@%i.service -After=database@%i.service -#Requires=updategraph.service -#After=updategraph.service - -[Service] -Type=oneshot -ExecStart=/usr/bin/rsyslog-config.sh %i - -[Install] -WantedBy=multi-user.target diff --git a/files/image_config/rsyslog/rsyslog@.service b/files/image_config/rsyslog/rsyslog@.service deleted file mode 100644 index 300724e47164..000000000000 --- a/files/image_config/rsyslog/rsyslog@.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Network Namespace Compatible Logging Service -Requires=syslog.socket -After=rsyslog-config@%i.service - -[Service] -Type=notify -User=root -ExecStart=/bin/ip netns exec asic%i /usr/sbin/rsyslogd -n -i /var/run/rsyslogd%i.pid -f /etc/rsyslog%i.conf -StandardOutput=null -Restart=on-failure - -[Install] -WantedBy=multi-user.target From 9dddcfffaecf61910d7a9101296b4f9db3326388 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Wed, 26 Feb 2020 14:01:59 -0800 Subject: [PATCH 35/57] [interfaces-config.sh]: Updated script to use sonic-db-cli to configure Loopback Ip in a specific namespace. - Modified redis-cli to accept a database docker instance number. - Minor fix in topology.sh --- .../x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh | 2 +- dockers/docker-database/base_image_files/redis-cli | 8 +++++++- files/image_config/interfaces/interfaces-config.sh | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh index 04b8498200b2..35f9976b8ccc 100755 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh @@ -14,7 +14,7 @@ start () { # eth48 - eth63: asic5 for ASIC in `seq $FIRST_FRONTEND_ASIC $LAST_FRONTEND_ASIC`; do for NUM in `seq 1 16`; do - ORIG="eth$((16 * $ASIC + $NUM - 1))" + ORIG="eth$((16 * $ASIC + $NUM))" TEMP="ethTemp999" NEW="eth$(($NUM))" echo "$ASIC : $NEW old $ORIG" diff --git a/dockers/docker-database/base_image_files/redis-cli b/dockers/docker-database/base_image_files/redis-cli index 6ce1951cd4b9..abc2cf4c7085 100755 --- a/dockers/docker-database/base_image_files/redis-cli +++ b/dockers/docker-database/base_image_files/redis-cli @@ -7,4 +7,10 @@ if [ -t 1 ] ; then DOCKER_EXEC_FLAGS+="t" fi -docker exec -$DOCKER_EXEC_FLAGS database redis-cli "$@" +[ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number +if [ $? -eq 0 ]; then # if it's a number, set the database instance to operate on + DEV="$1" + shift +fi + +docker exec -$DOCKER_EXEC_FLAGS database$DEV redis-cli "$@" diff --git a/files/image_config/interfaces/interfaces-config.sh b/files/image_config/interfaces/interfaces-config.sh index 91604a2dd6fc..01aad274d163 100755 --- a/files/image_config/interfaces/interfaces-config.sh +++ b/files/image_config/interfaces/interfaces-config.sh @@ -40,11 +40,11 @@ if [ -z "$NS" ]; then # Clean-up created files rm -f /tmp/ztp_input.json /tmp/ztp_port_data.json else - INTF_LIST=`redis-cli $NS CONFIG_DB KEYS 'LOOPBACK_INTERFACE*'` + INTF_LIST=`sonic-netns-exec $NS sonic-db-cli CONFIG_DB KEYS 'LOOPBACK_INTERFACE*'` for ENTRY in $INTF_LIST; do IFS='|' read -ra ADDR_ARRAY <<< "$ENTRY" ADDR=${ADDR_ARRAY[2]} ADDR=`echo $ADDR | tr -d \''[]'` - ip netns exec asic$NS ip addr add $ADDR dev lo + sonic-netns-exec $NS ip addr add $ADDR dev lo done fi From e2a9e6c15081c137a07fd1eea2231af8f86d2319 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Thu, 27 Feb 2020 18:03:31 -0800 Subject: [PATCH 36/57] [sonic-netns-exec]: Modified to accept network namespace string as a parameter. --- files/build_templates/docker_image_ctl.j2 | 28 +++++++++++++---------- files/scripts/sonic-netns-exec | 19 +++++---------- files/scripts/swss.sh | 23 +++++++++++-------- files/scripts/syncd.sh | 13 +++++++---- 4 files changed, 45 insertions(+), 38 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 0e31d2b901a4..92d0c22270be 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -14,15 +14,15 @@ link_namespace() { mkdir -p /var/run/netns PID="$(docker inspect -f {{"'{{.State.Pid}}'"}} "{{docker_container_name}}$DEV")" - if `ip netns | grep --quiet -w "$NET_NS$DEV"`; then # namespace exists - if [ $(readlink -f /var/run/netns/$NET_NS$DEV) = $(readlink -f /proc/$PID/ns/net) ]; then # namespace is correctly linked + if `ip netns | grep --quiet -w "$NET_NS"`; then # namespace exists + if [ $(readlink -f /var/run/netns/$NET_NS) = $(readlink -f /proc/$PID/ns/net) ]; then # namespace is correctly linked return 0 else # if it's incorrectly linked remove it - ip netns delete $NET_NS$DEV + ip netns delete $NET_NS fi fi - ln -s /proc/$PID/ns/net /var/run/netns/$NET_NS$DEV + ln -s /proc/$PID/ns/net /var/run/netns/$NET_NS } {%- endif %} @@ -63,7 +63,7 @@ function preStartAction() docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/ fi {%- elif docker_container_name == "snmp" %} - sonic-netns-exec $DEV sonic-db-cli STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) + sonic-netns-exec $NET_NS sonic-db-cli STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) {%- else %} : # nothing {%- endif %} @@ -82,15 +82,15 @@ function postStartAction() else # If there is a config db dump file, load it if [ -r /etc/sonic/config_db$DEV.json ]; then - sonic-netns-exec $DEV sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db + sonic-netns-exec $NET_NS sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db fi if [[ "$BOOT_TYPE" == "fast" ]]; then # set the key to expire in 3 minutes - /usr/bin/sonic-netns-exec $DEV sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" + /usr/bin/sonic-netns-exec $NET_NS sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" fi - /usr/bin/sonic-netns-exec $DEV sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" + /usr/bin/sonic-netns-exec $NET_NS sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" fi if [[ -x /usr/bin/db_migrator.py ]]; then @@ -132,14 +132,14 @@ start() { BOOT_TYPE=`getBootType` # Obtain our platform as we will mount directories with these names in each docker - PLATFORM=`sonic-netns-exec $DEV sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + PLATFORM=`sonic-netns-exec $NET_NS sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` {%- if docker_container_name == "database" %} # Don't mount HWSKU in {{docker_container_name}} container. HWSKU="" {%- else %} # Obtain our HWSKU as we will mount directories with these names in each docker - HWSKU=`sonic-netns-exec $DEV sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + HWSKU=`sonic-netns-exec $NET_NS sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` {%- endif %} DOCKERCHECK=`docker inspect --type container {{docker_container_name}}$DEV 2>/dev/null` @@ -248,14 +248,18 @@ stop() { docker stop {{docker_container_name}}$DEV {%- if docker_container_name == "database" %} if [ "$DEV" ]; then - ip netns delete "$NET_NS$DEV" + ip netns delete "$NET_NS" fi {%- endif %} } OP=$1 DEV=$2 # namespace/device number to operate on -NET_NS="asic" #name of the network namespace +if [ "$DEV" ]; then + NET_NS="asic$DEV" #name of the network namespace +else + NET_NS="" +fi case "$1" in start|wait|stop) diff --git a/files/scripts/sonic-netns-exec b/files/scripts/sonic-netns-exec index 75618d502e4a..3277017ba011 100755 --- a/files/scripts/sonic-netns-exec +++ b/files/scripts/sonic-netns-exec @@ -2,18 +2,11 @@ # Wrapper to execute any command in a specific # network namespace. # Usage: -# sonic-netns-exec - -NS="asic" #Network namespace -[ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number -# if it's a number, set the database instance to -# operate on that instance -if [ $? -eq 0 ]; then - DEV="$1" - shift -fi -if [ -z "$DEV" ]; then - "$@" +# sonic-netns-exec +NS="$1" +shift +if [ "$NS" != "" ]; then + ip netns exec $NS "$@" else - ip netns exec $NS$DEV "$@" + "$@" fi diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index a392178ee864..b27ad0b3d36e 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -28,8 +28,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" else @@ -40,7 +40,7 @@ function check_warm_boot() function validate_restore_count() { if [[ x"$WARM_BOOT" == x"true" ]]; then - RESTORE_COUNT=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` + RESTORE_COUNT=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` # We have to make sure db data has not been flushed. if [[ -z "$RESTORE_COUNT" ]]; then WARM_BOOT="false" @@ -54,7 +54,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(sonic-netns-exec $DEV sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(sonic-netns-exec $NET_NS sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -64,7 +64,7 @@ function wait_for_database_service() # $2 the string of a list of table prefixes function clean_up_tables() { - sonic-netns-exec $DEV sonic-db-cli $1 EVAL " + sonic-netns-exec $NET_NS sonic-db-cli $1 EVAL " local tables = {$2} for i = 1, table.getn(tables) do local matches = redis.call('KEYS', tables[i]) @@ -132,10 +132,10 @@ start() { # Don't flush DB during warm boot if [[ x"$WARM_BOOT" != x"true" ]]; then debug "Flushing APP, ASIC, COUNTER, CONFIG, and partial STATE databases ..." - sonic-netns-exec $DEV sonic-db-cli APPL_DB FLUSHDB - sonic-netns-exec $DEV sonic-db-cli ASIC_DB FLUSHDB - sonic-netns-exec $DEV sonic-db-cli COUNTERS_DB FLUSHDB - sonic-netns-exec $DEV sonic-db-cli FLEX_COUNTER_DB FLUSHDB + sonic-netns-exec $NET_NS sonic-db-cli APPL_DB FLUSHDB + sonic-netns-exec $NET_NS sonic-db-cli ASIC_DB FLUSHDB + sonic-netns-exec $NET_NS sonic-db-cli COUNTERS_DB FLUSHDB + sonic-netns-exec $NET_NS sonic-db-cli FLEX_COUNTER_DB FLUSHDB clean_up_tables STATE_DB "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*'" fi @@ -206,6 +206,11 @@ SERVICE="swss" PEER="syncd" DEBUGLOG="/tmp/swss-syncd-debug$DEV.log" LOCKFILE="/tmp/swss-syncd-lock$DEV" +if [ "$DEV" ]; then + NET_NS="asic$DEV" #name of the network namespace +else + NET_NS="" +fi case "$1" in start|wait|stop) diff --git a/files/scripts/syncd.sh b/files/scripts/syncd.sh index 8fac92eff74f..72ef4b55f098 100755 --- a/files/scripts/syncd.sh +++ b/files/scripts/syncd.sh @@ -26,8 +26,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`sonic-netns-exec $DEV sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` # SYSTEM_WARM_START could be empty, always make WARM_BOOT meaningful. if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" @@ -42,7 +42,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(sonic-netns-exec $DEV sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(sonic-netns-exec $NET_NS sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -59,7 +59,7 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - if [[ $(sonic-netns-exec $DEV sonic-db-cli STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + if [[ $(sonic-netns-exec $NET_NS sonic-db-cli STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then TYPE='fast' else TYPE='cold' @@ -195,6 +195,11 @@ SERVICE="syncd" PEER="swss" DEBUGLOG="/tmp/swss-syncd-debug$DEV.log" LOCKFILE="/tmp/swss-syncd-lock$DEV" +if [ "$DEV" ]; then + NET_NS="asic$DEV" #name of the network namespace +else + NET_NS="" +fi case "$1" in start|wait|stop) From 5f8ffe6b3292692b77f7268fa3e8cb7fecc17125 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 28 Feb 2020 11:05:35 -0800 Subject: [PATCH 37/57] Minor correction to pass the right parameter to sonic-netns-exec wrapper. --- files/build_templates/docker_image_ctl.j2 | 12 ++++++------ files/scripts/swss.sh | 18 +++++++++--------- files/scripts/syncd.sh | 8 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 92d0c22270be..0a4657382fec 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -63,7 +63,7 @@ function preStartAction() docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/ fi {%- elif docker_container_name == "snmp" %} - sonic-netns-exec $NET_NS sonic-db-cli STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) + sonic-netns-exec "$NET_NS" sonic-db-cli STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s) {%- else %} : # nothing {%- endif %} @@ -82,15 +82,15 @@ function postStartAction() else # If there is a config db dump file, load it if [ -r /etc/sonic/config_db$DEV.json ]; then - sonic-netns-exec $NET_NS sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db + sonic-netns-exec "$NET_NS" sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db fi if [[ "$BOOT_TYPE" == "fast" ]]; then # set the key to expire in 3 minutes - /usr/bin/sonic-netns-exec $NET_NS sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" + /usr/bin/sonic-netns-exec "$NET_NS" sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" fi - /usr/bin/sonic-netns-exec $NET_NS sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" + /usr/bin/sonic-netns-exec "$NET_NS" sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" fi if [[ -x /usr/bin/db_migrator.py ]]; then @@ -132,14 +132,14 @@ start() { BOOT_TYPE=`getBootType` # Obtain our platform as we will mount directories with these names in each docker - PLATFORM=`sonic-netns-exec $NET_NS sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + PLATFORM=`sonic-netns-exec "$NET_NS" sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` {%- if docker_container_name == "database" %} # Don't mount HWSKU in {{docker_container_name}} container. HWSKU="" {%- else %} # Obtain our HWSKU as we will mount directories with these names in each docker - HWSKU=`sonic-netns-exec $NET_NS sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + HWSKU=`sonic-netns-exec "$NET_NS" sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` {%- endif %} DOCKERCHECK=`docker inspect --type container {{docker_container_name}}$DEV 2>/dev/null` diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index b27ad0b3d36e..360e331f3636 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -28,8 +28,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`sonic-netns-exec "$NET_NS" sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`sonic-netns-exec "$NET_NS" sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" else @@ -40,7 +40,7 @@ function check_warm_boot() function validate_restore_count() { if [[ x"$WARM_BOOT" == x"true" ]]; then - RESTORE_COUNT=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` + RESTORE_COUNT=`sonic-netns-exec "$NET_NS" sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count` # We have to make sure db data has not been flushed. if [[ -z "$RESTORE_COUNT" ]]; then WARM_BOOT="false" @@ -54,7 +54,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(sonic-netns-exec $NET_NS sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(sonic-netns-exec "$NET_NS" sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -64,7 +64,7 @@ function wait_for_database_service() # $2 the string of a list of table prefixes function clean_up_tables() { - sonic-netns-exec $NET_NS sonic-db-cli $1 EVAL " + sonic-netns-exec "$NET_NS" sonic-db-cli $1 EVAL " local tables = {$2} for i = 1, table.getn(tables) do local matches = redis.call('KEYS', tables[i]) @@ -132,10 +132,10 @@ start() { # Don't flush DB during warm boot if [[ x"$WARM_BOOT" != x"true" ]]; then debug "Flushing APP, ASIC, COUNTER, CONFIG, and partial STATE databases ..." - sonic-netns-exec $NET_NS sonic-db-cli APPL_DB FLUSHDB - sonic-netns-exec $NET_NS sonic-db-cli ASIC_DB FLUSHDB - sonic-netns-exec $NET_NS sonic-db-cli COUNTERS_DB FLUSHDB - sonic-netns-exec $NET_NS sonic-db-cli FLEX_COUNTER_DB FLUSHDB + sonic-netns-exec "$NET_NS" sonic-db-cli APPL_DB FLUSHDB + sonic-netns-exec "$NET_NS" sonic-db-cli ASIC_DB FLUSHDB + sonic-netns-exec "$NET_NS" sonic-db-cli COUNTERS_DB FLUSHDB + sonic-netns-exec "$NET_NS" sonic-db-cli FLEX_COUNTER_DB FLUSHDB clean_up_tables STATE_DB "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*'" fi diff --git a/files/scripts/syncd.sh b/files/scripts/syncd.sh index 72ef4b55f098..9847cfec9406 100755 --- a/files/scripts/syncd.sh +++ b/files/scripts/syncd.sh @@ -26,8 +26,8 @@ function unlock_service_state_change() function check_warm_boot() { - SYSTEM_WARM_START=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`sonic-netns-exec $NET_NS sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + SYSTEM_WARM_START=`sonic-netns-exec "$NET_NS" sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`sonic-netns-exec "$NET_NS" sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` # SYSTEM_WARM_START could be empty, always make WARM_BOOT meaningful. if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then WARM_BOOT="true" @@ -42,7 +42,7 @@ function wait_for_database_service() /usr/bin/docker exec database$DEV ping_pong_db_insts # Wait for configDB initialization - until [[ $(sonic-netns-exec $NET_NS sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; + until [[ $(sonic-netns-exec "$NET_NS" sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; do sleep 1; done } @@ -59,7 +59,7 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - if [[ $(sonic-netns-exec $NET_NS sonic-db-cli STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + if [[ $(sonic-netns-exec "$NET_NS" sonic-db-cli STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then TYPE='fast' else TYPE='cold' From bf7b0c4bb44cc3ddb1d29c25fb9d0ca7e920af41 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 28 Feb 2020 11:16:00 -0800 Subject: [PATCH 38/57] [redis-cli]: Reverting changes added to redis-cli to execute in a specific database docker instance. --- dockers/docker-database/base_image_files/redis-cli | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/dockers/docker-database/base_image_files/redis-cli b/dockers/docker-database/base_image_files/redis-cli index abc2cf4c7085..6ce1951cd4b9 100755 --- a/dockers/docker-database/base_image_files/redis-cli +++ b/dockers/docker-database/base_image_files/redis-cli @@ -7,10 +7,4 @@ if [ -t 1 ] ; then DOCKER_EXEC_FLAGS+="t" fi -[ "$1" -eq "$1" ] 2> /dev/null # check if the first argument is a number -if [ $? -eq 0 ]; then # if it's a number, set the database instance to operate on - DEV="$1" - shift -fi - -docker exec -$DOCKER_EXEC_FLAGS database$DEV redis-cli "$@" +docker exec -$DOCKER_EXEC_FLAGS database redis-cli "$@" From 42a3572e6e2da9e8b722028f75bdad1b3ed2fdf2 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Wed, 4 Mar 2020 17:18:23 -0800 Subject: [PATCH 39/57] Review comments fix --- files/build_templates/docker_image_ctl.j2 | 5 ----- files/scripts/sonic-netns-exec | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 0a4657382fec..34e2a4803de8 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -96,11 +96,6 @@ function postStartAction() if [[ -x /usr/bin/db_migrator.py ]]; then # Migrate the DB to the latest schema version if needed /usr/bin/db_migrator.py -o migrate - - # Save in memory config_db to config_db.json for 2 reasons: - # 1. Persist the DB migration result. - # 2. Save in memory DB after warm reboot. - /usr/bin/config save -y fi {%- elif docker_container_name == "swss" %} docker exec swss$DEV rm -f /ready # remove cruft diff --git a/files/scripts/sonic-netns-exec b/files/scripts/sonic-netns-exec index 3277017ba011..166a2c7e4a2f 100755 --- a/files/scripts/sonic-netns-exec +++ b/files/scripts/sonic-netns-exec @@ -6,7 +6,7 @@ NS="$1" shift if [ "$NS" != "" ]; then - ip netns exec $NS "$@" + ip netns exec $NS $@ else - "$@" + $@ fi From 91af2237a1f603b9bbd78610aeae1a1ef00c4ebe Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Thu, 5 Mar 2020 18:12:48 -0800 Subject: [PATCH 40/57] [topology.sh]: Fix indentation --- files/image_config/topology/topology.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/files/image_config/topology/topology.sh b/files/image_config/topology/topology.sh index e1f278cadae1..dde7da247484 100755 --- a/files/image_config/topology/topology.sh +++ b/files/image_config/topology/topology.sh @@ -6,16 +6,16 @@ # start() { - TOPOLOGY_SCRIPT="topology.sh" - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` - HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` - /usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT start + TOPOLOGY_SCRIPT="topology.sh" + PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + /usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT start } stop() { - TOPOLOGY_SCRIPT="topology.sh" - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` - HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` - /usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT stop + TOPOLOGY_SCRIPT="topology.sh" + PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT stop } case "$1" in From 0e6033affcc05d383ba5a901d7aeeb378bf30c2a Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Mon, 9 Mar 2020 15:41:17 -0700 Subject: [PATCH 41/57] [interfaces-config]: remove multiple instances of interfaces-config@ service as Loopback interface configuration should not be done in this service. --- .../build_templates/sonic_debian_extension.j2 | 2 - .../interfaces/interfaces-config.sh | 71 ++++++++----------- .../interfaces/interfaces-config@.service | 11 --- 3 files changed, 30 insertions(+), 54 deletions(-) delete mode 100644 files/image_config/interfaces/interfaces-config@.service diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 1095fc219d8d..1c88d18f0cc6 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -214,11 +214,9 @@ sudo cp -f $IMAGE_CONFIGS/logrotate/logrotate.d/* $FILESYSTEM_ROOT/etc/logrotate sudo cp -f $IMAGE_CONFIGS/systemd/journald.conf $FILESYSTEM_ROOT/etc/systemd/ # Copy interfaces configuration files and templates -sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config@.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ -echo "interfaces-config@.service" | sudo tee -a $GENERATED_SERVICE_FILE echo "interfaces-config.service" | sudo tee -a $GENERATED_SERVICE_FILE # Copy dhcp client configuration template and create an initial configuration diff --git a/files/image_config/interfaces/interfaces-config.sh b/files/image_config/interfaces/interfaces-config.sh index 01aad274d163..b5352745a7ef 100755 --- a/files/image_config/interfaces/interfaces-config.sh +++ b/files/image_config/interfaces/interfaces-config.sh @@ -1,50 +1,39 @@ #!/bin/bash -NS=$1 -if [ -z "$NS" ]; then - ifdown --force eth0 - - # Check if ZTP DHCP policy has been installed - if [ -e /etc/network/ifupdown2/policy.d/ztp_dhcp.json ]; then - # Obtain port operational state information - redis-dump -d 0 -k "PORT_TABLE:Ethernet*" -y > /tmp/ztp_port_data.json - - if [ $? -ne 0 ] || [ ! -e /tmp/ztp_port_data.json ] || [ "$(cat /tmp/ztp_port_data.json)" = "" ]; then - echo "{}" > /tmp/ztp_port_data.json - fi - - # Create an input file with ztp input information - echo "{ \"PORT_DATA\" : $(cat /tmp/ztp_port_data.json) }" > \ - /tmp/ztp_input.json - else - echo "{ \"ZTP_DHCP_DISABLED\" : \"true\" }" > /tmp/ztp_input.json +ifdown --force eth0 + +# Check if ZTP DHCP policy has been installed +if [ -e /etc/network/ifupdown2/policy.d/ztp_dhcp.json ]; then + # Obtain port operational state information + redis-dump -d 0 -k "PORT_TABLE:Ethernet*" -y > /tmp/ztp_port_data.json + + if [ $? -ne 0 ] || [ ! -e /tmp/ztp_port_data.json ] || [ "$(cat /tmp/ztp_port_data.json)" = "" ]; then + echo "{}" > /tmp/ztp_port_data.json fi - # Create /e/n/i file for existing and active interfaces - sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/interfaces.j2 > /etc/network/interfaces + # Create an input file with ztp input information + echo "{ \"PORT_DATA\" : $(cat /tmp/ztp_port_data.json) }" > \ + /tmp/ztp_input.json +else + echo "{ \"ZTP_DHCP_DISABLED\" : \"true\" }" > /tmp/ztp_input.json +fi - [ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid - [ -f /var/run/dhclient6.eth0.pid ] && kill `cat /var/run/dhclient6.eth0.pid` && rm -f /var/run/dhclient6.eth0.pid +# Create /e/n/i file for existing and active interfaces +sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/interfaces.j2 > /etc/network/interfaces - for intf_pid in $(ls -1 /var/run/dhclient*.Ethernet*.pid 2> /dev/null); do - [ -f ${intf_pid} ] && kill `cat ${intf_pid}` && rm -f ${intf_pid} - done +[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid +[ -f /var/run/dhclient6.eth0.pid ] && kill `cat /var/run/dhclient6.eth0.pid` && rm -f /var/run/dhclient6.eth0.pid - sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/90-dhcp6-systcl.conf.j2 > /etc/sysctl.d/90-dhcp6-systcl.conf - # Read sysctl conf files again - sysctl -p /etc/sysctl.d/90-dhcp6-systcl.conf +for intf_pid in $(ls -1 /var/run/dhclient*.Ethernet*.pid 2> /dev/null); do + [ -f ${intf_pid} ] && kill `cat ${intf_pid}` && rm -f ${intf_pid} +done - sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/dhclient.conf.j2 > /etc/dhcp/dhclient.conf - systemctl restart networking +sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/90-dhcp6-systcl.conf.j2 > /etc/sysctl.d/90-dhcp6-systcl.conf +# Read sysctl conf files again +sysctl -p /etc/sysctl.d/90-dhcp6-systcl.conf - # Clean-up created files - rm -f /tmp/ztp_input.json /tmp/ztp_port_data.json -else - INTF_LIST=`sonic-netns-exec $NS sonic-db-cli CONFIG_DB KEYS 'LOOPBACK_INTERFACE*'` - for ENTRY in $INTF_LIST; do - IFS='|' read -ra ADDR_ARRAY <<< "$ENTRY" - ADDR=${ADDR_ARRAY[2]} - ADDR=`echo $ADDR | tr -d \''[]'` - sonic-netns-exec $NS ip addr add $ADDR dev lo - done -fi +sonic-cfggen -d -j /tmp/ztp_input.json -t /usr/share/sonic/templates/dhclient.conf.j2 > /etc/dhcp/dhclient.conf +systemctl restart networking + +# Clean-up created files +rm -f /tmp/ztp_input.json /tmp/ztp_port_data.json diff --git a/files/image_config/interfaces/interfaces-config@.service b/files/image_config/interfaces/interfaces-config@.service deleted file mode 100644 index 3bbadbf1bd33..000000000000 --- a/files/image_config/interfaces/interfaces-config@.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Update interfaces configuration -Requires=database@%i.service -After=database@%i.service - -[Service] -Type=oneshot -ExecStart=/usr/bin/interfaces-config.sh %i - -[Install] -RequiredBy=multi-user.target From fe3ba837ea1ba3af68024aeb908196aef81ca7ec Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Mon, 9 Mar 2020 18:43:44 -0700 Subject: [PATCH 42/57] [build_templates]: Combined single and multi instance service template files to a single template. Modified slave.mk to create single and multi-instance service files. --- .../bgp.service.j2 | 12 ++++++- .../{ => instance}/database.service.j2 | 11 ++++++ .../lldp.service.j2 | 11 ++++++ .../swss.service.j2 | 20 +++++++++++ .../syncd.service.j2 | 23 +++++++++++- .../teamd.service.j2 | 14 ++++++++ .../multi_instance/bgp@.service.j2 | 16 --------- .../multi_instance/database@.service.j2 | 15 -------- .../multi_instance/lldp@.service.j2 | 16 --------- .../multi_instance/swss@.service.j2 | 32 ----------------- .../multi_instance/syncd@.service.j2 | 36 ------------------- .../multi_instance/teamd@.service.j2 | 17 --------- slave.mk | 20 ++++++----- 13 files changed, 100 insertions(+), 143 deletions(-) rename files/build_templates/{single_instance => instance}/bgp.service.j2 (50%) rename files/build_templates/{ => instance}/database.service.j2 (52%) rename files/build_templates/{single_instance => instance}/lldp.service.j2 (54%) rename files/build_templates/{single_instance => instance}/swss.service.j2 (56%) rename files/build_templates/{single_instance => instance}/syncd.service.j2 (61%) rename files/build_templates/{single_instance => instance}/teamd.service.j2 (52%) delete mode 100644 files/build_templates/multi_instance/bgp@.service.j2 delete mode 100644 files/build_templates/multi_instance/database@.service.j2 delete mode 100644 files/build_templates/multi_instance/lldp@.service.j2 delete mode 100644 files/build_templates/multi_instance/swss@.service.j2 delete mode 100644 files/build_templates/multi_instance/syncd@.service.j2 delete mode 100644 files/build_templates/multi_instance/teamd@.service.j2 diff --git a/files/build_templates/single_instance/bgp.service.j2 b/files/build_templates/instance/bgp.service.j2 similarity index 50% rename from files/build_templates/single_instance/bgp.service.j2 rename to files/build_templates/instance/bgp.service.j2 index 7200a0e3ecf2..8fd4e85f8ba6 100644 --- a/files/build_templates/single_instance/bgp.service.j2 +++ b/files/build_templates/instance/bgp.service.j2 @@ -1,14 +1,24 @@ [Unit] Description=BGP container +{% if multi_instance == 'true' %} +Requires=database@%i.service +After=database@%i.service +{% else %} Requires=updategraph.service After=updategraph.service +{% endif %} Before=ntp-config.service [Service] User={{ sonicadmin_user }} +{% if multi_instance == 'true' %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i +{% else %} ExecStartPre=/usr/bin/{{docker_container_name}}.sh start ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop - +{% endif %} [Install] WantedBy=multi-user.target diff --git a/files/build_templates/database.service.j2 b/files/build_templates/instance/database.service.j2 similarity index 52% rename from files/build_templates/database.service.j2 rename to files/build_templates/instance/database.service.j2 index fd0063195e31..3dd8c557b69c 100644 --- a/files/build_templates/database.service.j2 +++ b/files/build_templates/instance/database.service.j2 @@ -1,16 +1,27 @@ [Unit] Description=Database container +{% if multi_instance == 'true' %} +Requires=docker.service database.service +After=docker.service database.service +{% else %} Requires=docker.service After=docker.service After=rc-local.service +{% endif %} StartLimitIntervalSec=1200 StartLimitBurst=3 [Service] User=root +{% if multi_instance == 'true' %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i +{% else %} ExecStartPre=/usr/bin/{{docker_container_name}}.sh start ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop +{% endif %} Restart=always RestartSec=30 diff --git a/files/build_templates/single_instance/lldp.service.j2 b/files/build_templates/instance/lldp.service.j2 similarity index 54% rename from files/build_templates/single_instance/lldp.service.j2 rename to files/build_templates/instance/lldp.service.j2 index 2599fc5c5bdc..d22a33e750f2 100644 --- a/files/build_templates/single_instance/lldp.service.j2 +++ b/files/build_templates/instance/lldp.service.j2 @@ -1,16 +1,27 @@ [Unit] Description=LLDP container +{% if multi_instance == 'true' %} +Requires=database@%i.service +After=database@%i.service swss@%i.service syncd@%i.service +{% else %} Requires=updategraph.service After=updategraph.service swss.service syncd.service +{% endif %} Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 [Service] User={{ sonicadmin_user }} +{% if multi_instance == 'true' %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i +{% else %} ExecStartPre=/usr/bin/{{docker_container_name}}.sh start ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop +{% endif %} Restart=always RestartSec=30 diff --git a/files/build_templates/single_instance/swss.service.j2 b/files/build_templates/instance/swss.service.j2 similarity index 56% rename from files/build_templates/single_instance/swss.service.j2 rename to files/build_templates/instance/swss.service.j2 index 44206b08ebce..12e1fa32ac40 100644 --- a/files/build_templates/single_instance/swss.service.j2 +++ b/files/build_templates/instance/swss.service.j2 @@ -1,12 +1,26 @@ [Unit] Description=switch state service +{% if multi_instance == 'true' %} +Requires=database@%i.service + {% if sonic_asic_platform == 'vs' %} +Requires=topology.service + {% endif %} +{% else %} Requires=database.service updategraph.service +{% endif %} {% if sonic_asic_platform == 'broadcom' %} Requires=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} Requires=nps-modules-4.9.0-11-2-amd64.service {% endif %} +{% if multi_instance == 'true' %} +After=database@%i.service + {% if sonic_asic_platform == 'vs' %} +After=topology.service + {% endif %} +{% else %} After=database.service updategraph.service +{% endif %} After=interfaces-config.service Before=ntp-config.service StartLimitIntervalSec=1200 @@ -15,9 +29,15 @@ StartLimitBurst=3 [Service] User=root Environment=sonic_asic_platform={{ sonic_asic_platform }} +{% if multi_instance == 'true' %} +ExecStartPre=/usr/local/bin/swss.sh start %i +ExecStart=/usr/local/bin/swss.sh wait %i +ExecStop=/usr/local/bin/swss.sh stop %i +{% else %} ExecStartPre=/usr/local/bin/swss.sh start ExecStart=/usr/local/bin/swss.sh wait ExecStop=/usr/local/bin/swss.sh stop +{% endif %} Restart=always RestartSec=30 diff --git a/files/build_templates/single_instance/syncd.service.j2 b/files/build_templates/instance/syncd.service.j2 similarity index 61% rename from files/build_templates/single_instance/syncd.service.j2 rename to files/build_templates/instance/syncd.service.j2 index 7a7d27114b07..2207ee412fea 100644 --- a/files/build_templates/single_instance/syncd.service.j2 +++ b/files/build_templates/instance/syncd.service.j2 @@ -1,27 +1,48 @@ [Unit] Description=syncd service +{% if multi_instance == 'true' %} +Requires=database@%i.service + {% if sonic_asic_platform == 'vs' %} +Requires=topology.service + {% endif %} +{% else %} Requires=database.service updategraph.service +{% endif %} {% if sonic_asic_platform == 'broadcom' %} Requires=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} Requires=nps-modules-4.9.0-11-2-amd64.service {% endif %} +{% if multi_instance == 'true' %} +After=database@%i.service +After=swss@%i.service + {% if sonic_asic_platform == 'vs' %} +After=topology.service + {% endif %} +{% else %} After=database.service updategraph.service +After=swss.service +{% endif %} After=interfaces-config.service {% if sonic_asic_platform == 'broadcom' %} After=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} After=nps-modules-4.9.0-11-2-amd64.service {% endif %} -After=swss.service Before=ntp-config.service [Service] User=root Environment=sonic_asic_platform={{ sonic_asic_platform }} +{% if multi_instance == 'true' %} +ExecStartPre=/usr/local/bin/syncd.sh start %i +ExecStart=/usr/local/bin/syncd.sh wait %i +ExecStop=/usr/local/bin/syncd.sh stop %i +{% else %} ExecStartPre=/usr/local/bin/syncd.sh start ExecStart=/usr/local/bin/syncd.sh wait ExecStop=/usr/local/bin/syncd.sh stop +{% endif %} {% if sonic_asic_platform == 'mellanox' %} TimeoutStartSec=150 {% endif %} diff --git a/files/build_templates/single_instance/teamd.service.j2 b/files/build_templates/instance/teamd.service.j2 similarity index 52% rename from files/build_templates/single_instance/teamd.service.j2 rename to files/build_templates/instance/teamd.service.j2 index be0521a4fbec..657506eda6e2 100644 --- a/files/build_templates/single_instance/teamd.service.j2 +++ b/files/build_templates/instance/teamd.service.j2 @@ -1,18 +1,32 @@ [Unit] Description=TEAMD container +{% if multi_instance == 'true' %} +Requires=swss@%i.service +After=swss@%i.service +{% else %} Requires=updategraph.service After=updategraph.service swss.service +{% endif %} Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 [Service] User={{ sonicadmin_user }} +{% if multi_instance == 'true' %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i +{% else %} ExecStartPre=/usr/bin/{{docker_container_name}}.sh start ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop +{% endif %} Restart=always RestartSec=30 [Install] +{% if multi_instance == 'true' %} +WantedBy=swss@%i.service +{% endif %} WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/bgp@.service.j2 b/files/build_templates/multi_instance/bgp@.service.j2 deleted file mode 100644 index 43042adf1ec7..000000000000 --- a/files/build_templates/multi_instance/bgp@.service.j2 +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=BGP container -#Requires=updategraph.service -#After=updategraph.service -After=database@%i.service -Requires=database@%i.service -Before=ntp-config.service - -[Service] -User=root -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i - -[Install] -WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/database@.service.j2 b/files/build_templates/multi_instance/database@.service.j2 deleted file mode 100644 index 7e38e4b20c70..000000000000 --- a/files/build_templates/multi_instance/database@.service.j2 +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=Database container -Requires=docker.service database.service -After=docker.service database.service - -[Service] -User=root -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i -Restart=on-failure -TimeoutStartSec=120 - -[Install] -WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/lldp@.service.j2 b/files/build_templates/multi_instance/lldp@.service.j2 deleted file mode 100644 index 9d128642e19e..000000000000 --- a/files/build_templates/multi_instance/lldp@.service.j2 +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=LLDP container -#Requires=updategraph.service -#After=updategraph.service -After=database@%i.service -Requires=database@%i.service -Before=ntp-config.service - -[Service] -User={{ sonicadmin_user }} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i - -[Install] -WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/swss@.service.j2 b/files/build_templates/multi_instance/swss@.service.j2 deleted file mode 100644 index 1ed9dc5da7b3..000000000000 --- a/files/build_templates/multi_instance/swss@.service.j2 +++ /dev/null @@ -1,32 +0,0 @@ -[Unit] -Description=switch state service -Requires=database@%i.service -#updategraph.service -{% if sonic_asic_platform == 'broadcom' %} -Requires=opennsl-modules.service -{% elif sonic_asic_platform == 'nephos' %} -Requires=nps-modules-4.9.0-9-2-amd64.service -{% elif sonic_asic_platform == 'vs' %} -Requires=topology.service -{% endif %} -After=database@%i.service -{% if sonic_asic_platform == 'vs' %} -After=topology.service -{% endif %} -#updategraph.service -After=interfaces-config@%i.service -Before=ntp-config.service -StartLimitIntervalSec=1200 -StartLimitBurst=3 - -[Service] -User=root -Environment=sonic_asic_platform={{ sonic_asic_platform }} -ExecStartPre=/usr/local/bin/swss.sh start %i -ExecStart=/usr/local/bin/swss.sh wait %i -ExecStop=/usr/local/bin/swss.sh stop %i -Restart=always -RestartSec=30 - -[Install] -WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/syncd@.service.j2 b/files/build_templates/multi_instance/syncd@.service.j2 deleted file mode 100644 index a9f108c2d30f..000000000000 --- a/files/build_templates/multi_instance/syncd@.service.j2 +++ /dev/null @@ -1,36 +0,0 @@ -[Unit] -Description=syncd service -Requires=database@%i.service -#updategraph.service -{% if sonic_asic_platform == 'broadcom' %} -Requires=opennsl-modules.service -{% elif sonic_asic_platform == 'nephos' %} -Requires=nps-modules-4.9.0-8-2-amd64.service -{% elif sonic_asic_platform == 'vs' %} -Requires=topology.service -{% endif %} -After=database@%i.service -#updategraph.service -After=interfaces-config.service -{% if sonic_asic_platform == 'broadcom' %} -After=opennsl-modules.service -{% elif sonic_asic_platform == 'nephos' %} -After=nps-modules-4.9.0-8-2-amd64.service -{% elif sonic_asic_platform == 'vs' %} -After=topology.service -{% endif %} -After=swss@%i.service -Before=ntp-config.service - -[Service] -User=root -Environment=sonic_asic_platform={{ sonic_asic_platform }} -ExecStartPre=/usr/local/bin/syncd.sh start %i -ExecStart=/usr/local/bin/syncd.sh wait %i -ExecStop=/usr/local/bin/syncd.sh stop %i -{% if sonic_asic_platform == 'mellanox' %} -TimeoutStartSec=150 -{% endif %} - -[Install] -WantedBy=multi-user.target diff --git a/files/build_templates/multi_instance/teamd@.service.j2 b/files/build_templates/multi_instance/teamd@.service.j2 deleted file mode 100644 index 63fdbd21c46f..000000000000 --- a/files/build_templates/multi_instance/teamd@.service.j2 +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=TEAMD container -#Requires=updategraph.service -Requires=swss@%i.service -#After=updategraph.service -After=swss@%i.service -Before=ntp-config.service - -[Service] -User=root -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i - -[Install] -WantedBy=swss@%i.service -RequiredBy=multi-user.target diff --git a/slave.mk b/slave.mk index 9ff6b0c665a3..45900a342cdb 100644 --- a/slave.mk +++ b/slave.mk @@ -667,6 +667,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ export platform_common_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_COMMON_PY2))" export redis_dump_load_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(REDIS_DUMP_LOAD_PY2))" export install_debug_image="$(INSTALL_DEBUG_TOOLS)" + export multi_instance="false" $(foreach docker, $($*_DOCKERS),\ export docker_image="$(docker)" @@ -684,16 +685,17 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ ) fi - if [ -f files/build_templates/multi_instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service.j2 ]; then - j2 files/build_templates/multi_instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service - - # performs the same check as the elif above, except with make commands so eval behaves properly - $(if $(shell ls files/build_templates/multi_instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service.j2 2>/dev/null),\ + if [ -f files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then + export multi_instance="true" + j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service + $(if $(shell ls files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 2>/dev/null),\ $(eval $(docker:-dbg.gz=.gz)_TEMPLATE = yes) - ) - fi - if [ -f files/build_templates/single_instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then - j2 files/build_templates/single_instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service + ) + export multi_instance="false" + j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service + $(if $(shell ls files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 2>/dev/null),\ + $(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes) + ) fi j2 files/build_templates/docker_image_ctl.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).sh chmod +x $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).sh From f4d5d492d7ac95973a96bdd74cef6398e89f8e64 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Mon, 9 Mar 2020 18:50:50 -0700 Subject: [PATCH 43/57] [slave.mk]: Fix indendation --- slave.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slave.mk b/slave.mk index 45900a342cdb..6717b9e9f559 100644 --- a/slave.mk +++ b/slave.mk @@ -710,7 +710,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ $(foreach docker, $($*_DOCKERS),\ $(if $($(docker:-dbg.gz=.gz)_TEMPLATE),\ $(if $($(docker:-dbg.gz=.gz)_GLOBAL),\ - $(eval SERVICES += "$(addsuffix .service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")\ + $(eval SERVICES += "$(addsuffix .service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")\ )\ $(eval SERVICES += "$(addsuffix @.service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))"),\ $(eval SERVICES += "$(addsuffix .service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))") From c2ce0b672b197b40953939eee2ea809ac32b1e71 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Mon, 9 Mar 2020 20:01:21 -0700 Subject: [PATCH 44/57] [docker_image_ctl]: Fix as per review comment. Use ip netns pid command to check if database docker process is linked to the correct network namespace. --- files/build_templates/docker_image_ctl.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 34e2a4803de8..76b20f4151c3 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -15,7 +15,7 @@ link_namespace() { PID="$(docker inspect -f {{"'{{.State.Pid}}'"}} "{{docker_container_name}}$DEV")" if `ip netns | grep --quiet -w "$NET_NS"`; then # namespace exists - if [ $(readlink -f /var/run/netns/$NET_NS) = $(readlink -f /proc/$PID/ns/net) ]; then # namespace is correctly linked + if `ip netns pid "$PID" | grep --quiet -w $PID`; then # namespace is correctly linked return 0 else # if it's incorrectly linked remove it ip netns delete $NET_NS From 34f921358d9d6bb8f47ac7a6b512cd201efba1cd Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Mon, 9 Mar 2020 20:17:26 -0700 Subject: [PATCH 45/57] [docker_img_ctl.j2]: Minor fix after resolving merge conflicts. --- files/build_templates/docker_image_ctl.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 60b42c590e8e..477ed495e621 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -85,7 +85,7 @@ function postStartAction() if [ -r /etc/sonic/init_cfg$DEV.json ]; then sonic-netns-exec "$NET_NS" sonic-cfggen -j /etc/sonic/init_cfg$DEV.json -j /etc/sonic/config_db$DEV.json --write-to-db else - sonic-netns-exec "$NET_NS" sonic-cfggen -j /etc/sonic/config_db.json --write-to-db + sonic-netns-exec "$NET_NS" sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db fi fi From cdb2fb3135d4bea97a9c512f70e699f40c9d6b86 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 10 Mar 2020 23:43:45 -0700 Subject: [PATCH 46/57] [database.service]: Rename service template file to ensure that database service is started in both global and namespace context for multi-asic platform. --- ...e.service.j2 => database.globalservice.j2} | 0 slave.mk | 20 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) rename files/build_templates/instance/{database.service.j2 => database.globalservice.j2} (100%) diff --git a/files/build_templates/instance/database.service.j2 b/files/build_templates/instance/database.globalservice.j2 similarity index 100% rename from files/build_templates/instance/database.service.j2 rename to files/build_templates/instance/database.globalservice.j2 diff --git a/slave.mk b/slave.mk index 6717b9e9f559..83259dcc1db2 100644 --- a/slave.mk +++ b/slave.mk @@ -684,7 +684,14 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ $(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes) ) fi - + # Any service template, inside instance directory, will be used to generate .service and @.service file. + # @.service will be used to create multiple instances of the same service. + # These services will be marked with TEMPLATE flag to denote that these services will be started + # in namespace context in case of multi-asic platforms. + # If a service template is marked as globalservice.j2, that template will be used to generate .service + # and @.service file. This service will be marked as GLOBAL and TEMPLATE to denote that + # this service will be started in host context and namespace context in case of multi-asic platforms. + # For single asic platforms, only .service files will be used. if [ -f files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then export multi_instance="true" j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service @@ -693,7 +700,16 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ ) export multi_instance="false" j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service - $(if $(shell ls files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 2>/dev/null),\ + fi + if [ -f files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 ]; then + export multi_instance="true" + j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service + $(if $(shell ls files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 2>/dev/null),\ + $(eval $(docker:-dbg.gz=.gz)_TEMPLATE = yes) + ) + export multi_instance="false" + j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service + $(if $(shell ls files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 2>/dev/null),\ $(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes) ) fi From 0594d1a0513c463d887d4ec7fb224da7a6c650eb Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 10 Mar 2020 23:44:11 -0700 Subject: [PATCH 47/57] [docker_img_ctl.j2]: Fix to use same init_cfg for all instances. --- files/build_templates/docker_image_ctl.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 477ed495e621..c7d3e6e7a25c 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -82,8 +82,8 @@ function postStartAction() else # If there is a config_db.json dump file, load it. if [ -r /etc/sonic/config_db$DEV.json ]; then - if [ -r /etc/sonic/init_cfg$DEV.json ]; then - sonic-netns-exec "$NET_NS" sonic-cfggen -j /etc/sonic/init_cfg$DEV.json -j /etc/sonic/config_db$DEV.json --write-to-db + if [ -r /etc/sonic/init_cfg.json ]; then + sonic-netns-exec "$NET_NS" sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db$DEV.json --write-to-db else sonic-netns-exec "$NET_NS" sonic-cfggen -j /etc/sonic/config_db$DEV.json --write-to-db fi From 45c0e73c7fa965789809c1c52289da9c3b41be2d Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Wed, 11 Mar 2020 18:42:06 -0700 Subject: [PATCH 48/57] [build_templates]: Change directory as per review comment. Fix dependencies in multiple instance services. Add database.service as symlink in the global services directory. Fix slave.mk file to generate the .services from j2 templates. --- files/build_templates/database.service.j2 | 1 + .../bgp.service.j2 | 2 ++ .../database.globalservice_.j2} | 0 .../per_namespace/database.service.j2 | 29 +++++++++++++++++++ .../lldp.service.j2 | 2 ++ .../swss.service.j2 | 2 ++ .../syncd.service.j2 | 2 ++ .../teamd.service.j2 | 5 ++-- .../interfaces/interfaces-config.service | 2 +- slave.mk | 27 +++-------------- 10 files changed, 45 insertions(+), 27 deletions(-) create mode 120000 files/build_templates/database.service.j2 rename files/build_templates/{instance => per_namespace}/bgp.service.j2 (93%) rename files/build_templates/{instance/database.globalservice.j2 => per_namespace/database.globalservice_.j2} (100%) create mode 100644 files/build_templates/per_namespace/database.service.j2 rename files/build_templates/{instance => per_namespace}/lldp.service.j2 (93%) rename files/build_templates/{instance => per_namespace}/swss.service.j2 (95%) rename files/build_templates/{instance => per_namespace}/syncd.service.j2 (96%) rename files/build_templates/{instance => per_namespace}/teamd.service.j2 (91%) diff --git a/files/build_templates/database.service.j2 b/files/build_templates/database.service.j2 new file mode 120000 index 000000000000..63340abef881 --- /dev/null +++ b/files/build_templates/database.service.j2 @@ -0,0 +1 @@ +per_namespace/database.service.j2 \ No newline at end of file diff --git a/files/build_templates/instance/bgp.service.j2 b/files/build_templates/per_namespace/bgp.service.j2 similarity index 93% rename from files/build_templates/instance/bgp.service.j2 rename to files/build_templates/per_namespace/bgp.service.j2 index d45f1f1238c5..a02210f71519 100644 --- a/files/build_templates/instance/bgp.service.j2 +++ b/files/build_templates/per_namespace/bgp.service.j2 @@ -2,7 +2,9 @@ Description=BGP container {% if multi_instance == 'true' %} Requires=database@%i.service +Requires=updategraph.service After=database@%i.service +After=updategraph.service {% else %} Requires=updategraph.service After=updategraph.service diff --git a/files/build_templates/instance/database.globalservice.j2 b/files/build_templates/per_namespace/database.globalservice_.j2 similarity index 100% rename from files/build_templates/instance/database.globalservice.j2 rename to files/build_templates/per_namespace/database.globalservice_.j2 diff --git a/files/build_templates/per_namespace/database.service.j2 b/files/build_templates/per_namespace/database.service.j2 new file mode 100644 index 000000000000..3dd8c557b69c --- /dev/null +++ b/files/build_templates/per_namespace/database.service.j2 @@ -0,0 +1,29 @@ +[Unit] +Description=Database container +{% if multi_instance == 'true' %} +Requires=docker.service database.service +After=docker.service database.service +{% else %} +Requires=docker.service +After=docker.service +After=rc-local.service +{% endif %} +StartLimitIntervalSec=1200 +StartLimitBurst=3 + +[Service] +User=root +{% if multi_instance == 'true' %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i +ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i +ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i +{% else %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start +ExecStart=/usr/bin/{{docker_container_name}}.sh wait +ExecStop=/usr/bin/{{docker_container_name}}.sh stop +{% endif %} +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target diff --git a/files/build_templates/instance/lldp.service.j2 b/files/build_templates/per_namespace/lldp.service.j2 similarity index 93% rename from files/build_templates/instance/lldp.service.j2 rename to files/build_templates/per_namespace/lldp.service.j2 index d22a33e750f2..03106fe9b07f 100644 --- a/files/build_templates/instance/lldp.service.j2 +++ b/files/build_templates/per_namespace/lldp.service.j2 @@ -2,7 +2,9 @@ Description=LLDP container {% if multi_instance == 'true' %} Requires=database@%i.service +Requires=updategraph.service After=database@%i.service swss@%i.service syncd@%i.service +After=updategraph.service {% else %} Requires=updategraph.service After=updategraph.service swss.service syncd.service diff --git a/files/build_templates/instance/swss.service.j2 b/files/build_templates/per_namespace/swss.service.j2 similarity index 95% rename from files/build_templates/instance/swss.service.j2 rename to files/build_templates/per_namespace/swss.service.j2 index 12e1fa32ac40..c68a678edf5b 100644 --- a/files/build_templates/instance/swss.service.j2 +++ b/files/build_templates/per_namespace/swss.service.j2 @@ -2,6 +2,7 @@ Description=switch state service {% if multi_instance == 'true' %} Requires=database@%i.service +Requires=updategraph.service {% if sonic_asic_platform == 'vs' %} Requires=topology.service {% endif %} @@ -15,6 +16,7 @@ Requires=nps-modules-4.9.0-11-2-amd64.service {% endif %} {% if multi_instance == 'true' %} After=database@%i.service +After=updategraph.service {% if sonic_asic_platform == 'vs' %} After=topology.service {% endif %} diff --git a/files/build_templates/instance/syncd.service.j2 b/files/build_templates/per_namespace/syncd.service.j2 similarity index 96% rename from files/build_templates/instance/syncd.service.j2 rename to files/build_templates/per_namespace/syncd.service.j2 index 2207ee412fea..b5a2bb16df30 100644 --- a/files/build_templates/instance/syncd.service.j2 +++ b/files/build_templates/per_namespace/syncd.service.j2 @@ -2,6 +2,7 @@ Description=syncd service {% if multi_instance == 'true' %} Requires=database@%i.service +Requires=updategraph.service {% if sonic_asic_platform == 'vs' %} Requires=topology.service {% endif %} @@ -16,6 +17,7 @@ Requires=nps-modules-4.9.0-11-2-amd64.service {% if multi_instance == 'true' %} After=database@%i.service After=swss@%i.service +After=updategraph.service {% if sonic_asic_platform == 'vs' %} After=topology.service {% endif %} diff --git a/files/build_templates/instance/teamd.service.j2 b/files/build_templates/per_namespace/teamd.service.j2 similarity index 91% rename from files/build_templates/instance/teamd.service.j2 rename to files/build_templates/per_namespace/teamd.service.j2 index 657506eda6e2..6762b5bff167 100644 --- a/files/build_templates/instance/teamd.service.j2 +++ b/files/build_templates/per_namespace/teamd.service.j2 @@ -2,7 +2,9 @@ Description=TEAMD container {% if multi_instance == 'true' %} Requires=swss@%i.service +Requires=updategraph.service After=swss@%i.service +After=updategraph.service {% else %} Requires=updategraph.service After=updategraph.service swss.service @@ -26,7 +28,4 @@ Restart=always RestartSec=30 [Install] -{% if multi_instance == 'true' %} -WantedBy=swss@%i.service -{% endif %} WantedBy=multi-user.target diff --git a/files/image_config/interfaces/interfaces-config.service b/files/image_config/interfaces/interfaces-config.service index fa2077c4e496..71178affdee8 100644 --- a/files/image_config/interfaces/interfaces-config.service +++ b/files/image_config/interfaces/interfaces-config.service @@ -8,4 +8,4 @@ Type=oneshot ExecStart=/usr/bin/interfaces-config.sh [Install] -RequiredBy=multi-user.target +WantedBy=multi-user.target diff --git a/slave.mk b/slave.mk index 83259dcc1db2..19173ff85235 100644 --- a/slave.mk +++ b/slave.mk @@ -685,33 +685,14 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ ) fi # Any service template, inside instance directory, will be used to generate .service and @.service file. - # @.service will be used to create multiple instances of the same service. - # These services will be marked with TEMPLATE flag to denote that these services will be started - # in namespace context in case of multi-asic platforms. - # If a service template is marked as globalservice.j2, that template will be used to generate .service - # and @.service file. This service will be marked as GLOBAL and TEMPLATE to denote that - # this service will be started in host context and namespace context in case of multi-asic platforms. - # For single asic platforms, only .service files will be used. - if [ -f files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then + if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then export multi_instance="true" - j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service - $(if $(shell ls files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 2>/dev/null),\ + j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service + $(if $(shell ls files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 2>/dev/null),\ $(eval $(docker:-dbg.gz=.gz)_TEMPLATE = yes) ) export multi_instance="false" - j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service - fi - if [ -f files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 ]; then - export multi_instance="true" - j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.service - $(if $(shell ls files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 2>/dev/null),\ - $(eval $(docker:-dbg.gz=.gz)_TEMPLATE = yes) - ) - export multi_instance="false" - j2 files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service - $(if $(shell ls files/build_templates/instance/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).globalservice.j2 2>/dev/null),\ - $(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes) - ) + j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service fi j2 files/build_templates/docker_image_ctl.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).sh chmod +x $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).sh From b4d2071179f71a63e1a56ec1653a30348e4a8877 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Wed, 11 Mar 2020 18:44:40 -0700 Subject: [PATCH 49/57] [docker_image_ctl]: Modify directory structure of frr directory --- files/build_templates/docker_image_ctl.j2 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index c7d3e6e7a25c..2cafc576700c 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -15,7 +15,7 @@ link_namespace() { PID="$(docker inspect -f {{"'{{.State.Pid}}'"}} "{{docker_container_name}}$DEV")" if `ip netns | grep --quiet -w "$NET_NS"`; then # namespace exists - if `ip netns pid "$PID" | grep --quiet -w $PID`; then # namespace is correctly linked + if `ip netns pids "$NET_NS" | grep --quiet -w $PID`; then # namespace is correctly linked return 0 else # if it's incorrectly linked remove it ip netns delete $NET_NS @@ -187,8 +187,9 @@ start() { fi {%- if docker_container_name == "bgp" %} if [ "$DEV" ]; then - if [ ! -d "/etc/sonic/frr$DEV" ]; then - cp -r /etc/sonic/frr /etc/sonic/frr$DEV + if [ ! -d "/etc/sonic/frr/$DEV" ]; then + mkdir /etc/sonic/frr/$DEV + cp -r /etc/sonic/frr/*.conf /etc/sonic/frr/$DEV fi fi {%- endif %} @@ -222,7 +223,7 @@ start() { {%- endif %} {%- endif %} {%- if docker_container_name == "bgp" %} - -v /etc/sonic/frr$DEV:/etc/frr:rw \ + -v /etc/sonic/frr/$DEV:/etc/frr:rw \ {%- endif %} -v /var/run/redis$DEV:/var/run/redis:rw \ -v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \ From 030be0b4c6fb4ce4858ef975e024545f87ca43f9 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Thu, 12 Mar 2020 11:23:10 -0700 Subject: [PATCH 50/57] [docker_image_ctl.j2]: Change command used to check if a namespace exists. --- files/build_templates/docker_image_ctl.j2 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 2cafc576700c..4eba207db060 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -14,8 +14,9 @@ link_namespace() { mkdir -p /var/run/netns PID="$(docker inspect -f {{"'{{.State.Pid}}'"}} "{{docker_container_name}}$DEV")" - if `ip netns | grep --quiet -w "$NET_NS"`; then # namespace exists - if `ip netns pids "$NET_NS" | grep --quiet -w $PID`; then # namespace is correctly linked + PIDS=`ip netns pids "$NET_NS" 2>/dev/null` + if [ "$?" -eq "0" ]; then + if `echo $PIDS | grep --quiet -w $PID`; then # namespace is correctly linked return 0 else # if it's incorrectly linked remove it ip netns delete $NET_NS From 42c6db3aedc44b6812f6652fdb3e96c0a829c6dd Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Thu, 12 Mar 2020 16:46:29 -0700 Subject: [PATCH 51/57] [docker_image_ctl]: Minor fix to add comment --- files/build_templates/docker_image_ctl.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 4eba207db060..297c9dd1c2bd 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -15,8 +15,8 @@ link_namespace() { PID="$(docker inspect -f {{"'{{.State.Pid}}'"}} "{{docker_container_name}}$DEV")" PIDS=`ip netns pids "$NET_NS" 2>/dev/null` - if [ "$?" -eq "0" ]; then - if `echo $PIDS | grep --quiet -w $PID`; then # namespace is correctly linked + if [ "$?" -eq "0" ]; then # namespace exists + if `echo $PIDS | grep --quiet -w $PID`; then # namespace is correctly linked return 0 else # if it's incorrectly linked remove it ip netns delete $NET_NS From 32c56c37c467e7cfe5ded5f970edbc46f94fb34e Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Thu, 12 Mar 2020 16:51:36 -0700 Subject: [PATCH 52/57] [database.globalservice]: Remove incorrect file. This file is no longer used. --- .../per_namespace/database.globalservice_.j2 | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 files/build_templates/per_namespace/database.globalservice_.j2 diff --git a/files/build_templates/per_namespace/database.globalservice_.j2 b/files/build_templates/per_namespace/database.globalservice_.j2 deleted file mode 100644 index 3dd8c557b69c..000000000000 --- a/files/build_templates/per_namespace/database.globalservice_.j2 +++ /dev/null @@ -1,29 +0,0 @@ -[Unit] -Description=Database container -{% if multi_instance == 'true' %} -Requires=docker.service database.service -After=docker.service database.service -{% else %} -Requires=docker.service -After=docker.service -After=rc-local.service -{% endif %} -StartLimitIntervalSec=1200 -StartLimitBurst=3 - -[Service] -User=root -{% if multi_instance == 'true' %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i -{% else %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start -ExecStart=/usr/bin/{{docker_container_name}}.sh wait -ExecStop=/usr/bin/{{docker_container_name}}.sh stop -{% endif %} -Restart=always -RestartSec=30 - -[Install] -WantedBy=multi-user.target From 6c8e56fdc51cd9a735146173475078aed9b66432 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 13 Mar 2020 15:23:35 -0700 Subject: [PATCH 53/57] [build_templates]: Modified service template file to make them concise. --- .../per_namespace/bgp.service.j2 | 18 +++-------- .../per_namespace/database.service.j2 | 19 ++++-------- .../per_namespace/lldp.service.j2 | 19 ++++-------- .../per_namespace/swss.service.j2 | 31 ++++++------------- .../per_namespace/syncd.service.j2 | 28 +++++------------ .../per_namespace/teamd.service.j2 | 19 ++++-------- .../build_templates/sonic_debian_extension.j2 | 2 ++ 7 files changed, 43 insertions(+), 93 deletions(-) diff --git a/files/build_templates/per_namespace/bgp.service.j2 b/files/build_templates/per_namespace/bgp.service.j2 index a02210f71519..a8835c9f7007 100644 --- a/files/build_templates/per_namespace/bgp.service.j2 +++ b/files/build_templates/per_namespace/bgp.service.j2 @@ -2,28 +2,20 @@ Description=BGP container {% if multi_instance == 'true' %} Requires=database@%i.service -Requires=updategraph.service After=database@%i.service -After=updategraph.service -{% else %} +{% endif %} Requires=updategraph.service After=updategraph.service -{% endif %} Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 [Service] User={{ sonicadmin_user }} -{% if multi_instance == 'true' %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i -{% else %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start -ExecStart=/usr/bin/{{docker_container_name}}.sh wait -ExecStop=/usr/bin/{{docker_container_name}}.sh stop -{% endif %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %} +ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %} +ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %} + Restart=always RestartSec=30 diff --git a/files/build_templates/per_namespace/database.service.j2 b/files/build_templates/per_namespace/database.service.j2 index 3dd8c557b69c..396fdc6678c2 100644 --- a/files/build_templates/per_namespace/database.service.j2 +++ b/files/build_templates/per_namespace/database.service.j2 @@ -1,27 +1,20 @@ [Unit] Description=Database container {% if multi_instance == 'true' %} -Requires=docker.service database.service -After=docker.service database.service -{% else %} +Requires=database.service +After=database.service +{% endif %} Requires=docker.service After=docker.service After=rc-local.service -{% endif %} StartLimitIntervalSec=1200 StartLimitBurst=3 [Service] User=root -{% if multi_instance == 'true' %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i -{% else %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start -ExecStart=/usr/bin/{{docker_container_name}}.sh wait -ExecStop=/usr/bin/{{docker_container_name}}.sh stop -{% endif %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %} +ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %} +ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %} Restart=always RestartSec=30 diff --git a/files/build_templates/per_namespace/lldp.service.j2 b/files/build_templates/per_namespace/lldp.service.j2 index 03106fe9b07f..231eb91b3522 100644 --- a/files/build_templates/per_namespace/lldp.service.j2 +++ b/files/build_templates/per_namespace/lldp.service.j2 @@ -2,28 +2,21 @@ Description=LLDP container {% if multi_instance == 'true' %} Requires=database@%i.service -Requires=updategraph.service After=database@%i.service swss@%i.service syncd@%i.service -After=updategraph.service {% else %} -Requires=updategraph.service -After=updategraph.service swss.service syncd.service +After=swss.service syncd.service {% endif %} +Requires=updategraph.service +After=updategraph.service Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 [Service] User={{ sonicadmin_user }} -{% if multi_instance == 'true' %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i -{% else %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start -ExecStart=/usr/bin/{{docker_container_name}}.sh wait -ExecStop=/usr/bin/{{docker_container_name}}.sh stop -{% endif %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %} +ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %} +ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %} Restart=always RestartSec=30 diff --git a/files/build_templates/per_namespace/swss.service.j2 b/files/build_templates/per_namespace/swss.service.j2 index c68a678edf5b..f5504dbbfcdb 100644 --- a/files/build_templates/per_namespace/swss.service.j2 +++ b/files/build_templates/per_namespace/swss.service.j2 @@ -2,27 +2,22 @@ Description=switch state service {% if multi_instance == 'true' %} Requires=database@%i.service -Requires=updategraph.service - {% if sonic_asic_platform == 'vs' %} +After=database@%i.service + {% if sonic_asic_platform == 'vs' %} Requires=topology.service - {% endif %} +After=topology.service + {% endif %} {% else %} -Requires=database.service updategraph.service +Requires=database.service +After=database.service {% endif %} {% if sonic_asic_platform == 'broadcom' %} Requires=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} Requires=nps-modules-4.9.0-11-2-amd64.service {% endif %} -{% if multi_instance == 'true' %} -After=database@%i.service +Requires=updategraph.service After=updategraph.service - {% if sonic_asic_platform == 'vs' %} -After=topology.service - {% endif %} -{% else %} -After=database.service updategraph.service -{% endif %} After=interfaces-config.service Before=ntp-config.service StartLimitIntervalSec=1200 @@ -31,15 +26,9 @@ StartLimitBurst=3 [Service] User=root Environment=sonic_asic_platform={{ sonic_asic_platform }} -{% if multi_instance == 'true' %} -ExecStartPre=/usr/local/bin/swss.sh start %i -ExecStart=/usr/local/bin/swss.sh wait %i -ExecStop=/usr/local/bin/swss.sh stop %i -{% else %} -ExecStartPre=/usr/local/bin/swss.sh start -ExecStart=/usr/local/bin/swss.sh wait -ExecStop=/usr/local/bin/swss.sh stop -{% endif %} +ExecStartPre=/usr/local/bin/swss.sh start{% if multi_instance == 'true' %} %i{% endif %} +ExecStart=/usr/local/bin/swss.sh wait{% if multi_instance == 'true' %} %i{% endif %} +ExecStop=/usr/local/bin/swss.sh stop{% if multi_instance == 'true' %} %i{% endif %} Restart=always RestartSec=30 diff --git a/files/build_templates/per_namespace/syncd.service.j2 b/files/build_templates/per_namespace/syncd.service.j2 index b5a2bb16df30..01f25a8a9d19 100644 --- a/files/build_templates/per_namespace/syncd.service.j2 +++ b/files/build_templates/per_namespace/syncd.service.j2 @@ -3,28 +3,22 @@ Description=syncd service {% if multi_instance == 'true' %} Requires=database@%i.service Requires=updategraph.service +After=database@%i.service swss@%i.service {% if sonic_asic_platform == 'vs' %} Requires=topology.service +After=topology.service {% endif %} {% else %} -Requires=database.service updategraph.service +Requires=database.service +After=database.service swss.service {% endif %} {% if sonic_asic_platform == 'broadcom' %} Requires=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} Requires=nps-modules-4.9.0-11-2-amd64.service {% endif %} -{% if multi_instance == 'true' %} -After=database@%i.service -After=swss@%i.service +Requires=updategraph.service After=updategraph.service - {% if sonic_asic_platform == 'vs' %} -After=topology.service - {% endif %} -{% else %} -After=database.service updategraph.service -After=swss.service -{% endif %} After=interfaces-config.service {% if sonic_asic_platform == 'broadcom' %} After=opennsl-modules.service @@ -36,15 +30,9 @@ Before=ntp-config.service [Service] User=root Environment=sonic_asic_platform={{ sonic_asic_platform }} -{% if multi_instance == 'true' %} -ExecStartPre=/usr/local/bin/syncd.sh start %i -ExecStart=/usr/local/bin/syncd.sh wait %i -ExecStop=/usr/local/bin/syncd.sh stop %i -{% else %} -ExecStartPre=/usr/local/bin/syncd.sh start -ExecStart=/usr/local/bin/syncd.sh wait -ExecStop=/usr/local/bin/syncd.sh stop -{% endif %} +ExecStartPre=/usr/local/bin/syncd.sh start{% if multi_instance == 'true' %} %i{% endif %} +ExecStart=/usr/local/bin/syncd.sh wait{% if multi_instance == 'true' %} %i{% endif %} +ExecStop=/usr/local/bin/syncd.sh stop{% if multi_instance == 'true' %} %i{% endif %} {% if sonic_asic_platform == 'mellanox' %} TimeoutStartSec=150 {% endif %} diff --git a/files/build_templates/per_namespace/teamd.service.j2 b/files/build_templates/per_namespace/teamd.service.j2 index 6762b5bff167..62cc5ebda817 100644 --- a/files/build_templates/per_namespace/teamd.service.j2 +++ b/files/build_templates/per_namespace/teamd.service.j2 @@ -2,28 +2,21 @@ Description=TEAMD container {% if multi_instance == 'true' %} Requires=swss@%i.service -Requires=updategraph.service After=swss@%i.service -After=updategraph.service {% else %} -Requires=updategraph.service -After=updategraph.service swss.service +After=swss.service {% endif %} +Requires=updategraph.service +After=updategraph.service Before=ntp-config.service StartLimitIntervalSec=1200 StartLimitBurst=3 [Service] User={{ sonicadmin_user }} -{% if multi_instance == 'true' %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start %i -ExecStart=/usr/bin/{{docker_container_name}}.sh wait %i -ExecStop=/usr/bin/{{docker_container_name}}.sh stop %i -{% else %} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start -ExecStart=/usr/bin/{{docker_container_name}}.sh wait -ExecStop=/usr/bin/{{docker_container_name}}.sh stop -{% endif %} +ExecStartPre=/usr/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %} +ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %} +ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %} Restart=always RestartSec=30 diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 1c88d18f0cc6..3321ebaffe03 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -430,6 +430,8 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys # Copy swss and syncd service script sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh + +# Copy sonic-netns-exec script sudo LANG=C cp $SCRIPTS_DIR/sonic-netns-exec $FILESYSTEM_ROOT/usr/bin/sonic-netns-exec # Copy systemd timer configuration From 27ea7544cab865063cc210fdd6747baf31f7a025 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 13 Mar 2020 18:11:55 -0700 Subject: [PATCH 54/57] [build_templates]: Modified templates as per review comments. --- files/build_templates/per_namespace/bgp.service.j2 | 6 ++---- files/build_templates/per_namespace/swss.service.j2 | 11 +++-------- .../build_templates/per_namespace/syncd.service.j2 | 13 ++++--------- .../build_templates/per_namespace/teamd.service.j2 | 7 +------ 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/files/build_templates/per_namespace/bgp.service.j2 b/files/build_templates/per_namespace/bgp.service.j2 index a8835c9f7007..79e9afc4ebc1 100644 --- a/files/build_templates/per_namespace/bgp.service.j2 +++ b/files/build_templates/per_namespace/bgp.service.j2 @@ -1,9 +1,7 @@ [Unit] Description=BGP container -{% if multi_instance == 'true' %} -Requires=database@%i.service -After=database@%i.service -{% endif %} +Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service +After=database{% if multi_instance == 'true' %}@%i{% endif %}.service Requires=updategraph.service After=updategraph.service Before=ntp-config.service diff --git a/files/build_templates/per_namespace/swss.service.j2 b/files/build_templates/per_namespace/swss.service.j2 index f5504dbbfcdb..53d6b4497df7 100644 --- a/files/build_templates/per_namespace/swss.service.j2 +++ b/files/build_templates/per_namespace/swss.service.j2 @@ -1,15 +1,10 @@ [Unit] Description=switch state service -{% if multi_instance == 'true' %} -Requires=database@%i.service -After=database@%i.service - {% if sonic_asic_platform == 'vs' %} +Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service +After=database{% if multi_instance == 'true' %}@%i{% endif %}.service +{% if multi_instance == 'true' and sonic_asic_platform == 'vs' %} Requires=topology.service After=topology.service - {% endif %} -{% else %} -Requires=database.service -After=database.service {% endif %} {% if sonic_asic_platform == 'broadcom' %} Requires=opennsl-modules.service diff --git a/files/build_templates/per_namespace/syncd.service.j2 b/files/build_templates/per_namespace/syncd.service.j2 index 01f25a8a9d19..816de57ad8c6 100644 --- a/files/build_templates/per_namespace/syncd.service.j2 +++ b/files/build_templates/per_namespace/syncd.service.j2 @@ -1,16 +1,11 @@ [Unit] Description=syncd service -{% if multi_instance == 'true' %} -Requires=database@%i.service -Requires=updategraph.service -After=database@%i.service swss@%i.service - {% if sonic_asic_platform == 'vs' %} +Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service +After=database{% if multi_instance == 'true' %}@%i{% endif %}.service +After=swss{% if multi_instance == 'true' %}@%i{% endif %}.service +{% if multi_instance == 'true' and sonic_asic_platform == 'vs' %} Requires=topology.service After=topology.service - {% endif %} -{% else %} -Requires=database.service -After=database.service swss.service {% endif %} {% if sonic_asic_platform == 'broadcom' %} Requires=opennsl-modules.service diff --git a/files/build_templates/per_namespace/teamd.service.j2 b/files/build_templates/per_namespace/teamd.service.j2 index 62cc5ebda817..3d45a277ba0e 100644 --- a/files/build_templates/per_namespace/teamd.service.j2 +++ b/files/build_templates/per_namespace/teamd.service.j2 @@ -1,12 +1,7 @@ [Unit] Description=TEAMD container -{% if multi_instance == 'true' %} -Requires=swss@%i.service -After=swss@%i.service -{% else %} -After=swss.service -{% endif %} Requires=updategraph.service +After=swss{% if multi_instance == 'true' %}@%i{% endif %}.service After=updategraph.service Before=ntp-config.service StartLimitIntervalSec=1200 From b4b557e4403d91ba34c730d4b19d4c0486e3345b Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Fri, 13 Mar 2020 23:00:15 -0700 Subject: [PATCH 55/57] Minor indendation fix. --- .../msft_multi_asic_vs/topology.sh | 4 ++-- files/build_templates/per_namespace/bgp.service.j2 | 2 +- files/build_templates/per_namespace/lldp.service.j2 | 10 ++++------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh index 35f9976b8ccc..cf70f3063189 100755 --- a/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh +++ b/device/virtual/x86_64-kvm_x86_64-r0/msft_multi_asic_vs/topology.sh @@ -16,8 +16,8 @@ start () { for NUM in `seq 1 16`; do ORIG="eth$((16 * $ASIC + $NUM))" TEMP="ethTemp999" - NEW="eth$(($NUM))" - echo "$ASIC : $NEW old $ORIG" + NEW="eth$(($NUM))" + echo "$ASIC : $NEW old $ORIG" ip link set dev $ORIG down ip link set dev $ORIG name $TEMP # rename to prevent conflicts before renaming in new namespace ip link set dev $TEMP netns asic$ASIC diff --git a/files/build_templates/per_namespace/bgp.service.j2 b/files/build_templates/per_namespace/bgp.service.j2 index 79e9afc4ebc1..16fe33b7cc22 100644 --- a/files/build_templates/per_namespace/bgp.service.j2 +++ b/files/build_templates/per_namespace/bgp.service.j2 @@ -1,8 +1,8 @@ [Unit] Description=BGP container Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service -After=database{% if multi_instance == 'true' %}@%i{% endif %}.service Requires=updategraph.service +After=database{% if multi_instance == 'true' %}@%i{% endif %}.service After=updategraph.service Before=ntp-config.service StartLimitIntervalSec=1200 diff --git a/files/build_templates/per_namespace/lldp.service.j2 b/files/build_templates/per_namespace/lldp.service.j2 index 231eb91b3522..7f117fcf8222 100644 --- a/files/build_templates/per_namespace/lldp.service.j2 +++ b/files/build_templates/per_namespace/lldp.service.j2 @@ -1,12 +1,10 @@ [Unit] Description=LLDP container -{% if multi_instance == 'true' %} -Requires=database@%i.service -After=database@%i.service swss@%i.service syncd@%i.service -{% else %} -After=swss.service syncd.service -{% endif %} +Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service Requires=updategraph.service +After=database{% if multi_instance == 'true' %}@%i{% endif %}.service +After=swss{% if multi_instance == 'true' %}@%i{% endif %}.service +After=syncd{% if multi_instance == 'true' %}@%i{% endif %}.service After=updategraph.service Before=ntp-config.service StartLimitIntervalSec=1200 From 4d1204d82e45e4a1a29b0256af1bcd211fe9f244 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 17 Mar 2020 18:27:30 -0700 Subject: [PATCH 56/57] [build_templates]: Minor update in per namespace service templates to make it readable. --- files/build_templates/per_namespace/bgp.service.j2 | 2 +- files/build_templates/per_namespace/lldp.service.j2 | 2 +- files/build_templates/per_namespace/syncd.service.j2 | 6 +++--- files/build_templates/per_namespace/teamd.service.j2 | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/files/build_templates/per_namespace/bgp.service.j2 b/files/build_templates/per_namespace/bgp.service.j2 index 16fe33b7cc22..79e9afc4ebc1 100644 --- a/files/build_templates/per_namespace/bgp.service.j2 +++ b/files/build_templates/per_namespace/bgp.service.j2 @@ -1,8 +1,8 @@ [Unit] Description=BGP container Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service -Requires=updategraph.service After=database{% if multi_instance == 'true' %}@%i{% endif %}.service +Requires=updategraph.service After=updategraph.service Before=ntp-config.service StartLimitIntervalSec=1200 diff --git a/files/build_templates/per_namespace/lldp.service.j2 b/files/build_templates/per_namespace/lldp.service.j2 index 7f117fcf8222..b48675b03202 100644 --- a/files/build_templates/per_namespace/lldp.service.j2 +++ b/files/build_templates/per_namespace/lldp.service.j2 @@ -1,10 +1,10 @@ [Unit] Description=LLDP container Requires=database{% if multi_instance == 'true' %}@%i{% endif %}.service -Requires=updategraph.service After=database{% if multi_instance == 'true' %}@%i{% endif %}.service After=swss{% if multi_instance == 'true' %}@%i{% endif %}.service After=syncd{% if multi_instance == 'true' %}@%i{% endif %}.service +Requires=updategraph.service After=updategraph.service Before=ntp-config.service StartLimitIntervalSec=1200 diff --git a/files/build_templates/per_namespace/syncd.service.j2 b/files/build_templates/per_namespace/syncd.service.j2 index 816de57ad8c6..d9ec03a8a2d4 100644 --- a/files/build_templates/per_namespace/syncd.service.j2 +++ b/files/build_templates/per_namespace/syncd.service.j2 @@ -12,14 +12,14 @@ Requires=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} Requires=nps-modules-4.9.0-11-2-amd64.service {% endif %} -Requires=updategraph.service -After=updategraph.service -After=interfaces-config.service {% if sonic_asic_platform == 'broadcom' %} After=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} After=nps-modules-4.9.0-11-2-amd64.service {% endif %} +Requires=updategraph.service +After=updategraph.service +After=interfaces-config.service Before=ntp-config.service [Service] diff --git a/files/build_templates/per_namespace/teamd.service.j2 b/files/build_templates/per_namespace/teamd.service.j2 index 3d45a277ba0e..092f9d2ebde2 100644 --- a/files/build_templates/per_namespace/teamd.service.j2 +++ b/files/build_templates/per_namespace/teamd.service.j2 @@ -1,7 +1,7 @@ [Unit] Description=TEAMD container -Requires=updategraph.service After=swss{% if multi_instance == 'true' %}@%i{% endif %}.service +Requires=updategraph.service After=updategraph.service Before=ntp-config.service StartLimitIntervalSec=1200 From fa25e1abb51edd9902a2f61d6cafa029741a1817 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi Date: Tue, 17 Mar 2020 18:48:53 -0700 Subject: [PATCH 57/57] [syncd.servic]: Minor update in template file to make it concise. --- files/build_templates/per_namespace/syncd.service.j2 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/files/build_templates/per_namespace/syncd.service.j2 b/files/build_templates/per_namespace/syncd.service.j2 index d9ec03a8a2d4..b2922e0d12b6 100644 --- a/files/build_templates/per_namespace/syncd.service.j2 +++ b/files/build_templates/per_namespace/syncd.service.j2 @@ -9,12 +9,9 @@ After=topology.service {% endif %} {% if sonic_asic_platform == 'broadcom' %} Requires=opennsl-modules.service -{% elif sonic_asic_platform == 'nephos' %} -Requires=nps-modules-4.9.0-11-2-amd64.service -{% endif %} -{% if sonic_asic_platform == 'broadcom' %} After=opennsl-modules.service {% elif sonic_asic_platform == 'nephos' %} +Requires=nps-modules-4.9.0-11-2-amd64.service After=nps-modules-4.9.0-11-2-amd64.service {% endif %} Requires=updategraph.service