add scripts
This commit is contained in:
90
test_firmwareupdater.sh
Executable file
90
test_firmwareupdater.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# stress_firmwareupdate.sh
|
||||
# Usage: ./stress_firmwareupdate.sh <DUT_IP> <REPEAT_COUNT>
|
||||
|
||||
# 檢查參數是否正確
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Usage: $0 <DUT_IP> <REPEAT_COUNT>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DUT_IP=$1
|
||||
REPEAT_COUNT=$2
|
||||
SSH_USER="root" # 假設使用 root 用戶,請根據實際情況修改
|
||||
SSH_PASSWORD="test0000" # 請替換為實際密碼
|
||||
FIRMWARE_UPDATE_CMD="/usr/local/chromeos-firmwareupdate_joxer_recovery -m factory"
|
||||
LOG_FILE="firmware_update.log"
|
||||
EVENT_LOG="/var/log/eventlog.txt"
|
||||
|
||||
|
||||
# 檢查 sshpass 是否安裝
|
||||
if ! command -v sshpass &> /dev/null; then
|
||||
echo "sshpass is not installed. Please install it first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 迴圈執行指定次數
|
||||
for ((i=1; i<=REPEAT_COUNT; i++)); do
|
||||
|
||||
echo "Fetching last line of $EVENT_LOG before firmware update..."
|
||||
LAST_LOG_BEFORE=$(sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$SSH_USER@$DUT_IP" "tail -n 1 $EVENT_LOG" 2>/dev/null)
|
||||
if [ -z "$LAST_LOG_BEFORE" ]; then
|
||||
echo "Failed to fetch $EVENT_LOG before update in iteration $i"
|
||||
exit 1
|
||||
fi
|
||||
echo "Last log line before update: $LAST_LOG_BEFORE"
|
||||
|
||||
# 執行固件更新指令並將輸出記錄到日誌
|
||||
echo "Starting firmware update iteration $i of $REPEAT_COUNT..."
|
||||
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$SSH_USER@$DUT_IP" "$FIRMWARE_UPDATE_CMD" > "$LOG_FILE" 2>&1
|
||||
|
||||
|
||||
# 檢查是否成功
|
||||
if grep -q "Firmware updater exits successfully." "$LOG_FILE"; then
|
||||
echo "Firmware update successful in iteration $i"
|
||||
else
|
||||
echo "Firmware update failed in iteration $i"
|
||||
cat "$LOG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 執行重啟
|
||||
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$SSH_USER@$DUT_IP" "logger -t TEST "CASPER before sleep""
|
||||
echo "sleep 300 sec before reboot"
|
||||
sleep 300
|
||||
|
||||
# 在重啟前,再次獲取 /var/log/eventlog 最後一行
|
||||
echo "Fetching last line of $EVENT_LOG after firmware update..."
|
||||
LAST_LOG_AFTER=$(sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$SSH_USER@$DUT_IP" "tail -n 1 $EVENT_LOG" 2>/dev/null)
|
||||
if [ -z "$LAST_LOG_AFTER" ]; then
|
||||
echo "Failed to fetch $EVENT_LOG after update in iteration $i"
|
||||
exit 1
|
||||
fi
|
||||
echo "Last log line after update: $LAST_LOG_AFTER"
|
||||
|
||||
# 比較前後日誌是否相同
|
||||
if [ "$LAST_LOG_BEFORE" != "$LAST_LOG_AFTER" ]; then
|
||||
echo "Abnormal reboot detected in iteration $i: event log changed."
|
||||
echo "Before: $LAST_LOG_BEFORE"
|
||||
echo "After: $LAST_LOG_AFTER"
|
||||
exit 1
|
||||
else
|
||||
echo "No abnormal reboot detected in iteration $i: event log unchanged."
|
||||
fi
|
||||
echo "Rebooting device..."
|
||||
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$SSH_USER@$DUT_IP" "reboot"
|
||||
|
||||
# 等待設備重啟完成(根據設備重啟時間調整)
|
||||
sleep 60
|
||||
|
||||
# 檢查設備是否重新上線
|
||||
until sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$SSH_USER@$DUT_IP" "echo 'Device is up'" &> /dev/null; do
|
||||
echo "Waiting for device to come back online..."
|
||||
sleep 10
|
||||
done
|
||||
|
||||
echo "Device is back online, proceeding to next iteration..."
|
||||
done
|
||||
|
||||
echo "All $REPEAT_COUNT firmware update iterations completed successfully."
|
||||
Reference in New Issue
Block a user