diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java index 559c0f60abc08..20a5399d28b92 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java @@ -50,6 +50,7 @@ import org.gradle.api.tasks.util.PatternFilterable; import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -214,6 +215,7 @@ public Void call(Object... args) { } }); + var processedVersions = new HashSet(); // Add `usesBwcDistribution(version)` extension method to test tasks to indicate they require a BWC distribution task.getExtensions().getExtraProperties().set("usesBwcDistribution", new Closure(task) { @Override @@ -221,8 +223,11 @@ public Void call(Object... args) { if (args.length != 1 || args[0] instanceof Version == false) { throw new IllegalArgumentException("Expected exactly one argument of type org.elasticsearch.gradle.Version"); } - + if (processedVersions.contains(args[0])) { + return null; + } Version version = (Version) args[0]; + processedVersions.add(version); boolean isReleased = bwcVersions.unreleasedInfo(version) == null; String versionString = version.toString(); ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString); @@ -263,7 +268,10 @@ private ElasticsearchDistribution createDistribution(Project project, String nam if (maybeDistro == null) { return distributions.create(name, distro -> { distro.setVersion(version); - distro.setArchitecture(Architecture.current()); + // distro.setArchitecture(Architecture.current()); + // distro.setArchitecture(Architecture.current()); + distro.setArchitecture(Architecture.X64); + // distro.setPlatform(ElasticsearchDistribution.Platform.LINUX); if (type != null) { distro.setType(type); } diff --git a/test/fixtures/old-elasticsearch/Dockerfile b/test/fixtures/old-elasticsearch/Dockerfile new file mode 100644 index 0000000000000..ad79217689ad0 --- /dev/null +++ b/test/fixtures/old-elasticsearch/Dockerfile @@ -0,0 +1 @@ +FROM alpine:3.21.0 diff --git a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalClusterFactory.java b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalClusterFactory.java index 6070ec140d254..b6486144ab449 100644 --- a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalClusterFactory.java +++ b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalClusterFactory.java @@ -175,7 +175,7 @@ public synchronized void start(Version version) { if (usesSecureSecretsFile) { writeSecureSecretsFile(); } else { - createKeystore(); +// createKeystore(); addKeystoreSettings(); addKeystoreFiles(); } @@ -280,6 +280,15 @@ public void waitUntilReady() { try { Retry.retryUntilTrue(NODE_UP_TIMEOUT, Duration.ofMillis(500), () -> { if (process.isAlive() == false) { +// try (var reader = process.errorReader()) { +// String line; +// while ((line = reader.readLine()) != null) { +// System.out.println("LINE " + line); +// } +// } catch (IOException e) { +// throw new UncheckedIOException("Error reading output from process.", e); +// } + System.out.println("process.exitValue() = " + process.exitValue()); throw new RuntimeException( "Elasticsearch process died while waiting for ports file. See console output for details." ); @@ -428,9 +437,9 @@ private void writeConfiguration() { String content = Files.readString(jvmOptionsFile); Map expansions = getJvmOptionsReplacements(); for (String key : expansions.keySet()) { - if (content.contains(key) == false) { - throw new IOException("Template property '" + key + "' not found in template."); - } +// if (content.contains(key) == false) { +// throw new IOException("Template property '" + key + "' not found in template."); +// } content = content.replace(key, expansions.get(key)); } Files.writeString(jvmOptionsFile, content); @@ -762,6 +771,7 @@ private void startElasticsearch() { true ); + ProcessReaper.instance().registerPid(getServiceName(), process.pid()); } diff --git a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/util/ProcessUtils.java b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/util/ProcessUtils.java index a28cfc3eda26c..0b1bff863c4eb 100644 --- a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/util/ProcessUtils.java +++ b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/util/ProcessUtils.java @@ -70,8 +70,7 @@ public static Process exec( processBuilder.environment().putAll(environment); try { - process = processBuilder.start(); - + process = processBuilder.inheritIO().start();; startLoggingThread( process.getInputStream(), inheritIO ? System.out::println : PROCESS_LOGGER::info, diff --git a/x-pack/qa/repository-old-versions/build.gradle b/x-pack/qa/repository-old-versions/build.gradle index f21aad9cdf75a..d1b72aa9fe771 100644 --- a/x-pack/qa/repository-old-versions/build.gradle +++ b/x-pack/qa/repository-old-versions/build.gradle @@ -16,9 +16,12 @@ import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE apply plugin: 'elasticsearch.jdk-download' apply plugin: 'elasticsearch.internal-testclusters' -apply plugin: 'elasticsearch.standalone-rest-test' +//apply plugin: 'elasticsearch.standalone-rest-test' +apply plugin: 'elasticsearch.internal-java-rest-test' + apply plugin: 'elasticsearch.rest-resources' + configurations { oldesFixture } @@ -180,5 +183,12 @@ if (OS.current() == OS.WINDOWS) { dependsOn "javaRestTestAfterRestart#${versionNoDots}" } } + + tasks.named("javaRestTest").configure { + dependsOn jdks.legacy + usesBwcDistribution(Version.fromString("7.17.20")) + usesBwcDistribution(Version.fromString("6.0.0")) + environment 'JAVA_HOME', jdks.legacy.javaHomePath + } } diff --git a/x-pack/qa/repository-old-versions/src/javaRestTest/java/org/elasticsearch/oldrepos/tests/OldDistroIT.java b/x-pack/qa/repository-old-versions/src/javaRestTest/java/org/elasticsearch/oldrepos/tests/OldDistroIT.java new file mode 100644 index 0000000000000..201c26b70adb7 --- /dev/null +++ b/x-pack/qa/repository-old-versions/src/javaRestTest/java/org/elasticsearch/oldrepos/tests/OldDistroIT.java @@ -0,0 +1,56 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.oldrepos.tests; + +import org.elasticsearch.client.Request; +import org.elasticsearch.client.Response; +import org.elasticsearch.test.cluster.ElasticsearchCluster; +import org.elasticsearch.test.cluster.local.LocalClusterConfigProvider; +import org.elasticsearch.test.cluster.local.LocalClusterSpecBuilder; +import org.elasticsearch.test.cluster.local.distribution.DistributionType; +import org.elasticsearch.test.cluster.util.Version; +import org.elasticsearch.test.rest.ESRestTestCase; +import org.junit.ClassRule; + +import java.io.IOException; + +import static org.hamcrest.Matchers.is; + +public class OldDistroIT extends ESRestTestCase { + + @ClassRule + public static ElasticsearchCluster cluster = ElasticsearchCluster.local() + // .version(Version.fromString("7.17.20")) + .version(Version.fromString("6.0.0")) + .distribution(DistributionType.DEFAULT) + .setting("xpack.security.enabled", "false") + .setting("xpack.ml.enabled", "false") + .apply(builder -> { + if (System.getenv("JAVA_HOME") != null) { + builder.environment("JAVA_HOME", System.getenv("JAVA_HOME")); + } + }) + .build(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } + + public void testCreateIndex() throws IOException { + Request request = request("PUT", "/" + "blubb"); + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + } + + private Request request(String method, String endpoint) { + Request request = new Request(method, endpoint); + request.setOptions(request.getOptions().toBuilder().addHeader("X-elastic-product-origin", "kibana").build()); + return request; + } +}