Skip to content

Commit 0b2343e

Browse files
author
CI (Automated)
committed
Merge remote-tracking branch 'local-from/develop' into HEAD
2 parents e5607bb + 1c114f2 commit 0b2343e

File tree

10 files changed

+347
-43
lines changed

10 files changed

+347
-43
lines changed

bosh-psmodules/modules/BOSH.Agent/BOSH.Agent.Tests.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,22 @@ Describe "Write-AgentConfig" {
128128
{ Write-AgentConfig -BoshDir $boshDir -IaaS azure } | Should Not Throw
129129
$configPath = (Join-Path $boshDir "agent.json")
130130
Test-Path $configPath | Should Be $True
131-
($configPath) | Should -FileContentMatch ([regex]::Escape('"SettingsPath": "C:/AzureData/CustomData.bin"'))
132-
($configPath) | Should -FileContentMatch ([regex]::Escape('"MetaDataPath": "C:/AzureData/CustomData.bin"'))
133-
($configPath) | Should -FileContentMatch ([regex]::Escape('"UseServerName": false'))
131+
$configContent = $(Get-Content $configPath | ConvertFrom-JSON)
132+
133+
$configContent.Infrastructure.Settings.Sources[0].SettingsPath | Should Be "C:/AzureData/CustomData.bin"
134+
$configContent.Infrastructure.Settings.Sources[0].MetaDataPath | Should Be "C:/AzureData/CustomData.bin"
135+
$configContent.Infrastructure.Settings.UseServerName | Should Be "false"
136+
}
137+
138+
It "enables ephemeral disk mounting when the flag is true" {
139+
{ Write-AgentConfig -BoshDir $boshDir -IaaS azure -EnableEphemeralDiskMounting $true } | Should Not Throw
140+
$configPath = (Join-Path $boshDir "agent.json")
141+
Test-Path $configPath | Should Be $True
142+
$configContent = $(Get-Content $configPath | ConvertFrom-JSON)
143+
144+
$configContent.Platform.Windows.EnableEphemeralDiskMounting | Should Be $true
134145
}
146+
135147
}
136148

137149
Context "when IaaS is 'gcp'" {

bosh-psmodules/modules/BOSH.Agent/BOSH.Agent.psm1

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,28 @@ function Write-AgentConfig {
9595
if ($EnableEphemeralDiskMounting) { $awsConfig.Platform.Windows = @{ EnableEphemeralDiskMounting = $true } }
9696
$awsConfig = $awsConfig | ConvertTo-JSON -Depth 100
9797

98-
$azureConfig = @"
99-
{
100-
"Platform": {
101-
"Linux": {
102-
"DevicePathResolutionType": "scsi"
103-
}
104-
},
105-
"Infrastructure": {
106-
"Settings": {
107-
"Sources": [
108-
{
109-
"Type": "File",
110-
"MetaDataPath": "C:/AzureData/CustomData.bin",
111-
"UserDataPath": "C:/AzureData/CustomData.bin",
112-
"SettingsPath": "C:/AzureData/CustomData.bin"
98+
$azureConfig = @{
99+
"Platform" = @{
100+
"Linux" = @{
101+
"DevicePathResolutionType" = "scsi"
113102
}
114-
],
115-
"UseServerName": false,
116-
"UseRegistry": true
103+
}
104+
"Infrastructure" = @{
105+
"Settings" = @{
106+
"Sources" = (,@{
107+
"Type" = "File"
108+
"MetaDataPath" = "C:/AzureData/CustomData.bin"
109+
"UserDataPath" = "C:/AzureData/CustomData.bin"
110+
"SettingsPath" = "C:/AzureData/CustomData.bin"
111+
})
112+
"UseServerName" = $false
113+
"UseRegistry" = $true
114+
}
115+
}
117116
}
118-
}
119-
}
120-
"@
117+
if ($EnableEphemeralDiskMounting) { $azureConfig.Platform.Windows = @{ EnableEphemeralDiskMounting = $true } }
118+
$azureConfig = $azureConfig | ConvertTo-JSON -Depth 100
119+
121120
$gcpConfig = @{
122121
"Platform" = @{
123122
"Linux" = @{

lib/packer/config/azure.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def provisioners
5252
[
5353
Base.pre_provisioners(@os),
5454
Provisioners::lgpo_exe,
55-
Provisioners.install_agent('azure').freeze,
55+
Provisioners.install_agent('azure', @mount_ephemeral_disk).freeze,
5656
Base.enable_security_patches(@os),
5757
Base.post_provisioners('azure', @os)
5858
].flatten

lib/stemcell/builder/azure.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def packer_config
5555
vm_size: @vm_size,
5656
output_directory: @output_directory,
5757
os: @os,
58-
vm_prefix: @vm_prefix
58+
vm_prefix: @vm_prefix,
59+
mount_ephemeral_disk: @mount_ephemeral_disk,
5960
).dump
6061
end
6162

lib/tasks/build/azure.rake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ namespace :build do
3535
publisher: Stemcell::Builder::validate_env('PUBLISHER'),
3636
offer: Stemcell::Builder::validate_env('OFFER'),
3737
sku: Stemcell::Builder::validate_env('SKU'),
38-
vm_prefix: ENV.fetch('VM_PREFIX', '')
38+
vm_prefix: ENV.fetch('VM_PREFIX', ''),
39+
mount_ephemeral_disk: ENV.fetch('MOUNT_EPHEMERAL_DISK', 'false'),
3940
)
4041

4142
azure_builder.build

spec/integration/build/azure_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
agent_commit
6464
)
6565

66+
# This allows the task to be ran multiple times by different tests
67+
Rake::Task['build:azure'].reenable
6668
Rake::Task['build:azure'].invoke
6769

6870
expect(File.read(File.join(@output_directory, "bosh-stemcell-#{version}-azure-vhd-uri.txt"))).to eq 'some-disk-image-url'

spec/packer/config/azure_spec.rb

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
vm_size: 'some-vm-size',
2626
output_directory: '',
2727
os: '',
28-
vm_prefix: 'some-vm-prefix'
28+
vm_prefix: 'some-vm-prefix',
29+
mount_ephemeral_disk: false,
2930
).builders
3031
expect(builders[0]).to eq(
3132
'type' => 'azure-arm',
@@ -79,11 +80,18 @@
7980
end
8081

8182
describe 'provisioners' do
83+
before(:each) do
84+
@stemcell_deps_dir = Dir.mktmpdir('gcp')
85+
ENV['STEMCELL_DEPS_DIR'] = @stemcell_deps_dir
86+
end
87+
88+
after(:each) do
89+
FileUtils.rm_rf(@stemcell_deps_dir)
90+
ENV.delete('STEMCELL_DEPS_DIR')
91+
end
92+
8293
context 'windows 2012' do
8394
it 'returns the expected provisioners' do
84-
stemcell_deps_dir = Dir.mktmpdir('azure')
85-
ENV['STEMCELL_DEPS_DIR'] = stemcell_deps_dir
86-
8795
allow(SecureRandom).to receive(:hex).and_return("some-password")
8896
provisioners = Packer::Config::Azure.new(
8997
client_id: '',
@@ -97,7 +105,8 @@
97105
vm_size: '',
98106
output_directory: 'some-output-directory',
99107
os: 'windows2012R2',
100-
vm_prefix: ''
108+
vm_prefix: '',
109+
mount_ephemeral_disk: false,
101110
).provisioners
102111
expected_provisioners_except_lgpo = [
103112
{"type"=>"file", "source"=>"build/bosh-psmodules.zip", "destination"=>"C:\\provision\\bosh-psmodules.zip"},
@@ -130,16 +139,10 @@
130139
expect(provisioners.detect {|x| x['destination'] == "C:\\windows\\LGPO.exe"}).not_to be_nil
131140
provisioners_no_lgpo = provisioners.delete_if {|x| x['destination'] == "C:\\windows\\LGPO.exe"}
132141
expect(provisioners_no_lgpo).to eq (expected_provisioners_except_lgpo)
133-
134-
FileUtils.rm_rf(stemcell_deps_dir)
135-
ENV.delete('STEMCELL_DEPS_DIR')
136142
end
137143
end
138144
context 'windows 2016' do
139145
it 'returns the expected provisioners' do
140-
stemcell_deps_dir = Dir.mktmpdir('azure')
141-
ENV['STEMCELL_DEPS_DIR'] = stemcell_deps_dir
142-
143146
allow(SecureRandom).to receive(:hex).and_return("some-password")
144147
provisioners = Packer::Config::Azure.new(
145148
client_id: '',
@@ -153,7 +156,8 @@
153156
vm_size: '',
154157
output_directory: 'some-output-directory',
155158
os: 'windows2016',
156-
vm_prefix: ''
159+
vm_prefix: '',
160+
mount_ephemeral_disk: false,
157161
).provisioners
158162
expected_provisioners_except_lgpo = [
159163
{"type"=>"file", "source"=>"build/bosh-psmodules.zip", "destination"=>"C:\\provision\\bosh-psmodules.zip"},
@@ -183,9 +187,38 @@
183187
expect(provisioners.detect {|x| x['destination'] == "C:\\windows\\LGPO.exe"}).not_to be_nil
184188
provisioners_no_lgpo = provisioners.delete_if {|x| x['destination'] == "C:\\windows\\LGPO.exe"}
185189
expect(provisioners_no_lgpo).to eq (expected_provisioners_except_lgpo)
190+
end
191+
192+
context 'when provisioning with emphemeral disk mounting enabled' do
193+
it 'calls Install-Agent with -EnableEphemeralDiskMounting' do
194+
allow(SecureRandom).to receive(:hex).and_return("some-password")
195+
provisioners = Packer::Config::Azure.new(
196+
client_id: '',
197+
client_secret: '',
198+
tenant_id: '',
199+
subscription_id: '',
200+
object_id: '',
201+
resource_group_name: '',
202+
storage_account: '',
203+
location: '',
204+
vm_size: '',
205+
output_directory: 'some-output-directory',
206+
os: 'windows2016',
207+
vm_prefix: '',
208+
mount_ephemeral_disk: true,
209+
).provisioners
186210

187-
FileUtils.rm_rf(stemcell_deps_dir)
188-
ENV.delete('STEMCELL_DEPS_DIR')
211+
expect(provisioners).to include(
212+
{
213+
"type"=>"powershell",
214+
"inline"=>[
215+
"$ErrorActionPreference = \"Stop\";",
216+
"trap { $host.SetShouldExit(1) }",
217+
"Install-Agent -IaaS azure -agentZipPath 'C:\\provision\\agent.zip' -EnableEphemeralDiskMounting"
218+
]
219+
}
220+
)
221+
end
189222
end
190223
end
191224
end

spec/stemcell/builder/azure_spec.rb

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
vm_size: vm_size,
5353
output_directory: output_directory,
5454
os: os,
55-
vm_prefix: vm_prefix
55+
vm_prefix: vm_prefix,
56+
mount_ephemeral_disk: false,
5657
).and_return(packer_config)
5758

5859
packer_runner = double(:packer_runner)
@@ -101,10 +102,91 @@
101102
publisher: publisher,
102103
offer: offer,
103104
sku: sku,
104-
vm_prefix: vm_prefix
105+
vm_prefix: vm_prefix,
106+
mount_ephemeral_disk: 'false',
105107
).build
106108
expect(stemcell_path).to eq('path-to-stemcell')
107109
end
108110
end
109111
end
112+
113+
describe 'handles mount_ephemeral_disk correctly' do
114+
it 'when parameter is set to true' do
115+
actual = Stemcell::Builder::Azure.new(
116+
client_id: '',
117+
client_secret: '',
118+
tenant_id: '',
119+
subscription_id: '',
120+
object_id: '',
121+
resource_group_name: '',
122+
storage_account: '',
123+
location: '',
124+
vm_size: '',
125+
publisher: '',
126+
offer: '',
127+
sku: '',
128+
vm_prefix:'',
129+
os: '',
130+
output_directory: '',
131+
version: '',
132+
agent_commit: '',
133+
packer_vars: '',
134+
mount_ephemeral_disk: 'true'
135+
)
136+
137+
expect(actual.instance_variable_get(:@mount_ephemeral_disk)).to equal(true)
138+
end
139+
140+
it 'when parameter is set to false' do
141+
actual = Stemcell::Builder::Azure.new(
142+
client_id: '',
143+
client_secret: '',
144+
tenant_id: '',
145+
subscription_id: '',
146+
object_id: '',
147+
resource_group_name: '',
148+
storage_account: '',
149+
location: '',
150+
vm_size: '',
151+
publisher: '',
152+
offer: '',
153+
sku: '',
154+
vm_prefix:'',
155+
os: '',
156+
output_directory: '',
157+
version: '',
158+
agent_commit: '',
159+
packer_vars: '',
160+
mount_ephemeral_disk: 'false'
161+
)
162+
163+
expect(actual.instance_variable_get(:@mount_ephemeral_disk)).to equal(false)
164+
end
165+
166+
it 'when parameter is missing' do
167+
actual = Stemcell::Builder::Azure.new(
168+
client_id: '',
169+
client_secret: '',
170+
tenant_id: '',
171+
subscription_id: '',
172+
object_id: '',
173+
resource_group_name: '',
174+
storage_account: '',
175+
location: '',
176+
vm_size: '',
177+
publisher: '',
178+
offer: '',
179+
sku: '',
180+
vm_prefix:'',
181+
os: '',
182+
output_directory: '',
183+
version: '',
184+
agent_commit: '',
185+
packer_vars: ''
186+
)
187+
188+
expect(actual.instance_variable_get(:@mount_ephemeral_disk)).to equal(false)
189+
end
190+
end
191+
110192
end

spec/stemcell/builder/base_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,43 @@
4242
end
4343
end
4444
end
45+
46+
describe 'Base' do
47+
context 'initialize handles mount_ephemeral_disk' do
48+
it 'handles true parameter' do
49+
actual = Stemcell::Builder::Base.new(
50+
os: '',
51+
output_directory: '',
52+
version: '',
53+
agent_commit: '',
54+
packer_vars: '',
55+
mount_ephemeral_disk: 'true'
56+
)
57+
expect(actual.instance_variable_get(:@mount_ephemeral_disk)).to equal(true)
58+
end
59+
60+
it 'handles false parameter' do
61+
actual = Stemcell::Builder::Base.new(
62+
os: '',
63+
output_directory: '',
64+
version: '',
65+
agent_commit: '',
66+
packer_vars: '',
67+
mount_ephemeral_disk: 'false'
68+
)
69+
expect(actual.instance_variable_get(:@mount_ephemeral_disk)).to equal(false)
70+
71+
end
72+
it 'handles missing parameter' do
73+
actual = Stemcell::Builder::Base.new(
74+
os: '',
75+
output_directory: '',
76+
version: '',
77+
agent_commit: '',
78+
packer_vars: ''
79+
)
80+
expect(actual.instance_variable_get(:@mount_ephemeral_disk)).to equal(false)
81+
end
82+
end
83+
end
4584
end

0 commit comments

Comments
 (0)