class Specinfra::Backend::BeakerExec

Public Instance Methods

add_pre_command(cmd) click to toggle source
# File lib/beaker-rspec/helpers/serverspec.rb, line 279
def add_pre_command(cmd)
  if Specinfra.configuration.pre_command
    pre_cmd = build_command(Specinfra.configuration.pre_command)
    "#{pre_cmd} && #{cmd}"
  else
    cmd
  end
end
build_command(cmd) click to toggle source
# File lib/beaker-rspec/helpers/serverspec.rb, line 268
def build_command(cmd)
  useshell = '/bin/sh'
  cmd = cmd.shelljoin if cmd.is_a?(Array)
  cmd = "#{String(useshell).shellescape} -c #{String(cmd).shellescape}"

  path = Specinfra.configuration.path
  cmd = %(env PATH="#{path}" #{cmd}) if path

  cmd
end
run_command(cmd, _opt = {}) click to toggle source

Run a unix style command using serverspec. Defaults to running on the ‘default_node’ test node, otherwise uses the node specified in @example.metadata @param [String] cmd The serverspec command to executed @param [Hash] opt No currently supported options @return [Hash] Returns a hash containing :exit_status, :stdout and :stderr

# File lib/beaker-rspec/helpers/serverspec.rb, line 254
def run_command(cmd, _opt = {})
  node = get_working_node
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  ret = ssh_exec!(node, cmd)

  if @example
    @example.metadata[:command] = cmd
    @example.metadata[:stdout]  = ret[:stdout]
  end

  CommandResult.new ret
end