From 3e31b283b5338ae285319c1fa1fcdb9ed00352e5 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Wed, 15 Feb 2023 16:41:26 +0200 Subject: [PATCH] windows: fix log collection The "Get-WinEvent" command used to retrieve Windows event log messages can fail if the specified log has no entries. We're using the "SilentlyContinue" action to avoid erroring out in such cases. However, the script still terminates abruptly while collecting logs. For this reason, we'll use the "Ignore" error action instead. We'd rather not have test failures just because we failed to retrieve some Windows event log entries. Unlike "SilentlyContinue", "Ignore" doesn't populate the global $Error variable, which may be used when running the script remotely. While at it, we're adding some log messages at the end of the "run_tests" and "collect-event-logs.ps1" scripts. Signed-off-by: Lucian Petrut --- scripts/ceph-windows/collect-event-logs.ps1 | 10 ++++++---- scripts/ceph-windows/run_tests | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/ceph-windows/collect-event-logs.ps1 b/scripts/ceph-windows/collect-event-logs.ps1 index ffdb123f..ecee7245 100644 --- a/scripts/ceph-windows/collect-event-logs.ps1 +++ b/scripts/ceph-windows/collect-event-logs.ps1 @@ -5,7 +5,7 @@ param ( [switch]$CleanupEventLog = $false ) -$ErrorActionPreference = "Stop" +$ErrorActionPreference = "Ignore" function DumpEventLogEvtx($path){ foreach ($i in (Get-WinEvent -ListLog * | ? {$_.RecordCount -gt 0 })) { @@ -15,7 +15,7 @@ function DumpEventLogEvtx($path){ $logFile = Join-Path $path $logName & $Env:WinDir\System32\wevtutil.exe epl $i.LogName $logFile if ($LASTEXITCODE) { - Throw "Failed to export $($i.LogName) to $logFile" + Write-Output "Failed to export $($i.LogName) to $logFile" } } } @@ -27,7 +27,7 @@ function DumpEventLogTxt($path){ Write-Output "exporting "$i.LogName" as "$logName $logFile = Join-Path $path $logName Get-WinEvent ` - -ErrorAction SilentlyContinue ` + -ErrorAction "Ignore" ` -FilterHashtable @{ LogName=$i.LogName; StartTime=$(Get-Date).AddHours(-6) @@ -40,7 +40,7 @@ function ClearEventLog(){ foreach ($i in (Get-WinEvent -ListLog * | ? {$_.RecordCount -gt 0 })) { & $Env:WinDir\System32\wevtutil.exe cl $i.LogName if ($LASTEXITCODE) { - Throw "Failed to clear $($i.LogName) from the event log" + Write-Output "Failed to clear $($i.LogName) from the event log" } } } @@ -56,3 +56,5 @@ if ($IncludeEvtxFiles) { if ($CleanupEventLog) { ClearEventLog } + +Write-Output "Successfully collected Windows event logs." diff --git a/scripts/ceph-windows/run_tests b/scripts/ceph-windows/run_tests index 8f8c07a6..3b147a5f 100644 --- a/scripts/ceph-windows/run_tests +++ b/scripts/ceph-windows/run_tests @@ -111,3 +111,5 @@ else SSH_TIMEOUT=15m ssh_exec python.exe /workspace/test_rbd_wnbd.py --test-name RbdFsFioTest --iterations 4 SSH_TIMEOUT=15m ssh_exec python.exe /workspace/test_rbd_wnbd.py --test-name RbdFsStampTest --iterations 4 fi + +echo "Windows tests succeeded." -- 2.39.5