-
Notifications
You must be signed in to change notification settings - Fork 60
/
vagrantfile
368 lines (324 loc) · 16.2 KB
/
vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# -*- mode: ruby -*-
VAGRANT_FILE_API_VERSION = "2"
# start workaround for https://github.com/mitchellh/vagrant-aws/issues/566
class Hash
def slice(*keep_keys)
h = {}
keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
h
end unless Hash.method_defined?(:slice)
def except(*less_keys)
slice(*keys - less_keys)
end unless Hash.method_defined?(:except)
end
# end workaround for https://github.com/mitchellh/vagrant-aws/issues/566
aws_access_key_id = ENV['AWS_ACCESS_KEY_ID'] || 'not-set'
aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] || 'not-set'
aws_subnet_id = ENV['AWS_SUBNET_ID'] || 'not-set'
aws_security_group_id = ENV['AWS_SECURITY_GROUP_ID'] || 'not-set'
aws_key_name = ENV['KEY_NAME'] || 'not-set'
azure_vm_password = ENV['AZURE_VM_PASSWORD'] || 'not-set'
pre_release_version = ENV['OctopusDSCPreReleaseVersion'] || 'not-set'
$run_test_scenario_script = <<SCRIPT
write-output "##teamcity[blockOpened name='Testing Scenario {scenario_name}']"
$env:TEAMCITY_PROJECT_NAME="#{ENV['TEAMCITY_PROJECT_NAME']}"
set-location c:/temp/tests
Import-Module Pester
$configuration = [PesterConfiguration]::Default
$configuration.TestResult.Enabled = $true
$configuration.TestResult.OutputPath = 'PesterTestResults_{scenario_name}.xml'
$configuration.TestResult.OutputFormat = 'NUnitXml'
$configuration.Run.Path = @('Spec/{scenario_name}.Tests.ps1')
$configuration.Output.Verbosity = 'Detailed'
Invoke-Pester -configuration $configuration
write-output "##teamcity[blockClosed name='Testing Scenario {scenario_name}']"
SCRIPT
def publish_logs(config, scenario, log_files)
log_files.each do |file|
dest = file.gsub(':', '').gsub('/', '-')
source = file.gsub('/', '\\')
config.vm.provision "winrm-file-download" do |winrm|
winrm.source = source
winrm.destination = "logs/#{scenario}-#{dest}"
end
config.vm.provision "shell", inline: "write-output \"##teamcity[publishArtifacts 'logs/#{scenario}-#{dest}']\""
end
end
def run_tests(config, scenario)
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', scenario)
config.vm.provision "winrm-file-download" do |winrm|
winrm.source = "c:/temp/tests/PesterTestResults_#{scenario}.xml"
winrm.destination = "PesterTestResults_#{scenario}.xml"
config.vm.provision "shell", inline: "write-output \"##teamcity[publishArtifacts 'PesterTestResults_#{scenario}.xml']\""
end
end
def run_octopus_scenario(config, scenario, log_files)
config.vm.provision "shell", inline: "write-output \"##teamcity[blockOpened name='Running Scenario #{scenario}']\""
config.vm.provision "dsc" do |dsc|
dsc.configuration_file = "#{scenario}.ps1"
dsc.configuration_data_file = "E2ETests/Scenarios/Configuration.psd1"
dsc.manifests_path = "E2ETests/Scenarios/"
dsc.abort_on_dsc_failure = true
end
config.vm.provision "shell", inline: "write-output \"##teamcity[blockClosed name='Running Scenario #{scenario}']\""
config.vm.provision "shell", path: "Tests/surface-logs.ps1"
publish_logs(config, scenario, log_files)
run_tests(config, scenario)
end
def run_tentacle_scenario(config, scenario, log_files)
config.vm.provision "shell", inline: "write-output \"##teamcity[blockOpened name='Running Scenario #{scenario}']\""
config.vm.provision "dsc" do |dsc|
dsc.configuration_file = "#{scenario}.ps1"
dsc.configuration_data_file = "E2ETests/Scenarios/Configuration.psd1"
dsc.manifests_path = "E2ETests/Scenarios/"
dsc.abort_on_dsc_failure = true
end
config.vm.provision "shell", inline: "write-output \"##teamcity[blockClosed name='Running Scenario #{scenario}']\""
config.vm.provision "shell", path: "Tests/surface-logs.ps1"
publish_logs(config, scenario, log_files)
end
Vagrant.configure(VAGRANT_FILE_API_VERSION) do |config|
hostname = "vagrantdsc.local"
config.vm.guest = :windows
config.vm.communicator = :winrm
config.vm.allowed_synced_folder_types = [:winrm]
config.vm.synced_folder ".", "/vagrant", disabled: true
if Vagrant.has_plugin?("vagrant-multi-hostsupdater")
config.multihostsupdater.aliases = {ip_address => [hostname]}
end
config.vm.provider "virtualbox" do |v, override|
v.gui = true
v.linked_clone = true
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--audio", "none"]
v.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
v.customize ["modifyvm", :id, "--usb", "off"]
v.customize ["modifyvm", :id, "--vram", "32"]
override.vm.box = "OctopusDeploy/dsc-test-server-windows-server-2019"
override.vm.box_url = "https://s3-ap-southeast-2.amazonaws.com/octopus-vagrant-boxes/vagrant/json/OctopusDeploy/virtualbox/dsc-test-server-windows-server-2019.json"
override.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
override.vm.network :forwarded_port, guest: 80, host: 8000, id: "web"
override.vm.network :forwarded_port, guest: 443, host: 8443, id: "ssl"
override.vm.network :forwarded_port, guest: 22, host: 9222, id: "ssh"
override.winrm.port = 5986
override.winrm.ssl_peer_verification = false
end
if Vagrant::Util::Platform.windows? then
config.vm.provider "hyperv" do |v, override|
override.vm.box = "OctopusDeploy/dsc-test-server-windows-server-1803"
override.vm.box_url = "https://s3-ap-southeast-2.amazonaws.com/octopus-vagrant-boxes/vagrant/json/OctopusDeploy/hyperv/dsc-test-server-windows-server-1803.json"
config.vm.network "public_network", bridge: ENV['OctopusDSCVMSwitch']
v.memory = 4096
v.maxmemory = 4096
v.cpus = 2
override.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
override.vm.network :forwarded_port, guest: 80, host: 8000, id: "web"
override.vm.network :forwarded_port, guest: 443, host: 8443, id: "ssl"
override.vm.network :forwarded_port, guest: 22, host: 9222, id: "ssh"
end
end
# this relies on the vagrant-aws & vagrant-winrm-syncedfolders plugins
config.vm.provider :aws do |aws, override|
aws.access_key_id = aws_access_key_id
aws.secret_access_key = aws_secret_access_key
aws.region = "ap-southeast-2"
aws.instance_type = "c4.xlarge"
aws.keypair_name = "#{aws_key_name}"
aws.tags = {
'Name' => 'Vagrant DSC testing',
'Application' => 'OctopusDSC',
'Lifetime' => '< 1 day',
'Environment' => 'Test'
}
aws.security_groups = [ aws_security_group_id ]
aws.subnet_id = aws_subnet_id
aws.associate_public_ip = true
aws.user_data = File.read("Tests/aws_user_data.ps1")
override.vm.box = "OctopusDeploy/dsc-test-server-windows-server-2019" #box added via launcher script
override.ssh.private_key_path = "./#{aws_key_name}.pem"
override.winrm.username = "Administrator"
override.winrm.timeout = 180
override.winrm.password = :aws # this uses the vagrant-aws-winrm plugin to get the password from aws
override.winrm.transport = :ssl
override.winrm.port = 5986
override.winrm.ssl_peer_verification = false
end
config.vm.provider :azure do |azure, override|
azure.resource_group_name = "OctopusDSCTesting"
azure.location = 'AustraliaEast'
azure.vm_name = "DSCTestVM"
azure.vm_size = 'Standard_DS2_v2'
azure.vm_image_urn = 'MicrosoftSQLServer:SQL2016SP1-WS2016:Express:latest'
azure.instance_ready_timeout = 600
azure.vm_password = azure_vm_password
azure.admin_username = "OctoAdmin"
azure.admin_password = azure_vm_password
override.vm.box = "dummy"
override.vm.box_url = "azure.dummy.box"
override.winrm.transport = :ssl
override.winrm.port = 5986
override.winrm.ssl_peer_verification = false
azure.winrm_install_self_signed_cert = true
azure.wait_for_destroy = true
end
# delete existing tests if they exist (for dev)
config.vm.provision "shell", inline: "if (Test-Path 'c:\\temp\\tests') {remove-item -force -recurse 'c:\\temp\\tests' }"
# upload tests
config.vm.provision "file", source: "E2ETests", destination: "c:\\temp\\tests"
config.vm.provision "shell", path: "Tests/install-test-dependencies.ps1"
# in theory, we shouldn't have to do this - the vagrant-dsc should upload it automatically, but cant get it to work
config.vm.provision "file", source: "OctopusDSC", destination: 'C:\Windows\System32\WindowsPowerShell\v1.0\modules\OctopusDSC'
config.vm.provision "shell", path: "Tests/configure-dsc-local-configuration-manager.ps1"
if pre_release_version != 'not-set' then
config.vm.provision "shell", path: "Tests/configure-module-for-prerelease-tests.ps1", args: ("-version " + pre_release_version)
end
if ENV['OctopusDSCTestMode'] != "TentacleOnly" then
# Run DSC to install server
run_octopus_scenario(config,
'Server_Scenario_01_Install',
['C:/ChezOctopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# Run DSC to install second HA node
run_octopus_scenario(config,
'Server_Scenario_02_Install_Second_Node',
['C:/ChezOctopus/Logs/OctopusServer.txt',
'C:/ChezOctopusSecondNode/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-HANode.config',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# remove the first node
run_octopus_scenario(config,
'Server_Scenario_03_Remove',
['C:/ChezOctopusSecondNode/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-HANode.config'])
# remove the second ode
run_octopus_scenario(config, 'Server_Scenario_04_Remove_Second_Node', [])
# Run DSC to install server with a custom instance name
run_octopus_scenario(config, 'Server_Scenario_05_Install_Custom_Instance',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-MyOctopusServer.config'])
# remove the server with a custom instance name
run_octopus_scenario(config, 'Server_Scenario_06_Remove_Custom_Instance', [])
# re-install old version
run_octopus_scenario(config,
'Server_Scenario_07_Reinstall',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# upgrade to the latest
run_octopus_scenario(config,
'Server_Scenario_08_Upgrade',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# install watchdog
run_octopus_scenario(config,
'Server_Scenario_09_Watchdog_Create',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# delete watchdog
run_octopus_scenario(config,
'Server_Scenario_10_Watchdog_Delete',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# remove again prior to installing 4
run_octopus_scenario(config, 'Server_Scenario_11_Remove',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# install v4
run_octopus_scenario(config, 'Server_Scenario_12_Built_In_Worker',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# remove again prior to testing "install only"
run_octopus_scenario(config, 'Server_Scenario_13_Remove',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
end
# install only without configure
run_octopus_scenario(config, 'Server_Scenario_14_Install_Without_Configure',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
# go from installed to configured
run_octopus_scenario(config, 'Server_Scenario_15_Configure_Preinstalled_Instance',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-OctopusServer.config'])
if ENV['OctopusDSCTestMode'] != 'ServerOnly' then
config.vm.provision "shell", path: "Tests/configure-octopus-for-tentacle-tests.ps1"
publish_logs(config, 'Tentacle_Setup', ['C:/Octopus/Logs/configure-octopus-for-tentacle-tests.txt'])
# initial tentacle install
run_tentacle_scenario(config,
'Tentacle_Scenario_01_Install',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-ConfigurePreInstalledInstance.config',
'C:/Octopus/OctopusServer-OctopusServer.config'])
config.vm.provision "shell", path: "Tests/register-polling-tentacle.ps1"
publish_logs(config, 'Tentacle_Scenario_01_Install', ['C:/Octopus/Logs/register-polling-tentacle.txt'])
config.vm.provision "shell", path: "Tests/trigger-and-wait-for-healthcheck.ps1"
publish_logs(config, 'Tentacle_Scenario_01_Install', ['C:/Octopus/Logs/trigger-and-wait-for-healthcheck.txt'])
run_tests(config, 'tentacle_scenario_01_install')
# uninstall tentacle
run_tentacle_scenario(config,
'Tentacle_Scenario_02_Remove',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-ConfigurePreInstalledInstance.config',
'C:/Octopus/OctopusServer-OctopusServer.config'])
config.vm.provision "shell", path: "Tests/trigger-and-wait-for-healthcheck.ps1"
publish_logs(config, 'Tentacle_Scenario_02_Remove', ['C:/Octopus/Logs/trigger-and-wait-for-healthcheck.txt'])
run_tests(config, 'tentacle_scenario_02_remove')
# Install old version
run_tentacle_scenario(config,
'Tentacle_Scenario_03_Reinstall',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-ConfigurePreInstalledInstance.config',
'C:/Octopus/OctopusServer-OctopusServer.config',
'C:/Octopus/OctopusTentacleHome/Logs/OctopusTentacle.txt',
'C:/Octopus/OctopusTentacleHome/Tentacle/Tentacle.config'])
config.vm.provision "shell", path: "Tests/trigger-and-wait-for-healthcheck.ps1"
publish_logs(config, 'Tentacle_Scenario_03_Reinstall', ['C:/Octopus/Logs/trigger-and-wait-for-healthcheck.txt'])
run_tests(config, 'tentacle_scenario_03_reinstall')
# Upgrade it
run_tentacle_scenario(config,
'Tentacle_Scenario_04_Upgrade',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-ConfigurePreInstalledInstance.config',
'C:/Octopus/OctopusServer-OctopusServer.config',
'C:/Octopus/OctopusTentacleHome/Logs/OctopusTentacle.txt',
'C:/Octopus/OctopusTentacleHome/Tentacle/Tentacle.config'])
config.vm.provision "shell", path: "Tests/trigger-and-wait-for-healthcheck.ps1"
publish_logs(config, 'Tentacle_Scenario_04_Upgrade', ['C:/Octopus/Logs/trigger-and-wait-for-healthcheck.txt'])
run_tests(config, 'tentacle_scenario_04_upgrade')
# install watchdog
run_tentacle_scenario(config,
'Tentacle_Scenario_05_Watchdog_Create',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-ConfigurePreInstalledInstance.config',
'C:/Octopus/OctopusServer-OctopusServer.config',
'C:/Octopus/OctopusTentacleHome/Logs/OctopusTentacle.txt',
'C:/Octopus/OctopusTentacleHome/Tentacle/Tentacle.config'])
run_tests(config, 'tentacle_scenario_05_watchdog_create')
# delete watchdog
run_tentacle_scenario(config,
'Tentacle_Scenario_06_Watchdog_Delete',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-ConfigurePreInstalledInstance.config',
'C:/Octopus/OctopusServer-OctopusServer.config',
'C:/Octopus/OctopusTentacleHome/Logs/OctopusTentacle.txt',
'C:/Octopus/OctopusTentacleHome/Tentacle/Tentacle.config'])
run_tests(config, 'tentacle_scenario_06_watchdog_delete')
# remove in preparation for testing comms port
run_tentacle_scenario(config,
'Tentacle_Scenario_07_Remove',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-ConfigurePreInstalledInstance.config',
'C:/Octopus/OctopusServer-OctopusServer.config',
'C:/Octopus/OctopusTentacleHome/Logs/OctopusTentacle.txt',
'C:/Octopus/OctopusTentacleHome/Tentacle/Tentacle.config'])
run_tests(config, 'tentacle_scenario_07_remove')
# tentacle comms port
run_tentacle_scenario(config,
'Tentacle_Scenario_08_Tentacle_Comms_Port',
['C:/Octopus/Logs/OctopusServer.txt',
'C:/Octopus/OctopusServer-ConfigurePreInstalledInstance.config',
'C:/Octopus/OctopusServer-OctopusServer.config',
'C:/Octopus/OctopusTentacleHome/Logs/OctopusTentacle.txt',
'C:/Octopus/OctopusTentacleHome/Tentacle/Tentacle.config'])
run_tests(config, 'tentacle_scenario_08_tentacle_comms_port')
end
end