Skip to content

Commit e915ac3

Browse files
committed
[API] Test Runner: Updates wipe cluster for 8.x
1 parent f92cc45 commit e915ac3

File tree

2 files changed

+61
-48
lines changed

2 files changed

+61
-48
lines changed

api-spec-testing/wipe_cluster.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ def clear_templates_xpack(client)
175175
].freeze
176176

177177
def xpack_template?(template)
178+
return true if template.include?('@')
179+
178180
xpack_prefixes = [
179181
'.monitoring', '.watch', '.triggered-watches', '.data-frame', '.ml-', '.transform',
180182
'data-streams-mappings', 'elastic-connectors'

api-spec-testing/wipe_cluster_8.rb

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ module RestAPIYAMLTests
2323
module WipeCluster8
2424
PRESERVE_ILM_POLICY_IDS = [
2525
'ilm-history-ilm-policy', 'slm-history-ilm-policy', 'watch-history-ilm-policy',
26-
'ml-size-based-ilm-policy', 'logs', 'metrics', 'synthetics', '7-days-default',
27-
'30-days-default', '90-days-default', '180-days-default', '365-days-default',
28-
'.fleet-actions-results-ilm-policy', '.deprecation-indexing-ilm-policy',
29-
'watch-history-ilm-policy-16', '.monitoring-8-ilm-policy'
26+
'watch-history-ilm-policy-16', 'ml-size-based-ilm-policy', 'logs', 'metrics', 'profiling',
27+
'synthetics', '7-days-default', '30-days-default', '90-days-default', '180-days-default',
28+
'365-days-default', '.fleet-files-ilm-policy', '.fleet-file-data-ilm-policy',
29+
'.fleet-actions-results-ilm-policy', '.fleet-file-fromhost-data-ilm-policy',
30+
'.fleet-file-fromhost-meta-ilm-policy', '.fleet-file-tohost-data-ilm-policy',
31+
'.fleet-file-tohost-meta-ilm-policy', '.deprecation-indexing-ilm-policy',
32+
'.monitoring-8-ilm-policy', 'behavioral_analytics-events-default_policy'
3033
].freeze
3134

3235
PLATINUM_TEMPLATES = [
@@ -37,9 +40,7 @@ module WipeCluster8
3740
'synthetics', 'synthetics-settings', 'synthetics-mappings',
3841
'.snapshot-blob-cache', '.deprecation-indexing-template',
3942
'.deprecation-indexing-mappings', '.deprecation-indexing-settings',
40-
'behavioral_analytics-events-mappings', 'behavioral_analytics-events-settings',
41-
'security-index-template', 'data-streams-mappings', 'ecs@dynamic_templates',
42-
'search-acl-filter'
43+
'security-index-template', 'data-streams-mappings', 'search-acl-filter'
4344
].freeze
4445

4546
# Wipe Cluster, based on PHP's implementation of ESRestTestCase.java:wipeCluster()
@@ -51,14 +52,21 @@ def self.run(client)
5152
check_for_unexpectedly_recreated_objects(client)
5253
end
5354

55+
def self.create_xpack_rest_user(client)
56+
client.security.put_user(
57+
username: 'x_pack_rest_user',
58+
body: { password: 'x-pack-test-password', roles: ['superuser'] }
59+
)
60+
end
61+
5462
class << self
5563
private
5664

5765
def wipe_cluster(client)
5866
read_plugins(client)
5967
if @has_rollups
6068
wipe_rollup_jobs(client)
61-
wait_for_pending_rollup_tasks(client)
69+
# wait_for_pending_rollup_tasks(client)
6270
end
6371
delete_all_slm_policies(client)
6472
wipe_searchable_snapshot_indices(client) if @has_xpack
@@ -71,12 +79,13 @@ def wipe_cluster(client)
7179
clear_ml_jobs(client)
7280
clear_datafeeds(client)
7381
delete_data_frame_analytics(client)
74-
delete_filters(client)
75-
clear_transforms(client)
82+
clear_ml_filters(client)
7683
end
7784
delete_all_ilm_policies(client) if @has_ilm
7885
delete_all_follow_patterns(client) if @has_ccr
7986
delete_all_node_shutdown_metadata(client)
87+
clear_tasks(client)
88+
clear_transforms(client)
8089
wipe_calendars(client)
8190
end
8291

@@ -86,7 +95,7 @@ def ensure_no_initializing_shards(client)
8695

8796
def check_for_unexpectedly_recreated_objects(client)
8897
unexpected_ilm_policies = client.ilm.get_lifecycle
89-
unexpected_ilm_policies.reject! { |k, _| PRESERVE_ILM_POLICY_IDS.include? k }
98+
unexpected_ilm_policies.reject! { |k, _| preserve_policy?(k) }
9099
unless unexpected_ilm_policies.empty?
91100
logger.info(
92101
"Expected no ILM policies after deletions, but found #{unexpected_ilm_policies.keys.join(',')}"
@@ -97,12 +106,12 @@ def check_for_unexpectedly_recreated_objects(client)
97106
templates = client.indices.get_index_template
98107
unexpected_templates = templates['index_templates'].reject do |t|
99108
# reject platinum templates
100-
PLATINUM_TEMPLATES.include? t['name']
109+
platinum_template?(t['name'])
101110
end.map { |t| t['name'] } # only keep the names
102111
legacy_templates = client.indices.get_template
103-
unexpected_templates << legacy_templates.keys.reject { |t| PLATINUM_TEMPLATES.include? t }
112+
unexpected_templates << legacy_templates.keys.reject { |t| platinum_template?(t) }
104113

105-
unless unexpected_templates.empty?
114+
unless unexpected_templates.reject(&:empty?).empty?
106115
logger.info(
107116
"Expected no templates after deletions, but found #{unexpected_templates.join(',')}"
108117
)
@@ -136,19 +145,19 @@ def wipe_rollup_jobs(client)
136145

137146
def wait_for_pending_rollup_tasks(client)
138147
filter = 'xpack/rollup/job'
148+
start_time = Time.now.to_i
149+
count = 0
139150
loop do
140151
results = client.cat.tasks(detailed: true).split("\n")
141-
count = 0
142152

143-
time = Time.now.to_i
144153
results.each do |task|
145-
next if task.empty?
154+
next if task.empty? || skippable_task?(task) || task.include?(filter)
146155

147-
logger.debug("Pending task: #{task}")
148-
count += 1 if task.include?(filter)
156+
count += 1
149157
end
150-
break unless count.positive? && Time.now.to_i < (time + 30)
158+
break unless count.positive? && Time.now.to_i < (start_time + 1)
151159
end
160+
logger.debug("Waited for #{count} pending rollup tasks for #{Time.now.to_i - start_time}s.") if count.positive?
152161
end
153162

154163
def delete_all_slm_policies(client)
@@ -229,7 +238,7 @@ def wipe_all_templates(client)
229238
# Always check for legacy templates
230239
templates = client.indices.get_template
231240
templates.each do |name, _|
232-
next if platinum_template? name
241+
next if platinum_template?(name)
233242

234243
begin
235244
client.indices.delete_template(name: name)
@@ -240,35 +249,51 @@ def wipe_all_templates(client)
240249
end
241250

242251
def platinum_template?(template)
252+
return true if template.include?('@')
253+
243254
platinum_prefixes = [
244-
'.monitoring', '.watch', '.triggered-watches', '.data-frame', '.ml-', '.transform',
245-
'data-streams-mappings', 'elastic-connectors'
255+
'.monitoring', '.watch', '.triggered-watches', '.data-frame', '.ml-',
256+
'.transform', '.deprecation', 'data-streams-mappings', '.fleet',
257+
'behavioral_analytics-', 'profiling', 'elastic-connectors', 'ilm-history', '.slm-history'
246258
].freeze
247-
platinum_prefixes.map { |a| return true if (a.include?(template) || template.start_with?(a)) }
259+
return true if template.start_with?(*platinum_prefixes)
248260

249261
PLATINUM_TEMPLATES.include? template
250262
end
251263

264+
def preserve_policy?(policy)
265+
PRESERVE_ILM_POLICY_IDS.include?(policy) || policy.include?('@')
266+
end
267+
252268
def wait_for_cluster_tasks(client)
253-
time = Time.now.to_i
269+
start_time = Time.now.to_i
254270
count = 0
255-
256271
loop do
257272
results = client.cluster.pending_tasks
258273
results['tasks'].each do |task|
259-
next if task.empty?
274+
next if task.empty? || skippable_task?(task)
260275

261-
logger.debug "Pending cluster task: #{task}"
262276
count += 1
263277
end
264-
break unless count.positive? && Time.now.to_i < (time + 10)
278+
break unless count.positive? && Time.now.to_i < (start_time + 5)
279+
end
280+
logger.debug("Waited for #{count} pending cluster tasks for #{Time.now.to_i - start_time}s.") if count.positive?
281+
end
282+
283+
def skippable_task?(task)
284+
names = ['health-node', 'cluster:monitor/tasks/lists', 'create-index-template-v2',
285+
'remove-component-template']
286+
if task.is_a?(String)
287+
names.select { |n| task.match? n }.any?
288+
elsif task.is_a?(Hash)
289+
names.select { |n| task['source'].match? n }.any?
265290
end
266291
end
267292

268293
def delete_all_ilm_policies(client)
269294
policies = client.ilm.get_lifecycle
270295
policies.each do |policy|
271-
client.ilm.delete_lifecycle(policy: policy[0]) unless PRESERVE_ILM_POLICY_IDS.include? policy[0]
296+
client.ilm.delete_lifecycle(policy: policy[0]) unless preserve_policy?(policy[0])
272297
end
273298
end
274299

@@ -294,13 +319,6 @@ def delete_all_follow_patterns(client)
294319
end
295320
end
296321

297-
def create_xpack_rest_user(client)
298-
client.security.put_user(
299-
username: 'x_pack_rest_user',
300-
body: { password: 'x-pack-test-password', roles: ['superuser'] }
301-
)
302-
end
303-
304322
def clear_roles(client)
305323
client.security.get_role.each do |role, _|
306324
begin; client.security.delete_role(name: role); rescue; end
@@ -376,13 +394,6 @@ def delete_all_node_shutdown_metadata(client)
376394
end
377395
end
378396

379-
def wipe_calendars(client)
380-
calendars = client.ml.get_calendars(calendar_id: '_all')['calendars']
381-
calendars.each do |calendar|
382-
client.ml.delete_calendar(calendar_id: calendar['calendar_id'])
383-
end
384-
end
385-
386397
def delete_data_frame_analytics(client)
387398
dfs = client.ml.get_data_frame_analytics
388399
return unless dfs['data_frame_analytics']
@@ -392,10 +403,10 @@ def delete_data_frame_analytics(client)
392403
end
393404
end
394405

395-
def delete_filters(client)
396-
filters = client.ml.get_filters
397-
filters['filters'].each do |filter|
398-
client.ml.delete_filter(filter_id: filter['filter_id'])
406+
def wipe_calendars(client)
407+
calendars = client.ml.get_calendars(calendar_id: '_all')['calendars']
408+
calendars.each do |calendar|
409+
client.ml.delete_calendar(calendar_id: calendar['calendar_id'])
399410
end
400411
end
401412
end

0 commit comments

Comments
 (0)