Skip to content

Commit 4927b69

Browse files
authored
Delete mounted indices after test case in ESRestTestCase (#73650)
This commit adds some clean up logic to ESRestTestCase so that searchable snapshots indices are deleted after test case executions, before the snapshot and repositories are wipe out. Backport of #73555
1 parent f5a1d94 commit 4927b69

File tree

8 files changed

+40
-61
lines changed

8 files changed

+40
-61
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,15 @@ protected boolean preserveSLMPoliciesUponCompletion() {
539539
return false;
540540
}
541541

542+
/**
543+
* Returns whether to preserve searchable snapshots indices. Defaults to not
544+
* preserving them. Only runs at all if xpack is installed on the cluster
545+
* being tested.
546+
*/
547+
protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
548+
return false;
549+
}
550+
542551
/**
543552
* Returns whether to wait to make absolutely certain that all snapshots
544553
* have been deleted.
@@ -560,6 +569,11 @@ private void wipeCluster() throws Exception {
560569
deleteAllSLMPolicies();
561570
}
562571

572+
// Clean up searchable snapshots indices before deleting snapshots and repositories
573+
if (hasXPack() && nodeVersions.first().onOrAfter(Version.V_7_8_0) && preserveSearchableSnapshotsIndicesUponCompletion() == false) {
574+
wipeSearchableSnapshotsIndices();
575+
}
576+
563577
SetOnce<Map<String, List<Map<?,?>>>> inProgressSnapshots = new SetOnce<>();
564578
if (waitForAllSnapshotsWiped()) {
565579
AtomicReference<Map<String, List<Map<?,?>>>> snapshots = new AtomicReference<>();
@@ -787,6 +801,22 @@ protected static void wipeDataStreams() throws IOException {
787801
}
788802
}
789803

804+
protected void wipeSearchableSnapshotsIndices() throws IOException {
805+
// retrieves all indices with a type of store equals to "snapshot"
806+
final Request request = new Request("GET", "_cluster/state/metadata");
807+
request.addParameter("filter_path", "metadata.indices.*.settings.index.store.snapshot");
808+
809+
final Response response = adminClient().performRequest(request);
810+
@SuppressWarnings("unchecked")
811+
Map<String, ?> indices = (Map<String, ?>) XContentMapValues.extractValue("metadata.indices", entityAsMap(response));
812+
if (indices != null) {
813+
for (String index : indices.keySet()) {
814+
assertAcked("Failed to delete searchable snapshot index [" + index + ']',
815+
adminClient().performRequest(new Request("DELETE", index)));
816+
}
817+
}
818+
}
819+
790820
/**
791821
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
792822
* start empty. There isn't an API to delete all snapshots. There is an API to delete all snapshot repositories but that leaves all of

x-pack/plugin/searchable-snapshots/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/clear_cache.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ setup:
5151
indices.delete:
5252
index: docs
5353

54-
---
55-
teardown:
56-
57-
- do:
58-
snapshot.delete:
59-
repository: repository-fs
60-
snapshot: snapshot
61-
ignore: 404
62-
63-
- do:
64-
snapshot.delete_repository:
65-
repository: repository-fs
66-
6754
---
6855
"Clear searchable snapshots cache":
6956
- skip:

x-pack/plugin/searchable-snapshots/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/indices_stats.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ setup:
5353
- do:
5454
indices.delete:
5555
index: docs
56-
---
57-
teardown:
58-
59-
- do:
60-
snapshot.delete:
61-
repository: repository-fs
62-
snapshot: snapshot
63-
ignore: 404
64-
65-
- do:
66-
snapshot.delete_repository:
67-
repository: repository-fs
6856

6957
---
7058
"Tests Indices Stats API for snapshot backed indices":

x-pack/plugin/searchable-snapshots/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/pit.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ setup:
5050
- do:
5151
indices.delete:
5252
index: docs
53-
---
54-
teardown:
55-
56-
- do:
57-
snapshot.delete:
58-
repository: repository-fs
59-
snapshot: snapshot
60-
ignore: 404
61-
62-
- do:
63-
snapshot.delete_repository:
64-
repository: repository-fs
6553

6654
---
6755
"Tests searches vs default-storage index":

x-pack/plugin/searchable-snapshots/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/shared_cache_stats.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ setup:
5353
- do:
5454
indices.delete:
5555
index: docs
56-
---
57-
teardown:
58-
59-
- do:
60-
snapshot.delete:
61-
repository: repository-fs
62-
snapshot: snapshot
63-
ignore: 404
64-
65-
- do:
66-
snapshot.delete_repository:
67-
repository: repository-fs
6856

6957
---
7058
"Node Cache Stats API with Frozen Indices":

x-pack/plugin/searchable-snapshots/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/stats.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ setup:
5050
- do:
5151
indices.delete:
5252
index: docs
53-
---
54-
teardown:
55-
56-
- do:
57-
snapshot.delete:
58-
repository: repository-fs
59-
snapshot: snapshot
60-
ignore: 404
61-
62-
- do:
63-
snapshot.delete_repository:
64-
repository: repository-fs
6553

6654
---
6755
"Tests searchable snapshots stats":

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ protected boolean preserveDataStreamsUponCompletion() {
6565
return true;
6666
}
6767

68+
@Override
69+
protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
70+
return true;
71+
}
72+
6873
enum ClusterType {
6974
OLD,
7075
MIXED,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ protected boolean preserveSnapshotsUponCompletion() {
106106
return true;
107107
}
108108

109+
@Override
110+
protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
111+
return true;
112+
}
113+
109114
public UpgradeClusterClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) {
110115
super(testCandidate);
111116
}

0 commit comments

Comments
 (0)