Skip to content

Commit 2b16d7b

Browse files
authored
Backport testclusters all (#47565)
* Bwc testclusters all (#46265) Convert all bwc projects to testclusters * Fix bwc versions config * WIP fix rolling upgrade * Fix bwc tests on old versions * Fix rolling upgrade
1 parent 8c180a7 commit 2b16d7b

File tree

20 files changed

+635
-938
lines changed

20 files changed

+635
-938
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private static String distributionProjectName(ElasticsearchDistribution distribu
255255
Platform platform = distribution.getPlatform();
256256
projectName += platform.toString() + (platform == Platform.WINDOWS ? "-zip" : "-tar");
257257
} else {
258-
projectName = "zip";
258+
projectName = distribution.getFlavor().equals(Flavor.DEFAULT) ?"zip" : "oss-zip";
259259
}
260260
} else {
261261
projectName += distribution.getType();

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -273,31 +273,7 @@ private void commonNodeConfig() {
273273
for (ElasticsearchNode node : nodes) {
274274
// Can only configure master nodes if we have node names defined
275275
if (nodeNames != null) {
276-
if (node.getVersion().onOrAfter("7.0.0")) {
277-
node.defaultConfig.keySet().stream()
278-
.filter(name -> name.startsWith("discovery.zen."))
279-
.collect(Collectors.toList())
280-
.forEach(node.defaultConfig::remove);
281-
node.defaultConfig.put("cluster.initial_master_nodes", "[" + nodeNames + "]");
282-
node.defaultConfig.put("discovery.seed_providers", "file");
283-
node.defaultConfig.put("discovery.seed_hosts", "[]");
284-
} else {
285-
node.defaultConfig.put("discovery.zen.master_election.wait_for_joins_timeout", "5s");
286-
if (nodes.size() > 1) {
287-
node.defaultConfig.put("discovery.zen.minimum_master_nodes", Integer.toString(nodes.size() / 2 + 1));
288-
}
289-
if (node.getVersion().onOrAfter("6.5.0")) {
290-
node.defaultConfig.put("discovery.zen.hosts_provider", "file");
291-
node.defaultConfig.put("discovery.zen.ping.unicast.hosts", "[]");
292-
} else {
293-
if (firstNode == null) {
294-
node.defaultConfig.put("discovery.zen.ping.unicast.hosts", "[]");
295-
} else {
296-
firstNode.waitForAllConditions();
297-
node.defaultConfig.put("discovery.zen.ping.unicast.hosts", "[\"" + firstNode.getTransportPortURI() + "\"]");
298-
}
299-
}
300-
}
276+
commonNodeConfig(node, nodeNames, firstNode);
301277
}
302278
if (firstNode == null) {
303279
firstNode = node;
@@ -309,6 +285,36 @@ private void commonNodeConfig() {
309285
}
310286
}
311287

288+
private void commonNodeConfig(ElasticsearchNode node, String nodeNames, ElasticsearchNode firstNode) {
289+
if (node.getVersion().onOrAfter("7.0.0")) {
290+
node.defaultConfig.keySet().stream()
291+
.filter(name -> name.startsWith("discovery.zen."))
292+
.collect(Collectors.toList())
293+
.forEach(node.defaultConfig::remove);
294+
if (nodeNames != null) {
295+
node.defaultConfig.put("cluster.initial_master_nodes", "[" + nodeNames + "]");
296+
}
297+
node.defaultConfig.put("discovery.seed_providers", "file");
298+
node.defaultConfig.put("discovery.seed_hosts", "[]");
299+
} else {
300+
node.defaultConfig.put("discovery.zen.master_election.wait_for_joins_timeout", "5s");
301+
if (nodes.size() > 1) {
302+
node.defaultConfig.put("discovery.zen.minimum_master_nodes", Integer.toString(nodes.size() / 2 + 1));
303+
}
304+
if (node.getVersion().onOrAfter("6.5.0")) {
305+
node.defaultConfig.put("discovery.zen.hosts_provider", "file");
306+
node.defaultConfig.put("discovery.zen.ping.unicast.hosts", "[]");
307+
} else {
308+
if (firstNode == null) {
309+
node.defaultConfig.put("discovery.zen.ping.unicast.hosts", "[]");
310+
} else {
311+
firstNode.waitForAllConditions();
312+
node.defaultConfig.put("discovery.zen.ping.unicast.hosts", "[\"" + firstNode.getTransportPortURI() + "\"]");
313+
}
314+
}
315+
}
316+
}
317+
312318
@Override
313319
public void restart() {
314320
nodes.forEach(ElasticsearchNode::restart);
@@ -328,7 +334,24 @@ public void nextNodeToNextVersion() {
328334
ElasticsearchNode node = nodes.getByName(clusterName + "-" + nodeIndex);
329335
node.stop(false);
330336
node.goToNextVersion();
331-
commonNodeConfig();
337+
commonNodeConfig(node, null, null);
338+
// We need to translate these settings there as there's no support to do per version config for testclusters yet
339+
if (node.getVersion().onOrAfter("7.0.0")) {
340+
if (node.settings.containsKey("xpack.security.authc.realms.file1.type")) {
341+
node.settings.remove("xpack.security.authc.realms.file1.type");
342+
node.settings.put(
343+
"xpack.security.authc.realms.file.file1.order",
344+
node.settings.remove("xpack.security.authc.realms.file1.order")
345+
);
346+
}
347+
if (node.settings.containsKey("xpack.security.authc.realms.native1.type")) {
348+
node.settings.remove("xpack.security.authc.realms.native1.type");
349+
node.settings.put(
350+
"xpack.security.authc.realms.native.native1.order",
351+
node.settings.remove("xpack.security.authc.realms.native1.order")
352+
);
353+
}
354+
}
332355
nodeIndex += 1;
333356
node.start();
334357
}

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
120120
private final LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>();
121121
private final List<URI> plugins = new ArrayList<>();
122122
private final List<File> modules = new ArrayList<>();
123-
private final LazyPropertyMap<String, CharSequence> settings = new LazyPropertyMap<>("Settings", this);
123+
final LazyPropertyMap<String, CharSequence> settings = new LazyPropertyMap<>("Settings", this);
124124
private final LazyPropertyMap<String, CharSequence> keystoreSettings = new LazyPropertyMap<>("Keystore", this);
125125
private final LazyPropertyMap<String, File> keystoreFiles = new LazyPropertyMap<>("Keystore files", this, FileEntry::new);
126126
private final LazyPropertyMap<String, CharSequence> systemProperties = new LazyPropertyMap<>("System properties", this);
@@ -732,6 +732,17 @@ public File getAuditLog() {
732732

733733
@Override
734734
public synchronized void stop(boolean tailLogs) {
735+
logToProcessStdout("Stopping node");
736+
try {
737+
if (Files.exists(httpPortsFile)) {
738+
Files.delete(httpPortsFile);
739+
}
740+
if (Files.exists(transportPortFile)) {
741+
Files.delete(transportPortFile);
742+
}
743+
} catch (IOException e) {
744+
throw new UncheckedIOException(e);
745+
}
735746
if (esProcess == null && tailLogs) {
736747
// This is a special case. If start() throws an exception the plugin will still call stop
737748
// Another exception here would eat the orriginal.
@@ -894,6 +905,8 @@ private void waitForProcessToExit(ProcessHandle processHandle) {
894905

895906
private void createWorkingDir(Path distroExtractDir) throws IOException {
896907
syncWithLinks(distroExtractDir, distroDir);
908+
// Start configuration from scratch in case of a restart
909+
project.delete(configFile.getParent());
897910
Files.createDirectories(configFile.getParent());
898911
Files.createDirectories(confPathRepo);
899912
Files.createDirectories(confPathData);

buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/VersionProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public static String getElasticsearch() {
1515
return elasticsearch;
1616
}
1717

18+
public static Version getElasticsearchVersion() {
19+
return Version.fromString(elasticsearch);
20+
}
21+
1822
public static String getLucene() {
1923
return lucene;
2024
}

qa/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ subprojects { Project subproj ->
1212
}
1313
plugins.withType(TestClustersPlugin).whenPluginAdded {
1414
testClusters.all {
15-
testDistribution = System.getProperty('tests.distribution', 'oss').toUpperCase()
15+
String configuredTestDistribution = System.getProperty('tests.distribution', 'oss').toUpperCase()
16+
testDistribution = configuredTestDistribution
17+
if (configuredTestDistribution.equals("DEFAULT")) {
18+
setting "xpack.security.enabled", "false"
19+
}
1620
}
1721
}
1822
}

qa/full-cluster-restart/build.gradle

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import org.elasticsearch.gradle.Version
2222
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
2323
import org.elasticsearch.gradle.testclusters.TestDistribution
2424

25-
apply plugin: 'elasticsearch.standalone-test'
2625
apply plugin: 'elasticsearch.testclusters'
26+
apply plugin: 'elasticsearch.standalone-test'
2727

28-
// This is a top level task which we will add dependencies to below.
29-
// It is a single task that can be used to backcompat tests against all versions.
30-
task bwcTest {
28+
tasks.register("bwcTest") {
3129
description = 'Runs backwards compatibility tests.'
3230
group = 'verification'
3331
}
@@ -36,18 +34,13 @@ for (Version bwcVersion : bwcVersions.indexCompatible) {
3634
String baseName = "v${bwcVersion}"
3735

3836
testClusters {
39-
String configuredTestDistribution = System.getProperty('tests.distribution', 'oss').toUpperCase()
4037
"${baseName}" {
41-
testDistribution = configuredTestDistribution
4238
versions = [ bwcVersion.toString(), project.version ]
4339
numberOfNodes = 2
4440
// some tests rely on the translog not being flushed
4541
setting 'indices.memory.shard_inactive_time', '20m'
4642
setting 'http.content_type.required', 'true'
4743
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
48-
if (configuredTestDistribution.equals("DEFAULT")) {
49-
setting "xpack.security.enabled", "false"
50-
}
5144
javaHome = project.file(project.ext.runtimeJavaHome)
5245
}
5346
}
@@ -87,9 +80,6 @@ for (Version bwcVersion : bwcVersions.indexCompatible) {
8780
}
8881
}
8982

90-
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
91-
92-
// basic integ tests includes testing bwc against the most recent version
9383
task bwcTestSnapshots {
9484
if (project.bwc_tests_enabled) {
9585
for (final def version : bwcVersions.unreleasedIndexCompatible) {
@@ -112,3 +102,5 @@ task testJar(type: Jar) {
112102
artifacts {
113103
testArtifacts testJar
114104
}
105+
106+
test.enabled = false

qa/mixed-cluster/build.gradle

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,89 @@
1717
* under the License.
1818
*/
1919

20-
import org.elasticsearch.gradle.test.RestIntegTestTask
2120
import org.elasticsearch.gradle.Version
21+
import org.elasticsearch.gradle.VersionProperties
22+
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
2223

24+
apply plugin: 'elasticsearch.testclusters'
2325
apply plugin: 'elasticsearch.standalone-test'
2426

25-
// This is a top level task which we will add dependencies to below.
26-
// It is a single task that can be used to backcompat tests against all versions.
27-
task bwcTest {
27+
tasks.register("bwcTest") {
2828
description = 'Runs backwards compatibility tests.'
2929
group = 'verification'
3030
}
3131

32-
for (Version version : bwcVersions.wireCompatible) {
33-
String baseName = "v${version}"
32+
configurations {
33+
restSpec
34+
}
3435

35-
Task mixedClusterTest = tasks.create(name: "${baseName}#mixedClusterTest", type: RestIntegTestTask) {
36-
mustRunAfter(precommit)
37-
includePackaged = true
36+
dependencies {
37+
restSpec project(':rest-api-spec')
38+
}
39+
40+
processTestResources {
41+
from ({ zipTree(configurations.restSpec.singleFile) })
42+
dependsOn configurations.restSpec
43+
}
44+
45+
for (Version bwcVersion : bwcVersions.wireCompatible) {
46+
if (bwcVersion == VersionProperties.getElasticsearchVersion()) {
47+
// Not really a mixed cluster
48+
continue ;
3849
}
3950

51+
String baseName = "v${bwcVersion}"
52+
4053
/* This project runs the core REST tests against a 4 node cluster where two of
4154
the nodes has a different minor. */
42-
Object extension = extensions.findByName("${baseName}#mixedClusterTestCluster")
43-
configure(extension) {
44-
numNodes = 4
45-
numBwcNodes = 2
46-
bwcVersion = version
47-
}
55+
testClusters {
56+
"${baseName}" {
57+
versions = [ bwcVersion.toString(), project.version ]
58+
numberOfNodes = 4
4859

49-
Task versionBwcTest = tasks.create(name: "${baseName}#bwcTest") {
50-
dependsOn = [mixedClusterTest]
60+
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
61+
javaHome = project.file(project.ext.runtimeJavaHome)
62+
}
5163
}
5264

53-
if (project.bwc_tests_enabled) {
54-
bwcTest.dependsOn(versionBwcTest)
65+
tasks.register("${baseName}#mixedClusterTest", RestTestRunnerTask) {
66+
useCluster testClusters."${baseName}"
67+
mustRunAfter(precommit)
68+
doFirst {
69+
project.delete("${buildDir}/cluster/shared/repo/${baseName}")
70+
// Getting the endpoints causes a wait for the cluster
71+
println "Test cluster endpoints are: ${-> testClusters."${baseName}".allHttpSocketURI.join(",") }"
72+
println "Upgrading one node to create a mixed cluster"
73+
testClusters."${baseName}".nextNodeToNextVersion()
74+
// Getting the endpoints causes a wait for the cluster
75+
println "Upgrade complete, endpoints are: ${-> testClusters."${baseName}".allHttpSocketURI.join(",") }"
76+
println "Upgrading another node to create a mixed cluster"
77+
testClusters."${baseName}".nextNodeToNextVersion()
78+
79+
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",") }")
80+
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName() }")
81+
}
82+
systemProperty 'tests.path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
83+
onlyIf { project.bwc_tests_enabled }
5584
}
5685

57-
tasks.getByName("${baseName}#mixedClusterTestRunner").configure {
58-
/* To support taking index snapshots, we have to set path.repo setting */
59-
systemProperty 'tests.path.repo', new File(buildDir, "cluster/shared/repo")
86+
tasks.register("${baseName}#bwcTest") {
87+
dependsOn "${baseName}#mixedClusterTest"
6088
}
61-
}
6289

63-
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
90+
tasks.bwcTest.dependsOn "${baseName}#bwcTest"
91+
}
6492

65-
// basic integ tests includes testing bwc against the most recent version
6693
task bwcTestSnapshots {
6794
if (project.bwc_tests_enabled) {
68-
for (final def version : bwcVersions.unreleasedWireCompatible) {
69-
dependsOn "v${version}#bwcTest"
95+
for (Version bwcVersion : bwcVersions.unreleasedWireCompatible) {
96+
if (bwcVersion != VersionProperties.getElasticsearchVersion()) {
97+
dependsOn "v${bwcVersion}#bwcTest"
98+
}
7099
}
71100
}
72101
}
73102

74103
check.dependsOn(bwcTestSnapshots)
104+
105+
test.enabled = false

0 commit comments

Comments
 (0)