Class: CemAcpt::TestRunner::Runner

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

Overview

Holds all the Runner related code

Constant Summary collapse

SUCCESS_STATUS =
[200, 0].freeze

Constants included from Logging

Logging::LEVEL_MAP

Instance Attribute Summary collapse

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(config) ⇒ Runner

Returns a new instance of Runner.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cem_acpt/test_runner.rb', line 29

def initialize(config)
  @config = config
  @module_builder = CemAcpt::Utils::Puppet::ModulePackageBuilder.new(config.get('module_dir'))
  @run_data = {}
  @duration = 0
  @exit_code = 0
  @bolt_test_runner = nil
  @results = CemAcpt::TestRunner::TestResults.new
  @statuses = []
  @provisioned = false
  @destroyed = false
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



26
27
28
# File 'lib/cem_acpt/test_runner.rb', line 26

def duration
  @duration
end

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



26
27
28
# File 'lib/cem_acpt/test_runner.rb', line 26

def exit_code
  @exit_code
end

#run_dataObject

This is opened up mainly for windows use.



27
28
29
# File 'lib/cem_acpt/test_runner.rb', line 27

def run_data
  @run_data
end

Instance Method Details

#clean_up(_trap_context = false) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/cem_acpt/test_runner.rb', line 91

def clean_up(_trap_context = false)
  logger.start_ci_group("CemAcpt v#{CemAcpt::VERSION} run finished at #{Time.now}")
  logger.debug('CemAcpt::TestRunner') { "Starting clean up, provisioned: #{@provisioned}, destroyed: #{@destroyed}" }

  if config.get('no_destroy_nodes')
    logger.warn('CemAcpt::TestRunner') { 'Not destroying test nodes because no-destroy-nodes is set...' }
    @provisioner&.show
    logger.info('CemAcpt') { "Test SSH Keys:\n  Private Key: #{@run_data[:private_key]}\n  Public Key:#{@run_data[:public_key]}" }
  else
    cleanup_bucket # Clean up bucket if we're testing the cem_windows module
    clean_ephemeral_ssh_keys
    destroy_test_nodes
  end
rescue StandardError => e
  logger.verbose('CemAcpt::TestRunner') { "Error cleaning up: #{e}\n#{e.backtrace.join("\n")}" }
ensure
  logger.end_ci_group
end

#inspectObject



42
43
44
# File 'lib/cem_acpt/test_runner.rb', line 42

def inspect
  to_s
end

#runObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cem_acpt/test_runner.rb', line 50

def run
  @start_time = Time.now
  module_dir = config.get('module_dir')
  @old_dir = Dir.pwd
  Dir.chdir(module_dir)
  configure_actions
  logger.start_ci_group("CemAcpt v#{CemAcpt::VERSION} run started at #{@start_time}")
  logger.info('CemAcpt::TestRunner') { "Using module directory: #{module_dir}..." }
  pre_provision_test_nodes
  provision_test_nodes
  @instance_names_ips = provisioner_output
  @provisioned = true
  logger.info('CemAcpt::TestRunner') { 'Provisioned test nodes...' }
  logger.debug('CemAcpt::TestRunner') { "Instance names and IPs: #{@instance_names_ips}" }
  # Verifying that we're running on windows nodes or not
  if config.get('tests').first.include? 'windows'
    logger.info('CemAcpt') { 'Running on windows nodes...' }
    upload_module_to_bucket

    @instance_names_ips.each do |k, v|
      # Login_info here is basically a super charged version of a hash from
      # instance_names_ips. It contains the username, password, and ip of the
      # windows node, as well as the test name that will be run on that node.
       = CemAcpt::Utils.(k, v)
      win_node = CemAcpt::Utils::WinRMRunner::WinNode.new(, @run_data[:win_remote_module_name])
      win_node.run
    end
  end
  @hosts = @instance_names_ips.map { |_, v| v['ip'] }
  run_tests
rescue StandardError => e
  logger.error('CemAcpt::TestRunner') { 'Run failed due to error...' }
  @results << e
ensure
  logger.end_ci_group
  clean_up
  process_test_results
  Dir.chdir(@old_dir) if @old_dir
  @results.to_a
end

#to_sObject



46
47
48
# File 'lib/cem_acpt/test_runner.rb', line 46

def to_s
  "#<#{self.class.name}:0x#{object_id.to_s(16)}>"
end