Skip to content

Commit 414ce4e

Browse files
committed
[TEST] portable packaging test project + windows
This creates projects for new packaging tests written in groovy that can run on linux and windows, and adds awareness of windows boxes to the gradle build and Vagrantfile. No tests have been ported here, the groovy tests just exit immediately. Also creates the project :qa:packaging-common for code that should be shared between tests, e.g. the kind of content that lives in the utils/ portion of the bats tests. This is a separate project so that extra plugins' projects may depend on it without conflicting with the tests' project. The default is to not test on any windows boxes unless explicitly specified (we can't provide windows boxes) to gradle via project properties or to vagrant via environment variables. Once the bats tests in :qa:vagrant have all been migrated, that project can be deleted and the vagrant test plugin applied to :qa:packaging directly, making it serve as both the groovy build for the tests, and the tasks that setup the VMs the tests run on. For elastic#26741
1 parent 67cd1e9 commit 414ce4e

File tree

10 files changed

+1268
-282
lines changed

10 files changed

+1268
-282
lines changed

TESTING.asciidoc

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

305-
== Testing scripts
305+
== Testing distributions and packaging
306306

307-
The simplest way to test scripts and the packaged distributions is to use
308-
Vagrant. You can get started by following there five easy steps:
307+
The packaging tests use Vagrant virtual machines to verify that installing
308+
and running elasticsearch distributions works correctly on supported operating systems.
309+
These tests should really only be run in vagrant vms because they're destructive.
310+
311+
The existing packaging tests are written with https://github.com/sstephenson/bats[Bats]
312+
and run on Linux boxes. These tests are being ported to a Groovy project that will
313+
run on all boxes.
314+
315+
To set up your environment and run the packaging tests, follow these steps:
309316

310317
. Install Virtual Box and Vagrant.
311318

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

315322
--------------------------------------
316323
vagrant plugin install vagrant-cachier
@@ -322,10 +329,9 @@ vagrant plugin install vagrant-cachier
322329
gradle :qa:vagrant:vagrantCheckVersion
323330
-------------------------------------
324331

325-
. Download and smoke test the VMs with `gradle vagrantSmokeTest` or
326-
`gradle -Pvagrant.boxes=all vagrantSmokeTest`. The first time you run this it will
327-
download the base images and provision the boxes and immediately quit. If you
328-
you this again it'll skip the download step.
332+
. Download and smoke test the VMs with `gradle vagrantSmokeTest`. The first time
333+
you run this it will download the base images and provision the boxes and immediately
334+
quit. If run again it will use the boxes already downloaded.
329335

330336
. Run the tests with `gradle packagingTest`. This will cause gradle to build
331337
the tar, zip, and deb packages and all the plugins. It will then run the tests
@@ -343,7 +349,7 @@ All the regular vagrant commands should just work so you can get a shell in a
343349
VM running trusty by running
344350
`vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404`.
345351

346-
These are the linux flavors the Vagrantfile currently supports:
352+
These are the linux flavors supported, all of which have boxes provided
347353

348354
* ubuntu-1404 aka trusty
349355
* ubuntu-1604 aka xenial
@@ -363,12 +369,42 @@ quality boxes available in vagrant atlas:
363369

364370
* sles-11
365371

366-
We're missing the following because our tests are very linux/bash centric:
372+
=== Testing packaging on Windows
373+
374+
The packaging tests also support Windows Server 2012R2 and Windows Server 2016.
375+
Unfortunately we're not able to provide boxes for them in open source use
376+
because of licensing issues. Any Virtualbox image that has WinRM enabled
377+
for remote management and supports Powershell for remote users should work.
378+
379+
Testing on Windows requires the https://github.com/criteo/vagrant-winrm[vagrant-winrm] plugin.
380+
381+
------------------------------------
382+
vagrant plugin install vagrant-winrm
383+
------------------------------------
384+
385+
To specify the Windows boxes to use, pass the project properties to gradle:
386+
387+
* `-Pvagrant.windows.2012r2.box`
388+
* `-Pvagrant.windows.2016.box`
389+
390+
These properties are required for Windows support in all gradle tasks that
391+
handle packaging tests. Either or both may be specified. Remember that to run tests
392+
on these boxes, they still need to be included in the value of `-Pvagrant.boxes`.
393+
When these properties are present, passing `-Pvagrant.boxes=all` will include the
394+
Windows boxes. You can also use `-Pvagrant.boxes=windows-all` to only test on Windows boxes.
395+
396+
If running vagrant directly, pass the box names in the environment variables:
367397

368-
* Windows Server 2012
398+
* `VAGRANT_WINDOWS_2012R2_BOX`
399+
* `VAGRANT_WINDOWS_2016_BOX`
369400

370-
It's important to think of VMs like cattle. If they become lame you just shoot
371-
them and let vagrant reprovision them. Say you've hosed your precise VM:
401+
=== Testing VMs are disposable
402+
403+
If your testing VM gets into a bad state, just destroy it and let Vagrant
404+
create a new one. It only takes a minute or two and Vagrant handles all
405+
the provisioning for you.
406+
407+
Let's say you've hosed your Ubuntu Precise VM:
372408

373409
----------------------------------------------------
374410
vagrant ssh ubuntu-1404 -c 'sudo rm -rf /bin'; echo oops
@@ -380,9 +416,6 @@ All you've got to do to get another one is
380416
vagrant destroy -f ubuntu-1404 && vagrant up ubuntu-1404 --provider virtualbox
381417
----------------------------------------------
382418

383-
The whole process takes a minute and a half on a modern laptop, two and a half
384-
without vagrant-cachier.
385-
386419
Its possible that some downloads will fail and it'll be impossible to restart
387420
them. This is a bug in vagrant. See the instructions here for how to work
388421
around it:
@@ -398,58 +431,72 @@ vagrant destroy -f
398431
`vagrant up` would normally start all the VMs but we've prevented that because
399432
that'd consume a ton of ram.
400433

401-
== Testing scripts more directly
434+
=== Running packaging tests more directly
402435

403-
In general its best to stick to testing in vagrant because the bats scripts are
404-
destructive. When working with a single package it's generally faster to run its
405-
tests in a tighter loop than gradle provides. In one window:
436+
Gradle's full packaging test build takes a while, but you can iterate faster
437+
by managing the VM and running the tests yourself.
438+
439+
To get the build ready for the packaging tests, run (on the host)
406440

407441
--------------------------------
408-
gradle :distribution:rpm:assemble
442+
gradle :qa:vagrant:setupPackaging :qa:vagrant:prepareGradleBuild
409443
--------------------------------
410444

411-
and in another window:
445+
and in another window, run the gradle task to bring up the VM. In this
446+
example let's test on Centos 7
447+
448+
-------------------------------------------------
449+
gradle :qa:vagrant:vagrantCentos7#up
450+
-------------------------------------------------
451+
452+
This task is available for all boxes specified with `-Pvagrant.boxes` -
453+
to see what's available, run `gradle :qa:vagrant:tasks --all`.
454+
455+
Then in another terminal, ssh into the VM
456+
457+
----------------------------------------------------
458+
vagrant ssh centos-7
459+
----------------------------------------------------
460+
461+
To run the Bats tests for just the RPM package (on the guest)
412462

413463
----------------------------------------------------
414-
vagrant up centos-7 --provider virtualbox && vagrant ssh centos-7
415464
cd $BATS_ARCHIVES
416465
sudo -E bats $BATS_TESTS/*rpm*.bats
417466
----------------------------------------------------
418467

419-
If you wanted to retest all the release artifacts on a single VM you could:
468+
Or to retest all the release artifacts on a single VM (on the guest)
420469

421470
-------------------------------------------------
422-
gradle setupBats
423-
cd qa/vagrant; vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404
424471
cd $BATS_ARCHIVES
425472
sudo -E bats $BATS_TESTS/*.bats
426473
-------------------------------------------------
427474

428-
You can also use Gradle to prepare the test environment and then starts a single VM:
429-
430-
-------------------------------------------------
431-
gradle vagrantFedora27#up
432-
-------------------------------------------------
433-
434-
Or any of vagrantCentos6#up, vagrantCentos7#up, vagrantDebian8#up,
435-
vagrantDebian9#up, vagrantFedora26#up, vagrantFedora27#up, vagrantOel6#up, vagrantOel7#up,
436-
vagrantOpensuse42#up,vagrantSles12#up, vagrantUbuntu1404#up, vagrantUbuntu1604#up.
437-
438-
Once up, you can then connect to the VM using SSH from the elasticsearch directory:
475+
To run the Groovy packaging tests, run (on the guest)
439476

440-
-------------------------------------------------
441-
vagrant ssh fedora-27
442-
-------------------------------------------------
443-
444-
Or from another directory:
445-
446-
-------------------------------------------------
447-
VAGRANT_CWD=/path/to/elasticsearch vagrant ssh fedora-27
448-
-------------------------------------------------
477+
------------------------------------------------
478+
cd ~/.elasticsearch && gradle :qa:packaging:run
479+
------------------------------------------------
449480

450-
Note: Starting vagrant VM outside of the elasticsearch folder requires to
451-
indicates the folder that contains the Vagrantfile using the VAGRANT_CWD
452-
environment variable.
481+
=== Testing plugins in packaging tests
482+
483+
If you're building plugins in an `elasticsearch-extra` directory, the Vagrantfile
484+
will mount that directory to the VM so it's included in the VM's gradle build. If
485+
your plugin's build needs some additional setup steps before it runs, you can add
486+
task dependencies to the `#prepareGradleBuild` tasks. For example
487+
488+
[source, groovy]
489+
----------------------------------------
490+
project(':qa:vagrant).tasks.findAll { t -> t.name.endsWith('prepareGradleBuild') }.each { task ->
491+
Task myPluginSetupTask = project.tasks.create(task.replace('prepareGradleBuild, 'mySetup')) {
492+
doLast {
493+
String vagrantBox = task.ext.box
494+
// vagrant command to setup box
495+
}
496+
}
497+
task.dependsOn(myPluginSetupTask)
498+
}
499+
----------------------------------------
453500

454501
== Testing backwards compatibility
455502

0 commit comments

Comments
 (0)