From d24b557666e932a6325a32ca283a8c84de837d05 Mon Sep 17 00:00:00 2001 From: Dan Cuomo Date: Tue, 28 Jan 2020 23:54:57 -0800 Subject: [PATCH] Re-adding prevention of SAC release. Also adding tests to determine at prereq check if SAC release and fail test. Lastly, swapped out "exit" for "throw" to create a terminating error but not exit the shell. --- Convert-LBFO2SET.psm1 | 24 +++++++++--------------- tests/unit/unit.tests.ps1 | 9 +++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Convert-LBFO2SET.psm1 b/Convert-LBFO2SET.psm1 index b818b30..fbfd934 100644 --- a/Convert-LBFO2SET.psm1 +++ b/Convert-LBFO2SET.psm1 @@ -79,13 +79,12 @@ Function Convert-LBFO2Set { } else { - Write-Error "An LBFO team associated with $LBFOTeam could not be detected." + Throw "An LBFO team associated with $LBFOTeam could not be detected." } } else { - Write-Error "Failed to find an LBFO team or vSwitch named $LBFOTeam`." - exit + Throw "Failed to find an LBFO team or vSwitch named $LBFOTeam`." } Remove-Variable isLBFOTeam,isvSwitch,tmpAdapter,tmpTeam -ErrorAction SilentlyContinue @@ -100,8 +99,7 @@ Function Convert-LBFO2Set { if (-NOT $here) { - Write-Error "Could not find the module path." - exit + throw "Could not find the module path." } # detect the version of Windows @@ -114,26 +112,24 @@ Function Convert-LBFO2Set { { switch ($osBldVer) { - { $_ -ge 14393 -and $_ -lt 17763} { + 14393 { $nicReconnBin = "nicReconnect1.exe" } - { $_ -ge 17763 } { + 17763 { $nicReconnBin = "nicReconnect5.exe" } default { - Write-Error "This version of Windows is not yet certified for Convert-LBFO2SET." - exit + throw "This version of Windows is not yet certified for Convert-LBFO2SET." } } } default { - Write-Error "A supported version of Windows was not detected." - exit + throw "A supported version of Windows was not detected." } } @@ -254,8 +250,7 @@ Function Convert-LBFO2Set { } catch { - Write-Error "Failed to migrate host vNIC(s)." - exit + throw "Failed to migrate host vNIC $($HostvNIC.Name)." } } @@ -263,8 +258,7 @@ Function Convert-LBFO2Set { $vmMigGood = Get-VMNetworkAdapter -All | Where-Object SwitchName -EQ $configData.LBFOVMSwitch.Name -ErrorAction SilentlyContinue if ($vmMigGood) { - Write-Error "Critical vmNIC migration failure. The following virtual NICs were not migrated to the new SET switch:`n$($vmMigGood | ForEach-Object { "`n`t$($_.Name) [$(if ($_.VMName) {"$($_.VMName)"} else {"host"})] " })" - exit + throw "Critical vmNIC migration failure. The following virtual NICs were not migrated to the new SET switch:`n$($vmMigGood | ForEach-Object { "`n`t$($_.Name) [$(if ($_.VMName) {"$($_.VMName)"} else {"host"})] " })" } #region Fire and Brimstone diff --git a/tests/unit/unit.tests.ps1 b/tests/unit/unit.tests.ps1 index b336c42..d13f606 100644 --- a/tests/unit/unit.tests.ps1 +++ b/tests/unit/unit.tests.ps1 @@ -1,12 +1,21 @@ Describe 'OSValidation' -Tag PreValidation { Context HostOS { $NodeOS = Get-CimInstance -ClassName 'Win32_OperatingSystem' + + # detect the version of Windows + $osBldVer = [System.Environment]::OSVersion.Version.Build ### Verify the Host is sufficient version It "${env:ComputerName}`: Must be Windows Server 2016, or Server 2019" { $NodeOS.Caption | Should be ($NodeOS.Caption -like '*Windows Server 2016*' -or $NodeOS.Caption -like '*Windows Server 2019*') } + It "${env:ComputerName}`: Must NOT be a SAC release" { + # 14393 defines Server 2016 RS1 + # 17763 defines Server 2019 RS5 + $osBldVer | Should -BeIn @(14393, 17763) + } + $HyperVInstallation = (Get-WindowsFeature -Name Hyper-V -ComputerName $env:ComputerName -ErrorAction SilentlyContinue).InstallState It "${env:ComputerName}`: Must have Hyper-V installed" {