mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-16 09:54:55 +00:00
[TEST] fix security template version check in rest tests (elastic/x-pack-elasticsearch#2506)
Since the template upgrade service was added, upgrades should be performed by a node with the highest version in the cluster, which may not be the master node. Original commit: elastic/x-pack-elasticsearch@d66145de54
This commit is contained in:
parent
8d8baffe24
commit
279c7e14fd
@ -5,8 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.security;
|
package org.elasticsearch.xpack.security;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
|
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
|
||||||
@ -14,8 +12,10 @@ import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
|
|||||||
import org.elasticsearch.test.rest.yaml.ObjectPath;
|
import org.elasticsearch.test.rest.yaml.ObjectPath;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.security.SecurityLifecycleService.SECURITY_TEMPLATE_NAME;
|
import static org.elasticsearch.xpack.security.SecurityLifecycleService.SECURITY_TEMPLATE_NAME;
|
||||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||||
@ -37,34 +37,18 @@ public abstract class SecurityClusterClientYamlTestCase extends ESClientYamlSuit
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void waitForSecurity() throws Exception {
|
public static void waitForSecurity() throws Exception {
|
||||||
String masterNode = null;
|
|
||||||
HttpEntity entity = client().performRequest("GET", "/_cat/nodes?h=id,master").getEntity();
|
|
||||||
String catNodesResponse = EntityUtils.toString(entity, StandardCharsets.UTF_8);
|
|
||||||
for (String line : catNodesResponse.split("\n")) {
|
|
||||||
int indexOfStar = line.indexOf('*'); // * in the node's output denotes it is master
|
|
||||||
if (indexOfStar != -1) {
|
|
||||||
masterNode = line.substring(0, indexOfStar).trim();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertNotNull(masterNode);
|
|
||||||
final String masterNodeId = masterNode;
|
|
||||||
|
|
||||||
assertBusy(() -> {
|
assertBusy(() -> {
|
||||||
try {
|
try {
|
||||||
Response nodeDetailsResponse = client().performRequest("GET", "/_nodes");
|
Response nodesResponse = client().performRequest("GET", "/_nodes");
|
||||||
ObjectPath path = ObjectPath.createFromResponse(nodeDetailsResponse);
|
ObjectPath nodesPath = ObjectPath.createFromResponse(nodesResponse);
|
||||||
Map<String, Object> nodes = path.evaluate("nodes");
|
Map<String, Object> nodes = nodesPath.evaluate("nodes");
|
||||||
String masterVersion = null;
|
Set<Version> nodeVersions = new HashSet<>();
|
||||||
for (String key : nodes.keySet()) {
|
for (String nodeId : nodes.keySet()) {
|
||||||
// get the ES version number master is on
|
String nodeVersionPath = "nodes." + nodeId + ".version";
|
||||||
if (key.startsWith(masterNodeId)) {
|
Version nodeVersion = Version.fromString(nodesPath.evaluate(nodeVersionPath));
|
||||||
masterVersion = path.evaluate("nodes." + key + ".version");
|
nodeVersions.add(nodeVersion);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
assertNotNull(masterVersion);
|
Version highestNodeVersion = Collections.max(nodeVersions);
|
||||||
final String masterTemplateVersion = masterVersion;
|
|
||||||
|
|
||||||
Response response = client().performRequest("GET", "/_cluster/state/metadata");
|
Response response = client().performRequest("GET", "/_cluster/state/metadata");
|
||||||
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
||||||
@ -74,10 +58,8 @@ public abstract class SecurityClusterClientYamlTestCase extends ESClientYamlSuit
|
|||||||
assertThat(mappings.size(), greaterThanOrEqualTo(1));
|
assertThat(mappings.size(), greaterThanOrEqualTo(1));
|
||||||
for (String key : mappings.keySet()) {
|
for (String key : mappings.keySet()) {
|
||||||
String templatePath = mappingsPath + "." + key + "._meta.security-version";
|
String templatePath = mappingsPath + "." + key + "._meta.security-version";
|
||||||
String templateVersion = objectPath.evaluate(templatePath);
|
Version templateVersion = Version.fromString(objectPath.evaluate(templatePath));
|
||||||
final Version mVersion = Version.fromString(masterTemplateVersion);
|
assertEquals(highestNodeVersion, templateVersion);
|
||||||
final Version tVersion = Version.fromString(templateVersion);
|
|
||||||
assertTrue(mVersion.onOrBefore(tVersion));
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AssertionError("failed to get cluster state", e);
|
throw new AssertionError("failed to get cluster state", e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user