Class: Specinfra::Backend::BeakerCygwin

Inherits:
BeakerBase
  • Object
show all
Includes:
PowerShell::ScriptHelper
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

#run_command(cmd, _opt = {}) ⇒ Hash

Run a windows 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



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/beaker-rspec/helpers/serverspec.rb', line 218

def run_command(cmd, _opt = {})
  node = get_working_node
  script = create_script(cmd)
  # when node is not cygwin rm -rf will fail so lets use native del instead
  # There should be a better way to do this, but for now , this works
  if node.is_cygwin?
    delete_command = 'rm -rf'
    redirection = '< /dev/null'
  else
    delete_command = 'del'
    redirection = '< NUL'
  end
  on node, "#{delete_command} script.ps1"
  create_remote_file(node, 'script.ps1', script)
  # When using cmd on a pswindows node redirection should be set to < NUl
  # when using a cygwing one, /dev/null should be fine
  ret = ssh_exec!(node, "powershell.exe -File script.ps1 #{redirection}")

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

  CommandResult.new ret
end