-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly support capabilities checks with mixed version clusters (#10…
…8513) When a capabilities check is done on a cluster with some nodes that do not support capabilities, always return false
- Loading branch information
Showing
7 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/NodesCapabilitiesUpgradeIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.upgrades; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.Name; | ||
|
||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.core.UpdateForV9; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.test.hamcrest.OptionalMatchers.isPresentWith; | ||
|
||
@UpdateForV9 | ||
public class NodesCapabilitiesUpgradeIT extends AbstractRollingUpgradeTestCase { | ||
|
||
private static Boolean upgradingBeforeCapabilities; | ||
|
||
public NodesCapabilitiesUpgradeIT(@Name("upgradedNodes") int upgradedNodes) { | ||
super(upgradedNodes); | ||
} | ||
|
||
@Before | ||
public void checkBeforeHasNoCapabilities() throws IOException { | ||
if (upgradingBeforeCapabilities == null) { | ||
// try to do a _capabilities query on a node before we upgrade | ||
try { | ||
clusterHasCapability("GET", "_capabilities", List.of(), List.of()); | ||
upgradingBeforeCapabilities = false; | ||
} catch (ResponseException e) { | ||
if (e.getResponse().getStatusLine().getStatusCode() == 400) { | ||
upgradingBeforeCapabilities = true; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
assumeTrue("Only valid when upgrading from versions without capabilities API", upgradingBeforeCapabilities); | ||
} | ||
|
||
public void testCapabilitiesReturnsFalsePartiallyUpgraded() throws IOException { | ||
if (isMixedCluster()) { | ||
// capabilities checks should either fail (if talking to an old node), | ||
// or return false as not all nodes have the API (if talking to a new node) | ||
try { | ||
assertThat( | ||
"Upgraded node should report no capabilities supported", | ||
clusterHasCapability("GET", "_capabilities", List.of(), List.of()), | ||
isPresentWith(false) | ||
); | ||
} catch (ResponseException e) { | ||
if (e.getResponse().getStatusLine().getStatusCode() != 400) { | ||
// throw explicitly to capture exception too | ||
throw new AssertionError("Old node should not have the capabilities API", e); | ||
} | ||
} | ||
} | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/capabilities/10_basic.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters