blitz 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
data/blitz.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{blitz}
8
- s.version = "0.1.15"
8
+ s.version = "0.1.16"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["pcapr"]
12
- s.date = %q{2011-10-13}
12
+ s.date = %q{2011-10-25}
13
13
  s.default_executable = %q{blitz}
14
14
  s.description = %q{Make load and performance testing a fun sport}
15
15
  s.email = %q{support@blitz.io}
@@ -34,11 +34,14 @@ Gem::Specification.new do |s|
34
34
  "lib/blitz/command/couch.rb",
35
35
  "lib/blitz/command/curl.rb",
36
36
  "lib/blitz/command/help.rb",
37
+ "lib/blitz/command/traceroute.rb",
37
38
  "lib/blitz/command/version.rb",
38
39
  "lib/blitz/curl/error.rb",
39
40
  "lib/blitz/curl/rush.rb",
40
41
  "lib/blitz/curl/sprint.rb",
41
42
  "lib/blitz/helper.rb",
43
+ "lib/blitz/traceroute.rb",
44
+ "lib/blitz/traceroute/error.rb",
42
45
  "spec/command/curl_spec.rb",
43
46
  "test/helper.rb",
44
47
  "test/test_blitz.rb"
data/lib/blitz.rb CHANGED
@@ -6,7 +6,7 @@ require 'pp'
6
6
 
7
7
  class Blitz # :nodoc:
8
8
  require 'blitz/helper'
9
- Version = "0.1.15"
9
+ Version = "0.1.16"
10
10
 
11
11
  extend Blitz::Helper
12
12
 
@@ -32,4 +32,6 @@ require 'blitz/client'
32
32
  require 'blitz/curl/error'
33
33
  require 'blitz/curl/sprint'
34
34
  require 'blitz/curl/rush'
35
+ require 'blitz/traceroute'
36
+ require 'blitz/traceroute/error'
35
37
  require 'blitz/command'
data/lib/blitz/client.rb CHANGED
@@ -18,6 +18,10 @@ class Client # :nodoc:
18
18
  JSON.parse blitz['/api/1/curl/execute'].post(data.to_json)
19
19
  end
20
20
 
21
+ def traceroute_execute data
22
+ JSON.parse blitz['/api/1/traceroute/execute'].post(data.to_json)
23
+ end
24
+
21
25
  def login
22
26
  JSON.parse blitz['/login/api'].get
23
27
  end
data/lib/blitz/command.rb CHANGED
@@ -29,6 +29,12 @@ class Command # :nodoc:
29
29
  include Test::Unit::Assertions
30
30
  include Helper
31
31
  include Term::ANSIColor
32
+
33
+ def shift key, argv
34
+ val = argv.shift
35
+ assert_not_nil(val, "missing value for #{key}")
36
+ val
37
+ end
32
38
  end
33
39
  end # Blitz
34
40
 
@@ -409,12 +409,6 @@ class Curl < Command # :nodoc:
409
409
 
410
410
  hash
411
411
  end
412
-
413
- def shift key, argv
414
- val = argv.shift
415
- assert_not_nil(val, "missing value for #{key}")
416
- val
417
- end
418
412
  end # Curl
419
413
  end # Command
420
414
  end # Blitz
@@ -10,6 +10,8 @@ class Help < Command # :nodoc:
10
10
  { :cmd => 'couch:fuzz', :help => 'Auto generate blitz tests from CouchDB' },
11
11
  { :cmd => 'curl', :help => 'Run a sprint or a rush' },
12
12
  { :cmd => 'curl:help', :help => 'Show help on sprint and rushing' },
13
+ { :cmd => 'traceroute', :help => 'Run traceroute remotely' },
14
+ { :cmd => 'traceroute:help', :help => 'Show help on traceroute' },
13
15
  { :cmd => 'version', :help => 'Show the version of this Ruby gem' }
14
16
  ]
15
17
 
@@ -0,0 +1,81 @@
1
+ class Blitz
2
+ class Command
3
+ class Traceroute < Command # :nodoc:
4
+ def cmd_help argv
5
+ puts
6
+ msg "Usage: blitz traceroute [-r <region>] host"
7
+ puts
8
+ end
9
+
10
+ def cmd_default argv
11
+ args = parse_cli argv
12
+
13
+ continue = true
14
+ last_index = nil
15
+ begin
16
+ [ 'INT', 'STOP', 'HUP' ].each do |s|
17
+ trap(s) { continue = false }
18
+ end
19
+
20
+ job = ::Blitz::Traceroute.queue args
21
+ msg "running from #{yellow(job.region)}..."
22
+ puts
23
+ job.result do |result|
24
+ print_result args, result, last_index
25
+ if not result.hops.empty?
26
+ last_index = result.hops.size
27
+ end
28
+ sleep 2.0 if not continue
29
+ continue
30
+ end
31
+ puts
32
+ msg "[#{red('aborted')}]" if not continue
33
+ rescue ::Blitz::Traceroute::Error::Region => e
34
+ error "#{yellow(e.region)}: #{red(e.message)}"
35
+ rescue ::Blitz::Traceroute::Error => e
36
+ error red(e.message)
37
+ end
38
+ end
39
+
40
+ def print_result args, result, last_index
41
+ if last_index and result.hops.size == last_index
42
+ return
43
+ end
44
+
45
+ result.hops[(last_index || 0)..result.hops.size].each do |hop|
46
+ if hop =~ /!/
47
+ puts red(hop)
48
+ elsif hop =~ /\*/
49
+ puts yellow(hop)
50
+ else
51
+ puts hop
52
+ end
53
+ end
54
+ end
55
+
56
+ private
57
+ def parse_cli argv
58
+ args = Hash.new
59
+
60
+ while not argv.empty?
61
+ break if argv.first[0,1] != '-'
62
+
63
+ k = argv.shift
64
+ if [ '-r', '--region' ].member? k
65
+ args['region'] = shift(k, argv)
66
+ next
67
+ end
68
+
69
+ raise ArgumentError, "Unknown option #{k}"
70
+ end
71
+
72
+ if argv.empty?
73
+ raise Test::Unit::AssertionFailedError, "missing host"
74
+ end
75
+
76
+ args['host'] = argv.shift
77
+ return args
78
+ end
79
+ end
80
+ end # Command
81
+ end # Blitz
@@ -0,0 +1,79 @@
1
+ class Blitz
2
+ class Traceroute
3
+ class Result
4
+ # The region from which the traceroute was executed
5
+ attr_reader :region
6
+
7
+ # The timeline of the rush containing various statistics.
8
+ attr_reader :hops
9
+
10
+ def initialize json # :nodoc:
11
+ result = json['result']
12
+ @region = result['region']
13
+ @hops = result['hops']
14
+ end
15
+ end
16
+
17
+ def self.execute args
18
+ self.queue(args).result
19
+ end
20
+
21
+ def self.queue args # :nodoc:
22
+ res = Command::API.client.traceroute_execute args
23
+ raise Error.new(res) if res['error']
24
+ return self.new res
25
+ end
26
+
27
+ attr_reader :job_id # :nodoc:
28
+ attr_reader :region # :nodoc:
29
+
30
+ def initialize json # :nodoc:
31
+ @job_id = json['job_id']
32
+ @region = json['region']
33
+ end
34
+
35
+ def result &block # :nodoc:
36
+ last = nil
37
+ while true
38
+ sleep 2.0
39
+
40
+ job = Command::API.client.job_status job_id
41
+ if job['error']
42
+ raise Error
43
+ end
44
+
45
+ result = job['result']
46
+ next if job['status'] == 'queued'
47
+ next if job['status'] == 'running' and not result
48
+
49
+ raise Error if not result
50
+
51
+ error = result['error']
52
+ if error
53
+ if error == 'dns'
54
+ raise Error::DNS.new(result)
55
+ elsif error == 'parse'
56
+ raise Error::Parse.new(result)
57
+ else
58
+ raise Error
59
+ end
60
+ end
61
+
62
+ last = Result.new(job)
63
+ continue = yield last rescue false
64
+ if continue == false
65
+ abort!
66
+ break
67
+ end
68
+
69
+ break if job['status'] == 'completed'
70
+ end
71
+
72
+ return last
73
+ end
74
+
75
+ def abort! # :nodoc:
76
+ Command::API.client.abort_job job_id rescue nil
77
+ end
78
+ end
79
+ end # blitz
@@ -0,0 +1,28 @@
1
+ class Blitz
2
+ class Traceroute
3
+ class Error < StandardError # :nodoc:
4
+ def initialize json={}
5
+ super json['reason'] || "Hmmm, something went wrong. Try again in a little bit?"
6
+ end
7
+
8
+ # The base class for all exceptions thrown by the distributed engines
9
+ class Region < Error
10
+ # The region from which the test was run
11
+ attr_reader :region
12
+
13
+ def initialize json # :nodoc:
14
+ @region = json['region']
15
+ super
16
+ end
17
+ end
18
+
19
+ # This exception is raised when the DNS resolution fails
20
+ class DNS < Region
21
+ end
22
+
23
+ # This exception is raised when the arguments to traceroute are invalid
24
+ class Parse < Region
25
+ end
26
+ end
27
+ end # Traceroute
28
+ end # Blitz
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: blitz
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.15
5
+ version: 0.1.16
6
6
  platform: ruby
7
7
  authors:
8
8
  - pcapr
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-13 00:00:00 -07:00
13
+ date: 2011-10-25 00:00:00 -07:00
14
14
  default_executable: blitz
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -148,11 +148,14 @@ files:
148
148
  - lib/blitz/command/couch.rb
149
149
  - lib/blitz/command/curl.rb
150
150
  - lib/blitz/command/help.rb
151
+ - lib/blitz/command/traceroute.rb
151
152
  - lib/blitz/command/version.rb
152
153
  - lib/blitz/curl/error.rb
153
154
  - lib/blitz/curl/rush.rb
154
155
  - lib/blitz/curl/sprint.rb
155
156
  - lib/blitz/helper.rb
157
+ - lib/blitz/traceroute.rb
158
+ - lib/blitz/traceroute/error.rb
156
159
  - spec/command/curl_spec.rb
157
160
  - test/helper.rb
158
161
  - test/test_blitz.rb
@@ -170,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
173
  requirements:
171
174
  - - ">="
172
175
  - !ruby/object:Gem::Version
173
- hash: 510668115
176
+ hash: -370311181
174
177
  segments:
175
178
  - 0
176
179
  version: "0"