Skip to content

Commit

Permalink
Ensure hosts are destroyed if post-suite fails
Browse files Browse the repository at this point in the history
When running `rake ci:test:aio[true]`, if the post-suite failed and we're not
preserving hosts, then the `beaker destroy` command would be skipped. Use a
nested ensure so the failure of post-suite doesn't prevent `beaker destroy` from
being called.

```
$ git diff
diff --git a/acceptance/teardown/common/099_Archive_Logs.rb b/acceptance/teardown/common/099_Archive_Logs.rb
index d940e2bea..2302633e1 100644
--- a/acceptance/teardown/common/099_Archive_Logs.rb
+++ b/acceptance/teardown/common/099_Archive_Logs.rb
@@ -1,5 +1,7 @@
 require 'date'

+raise "whoops"
+
 def file_glob(host, path)
   result = on(host, "ls #{path}", :acceptable_exit_codes => [0, 2])
   return [] if result.exit_code != 0

$ export BEAKER_PUPPET_VERSION=/home/josh/work/beaker-puppet
$ bundle update
...
$ bundle exec rake 'ci:test:aio[true]' SHA=8.4.0 TESTS=tests/load_libfacter.rb HOSTS=hosts.yaml
...
Begin teardown/common/099_Archive_Logs.rb
RuntimeError: whoops
...
beaker destroy
```
  • Loading branch information
joshcooper committed Jan 23, 2024
1 parent a54f696 commit aece90c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tasks/ci.rake
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@ def beaker_suite_retry(type)
puts '*** Retrying the following:'
puts tests_to_rerun.map { |spec| " #{spec}" }
beaker(:exec, tests_to_rerun.map { |str| "#{str}" }.join(','))
ensure
beaker(:exec, 'post-suite')
end
ensure
beaker(:exec, 'post-suite')
preserve_hosts = ENV['OPTIONS'].include?('--preserve-hosts=always') if ENV['OPTIONS']
beaker(:destroy) unless preserve_hosts
end
Expand Down

0 comments on commit aece90c

Please sign in to comment.