Skip to content

Commit 252a249

Browse files
committed
Move log fetching into per-example failure :after hook
1 parent 80a08e0 commit 252a249

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

spec/helpers/acceptance/tests/manifest_shared_examples.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class { 'elasticsearch' :
4141
end
4242

4343
if idempotency_check
44-
it 'is idempotent' do
44+
it 'is idempotent', :logs_on_failure do
4545
apply_manifest applied_manifest, :catch_changes => true
4646
end
4747
end

spec/spec_helper_acceptance.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ class { 'elasticsearch':
125125
c.before :context, :first_purge do
126126
shell 'rm -rf {/usr/share,/etc,/var/lib}/elasticsearch*'
127127
end
128+
129+
# Provide a hook filter to spit out some ES logs if the example fails.
130+
c.after(:example, :logs_on_failure) do |example|
131+
if example.exception
132+
hosts.each do |host|
133+
on host, "find / -name '#{v[:cluster_name]}.log' | xargs cat || true" do |result|
134+
puts result.formatted_output
135+
end
136+
end
137+
end
138+
end
128139
end
129140

130141
files_dir = ENV['files_dir'] || './spec/fixtures/artifacts'
@@ -259,16 +270,6 @@ class { "java" :
259270
MANIFEST
260271
end
261272
end
262-
263-
c.after :suite do |suite|
264-
unless suite.reporter.failed_examples.empty?
265-
hosts.each do |host|
266-
on host, 'find /var/log/elasticsearch | xargs cat || true' do |result|
267-
puts result.formatted_output
268-
end
269-
end
270-
end
271-
end
272273
end
273274

274275
# Java 8 is only easy to manage on recent distros

0 commit comments

Comments
 (0)