Skip to content

Commit c4d0f8d

Browse files
committed
[API] Test Runner: Wipe CLuster - updates wiping templates
1 parent e9805c3 commit c4d0f8d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ def self.run(client)
5252
wipe_datastreams(client)
5353
wipe_all_indices(client)
5454
if platinum?
55-
clear_templates_platinum(client)
55+
wipe_templates_for_xpack(client)
56+
else
57+
wipe_all_templates(client)
58+
end
59+
if platinum?
5660
clear_datafeeds(client)
5761
clear_ml_jobs(client)
5862
else
@@ -157,7 +161,7 @@ def clear_cluster_settings(client)
157161
client.cluster.put_settings(body: new_settings) unless new_settings.empty?
158162
end
159163

160-
def clear_templates_platinum(client)
164+
def wipe_templates_for_xpack(client)
161165
templates = client.indices.get_index_template
162166

163167
templates['index_templates'].each do |template|
@@ -178,16 +182,27 @@ def clear_templates_platinum(client)
178182

179183
# Always check for legacy templates
180184
templates = client.indices.get_template
181-
182185
templates.each do |name, _|
183186
next if platinum_template? name
184187

185188
begin
186189
client.indices.delete_template(name: name)
190+
rescue StandardError => e
191+
Elasticsearch::RestAPIYAMLTests::Logging.logger.info("Unable to remove index template #{name}")
187192
end
188193
end
189194
end
190195

196+
def wipe_all_templates(client)
197+
client.indices.delete_template(name: '*')
198+
begin
199+
client.indices.delete_index_template(name: '*')
200+
client.cluster.delete_component_template(name: '*')
201+
rescue StandardError => e
202+
Elasticsearch::RestAPIYAMLTests::Logging.logger.info('Using a version of ES that doesn\'t support index templates v2 yet, so it\'s safe to ignore')
203+
end
204+
end
205+
191206
def platinum_template?(template)
192207
platinum_prefixes = ['.monitoring', '.watch', '.triggered-watches', '.data-frame', '.ml-', '.transform', 'data-streams-mappings'].freeze
193208
platinum_prefixes.map { |a| return true if a.include? template }

0 commit comments

Comments
 (0)