QA: Create xpack yaml features (#31403)
This creates a YAML test "features" that indices if the cluster being tested has xpack installed (`xpack`) or if it does *not* have xpack installed (`no_xpack`). It uses those features to centralize skipping a few tests that fail if xpack is installed. The plan is to use this in a followup to skip docs tests that require xpack when xpack is not installed. We *plan* to use the declaration of required license level on the docs page to generate the required `skip`. Closes #30933.
This commit is contained in:
parent
ca4c857a90
commit
232c71b6bf
|
@ -57,13 +57,6 @@ for (Version version : bwcVersions.wireCompatible) {
|
|||
tasks.getByName("${baseName}#mixedClusterTestRunner").configure {
|
||||
/* To support taking index snapshots, we have to set path.repo setting */
|
||||
systemProperty 'tests.path.repo', new File(buildDir, "cluster/shared/repo")
|
||||
if ('zip'.equals(extension.distribution)) {
|
||||
systemProperty 'tests.rest.blacklist', [
|
||||
'cat.templates/10_basic/No templates',
|
||||
'cat.templates/10_basic/Sort templates',
|
||||
'cat.templates/10_basic/Multiple template',
|
||||
].join(',')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
---
|
||||
"No templates":
|
||||
- skip:
|
||||
features: default_shards
|
||||
features: default_shards, no_xpack
|
||||
- do:
|
||||
cat.templates: {}
|
||||
|
||||
|
@ -177,7 +177,7 @@
|
|||
---
|
||||
"Sort templates":
|
||||
- skip:
|
||||
features: default_shards
|
||||
features: default_shards, no_xpack
|
||||
- do:
|
||||
indices.put_template:
|
||||
name: test
|
||||
|
@ -227,7 +227,7 @@
|
|||
---
|
||||
"Multiple template":
|
||||
- skip:
|
||||
features: default_shards
|
||||
features: default_shards, no_xpack
|
||||
- do:
|
||||
indices.put_template:
|
||||
name: test_1
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.http.message.BasicHeader;
|
|||
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
|
@ -40,6 +41,8 @@ import org.elasticsearch.common.io.PathUtils;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -91,13 +94,38 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|||
/**
|
||||
* Convert the entity from a {@link Response} into a map of maps.
|
||||
*/
|
||||
public Map<String, Object> entityAsMap(Response response) throws IOException {
|
||||
public static Map<String, Object> entityAsMap(Response response) throws IOException {
|
||||
XContentType xContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue());
|
||||
try (XContentParser parser = createParser(xContentType.xContent(), response.getEntity().getContent())) {
|
||||
// EMPTY and THROW are fine here because `.map` doesn't use named x content or deprecation
|
||||
try (XContentParser parser = xContentType.xContent().createParser(
|
||||
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
|
||||
response.getEntity().getContent())) {
|
||||
return parser.map();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the cluster being tested have xpack installed?
|
||||
*/
|
||||
public static boolean hasXPack() throws IOException {
|
||||
RestClient client = adminClient();
|
||||
if (client == null) {
|
||||
throw new IllegalStateException("must be called inside of a rest test case test");
|
||||
}
|
||||
Map<?, ?> response = entityAsMap(client.performRequest(new Request("GET", "_nodes/plugins")));
|
||||
Map<?, ?> nodes = (Map<?, ?>) response.get("nodes");
|
||||
for (Map.Entry<?, ?> node : nodes.entrySet()) {
|
||||
Map<?, ?> nodeInfo = (Map<?, ?>) node.getValue();
|
||||
for (Object module: (List<?>) nodeInfo.get("modules")) {
|
||||
Map<?, ?> moduleInfo = (Map<?, ?>) module;
|
||||
if (moduleInfo.get("name").toString().startsWith("x-pack-")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<HttpHost> clusterHosts;
|
||||
/**
|
||||
* A client for the running Elasticsearch cluster
|
||||
|
|
|
@ -19,9 +19,12 @@
|
|||
|
||||
package org.elasticsearch.test.rest.yaml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
/**
|
||||
|
@ -53,11 +56,23 @@ public final class Features {
|
|||
* Tells whether all the features provided as argument are supported
|
||||
*/
|
||||
public static boolean areAllSupported(List<String> features) {
|
||||
for (String feature : features) {
|
||||
if (!SUPPORTED.contains(feature)) {
|
||||
return false;
|
||||
try {
|
||||
for (String feature : features) {
|
||||
if (feature.equals("xpack")) {
|
||||
if (false == ESRestTestCase.hasXPack()) {
|
||||
return false;
|
||||
}
|
||||
} else if (feature.equals("no_xpack")) {
|
||||
if (ESRestTestCase.hasXPack()) {
|
||||
return false;
|
||||
}
|
||||
} else if (false == SUPPORTED.contains(feature)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("error checking if xpack is available", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,18 +20,16 @@ public class MlRestTestStateCleaner {
|
|||
|
||||
private final Logger logger;
|
||||
private final RestClient adminClient;
|
||||
private final ESRestTestCase testCase;
|
||||
|
||||
public MlRestTestStateCleaner(Logger logger, RestClient adminClient, ESRestTestCase testCase) {
|
||||
public MlRestTestStateCleaner(Logger logger, RestClient adminClient) {
|
||||
this.logger = logger;
|
||||
this.adminClient = adminClient;
|
||||
this.testCase = testCase;
|
||||
}
|
||||
|
||||
public void clearMlMetadata() throws IOException {
|
||||
deleteAllDatafeeds();
|
||||
deleteAllJobs();
|
||||
// indices will be deleted by the ESIntegTestCase class
|
||||
// indices will be deleted by the ESRestTestCase class
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -41,7 +39,7 @@ public class MlRestTestStateCleaner {
|
|||
final Response datafeedsResponse = adminClient.performRequest(datafeedsRequest);
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<Map<String, Object>> datafeeds =
|
||||
(List<Map<String, Object>>) XContentMapValues.extractValue("datafeeds", testCase.entityAsMap(datafeedsResponse));
|
||||
(List<Map<String, Object>>) XContentMapValues.extractValue("datafeeds", ESRestTestCase.entityAsMap(datafeedsResponse));
|
||||
if (datafeeds == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -83,7 +81,7 @@ public class MlRestTestStateCleaner {
|
|||
final Response response = adminClient.performRequest(jobsRequest);
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<Map<String, Object>> jobConfigs =
|
||||
(List<Map<String, Object>>) XContentMapValues.extractValue("jobs", testCase.entityAsMap(response));
|
||||
(List<Map<String, Object>>) XContentMapValues.extractValue("jobs", ESRestTestCase.entityAsMap(response));
|
||||
if (jobConfigs == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -29,18 +29,16 @@ public class RollupRestTestStateCleaner {
|
|||
|
||||
private final Logger logger;
|
||||
private final RestClient adminClient;
|
||||
private final ESRestTestCase testCase;
|
||||
|
||||
public RollupRestTestStateCleaner(Logger logger, RestClient adminClient, ESRestTestCase testCase) {
|
||||
public RollupRestTestStateCleaner(Logger logger, RestClient adminClient) {
|
||||
this.logger = logger;
|
||||
this.adminClient = adminClient;
|
||||
this.testCase = testCase;
|
||||
}
|
||||
|
||||
public void clearRollupMetadata() throws Exception {
|
||||
deleteAllJobs();
|
||||
waitForPendingTasks();
|
||||
// indices will be deleted by the ESIntegTestCase class
|
||||
// indices will be deleted by the ESRestTestCase class
|
||||
}
|
||||
|
||||
private void waitForPendingTasks() throws Exception {
|
||||
|
@ -75,7 +73,7 @@ public class RollupRestTestStateCleaner {
|
|||
@SuppressWarnings("unchecked")
|
||||
private void deleteAllJobs() throws Exception {
|
||||
Response response = adminClient.performRequest("GET", "/_xpack/rollup/job/_all");
|
||||
Map<String, Object> jobs = testCase.entityAsMap(response);
|
||||
Map<String, Object> jobs = ESRestTestCase.entityAsMap(response);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> jobConfigs =
|
||||
(List<Map<String, Object>>) XContentMapValues.extractValue("jobs", jobs);
|
||||
|
|
|
@ -252,7 +252,7 @@ public class XPackRestIT extends ESClientYamlSuiteTestCase {
|
|||
*/
|
||||
private void clearMlState() throws Exception {
|
||||
if (isMachineLearningTest()) {
|
||||
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
|
||||
new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@ public class XPackRestIT extends ESClientYamlSuiteTestCase {
|
|||
*/
|
||||
private void clearRollupState() throws Exception {
|
||||
if (isRollupTest()) {
|
||||
new RollupRestTestStateCleaner(logger, adminClient(), this).clearRollupMetadata();
|
||||
new RollupRestTestStateCleaner(logger, adminClient()).clearRollupMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,6 @@ integTestRunner {
|
|||
'index/10_with_id/Index with ID',
|
||||
'indices.get_alias/10_basic/Get alias against closed indices',
|
||||
'indices.get_alias/20_empty/Check empty aliases when getting all aliases via /_alias',
|
||||
'cat.templates/10_basic/No templates',
|
||||
'cat.templates/10_basic/Sort templates',
|
||||
'cat.templates/10_basic/Multiple template',
|
||||
].join(',')
|
||||
|
||||
systemProperty 'tests.rest.cluster.username', System.getProperty('tests.rest.cluster.username', 'test_user')
|
||||
|
|
|
@ -802,7 +802,7 @@ public class DatafeedJobsRestIT extends ESRestTestCase {
|
|||
|
||||
@After
|
||||
public void clearMlState() throws Exception {
|
||||
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
|
||||
new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata();
|
||||
XPackRestTestHelper.waitForPendingTasks(adminClient());
|
||||
}
|
||||
|
||||
|
|
|
@ -676,7 +676,7 @@ public class MlJobIT extends ESRestTestCase {
|
|||
|
||||
@After
|
||||
public void clearMlState() throws Exception {
|
||||
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
|
||||
new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata();
|
||||
XPackRestTestHelper.waitForPendingTasks(adminClient());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue