From aaac734b56a9e0b5e30b58ed00c2e6830d851125 Mon Sep 17 00:00:00 2001 From: jumao Date: Sat, 30 Sep 2023 01:13:15 -0400 Subject: [PATCH] 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