Skip to content

Commit 304e105

Browse files
committed
fixup! Test
1 parent ce405e2 commit 304e105

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/FileSettingsRoleMappingUpgradeIT.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.upgrades;
1111

1212
import com.carrotsearch.randomizedtesting.annotations.Name;
13+
1314
import org.elasticsearch.client.Request;
1415
import org.elasticsearch.core.SuppressForbidden;
1516
import org.elasticsearch.test.XContentTestUtils;
@@ -90,20 +91,26 @@ public void checkVersions() {
9091
);
9192
}
9293

93-
protected static void waitForSecurityMigrationCompletion() throws Exception {
94+
private static void waitForSecurityMigrationCompletionIfIndexExists() throws Exception {
9495
final Request request = new Request("GET", "_cluster/state/metadata/.security-7");
9596
assertBusy(() -> {
9697
Map<String, Object> indices = new XContentTestUtils.JsonMapView(entityAsMap(client().performRequest(request))).get(
9798
"metadata.indices"
9899
);
99100
assertNotNull(indices);
100-
// JsonMapView doesn't support . prefixed indices (splits on .)
101-
@SuppressWarnings("unchecked")
102-
String responseVersion = new XContentTestUtils.JsonMapView((Map<String, Object>) indices.get(".security-7")).get(
103-
"migration_version.version"
104-
);
105-
assertNotNull(responseVersion);
106-
assertTrue(Integer.parseInt(responseVersion) >= ROLE_MAPPINGS_CLEANUP_MIGRATION_VERSION);
101+
// If the security index exists, migration needs to happen. There is a bug in pre cluster state role mappings code that tries
102+
// to write file based role mappings before security index manager state is recovered, this makes it look like the security
103+
// index is outdated (isIndexUpToDate == false). Because we can't rely on the index being there for old versions, this check
104+
// is needed.
105+
if (indices.containsKey(".security-7")) {
106+
// JsonMapView doesn't support . prefixed indices (splits on .)
107+
@SuppressWarnings("unchecked")
108+
String responseVersion = new XContentTestUtils.JsonMapView((Map<String, Object>) indices.get(".security-7")).get(
109+
"migration_version.version"
110+
);
111+
assertNotNull(responseVersion);
112+
assertTrue(Integer.parseInt(responseVersion) >= ROLE_MAPPINGS_CLEANUP_MIGRATION_VERSION);
113+
}
107114
});
108115
}
109116

@@ -123,7 +130,7 @@ public void testRoleMappingsAppliedOnUpgrade() throws Exception {
123130
).get("metadata.role_mappings.role_mappings");
124131
assertThat(clusterStateRoleMappings, is(not(nullValue())));
125132
assertThat(clusterStateRoleMappings.size(), equalTo(1));
126-
waitForSecurityMigrationCompletion();
133+
waitForSecurityMigrationCompletionIfIndexExists();
127134
assertThat(
128135
entityAsMap(client().performRequest(new Request("GET", "/_security/role_mapping"))).keySet(),
129136
contains("everyone_kibana-read-only-operator-mapping")

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractUpgradeTestCase.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
*/
77
package org.elasticsearch.upgrades;
88

9-
import org.apache.logging.log4j.LogManager;
10-
import org.apache.logging.log4j.Logger;
119
import org.elasticsearch.Build;
1210
import org.elasticsearch.Version;
1311
import org.elasticsearch.client.Request;
@@ -167,8 +165,6 @@ public void setupForTests() throws Exception {
167165
});
168166
}
169167

170-
private static final Logger log = LogManager.getLogger(AbstractUpgradeTestCase.class);
171-
172168
protected static void waitForSecurityMigrationCompletion(RestClient adminClient, int version) throws Exception {
173169
final Request request = new Request("GET", "_cluster/state/metadata/.security-7");
174170
assertBusy(() -> {

0 commit comments

Comments
 (0)