[test] packaging: gradle tasks for groovy tests (#29046)

The vagrant test plugin adds tasks for the groovy packaging tests,
which run after the bats packaging test tasks.Rename the 'bats'
configuration to 'packaging' and remove the option to inherit
archives from this configuration.
This commit is contained in:
Andy Bristol 2018-03-26 13:43:09 -07:00 committed by GitHub
parent 87957603c0
commit 7bf9091942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 96 deletions

View File

@ -414,16 +414,16 @@ and in another window:
---------------------------------------------------- ----------------------------------------------------
vagrant up centos-7 --provider virtualbox && vagrant ssh centos-7 vagrant up centos-7 --provider virtualbox && vagrant ssh centos-7
cd $BATS_ARCHIVES cd $PACKAGING_ARCHIVES
sudo -E bats $BATS_TESTS/*rpm*.bats sudo -E bats $BATS_TESTS/*rpm*.bats
---------------------------------------------------- ----------------------------------------------------
If you wanted to retest all the release artifacts on a single VM you could: If you wanted to retest all the release artifacts on a single VM you could:
------------------------------------------------- -------------------------------------------------
./gradlew setupBats ./gradlew setupPackagingTest
cd qa/vagrant; vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404 cd qa/vagrant; vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404
cd $BATS_ARCHIVES cd $PACKAGING_ARCHIVES
sudo -E bats $BATS_TESTS/*.bats sudo -E bats $BATS_TESTS/*.bats
------------------------------------------------- -------------------------------------------------

8
Vagrantfile vendored
View File

@ -334,9 +334,9 @@ export TAR=/elasticsearch/distribution/tar/build/distributions
export RPM=/elasticsearch/distribution/rpm/build/distributions export RPM=/elasticsearch/distribution/rpm/build/distributions
export DEB=/elasticsearch/distribution/deb/build/distributions export DEB=/elasticsearch/distribution/deb/build/distributions
export BATS=/project/build/bats export BATS=/project/build/bats
export BATS_UTILS=/project/build/bats/utils export BATS_UTILS=/project/build/packaging/bats/utils
export BATS_TESTS=/project/build/bats/tests export BATS_TESTS=/project/build/packaging/bats/tests
export BATS_ARCHIVES=/project/build/bats/archives export PACKAGING_ARCHIVES=/project/build/packaging/archives
VARS VARS
cat \<\<SUDOERS_VARS > /etc/sudoers.d/elasticsearch_vars cat \<\<SUDOERS_VARS > /etc/sudoers.d/elasticsearch_vars
Defaults env_keep += "ZIP" Defaults env_keep += "ZIP"
@ -346,7 +346,7 @@ Defaults env_keep += "DEB"
Defaults env_keep += "BATS" Defaults env_keep += "BATS"
Defaults env_keep += "BATS_UTILS" Defaults env_keep += "BATS_UTILS"
Defaults env_keep += "BATS_TESTS" Defaults env_keep += "BATS_TESTS"
Defaults env_keep += "BATS_ARCHIVES" Defaults env_keep += "PACKAGING_ARCHIVES"
SUDOERS_VARS SUDOERS_VARS
chmod 0440 /etc/sudoers.d/elasticsearch_vars chmod 0440 /etc/sudoers.d/elasticsearch_vars
SHELL SHELL

View File

@ -37,9 +37,6 @@ class VagrantPropertiesExtension {
@Input @Input
Boolean inheritTests Boolean inheritTests
@Input
Boolean inheritTestArchives
@Input @Input
Boolean inheritTestUtils Boolean inheritTestUtils
@ -60,10 +57,6 @@ class VagrantPropertiesExtension {
this.inheritTests = inheritTests this.inheritTests = inheritTests
} }
void setInheritTestArchives(Boolean inheritTestArchives) {
this.inheritTestArchives = inheritTestArchives
}
void setInheritTestUtils(Boolean inheritTestUtils) { void setInheritTestUtils(Boolean inheritTestUtils) {
this.inheritTestUtils = inheritTestUtils this.inheritTestUtils = inheritTestUtils
} }

View File

@ -1,6 +1,5 @@
package org.elasticsearch.gradle.vagrant package org.elasticsearch.gradle.vagrant
import com.carrotsearch.gradle.junit4.RandomizedTestingPlugin
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import org.elasticsearch.gradle.FileContentsTask import org.elasticsearch.gradle.FileContentsTask
import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.LoggedExec
@ -43,8 +42,9 @@ class VagrantTestPlugin implements Plugin<Project> {
/** Packages onboarded for upgrade tests **/ /** Packages onboarded for upgrade tests **/
static List<String> UPGRADE_FROM_ARCHIVES = ['rpm', 'deb'] static List<String> UPGRADE_FROM_ARCHIVES = ['rpm', 'deb']
private static final PACKAGING_CONFIGURATION = 'packaging'
private static final BATS = 'bats' private static final BATS = 'bats'
private static final String BATS_TEST_COMMAND ="cd \$BATS_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"
@Override @Override
@ -53,11 +53,11 @@ class VagrantTestPlugin implements Plugin<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, listVagrantBoxes(project))
// Add required repositories for Bats tests // Add required repositories for packaging tests
configureBatsRepositories(project) configurePackagingArchiveRepositories(project)
// Creates custom configurations for Bats testing files (and associated scripts and archives) // Creates custom configurations for Bats testing files (and associated scripts and archives)
createBatsConfiguration(project) createPackagingConfiguration(project)
// Creates all the main Vagrant tasks // Creates all the main Vagrant tasks
createVagrantTasks(project) createVagrantTasks(project)
@ -87,7 +87,7 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
} }
private static void configureBatsRepositories(Project project) { private static void configurePackagingArchiveRepositories(Project project) {
RepositoryHandler repos = project.repositories RepositoryHandler repos = project.repositories
// Try maven central first, it'll have releases before 5.0.0 // Try maven central first, it'll have releases before 5.0.0
@ -102,10 +102,10 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
} }
private static void createBatsConfiguration(Project project) { private static void createPackagingConfiguration(Project project) {
project.configurations.create(BATS) project.configurations.create(PACKAGING_CONFIGURATION)
String upgradeFromVersion = System.getProperty("tests.packaging.upgradeVersion"); String upgradeFromVersion = System.getProperty("tests.packaging.upgradeVersion")
if (upgradeFromVersion == null) { if (upgradeFromVersion == null) {
String firstPartOfSeed = project.rootProject.testSeed.tokenize(':').get(0) String firstPartOfSeed = project.rootProject.testSeed.tokenize(':').get(0)
final long seed = Long.parseUnsignedLong(firstPartOfSeed, 16) final long seed = Long.parseUnsignedLong(firstPartOfSeed, 16)
@ -120,12 +120,14 @@ class VagrantTestPlugin implements Plugin<Project> {
} else { } else {
it = "packages:${it}" it = "packages:${it}"
} }
project.dependencies.add(BATS, project.dependencies.project(path: ":distribution:${it}", configuration: 'default')) project.dependencies.add(PACKAGING_CONFIGURATION,
project.dependencies.project(path: ":distribution:${it}", configuration: 'default'))
} }
UPGRADE_FROM_ARCHIVES.each { UPGRADE_FROM_ARCHIVES.each {
// The version of elasticsearch that we upgrade *from* // The version of elasticsearch that we upgrade *from*
project.dependencies.add(BATS, "org.elasticsearch.distribution.${it}:elasticsearch:${upgradeFromVersion}@${it}") project.dependencies.add(PACKAGING_CONFIGURATION,
"org.elasticsearch.distribution.${it}:elasticsearch:${upgradeFromVersion}@${it}")
} }
project.extensions.esvagrant.upgradeFromVersion = upgradeFromVersion project.extensions.esvagrant.upgradeFromVersion = upgradeFromVersion
@ -154,22 +156,28 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
private static void createPrepareVagrantTestEnvTask(Project project) { private static void createPrepareVagrantTestEnvTask(Project project) {
File batsDir = new File("${project.buildDir}/${BATS}") File packagingDir = new File(project.buildDir, PACKAGING_CONFIGURATION)
Task createBatsDirsTask = project.tasks.create('createBatsDirs') File archivesDir = new File(packagingDir, 'archives')
createBatsDirsTask.outputs.dir batsDir Copy copyPackagingArchives = project.tasks.create('copyPackagingArchives', Copy) {
createBatsDirsTask.doLast { into archivesDir
batsDir.mkdirs() from project.configurations[PACKAGING_CONFIGURATION]
} }
Copy copyBatsArchives = project.tasks.create('copyBatsArchives', Copy) { Task createVersionFile = project.tasks.create('createVersionFile', FileContentsTask) {
dependsOn createBatsDirsTask dependsOn copyPackagingArchives
into "${batsDir}/archives" file "${archivesDir}/version"
from project.configurations[BATS] contents project.version
} }
Task createUpgradeFromFile = project.tasks.create('createUpgradeFromFile', FileContentsTask) {
dependsOn copyPackagingArchives
file "${archivesDir}/upgrade_from_version"
contents project.extensions.esvagrant.upgradeFromVersion
}
File batsDir = new File(packagingDir, BATS)
Copy copyBatsTests = project.tasks.create('copyBatsTests', Copy) { Copy copyBatsTests = project.tasks.create('copyBatsTests', Copy) {
dependsOn createBatsDirsTask
into "${batsDir}/tests" into "${batsDir}/tests"
from { from {
"${project.extensions.esvagrant.batsDir}/tests" "${project.extensions.esvagrant.batsDir}/tests"
@ -177,7 +185,6 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
Copy copyBatsUtils = project.tasks.create('copyBatsUtils', Copy) { Copy copyBatsUtils = project.tasks.create('copyBatsUtils', Copy) {
dependsOn createBatsDirsTask
into "${batsDir}/utils" into "${batsDir}/utils"
from { from {
"${project.extensions.esvagrant.batsDir}/utils" "${project.extensions.esvagrant.batsDir}/utils"
@ -185,9 +192,11 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
// Now we iterate over dependencies of the bats configuration. When a project dependency is found, // Now we iterate over dependencies of the bats configuration. When a project dependency is found,
// we bring back its own archives, test files or test utils. // we bring back its test files or test utils.
project.afterEvaluate { project.afterEvaluate {
project.configurations.bats.dependencies.findAll {it.targetConfiguration == BATS }.each { d -> project.configurations[PACKAGING_CONFIGURATION].dependencies
.findAll {it.targetConfiguration == PACKAGING_CONFIGURATION }
.each { d ->
if (d instanceof DefaultProjectDependency) { if (d instanceof DefaultProjectDependency) {
DefaultProjectDependency externalBatsDependency = (DefaultProjectDependency) d DefaultProjectDependency externalBatsDependency = (DefaultProjectDependency) d
Project externalBatsProject = externalBatsDependency.dependencyProject Project externalBatsProject = externalBatsDependency.dependencyProject
@ -196,9 +205,6 @@ class VagrantTestPlugin implements Plugin<Project> {
if (project.extensions.esvagrant.inheritTests) { if (project.extensions.esvagrant.inheritTests) {
copyBatsTests.from(externalBatsProject.files("${externalBatsDir}/tests")) copyBatsTests.from(externalBatsProject.files("${externalBatsDir}/tests"))
} }
if (project.extensions.esvagrant.inheritTestArchives) {
copyBatsArchives.from(externalBatsDependency.projectConfiguration.files)
}
if (project.extensions.esvagrant.inheritTestUtils) { if (project.extensions.esvagrant.inheritTestUtils) {
copyBatsUtils.from(externalBatsProject.files("${externalBatsDir}/utils")) copyBatsUtils.from(externalBatsProject.files("${externalBatsDir}/utils"))
} }
@ -206,21 +212,10 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
} }
Task createVersionFile = project.tasks.create('createVersionFile', FileContentsTask) { Task vagrantSetUpTask = project.tasks.create('setupPackagingTest')
dependsOn createBatsDirsTask
file "${batsDir}/archives/version"
contents project.version
}
Task createUpgradeFromFile = project.tasks.create('createUpgradeFromFile', FileContentsTask) {
dependsOn createBatsDirsTask
file "${batsDir}/archives/upgrade_from_version"
contents project.extensions.esvagrant.upgradeFromVersion
}
Task vagrantSetUpTask = project.tasks.create('setupBats')
vagrantSetUpTask.dependsOn 'vagrantCheckVersion' vagrantSetUpTask.dependsOn 'vagrantCheckVersion'
vagrantSetUpTask.dependsOn copyBatsTests, copyBatsUtils, copyBatsArchives, createVersionFile, createUpgradeFromFile vagrantSetUpTask.dependsOn copyPackagingArchives, createVersionFile, createUpgradeFromFile
vagrantSetUpTask.dependsOn copyBatsTests, copyBatsUtils
} }
private static void createPackagingTestTask(Project project) { private static void createPackagingTestTask(Project project) {
@ -270,8 +265,8 @@ class VagrantTestPlugin implements Plugin<Project> {
assert project.tasks.virtualboxCheckVersion != null assert project.tasks.virtualboxCheckVersion != null
Task virtualboxCheckVersion = project.tasks.virtualboxCheckVersion Task virtualboxCheckVersion = project.tasks.virtualboxCheckVersion
assert project.tasks.setupBats != null assert project.tasks.setupPackagingTest != null
Task setupBats = project.tasks.setupBats Task setupPackagingTest = project.tasks.setupPackagingTest
assert project.tasks.packagingTest != null assert project.tasks.packagingTest != null
Task packagingTest = project.tasks.packagingTest Task packagingTest = project.tasks.packagingTest
@ -308,7 +303,7 @@ class VagrantTestPlugin implements Plugin<Project> {
environmentVars vagrantEnvVars environmentVars vagrantEnvVars
dependsOn vagrantCheckVersion, virtualboxCheckVersion dependsOn vagrantCheckVersion, virtualboxCheckVersion
} }
update.mustRunAfter(setupBats) update.mustRunAfter(setupPackagingTest)
/* /*
* Destroying before every execution can be annoying while iterating on tests locally. Therefore, we provide a flag * Destroying before every execution can be annoying while iterating on tests locally. Therefore, we provide a flag
@ -359,32 +354,39 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
vagrantSmokeTest.dependsOn(smoke) vagrantSmokeTest.dependsOn(smoke)
Task packaging = project.tasks.create("vagrant${boxTask}#packagingTest", BatsOverVagrantTask) { Task batsPackagingTest = project.tasks.create("vagrant${boxTask}#batsPackagingTest", BatsOverVagrantTask) {
remoteCommand BATS_TEST_COMMAND remoteCommand BATS_TEST_COMMAND
boxName box boxName box
environmentVars vagrantEnvVars environmentVars vagrantEnvVars
dependsOn up, setupBats dependsOn up, setupPackagingTest
finalizedBy halt finalizedBy halt
} }
TaskExecutionAdapter packagingReproListener = new TaskExecutionAdapter() { TaskExecutionAdapter batsPackagingReproListener = createReproListener(project, batsPackagingTest.path)
@Override batsPackagingTest.doFirst {
void afterExecute(Task task, TaskState state) { project.gradle.addListener(batsPackagingReproListener)
final String gradlew = Os.isFamily(Os.FAMILY_WINDOWS) ? "gradlew" : "./gradlew"
if (state.failure != null) {
println "REPRODUCE WITH: ${gradlew} ${packaging.path} " +
"-Dtests.seed=${project.testSeed} "
} }
} batsPackagingTest.doLast {
} project.gradle.removeListener(batsPackagingReproListener)
packaging.doFirst {
project.gradle.addListener(packagingReproListener)
}
packaging.doLast {
project.gradle.removeListener(packagingReproListener)
} }
if (project.extensions.esvagrant.boxes.contains(box)) { if (project.extensions.esvagrant.boxes.contains(box)) {
packagingTest.dependsOn(packaging) packagingTest.dependsOn(batsPackagingTest)
}
// This task doesn't do anything yet. In the future it will execute a jar containing tests on the vm
Task groovyPackagingTest = project.tasks.create("vagrant${boxTask}#groovyPackagingTest")
groovyPackagingTest.dependsOn(up)
groovyPackagingTest.finalizedBy(halt)
TaskExecutionAdapter groovyPackagingReproListener = createReproListener(project, groovyPackagingTest.path)
groovyPackagingTest.doFirst {
project.gradle.addListener(groovyPackagingReproListener)
}
groovyPackagingTest.doLast {
project.gradle.removeListener(groovyPackagingReproListener)
}
if (project.extensions.esvagrant.boxes.contains(box)) {
packagingTest.dependsOn(groovyPackagingTest)
} }
Task platform = project.tasks.create("vagrant${boxTask}#platformTest", VagrantCommandTask) { Task platform = project.tasks.create("vagrant${boxTask}#platformTest", VagrantCommandTask) {
@ -395,15 +397,7 @@ class VagrantTestPlugin implements Plugin<Project> {
finalizedBy halt finalizedBy halt
args '--command', PLATFORM_TEST_COMMAND + " -Dtests.seed=${-> project.testSeed}" args '--command', PLATFORM_TEST_COMMAND + " -Dtests.seed=${-> project.testSeed}"
} }
TaskExecutionAdapter platformReproListener = new TaskExecutionAdapter() { TaskExecutionAdapter platformReproListener = createReproListener(project, platform.path)
@Override
void afterExecute(Task task, TaskState state) {
if (state.failure != null) {
println "REPRODUCE WITH: gradle ${platform.path} " +
"-Dtests.seed=${project.testSeed} "
}
}
}
platform.doFirst { platform.doFirst {
project.gradle.addListener(platformReproListener) project.gradle.addListener(platformReproListener)
} }
@ -415,4 +409,16 @@ class VagrantTestPlugin implements Plugin<Project> {
} }
} }
} }
private static TaskExecutionAdapter createReproListener(Project project, String reproTaskPath) {
return new TaskExecutionAdapter() {
@Override
void afterExecute(Task task, TaskState state) {
final String gradlew = Os.isFamily(Os.FAMILY_WINDOWS) ? "gradlew" : "./gradlew"
if (state.failure != null) {
println "REPRODUCE WITH: ${gradlew} ${reproTaskPath} -Dtests.seed=${project.testSeed} "
}
}
}
}
} }

View File

@ -25,14 +25,14 @@ for (Project subproj : project.rootProject.subprojects) {
if (subproj.path.startsWith(':plugins:') || subproj.path.equals(':example-plugins:custom-settings')) { if (subproj.path.startsWith(':plugins:') || subproj.path.equals(':example-plugins:custom-settings')) {
// add plugin as a dep // add plugin as a dep
dependencies { dependencies {
bats project(path: "${subproj.path}", configuration: 'zip') packaging project(path: "${subproj.path}", configuration: 'zip')
} }
plugins.add(subproj.name) plugins.add(subproj.name)
} }
} }
plugins = plugins.toSorted() plugins = plugins.toSorted()
setupBats { setupPackagingTest {
doFirst { doFirst {
File expectedPlugins = file('build/plugins/expected') File expectedPlugins = file('build/plugins/expected')
expectedPlugins.parentFile.mkdirs() expectedPlugins.parentFile.mkdirs()