Class: Specinfra::Backend::BeakerExec

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

Instance Method Summary collapse

Methods inherited from BeakerBase

#example, #ssh_exec!

Instance Method Details

#add_pre_command(cmd) ⇒ Object


289
290
291
292
293
294
295
296
# File 'lib/beaker-rspec/helpers/serverspec.rb', line 289

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


276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/beaker-rspec/helpers/serverspec.rb', line 276

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
  if path
    cmd = %Q{env PATH="#{path}" #{cmd}}
  end

  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) (defaults to: {})

    No currently supported options

Returns:

  • (Hash)

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


262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/beaker-rspec/helpers/serverspec.rb', line 262

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