stella 0.8.2.003 → 0.8.3.001

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stella
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2.003
4
+ version: 0.8.3.001
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-06 00:00:00 -05:00
12
+ date: 2010-03-15 00:00:00 -04:00
13
13
  default_executable: stella
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.5.8
43
+ version: 0.5.11
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: sysinfo
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 0.6.3
63
+ version: 0.6.4
64
64
  version:
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: nokogiri
@@ -114,7 +114,6 @@ files:
114
114
  - lib/stella/engine/load.rb
115
115
  - lib/stella/guidelines.rb
116
116
  - lib/stella/logger.rb
117
- - lib/stella/service.rb
118
117
  - lib/stella/testplan.rb
119
118
  - lib/stella/utils.rb
120
119
  - lib/stella/utils/httputil.rb
@@ -1,334 +0,0 @@
1
- Stella::Utils.require_vendor "httpclient", '2.1.5.2'
2
-
3
- class Hash
4
-
5
- # Courtesy of Julien Genestoux
6
- def flatten
7
- params = {}
8
- stack = []
9
-
10
- each do |k, v|
11
- if v.is_a?(Hash)
12
- stack << [k,v]
13
- elsif v.is_a?(Array)
14
- stack << [k,Hash.from_array(v)]
15
- else
16
- params[k] = v
17
- end
18
- end
19
-
20
- stack.each do |parent, hash|
21
- hash.each do |k, v|
22
- if v.is_a?(Hash)
23
- stack << ["#{parent}[#{k}]", v]
24
- else
25
- params["#{parent}[#{k}]"] = v
26
- end
27
- end
28
- end
29
-
30
- params
31
- end
32
-
33
- # Courtesy of Julien Genestoux
34
- # See: http://stackoverflow.com/questions/798710/how-to-turn-a-ruby-hash-into-http-params
35
- def to_params
36
- params = ''
37
- stack = []
38
-
39
- each do |k, v|
40
- if v.is_a?(Hash)
41
- stack << [k,v]
42
- elsif v.is_a?(Array)
43
- stack << [k,Hash.from_array(v)]
44
- else
45
- params << "#{k}=#{v}&"
46
- end
47
- end
48
-
49
- stack.each do |parent, hash|
50
- hash.each do |k, v|
51
- if v.is_a?(Hash)
52
- stack << ["#{parent}[#{k}]", v]
53
- else
54
- params << "#{parent}[#{k}]=#{v}&"
55
- end
56
- end
57
- end
58
-
59
- params.chop!
60
- params
61
- end
62
- def self.from_array(array = [])
63
- h = Hash.new
64
- array.size.times do |t|
65
- h[t] = array[t]
66
- end
67
- h
68
- end
69
-
70
- end
71
-
72
-
73
- class Stella::Service
74
- attr_accessor :runid, :tid, :uid, :rtid
75
- class Problem < Stella::Error
76
- def res() @obj end
77
- end
78
- module V1
79
- class NoTestplanSelected < Problem; end
80
- class NoUsecaseSelected < Problem; end
81
- class NoRequestSelected < Problem; end
82
- class NoTestrunSelected < Problem; end
83
- def testplan?(digest)
84
- req = uri('v1', 'testplan', "#{digest}.json")
85
- res = send_request :get, req
86
- !res.content.empty?
87
- rescue Stella::Service::Problem => ex
88
- raise ex unless ex.res.status == 404
89
- false
90
- end
91
- def testrun?(digest)
92
- req = uri('v1', 'testrun', "#{digest}.json")
93
- res = send_request :get, req
94
- !res.content.empty?
95
- rescue Stella::Service::Problem => ex
96
- raise ex unless ex.res.status == 404
97
- false
98
- end
99
- def testplan_create(desc, opts={})
100
- req = uri('v1', 'testplan', "create.json")
101
- params = {
102
- :desc => desc
103
- }.merge! opts
104
- res = send_request :post, req, params
105
- obj = JSON.parse res.content
106
- Stella.ld "CREATED TP: #{obj.inspect}"
107
- @tid = obj['digest']
108
- end
109
- def usecase_create(desc, opts={})
110
- raise NoTestplanSelected unless @tid
111
- req = uri('v1', 'testplan', 'usecase', "create.json")
112
- params = {
113
- :tid => @tid,
114
- :desc => desc
115
- }.merge! opts
116
-
117
- res = send_request :post, req, params
118
- obj = JSON.parse res.content
119
- Stella.ld "CREATED UC: #{obj.inspect}"
120
- @uid = obj['digest']
121
- end
122
- def request_create(uri, opts={})
123
- raise NoUsecaseSelected unless @uid
124
- req = uri('v1', 'testplan', 'usecase', 'request', "create.json")
125
- params = {
126
- :tid => @tid,
127
- :uid => @uid,
128
- :uri => uri
129
- }.merge! opts
130
- res = send_request :post, req, params
131
- obj = JSON.parse res.content
132
- @rtid = obj['digest']
133
- end
134
- def testrun_create(trun)
135
- raise NoTestplanSelected unless @tid
136
- req = uri('v1', 'testrun', "create.json")
137
- params = {
138
- :tid => @tid,
139
- :v => Stella::VERSION.to_s,
140
- :start_at => Stella::START_TIME.to_i,
141
- :mode => trun.mode,
142
- :clients => trun.clients,
143
- :duration => trun.duration,
144
- :arrival => trun.arrival,
145
- :repetitions => trun.repetitions,
146
- :nowait => trun.nowait,
147
- :hosts => trun.hosts,
148
- :status => 'created'
149
- }
150
- res = send_request :post, req, params
151
- obj = JSON.parse res.content
152
- Stella.ld "CREATED TRUN: #{obj.inspect}"
153
- trun.remote_digest = obj['digest']
154
- @runid = obj['digest']
155
- end
156
- def testrun_stats(stats, samples)
157
- raise NoTestrunSelected, "no testrun: #{runid}" unless @runid
158
- req = uri('v1', 'testrun', "stats.json")
159
- params = {
160
- :runid => @runid,
161
- :status => 'running',
162
- :stats => stats.to_json,
163
- :samples => samples.to_json
164
- }
165
- res = send_request :post, req, params
166
- obj = JSON.parse res.content
167
- Stella.ld "TESTRUN STATS: #{obj.inspect}"
168
- @runid
169
- end
170
- def testrun_finalize(duration)
171
- raise NoTestrunSelected unless @runid
172
- req = uri('v1', 'testrun', "finalize.json")
173
- params = {
174
- :runid => @runid,
175
- :duration => duration,
176
- :status => 'complete'
177
- }
178
- res = send_request :post, req, params
179
- obj = JSON.parse res.content
180
- Stella.ld "FINALIZE TESTRUN: #{obj.inspect}"
181
- @runid
182
- end
183
- def client_create(clientid, opts={})
184
- raise NoTestrunSelected unless @runid
185
- req = uri('v1', 'client', "create.json")
186
- params = {
187
- :runid => @runid,
188
- :clientid => clientid
189
- }.merge! opts
190
- res = send_request :post, req, params
191
- obj = JSON.parse res.content
192
- @rtid = obj['digest']
193
- end
194
- def client_log(clientid, data, opts={})
195
- raise NoTestrunSelected unless @runid
196
- req = uri('v1', 'client', clientid, 'log.json')
197
- params = {
198
- :data => data
199
- }.merge! opts
200
- res = send_request :post, req, params
201
- obj = JSON.parse res.content
202
- Stella.ld "LOGGED: #{obj.inspect}"
203
- obj
204
- end
205
- # Returns true if the testplan was created.
206
- # Otherwise false if it already exists.
207
- def testplan_sync(plan)
208
- if testplan? plan.digest
209
- @tid = plan.digest
210
- return false
211
- end
212
- Stella.stdout.info "Syncing Testplan #{plan.digest.short}"
213
- testplan_create plan.desc, :digest => plan.digest
214
- plan.usecases.each do |uc|
215
- Stella.stdout.info "Syncing Usecase #{uc.digest.short}"
216
- props = uc.to_hash
217
- props[:digest] ||= uc.digest
218
- usecase_create uc.desc, props
219
- uc.requests.each do |req|
220
- props = req.to_hash
221
- props[:digest] ||= req.digest
222
- props[:desc] = props.delete :description
223
- request_create props[:uri], props
224
- end
225
- end
226
- true
227
- end
228
- end
229
- end
230
-
231
- class Stella::Service
232
- unless defined?(API_VERSION)
233
- TOKEN = (ENV['STELLA_TOKEN'] || nil).freeze
234
- end
235
-
236
- include Stella::Service::V1
237
-
238
- attr_reader :http_client
239
- attr_accessor :proxy
240
- attr_reader :conf
241
-
242
- attr_reader :source
243
- attr_reader :apikey
244
-
245
- attr_accessor :tid, :uid, :rtid, :runid
246
-
247
- def initialize(source=nil,apikey=nil)
248
- begin
249
- require 'bone'
250
- rescue LoadError
251
- end
252
- if defined?(Bone)
253
- source ||= Bone['STELLA_SOURCE'] rescue nil
254
- apikey ||= Bone['STELLA_TOKEN'] rescue nil
255
- end
256
- source ||= ENV['STELLA_SOURCE']
257
- apikey ||= ENV['STELLA_TOKEN']
258
- @source, @apikey = source, apikey
259
- @proxy = OpenStruct.new
260
- @http_client = create_http_client
261
- raise Stella::Error, "Set STELLA_SOURCE" unless @source
262
- raise Stella::Error, "Set STELLA_TOKEN" unless @apikey
263
- end
264
-
265
- def uri(*parts)
266
- uri = URI.parse @source
267
- uri.path = '/stella/' << parts.join( '/')
268
- Stella.ld "SERVICE URI: #{uri}"
269
- uri
270
- end
271
-
272
- def send_request(meth, uri, params={}, headers={})
273
- headers['X-TOKEN'] ||= @apikey
274
-
275
- params = process_params(params)
276
-
277
- if meth == "delete"
278
- args = [meth, uri, headers]
279
- else
280
- args = [meth, uri, params, headers]
281
- end
282
- res = @http_client.send(*args) # booya!
283
-
284
- if res.status > 200
285
- raise Problem.new(res)
286
- end
287
-
288
- res
289
- end
290
-
291
- private
292
- # Turn nested Hashes into: "key[name][1]" etc...
293
- def process_params(raw={})
294
- cooked = {}
295
- raw.each_pair do |k,v|
296
- cooked.merge!(process_enumerable(k, v)) and next if Enumerable === v
297
- cooked[k] = v
298
- end
299
- cooked
300
- end
301
-
302
- def process_enumerable(k,v)
303
- cooked = {}
304
- case v.class.to_s
305
- when "Array"
306
- v.each_with_index do |v2,index|
307
- name = "#{k}[#{index}]"
308
- cooked[name] = Enumerable === v2 ? process_enumerable(name, v2) : v2
309
- end
310
- when "Hash"
311
- v.each_pair do |k2,v2|
312
- name = "#{k}[#{k2}]"
313
- cooked[name] = Enumerable === v2 ? process_enumerable(name, v2) : v2
314
- end
315
- end
316
- cooked
317
- end
318
-
319
- def create_http_client
320
- opts = {
321
- :proxy => @proxy.uri || nil, # a tautology for clarity
322
- :agent_name => "Stella/#{Stella::VERSION}",
323
- :from => nil
324
- }
325
- http_client = HTTPClient.new opts
326
- http_client.set_proxy_auth(@proxy.user, @proxy.pass) if @proxy.user
327
- http_client.debug_dev = STDOUT if Stella.debug? && Stella.log.lev > 1
328
- http_client.protocol_version = "HTTP/1.1"
329
- #http_client.ssl_config.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
330
- http_client
331
- end
332
-
333
- end
334
-