Class: CukeMonk
- Inherits:
-
Object
- Object
- CukeMonk
- Defined in:
- lib/virtualmonkey/cuke_monk.rb
Instance Attribute Summary collapse
-
#jobs ⇒ Object
Returns the value of attribute jobs.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #all_done? ⇒ Boolean
- #generate_reports ⇒ Object
-
#initialize ⇒ CukeMonk
constructor
A new instance of CukeMonk.
- #report_lost_deployments(jobs = {}) ⇒ Object
-
#run_test(deployment, feature, break_point = 1000000) ⇒ Object
Runs a cucumber test on a single Deployment * deployment<~String> the nickname of the deployment * feature<~String> the feature filename.
-
#run_tests(deployments, cmd) ⇒ Object
runs a feature on an array of deployments * deployments<~Array> array of strings containing the nicknames of the deployments * feature_name<~String> the feature filename.
- #status_change_hook ⇒ Object
- #watch_and_report ⇒ Object
Constructor Details
#initialize ⇒ CukeMonk
Returns a new instance of CukeMonk.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 76 def initialize() @jobs = [] @passed = [] @failed = [] @running = [] dirname = Time.now.strftime("%Y/%m/%d/%H-%M-%S") @log_dir = File.join("log", dirname) @log_started = dirname FileUtils.mkdir_p(@log_dir) @feature_dir = File.join(File.dirname(__FILE__), '..', '..', 'features') end |
Instance Attribute Details
#jobs ⇒ Object
Returns the value of attribute jobs.
58 59 60 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 58 def jobs @jobs end |
#options ⇒ Object
Returns the value of attribute options.
59 60 61 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 59 def @options end |
Instance Method Details
#all_done? ⇒ Boolean
124 125 126 127 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 124 def all_done? running = @jobs.select { |s| s.status == nil } running.size == 0 && @jobs.size > 0 end |
#generate_reports ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 129 def generate_reports passed = @jobs.select { |s| s.status == 0 } failed = @jobs.select { |s| s.status == 1 } running = @jobs.select { |s| s.status == nil } report_on = @jobs.select { |s| s.status == 0 || s.status == 1 } index = ERB.new File.read(File.dirname(__FILE__)+"/index.html.erb") bucket_name = "virtual_monkey" ## upload to s3 # setup credentials in ~/.fog s3 = Fog::AWS::Storage.new(:aws_access_key_id => Fog.credentials[:aws_access_key_id_test], :aws_secret_access_key => Fog.credentials[:aws_secret_access_key_test]) if directory = s3.directories.detect { |d| d.key == bucket_name } puts "found directory, re-using" else directory = s3.directories.create(:key => bucket_name) end raise 'could not create directory' unless directory s3.put_object(bucket_name, "#{@log_started}/index.html", index.result(binding), 'x-amz-acl' => 'public-read', 'Content-Type' => 'text/html') report_on.each do |j| begin done = 0 s3.put_object(bucket_name, "#{@log_started}/#{File.basename(j.logfile)}", IO.read(j.logfile), 'Content-Type' => 'text/plain', 'x-amz-acl' => 'public-read') s3.put_object(bucket_name, "#{@log_started}/#{File.basename(j.rest_log)}", IO.read(j.rest_log), 'Content-Type' => 'text/plain', 'x-amz-acl' => 'public-read') done = 1 rescue Exception => e unless e. =~ /Bad file descriptor/i raise e end sleep 1 end while not done end msg = <<END_OF_MESSAGE new results avilable at http://s3.amazonaws.com/#{bucket_name}/#{@log_started}/index.html\n-OR-\nin #{@log_dir}/index.html" END_OF_MESSAGE puts msg end |
#report_lost_deployments(jobs = {}) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 168 def report_lost_deployments(jobs = {}) running_change = jobs[:old_running] - jobs[:running] passed_change = jobs[:passed] - jobs[:old_passed] failed_change = jobs[:failed] - jobs[:old_failed] lost_jobs = running_change - passed_change - failed_change lost_jobs.each do |j| puts "LOST JOB---------------------------------" puts "Deployment Name: #{j.deployment.nickname}" puts "Status Code: #{j.status}" puts "Audit Entries: #{j.link_to_rightscale}" puts "Log File: #{j.logfile}" puts "Rest_Connection Log File: #{j.rest_log}" puts "-----------------------------------------" end end |
#run_test(deployment, feature, break_point = 1000000) ⇒ Object
Runs a cucumber test on a single Deployment
-
deployment<~String> the nickname of the deployment
-
feature<~String> the feature filename
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 63 def run_test(deployment, feature, break_point = 1000000) new_job = CukeJob.new new_job.logfile = File.join(@log_dir, "#{deployment.nickname}.log") new_job.rest_log = "#{@log_dir}/#{deployment.nickname}.rest_connection.log" new_job.deployment = deployment new_job.no_resume = "true" if @options[:no_resume] break_point = @options[:breakpoint] if @options[:breakpoint] cmd = "bin/grinder #{feature} #{break_point}" @jobs << new_job puts "running #{cmd}" new_job.run(deployment, cmd) end |
#run_tests(deployments, cmd) ⇒ Object
runs a feature on an array of deployments
-
deployments<~Array> array of strings containing the nicknames of the deployments
-
feature_name<~String> the feature filename
91 92 93 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 91 def run_tests(deployments,cmd) deployments.each { |d| run_test(d,cmd) } end |
#status_change_hook ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 116 def status_change_hook generate_reports if all_done? puts "monkey done." EM.stop end end |
#watch_and_report ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/virtualmonkey/cuke_monk.rb', line 95 def watch_and_report old_passed = @passed old_failed = @failed old_running = @running old_sum = old_passed.size + old_failed.size + old_running.size @passed = @jobs.select { |s| s.status == 0 } @failed = @jobs.select { |s| s.status == 1 } @running = @jobs.select { |s| s.status == nil } new_sum = @passed.size + @failed.size + @running.size puts "#{@passed.size} features passed. #{@failed.size} features failed. #{@running.size} features running." if new_sum < old_sum and new_sum < @jobs.size puts "WARNING: Jobs Lost! Finding..." report_lost_deployments({ :old_passed => old_passed, :passed => @passed, :old_failed => old_failed, :failed => @failed, :old_running => old_running, :running => @running }) end if old_passed != @passed || old_failed != @failed status_change_hook end end |