Skip to content

Commit 5b8bb7f

Browse files
authored
[7.13] Delete mounted indices after test case in ESRestTestCase (#73649)
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 10cb774 commit 5b8bb7f

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
@@ -567,6 +567,15 @@ protected boolean preserveAutoFollowPatternsUponCompletion() {
567567
return false;
568568
}
569569

570+
/**
571+
* Returns whether to preserve searchable snapshots indices. Defaults to not
572+
* preserving them. Only runs at all if xpack is installed on the cluster
573+
* being tested.
574+
*/
575+
protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
576+
return false;
577+
}
578+
570579
/**
571580
* Returns whether to wait to make absolutely certain that all snapshots
572581
* have been deleted.
@@ -591,6 +600,11 @@ private void wipeCluster() throws Exception {
591600
}
592601
}
593602

603+
// Clean up searchable snapshots indices before deleting snapshots and repositories
604+
if (hasXPack() && nodeVersions.first().onOrAfter(Version.V_7_8_0) && preserveSearchableSnapshotsIndicesUponCompletion() == false) {
605+
wipeSearchableSnapshotsIndices();
606+
}
607+
594608
SetOnce<Map<String, List<Map<?,?>>>> inProgressSnapshots = new SetOnce<>();
595609
if (waitForAllSnapshotsWiped()) {
596610
AtomicReference<Map<String, List<Map<?,?>>>> snapshots = new AtomicReference<>();
@@ -796,6 +810,22 @@ protected static void wipeDataStreams() throws IOException {
796810
}
797811
}
798812

813+
protected void wipeSearchableSnapshotsIndices() throws IOException {
814+
// retrieves all indices with a type of store equals to "snapshot"
815+
final Request request = new Request("GET", "_cluster/state/metadata");
816+
request.addParameter("filter_path", "metadata.indices.*.settings.index.store.snapshot");
817+
818+
final Response response = adminClient().performRequest(request);
819+
@SuppressWarnings("unchecked")
820+
Map<String, ?> indices = (Map<String, ?>) XContentMapValues.extractValue("metadata.indices", entityAsMap(response));
821+
if (indices != null) {
822+
for (String index : indices.keySet()) {
823+
assertAcked("Failed to delete searchable snapshot index [" + index + ']',
824+
adminClient().performRequest(new Request("DELETE", index)));
825+
}
826+
}
827+
}
828+
799829
/**
800830
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
801831
* 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
@@ -99,6 +99,11 @@ protected boolean preserveSnapshotsUponCompletion() {
9999
return true;
100100
}
101101

102+
@Override
103+
protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
104+
return true;
105+
}
106+
102107
public UpgradeClusterClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) {
103108
super(testCandidate);
104109
}

0 commit comments

Comments
 (0)