From af63bf57fe2ead04f2794764166a8c70eb7aae14 Mon Sep 17 00:00:00 2001 From: jumao Date: Fri, 1 Sep 2023 17:37:49 -0400 Subject: [PATCH 1/7] =?UTF-8?q?*=20[saidump]=20=E2=80=A2=09Saidump=20for?= =?UTF-8?q?=20DNX-SAI=20https://github.com/sonic-net/sonic-buildimage/issu?= =?UTF-8?q?es/13561?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Solution and modification: To use the redis-db SAVE option to save the snapshot of DB each time and recover later, instead of looping through each entry in the table and saving it. (1) Updated sonic-buildimage/build_debian.sh, to install Python library rdbtools into the host. (2) Updated sonic-buildimage/src/sonic-sairedis/saidump/saidump.cpp, add a new option -r, which updates the rdbtools's output-JSON files' format. (3) Add a new script file: files/scripts/saidump.sh, to do the below steps For each ASIC0, such as ASIC0, 1. Save the Redis data. sudo sonic-db-cli -n asic$1 SAVE > /dev/null 2. Move dump files to /var/run/redisX/ docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" 3. Run rdb command to convert the dump files into JSON files sudo python /usr/local/bin/rdb --command json /var/run/redis$1/dump.rdb | sudo tee /var/run/redis$1/dump.json > /dev/null 4. Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump result in standard output. docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json" 5. clear sudo rm -f /var/run/redis$1/dump.rdb sudo rm -f /var/run/redis$1/dump.json (4) Update sonic-buildimage/src/sonic-utilities/scripts/generate_dump, replace saidump with saidump.sh --- build_debian.sh | 16 ++++++++++++++++ files/scripts/saidump.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 files/scripts/saidump.sh diff --git a/build_debian.sh b/build_debian.sh index 11c3e85adb88..3c8519b6288c 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -729,6 +729,22 @@ SONIC_VERSION_CACHE=${SONIC_VERSION_CACHE} \ DBGOPT="${DBGOPT}" \ scripts/collect_host_image_version_files.sh $CONFIGURED_ARCH $IMAGE_DISTRO $TARGET_PATH $FILESYSTEM_ROOT +# Install libc6-dev and python3-dev for compiling python-lzf +sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install libc6-dev python3-dev + +# Install python-lzf +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install 'python-lzf==0.2.4' + +# Install rdbtools +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install 'rdbtools==0.1.15' + +# Uninstall libc6-dev and python3-dev for compiling python-lzf +sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove libc6-dev +sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove python3-dev + +## Copy saidump.sh +sudo cp ./files/scripts/saidump.sh $FILESYSTEM_ROOT/usr/local/bin/saidump.sh +sudo chmod +x $FILESYSTEM_ROOT/usr/local/bin/saidump.sh # Remove GCC sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove gcc diff --git a/files/scripts/saidump.sh b/files/scripts/saidump.sh new file mode 100755 index 000000000000..76e2dab9dd51 --- /dev/null +++ b/files/scripts/saidump.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +save_saidump_by_rdb() { + #1. Save the Redis data. + sudo sonic-db-cli -n asic$1 SAVE > /dev/null + #2. Move dump files to /var/run/redisX/ + docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" + #3. Run rdb command to convert the dump files into JSON files + sudo python /usr/local/bin/rdb --command json /var/run/redis$1/dump.rdb | sudo tee /var/run/redis$1/dump.json > /dev/null + #4. Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump result in standard output. + docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json" + #5. clear + sudo rm -f /var/run/redis$1/dump.rdb + sudo rm -f /var/run/redis$1/dump.json +} + +NUM_ASICS=`python -c 'from sonic_py_common.multi_asic import get_num_asics; print(get_num_asics())'` + + +if (( $# == 0 && $NUM_ASICS == 1 )); then + save_saidump_by_rdb +#validate if the argument is an integer +elif [[ "$1" =~ [0-9]+ ]] && (( $# == 1 && $1 >= 0 && $1 < $NUM_ASICS )) ; then + save_saidump_by_rdb $1 +else + echo "The number of ASICS is $NUM_ASICS." + echo "Usage:" + echo "saidump.sh or NULL" + echo " should be 0 ~ NUM_ASICS." + echo " E.g. \"saidump.sh 1\" is OK when NUMASICS is 2." + echo " NULL" + echo " E.g. \"saidump.sh\" is OK when NUMASICS is 1." +fi \ No newline at end of file From c8f599646c3836ba32bd68e69e62a543ac7de660 Mon Sep 17 00:00:00 2001 From: jumao Date: Wed, 6 Sep 2023 10:32:10 -0400 Subject: [PATCH 2/7] =?UTF-8?q?=20=20=20=20*=20[saidump]=20=20=20=20=20?= =?UTF-8?q?=E2=80=A2=20=20=20=20=20=20=20Saidump=20for=20DNX-SAI=20https:/?= =?UTF-8?q?/github.com/sonic-net/sonic-buildimage/issues/13561?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Solution and modification: To use the redis-db SAVE option to save the snapshot of DB each time and recover later, instead of looping through each entry in the table and saving it. (1) Updated sonic-buildimage/build_debian.sh, to install Python library rdbtools into the host. (2) Updated sonic-buildimage/src/sonic-sairedis/saidump/saidump.cpp, add a new option -r, which updates the rdbtools's output-JSON files' format. (3) Add a new script file: files/scripts/saidump.sh, to do the below steps For each ASIC0, such as ASIC0, 1. Save the Redis data. sudo sonic-db-cli -n asic$1 SAVE > /dev/null 2. Move dump files to /var/run/redisX/ docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" 3. Run rdb command to convert the dump files into JSON files sudo python /usr/local/bin/rdb --command json /var/run/redis$1/dump.rdb | sudo tee /var/run/redis$1/dump.json > /dev/null 4. Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump result in standard output. docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json" 5. clear sudo rm -f /var/run/redis$1/dump.rdb sudo rm -f /var/run/redis$1/dump.json (4) Update sonic-buildimage/src/sonic-utilities/scripts/generate_dump, replace saidump with saidump.sh --- files/scripts/saidump.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/files/scripts/saidump.sh b/files/scripts/saidump.sh index 76e2dab9dd51..4deb2d0c3646 100755 --- a/files/scripts/saidump.sh +++ b/files/scripts/saidump.sh @@ -1,15 +1,21 @@ #!/bin/bash +set -e + +function debug() +{ + /usr/bin/logger "$1" +} save_saidump_by_rdb() { - #1. Save the Redis data. + debug "saidump.sh: [1] sonic-db-cli -n asic$1 SAVE." sudo sonic-db-cli -n asic$1 SAVE > /dev/null - #2. Move dump files to /var/run/redisX/ + debug "saidump.sh: [2] Move dump.rdb to /var/run/redis$1/ in container database$1." docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" - #3. Run rdb command to convert the dump files into JSON files + debug "saidump.sh: [3] Run rdb command to convert the dump files into JSON files." sudo python /usr/local/bin/rdb --command json /var/run/redis$1/dump.rdb | sudo tee /var/run/redis$1/dump.json > /dev/null - #4. Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump result in standard output. + debug "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output." docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json" - #5. clear + debug "saidump.sh: [5] Clear temporary files." sudo rm -f /var/run/redis$1/dump.rdb sudo rm -f /var/run/redis$1/dump.json } From 1a414d52c80306711755fe394d58c4eaa0bfbf29 Mon Sep 17 00:00:00 2001 From: jumao Date: Mon, 18 Sep 2023 23:42:02 -0400 Subject: [PATCH 3/7] https://github.com/sonic-net/sonic-buildimage/pull/16466 fix based on review comments: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Install rdbtools into syncd docker and add saidump.sh into host. * [saidump] • Saidump for DNX-SAI https://github.com/sonic-net/sonic-buildimage/issues/13561 Solution and modification: To use the Redis-db SAVE option to save the snapshot of DB each time and recover later, instead of looping through each entry in the table and saving it. (1) Updated platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2, install Python library rdbtools into the syncd containter. (2) Updated sonic-buildimage/src/sonic-sairedis/saidump/saidump.cpp, add a new option -r, which updates the rdbtools's output-JSON files' format. (3) Updated sonic-buildimage/build_debian.sh, to add a new script file: files/scripts/saidump.sh into the host. This shell file does the below steps: For each ASIC0, such as ASIC0, 1. Save the Redis data. sudo sonic-db-cli -n asic$1 SAVE > /dev/null 2. Move dump files to /var/run/redisX/ docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" 3. Run rdb command to convert the dump files into JSON files docker exec syncd$1 sh -c "rdb --command json /var/run/redis$1/dump.rdb | tee /var/run/redis$1/dump.json > /dev/null" 4. Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump result in standard output. docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json -m 100" 5. clear sudo rm -f /var/run/redis$1/dump.rdb sudo rm -f /var/run/redis$1/dump.json (4) Update sonic-buildimage/src/sonic-utilities/scripts/generate_dump, to check the asic db size and if it is larger than xxx entries, then do with REDIS SAVE, otherwise, to do with old method: looping through each entry of Redis DB. --- build_debian.sh | 14 +--------- files/scripts/saidump.sh | 27 ++++++++++++------- .../docker-syncd-brcm-dnx/Dockerfile.j2 | 12 +++++++++ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index 3c8519b6288c..3fbc9065484f 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -729,22 +729,10 @@ SONIC_VERSION_CACHE=${SONIC_VERSION_CACHE} \ DBGOPT="${DBGOPT}" \ scripts/collect_host_image_version_files.sh $CONFIGURED_ARCH $IMAGE_DISTRO $TARGET_PATH $FILESYSTEM_ROOT -# Install libc6-dev and python3-dev for compiling python-lzf -sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install libc6-dev python3-dev - -# Install python-lzf -sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install 'python-lzf==0.2.4' - -# Install rdbtools -sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install 'rdbtools==0.1.15' - -# Uninstall libc6-dev and python3-dev for compiling python-lzf -sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove libc6-dev -sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove python3-dev - ## Copy saidump.sh sudo cp ./files/scripts/saidump.sh $FILESYSTEM_ROOT/usr/local/bin/saidump.sh sudo chmod +x $FILESYSTEM_ROOT/usr/local/bin/saidump.sh + # Remove GCC sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove gcc diff --git a/files/scripts/saidump.sh b/files/scripts/saidump.sh index 4deb2d0c3646..2d5f37a4929b 100755 --- a/files/scripts/saidump.sh +++ b/files/scripts/saidump.sh @@ -7,27 +7,34 @@ function debug() } save_saidump_by_rdb() { - debug "saidump.sh: [1] sonic-db-cli -n asic$1 SAVE." - sudo sonic-db-cli -n asic$1 SAVE > /dev/null - debug "saidump.sh: [2] Move dump.rdb to /var/run/redis$1/ in container database$1." - docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" + DEV=$1 # ASIC index to operate on + + if [ "$DEV" ]; then + debug "saidump.sh: [1] sonic-db-cli -n asic$DEV SAVE." + sonic-db-cli -n asic$DEV SAVE > /dev/null + else + debug "saidump.sh: [1] sonic-db-cli SAVE." + sonic-db-cli SAVE > /dev/null + fi + + debug "saidump.sh: [2] Move dump.rdb to /var/run/redis$DEV/ in container database$DEV." + docker exec database$DEV sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$DEV/" debug "saidump.sh: [3] Run rdb command to convert the dump files into JSON files." - sudo python /usr/local/bin/rdb --command json /var/run/redis$1/dump.rdb | sudo tee /var/run/redis$1/dump.json > /dev/null + docker exec syncd$DEV sh -c "rdb --command json /var/run/redis$DEV/dump.rdb | tee /var/run/redis$DEV/dump.json > /dev/null" debug "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output." - docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json" + docker exec syncd$DEV sh -c "saidump -r /var/run/redis$DEV/dump.json -m 100" debug "saidump.sh: [5] Clear temporary files." - sudo rm -f /var/run/redis$1/dump.rdb - sudo rm -f /var/run/redis$1/dump.json + sudo rm -f /var/run/redis$DEV/dump.rdb + sudo rm -f /var/run/redis$DEV/dump.json } NUM_ASICS=`python -c 'from sonic_py_common.multi_asic import get_num_asics; print(get_num_asics())'` - if (( $# == 0 && $NUM_ASICS == 1 )); then save_saidump_by_rdb #validate if the argument is an integer elif [[ "$1" =~ [0-9]+ ]] && (( $# == 1 && $1 >= 0 && $1 < $NUM_ASICS )) ; then - save_saidump_by_rdb $1 + save_saidump_by_rdb $1 else echo "The number of ASICS is $NUM_ASICS." echo "Usage:" diff --git a/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 b/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 index 8bf6a4e50289..49565bc3502e 100755 --- a/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 +++ b/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 @@ -23,6 +23,18 @@ RUN apt-get install -yf kmod ## BRCM uses ethtool to set host interface speed RUN apt-get install -y ethtool +## Install gcc, libc6-dev and python3-dev for compiling python-lzf +RUN apt-get -y install build-essential libc6-dev python3-dev + +## Install python-lzf +RUN pip3 install 'python-lzf==0.2.4' + +## Install rdbtools +RUN pip3 install 'rdbtools==0.1.15' + +## Uninstall gcc, libc6-dev and python3-dev for compiling python-lzf +RUN apt-get -y remove build-essential libc6-dev python3-dev + COPY ["files/dsserve", "files/bcmcmd", "start.sh", "start_led.sh", "bcmsh", "/usr/bin/"] RUN chmod +x /usr/bin/dsserve /usr/bin/bcmcmd From 65fc011e8a30c5c017b1227f5e94a0c0159b9e29 Mon Sep 17 00:00:00 2001 From: jumao Date: Wed, 27 Sep 2023 11:49:32 -0400 Subject: [PATCH 4/7] https://github.com/sonic-net/sonic-buildimage/pull/16466 fixing based on review comments: To add the rdbtools into base docker. Remove sudo in saidump.sh --- dockers/docker-base-bullseye/Dockerfile.j2 | 12 ++++++++++++ files/scripts/saidump.sh | 4 ++-- .../broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 | 12 ------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dockers/docker-base-bullseye/Dockerfile.j2 b/dockers/docker-base-bullseye/Dockerfile.j2 index bbf86034687b..6a1b33f8079d 100644 --- a/dockers/docker-base-bullseye/Dockerfile.j2 +++ b/dockers/docker-base-bullseye/Dockerfile.j2 @@ -83,6 +83,18 @@ RUN pip3 install supervisord-dependent-startup==1.4.0 RUN mkdir -p /var/log/supervisor /etc/supervisor/conf.d +## Install gcc, libc6-dev and python3-dev for compiling python-lzf +RUN apt-get -y install build-essential libc6-dev python3-dev + +## Install python-lzf +RUN pip3 install 'python-lzf==0.2.4' + +## Install rdbtools +RUN pip3 install 'rdbtools==0.1.15' + +## Uninstall gcc, libc6-dev and python3-dev for compiling python-lzf +RUN apt-get -y remove build-essential libc6-dev python3-dev + RUN apt-get -y purge \ exim4 \ exim4-base \ diff --git a/files/scripts/saidump.sh b/files/scripts/saidump.sh index 2d5f37a4929b..11b2bb4da692 100755 --- a/files/scripts/saidump.sh +++ b/files/scripts/saidump.sh @@ -24,8 +24,8 @@ save_saidump_by_rdb() { debug "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output." docker exec syncd$DEV sh -c "saidump -r /var/run/redis$DEV/dump.json -m 100" debug "saidump.sh: [5] Clear temporary files." - sudo rm -f /var/run/redis$DEV/dump.rdb - sudo rm -f /var/run/redis$DEV/dump.json + rm -f /var/run/redis$DEV/dump.rdb + rm -f /var/run/redis$DEV/dump.json } NUM_ASICS=`python -c 'from sonic_py_common.multi_asic import get_num_asics; print(get_num_asics())'` diff --git a/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 b/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 index 49565bc3502e..8bf6a4e50289 100755 --- a/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 +++ b/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 @@ -23,18 +23,6 @@ RUN apt-get install -yf kmod ## BRCM uses ethtool to set host interface speed RUN apt-get install -y ethtool -## Install gcc, libc6-dev and python3-dev for compiling python-lzf -RUN apt-get -y install build-essential libc6-dev python3-dev - -## Install python-lzf -RUN pip3 install 'python-lzf==0.2.4' - -## Install rdbtools -RUN pip3 install 'rdbtools==0.1.15' - -## Uninstall gcc, libc6-dev and python3-dev for compiling python-lzf -RUN apt-get -y remove build-essential libc6-dev python3-dev - COPY ["files/dsserve", "files/bcmcmd", "start.sh", "start_led.sh", "bcmsh", "/usr/bin/"] RUN chmod +x /usr/bin/dsserve /usr/bin/bcmcmd From aaac734b56a9e0b5e30b58ed00c2e6830d851125 Mon Sep 17 00:00:00 2001 From: jumao Date: Sat, 30 Sep 2023 01:13:15 -0400 Subject: [PATCH 5/7] https://github.com/sonic-net/sonic-buildimage/pull/16466 fixing based on review comments: To add the rdbtools into base docker. Move saidump.sh from host to syncd docker container. --- build_debian.sh | 4 -- files/scripts/saidump.sh | 46 ------------------- .../docker-syncd-brcm-dnx/Dockerfile.j2 | 4 ++ .../broadcom/docker-syncd-brcm-dnx/saidump.sh | 43 +++++++++++++++++ 4 files changed, 47 insertions(+), 50 deletions(-) delete mode 100755 files/scripts/saidump.sh create mode 100755 platform/broadcom/docker-syncd-brcm-dnx/saidump.sh diff --git a/build_debian.sh b/build_debian.sh index 32c125f273ef..505806fdc127 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -734,10 +734,6 @@ SONIC_VERSION_CACHE=${SONIC_VERSION_CACHE} \ DBGOPT="${DBGOPT}" \ scripts/collect_host_image_version_files.sh $CONFIGURED_ARCH $IMAGE_DISTRO $TARGET_PATH $FILESYSTEM_ROOT -## Copy saidump.sh -sudo cp ./files/scripts/saidump.sh $FILESYSTEM_ROOT/usr/local/bin/saidump.sh -sudo chmod +x $FILESYSTEM_ROOT/usr/local/bin/saidump.sh - # Remove GCC sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove gcc diff --git a/files/scripts/saidump.sh b/files/scripts/saidump.sh deleted file mode 100755 index 11b2bb4da692..000000000000 --- a/files/scripts/saidump.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -set -e - -function debug() -{ - /usr/bin/logger "$1" -} - -save_saidump_by_rdb() { - DEV=$1 # ASIC index to operate on - - if [ "$DEV" ]; then - debug "saidump.sh: [1] sonic-db-cli -n asic$DEV SAVE." - sonic-db-cli -n asic$DEV SAVE > /dev/null - else - debug "saidump.sh: [1] sonic-db-cli SAVE." - sonic-db-cli SAVE > /dev/null - fi - - debug "saidump.sh: [2] Move dump.rdb to /var/run/redis$DEV/ in container database$DEV." - docker exec database$DEV sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$DEV/" - debug "saidump.sh: [3] Run rdb command to convert the dump files into JSON files." - docker exec syncd$DEV sh -c "rdb --command json /var/run/redis$DEV/dump.rdb | tee /var/run/redis$DEV/dump.json > /dev/null" - debug "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output." - docker exec syncd$DEV sh -c "saidump -r /var/run/redis$DEV/dump.json -m 100" - debug "saidump.sh: [5] Clear temporary files." - rm -f /var/run/redis$DEV/dump.rdb - rm -f /var/run/redis$DEV/dump.json -} - -NUM_ASICS=`python -c 'from sonic_py_common.multi_asic import get_num_asics; print(get_num_asics())'` - -if (( $# == 0 && $NUM_ASICS == 1 )); then - save_saidump_by_rdb -#validate if the argument is an integer -elif [[ "$1" =~ [0-9]+ ]] && (( $# == 1 && $1 >= 0 && $1 < $NUM_ASICS )) ; then - save_saidump_by_rdb $1 -else - echo "The number of ASICS is $NUM_ASICS." - echo "Usage:" - echo "saidump.sh or NULL" - echo " should be 0 ~ NUM_ASICS." - echo " E.g. \"saidump.sh 1\" is OK when NUMASICS is 2." - echo " NULL" - echo " E.g. \"saidump.sh\" is OK when NUMASICS is 1." -fi \ No newline at end of file diff --git a/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 b/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 index 8bf6a4e50289..bb3b66b64674 100755 --- a/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 +++ b/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 @@ -30,6 +30,10 @@ COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] COPY ["critical_processes", "/etc/supervisor/"] +# Copy saidump.sh +COPY ["saidump.sh", "/usr/bin/"] +RUN chmod +x /usr/bin/saidump.sh + ## Clean up RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y RUN rm -rf /debs diff --git a/platform/broadcom/docker-syncd-brcm-dnx/saidump.sh b/platform/broadcom/docker-syncd-brcm-dnx/saidump.sh new file mode 100755 index 000000000000..3c2dd5b228a9 --- /dev/null +++ b/platform/broadcom/docker-syncd-brcm-dnx/saidump.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +function debug() +{ + /usr/bin/logger "$1" +} + +save_saidump_by_rdb() { + local filepath="/var/run/redis/sonic-db/database_config.json" + + #Get hostname, port, redis directory + local redis_config=$(python3 -c " +import json +with open('$filepath') as json_file: + data = json.load(json_file) + print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])") + + #split + redis_config=(${redis_config// / }) + local hostname=${redis_config[0]} + local port=${redis_config[1]} + local redis_dir=`dirname ${redis_config[2]}` + debug "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir" + + debug "saidump.sh: [1] Config Redis consistency directory." + redis-cli -h $hostname -p $port CONFIG SET dir $redis_dir > /dev/null + + debug "saidump.sh: [2] SAVE." + redis-cli -h $hostname -p $port SAVE > /dev/null + + debug "saidump.sh: [3] Run the rdb command to convert the dump.rdb into a JSON file." + rdb --command json $redis_dir/dump.rdb | tee $redis_dir/dump.json > /dev/null + + debug "saidump.sh: [4] Run saidump -r to update the JSON file's format, and then get the result in the standard output." + saidump -r $redis_dir/dump.json -m 100 + + debug "saidump.sh: [5] Clear the temporary files." + rm -f $redis_dir/dump.rdb + rm -f $redis_dir/dump.json +} + +save_saidump_by_rdb \ No newline at end of file From add5b59a92aa69be4903ce9db9ce79de2d4d5abd Mon Sep 17 00:00:00 2001 From: jumao Date: Mon, 2 Oct 2023 18:40:16 -0400 Subject: [PATCH 6/7] https://github.com/sonic-net/sonic-buildimage/pull/16466 fixing based on review comments: To move saidump.sh from this repo to sairedis repo. --- dockers/docker-base-bullseye/Dockerfile.j2 | 8 ++-- .../docker-syncd-brcm-dnx/Dockerfile.j2 | 4 -- .../broadcom/docker-syncd-brcm-dnx/saidump.sh | 43 ------------------- 3 files changed, 4 insertions(+), 51 deletions(-) delete mode 100755 platform/broadcom/docker-syncd-brcm-dnx/saidump.sh diff --git a/dockers/docker-base-bullseye/Dockerfile.j2 b/dockers/docker-base-bullseye/Dockerfile.j2 index 6a1b33f8079d..dcb0c1d4b5a5 100644 --- a/dockers/docker-base-bullseye/Dockerfile.j2 +++ b/dockers/docker-base-bullseye/Dockerfile.j2 @@ -83,16 +83,16 @@ RUN pip3 install supervisord-dependent-startup==1.4.0 RUN mkdir -p /var/log/supervisor /etc/supervisor/conf.d -## Install gcc, libc6-dev and python3-dev for compiling python-lzf +# Install gcc, libc6-dev and python3-dev for compiling python-lzf RUN apt-get -y install build-essential libc6-dev python3-dev -## Install python-lzf +# Install python-lzf RUN pip3 install 'python-lzf==0.2.4' -## Install rdbtools +# Install rdbtools RUN pip3 install 'rdbtools==0.1.15' -## Uninstall gcc, libc6-dev and python3-dev for compiling python-lzf +# Uninstall gcc, libc6-dev and python3-dev for compiling python-lzf RUN apt-get -y remove build-essential libc6-dev python3-dev RUN apt-get -y purge \ diff --git a/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 b/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 index bb3b66b64674..8bf6a4e50289 100755 --- a/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 +++ b/platform/broadcom/docker-syncd-brcm-dnx/Dockerfile.j2 @@ -30,10 +30,6 @@ COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] COPY ["critical_processes", "/etc/supervisor/"] -# Copy saidump.sh -COPY ["saidump.sh", "/usr/bin/"] -RUN chmod +x /usr/bin/saidump.sh - ## Clean up RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y RUN rm -rf /debs diff --git a/platform/broadcom/docker-syncd-brcm-dnx/saidump.sh b/platform/broadcom/docker-syncd-brcm-dnx/saidump.sh deleted file mode 100755 index 3c2dd5b228a9..000000000000 --- a/platform/broadcom/docker-syncd-brcm-dnx/saidump.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -e - -function debug() -{ - /usr/bin/logger "$1" -} - -save_saidump_by_rdb() { - local filepath="/var/run/redis/sonic-db/database_config.json" - - #Get hostname, port, redis directory - local redis_config=$(python3 -c " -import json -with open('$filepath') as json_file: - data = json.load(json_file) - print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])") - - #split - redis_config=(${redis_config// / }) - local hostname=${redis_config[0]} - local port=${redis_config[1]} - local redis_dir=`dirname ${redis_config[2]}` - debug "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir" - - debug "saidump.sh: [1] Config Redis consistency directory." - redis-cli -h $hostname -p $port CONFIG SET dir $redis_dir > /dev/null - - debug "saidump.sh: [2] SAVE." - redis-cli -h $hostname -p $port SAVE > /dev/null - - debug "saidump.sh: [3] Run the rdb command to convert the dump.rdb into a JSON file." - rdb --command json $redis_dir/dump.rdb | tee $redis_dir/dump.json > /dev/null - - debug "saidump.sh: [4] Run saidump -r to update the JSON file's format, and then get the result in the standard output." - saidump -r $redis_dir/dump.json -m 100 - - debug "saidump.sh: [5] Clear the temporary files." - rm -f $redis_dir/dump.rdb - rm -f $redis_dir/dump.json -} - -save_saidump_by_rdb \ No newline at end of file From 8640e461d72f72e0d4b36d0c7d11ca5a89c2c879 Mon Sep 17 00:00:00 2001 From: jumao Date: Fri, 27 Oct 2023 19:08:15 -0400 Subject: [PATCH 7/7] To process the review comment: https://github.com/sonic-net/sonic-buildimage/pull/16466#discussion_r1374926310 --- dockers/docker-base-bullseye/Dockerfile.j2 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dockers/docker-base-bullseye/Dockerfile.j2 b/dockers/docker-base-bullseye/Dockerfile.j2 index dcb0c1d4b5a5..1fa7196ea67c 100644 --- a/dockers/docker-base-bullseye/Dockerfile.j2 +++ b/dockers/docker-base-bullseye/Dockerfile.j2 @@ -93,7 +93,10 @@ RUN pip3 install 'python-lzf==0.2.4' RUN pip3 install 'rdbtools==0.1.15' # Uninstall gcc, libc6-dev and python3-dev for compiling python-lzf -RUN apt-get -y remove build-essential libc6-dev python3-dev +RUN apt-get -y purge build-essential libc6-dev python3-dev + +# Uninstall unused dependencies +RUN apt autoremove -y --purge RUN apt-get -y purge \ exim4 \