Skip to content

Commit 232c71b

Browse files
authored
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.
1 parent ca4c857 commit 232c71b

File tree

10 files changed

+63
-34
lines changed

10 files changed

+63
-34
lines changed

qa/mixed-cluster/build.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ for (Version version : bwcVersions.wireCompatible) {
5757
tasks.getByName("${baseName}#mixedClusterTestRunner").configure {
5858
/* To support taking index snapshots, we have to set path.repo setting */
5959
systemProperty 'tests.path.repo', new File(buildDir, "cluster/shared/repo")
60-
if ('zip'.equals(extension.distribution)) {
61-
systemProperty 'tests.rest.blacklist', [
62-
'cat.templates/10_basic/No templates',
63-
'cat.templates/10_basic/Sort templates',
64-
'cat.templates/10_basic/Multiple template',
65-
].join(',')
66-
}
6760
}
6861
}
6962

rest-api-spec/src/main/resources/rest-api-spec/test/cat.templates/10_basic.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
---
1616
"No templates":
1717
- skip:
18-
features: default_shards
18+
features: default_shards, no_xpack
1919
- do:
2020
cat.templates: {}
2121

@@ -177,7 +177,7 @@
177177
---
178178
"Sort templates":
179179
- skip:
180-
features: default_shards
180+
features: default_shards, no_xpack
181181
- do:
182182
indices.put_template:
183183
name: test
@@ -227,7 +227,7 @@
227227
---
228228
"Multiple template":
229229
- skip:
230-
features: default_shards
230+
features: default_shards, no_xpack
231231
- do:
232232
indices.put_template:
233233
name: test_1

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
3232
import org.apache.http.ssl.SSLContexts;
3333
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
34+
import org.elasticsearch.client.Request;
3435
import org.elasticsearch.client.Response;
3536
import org.elasticsearch.client.ResponseException;
3637
import org.elasticsearch.client.RestClient;
@@ -40,6 +41,8 @@
4041
import org.elasticsearch.common.settings.Settings;
4142
import org.elasticsearch.common.unit.TimeValue;
4243
import org.elasticsearch.common.util.concurrent.ThreadContext;
44+
import org.elasticsearch.common.xcontent.DeprecationHandler;
45+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
4346
import org.elasticsearch.common.xcontent.XContentBuilder;
4447
import org.elasticsearch.common.xcontent.XContentHelper;
4548
import org.elasticsearch.common.xcontent.XContentParser;
@@ -91,13 +94,38 @@ public abstract class ESRestTestCase extends ESTestCase {
9194
/**
9295
* Convert the entity from a {@link Response} into a map of maps.
9396
*/
94-
public Map<String, Object> entityAsMap(Response response) throws IOException {
97+
public static Map<String, Object> entityAsMap(Response response) throws IOException {
9598
XContentType xContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue());
96-
try (XContentParser parser = createParser(xContentType.xContent(), response.getEntity().getContent())) {
99+
// EMPTY and THROW are fine here because `.map` doesn't use named x content or deprecation
100+
try (XContentParser parser = xContentType.xContent().createParser(
101+
NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
102+
response.getEntity().getContent())) {
97103
return parser.map();
98104
}
99105
}
100106

107+
/**
108+
* Does the cluster being tested have xpack installed?
109+
*/
110+
public static boolean hasXPack() throws IOException {
111+
RestClient client = adminClient();
112+
if (client == null) {
113+
throw new IllegalStateException("must be called inside of a rest test case test");
114+
}
115+
Map<?, ?> response = entityAsMap(client.performRequest(new Request("GET", "_nodes/plugins")));
116+
Map<?, ?> nodes = (Map<?, ?>) response.get("nodes");
117+
for (Map.Entry<?, ?> node : nodes.entrySet()) {
118+
Map<?, ?> nodeInfo = (Map<?, ?>) node.getValue();
119+
for (Object module: (List<?>) nodeInfo.get("modules")) {
120+
Map<?, ?> moduleInfo = (Map<?, ?>) module;
121+
if (moduleInfo.get("name").toString().startsWith("x-pack-")) {
122+
return true;
123+
}
124+
}
125+
}
126+
return false;
127+
}
128+
101129
private static List<HttpHost> clusterHosts;
102130
/**
103131
* A client for the running Elasticsearch cluster

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Features.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
package org.elasticsearch.test.rest.yaml;
2121

22+
import java.io.IOException;
2223
import java.util.Arrays;
2324
import java.util.List;
2425

26+
import org.elasticsearch.test.rest.ESRestTestCase;
27+
2528
import static java.util.Collections.unmodifiableList;
2629

2730
/**
@@ -53,11 +56,23 @@ private Features() {
5356
* Tells whether all the features provided as argument are supported
5457
*/
5558
public static boolean areAllSupported(List<String> features) {
56-
for (String feature : features) {
57-
if (!SUPPORTED.contains(feature)) {
58-
return false;
59+
try {
60+
for (String feature : features) {
61+
if (feature.equals("xpack")) {
62+
if (false == ESRestTestCase.hasXPack()) {
63+
return false;
64+
}
65+
} else if (feature.equals("no_xpack")) {
66+
if (ESRestTestCase.hasXPack()) {
67+
return false;
68+
}
69+
} else if (false == SUPPORTED.contains(feature)) {
70+
return false;
71+
}
5972
}
73+
return true;
74+
} catch (IOException e) {
75+
throw new RuntimeException("error checking if xpack is available", e);
6076
}
61-
return true;
6277
}
6378
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ public class MlRestTestStateCleaner {
2020

2121
private final Logger logger;
2222
private final RestClient adminClient;
23-
private final ESRestTestCase testCase;
2423

25-
public MlRestTestStateCleaner(Logger logger, RestClient adminClient, ESRestTestCase testCase) {
24+
public MlRestTestStateCleaner(Logger logger, RestClient adminClient) {
2625
this.logger = logger;
2726
this.adminClient = adminClient;
28-
this.testCase = testCase;
2927
}
3028

3129
public void clearMlMetadata() throws IOException {
3230
deleteAllDatafeeds();
3331
deleteAllJobs();
34-
// indices will be deleted by the ESIntegTestCase class
32+
// indices will be deleted by the ESRestTestCase class
3533
}
3634

3735
@SuppressWarnings("unchecked")
@@ -41,7 +39,7 @@ private void deleteAllDatafeeds() throws IOException {
4139
final Response datafeedsResponse = adminClient.performRequest(datafeedsRequest);
4240
@SuppressWarnings("unchecked")
4341
final List<Map<String, Object>> datafeeds =
44-
(List<Map<String, Object>>) XContentMapValues.extractValue("datafeeds", testCase.entityAsMap(datafeedsResponse));
42+
(List<Map<String, Object>>) XContentMapValues.extractValue("datafeeds", ESRestTestCase.entityAsMap(datafeedsResponse));
4543
if (datafeeds == null) {
4644
return;
4745
}
@@ -83,7 +81,7 @@ private void deleteAllJobs() throws IOException {
8381
final Response response = adminClient.performRequest(jobsRequest);
8482
@SuppressWarnings("unchecked")
8583
final List<Map<String, Object>> jobConfigs =
86-
(List<Map<String, Object>>) XContentMapValues.extractValue("jobs", testCase.entityAsMap(response));
84+
(List<Map<String, Object>>) XContentMapValues.extractValue("jobs", ESRestTestCase.entityAsMap(response));
8785
if (jobConfigs == null) {
8886
return;
8987
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/RollupRestTestStateCleaner.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,16 @@ public class RollupRestTestStateCleaner {
2929

3030
private final Logger logger;
3131
private final RestClient adminClient;
32-
private final ESRestTestCase testCase;
3332

34-
public RollupRestTestStateCleaner(Logger logger, RestClient adminClient, ESRestTestCase testCase) {
33+
public RollupRestTestStateCleaner(Logger logger, RestClient adminClient) {
3534
this.logger = logger;
3635
this.adminClient = adminClient;
37-
this.testCase = testCase;
3836
}
3937

4038
public void clearRollupMetadata() throws Exception {
4139
deleteAllJobs();
4240
waitForPendingTasks();
43-
// indices will be deleted by the ESIntegTestCase class
41+
// indices will be deleted by the ESRestTestCase class
4442
}
4543

4644
private void waitForPendingTasks() throws Exception {
@@ -75,7 +73,7 @@ private void waitForPendingTasks() throws Exception {
7573
@SuppressWarnings("unchecked")
7674
private void deleteAllJobs() throws Exception {
7775
Response response = adminClient.performRequest("GET", "/_xpack/rollup/job/_all");
78-
Map<String, Object> jobs = testCase.entityAsMap(response);
76+
Map<String, Object> jobs = ESRestTestCase.entityAsMap(response);
7977
@SuppressWarnings("unchecked")
8078
List<Map<String, Object>> jobConfigs =
8179
(List<Map<String, Object>>) XContentMapValues.extractValue("jobs", jobs);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public void cleanup() throws Exception {
252252
*/
253253
private void clearMlState() throws Exception {
254254
if (isMachineLearningTest()) {
255-
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
255+
new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata();
256256
}
257257
}
258258

@@ -263,7 +263,7 @@ private void clearMlState() throws Exception {
263263
*/
264264
private void clearRollupState() throws Exception {
265265
if (isRollupTest()) {
266-
new RollupRestTestStateCleaner(logger, adminClient(), this).clearRollupMetadata();
266+
new RollupRestTestStateCleaner(logger, adminClient()).clearRollupMetadata();
267267
}
268268
}
269269

x-pack/qa/core-rest-tests-with-security/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ integTestRunner {
1616
'index/10_with_id/Index with ID',
1717
'indices.get_alias/10_basic/Get alias against closed indices',
1818
'indices.get_alias/20_empty/Check empty aliases when getting all aliases via /_alias',
19-
'cat.templates/10_basic/No templates',
20-
'cat.templates/10_basic/Sort templates',
21-
'cat.templates/10_basic/Multiple template',
2219
].join(',')
2320

2421
systemProperty 'tests.rest.cluster.username', System.getProperty('tests.rest.cluster.username', 'test_user')

x-pack/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ public static void openJob(RestClient client, String jobId) throws IOException {
802802

803803
@After
804804
public void clearMlState() throws Exception {
805-
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
805+
new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata();
806806
XPackRestTestHelper.waitForPendingTasks(adminClient());
807807
}
808808

x-pack/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ private static String responseEntityToString(Response response) throws IOExcepti
676676

677677
@After
678678
public void clearMlState() throws Exception {
679-
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
679+
new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata();
680680
XPackRestTestHelper.waitForPendingTasks(adminClient());
681681
}
682682
}

0 commit comments

Comments
 (0)