Skip to content

Commit 890afad

Browse files
[test] packaging: add windows boxes (#30402)
Adds windows server 2012r2 and 2016 vagrant boxes to packaging tests. They can only be used if IDs for their images are specified, which are passed to gradle and then to vagrant via env variables. Adds options to the project property `vagrant.boxes` to choose between linux and windows boxes. Bats tests are run only on linux boxes, and portable packaging tests run on all boxes. Platform tests are only run on linux boxes since they are not being maintained. For #26741
1 parent a4c9c2f commit 890afad

File tree

3 files changed

+331
-124
lines changed

3 files changed

+331
-124
lines changed

TESTING.asciidoc

+105-50
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,16 @@ comma separated list of nodes to connect to (e.g. localhost:9300). A transport c
303303
be created based on that and used for all the before|after test operations, and to extract
304304
the http addresses of the nodes so that REST requests can be sent to them.
305305

306-
== Testing scripts
306+
== Testing packaging
307307

308-
The simplest way to test scripts and the packaged distributions is to use
309-
Vagrant. You can get started by following there five easy steps:
308+
The packaging tests use Vagrant virtual machines to verify that installing
309+
and running elasticsearch distributions works correctly on supported operating systems.
310+
These tests should really only be run in vagrant vms because they're destructive.
310311

311312
. Install Virtual Box and Vagrant.
312313

313-
. (Optional) Install vagrant-cachier to squeeze a bit more performance out of
314-
the process:
314+
. (Optional) Install https://github.com/fgrehm/vagrant-cachier[vagrant-cachier] to squeeze
315+
a bit more performance out of the process:
315316

316317
--------------------------------------
317318
vagrant plugin install vagrant-cachier
@@ -325,26 +326,39 @@ vagrant plugin install vagrant-cachier
325326

326327
. Download and smoke test the VMs with `./gradlew vagrantSmokeTest` or
327328
`./gradlew -Pvagrant.boxes=all vagrantSmokeTest`. The first time you run this it will
328-
download the base images and provision the boxes and immediately quit. If you
329-
you this again it'll skip the download step.
329+
download the base images and provision the boxes and immediately quit. Downloading all
330+
the images may take a long time. After the images are already on your machine, they won't
331+
be downloaded again unless they have been updated to a new version.
330332

331333
. Run the tests with `./gradlew packagingTest`. This will cause Gradle to build
332334
the tar, zip, and deb packages and all the plugins. It will then run the tests
333335
on ubuntu-1404 and centos-7. We chose those two distributions as the default
334336
because they cover deb and rpm packaging and SyvVinit and systemd.
335337

336-
You can run on all the VMs by running `./gradlew -Pvagrant.boxes=all
337-
packagingTest`. You can run a particular VM with a command like `./gradlew
338-
-Pvagrant.boxes=oel-7 packagingTest`. See `./gradlew tasks` for a complete list
339-
of available vagrant boxes for testing. It's important to know that if you
340-
interrupt any of these Gradle commands then the boxes will remain running and
341-
you'll have to terminate them with `./gradlew stop`.
338+
You can choose which boxes to test by setting the `-Pvagrant.boxes` project property. All of
339+
the valid options for this property are:
340+
341+
* `sample` - The default, only chooses ubuntu-1404 and centos-7
342+
* List of box names, comma separated (e.g. `oel-7,fedora-26`) - Chooses exactly the boxes listed.
343+
* `linux-all` - All linux boxes.
344+
* `windows-all` - All Windows boxes. If there are any Windows boxes which do not
345+
have images available when this value is provided, the build will fail.
346+
* `all` - All boxes we test. If there are any boxes (e.g. Windows) which do not have images
347+
available when this value is provided, the build will fail.
348+
349+
For a complete list of boxes on which tests can be run, run `./gradlew :qa:vagrant:listAllBoxes`.
350+
For a list of boxes that have images available from your configuration, run
351+
`./gradlew :qa:vagrant:listAvailableBoxes`
352+
353+
Note that if you interrupt gradle in the middle of running these tasks, any boxes started
354+
will remain running and you'll have to stop them manually with `./gradlew stop` or
355+
`vagrant halt`.
342356

343357
All the regular vagrant commands should just work so you can get a shell in a
344358
VM running trusty by running
345359
`vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404`.
346360

347-
These are the linux flavors the Vagrantfile currently supports:
361+
These are the linux flavors supported, all of which we provide images for
348362

349363
* ubuntu-1404 aka trusty
350364
* ubuntu-1604 aka xenial
@@ -364,9 +378,42 @@ quality boxes available in vagrant atlas:
364378

365379
* sles-11
366380

367-
We're missing the following because our tests are very linux/bash centric:
381+
=== Testing packaging on Windows
382+
383+
The packaging tests also support Windows Server 2012R2 and Windows Server 2016.
384+
Unfortunately we're not able to provide boxes for them in open source use
385+
because of licensing issues. Any Virtualbox image that has WinRM and Powershell
386+
enabled for remote users should work.
387+
388+
Testing on Windows requires the https://github.com/criteo/vagrant-winrm[vagrant-winrm] plugin.
389+
390+
------------------------------------
391+
vagrant plugin install vagrant-winrm
392+
------------------------------------
393+
394+
Specify the image IDs of the Windows boxes to gradle with the following project
395+
properties. They can be set in `~/.gradle/gradle.properties` like
368396

369-
* Windows Server 2012
397+
------------------------------------
398+
vagrant.windows-2012r2.id=my-image-id
399+
vagrant.windows-2016.id=another-image-id
400+
------------------------------------
401+
402+
or passed on the command line like `-Pvagrant.windows-2012r2.id=my-image-id`
403+
`-Pvagrant.windows-2016=another-image-id`
404+
405+
These properties are required for Windows support in all gradle tasks that
406+
handle packaging tests. Either or both may be specified. Remember that to run tests
407+
on these boxes, the project property `vagrant.boxes` still needs to be set to a
408+
value that will include them.
409+
410+
If you're running vagrant commands outside of gradle, specify the Windows boxes
411+
with the environment variables
412+
413+
* `VAGRANT_WINDOWS_2012R2_BOX`
414+
* `VAGRANT_WINDOWS_2016_BOX`
415+
416+
=== Testing VMs are disposable
370417

371418
It's important to think of VMs like cattle. If they become lame you just shoot
372419
them and let vagrant reprovision them. Say you've hosed your precise VM:
@@ -399,54 +446,62 @@ vagrant destroy -f
399446
`vagrant up` would normally start all the VMs but we've prevented that because
400447
that'd consume a ton of ram.
401448

402-
== Testing scripts more directly
449+
=== Iterating on packaging tests
403450

404-
In general its best to stick to testing in vagrant because the bats scripts are
405-
destructive. When working with a single package it's generally faster to run its
406-
tests in a tighter loop than Gradle provides. In one window:
451+
Running the packaging tests through gradle can take a while because it will start
452+
and stop the VM each time. You can iterate faster by keeping the VM up and running
453+
the tests directly.
407454

408-
--------------------------------
409-
./gradlew :distribution:packages:rpm:assemble
410-
--------------------------------
455+
The packaging tests use a random seed to determine which past version to use for
456+
testing upgrades. To use a single past version fix the test seed when running
457+
the commands below (see <<Seed and repetitions.>>)
411458

412-
and in another window:
459+
First build the packaging tests and their dependencies
413460

414-
----------------------------------------------------
415-
vagrant up centos-7 --provider virtualbox && vagrant ssh centos-7
416-
cd $PACKAGING_ARCHIVES
417-
sudo -E bats $BATS_TESTS/*rpm*.bats
418-
----------------------------------------------------
461+
--------------------------------------------
462+
./gradlew :qa:vagrant:setupPackagingTest
463+
--------------------------------------------
419464

420-
If you wanted to retest all the release artifacts on a single VM you could:
465+
Then choose the VM you want to test on and bring it up. For example, to bring
466+
up Debian 9 use the gradle command below. Bringing the box up with vagrant directly
467+
may not mount the packaging test project in the right place. Once the VM is up, ssh
468+
into it
421469

422-
-------------------------------------------------
423-
./gradlew setupPackagingTest
424-
cd qa/vagrant; vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404
470+
--------------------------------------------
471+
./gradlew :qa:vagrant:vagrantDebian9#up
472+
vagrant ssh debian-9
473+
--------------------------------------------
474+
475+
Now inside the VM, to run the https://github.com/sstephenson/bats[bats] packaging tests
476+
477+
--------------------------------------------
425478
cd $PACKAGING_ARCHIVES
426-
sudo -E bats $BATS_TESTS/*.bats
427-
-------------------------------------------------
428479
429-
You can also use Gradle to prepare the test environment and then starts a single VM:
480+
# runs all bats tests
481+
sudo bats $BATS_TESTS/*.bats
430482
431-
-------------------------------------------------
432-
./gradlew vagrantFedora27#up
433-
-------------------------------------------------
483+
# you can also pass specific test files
484+
sudo bats $BATS_TESTS/20_tar_package.bats $BATS_TESTS/25_tar_plugins.bats
485+
--------------------------------------------
434486

435-
Or any of vagrantCentos6#up, vagrantCentos7#up, vagrantDebian8#up,
436-
vagrantDebian9#up, vagrantFedora26#up, vagrantFedora27#up, vagrantOel6#up, vagrantOel7#up,
437-
vagrantOpensuse42#up,vagrantSles12#up, vagrantUbuntu1404#up, vagrantUbuntu1604#up.
487+
To run the Java packaging tests, again inside the VM
438488

439-
Once up, you can then connect to the VM using SSH from the elasticsearch directory:
489+
--------------------------------------------
490+
bash $PACKAGING_TESTS/run-tests.sh
491+
--------------------------------------------
440492

441-
-------------------------------------------------
442-
vagrant ssh fedora-27
443-
-------------------------------------------------
493+
or on Windows
444494

445-
Or from another directory:
495+
--------------------------------------------
496+
powershell -File $Env:PACKAGING_TESTS/run-tests.ps1
497+
--------------------------------------------
446498

447-
-------------------------------------------------
448-
VAGRANT_CWD=/path/to/elasticsearch vagrant ssh fedora-27
449-
-------------------------------------------------
499+
When you've made changes you want to test, keep the VM up and reload the tests and
500+
distributions inside by running (on the host)
501+
502+
--------------------------------------------
503+
./gradlew :qa:vagrant:clean :qa:vagrant:setupPackagingTest
504+
--------------------------------------------
450505

451506
Note: Starting vagrant VM outside of the elasticsearch folder requires to
452507
indicates the folder that contains the Vagrantfile using the VAGRANT_CWD

Vagrantfile

+39
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ Vagrant.configure(2) do |config|
121121
sles_common config, box
122122
end
123123
end
124+
125+
windows_2012r2_box = ENV['VAGRANT_WINDOWS_2012R2_BOX']
126+
if windows_2012r2_box && windows_2012r2_box.empty? == false
127+
'windows-2012r2'.tap do |box|
128+
config.vm.define box, define_opts do |config|
129+
config.vm.box = windows_2012r2_box
130+
windows_common config, box
131+
end
132+
end
133+
end
134+
135+
windows_2016_box = ENV['VAGRANT_WINDOWS_2016_BOX']
136+
if windows_2016_box && windows_2016_box.empty? == false
137+
'windows-2016'.tap do |box|
138+
config.vm.define box, define_opts do |config|
139+
config.vm.box = windows_2016_box
140+
windows_common config, box
141+
end
142+
end
143+
end
124144
end
125145

126146
def deb_common(config, name, extra: '')
@@ -353,3 +373,22 @@ SUDOERS_VARS
353373
chmod 0440 /etc/sudoers.d/elasticsearch_vars
354374
SHELL
355375
end
376+
377+
def windows_common(config, name)
378+
config.vm.provision 'markerfile', type: 'shell', inline: <<-SHELL
379+
$ErrorActionPreference = "Stop"
380+
New-Item C:/is_vagrant_vm -ItemType file -Force | Out-Null
381+
SHELL
382+
383+
config.vm.provision 'set prompt', type: 'shell', inline: <<-SHELL
384+
$ErrorActionPreference = "Stop"
385+
$ps_prompt = 'function Prompt { "#{name}:$($ExecutionContext.SessionState.Path.CurrentLocation)>" }'
386+
$ps_prompt | Out-File $PsHome/Microsoft.PowerShell_profile.ps1
387+
SHELL
388+
389+
config.vm.provision 'set env variables', type: 'shell', inline: <<-SHELL
390+
$ErrorActionPreference = "Stop"
391+
[Environment]::SetEnvironmentVariable("PACKAGING_ARCHIVES", "C:/project/build/packaging/archives", "Machine")
392+
[Environment]::SetEnvironmentVariable("PACKAGING_TESTS", "C:/project/build/packaging/tests", "Machine")
393+
SHELL
394+
end

0 commit comments

Comments
 (0)