Skip to content

Commit 74e1c4f

Browse files
Austina Linfg-j
andcommitted
removing HyperV change to unblock Patch Tuesday
Revert "removed Enable-HyperV from provisioning steps" This reverts commit cc267b4. [#173045518](https://www.pivotaltracker.com/story/show/173045518) As a platform operator I should be able to use Windows stemcells with Hyper-V disabled Co-authored-by: Flora Gallina-Jones <[email protected]>
1 parent cc267b4 commit 74e1c4f

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

stemcell-automation/AutomationHelpers.Tests.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,43 @@ Describe "InstallCFFeatures" {
125125
}
126126
}
127127

128+
Describe "Enable-HyperV" {
129+
It "executes the Enable-Hyper-V powershell cmdlet when the os version is 2019" {
130+
Mock Enable-Hyper-V { }
131+
Mock Write-Log { }
132+
$osVersion2019 = "10.0.17763.2761"
133+
Mock Get-OSVersionString { $osVersion2019 }
134+
135+
{ Enable-HyperV } | Should -Not -Throw
136+
137+
Assert-MockCalled Enable-Hyper-V -Times 1 -Scope It
138+
Assert-MockCalled Write-Log -Times 1 -Scope It -ParameterFilter { $Message -eq "Successfully enabled HyperV" }
139+
}
140+
141+
It "does not execute the Enable-Hyper-V powershell cmdlet when the os version is not 2019" {
142+
Mock Enable-Hyper-V { }
143+
Mock Write-Log { }
144+
$osVersion1803 = "10.0.17134.2761"
145+
Mock Get-OSVersionString { $osVersion1803 }
146+
147+
{ Enable-HyperV } | Should -Not -Throw
148+
149+
Assert-MockCalled Enable-Hyper-V -Times 0 -Scope It
150+
Assert-MockCalled Write-Log -Times 1 -Scope It -ParameterFilter { $Message -eq "Did not enable HyperV because OS Version is not 2019" }
151+
}
152+
153+
It "fails gracefully when enabling Hyper-V" {
154+
Mock Enable-Hyper-V { throw "unable to comply" }
155+
Mock Write-Log { }
156+
$osVersion2019 = "10.0.17763.2761"
157+
Mock Get-OSVersionString { $osVersion2019 }
158+
159+
{ Enable-HyperV } | Should -Throw "unable to comply"
160+
161+
Assert-MockCalled Write-Log -Times 1 -Scope It -ParameterFilter { $Message -eq "unable to comply" }
162+
Assert-MockCalled Write-Log -Times 1 -Scope It -ParameterFilter { $Message -eq "Failed to enable HyperV. See 'c:\provision\log.log' for more info." }
163+
}
164+
}
128165

129166
Describe "InstallCFCell" {
130167
It "executes the Protect-CFCell powershell cmdlet" {

stemcell-automation/AutomationHelpers.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ function InstallCFFeatures
7171
}
7272
}
7373

74+
function Enable-HyperV
75+
{
76+
try
77+
{
78+
$osVersion2019Regex = "10\.0\.17763\..+"
79+
$osVersion = Get-OSVersionString
80+
if ($osVersion -match $osVersion2019Regex) {
81+
Enable-Hyper-V
82+
Write-Log "Successfully enabled HyperV"
83+
}
84+
else {
85+
Write-Log "Did not enable HyperV because OS Version is not 2019"
86+
}
87+
88+
}
89+
catch [Exception]
90+
{
91+
Write-Log $_.Exception.Message
92+
Write-Log "Failed to enable HyperV. See 'c:\provision\log.log' for more info."
93+
throw $_.Exception
94+
}
95+
}
7496

7597
function InstallCFCell
7698
{

stemcell-automation/ProvisionVM.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Describe "ProvisionVM" {
1212
Mock Enable-SSHD { $provisionerCalls.Add("Enable-SSHD") }
1313
Mock Install-SecurityPoliciesAndRegistries { $provisionerCalls.Add("Install-SecurityPoliciesAndRegistries") }
1414
Mock Extract-LGPO { $provisionerCalls.Add("Extract-LGPO") }
15+
Mock Enable-HyperV { $provisionerCalls.Add("Enable-HyperV") }
1516
Mock Install-WUCerts { $provisionerCalls.Add("Install-WUCerts") }
1617
Mock Create-VersionFile { $provisionerCalls.Add("Create-VersionFile") }
1718

@@ -35,6 +36,11 @@ Describe "ProvisionVM" {
3536

3637
Assert-MockCalled -CommandName InstallCFFeatures
3738
}
39+
It "enables Hyper-V when possible" {
40+
ProvisionVM
41+
42+
Assert-MockCalled -CommandName Enable-HyperV
43+
}
3844

3945
It "copy PSModules is the first provisioner called" {
4046
ProvisionVM

stemcell-automation/ProvisionVM.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function ProvisionVM() {
1313
Install-SecurityPoliciesAndRegistries
1414
Enable-SSHD
1515
InstallCFFeatures
16-
16+
Enable-HyperV
1717
try
1818
{
1919
Install-WUCerts

0 commit comments

Comments
 (0)