Skip to content

Commit ee59761

Browse files
committed
QA: Create xpack yaml features (elastic#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 elastic#30933.
1 parent 2424a1b commit ee59761

File tree

10 files changed

+64
-31
lines changed

10 files changed

+64
-31
lines changed

qa/mixed-cluster/build.gradle

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- skip:
2121
version: " - 5.0.99"
2222
reason: templates were introduced in 5.1.0
23+
features: default_shards, no_xpack
2324
- do:
2425
cat.templates: {}
2526

@@ -197,6 +198,7 @@
197198
- skip:
198199
version: " - 5.99.99"
199200
reason: this uses a new API that has been added in 6.0
201+
features: default_shards, no_xpack
200202
- do:
201203
indices.put_template:
202204
name: test
@@ -248,6 +250,7 @@
248250
- skip:
249251
version: " - 5.99.99"
250252
reason: this uses a new API that has been added in 6.0
253+
features: default_shards, no_xpack
251254
- do:
252255
indices.put_template:
253256
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
@@ -32,6 +32,7 @@
3232
import org.apache.http.ssl.SSLContexts;
3333
import org.elasticsearch.core.internal.io.IOUtils;
3434
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
35+
import org.elasticsearch.client.Request;
3536
import org.elasticsearch.client.Response;
3637
import org.elasticsearch.client.ResponseException;
3738
import org.elasticsearch.client.RestClient;
@@ -41,6 +42,8 @@
4142
import org.elasticsearch.common.settings.Settings;
4243
import org.elasticsearch.common.unit.TimeValue;
4344
import org.elasticsearch.common.util.concurrent.ThreadContext;
45+
import org.elasticsearch.common.xcontent.DeprecationHandler;
46+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
4447
import org.elasticsearch.common.xcontent.XContentBuilder;
4548
import org.elasticsearch.common.xcontent.XContentHelper;
4649
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
/**
@@ -52,11 +55,23 @@ private Features() {
5255
* Tells whether all the features provided as argument are supported
5356
*/
5457
public static boolean areAllSupported(List<String> features) {
55-
for (String feature : features) {
56-
if (!SUPPORTED.contains(feature)) {
57-
return false;
58+
try {
59+
for (String feature : features) {
60+
if (feature.equals("xpack")) {
61+
if (false == ESRestTestCase.hasXPack()) {
62+
return false;
63+
}
64+
} else if (feature.equals("no_xpack")) {
65+
if (ESRestTestCase.hasXPack()) {
66+
return false;
67+
}
68+
} else if (false == SUPPORTED.contains(feature)) {
69+
return false;
70+
}
5871
}
72+
return true;
73+
} catch (IOException e) {
74+
throw new RuntimeException("error checking if xpack is available", e);
5975
}
60-
return true;
6176
}
6277
}

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
@@ -250,7 +250,7 @@ public void cleanup() throws Exception {
250250
*/
251251
private void clearMlState() throws Exception {
252252
if (isMachineLearningTest()) {
253-
new MlRestTestStateCleaner(logger, adminClient(), this).clearMlMetadata();
253+
new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata();
254254
}
255255
}
256256

@@ -261,7 +261,7 @@ private void clearMlState() throws Exception {
261261
*/
262262
private void clearRollupState() throws Exception {
263263
if (isRollupTest()) {
264-
new RollupRestTestStateCleaner(logger, adminClient(), this).clearRollupMetadata();
264+
new RollupRestTestStateCleaner(logger, adminClient()).clearRollupMetadata();
265265
}
266266
}
267267

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ integTestRunner {
1515
['cat.aliases/10_basic/Empty cluster',
1616
'index/10_with_id/Index with ID',
1717
'indices.get_alias/10_basic/Get alias against closed indices',
18-
'cat.templates/10_basic/No templates',
19-
'cat.templates/10_basic/Sort templates',
20-
'cat.templates/10_basic/Multiple template',
18+
'indices.get_alias/20_empty/Check empty aliases when getting all aliases via /_alias',
2119
].join(',')
2220

2321
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)