Class: CemAcpt::Utils::WinRMRunner::RunnerWrapper

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cem_acpt/utils/winrm_runner.rb

Overview

A wrapper class for executing commands on a windows node Provides error handling and logging on each command being executed

Constant Summary

Constants included from Logging

Logging::LEVEL_MAP

Instance Method Summary collapse

Methods included from Logging

current_log_config, #current_log_config, current_log_format, #current_log_format, #current_log_level, current_log_level, included, #logger, logger, new_log_config, #new_log_config, new_log_formatter, #new_log_formatter, #new_log_level, new_log_level, #new_logger, new_logger, verbose?, #verbose?

Constructor Details

#initialize(shell) ⇒ RunnerWrapper

Returns a new instance of RunnerWrapper.



16
17
18
# File 'lib/cem_acpt/utils/winrm_runner.rb', line 16

def initialize(shell)
  @shell = shell
end

Instance Method Details

#run(command) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cem_acpt/utils/winrm_runner.rb', line 20

def run(command)
  output = @shell.run(command) do |stdout, stderr|
    puts stdout
    puts stderr
  end

  # At any point, if the exit code is not 0, we will raise an error and stop the test
  # Because if one command fails, it will effect the rest of the test.
  if output.exitcode != 0
    raise WinRMExecutionError, "Command #{command} failed with exit code #{output.exitcode}. Error: #{output.stderr}"
  end
end