Skip to content

Commit c5f1eb8

Browse files
committed
[test] packaging: add groovy test project
Adds behavior to the vagrant test plugin that runs jars from the packagingTest configuration inside test VMs. Makes :qa:vagrant a project which builds such a packaging test uberjar. This test project doesn't run anything yet. For elastic#26741
1 parent a3e5773 commit c5f1eb8

File tree

4 files changed

+86
-11
lines changed

4 files changed

+86
-11
lines changed

Vagrantfile

+2
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export BATS=/project/build/bats
337337
export BATS_UTILS=/project/build/packaging/bats/utils
338338
export BATS_TESTS=/project/build/packaging/bats/tests
339339
export PACKAGING_ARCHIVES=/project/build/packaging/archives
340+
export PACKAGING_TESTS=/project/build/packaging/tests
340341
VARS
341342
cat \<\<SUDOERS_VARS > /etc/sudoers.d/elasticsearch_vars
342343
Defaults env_keep += "ZIP"
@@ -347,6 +348,7 @@ Defaults env_keep += "BATS"
347348
Defaults env_keep += "BATS_UTILS"
348349
Defaults env_keep += "BATS_TESTS"
349350
Defaults env_keep += "PACKAGING_ARCHIVES"
351+
Defaults env_keep += "PACKAGING_TESTS"
350352
SUDOERS_VARS
351353
chmod 0440 /etc/sudoers.d/elasticsearch_vars
352354
SHELL

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy

+23-9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class VagrantTestPlugin implements Plugin<Project> {
4343
static List<String> UPGRADE_FROM_ARCHIVES = ['rpm', 'deb']
4444

4545
private static final PACKAGING_CONFIGURATION = 'packaging'
46+
private static final PACKAGING_TEST_CONFIGURATION = 'packagingTest'
4647
private static final BATS = 'bats'
4748
private static final String BATS_TEST_COMMAND ="cd \$PACKAGING_ARCHIVES && sudo bats --tap \$BATS_TESTS/*.$BATS"
4849
private static final String PLATFORM_TEST_COMMAND ="rm -rf ~/elasticsearch && rsync -r /elasticsearch/ ~/elasticsearch && cd ~/elasticsearch && ./gradlew test integTest"
@@ -58,6 +59,7 @@ class VagrantTestPlugin implements Plugin<Project> {
5859

5960
// Creates custom configurations for Bats testing files (and associated scripts and archives)
6061
createPackagingConfiguration(project)
62+
project.configurations.create(PACKAGING_TEST_CONFIGURATION)
6163

6264
// Creates all the main Vagrant tasks
6365
createVagrantTasks(project)
@@ -134,10 +136,12 @@ class VagrantTestPlugin implements Plugin<Project> {
134136
}
135137

136138
private static void createCleanTask(Project project) {
137-
project.tasks.create('clean', Delete.class) {
138-
description 'Clean the project build directory'
139-
group 'Build'
140-
delete project.buildDir
139+
if (project.tasks.findByName('clean') == null) {
140+
project.tasks.create('clean', Delete.class) {
141+
description 'Clean the project build directory'
142+
group 'Build'
143+
delete project.buildDir
144+
}
141145
}
142146
}
143147

@@ -164,6 +168,12 @@ class VagrantTestPlugin implements Plugin<Project> {
164168
from project.configurations[PACKAGING_CONFIGURATION]
165169
}
166170

171+
File testsDir = new File(packagingDir, 'tests')
172+
Copy copyPackagingTests = project.tasks.create('copyPackagingTests', Copy) {
173+
into testsDir
174+
from project.configurations[PACKAGING_TEST_CONFIGURATION]
175+
}
176+
167177
Task createVersionFile = project.tasks.create('createVersionFile', FileContentsTask) {
168178
dependsOn copyPackagingArchives
169179
file "${archivesDir}/version"
@@ -214,7 +224,7 @@ class VagrantTestPlugin implements Plugin<Project> {
214224

215225
Task vagrantSetUpTask = project.tasks.create('setupPackagingTest')
216226
vagrantSetUpTask.dependsOn 'vagrantCheckVersion'
217-
vagrantSetUpTask.dependsOn copyPackagingArchives, createVersionFile, createUpgradeFromFile
227+
vagrantSetUpTask.dependsOn copyPackagingArchives, copyPackagingTests, createVersionFile, createUpgradeFromFile
218228
vagrantSetUpTask.dependsOn copyBatsTests, copyBatsUtils
219229
}
220230

@@ -373,10 +383,14 @@ class VagrantTestPlugin implements Plugin<Project> {
373383
packagingTest.dependsOn(batsPackagingTest)
374384
}
375385

376-
// This task doesn't do anything yet. In the future it will execute a jar containing tests on the vm
377-
Task groovyPackagingTest = project.tasks.create("vagrant${boxTask}#groovyPackagingTest")
378-
groovyPackagingTest.dependsOn(up)
379-
groovyPackagingTest.finalizedBy(halt)
386+
Task groovyPackagingTest = project.tasks.create("vagrant${boxTask}#groovyPackagingTest", VagrantCommandTask) {
387+
command 'ssh'
388+
boxName box
389+
environmentVars vagrantEnvVars
390+
dependsOn up, setupPackagingTest
391+
finalizedBy halt
392+
args '--command', 'set -e; for jar in $PACKAGING_TESTS/*.jar; do java -jar $jar; done'
393+
}
380394

381395
TaskExecutionAdapter groovyPackagingReproListener = createReproListener(project, groovyPackagingTest.path)
382396
groovyPackagingTest.doFirst {

qa/vagrant/build.gradle

+34-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,27 @@
1717
* under the License.
1818
*/
1919

20-
apply plugin: 'elasticsearch.vagrantsupport'
21-
apply plugin: 'elasticsearch.vagrant'
20+
plugins {
21+
id 'groovy'
22+
id 'application'
23+
id 'com.github.johnrengelman.shadow' version '2.0.2'
24+
id 'elasticsearch.build'
25+
id 'elasticsearch.vagrantsupport'
26+
id 'elasticsearch.vagrant'
27+
}
28+
29+
dependencies {
30+
compile localGroovy()
31+
compile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
32+
runtime project(':libs:elasticsearch-core') // needs to be on the classpath for JarHell
33+
packagingTest project(path: project.path, configuration: 'shadow')
34+
}
35+
36+
shadowJar {
37+
dependencies {
38+
exclude(project(":libs:elasticsearch-core")) // isn't needed in tests
39+
}
40+
}
2241

2342
List<String> plugins = []
2443
for (Project subproj : project.rootProject.subprojects) {
@@ -39,3 +58,16 @@ setupPackagingTest {
3958
expectedPlugins.setText(plugins.join('\n'), 'UTF-8')
4059
}
4160
}
61+
62+
mainClassName = 'org.elasticsearch.packaging.PackagingMain'
63+
64+
tasks.test.enabled = false
65+
66+
tasks.dependencyLicenses.enabled = false
67+
tasks.dependenciesInfo.enabled = false
68+
69+
tasks.thirdPartyAudit.enabled = false
70+
71+
tasks.forbiddenApis.enabled = false
72+
tasks.forbiddenApisMain.enabled = false
73+
tasks.forbiddenApisTest.enabled = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.packaging
21+
22+
/**
23+
* This class doesn't do anything yet
24+
*/
25+
class PackagingMain {
26+
static void main(String[] args) {}
27+
}

0 commit comments

Comments
 (0)