Skip to content

Removing the legacy global template from yaml rest tests #115588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
import org.apache.lucene.tests.util.TimeUnits;
import org.elasticsearch.client.Node;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.client.sniff.ElasticsearchNodesSniffer;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.core.UpdateForV9;
Expand All @@ -41,11 +37,8 @@
import org.elasticsearch.test.rest.yaml.section.ExecutableSection;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -67,8 +60,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;

/**
* Runs a suite of yaml tests shared with all the official Elasticsearch
* clients against an elasticsearch cluster.
Expand Down Expand Up @@ -125,15 +116,6 @@ protected ESClientYamlSuiteTestCase(ClientYamlTestCandidate testCandidate) {
this.testCandidate = testCandidate;
}

private static Settings globalTemplateIndexSettings;

@BeforeClass
public static void initializeGlobalTemplateIndexSettings() {
globalTemplateIndexSettings = usually()
? Settings.EMPTY
: Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2).build();
}

@Before
public void initAndResetContext() throws Exception {
if (restTestExecutionContext == null) {
Expand Down Expand Up @@ -511,34 +493,6 @@ public void test() throws IOException {
inFipsJvm() && testCandidate.getTestSection().getPrerequisiteSection().hasYamlRunnerFeature("fips_140")
);

final Settings globalTemplateSettings = getGlobalTemplateSettings(
testCandidate.getTestSection().getPrerequisiteSection().hasYamlRunnerFeature("default_shards")
);
if (globalTemplateSettings.isEmpty() == false && ESRestTestCase.has(ProductFeature.LEGACY_TEMPLATES)) {

final XContentBuilder template = jsonBuilder();
template.startObject();
{
template.array("index_patterns", "*");
template.startObject("settings");
globalTemplateSettings.toXContent(template, ToXContent.EMPTY_PARAMS);
template.endObject();
}
template.endObject();

final Request request = new Request("PUT", "/_template/global");
request.setJsonEntity(Strings.toString(template));
// Because not all case have transitioned to a composable template, it's possible that
// this can overlap an installed composable template since this is a global (*)
// template. In order to avoid this failing the test, we override the warnings handler
// to be permissive in this case. This can be removed once all tests use composable
// templates instead of legacy templates
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.setWarningsHandler(WarningsHandler.PERMISSIVE);
request.setOptions(builder.build());
adminClient().performRequest(request);
}

if (skipSetupSections() == false && testCandidate.getSetupSection().isEmpty() == false) {
logger.debug("start setup test [{}]", testCandidate.getTestPath());
for (ExecutableSection executableSection : testCandidate.getSetupSection().getExecutableSections()) {
Expand All @@ -562,23 +516,6 @@ public void test() throws IOException {
}
}

@Deprecated
protected Settings getGlobalTemplateSettings(List<String> features) {
if (features.contains("default_shards")) {
return Settings.EMPTY;
} else {
return globalTemplateIndexSettings;
}
}

protected Settings getGlobalTemplateSettings(boolean defaultShardsFeature) {
if (defaultShardsFeature) {
return Settings.EMPTY;
} else {
return globalTemplateIndexSettings;
}
}

protected boolean skipSetupSections() {
return false;
}
Expand Down