stella 2.0.3.001 → 2.1.0.001

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,5 +1,16 @@
1
1
  STELLA, CHANGES
2
2
 
3
+ #### 2.1.0 (2011-07-06) ###############################
4
+
5
+ * FIXED: Different CLI output when a testplan is specified
6
+ * ADDED: Handle bad or missing api credentials
7
+ * ADDED: Globals -A and -K for supplying API credentials
8
+ * CHANGE: Default output is now CLI (use -F json)
9
+ * CHANGE: Global -f is now -u (for usecase)
10
+ * CHANGE: Global -F is now -f (output format)
11
+ * CHANGE: STELLA_USER env var is now STELLA_ACCOUNT
12
+
13
+
3
14
  #### 2.0.3 (2011-07-06) ###############################
4
15
 
5
16
  * ADDED: Stella::API
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  :MAJOR: 2
2
- :MINOR: 0
3
- :PATCH: 3
2
+ :MINOR: 1
3
+ :PATCH: 0
4
4
  :BUILD: '001'
data/bin/stella CHANGED
@@ -44,10 +44,15 @@ class Stella::CLI::Definition
44
44
  #global :H, :withheader, "Include X-Stella-ID request header"
45
45
  #global :P, :withparam, "Include __stella query parameter header"
46
46
  global :T, :timeout, Float, "HTTP request timeout (default: unlimited)"
47
- global :F, :format, String, "Output format (partial support)"
48
47
  global :R, :remote, "Run command remotely (via blamestella.com)"
49
- global :f, :filter, String, "Only run usecases that match this filter"
48
+ global :A, :account, String, "API account (overrides STELLA_ACCOUNT)"
49
+ global :K, :key, String, "API key (overrides STELLA_KEY)"
50
50
  global :p, :testplan, String, "Path to testplan"
51
+ global :u, :usecase, String, "Only run usecases that match the given filter"
52
+ global :f, :format, String, "Output format (partial support)" do |v|
53
+ raise "Unsupported format: #{v}" unless ['csv', 'json', 'yaml'].member?(v)
54
+ v
55
+ end
51
56
  global :n, :nocolor, "Disable output colors" do
52
57
  String.disable_color
53
58
  end
@@ -96,9 +101,9 @@ class Stella::CLI::Definition
96
101
 
97
102
  after do |obj|
98
103
  @elapsed = Time.now - @start
99
- if @elapsed > 0.1 && Stella.noise > 1
100
- Stella.li "#{$/}Elapsed: %.2f seconds" % @elapsed.to_f
101
- end
104
+ #if @elapsed > 0.1 && Stella.noise > 3
105
+ # Stella.li "#{$/}Elapsed: %.2f seconds" % @elapsed.to_f
106
+ #end
102
107
  code = obj.exit_code if obj.respond_to? :exit_code
103
108
  exit code ||= 0
104
109
  end
data/lib/stella/api.rb CHANGED
@@ -1,18 +1,20 @@
1
1
  require 'httparty'
2
2
  require 'stella'
3
3
 
4
- class Stella
4
+ class Stella
5
5
  class API
6
6
  include HTTParty
7
-
8
7
  ssl_ca_file Stella::Client::SSL_CERT_PATH
9
8
  format :json
10
9
  attr_reader :httparty_opts, :response
11
- def initialize user=nil, key=nil, httparty_opts={}
10
+ def initialize account=nil, key=nil, httparty_opts={}
12
11
  self.class.base_uri ENV['STELLA_HOST'] || 'https://www.blamestella.com/api/v2'
13
- @httparty_opts = httparty_opts.merge({
14
- :basic_auth => { :username => user || ENV['STELLA_USER'], :password => key || ENV['STELLA_KEY'] }
15
- })
12
+ @httparty_opts = httparty_opts
13
+ account ||= ENV['STELLA_ACCOUNT']
14
+ key ||= ENV['STELLA_KEY']
15
+ unless account.to_s.empty? || key.to_s.empty?
16
+ @httparty_opts[:basic_auth] ||= { :username => account, :password => key }
17
+ end
16
18
  end
17
19
  def get path, params=nil
18
20
  opts = httparty_opts
@@ -57,6 +59,9 @@ class Stella
57
59
  def indifferent_hash
58
60
  Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
59
61
  end
62
+
63
+ class Unauthorized < RuntimeError
64
+ end
60
65
  end
61
66
  end
62
67
 
data/lib/stella/cli.rb CHANGED
@@ -13,20 +13,38 @@ class Stella::CLI < Drydock::Command
13
13
 
14
14
 
15
15
  def checkup
16
+ require 'stella/api'
16
17
  base_uri = Stella.canonical_uri(@argv.first)
17
18
  run_opts = {
18
19
  :repetitions => @option.repetitions || 1,
19
20
  :concurrency => @option.concurrency || 1,
20
21
  :wait => @option.wait || 1
21
22
  }
23
+ # NOTE ABOUT CLI OUTPUT:
24
+ # Output when a testplan is supplied comes from Engine.run
25
+ # while it's being executed. Otherwise it's generated from
26
+ # testrun.report after the generic testplan has run.
27
+ if @global.format || !@global.testplan
28
+ Stella.noise = 0
29
+ end
30
+ @global.remote ||= @global.account || @global.key
22
31
  if @global.remote
23
- require 'stella/api'
24
- @api = Stella::API.new
32
+ raise "Running a testplan remotely isn't supported yet (soon!)" if @global.testplan
33
+ @api = Stella::API.new @global.account, @global.key
25
34
  ret = @api.post :checkup, :uri => base_uri
35
+ pp @api.response if Stella.debug
36
+ if @api.response.code >= 400
37
+ raise Stella::API::Unauthorized if @api.response.code == 401
38
+ STDERR.puts ret[:msg]
39
+ @exit_code = 1 and return
40
+ end
26
41
  begin
27
42
  run_hash = @api.get "/checkup/#{ret[:runid]}"
28
43
  @run = Stella::Testrun.from_hash run_hash if run_hash
44
+ STDERR.print '.' unless Stella.quiet?
45
+ sleep 1 if @run && !@run.done?
29
46
  end while @run && !@run.done?
47
+ STDERR.puts unless Stella.quiet?
30
48
  else
31
49
  if @global.testplan
32
50
  unless File.owned?(@global.testplan)
@@ -34,7 +52,7 @@ class Stella::CLI < Drydock::Command
34
52
  end
35
53
  Stella.ld "Load #{@global.testplan}"
36
54
  load @global.testplan
37
- filter = @global.filter
55
+ filter = @global.usecase
38
56
  planname = Stella::Testplan.plans.keys.first
39
57
  @plan = Stella::Testplan.plan(planname)
40
58
  if filter
@@ -53,18 +71,41 @@ class Stella::CLI < Drydock::Command
53
71
 
54
72
  @report = @run.report
55
73
 
56
- if Stella.quiet?
57
- @exit_code = @report.error_count
58
- else
59
- @global.format ||= 'json'
60
- if @global.verbose == 0
74
+ @exit_code = @report.error_count if Stella.quiet?
75
+
76
+ unless @global.testplan
77
+ case @global.format
78
+ when 'csv'
61
79
  metrics = @report.metrics_pack
62
80
  puts metrics.dump(@global.format)
63
- elsif @global.verbose >= 1
81
+ when 'json', 'yaml'
64
82
  puts @run.dump(@global.format)
83
+ else
84
+ metrics = @report.metrics
85
+ # @run.planid.shorten(12), @run.runid.shorten(12),
86
+ args = [@report.statuses.values.first,
87
+ metrics.response_time.mean*1000,
88
+ metrics.socket_connect.mean*1000,
89
+ metrics.first_byte.mean*1000,
90
+ metrics.last_byte.mean*1000]
91
+ Stella.li "[%3s] %6.2fms (%5.2fms + %5.2fms + %5.2fms)" % args
92
+ if @global.verbose > 0 || @report.errors?
93
+ Stella.li ''
94
+ Stella.li ' Headers:'
95
+ Stella.li ' %s' % [@report.headers.request_headers.split(/\n/).join("\n ")]
96
+ Stella.li
97
+ Stella.li ' %s' % [@report.headers.response_headers.split(/\n/).join("\n ")]
98
+ end
99
+ #puts @report.metrics_pack.dump(:json)
65
100
  end
66
101
  end
67
-
102
+ rescue Stella::API::Unauthorized => ex
103
+ STDERR.puts "Please check your credentials!"
104
+ STDERR.puts " e.g."
105
+ STDERR.puts " export STELLA_ACCOUNT=youraccount"
106
+ STDERR.puts " export STELLA_KEY=yourapikey"
107
+ STDERR.puts " OR "
108
+ STDERR.puts " stella -A youraccount -K yourapikey checkup #{@argv.first}"
68
109
  end
69
110
 
70
111
  def example
data/lib/stella/engine.rb CHANGED
@@ -49,28 +49,31 @@ class Stella
49
49
  Benelux.current_track "client_#{client.clientid.shorten}"
50
50
  begin
51
51
  opts[:repetitions].times do |idx|
52
- Stella.li '%-61s %s' % [testrun.plan.desc, testrun.plan.planid.shorten(12)] if Stella.noise >= 2
52
+ Stella.li '%-61s %s' % [testrun.plan.desc, testrun.plan.planid.shorten(12)] if Stella.noise >= 2 && !Stella.quiet?
53
53
  testrun.plan.usecases.each_with_index do |uc,i|
54
54
  if opts[:usecases].nil? || opts[:usecases].member?(uc.class)
55
55
  Benelux.current_track.add_tags :usecase => uc.id
56
56
  Stella.rescue {
57
- Stella.li ' %-60s %s' % [uc.desc, uc.ucid.shorten(12)] if Stella.noise >= 2
57
+ Stella.li ' %-60s %s' % [uc.desc, uc.ucid.shorten(12)] if Stella.noise >= 1 && !Stella.quiet?
58
58
  client.execute uc do |session|
59
- Stella.li ' %3d %4s %-76s' % [session.status, session.http_method.upcase, session.uri] if Stella.noise >= 2
60
- if Stella.noise >= 3
61
- Stella.li ' %s' % [session.req.header.dump.split(/\n/).join("\n ")]
59
+ Stella.li ' %3d %-4s %-76s' % [session.status, session.http_method.upcase, session.uri] if Stella.noise >= 1 && !Stella.quiet?
60
+ if Stella.noise >= 2 && !Stella.quiet?
61
+ Stella.li ' %s' % [session.req.header.dump.split(/\n/).join("\n ")]
62
62
  Stella.li
63
- Stella.li ' %s' % [session.res.header.dump.split(/\n/).join("\n ")]
63
+ Stella.li ' %s' % [session.res.header.dump.split(/\n/).join("\n ")]
64
+ Stella.li ''
64
65
  end
65
66
  end
66
67
  }
67
68
  if client.exception
68
- Stella.li ' %4s %s (%s)' % ['', client.exception.message, client.exception.class]
69
+ if Stella.noise >= 1
70
+ Stella.li ' %4s %s (%s)' % ['', client.exception.message, client.exception.class]
71
+ end
69
72
  # TODO: use a throw. This won't stop the next repetition.
70
73
  break if Stella::TestplanQuit === client.exception
71
74
  end
72
75
  else
73
- Stella.li ' %-60s %s' % ["#{uc.desc} (skipped)", uc.ucid.shorten(12)] if Stella.noise >= 2
76
+ #Stella.li ' %-60s %s' % ["#{uc.desc} (skipped)", uc.ucid.shorten(12)] if Stella.noise >= 2
74
77
  end
75
78
  Benelux.current_track.remove_tags :usecase
76
79
  end
data/stella.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stella}
8
- s.version = "2.0.3.001"
8
+ s.version = "2.1.0.001"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Delano Mandelbaum"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: stella
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.3.001
5
+ version: 2.1.0.001
6
6
  platform: ruby
7
7
  authors:
8
8
  - Delano Mandelbaum