lib/beaker/dsl/helpers.rb in beaker-1.1.0 vs lib/beaker/dsl/helpers.rb in beaker-1.2.0

- old
+ new

@@ -634,38 +634,64 @@ # # @option opts [Boolean] :trace (false) If this key exists in the Hash, # the "--trace" command line parameter will be # passed to the 'puppet apply' command. # + # @option opts [Array<Integer>] :acceptable_exit_codes ([0]) The list of exit + # codes that will NOT raise an error when found upon + # command completion. If provided, these values will + # be combined with those used in :catch_failures and + # :expect_failures to create the full list of + # 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, + # `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 + # `puppet --apply` indicates there was a # failure 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. + # # @param [Block] block This method will yield to a block of code passed # 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] = 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") + end if opts[:catch_failures] args << '--detailed-exitcodes' - # 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." - # We're after failures specifically so catch exit codes 4 and 6 only. + # 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' + + # We're after failures specifically so allow exit codes 1, 4, and 6 only. + on_options[:acceptable_exit_codes] |= [1, 4, 6] + else + # Either use the provided acceptable_exit_codes or default to [0] + on_options[:acceptable_exit_codes] |= [0] end # Not really thrilled with this implementation, might want to improve it # later. Basically, there is a magic trick in the constructor of # PuppetCommand which allows you to pass in a Hash for the last value in