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



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

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



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

def build_command(cmd)
  useshell = '/bin/sh'
  cmd = cmd.shelljoin if cmd.is_a?(Array)
  cmd = "#{useshell.shellescape} -c #{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



251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/beaker-rspec/helpers/serverspec.rb', line 251

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