Skip to content

Commit f561bad

Browse files
authored
QA: Test template creation during rolling restart (#30850)
Adds a test that we create the appropriate x-pack templates during the rolling restart from the pre-6.2 OSS-zip distribution to the new zip distribution that contains xpack. This is one way to answer the question "does xpack acting sanely during the rolling upgrade and after it?" It isn't as good as full exercising xpack but it is fairly simple and would have caught #30832. Relates to #30731
1 parent b4195d3 commit f561bad

File tree

2 files changed

+119
-18
lines changed

2 files changed

+119
-18
lines changed

qa/rolling-upgrade/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ for (Version version : bwcVersions.wireCompatible) {
7272
Task oldClusterTestRunner = tasks.getByName("${baseName}#oldClusterTestRunner")
7373
oldClusterTestRunner.configure {
7474
systemProperty 'tests.rest.suite', 'old_cluster'
75+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
7576
}
7677

7778
Closure configureUpgradeCluster = {String name, Task lastRunner, int stopNode, Closure unicastSeed ->
@@ -96,6 +97,7 @@ for (Version version : bwcVersions.wireCompatible) {
9697
oneThirdUpgradedTestRunner.configure {
9798
systemProperty 'tests.rest.suite', 'mixed_cluster'
9899
systemProperty 'tests.first_round', 'true'
100+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
99101
finalizedBy "${baseName}#oldClusterTestCluster#node1.stop"
100102
}
101103

@@ -108,6 +110,7 @@ for (Version version : bwcVersions.wireCompatible) {
108110
twoThirdsUpgradedTestRunner.configure {
109111
systemProperty 'tests.rest.suite', 'mixed_cluster'
110112
systemProperty 'tests.first_round', 'false'
113+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
111114
finalizedBy "${baseName}#oldClusterTestCluster#node2.stop"
112115
}
113116

@@ -119,6 +122,7 @@ for (Version version : bwcVersions.wireCompatible) {
119122
Task upgradedClusterTestRunner = tasks.getByName("${baseName}#upgradedClusterTestRunner")
120123
upgradedClusterTestRunner.configure {
121124
systemProperty 'tests.rest.suite', 'upgraded_cluster'
125+
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
122126
/*
123127
* Force stopping all the upgraded nodes after the test runner
124128
* so they are alive during the test.

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/XPackIT.java

Lines changed: 115 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@
1919
package org.elasticsearch.upgrades;
2020

2121
import org.apache.http.util.EntityUtils;
22-
import org.elasticsearch.common.Booleans;
22+
import org.elasticsearch.common.xcontent.DeprecationHandler;
23+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
24+
import org.elasticsearch.common.xcontent.XContentParser;
25+
import org.elasticsearch.common.xcontent.json.JsonXContent;
2326
import org.junit.Before;
27+
import org.elasticsearch.Version;
2428
import org.elasticsearch.client.Request;
25-
import org.elasticsearch.client.Response;
2629

2730
import java.io.IOException;
28-
import java.nio.charset.StandardCharsets;
31+
import java.util.ArrayList;
32+
import java.util.Collections;
33+
import java.util.List;
34+
import java.util.Map;
2935

3036
import static org.hamcrest.Matchers.equalTo;
37+
import static org.hamcrest.Matchers.hasSize;
3138
import static org.junit.Assume.assumeThat;
3239

3340
/**
@@ -36,11 +43,9 @@
3643
*/
3744
public class XPackIT extends AbstractRollingTestCase {
3845
@Before
39-
public void skipIfNotXPack() {
46+
public void skipIfNotZip() {
4047
assumeThat("test is only supported if the distribution contains xpack",
4148
System.getProperty("tests.distribution"), equalTo("zip"));
42-
assumeThat("running this on the unupgraded cluster would change its state and it wouldn't work prior to 6.3 anyway",
43-
CLUSTER_TYPE, equalTo(ClusterType.UPGRADED));
4449
/*
4550
* *Mostly* we want this for when we're upgrading from pre-6.3's
4651
* zip distribution which doesn't contain xpack to post 6.3's zip
@@ -50,11 +55,81 @@ public void skipIfNotXPack() {
5055
}
5156

5257
/**
53-
* Test a basic feature (SQL) which doesn't require any trial license.
54-
* Note that the test methods on this class can run in any order so we
55-
* <strong>might</strong> have already installed a trial license.
58+
* Tests that xpack is able to work itself into a sane state during the
59+
* upgrade by testing that it is able to create all of the templates that
60+
* it needs. This isn't a very strong assertion of sanity, but it is better
61+
* than nothing and should catch a few sad cases.
62+
* <p>
63+
* The trouble is that when xpack isn't able to create the templates that
64+
* it needs it retries over and over and over again. This can
65+
* <strong>really</strong> slow things down. This test asserts that xpack
66+
* was able to create the templates so it <strong>shouldn't</strong> be
67+
* spinning trying to create things and slowing down the rest of the
68+
* system.
69+
*/
70+
public void testIndexTemplatesCreated() throws Exception {
71+
Version upgradeFromVersion =
72+
Version.fromString(System.getProperty("tests.upgrade_from_version"));
73+
boolean upgradeFromVersionHasXPack = upgradeFromVersion.onOrAfter(Version.V_6_3_0);
74+
assumeFalse("this test doesn't really prove anything if the starting version has xpack and it is *much* more complex to maintain",
75+
upgradeFromVersionHasXPack);
76+
assumeFalse("since we're upgrading from a version without x-pack it won't have any templates",
77+
CLUSTER_TYPE == ClusterType.OLD);
78+
79+
List<String> expectedTemplates = new ArrayList<>();
80+
// Watcher creates its templates as soon as the first watcher node connects
81+
expectedTemplates.add(".triggered_watches");
82+
expectedTemplates.add(".watch-history-8");
83+
expectedTemplates.add(".watches");
84+
if (masterIsNewVersion()) {
85+
// Everything else waits until the master is upgraded to create its templates
86+
expectedTemplates.add(".ml-anomalies-");
87+
expectedTemplates.add(".ml-meta");
88+
expectedTemplates.add(".ml-notifications");
89+
expectedTemplates.add(".ml-state");
90+
expectedTemplates.add("logstash-index-template");
91+
expectedTemplates.add("security-index-template");
92+
expectedTemplates.add("security_audit_log");
93+
}
94+
Collections.sort(expectedTemplates);
95+
96+
/*
97+
* The index templates are created asynchronously after startup and
98+
* while this is usually fast we use assertBusy here just in case
99+
* they aren't created by the time this test is run.
100+
*/
101+
assertBusy(() -> {
102+
List<String> actualTemplates;
103+
try (XContentParser parser = JsonXContent.jsonXContent.createParser(
104+
NamedXContentRegistry.EMPTY,
105+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
106+
client().performRequest(new Request("GET", "/_template")).getEntity().getContent())) {
107+
actualTemplates = new ArrayList<>(parser.map().keySet());
108+
}
109+
Collections.sort(actualTemplates);
110+
/*
111+
* This test asserts that the templates match *exactly* to force
112+
* us to keep the list of templates up to date. Most templates
113+
* aren't likely to cause a problem on upgrade but it is better
114+
* to be safe and make sure they are all created than to be sorry
115+
* and miss a bug that causes one to be missed on upgrade.
116+
*
117+
* We sort the templates so the error message is easy to read.
118+
*/
119+
assertEquals(expectedTemplates, actualTemplates);
120+
});
121+
}
122+
123+
/**
124+
* Test a basic feature (SQL) after the upgrade which only requires the
125+
* "default" basic license. Note that the test methods on this class can
126+
* run in any order so we <strong>might</strong> have already installed a
127+
* trial license.
56128
*/
57-
public void testBasicFeature() throws IOException {
129+
public void testBasicFeatureAfterUpgrade() throws IOException {
130+
assumeThat("running this on the unupgraded cluster would change its state and it wouldn't work prior to 6.3 anyway",
131+
CLUSTER_TYPE, equalTo(ClusterType.UPGRADED));
132+
58133
Request bulk = new Request("POST", "/sql_test/doc/_bulk");
59134
bulk.setJsonEntity(
60135
"{\"index\":{}}\n"
@@ -71,16 +146,20 @@ public void testBasicFeature() throws IOException {
71146
}
72147

73148
/**
74-
* Test creating a trial license and using it. This is interesting because
75-
* our other tests test cover starting a new cluster with the default
76-
* distribution and enabling the trial license but this test is the only
77-
* one that can upgrade from the oss distribution to the default
78-
* distribution with xpack and the create a trial license. We don't
79-
* <strong>do</strong> a lot with the trial license because for the most
80-
* part those things are tested elsewhere, off in xpack. But we do use the
81-
* trial license a little bit to make sure that it works.
149+
* Test creating a trial license after the upgrade and a feature (ML) that
150+
* requires the license. Our other tests test cover starting a new cluster
151+
* with the default distribution and enabling the trial license but this
152+
* test is the only one tests the rolling upgrade from the oss distribution
153+
* to the default distribution with xpack and then creating of a trial
154+
* license. We don't <strong>do</strong> a lot with the trial license
155+
* because for the most part those things are tested elsewhere, off in
156+
* xpack. But we do use the trial license a little bit to make sure that
157+
* creating it worked properly.
82158
*/
83159
public void testTrialLicense() throws IOException {
160+
assumeThat("running this on the unupgraded cluster would change its state and it wouldn't work prior to 6.3 anyway",
161+
CLUSTER_TYPE, equalTo(ClusterType.UPGRADED));
162+
84163
Request startTrial = new Request("POST", "/_xpack/license/start_trial");
85164
startTrial.addParameter("acknowledge", "true");
86165
client().performRequest(startTrial);
@@ -108,4 +187,22 @@ public void testTrialLicense() throws IOException {
108187
+ "}\n");
109188
client().performRequest(createJob);
110189
}
190+
191+
/**
192+
* Has the master been upgraded to the new version?
193+
*/
194+
private boolean masterIsNewVersion() throws IOException {
195+
Map<?, ?> map;
196+
try (XContentParser parser = JsonXContent.jsonXContent.createParser(
197+
NamedXContentRegistry.EMPTY,
198+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
199+
client().performRequest(new Request("GET", "/_nodes/_master")).getEntity().getContent())) {
200+
map = parser.map();
201+
}
202+
map = (Map<?, ?>) map.get("nodes");
203+
assertThat(map.values(), hasSize(1));
204+
map = (Map<?, ?>) map.values().iterator().next();
205+
Version masterVersion = Version.fromString(map.get("version").toString());
206+
return Version.CURRENT.equals(masterVersion);
207+
}
111208
}

0 commit comments

Comments
 (0)