Class: Beaker::CLI
- Inherits:
-
Object
- Object
- Beaker::CLI
- Defined in:
- lib/beaker/cli.rb
Constant Summary collapse
- VERSION_STRING =
" wWWWw |o o| | O | %s! |(\")| / \\X/ \\ | V | | | | "
Instance Method Summary collapse
-
#execute! ⇒ Object
Run Beaker tests.
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
-
#print_command_line(log_level = :debug) ⇒ Object
Prints the command line that can be called to reproduce this run (assuming the environment is the same).
-
#print_env_vars_affecting_beaker(log_level) ⇒ Object
Prints Environment variables affecting the beaker run (those that beaker introspects + the ruby env that beaker runs within).
- #print_reproduction_info(log_level = :debug) ⇒ Object
-
#provision ⇒ Object
Provision, validate and configure all hosts as defined in the hosts file.
-
#run_suite(suite_name, failure_strategy = :slow) ⇒ Object
Run the provided test suite.
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/beaker/cli.rb', line 12 def initialize @timestamp = Time.now @options_parser = Beaker::Options::Parser.new @options = @options_parser.parse_args @logger = Beaker::Logger.new(@options) @options[:logger] = @logger @options[:timestamp] = @timestamp @execute = true if @options[:help] @logger.notify(@options_parser.usage) @execute = false return end if @options[:version] @logger.notify(VERSION_STRING % Beaker::Version::STRING) @execute = false return end @logger.info(@options.dump) if @options[:parse_only] @execute = false return end #add additional paths to the LOAD_PATH if not @options[:load_path].empty? @options[:load_path].each do |path| $LOAD_PATH << File.(path) end end @options[:helper].each do |helper| require File.(helper) end @options[:log_dated_dir] = Beaker::Logger.generate_dated_log_folder(@options[:log_dir], @timestamp) @options[:xml_dated_dir] = Beaker::Logger.generate_dated_log_folder(@options[:xml_dir], @timestamp) end |
Instance Method Details
#execute! ⇒ Object
Run Beaker tests.
-
provision hosts (includes validation and configuration)
-
run pre-suite
-
run tests
-
run post-suite
-
cleanup hosts
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/beaker/cli.rb', line 72 def execute! if !@execute return end begin trap(:INT) do @logger.warn "Interrupt received; exiting..." exit(1) end provision # Setup perf monitoring if needed @perf = Beaker::Perf.new( @hosts, @options ) if @options[:collect_perf_data] errored = false #pre acceptance phase run_suite(:pre_suite, :fast) #testing phase begin run_suite(:tests) #post acceptance phase rescue => e #post acceptance on failure #run post-suite if we are in fail-slow mode if @options[:fail_mode].to_s =~ /slow/ run_suite(:post_suite) end raise e else #post acceptance on success run_suite(:post_suite) end #cleanup phase rescue => e #cleanup on error if @options[:preserve_hosts].to_s =~ /(never)|(onpass)/ @logger.notify "Cleanup: cleaning up after failed run" if @network_manager @network_manager.cleanup end end @perf.print_perf_info if @options[:collect_perf_data] print_reproduction_info( :error ) @logger.error "Failed running the test suite." puts '' exit 1 else #cleanup on success if @options[:preserve_hosts].to_s =~ /(never)|(onfail)/ @logger.notify "Cleanup: cleaning up after successful run" if @network_manager @network_manager.cleanup end end if @logger.is_debug? print_reproduction_info( :debug ) end @perf.print_perf_info if @options[:collect_perf_data] end end |
#print_command_line(log_level = :debug) ⇒ Object
Prints the command line that can be called to reproduce this run (assuming the environment is the same)
196 197 198 199 |
# File 'lib/beaker/cli.rb', line 196 def print_command_line( log_level = :debug ) @logger.send(log_level, "\nYou can reproduce this run with:\n") @logger.send(log_level, @options[:command_line]) end |
#print_env_vars_affecting_beaker(log_level) ⇒ Object
Prints Environment variables affecting the beaker run (those that beaker introspects + the ruby env that beaker runs within)
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/beaker/cli.rb', line 167 def print_env_vars_affecting_beaker( log_level ) non_beaker_env_vars = [ 'BUNDLE_PATH', 'BUNDLE_BIN', 'GEM_HOME', 'GEM_PATH', 'RUBYLIB', 'PATH'] env_var_map = non_beaker_env_vars.inject({}) do |memo, possibly_set_vars| set_var = Array(possibly_set_vars).detect {|possible_var| ENV[possible_var] } memo[set_var] = ENV[set_var] if set_var memo end env_var_map = env_var_map.merge(Beaker::Options::Presets.new.env_vars) @logger.send( log_level, "\nImportant ENV variables that may have affected your run:" ) env_var_map.each_pair do |var, value| if value.is_a?(Hash) value.each_pair do | subvar, subvalue | @logger.send( log_level, " #{subvar}\t\t#{subvalue}" ) end else @logger.send( log_level, " #{var}\t\t#{value}" ) end end end |
#print_reproduction_info(log_level = :debug) ⇒ Object
155 156 157 158 |
# File 'lib/beaker/cli.rb', line 155 def print_reproduction_info( log_level = :debug ) print_command_line( log_level ) print_env_vars_affecting_beaker( log_level ) end |
#provision ⇒ Object
Provision, validate and configure all hosts as defined in the hosts file
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/beaker/cli.rb', line 52 def provision begin @hosts = [] @network_manager = Beaker::NetworkManager.new(@options, @logger) @hosts = @network_manager.provision @network_manager.proxy_package_manager @network_manager.validate @network_manager.configure rescue => e report_and_raise(@logger, e, "CLI.provision") end end |
#run_suite(suite_name, failure_strategy = :slow) ⇒ Object
Run the provided test suite
144 145 146 147 148 149 150 151 152 |
# File 'lib/beaker/cli.rb', line 144 def run_suite(suite_name, failure_strategy = :slow) if (@options[suite_name].empty?) @logger.notify("No tests to run for suite '#{suite_name.to_s}'") return end Beaker::TestSuite.new( suite_name, @hosts, @options, @timestamp, failure_strategy ).run_and_raise_on_failure end |