Skip to content

Commit

Permalink
Convert core xpack rest tests to new test framework (elastic#100301)
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java
#	x-pack/plugin/build.gradle
  • Loading branch information
mark-vieira committed Oct 4, 2023
1 parent 657cb5d commit a75101b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
public enum FeatureFlag {
TIME_SERIES_MODE("es.index_mode_feature_flag_registered=true", Version.fromString("8.0.0"), null),
INFERENCE_RESCORER("es.inference_rescorer_feature_flag_enabled", Version.fromString("8.10.0"), null),
DATA_STREAM_LIFECYCLE_ENABLED("es.dlm_feature_flag_enabled=true", Version.fromString("8.8.0"), null);

public final String systemProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class DefaultLocalClusterSpecBuilder extends AbstractLocalClusterSpecBuil

public DefaultLocalClusterSpecBuilder() {
super();
this.apply(c -> c.systemProperty("ingest.geoip.downloader.enabled.default", "false"));
this.apply(new FipsEnabledClusterConfigProvider());
this.settings(new DefaultSettingsProvider());
this.environment(new DefaultEnvironmentProvider());
Expand Down
69 changes: 8 additions & 61 deletions x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
import org.elasticsearch.gradle.util.GradleUtils

apply plugin: 'elasticsearch.legacy-yaml-rest-test'
apply plugin: 'elasticsearch.legacy-yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.validate-rest-spec'
apply plugin: 'elasticsearch.internal-test-artifact'

Expand All @@ -15,6 +16,7 @@ base {
dependencies {
testImplementation project(xpackModule('core'))
testImplementation(testArtifact(project(xpackModule('core'))))
testImplementation(testArtifact(project(":x-pack:plugin:security:qa:service-account"), "javaRestTest"))
testImplementation project(':test:yaml-rest-runner')
}

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

// location for keys and certificates
File extraResourceDir = file("$buildDir/extra_resource")
File nodeKey = file("$extraResourceDir/testnode.pem")
File nodeCert = file("$extraResourceDir/testnode.crt")
// location for service tokens
File serviceTokens = file("$extraResourceDir/service_tokens")

// Add key and certs to test classpath: it expects them there
// User cert and key PEM files instead of a JKS Keystore for the cluster's trust material so that
// it can run in a FIPS 140 JVM
// TODO: Remove all existing uses of cross project file references when the new approach for referencing static files is available
// https://github.com/elastic/elasticsearch/pull/32201
tasks.register("copyExtraResources", Copy) {
from(project(':x-pack:plugin:core').file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/')) {
include 'testnode.crt', 'testnode.pem'
}
from(project(':x-pack:plugin:security:qa:service-account').file('src/javaRestTest/resources/')) {
include 'service_tokens'
}
into extraResourceDir
}
// Add keystores to test classpath: it expects it there
sourceSets.yamlRestTest.resources.srcDir(extraResourceDir)
tasks.named("processYamlRestTestResources").configure {
dependsOn("copyExtraResources")
}
def restTestBlacklist = []
// TODO: fix this rest test to not depend on a hardcoded port!
restTestBlacklist.addAll(['getting_started/10_monitor_cluster_health/*'])
Expand All @@ -75,9 +51,12 @@ if (BuildParams.isSnapshotBuild() == false) {
restTestBlacklist.add('privileges/11_builtin/Test get builtin privileges')
}

tasks.withType(StandaloneRestIntegTestTask).configureEach {
usesDefaultDistribution()
}

tasks.named("yamlRestTest").configure {
systemProperty 'tests.rest.blacklist', restTestBlacklist.join(',')
dependsOn "copyExtraResources"
}

tasks.named("yamlRestTestV7CompatTest").configure {
Expand Down Expand Up @@ -196,38 +175,6 @@ tasks.named("yamlRestTestV7CompatTransform").configure { task ->
)
}


testClusters.configureEach {
testDistribution = 'DEFAULT' // this is important since we use the reindex module in ML
setting 'xpack.ml.enabled', 'true'
setting 'xpack.security.enabled', 'true'
setting 'xpack.watcher.enabled', 'false'
// Integration tests are supposed to enable/disable exporters before/after each test
setting 'xpack.security.authc.token.enabled', 'true'
setting 'xpack.security.authc.api_key.enabled', 'true'
setting 'xpack.security.transport.ssl.enabled', 'true'
setting 'xpack.security.transport.ssl.key', nodeKey.name
setting 'xpack.security.transport.ssl.certificate', nodeCert.name
setting 'xpack.security.transport.ssl.verification_mode', 'certificate'
setting 'xpack.security.audit.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial'
// disable ILM history, since it disturbs tests using _all
setting 'indices.lifecycle.history_index_enabled', 'false'
keystore 'bootstrap.password', 'x-pack-test-password'
keystore 'xpack.security.transport.ssl.secure_key_passphrase', 'testnode'
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'

user username: "x_pack_rest_user", password: "x-pack-test-password"
extraConfigFile nodeKey.name, nodeKey
extraConfigFile nodeCert.name, nodeCert
extraConfigFile serviceTokens.name, serviceTokens

requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
requiresFeature 'es.inference_rescorer_feature_flag_enabled', Version.fromString("8.10.0")
requiresFeature 'es.dlm_feature_flag_enabled', Version.fromString("8.9.0")
}

tasks.register('enforceApiSpecsConvention').configure {
doLast {
if (fileTree('src/test/resources/rest-api-spec/api').files) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,47 @@

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.cluster.util.resource.Resource;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.junit.Before;
import org.junit.ClassRule;

public class XPackRestIT extends AbstractXPackRestTest {

@ClassRule
public static final ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.name("yamlRestTest")
.setting("xpack.ml.enabled", "true")
.setting("xpack.security.enabled", "true")
.setting("xpack.watcher.enabled", "false")
// Integration tests are supposed to enable/disable exporters before/after each test
.setting("xpack.security.authc.token.enabled", "true")
.setting("xpack.security.authc.api_key.enabled", "true")
.setting("xpack.security.transport.ssl.enabled", "true")
.setting("xpack.security.transport.ssl.key", "testnode.pem")
.setting("xpack.security.transport.ssl.certificate", "testnode.crt")
.setting("xpack.security.transport.ssl.verification_mode", "certificate")
.setting("xpack.security.audit.enabled", "true")
.setting("xpack.license.self_generated.type", "trial")
// disable ILM history, since it disturbs tests using _all
.setting("indices.lifecycle.history_index_enabled", "false")
.keystore("bootstrap.password", "x-pack-test-password")
.keystore("xpack.security.transport.ssl.secure_key_passphrase", "testnode")
.setting("xpack.searchable.snapshot.shared_cache.size", "16MB")
.setting("xpack.searchable.snapshot.shared_cache.region_size", "256KB")
.user("x_pack_rest_user", "x-pack-test-password")
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.INFERENCE_RESCORER)
.feature(FeatureFlag.DATA_STREAM_LIFECYCLE_ENABLED)
.configFile("testnode.pem", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem"))
.configFile("testnode.crt", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt"))
.configFile("service_tokens", Resource.fromClasspath("service_tokens"))
.build();

public XPackRestIT(ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}
Expand All @@ -30,4 +66,9 @@ public static Iterable<Object[]> parameters() throws Exception {
public void setupLicense() {
super.waitForLicense();
}

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}

0 comments on commit a75101b

Please sign in to comment.