From 72c235419b714ec12b2c8358a0dda5f0ae77a2b5 Mon Sep 17 00:00:00 2001 From: fumingwei Date: Tue, 27 Feb 2024 15:55:13 +0800 Subject: [PATCH] bugfix:TSG-19452:add retry read sn function in tsg-os-HAL --- .../roles/tsg-os-HAL/files/script/tsg-os-HAL.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ansible/roles/tsg-os-HAL/files/script/tsg-os-HAL.sh b/ansible/roles/tsg-os-HAL/files/script/tsg-os-HAL.sh index 354c9b9b..c3af23aa 100644 --- a/ansible/roles/tsg-os-HAL/files/script/tsg-os-HAL.sh +++ b/ansible/roles/tsg-os-HAL/files/script/tsg-os-HAL.sh @@ -288,7 +288,7 @@ read_device_type() read_sn() { if [ ${DEVICE_TYPE} == "9000-NPB" ]; then - SN=`ipmitool fru -t 130 | awk 'NR==12' | awk '{ print $4}'` + SN=`ipmitool fru -t 130 | grep 'Product Serial' | awk '{ print $4}' | head -n 1` else SN=`ipmitool fru list | grep 'Product Serial' | awk '{ print $4}' | head -n 1` fi @@ -298,6 +298,18 @@ read_sn() fi } +retry_read_sn_when_sn_unavailable() +{ + retry_max_count=10 + i=1 + until [ $i -gt $retry_max_count ] || [ $SN != "unknown" ] + do + sleep $((RANDOM % 6 + 1)) + read_sn + ((i++)) + done +} + add_node_metadata() { local node_name="localhost" @@ -342,4 +354,5 @@ set_mrzcpd_conf # add sn to k8s node annotations. read_device_type read_sn +retry_read_sn_when_sn_unavailable add_node_metadata