Skip to content

Commit 204652b

Browse files
committed
Updated the YAML clean up phase
1 parent 1e7ff48 commit 204652b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/Elasticsearch/Tests/Utility.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ private static function wipeCluster(Client $client): void
122122
self::deleteAllSLMPolicies($client);
123123
}
124124

125+
// Clean up searchable snapshots indices before deleting snapshots and repositories
126+
if (getenv('TEST_SUITE') === 'platinum' && version_compare(self::getVersion($client), '7.7.99') > 0) {
127+
self::wipeSearchableSnapshotsIndices($client);
128+
}
129+
125130
self::wipeSnapshots($client);
126131
self::wipeDataStreams($client);
127132
self::wipeAllIndices($client);
@@ -154,6 +159,8 @@ private static function wipeCluster(Client $client): void
154159
self::deleteAllAutoFollowPatterns($client);
155160
self::deleteAllTasks($client);
156161
}
162+
163+
self::deleteAllNodeShutdownMetadata($client);
157164
}
158165

159166
/**
@@ -491,6 +498,7 @@ private static function isXPackTemplate(string $name): bool
491498
case ".deprecation-indexing-template":
492499
case "logstash-index-template":
493500
case "security-index-template":
501+
case "data-streams-mappings":
494502
return true;
495503
}
496504
return false;
@@ -562,6 +570,49 @@ private static function deleteAllTasks(Client $client): void
562570
}
563571
}
564572

573+
/**
574+
* If any nodes are registered for shutdown, removes their metadata
575+
*
576+
* @see https://github.com/elastic/elasticsearch/commit/cea054f7dae215475ea0499bc7060ca7ec05382f
577+
*/
578+
private static function deleteAllNodeShutdownMetadata(Client $client)
579+
{
580+
$nodes = $client->shutdown()->getNode();
581+
if (isset($nodes['_nodes']) && isset($nodes['cluster_name'])) {
582+
// If the response contains these two keys, the feature flag isn't enabled on this cluster, so skip out now.
583+
// We can't check the system property directly because it only gets set for the cluster under test's JVM, not for the test
584+
// runner's JVM.
585+
return;
586+
}
587+
foreach ($nodes['nodes'] as $node) {
588+
$client->shutdown()->deleteNode($node['node_id']);
589+
}
590+
}
591+
592+
/**
593+
* Delete searchable snapshots index
594+
*
595+
* @see https://github.com/elastic/elasticsearch/commit/4927b6917deca6793776cf0c839eadf5ea512b4a
596+
*/
597+
private static function wipeSearchableSnapshotsIndices(Client $client)
598+
{
599+
$indices = $client->cluster()->state([
600+
'metric' => 'metadata',
601+
'filter_path' => 'metadata.indices.*.settings.index.store.snapshot'
602+
]);
603+
if (!isset($indices['metadata']['indices'])) {
604+
return;
605+
}
606+
foreach ($indices['metadata']['indices'] as $index => $value) {
607+
$client->indices()->delete([
608+
'index' => $index,
609+
'client' => [
610+
'ignore' => 404
611+
]
612+
]);
613+
}
614+
}
615+
565616
/**
566617
* Wait for Cluster state updates to finish
567618
*

0 commit comments

Comments
 (0)