Class: Specinfra::Backend::BeakerExec

Inherits:
BeakerBase
  • Object
show all
Defined in:
lib/beaker-rspec/helpers/serverspec.rb

Instance Attribute Summary

Attributes inherited from BeakerBase

#example

Instance Method Summary collapse

Methods inherited from BeakerBase

#ssh_exec!

Instance Method Details

#add_pre_command(cmd) ⇒ Object



279
280
281
282
283
284
285
286
# 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) ⇒ Object



268
269
270
271
272
273
274
275
276
277
# 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 = {}) ⇒ Hash

Run a unix style command using serverspec. Defaults to running on the ‘default_node’ test node, otherwise uses the node specified in @example.metadata

Parameters:

  • cmd (String)

    The serverspec command to executed

  • opt (Hash)

    No currently supported options

Returns:

  • (Hash)

    Returns a hash containing :exit_status, :stdout and :stderr



254
255
256
257
258
259
260
261
262
263
264
265
266
# 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.[:command] = cmd
    @example.[:stdout]  = ret[:stdout]
  end

  CommandResult.new ret
end