2015-11-02 12:40:47 -05:00
|
|
|
/*
|
|
|
|
* Licensed to Elasticsearch under one or more contributor
|
|
|
|
* license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright
|
|
|
|
* ownership. Elasticsearch licenses this file to you under
|
|
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import org.elasticsearch.gradle.vagrant.VagrantCommandTask
|
|
|
|
import org.elasticsearch.gradle.vagrant.BatsOverVagrantTask
|
2015-11-05 15:47:54 -05:00
|
|
|
import org.elasticsearch.gradle.FileContentsTask
|
2015-11-02 12:40:47 -05:00
|
|
|
import org.gradle.api.InvalidUserDataException
|
|
|
|
|
2015-11-05 15:47:54 -05:00
|
|
|
String testScripts = '*.bats'
|
|
|
|
String testCommand = "cd \$TESTROOT && sudo bats --tap \$BATS/$testScripts"
|
|
|
|
String smokeTestCommand = 'echo I work'
|
|
|
|
List<String> representativeBoxes = ['ubuntu-1404', 'centos-7']
|
|
|
|
List<String> boxes = representativeBoxes + ['ubuntu-1204', 'ubuntu-1504',
|
|
|
|
'debian-8', 'centos-6', 'oel-7', 'fedora-22', 'opensuse-13', 'sles-12']
|
|
|
|
|
|
|
|
/* The version of elasticsearch that we upgrade *from* as part of testing
|
|
|
|
* upgrades. */
|
|
|
|
String upgradeFromVersion = '2.0.0'
|
2015-11-02 12:40:47 -05:00
|
|
|
|
|
|
|
configurations {
|
|
|
|
test
|
|
|
|
}
|
|
|
|
|
2015-11-05 15:47:54 -05:00
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
|
|
|
}
|
|
|
|
|
2015-11-02 12:40:47 -05:00
|
|
|
dependencies {
|
2015-11-20 14:58:50 -05:00
|
|
|
test project(path: ':distribution:tar', configuration: 'archives')
|
|
|
|
test project(path: ':distribution:rpm', configuration: 'archives')
|
|
|
|
test project(path: ':distribution:deb', configuration: 'archives')
|
2015-11-05 15:47:54 -05:00
|
|
|
|
2015-11-02 12:40:47 -05:00
|
|
|
// Collect all the plugins
|
|
|
|
for (Project subproj : project.rootProject.subprojects) {
|
|
|
|
if (subproj.path.startsWith(':plugins:')) {
|
2015-11-20 14:58:50 -05:00
|
|
|
test project("${subproj.path}")
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 15:47:54 -05:00
|
|
|
|
|
|
|
// The version of elasticsearch that we upgrade *from*
|
|
|
|
test "org.elasticsearch.distribution.deb:elasticsearch:$upgradeFromVersion@deb"
|
|
|
|
test "org.elasticsearch.distribution.rpm:elasticsearch:$upgradeFromVersion@rpm"
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
task checkPackages {
|
|
|
|
group 'Verification'
|
|
|
|
description 'Check the packages against a representative sample of the ' +
|
|
|
|
'linux distributions we have in our Vagrantfile'
|
|
|
|
}
|
|
|
|
|
|
|
|
task checkPackagesAllDistros {
|
|
|
|
group 'Verification'
|
|
|
|
description 'Check the packages against all the linux distributions we ' +
|
|
|
|
'have in our Vagrantfile'
|
|
|
|
}
|
|
|
|
|
|
|
|
task clean(type: Delete) {
|
2015-11-05 15:47:54 -05:00
|
|
|
group 'Build'
|
2015-11-02 12:40:47 -05:00
|
|
|
delete buildDir
|
|
|
|
}
|
|
|
|
|
2015-11-05 15:47:54 -05:00
|
|
|
File testRoot = new File("$buildDir/testroot")
|
|
|
|
task createTestRoot {
|
|
|
|
outputs.dir testRoot
|
|
|
|
doLast {
|
|
|
|
testRoot.mkdirs()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task createVersionFile(type: FileContentsTask) {
|
|
|
|
dependsOn createTestRoot
|
|
|
|
file "${testRoot}/version"
|
|
|
|
contents = version
|
|
|
|
}
|
|
|
|
|
|
|
|
task createUpgradeFromFile(type: FileContentsTask) {
|
|
|
|
dependsOn createTestRoot
|
|
|
|
file "${testRoot}/upgrade_from_version"
|
|
|
|
contents = upgradeFromVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
task prepareTestRoot(type: Copy) {
|
|
|
|
description 'Dump bats test dependencies into the $TESTROOT'
|
|
|
|
into testRoot
|
2015-11-02 12:40:47 -05:00
|
|
|
from configurations.test
|
2015-11-05 15:47:54 -05:00
|
|
|
|
|
|
|
dependsOn createVersionFile, createUpgradeFromFile
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
task checkVagrantVersion(type: Exec) {
|
|
|
|
group 'Package Verification'
|
|
|
|
description 'Check that the version of vagrant is ok'
|
|
|
|
commandLine 'vagrant', '--version'
|
|
|
|
standardOutput = new ByteArrayOutputStream()
|
|
|
|
doLast {
|
2015-11-05 15:47:54 -05:00
|
|
|
String version = standardOutput.toString().trim()
|
2015-11-02 12:40:47 -05:00
|
|
|
if ((version ==~ /Vagrant 1\.[789]\..+/) == false) {
|
2015-11-05 15:47:54 -05:00
|
|
|
throw new InvalidUserDataException(
|
|
|
|
"Illegal version of vagrant [${version}]. Need [Vagrant 1.7+]")
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task vagrantSmokeTest {
|
|
|
|
group 'Vagrant'
|
|
|
|
description 'Smoke test some representative distros from the Vagrantfile'
|
|
|
|
}
|
|
|
|
|
|
|
|
task vagrantSmokeTestAllDistros {
|
|
|
|
group 'Vagrant'
|
|
|
|
description 'Smoke test all distros from the Vagrantfile'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each box gets it own set of tasks
|
|
|
|
boxes.each { box ->
|
2015-11-05 15:47:54 -05:00
|
|
|
String boxTask = taskifyBoxName box
|
|
|
|
task "vagrantUp${boxTask}"(type: VagrantCommandTask) {
|
2015-11-02 12:40:47 -05:00
|
|
|
group 'Vagrant'
|
2015-11-05 15:47:54 -05:00
|
|
|
description "Startup a vagrant VM running ${box}"
|
2015-11-02 12:40:47 -05:00
|
|
|
boxName box
|
|
|
|
/* Its important that we try to reprovision the box even if it already
|
|
|
|
exists. That way updates to the vagrant configuration take automatically.
|
|
|
|
That isn't to say that the updates will always be compatible. Its ok to
|
|
|
|
just destroy the boxes if they get busted but that is a manual step
|
|
|
|
because its slow-ish. */
|
|
|
|
/* We lock the provider to virtualbox because the Vagrantfile specifies
|
|
|
|
lots of boxes that only work properly in virtualbox. Virtualbox is
|
|
|
|
vagrant's default but its possible to change that default and folks do.
|
|
|
|
But the boxes that we use are unlikely to work properly with other
|
|
|
|
virtualization providers. Thus the lock. */
|
|
|
|
commandLine 'up', box, '--provision', '--provider', 'virtualbox'
|
|
|
|
/* It'd be possible to check if the box is already up here and output
|
|
|
|
SKIPPED but that would require running vagrant status which is slow! */
|
|
|
|
dependsOn checkVagrantVersion
|
|
|
|
}
|
2015-11-05 15:47:54 -05:00
|
|
|
task "vagrantHalt${boxTask}"(type: VagrantCommandTask) {
|
2015-11-02 12:40:47 -05:00
|
|
|
group 'Vagrant'
|
|
|
|
description "Shutdown the vagrant VM running $box"
|
|
|
|
boxName box
|
|
|
|
commandLine 'halt', box
|
|
|
|
}
|
|
|
|
|
2015-11-05 15:47:54 -05:00
|
|
|
task "smokeTest${boxTask}"(type: Exec) {
|
2015-11-02 12:40:47 -05:00
|
|
|
group 'Vagrant'
|
2015-11-05 15:47:54 -05:00
|
|
|
description "Smoke test the ${box} VM"
|
|
|
|
dependsOn "vagrantUp${boxTask}"
|
|
|
|
finalizedBy "vagrantHalt${boxTask}"
|
2015-11-02 12:40:47 -05:00
|
|
|
commandLine 'vagrant', 'ssh', box, '--command',
|
2015-11-05 15:47:54 -05:00
|
|
|
"set -o pipefail && ${smokeTestCommand} | sed -ue \'s/^/ ${box}: /'"
|
2015-11-02 12:40:47 -05:00
|
|
|
vagrantSmokeTestAllDistros.dependsOn name
|
|
|
|
if (representativeBoxes.contains(box)) {
|
|
|
|
vagrantSmokeTest.dependsOn name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 15:47:54 -05:00
|
|
|
task "check${boxTask}"(type: BatsOverVagrantTask) {
|
2015-11-02 12:40:47 -05:00
|
|
|
group 'Package Verification'
|
2015-11-05 15:47:54 -05:00
|
|
|
description "Run packaging tests against ${box}"
|
|
|
|
dependsOn "vagrantUp${boxTask}"
|
|
|
|
finalizedBy "vagrantHalt${boxTask}"
|
2015-11-02 12:40:47 -05:00
|
|
|
boxName box
|
|
|
|
command testCommand
|
2015-11-05 15:47:54 -05:00
|
|
|
dependsOn prepareTestRoot
|
2015-11-02 12:40:47 -05:00
|
|
|
checkPackagesAllDistros.dependsOn name
|
|
|
|
if (representativeBoxes.contains(box)) {
|
|
|
|
checkPackages.dependsOn name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Twists the box name into a sensible task name
|
2015-11-05 15:47:54 -05:00
|
|
|
String taskifyBoxName(box) {
|
2015-11-02 12:40:47 -05:00
|
|
|
box.capitalize().replace('-', '')
|
|
|
|
}
|