rhc 0.98.16 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/rhc +7 -49
- data/bin/rhc-app +14 -3
- data/bin/rhc-chk +16 -16
- data/bin/rhc-create-app +2 -0
- data/bin/rhc-create-domain +1 -2
- data/bin/rhc-ctl-app +12 -3
- data/bin/rhc-ctl-domain +1 -2
- data/bin/rhc-domain +1 -2
- data/bin/rhc-domain-info +1 -2
- data/bin/rhc-port-forward +1 -2
- data/bin/rhc-snapshot +3 -0
- data/bin/rhc-sshkey +1 -2
- data/bin/rhc-tail-files +1 -1
- data/bin/rhc-user-info +1 -3
- data/features/application.feature +4 -1
- data/features/domain.feature +0 -4
- data/features/geared_application.feature +11 -0
- data/features/lib/rhc_helper/app.rb +16 -5
- data/features/lib/rhc_helper/cartridge.rb +25 -9
- data/features/lib/rhc_helper/commandify.rb +34 -7
- data/features/lib/rhc_helper/domain.rb +2 -2
- data/features/lib/rhc_helper/httpify.rb +24 -14
- data/features/lib/rhc_helper/persistable.rb +1 -1
- data/features/lib/rhc_helper/sshkey.rb +11 -7
- data/features/lib/rhc_helper.rb +5 -3
- data/features/multiple_cartridge.feature +1 -1
- data/features/scaled_application.feature +48 -0
- data/features/sshkey.feature +37 -31
- data/features/step_definitions/application_steps.rb +18 -7
- data/features/step_definitions/cartridge_steps.rb +29 -3
- data/features/step_definitions/domain_steps.rb +2 -2
- data/features/step_definitions/sshkey_steps.rb +34 -34
- data/features/support/assumptions.rb +21 -9
- data/features/support/before_hooks.rb +24 -6
- data/features/support/env.rb +45 -19
- data/lib/rhc/cartridge_helper.rb +27 -0
- data/lib/rhc/cli.rb +1 -1
- data/lib/rhc/command_runner.rb +31 -3
- data/lib/rhc/commands/alias.rb +38 -0
- data/lib/rhc/commands/app.rb +478 -0
- data/lib/rhc/commands/base.rb +42 -12
- data/lib/rhc/commands/cartridge.rb +189 -0
- data/lib/rhc/commands/domain.rb +11 -49
- data/lib/rhc/commands/port-forward.rb +0 -1
- data/lib/rhc/commands/setup.rb +2 -1
- data/lib/rhc/commands/snapshot.rb +118 -0
- data/lib/rhc/commands/sshkey.rb +24 -38
- data/lib/rhc/commands/tail.rb +24 -0
- data/lib/rhc/commands/threaddump.rb +16 -0
- data/lib/rhc/commands.rb +33 -7
- data/lib/rhc/config.rb +28 -12
- data/lib/rhc/context_helper.rb +19 -5
- data/lib/rhc/core_ext.rb +86 -0
- data/lib/rhc/exceptions.rb +44 -0
- data/lib/rhc/git_helper.rb +59 -0
- data/lib/rhc/helpers.rb +86 -5
- data/lib/rhc/output_helpers.rb +213 -0
- data/lib/rhc/rest/application.rb +134 -67
- data/lib/rhc/rest/base.rb +48 -0
- data/lib/rhc/rest/cartridge.rb +40 -44
- data/lib/rhc/rest/client.rb +127 -59
- data/lib/rhc/rest/domain.rb +29 -39
- data/lib/rhc/rest/gear_group.rb +10 -0
- data/lib/rhc/rest/key.rb +8 -23
- data/lib/rhc/rest/user.rb +8 -24
- data/lib/rhc/rest.rb +22 -11
- data/lib/rhc/ssh_key_helpers.rb +47 -0
- data/lib/rhc/usage_templates/help.erb +0 -1
- data/lib/rhc/version.rb +3 -3
- data/lib/rhc/wizard.rb +123 -225
- data/lib/rhc-common.rb +43 -62
- data/spec/rest_spec_helper.rb +159 -36
- data/spec/rhc/cli_spec.rb +29 -1
- data/spec/rhc/command_spec.rb +32 -35
- data/spec/rhc/commands/alias_spec.rb +123 -0
- data/spec/rhc/commands/app_spec.rb +414 -0
- data/spec/rhc/commands/cartridge_spec.rb +342 -0
- data/spec/rhc/commands/domain_spec.rb +8 -8
- data/spec/rhc/commands/setup_spec.rb +17 -6
- data/spec/rhc/commands/snapshot_spec.rb +140 -0
- data/spec/rhc/commands/sshkey_spec.rb +26 -4
- data/spec/rhc/commands/tail_spec.rb +34 -0
- data/spec/rhc/commands/threaddump_spec.rb +83 -0
- data/spec/rhc/config_spec.rb +39 -13
- data/spec/rhc/context_spec.rb +51 -0
- data/spec/rhc/helpers_spec.rb +52 -12
- data/spec/rhc/rest_application_spec.rb +16 -3
- data/spec/rhc/rest_client_spec.rb +144 -36
- data/spec/rhc/rest_spec.rb +1 -1
- data/spec/rhc/wizard_spec.rb +133 -232
- data/spec/spec_helper.rb +4 -3
- metadata +56 -31
- data/features/support/ssh.sh +0 -2
- data/spec/rhc/common_spec.rb +0 -49
data/spec/rhc/wizard_spec.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'rest_spec_helper'
|
2
3
|
require 'rhc/wizard'
|
3
4
|
require 'rhc/vendor/parseconfig'
|
4
5
|
require 'rhc/config'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'rest_spec_helper'
|
5
8
|
|
6
9
|
describe RHC::Wizard do
|
7
10
|
before(:all) do
|
8
11
|
mock_terminal
|
12
|
+
RHC::Config.set_defaults
|
9
13
|
FakeFS.activate!
|
14
|
+
FakeFS::FileSystem.clear
|
10
15
|
end
|
11
16
|
|
12
17
|
after(:all) do
|
13
|
-
FakeFS::FileSystem.clear
|
14
18
|
FakeFS.deactivate!
|
15
19
|
end
|
16
20
|
|
@@ -33,7 +37,6 @@ describe RHC::Wizard do
|
|
33
37
|
$terminal.write_line "#{@wizard.mock_user}"
|
34
38
|
$terminal.write_line "password"
|
35
39
|
|
36
|
-
@wizard.stub_user_info
|
37
40
|
|
38
41
|
@wizard.run_next_stage
|
39
42
|
|
@@ -63,9 +66,10 @@ describe RHC::Wizard do
|
|
63
66
|
end
|
64
67
|
|
65
68
|
it "should ask to upload ssh keys" do
|
66
|
-
|
67
|
-
@wizard.set_expected_key_name_and_action('default', 'add')
|
69
|
+
@rest_client.stub(:get_ssh_keys) { @wizard.get_mock_key_data }
|
68
70
|
$terminal.write_line('yes')
|
71
|
+
@wizard.stub_rhc_client_new
|
72
|
+
@wizard.ssh_keys = []
|
69
73
|
@wizard.run_next_stage
|
70
74
|
end
|
71
75
|
|
@@ -77,7 +81,6 @@ describe RHC::Wizard do
|
|
77
81
|
end
|
78
82
|
|
79
83
|
it "should ask for a namespace" do
|
80
|
-
@wizard.stub_user_info
|
81
84
|
$terminal.write_line("thisnamespaceistoobigandhastoomanycharacterstobevalid")
|
82
85
|
|
83
86
|
$terminal.write_line("invalidnamespace")
|
@@ -88,14 +91,9 @@ describe RHC::Wizard do
|
|
88
91
|
end
|
89
92
|
|
90
93
|
it "should show app creation commands" do
|
91
|
-
mock_carts = ['ruby', 'python', 'jbosseap']
|
92
|
-
RHC.stub(:get_cartridges_list) { mock_carts }
|
93
|
-
@wizard.stub_user_info
|
94
94
|
@wizard.run_next_stage
|
95
95
|
output = $terminal.read
|
96
|
-
|
97
|
-
output.should match("\\* #{cart} - rhc app create -t #{cart} -a <app name>")
|
98
|
-
end
|
96
|
+
output.should match 'Below is a list of'
|
99
97
|
end
|
100
98
|
|
101
99
|
it "should show a thank you message" do
|
@@ -123,8 +121,6 @@ describe RHC::Wizard do
|
|
123
121
|
$terminal.write_line "#{@wizard.mock_user}"
|
124
122
|
$terminal.write_line "password"
|
125
123
|
|
126
|
-
@wizard.stub_user_info
|
127
|
-
|
128
124
|
@wizard.run_next_stage
|
129
125
|
|
130
126
|
output = $terminal.read
|
@@ -153,8 +149,8 @@ describe RHC::Wizard do
|
|
153
149
|
end
|
154
150
|
|
155
151
|
it "should upload ssh key as default" do
|
156
|
-
|
157
|
-
@wizard.
|
152
|
+
@rest_client.stub(:sshkeys) {[]}
|
153
|
+
@wizard.stub(:get_preferred_key_name) { 'default' }
|
158
154
|
$terminal.write_line('yes')
|
159
155
|
@wizard.run_next_stage
|
160
156
|
end
|
@@ -168,7 +164,6 @@ describe RHC::Wizard do
|
|
168
164
|
end
|
169
165
|
|
170
166
|
it "should ask for a namespace" do
|
171
|
-
@wizard.stub_user_info
|
172
167
|
$terminal.write_line("testnamespace")
|
173
168
|
@wizard.run_next_stage
|
174
169
|
output = $terminal.read
|
@@ -176,14 +171,9 @@ describe RHC::Wizard do
|
|
176
171
|
end
|
177
172
|
|
178
173
|
it "should show app creation commands" do
|
179
|
-
mock_carts = ['ruby', 'python', 'jbosseap']
|
180
|
-
RHC.stub(:get_cartridges_list) { mock_carts }
|
181
|
-
@wizard.stub_user_info
|
182
174
|
@wizard.run_next_stage
|
183
175
|
output = $terminal.read
|
184
|
-
|
185
|
-
output.should match("\\* #{cart} - rhc app create -t #{cart} -a <app name>")
|
186
|
-
end
|
176
|
+
output.should match 'Below is a list of'
|
187
177
|
end
|
188
178
|
|
189
179
|
it "should show a thank you message" do
|
@@ -203,7 +193,6 @@ describe RHC::Wizard do
|
|
203
193
|
|
204
194
|
it "should ask for password input with default login" do
|
205
195
|
@wizard.stub_rhc_client_new
|
206
|
-
@wizard.stub_user_info
|
207
196
|
|
208
197
|
$terminal.write_line("") # hit enter for default
|
209
198
|
$terminal.write_line "password"
|
@@ -234,35 +223,32 @@ describe RHC::Wizard do
|
|
234
223
|
File.exists?(public_key_file).should be true
|
235
224
|
end
|
236
225
|
|
237
|
-
it "should find out that you have not uploaded the
|
226
|
+
it "should find out that you have not uploaded the default key and ask to name the key" do
|
238
227
|
key_data = @wizard.get_mock_key_data
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
228
|
+
@wizard.ssh_keys = key_data
|
229
|
+
key_name = '73ce2cc1'
|
230
|
+
|
243
231
|
fingerprint, short_name = @wizard.get_key_fingerprint
|
244
|
-
@wizard.
|
232
|
+
@wizard.rest_client.stub(:find_key) { key_data.detect{|k| k.name == key_name} }
|
245
233
|
$terminal.write_line('yes')
|
246
|
-
$terminal.write_line(
|
234
|
+
$terminal.write_line(key_name) # answering with an existing key name
|
247
235
|
@wizard.run_next_stage
|
248
236
|
output = $terminal.read
|
249
|
-
|
250
|
-
|
251
|
-
output.should match("#{key
|
237
|
+
key_data.each do |key|
|
238
|
+
output.should match("Name: #{key.name}")
|
239
|
+
output.should match("Fingerprint: #{key.fingerprint}")
|
252
240
|
end
|
253
|
-
output.should match("|#{short_name}|")
|
241
|
+
output.should match("|#{short_name}|") # prompt with the default name
|
254
242
|
end
|
255
243
|
|
256
|
-
it "should check for client tools
|
257
|
-
@wizard.
|
258
|
-
|
244
|
+
it "should check for client tools and find them" do
|
245
|
+
@wizard.setup_mock_has_git(true)
|
259
246
|
@wizard.run_next_stage
|
260
247
|
output = $terminal.read
|
261
248
|
output.should match("Checking for git \.\.\. found")
|
262
249
|
end
|
263
250
|
|
264
251
|
it "should ask for a namespace" do
|
265
|
-
@wizard.stub_user_info
|
266
252
|
$terminal.write_line("testnamespace")
|
267
253
|
@wizard.run_next_stage
|
268
254
|
output = $terminal.read
|
@@ -270,14 +256,9 @@ describe RHC::Wizard do
|
|
270
256
|
end
|
271
257
|
|
272
258
|
it "should show app creation commands" do
|
273
|
-
mock_carts = ['ruby', 'python', 'jbosseap']
|
274
|
-
RHC.stub(:get_cartridges_list) { mock_carts }
|
275
|
-
@wizard.stub_user_info
|
276
259
|
@wizard.run_next_stage
|
277
260
|
output = $terminal.read
|
278
|
-
|
279
|
-
output.should match("\\* #{cart} - rhc app create -t #{cart} -a <app name>")
|
280
|
-
end
|
261
|
+
output.should match 'Below is a list of'
|
281
262
|
end
|
282
263
|
|
283
264
|
it "should show a thank you message" do
|
@@ -298,7 +279,6 @@ describe RHC::Wizard do
|
|
298
279
|
|
299
280
|
it "should ask for password input with default login" do
|
300
281
|
@wizard.stub_rhc_client_new
|
301
|
-
@wizard.stub_user_info
|
302
282
|
|
303
283
|
$terminal.write_line("") # hit enter for default
|
304
284
|
$terminal.write_line "password"
|
@@ -319,10 +299,7 @@ describe RHC::Wizard do
|
|
319
299
|
end
|
320
300
|
|
321
301
|
it "should check for ssh keys and find a match" do
|
322
|
-
|
323
|
-
RHC.stub(:get_ssh_keys) do
|
324
|
-
key_data
|
325
|
-
end
|
302
|
+
@wizard.stub(:ssh_key_uploaded?) { true } # an SSH key already exists
|
326
303
|
@wizard.run_next_stage # key config is pretty much a noop here
|
327
304
|
|
328
305
|
# run the key check stage
|
@@ -340,7 +317,6 @@ describe RHC::Wizard do
|
|
340
317
|
end
|
341
318
|
|
342
319
|
it "should ask for a namespace" do
|
343
|
-
@wizard.stub_user_info
|
344
320
|
$terminal.write_line("testnamespace")
|
345
321
|
@wizard.run_next_stage
|
346
322
|
output = $terminal.read
|
@@ -348,14 +324,9 @@ describe RHC::Wizard do
|
|
348
324
|
end
|
349
325
|
|
350
326
|
it "should show app creation commands" do
|
351
|
-
mock_carts = ['ruby', 'python', 'jbosseap']
|
352
|
-
RHC.stub(:get_cartridges_list) { mock_carts }
|
353
|
-
@wizard.stub_user_info
|
354
327
|
@wizard.run_next_stage
|
355
328
|
output = $terminal.read
|
356
|
-
|
357
|
-
output.should match("\\* #{cart} - rhc app create -t #{cart} -a <app name>")
|
358
|
-
end
|
329
|
+
output.should match 'Below is a list of'
|
359
330
|
end
|
360
331
|
|
361
332
|
it "should show a thank you message" do
|
@@ -367,15 +338,19 @@ describe RHC::Wizard do
|
|
367
338
|
|
368
339
|
context "Repeat run of rhc setup with everything set" do
|
369
340
|
before(:all) do
|
341
|
+
@namespace = 'testnamespace'
|
370
342
|
@wizard = RerunWizardDriver.new
|
343
|
+
@rest_client = RestSpecHelper::MockRestClient.new
|
344
|
+
domain = @rest_client.add_domain(@namespace)
|
345
|
+
domain.add_application('test1', 'mock_standalone_cart-1')
|
346
|
+
domain.add_application('test2', 'mock_standalone_cart-2')
|
371
347
|
@wizard.setup_mock_config("old_mock_user@bar.baz")
|
372
348
|
@wizard.setup_mock_ssh(true)
|
349
|
+
@wizard.setup_mock_domain_and_applications(@namespace, 'test1' => :default, 'test2' => :default)
|
373
350
|
@wizard.run_next_stage # we can skip testing the greeting
|
374
351
|
end
|
375
352
|
|
376
353
|
it "should ask password input with default login(use a different one)" do
|
377
|
-
@wizard.stub_rhc_client_new
|
378
|
-
@wizard.stub_user_info
|
379
354
|
$terminal.write_line(@wizard.mock_user)
|
380
355
|
$terminal.write_line "password"
|
381
356
|
|
@@ -396,22 +371,21 @@ describe RHC::Wizard do
|
|
396
371
|
|
397
372
|
it "should check for ssh keys, not find it on the server and update existing key" do
|
398
373
|
key_data = @wizard.get_mock_key_data
|
399
|
-
key_data
|
400
|
-
|
401
|
-
|
402
|
-
|
374
|
+
key_data.delete_if { |k| k.name == '73ce2cc1' }
|
375
|
+
key_name = 'default'
|
376
|
+
@rest_client.stub(:sshkeys) { key_data }
|
377
|
+
@rest_client.stub(:find_key) { key_data.detect {|k| k.name == key_name } }
|
403
378
|
|
404
379
|
@wizard.run_next_stage # key config is pretty much a noop here
|
405
380
|
|
406
|
-
@wizard.set_expected_key_name_and_action('default', 'update')
|
407
381
|
$terminal.write_line('yes')
|
408
|
-
$terminal.write_line(
|
382
|
+
$terminal.write_line(key_name)
|
409
383
|
|
410
384
|
# run the key check stage
|
411
385
|
@wizard.run_next_stage
|
412
386
|
|
413
387
|
output = $terminal.read
|
414
|
-
output.should match("
|
388
|
+
output.should match("Key with the name #{key_name} already exists. Updating")
|
415
389
|
end
|
416
390
|
|
417
391
|
it "should check for client tools and find them" do
|
@@ -422,23 +396,17 @@ describe RHC::Wizard do
|
|
422
396
|
end
|
423
397
|
|
424
398
|
it "should show namespace" do
|
425
|
-
@wizard.stub_user_info([{"namespace" => "setnamespace"}])
|
426
399
|
@wizard.run_next_stage
|
427
400
|
output = $terminal.read
|
428
401
|
output.should match("Checking for your namespace ... found namespace:")
|
429
|
-
output.should match(
|
402
|
+
output.should match(@namespace)
|
430
403
|
end
|
431
404
|
|
432
405
|
it "should list apps" do
|
433
|
-
@wizard.stub_user_info([{"namespace" => "setnamespace"}],
|
434
|
-
{"test1" => {},
|
435
|
-
"test2" => {}
|
436
|
-
}
|
437
|
-
)
|
438
406
|
@wizard.run_next_stage
|
439
407
|
output = $terminal.read
|
440
|
-
output.should match("test1 -
|
441
|
-
output.should match("test2 -
|
408
|
+
output.should match("test1 - https://test1-#{@namespace}.#{@wizard.libra_server}/")
|
409
|
+
output.should match("test2 - https://test2-#{@namespace}.#{@wizard.libra_server}/")
|
442
410
|
end
|
443
411
|
|
444
412
|
it "should show a thank you message" do
|
@@ -461,8 +429,6 @@ describe RHC::Wizard do
|
|
461
429
|
$terminal.write_line "#{@wizard.mock_user}"
|
462
430
|
$terminal.write_line "password"
|
463
431
|
|
464
|
-
@wizard.stub_user_info
|
465
|
-
|
466
432
|
@wizard.run_next_stage
|
467
433
|
|
468
434
|
output = $terminal.read
|
@@ -496,7 +462,6 @@ describe RHC::Wizard do
|
|
496
462
|
end
|
497
463
|
|
498
464
|
it "should ask for namespace and decline entering one" do
|
499
|
-
@wizard.stub_user_info
|
500
465
|
$terminal.write_line("")
|
501
466
|
@wizard.run_next_stage
|
502
467
|
output = $terminal.read
|
@@ -504,11 +469,7 @@ describe RHC::Wizard do
|
|
504
469
|
end
|
505
470
|
|
506
471
|
it "should list apps without domain" do
|
507
|
-
@wizard.
|
508
|
-
{"test1" => {},
|
509
|
-
"test2" => {}
|
510
|
-
}
|
511
|
-
)
|
472
|
+
@wizard.setup_mock_domain_and_applications(nil, 'test1' => nil, 'test2' => nil)
|
512
473
|
@wizard.run_next_stage
|
513
474
|
output = $terminal.read
|
514
475
|
output.should match("test1 - no public url")
|
@@ -525,12 +486,11 @@ describe RHC::Wizard do
|
|
525
486
|
it "should run" do
|
526
487
|
@wizard.libra_server = nil
|
527
488
|
@wizard.stub_rhc_client_new
|
528
|
-
@wizard.stub_user_info
|
529
489
|
@wizard.setup_mock_ssh
|
530
490
|
|
531
491
|
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
532
492
|
mock_carts = ['ruby', 'python', 'jbosseap']
|
533
|
-
|
493
|
+
@rest_client.stub(:cartridges) { mock_carts }
|
534
494
|
|
535
495
|
$terminal.write_line "#{@wizard.mock_user}"
|
536
496
|
$terminal.write_line "password"
|
@@ -542,64 +502,26 @@ describe RHC::Wizard do
|
|
542
502
|
|
543
503
|
it "should fail" do
|
544
504
|
@wizard.stub_rhc_client_new
|
545
|
-
@wizard.stub_user_info
|
546
505
|
@wizard.stub(:login_stage) { nil }
|
547
506
|
@wizard.run().should be_nil
|
548
507
|
end
|
549
|
-
|
550
|
-
it "should cover package kit install steps" do
|
551
|
-
@wizard.libra_server = nil
|
552
|
-
@wizard.stub_rhc_client_new
|
553
|
-
@wizard.stub_user_info
|
554
|
-
@wizard.setup_mock_ssh
|
555
|
-
@wizard.setup_mock_package_kit(false)
|
556
|
-
|
557
|
-
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
558
|
-
mock_carts = ['ruby', 'python', 'jbosseap']
|
559
|
-
RHC.stub(:get_cartridges_list) { mock_carts }
|
560
|
-
# we need to do this because get_character does not get caught
|
561
|
-
# by our mock terminal
|
562
|
-
@wizard.stub(:get_character) {ask ""}
|
563
|
-
|
564
|
-
$terminal.write_line ""
|
565
|
-
$terminal.write_line "password"
|
566
|
-
$terminal.write_line("no")
|
567
|
-
$terminal.write_line("yes")
|
568
|
-
$terminal.write_line("")
|
569
|
-
$terminal.write_line("")
|
570
|
-
|
571
|
-
@wizard.run().should be_true
|
572
|
-
|
573
|
-
output = $terminal.read
|
574
|
-
output.should match("You may safely continue while the installer is running")
|
575
|
-
end
|
576
508
|
end
|
577
509
|
|
578
510
|
context "Check SSHWizard" do
|
579
511
|
it "should generate and upload keys since the user does not have them" do
|
580
512
|
wizard = SSHWizardDriver.new
|
581
|
-
|
582
|
-
|
583
|
-
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
584
|
-
wizard.set_expected_key_name_and_action('default', 'add')
|
585
|
-
$terminal.write_line("yes")
|
513
|
+
key_name = 'default'
|
514
|
+
$terminal.write_line("yes\n#{key_name}\n")
|
586
515
|
|
587
516
|
wizard.run().should be_true
|
588
517
|
|
589
518
|
output = $terminal.read
|
590
|
-
output.should match("
|
519
|
+
output.should match("Uploading key '#{key_name}'")
|
591
520
|
end
|
592
521
|
|
593
522
|
it "should pass through since the user has keys already" do
|
594
523
|
wizard = SSHWizardDriver.new
|
595
|
-
wizard.
|
596
|
-
wizard.stub_user_info
|
597
|
-
wizard.setup_mock_ssh(true)
|
598
|
-
key_data = wizard.get_mock_key_data
|
599
|
-
RHC.stub(:get_ssh_keys) do
|
600
|
-
key_data
|
601
|
-
end
|
602
|
-
|
524
|
+
wizard.stub(:ssh_key_uploaded?) { true }
|
603
525
|
wizard.run().should be_true
|
604
526
|
|
605
527
|
output = $terminal.read
|
@@ -608,23 +530,6 @@ describe RHC::Wizard do
|
|
608
530
|
end
|
609
531
|
|
610
532
|
context "Check odds and ends" do
|
611
|
-
it "should call dbus_send_session_method and get multiple return values" do
|
612
|
-
wizard = FirstRunWizardDriver.new
|
613
|
-
wizard.stub(:dbus_send_exec) do |cmd|
|
614
|
-
"\\nboolean true\\nboolean false\\nstring hello\\nother world\\n"
|
615
|
-
end
|
616
|
-
results = wizard.send(:dbus_send_session_method, "test", "foo.bar", "bar/baz", "alpha.Beta", "")
|
617
|
-
results.should == [true, false, "hello", "world"]
|
618
|
-
end
|
619
|
-
|
620
|
-
it "should call dbus_send_session_method and get one return value" do
|
621
|
-
wizard = FirstRunWizardDriver.new
|
622
|
-
wizard.stub(:dbus_send_exec) do |cmd|
|
623
|
-
"\\nstring hello world\\n"
|
624
|
-
end
|
625
|
-
results = wizard.send(:dbus_send_session_method, "test", "foo.bar", "bar/baz", "alpha.Beta", "")
|
626
|
-
results.should == "hello world"
|
627
|
-
end
|
628
533
|
|
629
534
|
it "should cause has_git? to catch an exception and return false" do
|
630
535
|
wizard = FirstRunWizardDriver.new
|
@@ -632,25 +537,13 @@ describe RHC::Wizard do
|
|
632
537
|
wizard.send(:has_git?).should be_false
|
633
538
|
end
|
634
539
|
|
635
|
-
it "should cause package_kit_install to catch exception and call generic_unix_install_check" do
|
636
|
-
wizard = RerunWizardDriver.new
|
637
|
-
wizard.setup_mock_package_kit(false)
|
638
|
-
wizard.stub(:dbus_send_exec) do |cmd|
|
639
|
-
"Error: mock error" if cmd.start_with?("dbus-send")
|
640
|
-
end
|
641
|
-
wizard.send(:package_kit_install)
|
642
|
-
|
643
|
-
output = $terminal.read
|
644
|
-
output.should match("Checking for git ... needs to be installed")
|
645
|
-
output.should match("Automated installation of client tools is not supported")
|
646
|
-
end
|
647
|
-
|
648
540
|
it "should cause ssh_key_upload? to catch NoMethodError and call the fallback to get the fingerprint" do
|
649
541
|
wizard = RerunWizardDriver.new
|
650
542
|
Net::SSH::KeyFactory.stub(:load_public_key) { raise NoMethodError }
|
651
543
|
@fallback_run = false
|
652
544
|
wizard.stub(:ssh_keygen_fallback) { @fallback_run = true }
|
653
|
-
|
545
|
+
key_data = wizard.get_mock_key_data
|
546
|
+
@rest_client.stub(:sshkeys) { key_data }
|
654
547
|
|
655
548
|
wizard.send(:ssh_key_uploaded?)
|
656
549
|
|
@@ -663,7 +556,7 @@ describe RHC::Wizard do
|
|
663
556
|
@fallback_run = false
|
664
557
|
wizard.stub(:ssh_keygen_fallback) do
|
665
558
|
@fallback_run = true
|
666
|
-
|
559
|
+
[OpenStruct.new( :name => 'default', :fingerprint => 'AA:BB:CC:DD:EE:FF', :type => 'ssh-rsa' )]
|
667
560
|
end
|
668
561
|
$?.stub(:exitstatus) { 255 }
|
669
562
|
Net::SSH::KeyFactory.stub(:load_public_key) { raise NoMethodError }
|
@@ -671,7 +564,7 @@ describe RHC::Wizard do
|
|
671
564
|
wizard.send(:upload_ssh_key).should be_false
|
672
565
|
|
673
566
|
output = $terminal.read
|
674
|
-
output.should match("Your ssh public key at .*
|
567
|
+
output.should match("Your ssh public key at .* is invalid or unreadable\.")
|
675
568
|
@fallback_run.should be_true
|
676
569
|
end
|
677
570
|
|
@@ -683,7 +576,7 @@ describe RHC::Wizard do
|
|
683
576
|
wizard.send(:upload_ssh_key).should be_false
|
684
577
|
|
685
578
|
output = $terminal.read
|
686
|
-
output.should match("Your ssh public key at .*
|
579
|
+
output.should match("Your ssh public key at .* is invalid or unreadable\.")
|
687
580
|
end
|
688
581
|
|
689
582
|
it "should match ssh key fallback fingerprint to net::ssh fingerprint" do
|
@@ -700,37 +593,63 @@ describe RHC::Wizard do
|
|
700
593
|
end
|
701
594
|
FakeFS.activate!
|
702
595
|
end
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
596
|
+
|
597
|
+
context "when REST Client gets ValidationException for #add_domain" do
|
598
|
+
it "prints the exception message" do
|
599
|
+
msg = "Resource conflict"
|
600
|
+
wizard = FirstRunWizardDriver.new
|
601
|
+
wizard.rest_client.stub(:add_domain) { raise RHC::Rest::ValidationException, msg }
|
602
|
+
$terminal.write_line "testnamespace" # try to add a namespace
|
603
|
+
$terminal.write_line '' # the above input will raise exception.
|
604
|
+
# we now skip configuring namespace.
|
605
|
+
wizard.send(:ask_for_namespace)
|
606
|
+
output = $terminal.read
|
607
|
+
output.should match msg
|
711
608
|
end
|
712
609
|
end
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
610
|
+
|
611
|
+
it "should update the key correctly" do
|
612
|
+
key_name = 'default'
|
613
|
+
wizard = FirstRunWizardDriver.new
|
614
|
+
key_data = wizard.get_mock_key_data
|
615
|
+
wizard.ssh_keys = key_data
|
616
|
+
wizard.stub(:get_preferred_key_name) { key_name }
|
617
|
+
wizard.stub(:ssh_key_triple_for_default_key) { wizard.pub_key.chomp.split }
|
618
|
+
wizard.stub(:fingerprint_for_default_key) { "" } # this value is irrelevant
|
619
|
+
wizard.rest_client.stub(:find_key) { key_data.detect { |k| k.name == key_name } }
|
620
|
+
|
621
|
+
wizard.send(:upload_ssh_key)
|
622
|
+
output = $terminal.read
|
623
|
+
output.should match 'Updating'
|
624
|
+
end
|
625
|
+
|
626
|
+
it 'should pick a usable SSH key name' do
|
627
|
+
key_name = 'default'
|
628
|
+
wizard = FirstRunWizardDriver.new
|
629
|
+
key_data = wizard.get_mock_key_data
|
630
|
+
Socket.stub(:gethostname) { key_name }
|
631
|
+
$terminal.write_line("\n") # to accept default key name
|
632
|
+
wizard.ssh_keys = key_data
|
633
|
+
wizard.stub(:ssh_key_triple_for_default_key) { wizard.pub_key.chomp.split }
|
634
|
+
wizard.stub(:fingerprint_for_default_key) { "" } # this value is irrelevant
|
635
|
+
wizard.rest_client.stub(:add_key) { true }
|
636
|
+
|
637
|
+
wizard.send(:upload_ssh_key)
|
638
|
+
output = $terminal.read
|
639
|
+
# since the clashing key name is short, we expect to present
|
640
|
+
# a key name with "1" attached to it.
|
641
|
+
output.should match "|" + key_name + "1" + "|"
|
726
642
|
end
|
643
|
+
end
|
644
|
+
|
645
|
+
module WizardDriver
|
727
646
|
|
728
|
-
attr_accessor :mock_user, :libra_server, :config_path, :ssh_dir
|
647
|
+
attr_accessor :mock_user, :libra_server, :config_path, :ssh_dir, :rest_client
|
729
648
|
def initialize(*args)
|
730
649
|
RHC::Config.home_dir = '/home/mock_user'
|
731
650
|
super *args
|
732
651
|
@ssh_dir = "#{RHC::Config.home_dir}/.ssh/"
|
733
|
-
@libra_server = '
|
652
|
+
@libra_server = 'fake.foo'
|
734
653
|
@mock_user = 'mock_user@foo.bar'
|
735
654
|
@current_wizard_stage = nil
|
736
655
|
@platform_windows = false
|
@@ -747,23 +666,9 @@ describe RHC::Wizard do
|
|
747
666
|
self.send stages[@current_wizard_stage]
|
748
667
|
end
|
749
668
|
|
669
|
+
# Set up @rest_client so that we can stub subsequent REST calls
|
750
670
|
def stub_rhc_client_new
|
751
|
-
|
752
|
-
MockRestApi.new(end_point, name, password)
|
753
|
-
end
|
754
|
-
end
|
755
|
-
|
756
|
-
def stub_user_info(domains=[], app_info=[], key_type="", key="", keys={})
|
757
|
-
RHC.stub(:get_user_info) do
|
758
|
-
{"ssh_key" => key,
|
759
|
-
"ssh_key_type" => key_type,
|
760
|
-
"keys" => keys,
|
761
|
-
"app_info" => app_info,
|
762
|
-
"user_info" => {"domains" => domains,
|
763
|
-
"rhc_domain" => @libra_server},
|
764
|
-
"domains" => domains,
|
765
|
-
"rhlogin" => @mock_user}
|
766
|
-
end
|
671
|
+
@rest_client = RestSpecHelper::MockRestClient.new
|
767
672
|
end
|
768
673
|
|
769
674
|
def setup_mock_config(rhlogin=@mock_user)
|
@@ -789,23 +694,24 @@ EOF
|
|
789
694
|
end
|
790
695
|
end
|
791
696
|
|
792
|
-
def
|
793
|
-
|
794
|
-
|
795
|
-
unless File.exists?('/usr/bin/dbus-send')
|
796
|
-
FileUtils.mkdir_p '/usr/bin/'
|
797
|
-
File.open('/usr/bin/dbus-send', 'w') { |f| f.write('dummy') }
|
798
|
-
end
|
799
|
-
|
800
|
-
setup_mock_has_git(false)
|
697
|
+
def setup_mock_has_git(bool)
|
698
|
+
self.stub(:"has_git?") { bool }
|
699
|
+
end
|
801
700
|
|
802
|
-
|
803
|
-
|
701
|
+
def setup_mock_domain_and_applications(domain, apps = {})
|
702
|
+
stub_rhc_client_new
|
703
|
+
apps_ary = []
|
704
|
+
apps.each do |app, url|
|
705
|
+
apps_ary.push OpenStruct.new(
|
706
|
+
:name => app,
|
707
|
+
:app_url => url == :default ? "http://#{app}-#{domain}.#{@libra_server}/" : url,
|
708
|
+
:u => true
|
709
|
+
)
|
804
710
|
end
|
805
|
-
end
|
806
711
|
|
807
|
-
|
808
|
-
|
712
|
+
@rest_client.stub(:domains) {
|
713
|
+
[OpenStruct.new(:id => domain, :applications => apps_ary)]
|
714
|
+
}
|
809
715
|
end
|
810
716
|
|
811
717
|
def windows=(bool)
|
@@ -816,17 +722,6 @@ EOF
|
|
816
722
|
@platform_windows
|
817
723
|
end
|
818
724
|
|
819
|
-
def set_expected_key_name_and_action(key_name, action)
|
820
|
-
@expected_key_name = key_name
|
821
|
-
@expected_key_action = action
|
822
|
-
end
|
823
|
-
|
824
|
-
def add_or_update_key(action, key_name, pub_ssh_path, username, password)
|
825
|
-
raise "Error: Expected '#{@expected_key_action}' ssh key action but got '#{action}'" if @expected_key_action and action != @expected_key_action
|
826
|
-
raise "Error: Expected '#{@expected_key_name}' ssh key name but got '#{key_name}'" if @expected_key_name and key_name != @expected_key_name
|
827
|
-
true
|
828
|
-
end
|
829
|
-
|
830
725
|
def get_key_fingerprint(path=RHC::Config.ssh_pub_key_file_path)
|
831
726
|
# returns the fingerprint and the short name used as the default
|
832
727
|
# key name
|
@@ -839,14 +734,20 @@ EOF
|
|
839
734
|
@ssh_keys = data
|
840
735
|
end
|
841
736
|
|
737
|
+
class Sshkey < OpenStruct
|
738
|
+
def update(type, content)
|
739
|
+
self.type = type
|
740
|
+
self.content = content
|
741
|
+
end
|
742
|
+
end
|
743
|
+
|
842
744
|
def get_mock_key_data
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
"fingerprint" => "0f:97:4b:82:87:bb:c6:dc:40:a3:c1:bc:bb:55:1e:fa"}
|
745
|
+
[
|
746
|
+
Sshkey.new(:name => 'default', :type => 'ssh-rsa', :fingerprint => "0f:97:4b:82:87:bb:c6:dc:40:a3:c1:bc:bb:55:1e:fa"),
|
747
|
+
Sshkey.new(:name => 'cb490595', :type => 'ssh-rsa', :fingerprint => "cb:49:05:95:b4:42:1c:95:74:f7:2d:41:0d:f0:37:3b"),
|
748
|
+
Sshkey.new(:name => '96d90241', :type => 'ssh-rsa', :fingerprint => "96:d9:02:41:e1:cb:0d:ce:e5:3b:fc:da:13:65:3e:32"),
|
749
|
+
Sshkey.new(:name => '73ce2cc1', :type => 'ssh-rsa', :fingerprint => "73:ce:2c:c1:01:ea:79:cc:f6:be:86:45:67:96:7f:e3")
|
750
|
+
]
|
850
751
|
end
|
851
752
|
|
852
753
|
def priv_key
|
@@ -910,7 +811,7 @@ EOF
|
|
910
811
|
include WizardDriver
|
911
812
|
|
912
813
|
def initialize
|
913
|
-
super
|
814
|
+
super RestSpecHelper::MockRestClient.new
|
914
815
|
end
|
915
816
|
end
|
916
817
|
end
|