Skip to content

Commit b263b0f

Browse files
committed
[API] Test Runner - wipe_cluster: Updates logging
1 parent ab2a697 commit b263b0f

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
module Elasticsearch
2121
module RestAPIYAMLTests
2222
module Logging
23-
def self.logger
23+
def logger
2424
@logger ||= Logger.new($stdout)
2525
end
2626
end

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class SkipTestsException < StandardError
3131
#
3232
# @since 6.2.0
3333
class TestFile
34+
include Elasticsearch::RestAPIYAMLTests::Logging
3435
attr_reader :features_to_skip, :name, :client
3536

3637
# Initialize a single test file.
@@ -49,8 +50,8 @@ def initialize(file_name, client, features_to_skip = [])
4950
begin
5051
documents = YAML.load_stream(File.new(file_name))
5152
rescue StandardError => e
52-
Elasticsearch::RestAPIYAMLTests::Logging.logger.error e
53-
Elasticsearch::RestAPIYAMLTests::Logging.logger.error "Filename : #{@name}"
53+
logger.error e
54+
logger.error "Filename : #{@name}"
5455
end
5556
@test_definitions = documents.reject { |doc| doc['setup'] || doc['teardown'] }
5657
@setup = documents.find { |doc| doc['setup'] }
@@ -156,7 +157,7 @@ def run_actions_and_retry(actions)
156157
# happening
157158
count += 1
158159
sleep 10
159-
Elasticsearch::RestAPIYAMLTests::Logging.logger.debug(
160+
logger.debug(
160161
"The server responded with an #{e.class} error. Retrying action - (#{count})"
161162
)
162163
raise e if count > 11
@@ -166,9 +167,7 @@ def run_actions_and_retry(actions)
166167
end
167168
break if actions.empty?
168169
end
169-
170170
end
171-
172171
end
173172
end
174173
end

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
require_relative 'logging'
19+
include Elasticsearch::RestAPIYAMLTests::Logging
1920

2021
module Elasticsearch
2122
module RestAPIYAMLTests
@@ -67,12 +68,10 @@ def wipe_cluster(client)
6768
wipe_all_templates(client)
6869
end
6970
wipe_cluster_settings(client)
70-
7171
if platinum?
7272
clear_ml_jobs(client)
7373
clear_datafeeds(client)
7474
end
75-
7675
delete_all_ilm_policies(client) if @has_ilm
7776
delete_all_follow_patterns(client) if @has_ccr
7877
delete_all_node_shutdown_metadata(client)
@@ -88,9 +87,11 @@ def ensure_no_initializing_shards(client)
8887
def check_for_unexpectedly_recreated_objects(client)
8988
unexpected_ilm_policies = client.index_lifecycle_management.get_lifecycle
9089
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?
90+
unless unexpected_ilm_policies.empty?
91+
logger.info(
92+
"Expected no ILM policies after deletions, but found #{unexpected_ilm_policies.keys.join(',')}"
93+
)
94+
end
9495
return unless platinum?
9596

9697
templates = client.indices.get_index_template
@@ -101,9 +102,11 @@ def check_for_unexpectedly_recreated_objects(client)
101102
legacy_templates = client.indices.get_template
102103
unexpected_templates << legacy_templates.keys.reject { |t| PLATINUM_TEMPLATES.include? t }
103104

104-
Elasticsearch::RestAPIYAMLTests::Logging.logger.info(
105-
"Expected no templates after deletions, but found #{unexpected_templates.join(',')}"
106-
) unless unexpected_templates.empty?
105+
unless unexpected_templates.empty?
106+
logger.info(
107+
"Expected no templates after deletions, but found #{unexpected_templates.join(',')}"
108+
)
109+
end
107110
end
108111

109112
def platinum?
@@ -141,7 +144,7 @@ def wait_for_pending_rollup_tasks(client)
141144
results.each do |task|
142145
next if task.empty?
143146

144-
Elasticsearch::RestAPIYAMLTests::Logging.logger.debug("Pending task: #{task}")
147+
logger.debug("Pending task: #{task}")
145148
count += 1 if task.include?(filter)
146149
end
147150
break unless count.positive? && Time.now.to_i < (time + 30)
@@ -161,12 +164,12 @@ def wipe_searchable_snapshot_indices(client)
161164
return unless indices.dig('metadata', 'indices')
162165

163166
indices['metadata']['indices'].each do |index|
164-
case index.class
165-
when Array
166-
client.indices.delete(index: index[0], ignore: 404)
167-
when Hash
168-
client.indices.delete(index: index.keys.first, ignore: 404)
169-
end
167+
index_name = if index.is_a?(Array)
168+
index[0]
169+
elsif index.is_a?(Hash)
170+
index.keys.first
171+
end
172+
client.indices.delete(index: index_name, ignore: 404)
170173
end
171174
end
172175

@@ -176,11 +179,13 @@ def wipe_snapshots(client)
176179
repositories = client.snapshot.get_repository(repository: '_all')
177180
break if repositories.empty?
178181

179-
repositories = client.snapshot.get_repository(repository: '_all')
180182
repositories.each_key do |repository|
181183
if repositories[repository]['type'] == 'fs'
182184
response = client.snapshot.get(repository: repository, snapshot: '_all', ignore_unavailable: true)
183185
response['snapshots'].each do |snapshot|
186+
if snapshot['state'] != 'SUCCESS'
187+
logger.debug("Found snapshot that did not succeed #{snapshot}")
188+
end
184189
client.snapshot.delete(repository: repository, snapshot: snapshot['snapshot'], ignore: 404)
185190
end
186191
end
@@ -193,7 +198,7 @@ def wipe_datastreams(client)
193198
begin
194199
client.indices.delete_data_stream(name: '*', expand_wildcards: 'all')
195200
rescue StandardError => e
196-
Elasticsearch::RestAPIYAMLTests::Logging.logger.error "Caught exception attempting to delete data streams: #{e}"
201+
logger.error "Caught exception attempting to delete data streams: #{e}"
197202
client.indices.delete_data_stream(name: '*')
198203
end
199204
end
@@ -229,7 +234,7 @@ def wipe_templates_for_xpack(client)
229234
begin
230235
client.indices.delete_template(name: name)
231236
rescue StandardError => e
232-
Elasticsearch::RestAPIYAMLTests::Logging.logger.info("Unable to remove index template #{name}")
237+
logger.info("Unable to remove index template #{name}")
233238
end
234239
end
235240
end
@@ -240,7 +245,7 @@ def wipe_all_templates(client)
240245
client.indices.delete_index_template(name: '*')
241246
client.cluster.delete_component_template(name: '*')
242247
rescue StandardError => e
243-
Elasticsearch::RestAPIYAMLTests::Logging.logger.info('Using a version of ES that doesn\'t support index templates v2 yet, so it\'s safe to ignore')
248+
logger.info('Using a version of ES that doesn\'t support index templates v2 yet, so it\'s safe to ignore')
244249
end
245250
end
246251

@@ -260,7 +265,7 @@ def wait_for_cluster_tasks(client)
260265
results['tasks'].each do |task|
261266
next if task.empty?
262267

263-
Elasticsearch::RestAPIYAMLTests::Logging.logger.debug "Pending cluster task: #{task}"
268+
logger.debug "Pending cluster task: #{task}"
264269
count += 1
265270
end
266271
break unless count.positive? && Time.now.to_i < (time + 30)

0 commit comments

Comments
 (0)