Skip to content

Commit

Permalink
Ensure Fleet REST yaml tests work in serverless (elastic#115869)
Browse files Browse the repository at this point in the history
Use new gradle plugin for the yaml tests so they can be executed
in serverless CI as well.

Relates ES-8275
  • Loading branch information
kingherc authored Nov 12, 2024
1 parent d34c563 commit bcf1bd4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public SearchRequestBuilder setWaitForCheckpoints(Map<String, long[]> waitForChe
return this;
}

/**
* Set the timeout for the {@link #setWaitForCheckpoints(Map)} request.
*/
public SearchRequestBuilder setWaitForCheckpointsTimeout(final TimeValue waitForCheckpointsTimeout) {
request.setWaitForCheckpointsTimeout(waitForCheckpointsTimeout);
return this;
}

/**
* Specifies what type of requested indices to ignore and wildcard indices expressions.
* <p>
Expand Down
35 changes: 24 additions & 11 deletions x-pack/plugin/fleet/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
/*
* 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.
*/

dependencies {
yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
}
import org.elasticsearch.gradle.internal.info.BuildParams

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

restResources {
restApi {
include '_common', 'bulk', 'cluster', 'nodes', 'indices', 'index', 'xpack', 'security', 'fleet'
}
}

testClusters.configureEach {
testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial'
extraConfigFile 'roles.yml', file('roles.yml')
user username: 'elastic_admin', password: 'admin-password'
user username: 'fleet_unprivileged_secrets', password: 'password', role: 'unprivileged_secrets'
artifacts {
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
}

tasks.named('yamlRestTest') {
usesDefaultDistribution()
}
tasks.named('yamlRestCompatTest') {
usesDefaultDistribution()
}
if (BuildParams.inFipsJvm){
// This test cluster is using a BASIC license and FIPS 140 mode is not supported in BASIC
tasks.named("yamlRestTest").configure{enabled = false }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,43 @@
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.local.distribution.DistributionType;
import org.elasticsearch.test.cluster.util.resource.Resource;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.junit.ClassRule;

public class FleetRestIT extends ESClientYamlSuiteTestCase {

public FleetRestIT(final ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}

@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.setting("xpack.license.self_generated.type", "basic")
.setting("xpack.security.enabled", "true")
.rolesFile(Resource.fromClasspath("roles.yml"))
.user("elastic_admin", "admin-password", "superuser", true)
.user("fleet_unprivileged_secrets", "password", "unprivileged_secrets", true)
.build();

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

@Override
protected Settings restClientSettings() {
String authentication = basicAuthHeaderValue("elastic_admin", new SecureString("admin-password".toCharArray()));
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", authentication).build();
String token = basicAuthHeaderValue("elastic_admin", new SecureString("admin-password".toCharArray()));
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
}

@ParametersFactory
public static Iterable<Object[]> parameters() throws Exception {
return ESClientYamlSuiteTestCase.createParameters();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ setup:
index: "test-after-refresh"
allow_partial_search_results: false
wait_for_checkpoints: 2
wait_for_checkpoints_timeout: 1m
body: { query: { match_all: {} } }

---
Expand All @@ -115,7 +116,7 @@ setup:
body:
- { "allow_partial_search_results": false, wait_for_checkpoints: 1 }
- { query: { match_all: { } } }
- { "allow_partial_search_results": false, wait_for_checkpoints: 2 }
- { "allow_partial_search_results": false, wait_for_checkpoints: 2, wait_for_checkpoints_timeout: 1m }
- { query: { match_all: { } } }

- match: { responses.0._shards.successful: 1 }
Expand All @@ -128,7 +129,7 @@ setup:
- {query: { match_all: {} } }
- { "index": "test-alias", "allow_partial_search_results": false, wait_for_checkpoints: 1 }
- { query: { match_all: { } } }
- {"index": "test-refresh-disabled", "allow_partial_search_results": false, wait_for_checkpoints: 2}
- { "index": "test-refresh-disabled", "allow_partial_search_results": false, wait_for_checkpoints: 2, wait_for_checkpoints_timeout: 1m }
- {query: { match_all: {} } }

- match: { responses.0._shards.successful: 1 }
Expand Down
File renamed without changes.

0 comments on commit bcf1bd4

Please sign in to comment.