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

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

Constructor Details

#initialize(config) ⇒ Runner

Returns a new instance of Runner.



25
26
27
28
29
30
31
32
33
34
# File 'lib/cem_acpt/test_runner.rb', line 25

def initialize(config)
  @config = config
  @run_data = {}
  @duration = 0
  @exit_code = 0
  @results = []
  @http_statuses = []
  @provisioned = false
  @destroyed = false
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



22
23
24
# File 'lib/cem_acpt/test_runner.rb', line 22

def duration
  @duration
end

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



22
23
24
# File 'lib/cem_acpt/test_runner.rb', line 22

def exit_code
  @exit_code
end

#run_dataObject

This is opened up mainly for windows use.



23
24
25
# File 'lib/cem_acpt/test_runner.rb', line 23

def run_data
  @run_data
end

Instance Method Details

#clean_up(_trap_context = false) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/cem_acpt/test_runner.rb', line 95

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}" }
  logger.verbose('CemAcpt::TestRunner') { e.backtrace.join("\n") }
ensure
  logger.end_ci_group
end

#inspectObject



36
37
38
# File 'lib/cem_acpt/test_runner.rb', line 36

def inspect
  to_s
end

#runObject



44
45
46
47
48
49
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
90
91
92
93
# File 'lib/cem_acpt/test_runner.rb', line 44

def run
  @run_data = {}
  @start_time = Time.now
  module_dir = config.get('module_dir')
  @old_dir = Dir.pwd
  Dir.chdir(module_dir)
  logger.start_ci_group("CemAcpt v#{CemAcpt::VERSION} run started at #{@start_time}")
  logger.info('CemAcpt::TestRunner') { "Using module directory: #{module_dir}..." }
  @run_data[:private_key], @run_data[:public_key], @run_data[:known_hosts] = new_ephemeral_ssh_keys
  logger.info('CemAcpt::TestRunner') { 'Created ephemeral SSH key pair...' }
  @run_data[:module_package_path] = build_module_package
  logger.info('CemAcpt::TestRunner') { "Created module package: #{@run_data[:module_package_path]}..." }
  @run_data[:test_data] = new_test_data
  logger.info('CemAcpt::TestRunner') { 'Created test data...' }
  logger.verbose('CemAcpt::TestRunner') { "Test data: #{@run_data[:test_data]}" }
  @run_data[:nodes] = new_node_data
  logger.info('CemAcpt::TestRunner') { 'Created node data...' }
  logger.verbose('CemAcpt::TestRunner') { "Node data: #{@run_data[:nodes]}" }
  @instance_names_ips = provision_test_nodes
  logger.info('CemAcpt::TestRunner') { "Instance names and IPs class: #{@instance_names_ips.class}" }
  @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
  @results = run_tests(@instance_names_ips.map { |_, v| v['ip'] },
                        config.get('actions.only'),
                        config.get('actions.except'))
rescue StandardError => e
  logger.error('CemAcpt::TestRunner') { 'Run failed due to error...' }
  @results << ActionResult.new(e)
ensure
  logger.end_ci_group
  clean_up
  process_test_results
  Dir.chdir(@old_dir) if @old_dir
  @results
end

#to_sObject



40
41
42
# File 'lib/cem_acpt/test_runner.rb', line 40

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