From e3e1c6227e1d480ece6b1fb799e7ccf8211a471f Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Thu, 27 Mar 2025 10:13:29 -0700 Subject: [PATCH] Migrate x-pack core module to new testing framework (#125740) (cherry picked from commit 0c50403ebbde38d7b8cac3392f7326fec3722d8b) --- .../internal/RestrictedBuildApiService.java | 1 - x-pack/plugin/core/build.gradle | 18 +++++----------- .../xpack/core/DataStreamRestIT.java | 21 +++++++++++++++++++ .../xpack/core/LicenseInstallationIT.java | 18 ++++++++++++++++ .../xpack/core/StackTemplatesRestIT.java | 20 ++++++++++++++++++ .../XPackCoreClientYamlTestSuiteIT.java | 18 ++++++++++++++++ 6 files changed, 82 insertions(+), 14 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java index c7da5683ee413..b9b0cdcb5bcf0 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java @@ -36,7 +36,6 @@ private static ListMultimap, String> createLegacyRestTestBasePluginUsag map.put(LegacyRestTestBasePlugin.class, ":qa:remote-clusters"); map.put(LegacyRestTestBasePlugin.class, ":qa:repository-multi-version"); map.put(LegacyRestTestBasePlugin.class, ":qa:rolling-upgrade-legacy"); - map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:core"); map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ent-search"); map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:fleet"); map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:logstash"); diff --git a/x-pack/plugin/core/build.gradle b/x-pack/plugin/core/build.gradle index 811c142234a65..4987bc6bd214e 100644 --- a/x-pack/plugin/core/build.gradle +++ b/x-pack/plugin/core/build.gradle @@ -7,9 +7,9 @@ import java.nio.file.Paths apply plugin: 'elasticsearch.internal-es-plugin' apply plugin: 'elasticsearch.publish' apply plugin: 'elasticsearch.internal-cluster-test' -apply plugin: 'elasticsearch.legacy-yaml-rest-test' -apply plugin: 'elasticsearch.legacy-java-rest-test' -apply plugin: 'elasticsearch.legacy-yaml-rest-compat-test' +apply plugin: 'elasticsearch.internal-yaml-rest-test' +apply plugin: 'elasticsearch.internal-java-rest-test' +apply plugin: 'elasticsearch.yaml-rest-compat-test' apply plugin: 'elasticsearch.internal-test-artifact' base { @@ -144,16 +144,8 @@ restResources { } } -testClusters.configureEach { - testDistribution = 'default' - setting 'xpack.security.enabled', 'true' - setting 'xpack.license.self_generated.type', 'trial' - //disabling ILM history as it disturbs testDSXpackUsage test - setting 'indices.lifecycle.history_index_enabled', 'false' - keystore 'bootstrap.password', 'x-pack-test-password' - user username: "x_pack_rest_user", password: "x-pack-test-password" - requiresFeature 'es.failure_store_feature_flag_enabled', Version.fromString("8.15.0") - systemProperty 'es.queryable_built_in_roles_enabled', 'false' +tasks.named("javaRestTest") { + usesDefaultDistribution("uses the _xpack api") } if (buildParams.snapshotBuild == false) { diff --git a/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/DataStreamRestIT.java b/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/DataStreamRestIT.java index 600a41ed01beb..6812d6179cb5e 100644 --- a/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/DataStreamRestIT.java +++ b/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/DataStreamRestIT.java @@ -13,10 +13,14 @@ import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.test.cluster.ElasticsearchCluster; +import org.elasticsearch.test.cluster.FeatureFlag; +import org.elasticsearch.test.cluster.local.distribution.DistributionType; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParserConfiguration; import org.elasticsearch.xcontent.json.JsonXContent; +import org.junit.ClassRule; import java.util.List; import java.util.Map; @@ -27,6 +31,18 @@ public class DataStreamRestIT extends ESRestTestCase { + @ClassRule + public static ElasticsearchCluster cluster = ElasticsearchCluster.local() + .distribution(DistributionType.DEFAULT) + .setting("xpack.security.enabled", "true") + .setting("xpack.license.self_generated.type", "trial") + .setting("indices.lifecycle.history_index_enabled", "false") + .feature(FeatureFlag.FAILURE_STORE_ENABLED) + .keystore("bootstrap.password", "x-pack-test-password") + .user("x_pack_rest_user", "x-pack-test-password") + .systemProperty("es.queryable_built_in_roles_enabled", "false") + .build(); + private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password")); @Override @@ -143,4 +159,9 @@ private void putFailureStoreTemplate() { throw new RuntimeException(e); } } + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } } diff --git a/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/LicenseInstallationIT.java b/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/LicenseInstallationIT.java index 1f670e0ee2d8c..aa95b1a528f12 100644 --- a/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/LicenseInstallationIT.java +++ b/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/LicenseInstallationIT.java @@ -18,11 +18,14 @@ import org.elasticsearch.license.License; import org.elasticsearch.license.LicenseSettings; import org.elasticsearch.license.TestUtils; +import org.elasticsearch.test.cluster.ElasticsearchCluster; +import org.elasticsearch.test.cluster.FeatureFlag; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.json.JsonXContent; import org.junit.Before; +import org.junit.ClassRule; import java.io.IOException; import java.util.Locale; @@ -39,6 +42,16 @@ */ public class LicenseInstallationIT extends ESRestTestCase { + @ClassRule + public static ElasticsearchCluster cluster = ElasticsearchCluster.local() + .setting("xpack.security.enabled", "true") + .setting("xpack.license.self_generated.type", "trial") + .feature(FeatureFlag.FAILURE_STORE_ENABLED) + .keystore("bootstrap.password", "x-pack-test-password") + .user("x_pack_rest_user", "x-pack-test-password") + .systemProperty("es.queryable_built_in_roles_enabled", "false") + .build(); + @Override protected Settings restClientSettings() { String token = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password".toCharArray())); @@ -159,4 +172,9 @@ private void assertClusterUsingTrialLicense() throws Exception { assertThat("the cluster should be using a trial license", innerMap.get("type"), equalTo("trial")); }); } + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } } diff --git a/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/StackTemplatesRestIT.java b/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/StackTemplatesRestIT.java index fcbf955c2b9ae..534f6bca07a65 100644 --- a/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/StackTemplatesRestIT.java +++ b/x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/StackTemplatesRestIT.java @@ -12,12 +12,27 @@ import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.test.cluster.ElasticsearchCluster; +import org.elasticsearch.test.cluster.FeatureFlag; +import org.elasticsearch.test.cluster.local.distribution.DistributionType; import org.elasticsearch.test.rest.ESRestTestCase; +import org.junit.ClassRule; import static org.hamcrest.Matchers.is; public class StackTemplatesRestIT extends ESRestTestCase { + @ClassRule + public static ElasticsearchCluster cluster = ElasticsearchCluster.local() + .distribution(DistributionType.DEFAULT) + .setting("xpack.security.enabled", "true") + .setting("xpack.license.self_generated.type", "trial") + .feature(FeatureFlag.FAILURE_STORE_ENABLED) + .keystore("bootstrap.password", "x-pack-test-password") + .user("x_pack_rest_user", "x-pack-test-password") + .systemProperty("es.queryable_built_in_roles_enabled", "false") + .build(); + private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password")); @Override @@ -56,4 +71,9 @@ public void testTemplatesCanBeDisabled() throws Exception { ResponseException exception = expectThrows(ResponseException.class, () -> client.performRequest(deleteRequest)); assertThat(exception.getResponse().getStatusLine().getStatusCode(), is(404)); } + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } } diff --git a/x-pack/plugin/core/src/yamlRestTest/java/org/elasticsearch/license/XPackCoreClientYamlTestSuiteIT.java b/x-pack/plugin/core/src/yamlRestTest/java/org/elasticsearch/license/XPackCoreClientYamlTestSuiteIT.java index 105df6dbeca4a..a6c658bb1fe60 100644 --- a/x-pack/plugin/core/src/yamlRestTest/java/org/elasticsearch/license/XPackCoreClientYamlTestSuiteIT.java +++ b/x-pack/plugin/core/src/yamlRestTest/java/org/elasticsearch/license/XPackCoreClientYamlTestSuiteIT.java @@ -13,11 +13,24 @@ import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.test.cluster.ElasticsearchCluster; +import org.elasticsearch.test.cluster.FeatureFlag; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.junit.ClassRule; public class XPackCoreClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + @ClassRule + public static ElasticsearchCluster cluster = ElasticsearchCluster.local() + .setting("xpack.security.enabled", "true") + .setting("xpack.license.self_generated.type", "trial") + .feature(FeatureFlag.FAILURE_STORE_ENABLED) + .keystore("bootstrap.password", "x-pack-test-password") + .user("x_pack_rest_user", "x-pack-test-password") + .systemProperty("es.queryable_built_in_roles_enabled", "false") + .build(); + private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password")); public XPackCoreClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { @@ -33,4 +46,9 @@ public static Iterable parameters() throws Exception { protected Settings restClientSettings() { return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE).build(); } + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } }