Skip to content

Commit 00fa4de

Browse files
committed
Powershell: Install-CFFeatures handles IAAS conditionality
1 parent b7366f3 commit 00fa4de

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

modules/BOSH.CFCell/BOSH.CFCell.Tests.ps1

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,48 @@ Describe "Install-CFFeatures" {
6767
Mock -ModuleName BOSH.CFCell Write-Log { }
6868
Mock -ModuleName BOSH.CFCell Get-WinRMConfig { "Some config" }
6969
Mock -ModuleName BOSH.CFCell WindowsFeatureInstall { }
70-
Mock Uninstall-WindowsFeature { }
7170
Mock -ModuleName BOSH.CFCell Uninstall-WindowsFeature { }
7271
Mock -ModuleName BOSH.CFCell Set-Service { }
7372
Mock -ModuleName BOSH.CFCell Restart-Computer { }
74-
Mock -ModuleName BOSH.CFCell Get-OSVersionString { "10.0.1803" }
7573
}
7674

7775
It "triggers a machine restart when the -ForceReboot flag is set" {
78-
{ Install-CFFeatures -IaaS "ignored" -ForceReboot } | Should -Not -Throw
76+
{ Install-CFFeatures -IaaS "not-vsphere" -ForceReboot } | Should -Not -Throw
7977

8078
Assert-MockCalled Restart-Computer -Times 1 -Scope It -ModuleName BOSH.CFCell
8179
}
8280

8381
It "doesn't trigger a machine restart if -ForceReboot flag not set" {
84-
{ Install-CFFeatures -IaaS "ignored" } | Should -Not -Throw
82+
{ Install-CFFeatures -IaaS "not-vsphere" } | Should -Not -Throw
8583

8684
Assert-MockCalled Restart-Computer -Times 0 -Scope It -ModuleName BOSH.CFCell
8785
}
8886

8987
It "logs Installing CloudFoundry Cell Windows Features" {
90-
{ Install-CFFeatures -IaaS "ignored" } | Should -Not -Throw
88+
{ Install-CFFeatures -IaaS "not-vsphere" } | Should -Not -Throw
9189

9290
Assert-MockCalled Write-Log -Times 1 -Scope It -ModuleName BOSH.CFCell -ParameterFilter { $Message -eq "Installing CloudFoundry Cell Windows Features" }
9391
}
9492

9593
It "logs Installed CloudFoundry Cell Windows Features after installation" {
96-
{ Install-CFFeatures -IaaS "ignored" } | Should -Not -Throw
94+
{ Install-CFFeatures -IaaS "not-vsphere" } | Should -Not -Throw
9795

9896
Assert-MockCalled Write-Log -Times 1 -Scope It -ModuleName BOSH.CFCell -ParameterFilter { $Message -eq "Installed CloudFoundry Cell Windows Features" }
9997
}
98+
99+
It "calls Uninstall-WindowsFeature (for '*Defender')" {
100+
{ Install-CFFeatures -IaaS "not-vsphere" } | Should -Not -Throw
101+
102+
Should -Invoke -ModuleName BOSH.CFCell -CommandName Uninstall-WindowsFeature
103+
}
104+
105+
Context "when -IaaS is 'vsphere'" {
106+
It "does not call Uninstall-WindowsFeature (for '*Defender')" {
107+
{ Install-CFFeatures -IaaS "vsphere" } | Should -Not -Throw
108+
109+
Should -Not -Invoke -ModuleName BOSH.CFCell -CommandName Uninstall-WindowsFeature
110+
}
111+
}
100112
}
101113

102114
Describe "Remove-DockerPackage" {

modules/BOSH.CFCell/BOSH.CFCell.psm1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ function Install-CFFeatures {
2020

2121
WindowsFeatureInstall("FS-Resource-Manager")
2222
WindowsFeatureInstall("Containers")
23-
Get-WindowsFeature | Where-Object -FilterScript { $_.Name -like '*Defender*' } | Uninstall-WindowsFeature -Remove
24-
23+
if ($IaaS -ne "vsphere") {
24+
Get-WindowsFeature | Where-Object -FilterScript { $_.Name -like '*Defender*' } | Uninstall-WindowsFeature -Remove
25+
}
2526
Write-Log "Installed CloudFoundry Cell Windows Features"
2627

2728
Write-Log "Setting WinRM startup type to automatic"

stembuild/modules/BOSH.CFCell/BOSH.CFCell.Tests.ps1

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,48 @@ Describe "Install-CFFeatures" {
100100
Mock -ModuleName BOSH.CFCell Write-Log { }
101101
Mock -ModuleName BOSH.CFCell Get-WinRMConfig { "Some config" }
102102
Mock -ModuleName BOSH.CFCell WindowsFeatureInstall { }
103-
Mock Uninstall-WindowsFeature { }
104103
Mock -ModuleName BOSH.CFCell Uninstall-WindowsFeature { }
105104
Mock -ModuleName BOSH.CFCell Set-Service { }
106105
Mock -ModuleName BOSH.CFCell Restart-Computer { }
107-
Mock -ModuleName BOSH.CFCell Get-OSVersionString { "10.0.1803" }
108106
}
109107

110108
It "triggers a machine restart when the -ForceReboot flag is set" {
111-
{ Install-CFFeatures -IaaS "ignored" -ForceReboot } | Should -Not -Throw
109+
{ Install-CFFeatures -IaaS "not-vsphere" -ForceReboot } | Should -Not -Throw
112110

113111
Assert-MockCalled Restart-Computer -Times 1 -Scope It -ModuleName BOSH.CFCell
114112
}
115113

116114
It "doesn't trigger a machine restart if -ForceReboot flag not set" {
117-
{ Install-CFFeatures -IaaS "ignored" } | Should -Not -Throw
115+
{ Install-CFFeatures -IaaS "not-vsphere" } | Should -Not -Throw
118116

119117
Assert-MockCalled Restart-Computer -Times 0 -Scope It -ModuleName BOSH.CFCell
120118
}
121119

122120
It "logs Installing CloudFoundry Cell Windows Features" {
123-
{ Install-CFFeatures -IaaS "ignored" } | Should -Not -Throw
121+
{ Install-CFFeatures -IaaS "not-vsphere" } | Should -Not -Throw
124122

125123
Assert-MockCalled Write-Log -Times 1 -Scope It -ModuleName BOSH.CFCell -ParameterFilter { $Message -eq "Installing CloudFoundry Cell Windows Features" }
126124
}
127125

128126
It "logs Installed CloudFoundry Cell Windows Features after installation" {
129-
{ Install-CFFeatures -IaaS "ignored" } | Should -Not -Throw
127+
{ Install-CFFeatures -IaaS "not-vsphere" } | Should -Not -Throw
130128

131129
Assert-MockCalled Write-Log -Times 1 -Scope It -ModuleName BOSH.CFCell -ParameterFilter { $Message -eq "Installed CloudFoundry Cell Windows Features" }
132130
}
131+
132+
It "calls Uninstall-WindowsFeature (for '*Defender')" {
133+
{ Install-CFFeatures -IaaS "not-vsphere" } | Should -Not -Throw
134+
135+
Should -Invoke -ModuleName BOSH.CFCell -CommandName Uninstall-WindowsFeature
136+
}
137+
138+
Context "when -IaaS is 'vsphere'" {
139+
It "does not call Uninstall-WindowsFeature (for '*Defender')" {
140+
{ Install-CFFeatures -IaaS "vsphere" } | Should -Not -Throw
141+
142+
Should -Not -Invoke -ModuleName BOSH.CFCell -CommandName Uninstall-WindowsFeature
143+
}
144+
}
133145
}
134146

135147
Describe "Remove-DockerPackage" {

stembuild/modules/BOSH.CFCell/BOSH.CFCell.psm1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ function Install-CFFeatures {
2020

2121
WindowsFeatureInstall("FS-Resource-Manager")
2222
WindowsFeatureInstall("Containers")
23-
23+
if ($IaaS -ne "vsphere") {
24+
Get-WindowsFeature | Where-Object -FilterScript { $_.Name -like '*Defender*' } | Uninstall-WindowsFeature -Remove
25+
}
2426
Write-Log "Installed CloudFoundry Cell Windows Features"
2527

2628
Write-Log "Setting WinRM startup type to automatic"

0 commit comments

Comments
 (0)