engineyard 1.3.17 → 1.3.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,21 @@
1
1
  require 'rubygems'
2
2
  require 'sinatra/base'
3
3
  require 'json'
4
+ require File.expand_path('../scenarios', __FILE__)
4
5
 
5
6
  class FakeAwsm < Sinatra::Base
7
+ SCENARIOS = {
8
+ "empty" => Scenario::Base,
9
+ "one app, one environment, not linked" => Scenario::UnlinkedApp,
10
+ "two apps" => Scenario::TwoApps,
11
+ "one app, one environment" => Scenario::LinkedApp,
12
+ "two accounts, two apps, two environments, ambiguous" => Scenario::MultipleAmbiguousAccounts,
13
+ "one app, one environment, no instances" => Scenario::LinkedAppNotRunning,
14
+ "one app, one environment, app master red" => Scenario::LinkedAppRedMaster,
15
+ "one app, many environments" => Scenario::OneAppManyEnvs,
16
+ "one app, many similarly-named environments" => Scenario::OneAppManySimilarlyNamedEnvs,
17
+ "two apps, same git uri" => Scenario::TwoAppsSameGitUri,
18
+ }
6
19
 
7
20
  def initialize(*_)
8
21
  super
@@ -10,7 +23,7 @@ class FakeAwsm < Sinatra::Base
10
23
  # every request. It makes sense; you hardly ever want to keep
11
24
  # state in your application object (accidentally or otherwise),
12
25
  # but in this situation that's exactly what we want to do.
13
- @@cloud_mock = Scenario::Base # have to start somewhere
26
+ @@cloud_mock = CloudMock.new(Scenario::Base.new('git://example.com'))
14
27
  end
15
28
 
16
29
  before { content_type "application/json" }
@@ -21,36 +34,17 @@ class FakeAwsm < Sinatra::Base
21
34
  end
22
35
 
23
36
  put "/scenario" do
24
- new_scenario = case params[:scenario]
25
- when "empty"
26
- Scenario::Base
27
- when "one app, one environment, not linked"
28
- Scenario::UnlinkedApp
29
- when "two apps"
30
- Scenario::TwoApps
31
- when "one app, one environment"
32
- Scenario::LinkedApp
33
- when "two accounts, two apps, two environments, ambiguous"
34
- Scenario::MultipleAmbiguousAccounts
35
- when "one app, one environment, no instances"
36
- Scenario::LinkedAppNotRunning
37
- when "one app, one environment, app master red"
38
- Scenario::LinkedAppRedMaster
39
- when "one app, many environments"
40
- Scenario::OneAppManyEnvs
41
- when "one app, many similarly-named environments"
42
- Scenario::OneAppManySimilarlyNamedEnvs
43
- when "two apps, same git uri"
44
- Scenario::TwoAppsSameGitUri
45
- else
46
- status(400)
47
- return {"ok" => "false", "message" => "wtf is the #{params[:scenario]} scenario?"}.to_json
48
- end
37
+ new_scenario = SCENARIOS[params[:scenario]]
38
+ unless new_scenario
39
+ status(400)
40
+ return {"ok" => "false", "message" => "wtf is the #{params[:scenario]} scenario?"}.to_json
41
+ end
49
42
  @@cloud_mock = CloudMock.new(new_scenario.new(params[:remote]))
50
43
  {"ok" => "true"}.to_json
51
44
  end
52
45
 
53
46
  get "/api/v2/apps" do
47
+ raise('No user agent header') unless env['HTTP_USER_AGENT'] =~ %r#^EngineYardCLI/#
54
48
  {"apps" => @@cloud_mock.apps}.to_json
55
49
  end
56
50
 
@@ -226,368 +220,6 @@ private
226
220
  end
227
221
  end
228
222
  end
229
-
230
- module Scenario
231
- class Base
232
- attr_accessor :git_remote
233
-
234
- def initialize(git_remote)
235
- self.git_remote = git_remote
236
- end
237
-
238
- def starting_accounts() [{"name" => "main"}] end
239
- def starting_apps() [] end
240
- def starting_environments() [] end
241
- def starting_app_joins() [] end
242
-
243
- end
244
-
245
- class LinkedApp < Base
246
- def _instances
247
- [{
248
- "id" => 27220,
249
- "role" => "app_master",
250
- "name" => nil,
251
- "status" => "running",
252
- "amazon_id" => 'i-ddbbdd92',
253
- "public_hostname" => "app_master_hostname.compute-1.amazonaws.com",
254
- }, {
255
- "id" => 22721,
256
- "name" => nil,
257
- "role" => "db_master",
258
- "status" => "running",
259
- "amazon_id" => "i-d4cdddbf",
260
- "public_hostname" => "db_master_hostname.compute-1.amazonaws.com",
261
- }, {
262
- "id" => 22724,
263
- "name" => nil,
264
- "role" => "db_slave",
265
- "status" => "running",
266
- "amazon_id" => "i-asdfasdfaj",
267
- "public_hostname" => "db_slave_1_hostname.compute-1.amazonaws.com",
268
- }, {
269
- "id" => 22725,
270
- "name" => nil,
271
- "role" => "db_slave",
272
- "status" => "running",
273
- "amazon_id" => "i-asdfasdfaj",
274
- "public_hostname" => "db_slave_2_hostname.compute-1.amazonaws.com",
275
- }, {
276
- "id" => 22722,
277
- "role" => "app",
278
- "name" => nil,
279
- "status" => "building",
280
- "amazon_id" => "i-d2e3f1b9",
281
- "public_hostname" => "app_hostname.compute-1.amazonaws.com",
282
- }, {
283
- "id" => 22723,
284
- "role" => "util",
285
- "name" => "fluffy",
286
- "status" => "running",
287
- "amazon_id" => "i-80e3f1eb",
288
- "public_hostname" => "util_fluffy_hostname.compute-1.amazonaws.com",
289
- }, {
290
- "id" => 22727,
291
- "role" => "util",
292
- "name" => "rocky",
293
- "status" => "running",
294
- "amazon_id" => "i-80etf1eb",
295
- "public_hostname" => "util_rocky_hostname.compute-1.amazonaws.com",
296
- }]
297
- end
298
- private :_instances
299
-
300
- def starting_apps
301
- [{
302
- "id" => 1001,
303
- "name" => "rails232app",
304
- "repository_uri" => git_remote}]
305
- end
306
-
307
- def starting_environments
308
- [{
309
- "id" => 200,
310
- "ssh_username" => "turkey",
311
- "instances" => _instances,
312
- "name" => "giblets",
313
- "instances_count" => 4,
314
- "stack_name" => "nginx_mongrel",
315
- "framework_env" => "production"}]
316
- end
317
-
318
- def starting_app_joins
319
- [[1001, 200]]
320
- end
321
-
322
- end # LinkedApp
323
-
324
- class MultipleAmbiguousAccounts < LinkedApp
325
- def starting_accounts
326
- super + [{"name" => "account_2", "id" => 256}]
327
- end
328
-
329
- def starting_apps
330
- apps = super
331
- new_app = apps.first.dup
332
- new_app["id"] += 1000
333
- new_app["account"] = starting_accounts.last
334
- apps + [new_app]
335
- end
336
-
337
- def starting_environments
338
- envs = super
339
- new_env = envs.first.dup
340
- new_env["id"] += 1000
341
- new_env["account"] = starting_accounts.last
342
- envs + [new_env]
343
- end
344
-
345
- def starting_app_joins
346
- joins = super
347
- new_join = [joins.first[0] + 1000,
348
- joins.first[1] + 1000]
349
- joins + [new_join]
350
- end
351
- end
352
-
353
- class UnlinkedApp < Base
354
- def starting_apps
355
- [{
356
- "id" => 1001,
357
- "name" => "rails232app",
358
- "repository_uri" => git_remote}]
359
- end
360
-
361
- def starting_environments
362
- [{
363
- "ssh_username" => "turkey",
364
- "instances" => [{
365
- "status" => "running",
366
- "id" => 27220,
367
- "amazon_id" => 'i-ddbbdd92',
368
- "role" => "solo",
369
- "public_hostname" => "ec2-174-129-198-124.compute-1.amazonaws.com"}],
370
- "name" => "giblets",
371
- "instances_count" => 1,
372
- "stack_name" => "nginx_mongrel",
373
- "id" => 200,
374
- "framework_env" => "production"}]
375
- end
376
- end # UnlinkedApp
377
-
378
- class LinkedAppNotRunning < Base
379
- def starting_apps
380
- [{
381
- "id" => 1001,
382
- "name" => "rails232app",
383
- "repository_uri" => git_remote}]
384
- end
385
-
386
- def starting_environments
387
- [{
388
- "ssh_username" => "turkey",
389
- "instances" => [],
390
- "name" => "giblets",
391
- "instances_count" => 0,
392
- "stack_name" => "nginx_mongrel",
393
- "id" => 200,
394
- "framework_env" => "production"}]
395
- end
396
-
397
- def starting_app_joins
398
- [[1001, 200]]
399
- end
400
- end # LinkedAppNotRunning
401
-
402
- class LinkedAppRedMaster < LinkedApp
403
- def starting_environments
404
- envs = super
405
- envs[0]["instances"][0]["status"] = "error"
406
- envs
407
- end
408
- end
409
-
410
- class OneAppManyEnvs < Base
411
- def starting_apps
412
- [{
413
- "id" => 1001,
414
- "name" => "rails232app",
415
- "repository_uri" => git_remote}]
416
- end
417
-
418
- def starting_app_joins
419
- [
420
- [1001, 200],
421
- [1001, 202],
422
- ]
423
- end
424
-
425
- def starting_environments
426
- [{
427
- "ssh_username" => "turkey",
428
- "instances" => [{
429
- "status" => "running",
430
- "id" => 27220,
431
- "amazon_id" => 'i-ddbbdd92',
432
- "role" => "solo",
433
- "public_hostname" => "app_master_hostname.compute-1.amazonaws.com"}],
434
- "name" => "giblets",
435
- "instances_count" => 1,
436
- "stack_name" => "nginx_mongrel",
437
- "id" => 200,
438
- "framework_env" => "production",
439
- }, {
440
- "ssh_username" => "ham",
441
- "instances" => [],
442
- "name" => "bakon",
443
- "instances_count" => 0,
444
- "stack_name" => "nginx_passenger",
445
- "id" => 202,
446
- }, {
447
- "ssh_username" => "hamburger",
448
- "instances" => [],
449
- "name" => "beef",
450
- "instances_count" => 0,
451
- "stack_name" => "nginx_passenger",
452
- "id" => 206,
453
- }]
454
- end
455
- end # OneAppTwoEnvs
456
-
457
- class TwoApps < Base
458
- def railsapp_master
459
- {
460
- "status" => "running",
461
- "name" => nil,
462
- "role" => "solo",
463
- "public_hostname" => "ec2-174-129-7-113.compute-1.amazonaws.com",
464
- "id" => 35707,
465
- "amazon_id" => "i-0911f063",
466
- }
467
- end
468
- private :railsapp_master
469
-
470
- def keycollector_master
471
- {
472
- "status" => "running",
473
- "name" => nil,
474
- "role" => "solo",
475
- "public_hostname" => "app_master_hostname.compute-1.amazonaws.com",
476
- "id" => 75428,
477
- "amazon_id" => "i-051195b9",
478
- }
479
- end
480
- private :keycollector_master
481
-
482
- def starting_apps
483
- [{
484
- "id" => 3202,
485
- "name" => "keycollector",
486
- "repository_uri" => "git@github.com:smerritt/keycollector.git",
487
- }, {
488
- "id" => 6125,
489
- "name" => "rails232app",
490
- "repository_uri" => "git://github.com/smerritt/rails232app.git"}]
491
- end
492
-
493
- def starting_app_joins
494
- [
495
- [6125, 200],
496
- [3202, 439],
497
- ]
498
- end
499
-
500
- def starting_environments
501
- [{
502
- "id" => 200,
503
- "name" => "giblets",
504
- "framework_env" => "staging",
505
- "ssh_username" => "turkey",
506
- "instances_count" => 1,
507
- "instances" => [railsapp_master],
508
- "stack_name" => "nginx_unicorn",
509
- }, {
510
- "id" => 439,
511
- "framework_env" => "production",
512
- "name" => "keycollector_production",
513
- "ssh_username" => "deploy",
514
- "stack_name" => "nginx_mongrel",
515
- "instances_count" => 1,
516
- "instances" => [keycollector_master],
517
- }]
518
- end
519
- end # TwoApps
520
-
521
- class TwoAppsSameGitUri < TwoApps
522
- def starting_apps
523
- apps = super
524
- apps.each do |app|
525
- app["repository_uri"] = "git://github.com/engineyard/dup.git"
526
- end
527
- apps
528
- end
529
- end # TwoAppsSameGitUri
530
-
531
- class OneAppManySimilarlyNamedEnvs < Base
532
- def starting_apps
533
- [{
534
- "id" => 1001,
535
- "name" => "rails232app",
536
- "repository_uri" => git_remote}]
537
- end
538
-
539
- def starting_environments
540
- [{
541
- "id" => 200,
542
- "ssh_username" => "turkey",
543
- "instances" => [{
544
- "status" => "running",
545
- "id" => 27220,
546
- "amazon_id" => 'i-ddbbdd92',
547
- "role" => "solo",
548
- "public_hostname" => "app_master_hostname.compute-1.amazonaws.com"}],
549
- "name" => "railsapp_production",
550
- "instances_count" => 1,
551
- "stack_name" => "nginx_mongrel",
552
- "framework_env" => "production",
553
- }, {
554
- "id" => 202,
555
- "ssh_username" => "ham",
556
- "instances" => [{
557
- "public_hostname" => '127.3.2.1',
558
- "status" => "running",
559
- "id" => 63066,
560
- "role" => "solo",
561
- }],
562
- "name" => "railsapp_staging",
563
- "instances_count" => 1,
564
- "stack_name" => "nginx_passenger",
565
- "framework_env" => "production",
566
- }, {
567
- "ssh_username" => "ham",
568
- "instances" => [{
569
- "status" => "running",
570
- "id" => 59395,
571
- "role" => "solo",
572
- "public_hostname" => "ec2-174-129-198-124.compute-1.amazonaws.com",
573
- }],
574
- "name" => "railsapp_staging_2",
575
- "instances_count" => 1,
576
- "stack_name" => "nginx_passenger",
577
- "id" => 204,
578
- "framework_env" => "production",
579
- }]
580
- end
581
-
582
- def starting_app_joins
583
- [
584
- [1001, 200],
585
- [1001, 202],
586
- [1001, 204],
587
- ]
588
- end
589
- end # OneAppManySimilarlyNamedEnvs
590
- end
591
223
  end
592
224
 
593
225
  run FakeAwsm.new
Binary file
@@ -187,6 +187,16 @@ module Spec
187
187
  end
188
188
 
189
189
  end
190
+
191
+ module Fixtures
192
+ def fixture_recipes_tgz
193
+ File.expand_path('../fixture_recipes.tgz', __FILE__)
194
+ end
195
+
196
+ def link_recipes_tgz(git_dir)
197
+ system("ln -s #{fixture_recipes_tgz} #{git_dir.join('recipes.tgz')}")
198
+ end
199
+ end
190
200
  end
191
201
  end
192
202