[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
This commit is contained in:
Andy Bristol 2018-05-16 16:42:08 -07:00 committed by GitHub
parent a4c9c2fa2a
commit 890afadb37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 332 additions and 125 deletions

View File

@ -303,15 +303,16 @@ comma separated list of nodes to connect to (e.g. localhost:9300). A transport c
be created based on that and used for all the before|after test operations, and to extract be created based on that and used for all the before|after test operations, and to extract
the http addresses of the nodes so that REST requests can be sent to them. the http addresses of the nodes so that REST requests can be sent to them.
== Testing scripts == Testing packaging
The simplest way to test scripts and the packaged distributions is to use The packaging tests use Vagrant virtual machines to verify that installing
Vagrant. You can get started by following there five easy steps: and running elasticsearch distributions works correctly on supported operating systems.
These tests should really only be run in vagrant vms because they're destructive.
. Install Virtual Box and Vagrant. . Install Virtual Box and Vagrant.
. (Optional) Install vagrant-cachier to squeeze a bit more performance out of . (Optional) Install https://github.com/fgrehm/vagrant-cachier[vagrant-cachier] to squeeze
the process: a bit more performance out of the process:
-------------------------------------- --------------------------------------
vagrant plugin install vagrant-cachier vagrant plugin install vagrant-cachier
@ -325,26 +326,39 @@ vagrant plugin install vagrant-cachier
. Download and smoke test the VMs with `./gradlew vagrantSmokeTest` or . Download and smoke test the VMs with `./gradlew vagrantSmokeTest` or
`./gradlew -Pvagrant.boxes=all vagrantSmokeTest`. The first time you run this it will `./gradlew -Pvagrant.boxes=all vagrantSmokeTest`. The first time you run this it will
download the base images and provision the boxes and immediately quit. If you download the base images and provision the boxes and immediately quit. Downloading all
you this again it'll skip the download step. the images may take a long time. After the images are already on your machine, they won't
be downloaded again unless they have been updated to a new version.
. Run the tests with `./gradlew packagingTest`. This will cause Gradle to build . Run the tests with `./gradlew packagingTest`. This will cause Gradle to build
the tar, zip, and deb packages and all the plugins. It will then run the tests the tar, zip, and deb packages and all the plugins. It will then run the tests
on ubuntu-1404 and centos-7. We chose those two distributions as the default on ubuntu-1404 and centos-7. We chose those two distributions as the default
because they cover deb and rpm packaging and SyvVinit and systemd. because they cover deb and rpm packaging and SyvVinit and systemd.
You can run on all the VMs by running `./gradlew -Pvagrant.boxes=all You can choose which boxes to test by setting the `-Pvagrant.boxes` project property. All of
packagingTest`. You can run a particular VM with a command like `./gradlew the valid options for this property are:
-Pvagrant.boxes=oel-7 packagingTest`. See `./gradlew tasks` for a complete list
of available vagrant boxes for testing. It's important to know that if you * `sample` - The default, only chooses ubuntu-1404 and centos-7
interrupt any of these Gradle commands then the boxes will remain running and * List of box names, comma separated (e.g. `oel-7,fedora-26`) - Chooses exactly the boxes listed.
you'll have to terminate them with `./gradlew stop`. * `linux-all` - All linux boxes.
* `windows-all` - All Windows boxes. If there are any Windows boxes which do not
have images available when this value is provided, the build will fail.
* `all` - All boxes we test. If there are any boxes (e.g. Windows) which do not have images
available when this value is provided, the build will fail.
For a complete list of boxes on which tests can be run, run `./gradlew :qa:vagrant:listAllBoxes`.
For a list of boxes that have images available from your configuration, run
`./gradlew :qa:vagrant:listAvailableBoxes`
Note that if you interrupt gradle in the middle of running these tasks, any boxes started
will remain running and you'll have to stop them manually with `./gradlew stop` or
`vagrant halt`.
All the regular vagrant commands should just work so you can get a shell in a All the regular vagrant commands should just work so you can get a shell in a
VM running trusty by running VM running trusty by running
`vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404`. `vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404`.
These are the linux flavors the Vagrantfile currently supports: These are the linux flavors supported, all of which we provide images for
* ubuntu-1404 aka trusty * ubuntu-1404 aka trusty
* ubuntu-1604 aka xenial * ubuntu-1604 aka xenial
@ -364,9 +378,42 @@ quality boxes available in vagrant atlas:
* sles-11 * sles-11
We're missing the following because our tests are very linux/bash centric: === Testing packaging on Windows
* Windows Server 2012 The packaging tests also support Windows Server 2012R2 and Windows Server 2016.
Unfortunately we're not able to provide boxes for them in open source use
because of licensing issues. Any Virtualbox image that has WinRM and Powershell
enabled for remote users should work.
Testing on Windows requires the https://github.com/criteo/vagrant-winrm[vagrant-winrm] plugin.
------------------------------------
vagrant plugin install vagrant-winrm
------------------------------------
Specify the image IDs of the Windows boxes to gradle with the following project
properties. They can be set in `~/.gradle/gradle.properties` like
------------------------------------
vagrant.windows-2012r2.id=my-image-id
vagrant.windows-2016.id=another-image-id
------------------------------------
or passed on the command line like `-Pvagrant.windows-2012r2.id=my-image-id`
`-Pvagrant.windows-2016=another-image-id`
These properties are required for Windows support in all gradle tasks that
handle packaging tests. Either or both may be specified. Remember that to run tests
on these boxes, the project property `vagrant.boxes` still needs to be set to a
value that will include them.
If you're running vagrant commands outside of gradle, specify the Windows boxes
with the environment variables
* `VAGRANT_WINDOWS_2012R2_BOX`
* `VAGRANT_WINDOWS_2016_BOX`
=== Testing VMs are disposable
It's important to think of VMs like cattle. If they become lame you just shoot It's important to think of VMs like cattle. If they become lame you just shoot
them and let vagrant reprovision them. Say you've hosed your precise VM: them and let vagrant reprovision them. Say you've hosed your precise VM:
@ -399,54 +446,62 @@ vagrant destroy -f
`vagrant up` would normally start all the VMs but we've prevented that because `vagrant up` would normally start all the VMs but we've prevented that because
that'd consume a ton of ram. that'd consume a ton of ram.
== Testing scripts more directly === Iterating on packaging tests
In general its best to stick to testing in vagrant because the bats scripts are Running the packaging tests through gradle can take a while because it will start
destructive. When working with a single package it's generally faster to run its and stop the VM each time. You can iterate faster by keeping the VM up and running
tests in a tighter loop than Gradle provides. In one window: the tests directly.
-------------------------------- The packaging tests use a random seed to determine which past version to use for
./gradlew :distribution:packages:rpm:assemble testing upgrades. To use a single past version fix the test seed when running
-------------------------------- the commands below (see <<Seed and repetitions.>>)
and in another window: First build the packaging tests and their dependencies
---------------------------------------------------- --------------------------------------------
vagrant up centos-7 --provider virtualbox && vagrant ssh centos-7 ./gradlew :qa:vagrant:setupPackagingTest
--------------------------------------------
Then choose the VM you want to test on and bring it up. For example, to bring
up Debian 9 use the gradle command below. Bringing the box up with vagrant directly
may not mount the packaging test project in the right place. Once the VM is up, ssh
into it
--------------------------------------------
./gradlew :qa:vagrant:vagrantDebian9#up
vagrant ssh debian-9
--------------------------------------------
Now inside the VM, to run the https://github.com/sstephenson/bats[bats] packaging tests
--------------------------------------------
cd $PACKAGING_ARCHIVES cd $PACKAGING_ARCHIVES
sudo -E bats $BATS_TESTS/*rpm*.bats
----------------------------------------------------
If you wanted to retest all the release artifacts on a single VM you could: # runs all bats tests
sudo bats $BATS_TESTS/*.bats
------------------------------------------------- # you can also pass specific test files
./gradlew setupPackagingTest sudo bats $BATS_TESTS/20_tar_package.bats $BATS_TESTS/25_tar_plugins.bats
cd qa/vagrant; vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404 --------------------------------------------
cd $PACKAGING_ARCHIVES
sudo -E bats $BATS_TESTS/*.bats
-------------------------------------------------
You can also use Gradle to prepare the test environment and then starts a single VM: To run the Java packaging tests, again inside the VM
------------------------------------------------- --------------------------------------------
./gradlew vagrantFedora27#up bash $PACKAGING_TESTS/run-tests.sh
------------------------------------------------- --------------------------------------------
Or any of vagrantCentos6#up, vagrantCentos7#up, vagrantDebian8#up, or on Windows
vagrantDebian9#up, vagrantFedora26#up, vagrantFedora27#up, vagrantOel6#up, vagrantOel7#up,
vagrantOpensuse42#up,vagrantSles12#up, vagrantUbuntu1404#up, vagrantUbuntu1604#up.
Once up, you can then connect to the VM using SSH from the elasticsearch directory: --------------------------------------------
powershell -File $Env:PACKAGING_TESTS/run-tests.ps1
--------------------------------------------
------------------------------------------------- When you've made changes you want to test, keep the VM up and reload the tests and
vagrant ssh fedora-27 distributions inside by running (on the host)
-------------------------------------------------
Or from another directory: --------------------------------------------
./gradlew :qa:vagrant:clean :qa:vagrant:setupPackagingTest
------------------------------------------------- --------------------------------------------
VAGRANT_CWD=/path/to/elasticsearch vagrant ssh fedora-27
-------------------------------------------------
Note: Starting vagrant VM outside of the elasticsearch folder requires to Note: Starting vagrant VM outside of the elasticsearch folder requires to
indicates the folder that contains the Vagrantfile using the VAGRANT_CWD indicates the folder that contains the Vagrantfile using the VAGRANT_CWD

39
Vagrantfile vendored
View File

@ -121,6 +121,26 @@ Vagrant.configure(2) do |config|
sles_common config, box sles_common config, box
end end
end end
windows_2012r2_box = ENV['VAGRANT_WINDOWS_2012R2_BOX']
if windows_2012r2_box && windows_2012r2_box.empty? == false
'windows-2012r2'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = windows_2012r2_box
windows_common config, box
end
end
end
windows_2016_box = ENV['VAGRANT_WINDOWS_2016_BOX']
if windows_2016_box && windows_2016_box.empty? == false
'windows-2016'.tap do |box|
config.vm.define box, define_opts do |config|
config.vm.box = windows_2016_box
windows_common config, box
end
end
end
end end
def deb_common(config, name, extra: '') def deb_common(config, name, extra: '')
@ -353,3 +373,22 @@ SUDOERS_VARS
chmod 0440 /etc/sudoers.d/elasticsearch_vars chmod 0440 /etc/sudoers.d/elasticsearch_vars
SHELL SHELL
end end
def windows_common(config, name)
config.vm.provision 'markerfile', type: 'shell', inline: <<-SHELL
$ErrorActionPreference = "Stop"
New-Item C:/is_vagrant_vm -ItemType file -Force | Out-Null
SHELL
config.vm.provision 'set prompt', type: 'shell', inline: <<-SHELL
$ErrorActionPreference = "Stop"
$ps_prompt = 'function Prompt { "#{name}:$($ExecutionContext.SessionState.Path.CurrentLocation)>" }'
$ps_prompt | Out-File $PsHome/Microsoft.PowerShell_profile.ps1
SHELL
config.vm.provision 'set env variables', type: 'shell', inline: <<-SHELL
$ErrorActionPreference = "Stop"
[Environment]::SetEnvironmentVariable("PACKAGING_ARCHIVES", "C:/project/build/packaging/archives", "Machine")
[Environment]::SetEnvironmentVariable("PACKAGING_TESTS", "C:/project/build/packaging/tests", "Machine")
SHELL
end

View File

@ -13,10 +13,12 @@ import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.Exec import org.gradle.api.tasks.Exec
import org.gradle.api.tasks.TaskState import org.gradle.api.tasks.TaskState
import static java.util.Collections.unmodifiableList
class VagrantTestPlugin implements Plugin<Project> { class VagrantTestPlugin implements Plugin<Project> {
/** All available boxes **/ /** All Linux boxes that we test. These are all always supplied **/
static List<String> BOXES = [ static final List<String> LINUX_BOXES = unmodifiableList([
'centos-6', 'centos-6',
'centos-7', 'centos-7',
'debian-8', 'debian-8',
@ -29,26 +31,35 @@ class VagrantTestPlugin implements Plugin<Project> {
'sles-12', 'sles-12',
'ubuntu-1404', 'ubuntu-1404',
'ubuntu-1604' 'ubuntu-1604'
] ])
/** All Windows boxes that we test, which may or may not be supplied **/
static final List<String> WINDOWS_BOXES = unmodifiableList([
'windows-2012r2',
'windows-2016'
])
/** All boxes that we test, some of which may not be supplied **/
static final List<String> ALL_BOXES = unmodifiableList(LINUX_BOXES + WINDOWS_BOXES)
/** Boxes used when sampling the tests **/ /** Boxes used when sampling the tests **/
static List<String> SAMPLE = [ static final List<String> SAMPLE = unmodifiableList([
'centos-7', 'centos-7',
'ubuntu-1404', 'ubuntu-1404'
] ])
/** All distributions to bring into test VM, whether or not they are used **/ /** All distributions to bring into test VM, whether or not they are used **/
static List<String> DISTRIBUTIONS = [ static final List<String> DISTRIBUTIONS = unmodifiableList([
'archives:tar', 'archives:tar',
'archives:oss-tar', 'archives:oss-tar',
'packages:rpm', 'packages:rpm',
'packages:oss-rpm', 'packages:oss-rpm',
'packages:deb', 'packages:deb',
'packages:oss-deb' 'packages:oss-deb'
] ])
/** Packages onboarded for upgrade tests **/ /** Packages onboarded for upgrade tests **/
static List<String> UPGRADE_FROM_ARCHIVES = ['rpm', 'deb'] static final List<String> UPGRADE_FROM_ARCHIVES = unmodifiableList(['rpm', 'deb'])
private static final PACKAGING_CONFIGURATION = 'packaging' private static final PACKAGING_CONFIGURATION = 'packaging'
private static final PACKAGING_TEST_CONFIGURATION = 'packagingTest' private static final PACKAGING_TEST_CONFIGURATION = 'packagingTest'
@ -56,11 +67,19 @@ class VagrantTestPlugin implements Plugin<Project> {
private static final String BATS_TEST_COMMAND ="cd \$PACKAGING_ARCHIVES && sudo bats --tap \$BATS_TESTS/*.$BATS" private static final String BATS_TEST_COMMAND ="cd \$PACKAGING_ARCHIVES && sudo bats --tap \$BATS_TESTS/*.$BATS"
private static final String PLATFORM_TEST_COMMAND ="rm -rf ~/elasticsearch && rsync -r /elasticsearch/ ~/elasticsearch && cd ~/elasticsearch && ./gradlew test integTest" private static final String PLATFORM_TEST_COMMAND ="rm -rf ~/elasticsearch && rsync -r /elasticsearch/ ~/elasticsearch && cd ~/elasticsearch && ./gradlew test integTest"
/** Boxes that have been supplied and are available for testing **/
List<String> availableBoxes = []
/** extra env vars to pass to vagrant for box configuration **/
Map<String, String> vagrantBoxEnvVars = [:]
@Override @Override
void apply(Project project) { void apply(Project project) {
collectAvailableBoxes(project)
// Creates the Vagrant extension for the project // Creates the Vagrant extension for the project
project.extensions.create('esvagrant', VagrantPropertiesExtension, listVagrantBoxes(project)) project.extensions.create('esvagrant', VagrantPropertiesExtension, listSelectedBoxes(project))
// Add required repositories for packaging tests // Add required repositories for packaging tests
configurePackagingArchiveRepositories(project) configurePackagingArchiveRepositories(project)
@ -73,12 +92,17 @@ class VagrantTestPlugin implements Plugin<Project> {
createVagrantTasks(project) createVagrantTasks(project)
if (project.extensions.esvagrant.boxes == null || project.extensions.esvagrant.boxes.size() == 0) { if (project.extensions.esvagrant.boxes == null || project.extensions.esvagrant.boxes.size() == 0) {
throw new InvalidUserDataException('Vagrant boxes cannot be null or empty for esvagrant') throw new InvalidUserDataException('Must specify at least one vagrant box')
} }
for (String box : project.extensions.esvagrant.boxes) { for (String box : project.extensions.esvagrant.boxes) {
if (BOXES.contains(box) == false) { if (ALL_BOXES.contains(box) == false) {
throw new InvalidUserDataException("Vagrant box [${box}] not found, available virtual machines are ${BOXES}") throw new InvalidUserDataException("Vagrant box [${box}] is unknown to this plugin. Valid boxes are ${ALL_BOXES}")
}
if (availableBoxes.contains(box) == false) {
throw new InvalidUserDataException("Vagrant box [${box}] is not available because an image is not supplied for it. " +
"Available boxes with supplied images are ${availableBoxes}")
} }
} }
@ -86,14 +110,45 @@ class VagrantTestPlugin implements Plugin<Project> {
createVagrantBoxesTasks(project) createVagrantBoxesTasks(project)
} }
private List<String> listVagrantBoxes(Project project) { /**
* Enumerate all the boxes that we know about and could possibly choose to test
*/
private void collectAvailableBoxes(Project project) {
// these images are hardcoded in the Vagrantfile and are always available
availableBoxes.addAll(LINUX_BOXES)
// these images need to be provided at runtime
String windows_2012r2_box = project.getProperties().get('vagrant.windows-2012r2.id')
if (windows_2012r2_box != null && windows_2012r2_box.isEmpty() == false) {
availableBoxes.add('windows-2012r2')
vagrantBoxEnvVars['VAGRANT_WINDOWS_2012R2_BOX'] = windows_2012r2_box
}
String windows_2016_box = project.getProperties().get('vagrant.windows-2016.id')
if (windows_2016_box != null && windows_2016_box.isEmpty() == false) {
availableBoxes.add('windows-2016')
vagrantBoxEnvVars['VAGRANT_WINDOWS_2016_BOX'] = windows_2016_box
}
}
/**
* Enumerate all the boxes that we have chosen to test
*/
private static List<String> listSelectedBoxes(Project project) {
String vagrantBoxes = project.getProperties().get('vagrant.boxes', 'sample') String vagrantBoxes = project.getProperties().get('vagrant.boxes', 'sample')
if (vagrantBoxes == 'sample') { switch (vagrantBoxes) {
return SAMPLE case 'sample':
} else if (vagrantBoxes == 'all') { return SAMPLE
return BOXES case 'linux-all':
} else { return LINUX_BOXES
return vagrantBoxes.split(',') case 'windows-all':
return WINDOWS_BOXES
case 'all':
return ALL_BOXES
case '':
return []
default:
return vagrantBoxes.split(',')
} }
} }
@ -184,11 +239,19 @@ class VagrantTestPlugin implements Plugin<Project> {
from project.configurations[PACKAGING_TEST_CONFIGURATION] from project.configurations[PACKAGING_TEST_CONFIGURATION]
} }
Task createTestRunnerScript = project.tasks.create('createTestRunnerScript', FileContentsTask) { Task createLinuxRunnerScript = project.tasks.create('createLinuxRunnerScript', FileContentsTask) {
dependsOn copyPackagingTests dependsOn copyPackagingTests
file "${testsDir}/run-tests.sh" file "${testsDir}/run-tests.sh"
contents "java -cp \"\$PACKAGING_TESTS/*\" org.junit.runner.JUnitCore ${-> project.extensions.esvagrant.testClass}" contents "java -cp \"\$PACKAGING_TESTS/*\" org.junit.runner.JUnitCore ${-> project.extensions.esvagrant.testClass}"
} }
Task createWindowsRunnerScript = project.tasks.create('createWindowsRunnerScript', FileContentsTask) {
dependsOn copyPackagingTests
file "${testsDir}/run-tests.ps1"
contents """\
java -cp "\$Env:PACKAGING_TESTS/*" org.junit.runner.JUnitCore ${-> project.extensions.esvagrant.testClass}
exit \$LASTEXITCODE
"""
}
Task createVersionFile = project.tasks.create('createVersionFile', FileContentsTask) { Task createVersionFile = project.tasks.create('createVersionFile', FileContentsTask) {
dependsOn copyPackagingArchives dependsOn copyPackagingArchives
@ -249,20 +312,24 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
Task vagrantSetUpTask = project.tasks.create('setupPackagingTest') Task vagrantSetUpTask = project.tasks.create('setupPackagingTest')
vagrantSetUpTask.dependsOn 'vagrantCheckVersion' vagrantSetUpTask.dependsOn(
vagrantSetUpTask.dependsOn copyPackagingArchives, copyPackagingTests, createTestRunnerScript 'vagrantCheckVersion',
vagrantSetUpTask.dependsOn createVersionFile, createUpgradeFromFile, createUpgradeIsOssFile copyPackagingArchives,
vagrantSetUpTask.dependsOn copyBatsTests, copyBatsUtils copyPackagingTests,
createLinuxRunnerScript,
createWindowsRunnerScript,
createVersionFile,
createUpgradeFromFile,
createUpgradeIsOssFile,
copyBatsTests,
copyBatsUtils
)
} }
private static void createPackagingTestTask(Project project) { private static void createPackagingTestTask(Project project) {
project.tasks.create('packagingTest') { project.tasks.create('packagingTest') {
group 'Verification' group 'Verification'
description "Tests yum/apt packages using vagrant and bats.\n" + description "Tests distribution installation on different platforms using vagrant. See TESTING.asciidoc for details."
" Specify the vagrant boxes to test using the gradle property 'vagrant.boxes'.\n" +
" 'sample' can be used to test a single yum and apt box. 'all' can be used to\n" +
" test all available boxes. The available boxes are: \n" +
" ${BOXES}"
dependsOn 'vagrantCheckVersion' dependsOn 'vagrantCheckVersion'
} }
} }
@ -270,24 +337,49 @@ class VagrantTestPlugin implements Plugin<Project> {
private static void createPlatformTestTask(Project project) { private static void createPlatformTestTask(Project project) {
project.tasks.create('platformTest') { project.tasks.create('platformTest') {
group 'Verification' group 'Verification'
description "Test unit and integ tests on different platforms using vagrant.\n" + description "Test unit and integ tests on different platforms using vagrant. See TESTING.asciidoc for details. This test " +
" Specify the vagrant boxes to test using the gradle property 'vagrant.boxes'.\n" + "is unmaintained."
" 'all' can be used to test all available boxes. The available boxes are: \n" +
" ${BOXES}"
dependsOn 'vagrantCheckVersion' dependsOn 'vagrantCheckVersion'
} }
} }
private static void createVagrantTasks(Project project) { private void createBoxListTasks(Project project) {
project.tasks.create('listAllBoxes') {
group 'Verification'
description 'List all vagrant boxes which can be tested by this plugin'
doLast {
println("All vagrant boxes supported by ${project.path}")
for (String box : ALL_BOXES) {
println(box)
}
}
dependsOn 'vagrantCheckVersion'
}
project.tasks.create('listAvailableBoxes') {
group 'Verification'
description 'List all vagrant boxes which are available for testing'
doLast {
println("All vagrant boxes available to ${project.path}")
for (String box : availableBoxes) {
println(box)
}
}
dependsOn 'vagrantCheckVersion'
}
}
private void createVagrantTasks(Project project) {
createCleanTask(project) createCleanTask(project)
createStopTask(project) createStopTask(project)
createSmokeTestTask(project) createSmokeTestTask(project)
createPrepareVagrantTestEnvTask(project) createPrepareVagrantTestEnvTask(project)
createPackagingTestTask(project) createPackagingTestTask(project)
createPlatformTestTask(project) createPlatformTestTask(project)
createBoxListTasks(project)
} }
private static void createVagrantBoxesTasks(Project project) { private void createVagrantBoxesTasks(Project project) {
assert project.extensions.esvagrant.boxes != null assert project.extensions.esvagrant.boxes != null
assert project.tasks.stop != null assert project.tasks.stop != null
@ -320,9 +412,10 @@ class VagrantTestPlugin implements Plugin<Project> {
'VAGRANT_VAGRANTFILE' : 'Vagrantfile', 'VAGRANT_VAGRANTFILE' : 'Vagrantfile',
'VAGRANT_PROJECT_DIR' : "${project.projectDir.absolutePath}" 'VAGRANT_PROJECT_DIR' : "${project.projectDir.absolutePath}"
] ]
vagrantEnvVars.putAll(vagrantBoxEnvVars)
// Each box gets it own set of tasks // Each box gets it own set of tasks
for (String box : BOXES) { for (String box : availableBoxes) {
String boxTask = box.capitalize().replace('-', '') String boxTask = box.capitalize().replace('-', '')
// always add a halt task for all boxes, so clean makes sure they are all shutdown // always add a halt task for all boxes, so clean makes sure they are all shutdown
@ -363,6 +456,7 @@ class VagrantTestPlugin implements Plugin<Project> {
final Task destroy = project.tasks.create("vagrant${boxTask}#destroy", LoggedExec) { final Task destroy = project.tasks.create("vagrant${boxTask}#destroy", LoggedExec) {
commandLine "bash", "-c", "vagrant status ${box} | grep -q \"${box}\\s\\+not created\" || vagrant destroy ${box} --force" commandLine "bash", "-c", "vagrant status ${box} | grep -q \"${box}\\s\\+not created\" || vagrant destroy ${box} --force"
workingDir project.rootProject.rootDir workingDir project.rootProject.rootDir
environment vagrantEnvVars
} }
destroy.onlyIf { vagrantDestroy } destroy.onlyIf { vagrantDestroy }
update.mustRunAfter(destroy) update.mustRunAfter(destroy)
@ -386,37 +480,42 @@ class VagrantTestPlugin implements Plugin<Project> {
environment vagrantEnvVars environment vagrantEnvVars
dependsOn up dependsOn up
finalizedBy halt finalizedBy halt
commandLine 'vagrant', 'ssh', box, '--command',
"set -o pipefail && echo 'Hello from ${project.path}' | sed -ue 's/^/ ${box}: /'"
} }
vagrantSmokeTest.dependsOn(smoke) vagrantSmokeTest.dependsOn(smoke)
if (LINUX_BOXES.contains(box)) {
Task batsPackagingTest = project.tasks.create("vagrant${boxTask}#batsPackagingTest", BatsOverVagrantTask) { smoke.commandLine = ['vagrant', 'ssh', box, '--command',
remoteCommand BATS_TEST_COMMAND "set -o pipefail && echo 'Hello from ${project.path}' | sed -ue 's/^/ ${box}: /'"]
boxName box } else {
environmentVars vagrantEnvVars smoke.commandLine = ['vagrant', 'winrm', box, '--command',
dependsOn up, setupPackagingTest "Write-Host ' ${box}: Hello from ${project.path}'"]
finalizedBy halt
} }
TaskExecutionAdapter batsPackagingReproListener = createReproListener(project, batsPackagingTest.path) if (LINUX_BOXES.contains(box)) {
batsPackagingTest.doFirst { Task batsPackagingTest = project.tasks.create("vagrant${boxTask}#batsPackagingTest", BatsOverVagrantTask) {
project.gradle.addListener(batsPackagingReproListener) remoteCommand BATS_TEST_COMMAND
} boxName box
batsPackagingTest.doLast { environmentVars vagrantEnvVars
project.gradle.removeListener(batsPackagingReproListener) dependsOn up, setupPackagingTest
} finalizedBy halt
if (project.extensions.esvagrant.boxes.contains(box)) { }
packagingTest.dependsOn(batsPackagingTest)
TaskExecutionAdapter batsPackagingReproListener = createReproListener(project, batsPackagingTest.path)
batsPackagingTest.doFirst {
project.gradle.addListener(batsPackagingReproListener)
}
batsPackagingTest.doLast {
project.gradle.removeListener(batsPackagingReproListener)
}
if (project.extensions.esvagrant.boxes.contains(box)) {
packagingTest.dependsOn(batsPackagingTest)
}
} }
Task javaPackagingTest = project.tasks.create("vagrant${boxTask}#javaPackagingTest", VagrantCommandTask) { Task javaPackagingTest = project.tasks.create("vagrant${boxTask}#javaPackagingTest", VagrantCommandTask) {
command 'ssh'
boxName box boxName box
environmentVars vagrantEnvVars environmentVars vagrantEnvVars
dependsOn up, setupPackagingTest dependsOn up, setupPackagingTest
finalizedBy halt finalizedBy halt
args '--command', "bash \"\$PACKAGING_TESTS/run-tests.sh\""
} }
// todo remove this onlyIf after all packaging tests are consolidated // todo remove this onlyIf after all packaging tests are consolidated
@ -424,6 +523,14 @@ class VagrantTestPlugin implements Plugin<Project> {
project.extensions.esvagrant.testClass != null project.extensions.esvagrant.testClass != null
} }
if (LINUX_BOXES.contains(box)) {
javaPackagingTest.command = 'ssh'
javaPackagingTest.args = ['--command', 'bash "$PACKAGING_TESTS/run-tests.sh"']
} else {
javaPackagingTest.command = 'winrm'
javaPackagingTest.args = ['--command', 'powershell -File "$Env:PACKAGING_TESTS/run-tests.ps1"']
}
TaskExecutionAdapter javaPackagingReproListener = createReproListener(project, javaPackagingTest.path) TaskExecutionAdapter javaPackagingReproListener = createReproListener(project, javaPackagingTest.path)
javaPackagingTest.doFirst { javaPackagingTest.doFirst {
project.gradle.addListener(javaPackagingReproListener) project.gradle.addListener(javaPackagingReproListener)
@ -435,23 +542,29 @@ class VagrantTestPlugin implements Plugin<Project> {
packagingTest.dependsOn(javaPackagingTest) packagingTest.dependsOn(javaPackagingTest)
} }
Task platform = project.tasks.create("vagrant${boxTask}#platformTest", VagrantCommandTask) { /*
command 'ssh' * This test is unmaintained and was created to run on Linux. We won't allow it to run on Windows
boxName box * until it's been brought back into maintenance
environmentVars vagrantEnvVars */
dependsOn up if (LINUX_BOXES.contains(box)) {
finalizedBy halt Task platform = project.tasks.create("vagrant${boxTask}#platformTest", VagrantCommandTask) {
args '--command', PLATFORM_TEST_COMMAND + " -Dtests.seed=${-> project.testSeed}" command 'ssh'
} boxName box
TaskExecutionAdapter platformReproListener = createReproListener(project, platform.path) environmentVars vagrantEnvVars
platform.doFirst { dependsOn up
project.gradle.addListener(platformReproListener) finalizedBy halt
} args '--command', PLATFORM_TEST_COMMAND + " -Dtests.seed=${-> project.testSeed}"
platform.doLast { }
project.gradle.removeListener(platformReproListener) TaskExecutionAdapter platformReproListener = createReproListener(project, platform.path)
} platform.doFirst {
if (project.extensions.esvagrant.boxes.contains(box)) { project.gradle.addListener(platformReproListener)
platformTest.dependsOn(platform) }
platform.doLast {
project.gradle.removeListener(platformReproListener)
}
if (project.extensions.esvagrant.boxes.contains(box)) {
platformTest.dependsOn(platform)
}
} }
} }
} }