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.



21
22
23
24
25
26
27
28
# File 'lib/cem_acpt/test_runner.rb', line 21

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

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



19
20
21
# File 'lib/cem_acpt/test_runner.rb', line 19

def duration
  @duration
end

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



19
20
21
# File 'lib/cem_acpt/test_runner.rb', line 19

def exit_code
  @exit_code
end

Instance Method Details

#clean_up(trap_context = false) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/cem_acpt/test_runner.rb', line 68

def clean_up(trap_context = false)
  kill_keep_terminal_alive unless trap_context

  return no_destroy if config.get('no_destroy_nodes')

  clean_ephemeral_ssh_keys
  destroy_test_nodes
end

#inspectObject



30
31
32
# File 'lib/cem_acpt/test_runner.rb', line 30

def inspect
  to_s
end

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cem_acpt/test_runner.rb', line 38

def run
  @run_data = {}
  @start_time = Time.now
  logger.with_ci_group("CemAcpt v#{CemAcpt::VERSION} run started at #{@start_time}") do
    logger.info('CemAcpt') { "Using module directory: #{config.get('module_dir')}..." }
    Dir.chdir(config.get('module_dir')) do
      keep_terminal_alive
      @run_data[:private_key], @run_data[:public_key], @run_data[:known_hosts] = new_ephemeral_ssh_keys
      logger.info('CemAcpt') { 'Created ephemeral SSH key pair...' }
      @run_data[:module_package_path] = build_module_package
      logger.info('CemAcpt') { "Created module package: #{@run_data[:module_package_path]}..." }
      @run_data[:test_data] = new_test_data
      logger.info('CemAcpt') { 'Created test data...' }
      logger.verbose('CemAcpt') { "Test data: #{@run_data[:test_data]}" }
      @run_data[:nodes] = new_node_data
      logger.info('CemAcpt') { 'Created node data...' }
      logger.verbose('CemAcpt') { "Node data: #{@run_data[:nodes]}" }
      @instance_names_ips = provision_test_nodes
      logger.info('CemAcpt') { 'Provisioned test nodes...' }
      logger.debug('CemAcpt') { "Instance names and IPs: #{@instance_names_ips}" }
      @results = run_tests(@instance_names_ips.map { |_, v| v['ip'] },
                           config.get('actions.only'),
                           config.get('actions.except'))
    end
  end
ensure
  clean_up
  process_test_results
end

#to_sObject



34
35
36
# File 'lib/cem_acpt/test_runner.rb', line 34

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