Method: Beaker::DSL::Helpers::HostHelpers#shell

Defined in:
lib/beaker/dsl/helpers/host_helpers.rb

#shell(command, opts = {}) ⇒ Result

The method for executing commands on the default host

Examples:

Most basic usage

shell 'ls /tmp'

Allowing additional exit codes to pass

shell 'puppet agent -t', :acceptable_exit_codes => [0,2]

Using the returned result for any kind of checking

if shell('ls -la ~').stdout =~ /\.bin/
  ...do some action...
end

Using TestCase helpers from within a test.

shell('cat /etc/puppet/puppet.conf') do |result|
  assert_match result.stdout, /server = #{master}/, 'WTF Mate'
end

Options Hash (opts):

  • :silent (Boolean) — default: false

    Do not produce log output

  • :acceptable_exit_codes (Array<Fixnum>) — default: [0]

    An array (or range) of integer exit codes that should be considered acceptable. An error will be thrown if the exit code does not match one of the values in this list.

  • :accept_all_exit_codes (Boolean) — default: false

    Consider all exit codes as passing.

  • :dry_run (Boolean) — default: false

    Do not actually execute any commands on the SUT

  • :stdin (String) — default: nil

    Input to be provided during command execution on the SUT.

  • :pty (Boolean) — default: false

    Execute this command in a pseudoterminal.

  • :expect_connection_failure (Boolean) — default: false

    Expect this command to result in a connection failure, reconnect and continue execution.

  • :environment (Hash{String=>String}) — default: {}

    These will be treated as extra environment variables that should be set before running the command.

  • :run_in_parallel (Boolean)

    Whether to run on each host in parallel.

Raises:

  • (FailTest)

    Raises an exception if command obviously fails.



121
122
123
# File 'lib/beaker/dsl/helpers/host_helpers.rb', line 121

def shell(command, opts = {}, &)
  on(default, command, opts, &)
end