Skip to content

Commit 2217ba3

Browse files
committed
[API] Refactors and updates wipe_cluster
Adds ensure_no_initializing_shards and check_for_unexpectedly_recreated_objects
1 parent a871e44 commit 2217ba3

File tree

1 file changed

+60
-29
lines changed

1 file changed

+60
-29
lines changed

elasticsearch-api/api-spec-testing/wipe_cluster.rb

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,71 @@ module WipeCluster
4141
# Wipe Cluster, based on PHP's implementation of ESRestTestCase.java:wipeCluster()
4242
# https://github.com/elastic/elasticsearch-php/blob/7.10/tests/Elasticsearch/Tests/Utility.php#L97
4343
def self.run(client)
44-
read_plugins(client)
45-
if @has_rollups
46-
wipe_rollup_jobs(client)
47-
wait_for_pending_rollup_tasks(client)
48-
end
49-
delete_all_slm_policies(client)
50-
wipe_searchable_snapshot_indices(client) if @has_xpack
51-
wipe_snapshots(client)
52-
wipe_datastreams(client)
53-
wipe_all_indices(client)
54-
if platinum?
55-
wipe_templates_for_xpack(client)
56-
else
57-
wipe_all_templates(client)
58-
end
59-
wipe_cluster_settings(client)
60-
61-
if platinum?
62-
clear_ml_jobs(client)
63-
clear_datafeeds(client)
64-
end
65-
66-
delete_all_ilm_policies(client) if @has_ilm
67-
delete_all_follow_patterns(client) if @has_ccr
68-
delete_all_node_shutdown_metadata(client)
69-
# clear_ml_filters(client)
70-
# clear_tasks(client)
71-
# clear_transforms(client)
44+
ensure_no_initializing_shards(client)
45+
wipe_cluster(client)
7246
wait_for_cluster_tasks(client)
47+
check_for_unexpectedly_recreated_objects(client)
7348
end
7449

7550
class << self
7651
private
7752

53+
def wipe_cluster(client)
54+
read_plugins(client)
55+
if @has_rollups
56+
wipe_rollup_jobs(client)
57+
wait_for_pending_rollup_tasks(client)
58+
end
59+
delete_all_slm_policies(client)
60+
wipe_searchable_snapshot_indices(client) if @has_xpack
61+
wipe_snapshots(client)
62+
wipe_datastreams(client)
63+
wipe_all_indices(client)
64+
if platinum?
65+
wipe_templates_for_xpack(client)
66+
else
67+
wipe_all_templates(client)
68+
end
69+
wipe_cluster_settings(client)
70+
71+
if platinum?
72+
clear_ml_jobs(client)
73+
clear_datafeeds(client)
74+
end
75+
76+
delete_all_ilm_policies(client) if @has_ilm
77+
delete_all_follow_patterns(client) if @has_ccr
78+
delete_all_node_shutdown_metadata(client)
79+
# clear_ml_filters(client)
80+
# clear_tasks(client)
81+
# clear_transforms(client)
82+
end
83+
84+
def ensure_no_initializing_shards(client)
85+
client.cluster.health(wait_for_no_initializing_shards: true, timeout: '70s', level: 'shards')
86+
end
87+
88+
def check_for_unexpectedly_recreated_objects(client)
89+
unexpected_ilm_policies = client.index_lifecycle_management.get_lifecycle
90+
unexpected_ilm_policies.reject! { |k, _| PRESERVE_ILM_POLICY_IDS.include? k }
91+
Elasticsearch::RestAPIYAMLTests::Logging.logger.info(
92+
"Expected no ILM policies after deletions, but found #{unexpected_ilm_policies.keys.join(',')}"
93+
) unless unexpected_ilm_policies.empty?
94+
return unless platinum?
95+
96+
templates = client.indices.get_index_template
97+
unexpected_templates = templates['index_templates'].reject do |t|
98+
# reject platinum templates
99+
PLATINUM_TEMPLATES.include? t['name']
100+
end.map { |t| t['name'] } # only keep the names
101+
legacy_templates = client.indices.get_template
102+
unexpected_templates << legacy_templates.keys.reject { |t| PLATINUM_TEMPLATES.include? t }
103+
104+
Elasticsearch::RestAPIYAMLTests::Logging.logger.info(
105+
"Expected no templates after deletions, but found #{unexpected_templates.join(',')}"
106+
) unless unexpected_templates.empty?
107+
end
108+
78109
def platinum?
79110
ENV['TEST_SUITE'] == 'platinum'
80111
end
@@ -110,7 +141,7 @@ def wait_for_pending_rollup_tasks(client)
110141
results.each do |task|
111142
next if task.empty?
112143

113-
Elasticsearch::RestAPIYAMLTests::Logging.logger.debug "Pending task: #{task}"
144+
Elasticsearch::RestAPIYAMLTests::Logging.logger.debug("Pending task: #{task}")
114145
count += 1 if task.include?(filter)
115146
end
116147
break unless count.positive? && Time.now.to_i < (time + 30)

0 commit comments

Comments
 (0)