Skip to content

Commit

Permalink
[Mellanox] Test fixes and URL support for BFB installer (sonic-net#19860
Browse files Browse the repository at this point in the history
)

- Why I did it
Test Fixes:
1. Changed timeout from 300 seconds to 600 seconds
2. Changes to the logic for existing rshim list
3. Changed the kill signals for sub processes from SIGTERM to SIGKILL

Features added:
1. Added url support for the installer: Image can be installed in the following method:
sonic-bfb-installer.sh -r rshim3,rshim5 -b http://server.com/path/to/image/sonic-nvidia-bluefield.bfb
  • Loading branch information
gpunathilell authored Sep 3, 2024
1 parent 9a565fe commit 76af66f
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions platform/mellanox/sonic-bfb-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ usage(){
echo "-c Config file"
echo "-h Help"
}
WORK_DIR=`mktemp -d -p "$DIR"`

bfb_install_call(){
#Example:sudo bfb-install -b <full path to image> -r rshim<id>
local result_file=$(mktemp "/tmp/result_file.XXXXX")
trap "rm -f $result_file" EXIT
local cmd="timeout 300s bfb-install -b $2 -r $1 $appendix"
local result_file=$(mktemp "${WORK_DIR}/result_file.XXXXX")
local cmd="timeout 600s bfb-install -b $2 -r $1 $appendix"
echo "Installing bfb image on DPU connected to $1 using $cmd"
local indicator="$1:"
eval "$cmd" > "$result_file" 2>&1 > >(while IFS= read -r line; do echo "$indicator $line"; done > "$result_file")
Expand All @@ -44,7 +44,26 @@ bfb_install_call(){
if [ $exit_status -ne 0 ] ||[ $verbose = true ]; then
cat "$result_file"
fi
rm -f $result_file
}

file_cleanup(){
rm -rf "$WORK_DIR"
}

is_url() {
local link=$1
if [[ $link =~ https?:// ]]; then
echo "Detected URL. Downloading file"
filename="${WORK_DIR}/sonic-nvidia-bluefield.bfb"
curl -L -o "$filename" "$link"
res=$?
if test "$res" != "0"; then
echo "the curl command failed with: $res"
exit 1
fi
bfb="$filename"
echo "bfb path changed to $bfb"
fi
}

validate_rshim(){
Expand All @@ -71,8 +90,6 @@ check_for_root(){
fi
}



main(){
check_for_root
local config=
Expand Down Expand Up @@ -104,13 +121,16 @@ main(){
echo "Error : bfb image is not provided."
usage
exit 1
else
is_url $bfb
fi
trap "file_cleanup" EXIT
if [[ -f ${config} ]]; then
echo "Using ${config} file"
appendix="-c ${config}"
fi
dev_names_det+=($(
ls /dev/rshim* | awk -F'/' '/^\/dev\/rshim/ {gsub(/:/,"",$NF); print $NF}'
ls -d /dev/rshim? | awk -F'/' '{print $NF}'
))
if [ "${#dev_names_det[@]}" -eq 0 ]; then
echo "No rshim interfaces detected! Make sure to run the $command_name script from the host device/ switch!"
Expand All @@ -127,7 +147,7 @@ main(){
echo "${dev_names_det[@]}"
else
IFS=',' read -ra dev_names <<< "$rshim_dev"
validate_rshim $dev_names
validate_rshim ${dev_names[@]}
fi
fi
trap 'kill_ch_procs' SIGINT SIGTERM SIGHUP
Expand All @@ -148,7 +168,7 @@ kill_all_descendant_procs() {
done
fi
if [[ "$self_kill" == true ]]; then
kill -15 "$pid" > /dev/null 2>&1
kill -9 "$pid" > /dev/null 2>&1
fi
}

Expand Down

0 comments on commit 76af66f

Please sign in to comment.