From cda57cad986356615726b9ff49c5a7ef52f5d9c9 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 7 Jun 2022 09:56:50 -0700 Subject: [PATCH 1/2] Backport test fixes from (#17233) --- .../Test-Connection.Tests.ps1 | 11 ++----- .../engine/Remoting/PSSession.Tests.ps1 | 10 ++---- .../Remoting/RemoteSession.Basic.Tests.ps1 | 33 ++++--------------- .../Modules/HelpersCommon/HelpersCommon.psd1 | 1 + .../Modules/HelpersCommon/HelpersCommon.psm1 | 16 +++++++++ 5 files changed, 27 insertions(+), 44 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 index 7addac6dc61..5173e0a68bb 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 @@ -96,15 +96,8 @@ Describe "Test-Connection" -tags "CI" { { Test-Connection "fakeHost" -Count 1 -ErrorAction Stop } | Should -Throw -ErrorId "TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand" # Error code = 11001 - Host not found. - $platform = Get-PlatformInfo - if ($platform.Platform -match "raspbian" -or ( $platform.Platform -match 'ubuntu' -and $platform.Version -eq '20.04')) { - $code = 11 - } elseif (!$IsWindows) { - $code = -131073 - } else { - $code = 11001 - } - $error[0].Exception.InnerException.ErrorCode | Should -Be $code + # Error code = -131073 - Invalid address + $error[0].Exception.InnerException.ErrorCode | Should -BeIn 11, -131073, 11001 } It "Force IPv4 with implicit PingOptions" { diff --git a/test/powershell/engine/Remoting/PSSession.Tests.ps1 b/test/powershell/engine/Remoting/PSSession.Tests.ps1 index 25c7ab9c582..cbf7313eed0 100644 --- a/test/powershell/engine/Remoting/PSSession.Tests.ps1 +++ b/test/powershell/engine/Remoting/PSSession.Tests.ps1 @@ -79,14 +79,8 @@ Describe "SkipCACheck and SkipCNCheck PSSession options are required for New-PSS It "" -TestCases $testCases { param ($scriptBlock, $expectedErrorCode) - $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') - ) { - Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, and CentOS 8" + if ( -not (Get-WsManSupport)) { + Set-ItResult -Skipped -Because "MI library not available for this platform" return } diff --git a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 index d56ed1999ac..84e25a276ec 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 @@ -10,15 +10,8 @@ function GetRandomString() Describe "New-PSSession basic test" -Tag @("CI") { It "New-PSSession should not crash powershell" { - $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or - ($IsMacOS) - ) { - Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, CentOS 8, and not compatible with macOS" + if ( -not (Get-WsManSupport)) { + Set-ItResult -Skipped -Because "MI library not available for this platform" return } @@ -29,15 +22,8 @@ Describe "New-PSSession basic test" -Tag @("CI") { Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") { It "New-PSSession should throw when specifying Basic Auth over HTTP on Unix" -Skip:($IsWindows) { - $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or - ($IsMacOS) - ) { - Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, CentOS 8, and not compatible with macOS" + if ( -not (Get-WsManSupport)) { + Set-ItResult -Skipped -Because "MI library not available for this platform" return } @@ -53,15 +39,8 @@ Describe "Basic Auth over HTTP not allowed on Unix" -Tag @("CI") { # Skip this test for macOS because the latest OS release is incompatible with our shipped libmi for WinRM/OMI. It "New-PSSession should NOT throw a ConnectFailed exception when specifying Basic Auth over HTTPS on Unix" -Skip:($IsWindows) { - $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and ($platformInfo.Version -eq '10' -or $platformInfo.Version -eq '')) -or # debian 11 has empty Version ID - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or - ($IsMacOS) - ) { - Set-ItResult -Skipped -Because "MI library not available for Alpine, Raspberry Pi, Debian 10 and 11, CentOS 8, and not compatible with macOS" + if ( -not (Get-WsManSupport)) { + Set-ItResult -Skipped -Because "MI library not available for this platform" return } diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 index 3d501983806..43d2ada88cc 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 @@ -35,6 +35,7 @@ FunctionsToExport = @( 'Wait-FileToBePresent' 'Wait-UntilTrue' 'Get-PlatformInfo' + 'Get-WSManSupport' ) CmdletsToExport= @() diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index 894a85ff14d..3c3d8a0db2a 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -388,3 +388,19 @@ function Get-PlatformInfo { return "unknown" } } + +# return true if WsMan is supported on the current platform +function Get-WsManSupport { + $platformInfo = Get-PlatformInfo + if ( + ($platformInfo.Platform -match "alpine|raspbian") -or + ($platformInfo.Platform -eq "debian" -and $platformInfo.Version -ne '9') -or + ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or + ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or + ($platformInfo.Platform -eq 'mariner') -or + ($IsMacOS) + ) { + return $false + } + return $true +} From 4cadd3f1072c92d97d071cb6566c4f0e8d10fde1 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 7 Jun 2022 09:57:16 -0700 Subject: [PATCH 2/2] Simplify WSMan logic --- .../Modules/HelpersCommon/HelpersCommon.psm1 | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index 3c3d8a0db2a..9e5510e0e82 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -392,15 +392,13 @@ function Get-PlatformInfo { # return true if WsMan is supported on the current platform function Get-WsManSupport { $platformInfo = Get-PlatformInfo - if ( - ($platformInfo.Platform -match "alpine|raspbian") -or - ($platformInfo.Platform -eq "debian" -and $platformInfo.Version -ne '9') -or - ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '8') -or - ($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '20.04') -or - ($platformInfo.Platform -eq 'mariner') -or - ($IsMacOS) - ) { - return $false + if (($platformInfo.Platform -eq 'ubuntu' -and $platformInfo.Version -eq '18.04') -or + ($platformInfo.Platform -eq 'centos' -and $platformInfo.Version -eq '7') -or + $IsWindows + ) + { + return $true } - return $true + + return $false }