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.
|
|
|
|
*/
|
|
|
|
|
2015-11-05 15:47:54 -05:00
|
|
|
import org.elasticsearch.gradle.FileContentsTask
|
2015-12-18 15:43:47 -05:00
|
|
|
import org.elasticsearch.gradle.vagrant.BatsOverVagrantTask
|
|
|
|
import org.elasticsearch.gradle.vagrant.VagrantCommandTask
|
2015-11-02 12:40:47 -05:00
|
|
|
|
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'
|
2016-04-06 15:31:15 -04:00
|
|
|
|
|
|
|
// the images we allow testing with
|
|
|
|
List<String> availableBoxes = [
|
|
|
|
'centos-6',
|
|
|
|
'centos-7',
|
|
|
|
'debian-8',
|
2016-07-07 13:31:30 -04:00
|
|
|
'fedora-24',
|
2016-04-06 15:31:15 -04:00
|
|
|
'oel-6',
|
|
|
|
'oel-7',
|
|
|
|
'opensuse-13',
|
|
|
|
'sles-12',
|
|
|
|
'ubuntu-1204',
|
|
|
|
'ubuntu-1404',
|
2016-09-12 11:58:32 -04:00
|
|
|
'ubuntu-1604'
|
2016-03-18 13:33:58 -04:00
|
|
|
]
|
2015-11-05 15:47:54 -05:00
|
|
|
|
2016-06-27 12:13:06 -04:00
|
|
|
String vagrantBoxes = getProperties().get('vagrant.boxes', 'sample')
|
2016-04-06 15:31:15 -04:00
|
|
|
List<String> boxes = []
|
2016-06-27 12:13:06 -04:00
|
|
|
for (String box : vagrantBoxes.split(',')) {
|
2016-04-06 15:31:15 -04:00
|
|
|
if (box == 'sample') {
|
|
|
|
boxes.add('centos-7')
|
|
|
|
boxes.add('ubuntu-1404')
|
|
|
|
} else if (box == 'all') {
|
|
|
|
boxes = availableBoxes
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
if (availableBoxes.contains(box) == false) {
|
|
|
|
throw new IllegalArgumentException("Unknown vagrant box '${box}'")
|
|
|
|
}
|
|
|
|
boxes.add(box)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-27 12:13:06 -04:00
|
|
|
long seed
|
2016-06-29 14:18:25 -04:00
|
|
|
String formattedSeed = null
|
2016-06-27 12:13:06 -04:00
|
|
|
String[] upgradeFromVersions
|
|
|
|
String upgradeFromVersion
|
|
|
|
|
|
|
|
String maybeTestsSeed = System.getProperty("tests.seed", null);
|
|
|
|
if (maybeTestsSeed != null) {
|
2016-06-29 14:18:25 -04:00
|
|
|
List<String> seeds = maybeTestsSeed.tokenize(':')
|
|
|
|
if (seeds.size() != 0) {
|
|
|
|
String masterSeed = seeds.get(0)
|
|
|
|
seed = new BigInteger(masterSeed, 16).longValue()
|
|
|
|
formattedSeed = maybeTestsSeed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (formattedSeed == null) {
|
2016-06-27 12:13:06 -04:00
|
|
|
seed = new Random().nextLong()
|
|
|
|
formattedSeed = String.format("%016X", seed)
|
|
|
|
}
|
|
|
|
|
|
|
|
String maybeUpdradeFromVersions = System.getProperty("tests.packaging.upgrade.from.versions", null)
|
|
|
|
if (maybeUpdradeFromVersions != null) {
|
|
|
|
upgradeFromVersions = maybeUpdradeFromVersions.split(",")
|
|
|
|
} else {
|
|
|
|
upgradeFromVersions = new File(project.projectDir, 'versions')
|
|
|
|
}
|
|
|
|
|
|
|
|
upgradeFromVersion = upgradeFromVersions[new Random(seed).nextInt(upgradeFromVersions.length)]
|
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:')) {
|
2016-07-21 10:02:37 -04:00
|
|
|
test project(path: "${subproj.path}", configuration: 'zip')
|
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 clean(type: Delete) {
|
2015-11-05 15:47:54 -05:00
|
|
|
group 'Build'
|
2015-11-02 12:40:47 -05:00
|
|
|
delete buildDir
|
|
|
|
}
|
|
|
|
|
2016-04-06 17:14:46 -04:00
|
|
|
task stop {
|
|
|
|
group 'Verification'
|
|
|
|
description 'Stop any tasks from tests that still may be running'
|
|
|
|
}
|
|
|
|
|
2016-06-27 12:13:06 -04:00
|
|
|
Set<String> getVersions() {
|
|
|
|
Node xml
|
2016-09-12 19:48:12 -04:00
|
|
|
new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s ->
|
2016-06-27 12:13:06 -04:00
|
|
|
xml = new XmlParser().parse(s)
|
|
|
|
}
|
2016-09-13 11:52:06 -04:00
|
|
|
|
|
|
|
// List all N-1 releases from maven central
|
|
|
|
int major = Integer.parseInt(project.version.substring(0, project.version.indexOf('.'))) - 1
|
|
|
|
Set<String> versions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /$major\.\d\.\d/ })
|
|
|
|
if (versions.isEmpty() == false) {
|
|
|
|
return versions;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no version is found, we run the tests with the current version
|
|
|
|
return Collections.singleton(project.version);
|
2016-06-27 12:13:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
task updatePackagingTestUpgradeFromVersions {
|
2016-08-23 09:57:45 -04:00
|
|
|
group 'Verification'
|
|
|
|
description 'Update file containing options for the\n "starting" version in the "upgrade from" packaging tests.'
|
2016-06-27 12:13:06 -04:00
|
|
|
doLast {
|
|
|
|
Set<String> versions = getVersions()
|
|
|
|
new File(project.projectDir, 'versions').text = versions.join('\n') + '\n'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task verifyPackagingTestUpgradeFromVersions {
|
|
|
|
doLast {
|
|
|
|
String maybeUpdateFromVersions = System.getProperty("tests.packaging.upgrade.from.versions", null)
|
|
|
|
if (maybeUpdateFromVersions == null) {
|
|
|
|
Set<String> versions = getVersions()
|
|
|
|
Set<String> actualVersions = new HashSet<>(Arrays.asList(upgradeFromVersions))
|
|
|
|
if (!versions.equals(actualVersions)) {
|
|
|
|
throw new GradleException("out-of-date versions [" + actualVersions + "], expected [" + versions + "]; run gradle updatePackagingTestUpgradeFromVersions")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 15:47:54 -05:00
|
|
|
File testRoot = new File("$buildDir/testroot")
|
|
|
|
task createTestRoot {
|
2016-06-27 12:13:06 -04:00
|
|
|
dependsOn verifyPackagingTestUpgradeFromVersions
|
2015-11-05 15:47:54 -05:00
|
|
|
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
|
2016-06-27 12:34:10 -04:00
|
|
|
doFirst {
|
|
|
|
gradle.addBuildListener new BuildAdapter() {
|
|
|
|
@Override
|
|
|
|
void buildFinished(BuildResult result) {
|
|
|
|
if (result.failure) {
|
|
|
|
println "Reproduce with: gradle packagingTest -Pvagrant.boxes=${vagrantBoxes} -Dtests.seed=${formattedSeed} -Dtests.packaging.upgrade.from.versions=${upgradeFromVersions.join(",")}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
task checkVagrantVersion(type: Exec) {
|
|
|
|
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 {
|
2016-04-06 15:31:15 -04:00
|
|
|
group 'Verification'
|
|
|
|
description 'Smoke test the specified vagrant boxes'
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
|
|
|
|
2016-04-06 15:31:15 -04:00
|
|
|
task packagingTest {
|
|
|
|
group 'Verification'
|
|
|
|
description "Tests yum/apt packages using vagrant and bats.\n" +
|
|
|
|
" 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" +
|
2016-04-06 16:08:38 -04:00
|
|
|
" test all available boxes. The available boxes are: \n" +
|
|
|
|
" ${availableBoxes}"
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Each box gets it own set of tasks
|
2016-04-06 16:07:11 -04:00
|
|
|
for (String box : availableBoxes) {
|
2016-04-06 15:31:15 -04:00
|
|
|
String boxTask = box.capitalize().replace('-', '')
|
2016-04-06 16:07:11 -04:00
|
|
|
|
|
|
|
// always add a halt task for all boxes, so clean makes sure they are all shutdown
|
|
|
|
Task halt = tasks.create("vagrant${boxTask}#halt", VagrantCommandTask) {
|
|
|
|
boxName box
|
2016-05-04 20:29:23 -04:00
|
|
|
args 'halt', box
|
2016-04-06 16:07:11 -04:00
|
|
|
}
|
2016-04-06 17:14:46 -04:00
|
|
|
stop.dependsOn(halt)
|
2016-04-06 16:07:11 -04:00
|
|
|
if (boxes.contains(box) == false) {
|
|
|
|
// we only need a halt task if this box was not specified
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-29 11:04:54 -04:00
|
|
|
Task update = tasks.create("vagrant${boxTask}#update", VagrantCommandTask) {
|
|
|
|
boxName box
|
|
|
|
args 'box', 'update', box
|
|
|
|
dependsOn checkVagrantVersion
|
|
|
|
}
|
|
|
|
|
2016-04-06 15:31:15 -04:00
|
|
|
Task up = tasks.create("vagrant${boxTask}#up", VagrantCommandTask) {
|
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. */
|
2016-05-04 20:29:23 -04:00
|
|
|
args 'up', box, '--provision', '--provider', 'virtualbox'
|
2015-11-02 12:40:47 -05:00
|
|
|
/* 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! */
|
2016-06-29 11:04:54 -04:00
|
|
|
dependsOn update
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
|
|
|
|
2016-04-06 15:31:15 -04:00
|
|
|
Task smoke = tasks.create("vagrant${boxTask}#smoketest", Exec) {
|
|
|
|
dependsOn up
|
|
|
|
finalizedBy halt
|
2015-11-02 12:40:47 -05:00
|
|
|
commandLine 'vagrant', 'ssh', box, '--command',
|
2016-04-13 12:24:39 -04:00
|
|
|
"set -o pipefail && ${smokeTestCommand} | sed -ue 's/^/ ${box}: /'"
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|
2016-06-27 12:34:10 -04:00
|
|
|
vagrantSmokeTest.dependsOn(smoke)
|
2015-11-02 12:40:47 -05:00
|
|
|
|
2016-04-06 15:31:15 -04:00
|
|
|
Task packaging = tasks.create("packagingTest${boxTask}", BatsOverVagrantTask) {
|
|
|
|
dependsOn up
|
|
|
|
finalizedBy halt
|
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
|
|
|
}
|
2016-04-06 15:31:15 -04:00
|
|
|
packagingTest.dependsOn(packaging)
|
2015-11-02 12:40:47 -05:00
|
|
|
}
|