Skip to content

Commit c63272e

Browse files
authored
Convert core xpack rest tests to new test framework (#100301) (#100306)
# Conflicts: # test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java # x-pack/plugin/build.gradle
1 parent 657cb5d commit c63272e

File tree

4 files changed

+51
-61
lines changed

4 files changed

+51
-61
lines changed

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
public enum FeatureFlag {
1818
TIME_SERIES_MODE("es.index_mode_feature_flag_registered=true", Version.fromString("8.0.0"), null),
19+
INFERENCE_RESCORER("es.inference_rescorer_feature_flag_enabled", Version.fromString("8.10.0"), null),
1920
DATA_STREAM_LIFECYCLE_ENABLED("es.dlm_feature_flag_enabled=true", Version.fromString("8.8.0"), null);
2021

2122
public final String systemProperty;

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/DefaultLocalClusterSpecBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class DefaultLocalClusterSpecBuilder extends AbstractLocalClusterSpecBuil
1919

2020
public DefaultLocalClusterSpecBuilder() {
2121
super();
22+
this.apply(c -> c.systemProperty("ingest.geoip.downloader.enabled.default", "false"));
2223
this.apply(new FipsEnabledClusterConfigProvider());
2324
this.settings(new DefaultSettingsProvider());
2425
this.environment(new DefaultEnvironmentProvider());

x-pack/plugin/build.gradle

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import org.elasticsearch.gradle.Version
22
import org.elasticsearch.gradle.VersionProperties
33
import org.elasticsearch.gradle.internal.info.BuildParams
4+
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
45
import org.elasticsearch.gradle.util.GradleUtils
56

6-
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
7-
apply plugin: 'elasticsearch.legacy-yaml-rest-compat-test'
7+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
8+
apply plugin: 'elasticsearch.yaml-rest-compat-test'
89
apply plugin: 'elasticsearch.validate-rest-spec'
910
apply plugin: 'elasticsearch.internal-test-artifact'
1011

@@ -15,6 +16,7 @@ base {
1516
dependencies {
1617
testImplementation project(xpackModule('core'))
1718
testImplementation(testArtifact(project(xpackModule('core'))))
19+
testImplementation(testArtifact(project(":x-pack:plugin:security:qa:service-account"), "javaRestTest"))
1820
testImplementation project(':test:yaml-rest-runner')
1921
}
2022

@@ -33,32 +35,6 @@ artifacts {
3335
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
3436
}
3537

36-
// location for keys and certificates
37-
File extraResourceDir = file("$buildDir/extra_resource")
38-
File nodeKey = file("$extraResourceDir/testnode.pem")
39-
File nodeCert = file("$extraResourceDir/testnode.crt")
40-
// location for service tokens
41-
File serviceTokens = file("$extraResourceDir/service_tokens")
42-
43-
// Add key and certs to test classpath: it expects them there
44-
// User cert and key PEM files instead of a JKS Keystore for the cluster's trust material so that
45-
// it can run in a FIPS 140 JVM
46-
// TODO: Remove all existing uses of cross project file references when the new approach for referencing static files is available
47-
// https://github.com/elastic/elasticsearch/pull/32201
48-
tasks.register("copyExtraResources", Copy) {
49-
from(project(':x-pack:plugin:core').file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/')) {
50-
include 'testnode.crt', 'testnode.pem'
51-
}
52-
from(project(':x-pack:plugin:security:qa:service-account').file('src/javaRestTest/resources/')) {
53-
include 'service_tokens'
54-
}
55-
into extraResourceDir
56-
}
57-
// Add keystores to test classpath: it expects it there
58-
sourceSets.yamlRestTest.resources.srcDir(extraResourceDir)
59-
tasks.named("processYamlRestTestResources").configure {
60-
dependsOn("copyExtraResources")
61-
}
6238
def restTestBlacklist = []
6339
// TODO: fix this rest test to not depend on a hardcoded port!
6440
restTestBlacklist.addAll(['getting_started/10_monitor_cluster_health/*'])
@@ -75,9 +51,12 @@ if (BuildParams.isSnapshotBuild() == false) {
7551
restTestBlacklist.add('privileges/11_builtin/Test get builtin privileges')
7652
}
7753

54+
tasks.withType(StandaloneRestIntegTestTask).configureEach {
55+
usesDefaultDistribution()
56+
}
57+
7858
tasks.named("yamlRestTest").configure {
7959
systemProperty 'tests.rest.blacklist', restTestBlacklist.join(',')
80-
dependsOn "copyExtraResources"
8160
}
8261

8362
tasks.named("yamlRestTestV7CompatTest").configure {
@@ -196,38 +175,6 @@ tasks.named("yamlRestTestV7CompatTransform").configure { task ->
196175
)
197176
}
198177

199-
200-
testClusters.configureEach {
201-
testDistribution = 'DEFAULT' // this is important since we use the reindex module in ML
202-
setting 'xpack.ml.enabled', 'true'
203-
setting 'xpack.security.enabled', 'true'
204-
setting 'xpack.watcher.enabled', 'false'
205-
// Integration tests are supposed to enable/disable exporters before/after each test
206-
setting 'xpack.security.authc.token.enabled', 'true'
207-
setting 'xpack.security.authc.api_key.enabled', 'true'
208-
setting 'xpack.security.transport.ssl.enabled', 'true'
209-
setting 'xpack.security.transport.ssl.key', nodeKey.name
210-
setting 'xpack.security.transport.ssl.certificate', nodeCert.name
211-
setting 'xpack.security.transport.ssl.verification_mode', 'certificate'
212-
setting 'xpack.security.audit.enabled', 'true'
213-
setting 'xpack.license.self_generated.type', 'trial'
214-
// disable ILM history, since it disturbs tests using _all
215-
setting 'indices.lifecycle.history_index_enabled', 'false'
216-
keystore 'bootstrap.password', 'x-pack-test-password'
217-
keystore 'xpack.security.transport.ssl.secure_key_passphrase', 'testnode'
218-
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
219-
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
220-
221-
user username: "x_pack_rest_user", password: "x-pack-test-password"
222-
extraConfigFile nodeKey.name, nodeKey
223-
extraConfigFile nodeCert.name, nodeCert
224-
extraConfigFile serviceTokens.name, serviceTokens
225-
226-
requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
227-
requiresFeature 'es.inference_rescorer_feature_flag_enabled', Version.fromString("8.10.0")
228-
requiresFeature 'es.dlm_feature_flag_enabled', Version.fromString("8.9.0")
229-
}
230-
231178
tasks.register('enforceApiSpecsConvention').configure {
232179
doLast {
233180
if (fileTree('src/test/resources/rest-api-spec/api').files) {

x-pack/plugin/src/yamlRestTest/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,47 @@
99

1010
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1111

12+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
13+
import org.elasticsearch.test.cluster.FeatureFlag;
14+
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
15+
import org.elasticsearch.test.cluster.util.resource.Resource;
1216
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
1317
import org.junit.Before;
18+
import org.junit.ClassRule;
1419

1520
public class XPackRestIT extends AbstractXPackRestTest {
1621

22+
@ClassRule
23+
public static final ElasticsearchCluster cluster = ElasticsearchCluster.local()
24+
.distribution(DistributionType.DEFAULT)
25+
.name("yamlRestTest")
26+
.setting("xpack.ml.enabled", "true")
27+
.setting("xpack.security.enabled", "true")
28+
.setting("xpack.watcher.enabled", "false")
29+
// Integration tests are supposed to enable/disable exporters before/after each test
30+
.setting("xpack.security.authc.token.enabled", "true")
31+
.setting("xpack.security.authc.api_key.enabled", "true")
32+
.setting("xpack.security.transport.ssl.enabled", "true")
33+
.setting("xpack.security.transport.ssl.key", "testnode.pem")
34+
.setting("xpack.security.transport.ssl.certificate", "testnode.crt")
35+
.setting("xpack.security.transport.ssl.verification_mode", "certificate")
36+
.setting("xpack.security.audit.enabled", "true")
37+
.setting("xpack.license.self_generated.type", "trial")
38+
// disable ILM history, since it disturbs tests using _all
39+
.setting("indices.lifecycle.history_index_enabled", "false")
40+
.keystore("bootstrap.password", "x-pack-test-password")
41+
.keystore("xpack.security.transport.ssl.secure_key_passphrase", "testnode")
42+
.setting("xpack.searchable.snapshot.shared_cache.size", "16MB")
43+
.setting("xpack.searchable.snapshot.shared_cache.region_size", "256KB")
44+
.user("x_pack_rest_user", "x-pack-test-password")
45+
.feature(FeatureFlag.TIME_SERIES_MODE)
46+
.feature(FeatureFlag.INFERENCE_RESCORER)
47+
.feature(FeatureFlag.DATA_STREAM_LIFECYCLE_ENABLED)
48+
.configFile("testnode.pem", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem"))
49+
.configFile("testnode.crt", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt"))
50+
.configFile("service_tokens", Resource.fromClasspath("service_tokens"))
51+
.build();
52+
1753
public XPackRestIT(ClientYamlTestCandidate testCandidate) {
1854
super(testCandidate);
1955
}
@@ -30,4 +66,9 @@ public static Iterable<Object[]> parameters() throws Exception {
3066
public void setupLicense() {
3167
super.waitForLicense();
3268
}
69+
70+
@Override
71+
protected String getTestRestCluster() {
72+
return cluster.getHttpAddresses();
73+
}
3374
}

0 commit comments

Comments
 (0)