lib/beaker/dsl/helpers.rb in beaker-1.2.0 vs lib/beaker/dsl/helpers.rb in beaker-1.3.0
- old
+ new
@@ -644,19 +644,23 @@
# passing exit codes.
#
# @options opts [Hash] :environment Additional environment variables to be
# passed to the 'puppet apply' command
#
- # @option opts [Boolean] :catch_failures (false) By default
- # `puppet --apply` will exit with 0,
- # which does not count as a test
- # failure, even if there were errors applying
- # the manifest. This option enables detailed
- # exit codes and causes a test failure if
- # `puppet --apply` indicates there was a
- # failure during its execution.
+ # @option opts [Boolean] :catch_failures (false) By default `puppet
+ # --apply` will exit with 0, which does not count
+ # as a test failure, even if there were errors or
+ # changes when applying the manifest. This option
+ # enables detailed exit codes and causes a test
+ # failure if `puppet --apply` indicates there was
+ # a failure during its execution.
#
+ # @option opts [Boolean] :catch_changes (false) This option enables
+ # detailed exit codes and causes a test failure
+ # if `puppet --apply` indicates that there were
+ # changes or failures during its execution.
+ #
# @option opts [Boolean] :expect_failures (false) This option enables
# detailed exit codes and causes a test failure
# if `puppet --apply` indicates there were no
# failure during its execution.
#
@@ -664,25 +668,30 @@
# by the caller; this can be used for additional
# validation, etc.
#
def apply_manifest_on(host, manifest, opts = {}, &block)
on_options = {:stdin => manifest + "\n"}
- on_options[:acceptable_exit_codes] = Array(opts.delete(:acceptable_exit_codes))
+ on_options[:acceptable_exit_codes] = Array(opts.delete(:acceptable_exit_codes))
args = ["--verbose"]
args << "--parseonly" if opts[:parseonly]
args << "--trace" if opts[:trace]
# From puppet help:
# "... an exit code of '2' means there were changes, an exit code of
# '4' means there were failures during the transaction, and an exit
# code of '6' means there were both changes and failures."
- if opts[:catch_failures] and opts[:expect_failures]
- raise(ArgumentError, "Cannot specify both `catch_failures` and `expect_failures` for a single manifest")
+ if [opts[:catch_changes],opts[:catch_failures],opts[:expect_failures]].select{|x|x}.length > 1
+ raise(ArgumentError, "Cannot specify more than one of `catch_failures`, `catch_changes`, or `expect_failures` for a single manifest")
end
- if opts[:catch_failures]
+ if opts[:catch_changes]
args << '--detailed-exitcodes'
+ # We're after idempotency so allow exit code 0 only.
+ on_options[:acceptable_exit_codes] |= [0]
+ elsif opts[:catch_failures]
+ args << '--detailed-exitcodes'
+
# We're after only complete success so allow exit codes 0 and 2 only.
on_options[:acceptable_exit_codes] |= [0, 2]
elsif opts[:expect_failures]
args << '--detailed-exitcodes'
@@ -876,11 +885,11 @@
# Ensure the host has requested a cert, then sign it
#
# @param [Host] host The host to sign for
#
- # @returns nil
+ # @return nil
# @raise [FailTest] if process times out
def sign_certificate_for(host)
if [master, dashboard, database].include? host
on host, puppet( 'agent -t' ), :acceptable_exit_codes => [0,1,2]
@@ -914,10 +923,10 @@
#
# @param [Host] host The host to query the fact for
# @param [String] name The name of the fact to query for
# @!macro common_opts
#
- # @returns String The value of the fact 'name' on the provided host
+ # @return String The value of the fact 'name' on the provided host
# @raise [FailTest] Raises an exception if call to facter fails
def fact_on(host, name, opts = {})
result = on host, facter(name, opts)
result.stdout.chomp if result.stdout
end