rhc 0.93.19 → 0.94.8
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 +53 -43
- data/bin/rhc-app +17 -14
- data/bin/rhc-chk +116 -48
- data/bin/rhc-create-app +1 -1
- data/bin/rhc-create-domain +0 -15
- data/lib/rhc-common.rb +47 -64
- data/lib/rhc-rest.rb +4 -8
- data/lib/rhc-rest/client.rb +1 -0
- data/lib/rhc-rest/exceptions/exceptions.rb +2 -2
- data/lib/rhc/client.rb +2 -0
- data/lib/rhc/config.rb +18 -9
- data/lib/rhc/json.rb +0 -1
- data/lib/rhc/targz.rb +1 -2
- data/lib/rhc/vendor/parseconfig.rb +178 -0
- data/lib/rhc/wizard.rb +12 -4
- data/spec/rhc/wizard_spec.rb +366 -145
- metadata +219 -213
data/lib/rhc/wizard.rb
CHANGED
@@ -76,7 +76,9 @@ module RHC
|
|
76
76
|
|
77
77
|
# get_password adds an extra untracked newline so set :bottom to -1
|
78
78
|
section(:top => 1, :bottom => -1) do
|
79
|
-
@username = ask("To connect to #{@libra_server} enter your OpenShift login (email or Red Hat login id): ")
|
79
|
+
@username = ask("To connect to #{@libra_server} enter your OpenShift login (email or Red Hat login id): ") do |q|
|
80
|
+
q.default = RHC::Config.default_rhlogin
|
81
|
+
end
|
80
82
|
@password = RHC::get_password
|
81
83
|
end
|
82
84
|
|
@@ -447,6 +449,9 @@ EOF
|
|
447
449
|
full_iface = "org.freedesktop.PackageKit.#{iface}"
|
448
450
|
dbus_send_session_method name, service, obj_path, full_iface, stringafied_params, wait_for_reply
|
449
451
|
end
|
452
|
+
def package_kit_git_installed?
|
453
|
+
package_kit_method('IsInstalled', 'Query', 'string:git string:')
|
454
|
+
end
|
450
455
|
|
451
456
|
def package_kit_install
|
452
457
|
section(:top => 1) do
|
@@ -454,9 +459,8 @@ EOF
|
|
454
459
|
end
|
455
460
|
|
456
461
|
begin
|
457
|
-
git_installed = package_kit_method('IsInstalled', 'Query', 'string:git string:')
|
458
462
|
# double check due to slight differences in older platforms
|
459
|
-
if
|
463
|
+
if has_git? or package_kit_git_installed?
|
460
464
|
section(:bottom => 1) { say "found" }
|
461
465
|
else
|
462
466
|
section(:bottom => 1) { say "needs to be installed" }
|
@@ -516,7 +520,11 @@ EOF
|
|
516
520
|
end
|
517
521
|
|
518
522
|
def has_git?
|
519
|
-
|
523
|
+
begin
|
524
|
+
%x{ git --version }
|
525
|
+
rescue
|
526
|
+
end
|
527
|
+
|
520
528
|
$?.success?
|
521
529
|
rescue
|
522
530
|
false
|
data/spec/rhc/wizard_spec.rb
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'fakefs/safe'
|
3
3
|
require 'rhc/wizard'
|
4
|
-
require 'parseconfig'
|
4
|
+
require 'rhc/vendor/parseconfig'
|
5
5
|
require 'rhc/config'
|
6
6
|
|
7
|
-
# monkey patch ParseConfig so it works with fakefs
|
8
|
-
# TODO: if this is useful elsewhere move to helpers
|
9
|
-
class ParseConfig
|
10
|
-
def open(*args)
|
11
|
-
File.open *args
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
7
|
# chmod isn't implemented in the released fakefs gem
|
16
8
|
# but is in git. Once the git version is released we
|
17
9
|
# should remove this and actively check permissions
|
@@ -28,6 +20,7 @@ describe RHC::Wizard do
|
|
28
20
|
end
|
29
21
|
|
30
22
|
after(:all) do
|
23
|
+
FakeFS::FileSystem.clear
|
31
24
|
FakeFS.deactivate!
|
32
25
|
end
|
33
26
|
|
@@ -45,12 +38,12 @@ describe RHC::Wizard do
|
|
45
38
|
end
|
46
39
|
|
47
40
|
it "should ask for login and hide password input" do
|
41
|
+
@wizard.stub_rhc_client_new
|
48
42
|
# queue up input
|
49
43
|
$terminal.write_line "#{@wizard.mock_user}"
|
50
44
|
$terminal.write_line "password"
|
51
45
|
|
52
46
|
@wizard.stub_user_info
|
53
|
-
@wizard.stub_rest_api
|
54
47
|
|
55
48
|
@wizard.run_next_stage
|
56
49
|
|
@@ -63,9 +56,9 @@ describe RHC::Wizard do
|
|
63
56
|
File.exists?(@wizard.config_path).should be false
|
64
57
|
@wizard.run_next_stage
|
65
58
|
File.readable?(@wizard.config_path).should be true
|
66
|
-
cp = ParseConfig.new @wizard.config_path
|
67
|
-
cp
|
68
|
-
cp
|
59
|
+
cp = RHC::Vendor::ParseConfig.new @wizard.config_path
|
60
|
+
cp["default_rhlogin"].should == @wizard.mock_user
|
61
|
+
cp["libra_server"].should == @wizard.libra_server
|
69
62
|
end
|
70
63
|
|
71
64
|
it "should write out generated ssh keys" do
|
@@ -79,164 +72,375 @@ describe RHC::Wizard do
|
|
79
72
|
File.exists?(public_key_file).should be true
|
80
73
|
end
|
81
74
|
|
82
|
-
it "should upload ssh keys" do
|
83
|
-
|
84
|
-
|
85
|
-
$terminal.write_line('
|
75
|
+
it "should ask to upload ssh keys" do
|
76
|
+
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
77
|
+
@wizard.set_expected_key_name_and_action('default', 'add')
|
78
|
+
$terminal.write_line('yes')
|
86
79
|
@wizard.run_next_stage
|
87
80
|
end
|
88
81
|
|
89
82
|
it "should check for client tools" do
|
90
|
-
|
83
|
+
@wizard.run_next_stage
|
84
|
+
output = $terminal.read
|
85
|
+
output.should match("Checking for git \.\.\. found")
|
91
86
|
end
|
92
87
|
|
93
88
|
it "should ask for a namespace" do
|
94
|
-
|
89
|
+
@wizard.stub_user_info
|
90
|
+
$terminal.write_line("testnamespace")
|
91
|
+
@wizard.run_next_stage
|
92
|
+
output = $terminal.read
|
93
|
+
output.should match("Checking for your namespace \.\.\. not found")
|
95
94
|
end
|
96
95
|
|
97
96
|
it "should show app creation commands" do
|
98
|
-
|
97
|
+
mock_carts = ['ruby', 'python', 'jbosseap']
|
98
|
+
RHC.stub(:get_cartridges_list) { mock_carts }
|
99
|
+
@wizard.stub_user_info
|
100
|
+
@wizard.run_next_stage
|
101
|
+
output = $terminal.read
|
102
|
+
mock_carts.each do |cart|
|
103
|
+
output.should match("\\* #{cart} - rhc app create -t #{cart} -a <app name>")
|
104
|
+
end
|
99
105
|
end
|
100
106
|
|
101
107
|
it "should show a thank you message" do
|
102
|
-
|
108
|
+
@wizard.run_next_stage
|
109
|
+
output = $terminal.read
|
110
|
+
output.should match ("The OpenShift client tools have been configured on your computer")
|
103
111
|
end
|
104
112
|
end
|
105
113
|
|
106
114
|
context "Repeat run of rhc setup without anything set" do
|
107
|
-
|
115
|
+
before(:all) do
|
116
|
+
@wizard = RerunWizardDriver.new
|
117
|
+
end
|
108
118
|
|
109
119
|
it "should print out repeat run greeting" do
|
110
|
-
|
120
|
+
@wizard.run_next_stage
|
121
|
+
greeting = $terminal.read
|
122
|
+
greeting.count("\n").should == 7
|
123
|
+
greeting.should match(Regexp.escape("Starting Interactive Setup for OpenShift's command line interface"))
|
124
|
+
greeting.should match(Regexp.escape("#{@wizard.config_path}\n"))
|
111
125
|
end
|
112
126
|
|
113
127
|
it "should ask for login and hide password input" do
|
128
|
+
@wizard.stub_rhc_client_new
|
129
|
+
$terminal.write_line "#{@wizard.mock_user}"
|
130
|
+
$terminal.write_line "password"
|
131
|
+
|
132
|
+
@wizard.stub_user_info
|
133
|
+
|
134
|
+
@wizard.run_next_stage
|
114
135
|
|
136
|
+
output = $terminal.read
|
137
|
+
output.should match("OpenShift login")
|
138
|
+
output.should =~ /(#{Regexp.escape("Password: ********\n")})$/
|
115
139
|
end
|
116
140
|
|
117
141
|
it "should write out a config" do
|
118
|
-
|
142
|
+
File.exists?(@wizard.config_path).should be false
|
143
|
+
@wizard.run_next_stage
|
144
|
+
File.readable?(@wizard.config_path).should be true
|
145
|
+
cp = RHC::Vendor::ParseConfig.new @wizard.config_path
|
146
|
+
cp["default_rhlogin"].should == @wizard.mock_user
|
147
|
+
cp["libra_server"].should == @wizard.libra_server
|
119
148
|
end
|
120
149
|
|
121
150
|
it "should write out generated ssh keys" do
|
122
|
-
|
151
|
+
@wizard.setup_mock_ssh
|
152
|
+
private_key_file = File.join(@wizard.ssh_dir, "id_rsa")
|
153
|
+
public_key_file = File.join(@wizard.ssh_dir, "id_rsa.pub")
|
154
|
+
File.exists?(private_key_file).should be false
|
155
|
+
File.exists?(public_key_file).should be false
|
156
|
+
@wizard.run_next_stage
|
157
|
+
File.exists?(private_key_file).should be true
|
158
|
+
File.exists?(public_key_file).should be true
|
123
159
|
end
|
124
160
|
|
125
161
|
it "should upload ssh key as default" do
|
126
|
-
|
162
|
+
RHC.stub(:get_ssh_keys) { {"keys" => [], "fingerprint" => nil} }
|
163
|
+
@wizard.set_expected_key_name_and_action('default', 'add')
|
164
|
+
$terminal.write_line('yes')
|
165
|
+
@wizard.run_next_stage
|
127
166
|
end
|
128
167
|
|
129
168
|
it "should check for client tools and print they need to be installed" do
|
130
|
-
|
169
|
+
@wizard.has_git(false)
|
170
|
+
@wizard.run_next_stage
|
171
|
+
output = $terminal.read
|
172
|
+
output.should match("Checking for git \.\.\. needs to be installed")
|
173
|
+
output.should match("Automated installation of client tools is not supported for your platform")
|
131
174
|
end
|
132
175
|
|
133
176
|
it "should ask for a namespace" do
|
134
|
-
|
177
|
+
@wizard.stub_user_info
|
178
|
+
$terminal.write_line("testnamespace")
|
179
|
+
@wizard.run_next_stage
|
180
|
+
output = $terminal.read
|
181
|
+
output.should match("Checking for your namespace \.\.\. not found")
|
135
182
|
end
|
136
183
|
|
137
184
|
it "should show app creation commands" do
|
138
|
-
|
185
|
+
mock_carts = ['ruby', 'python', 'jbosseap']
|
186
|
+
RHC.stub(:get_cartridges_list) { mock_carts }
|
187
|
+
@wizard.stub_user_info
|
188
|
+
@wizard.run_next_stage
|
189
|
+
output = $terminal.read
|
190
|
+
mock_carts.each do |cart|
|
191
|
+
output.should match("\\* #{cart} - rhc app create -t #{cart} -a <app name>")
|
192
|
+
end
|
139
193
|
end
|
140
194
|
|
141
195
|
it "should show a thank you message" do
|
142
|
-
|
196
|
+
@wizard.run_next_stage
|
197
|
+
output = $terminal.read
|
198
|
+
output.should match ("Thank you")
|
143
199
|
end
|
144
200
|
end
|
145
201
|
|
146
202
|
context "Repeat run of rhc setup with config set" do
|
203
|
+
before(:all) do
|
204
|
+
@wizard = RerunWizardDriver.new
|
205
|
+
@wizard.setup_mock_config
|
206
|
+
@wizard.run_next_stage # we can skip testing the greeting
|
207
|
+
end
|
147
208
|
|
148
|
-
it "should
|
209
|
+
it "should ask for password input with default login" do
|
210
|
+
@wizard.stub_rhc_client_new
|
211
|
+
@wizard.stub_user_info
|
149
212
|
|
150
|
-
|
213
|
+
$terminal.write_line("") # hit enter for default
|
214
|
+
$terminal.write_line "password"
|
151
215
|
|
152
|
-
|
216
|
+
@wizard.run_next_stage
|
153
217
|
|
218
|
+
output = $terminal.read
|
219
|
+
output.should match("|#{@wizard.mock_user}|")
|
154
220
|
end
|
155
221
|
|
156
|
-
it "should write out
|
222
|
+
it "should write out a config" do
|
223
|
+
File.exists?(@wizard.config_path).should be true
|
224
|
+
@wizard.run_next_stage
|
225
|
+
File.readable?(@wizard.config_path).should be true
|
226
|
+
cp = RHC::Vendor::ParseConfig.new @wizard.config_path
|
227
|
+
cp["default_rhlogin"].should == @wizard.mock_user
|
228
|
+
cp["libra_server"].should == @wizard.libra_server
|
229
|
+
end
|
157
230
|
|
231
|
+
it "should write out generated ssh keys" do
|
232
|
+
@wizard.setup_mock_ssh
|
233
|
+
private_key_file = File.join(@wizard.ssh_dir, "id_rsa")
|
234
|
+
public_key_file = File.join(@wizard.ssh_dir, "id_rsa.pub")
|
235
|
+
File.exists?(private_key_file).should be false
|
236
|
+
File.exists?(public_key_file).should be false
|
237
|
+
@wizard.run_next_stage
|
238
|
+
File.exists?(private_key_file).should be true
|
239
|
+
File.exists?(public_key_file).should be true
|
158
240
|
end
|
159
241
|
|
160
|
-
it "should find out that you
|
242
|
+
it "should find out that you have not uploaded the keys and ask to name the key" do
|
243
|
+
key_data = @wizard.get_mock_key_data
|
244
|
+
RHC.stub(:get_ssh_keys) do
|
245
|
+
key_data
|
246
|
+
end
|
161
247
|
|
248
|
+
fingerprint, short_name = @wizard.get_key_fingerprint
|
249
|
+
@wizard.set_expected_key_name_and_action(short_name, 'add')
|
250
|
+
$terminal.write_line('yes')
|
251
|
+
$terminal.write_line("") # use default name
|
252
|
+
@wizard.run_next_stage
|
253
|
+
output = $terminal.read
|
254
|
+
output.should match("default - #{key_data['fingerprint']}")
|
255
|
+
key_data['keys'].each do |key, value|
|
256
|
+
output.should match("#{key} - #{value['fingerprint']}")
|
257
|
+
end
|
258
|
+
output.should match("|#{short_name}|")
|
162
259
|
end
|
163
260
|
|
164
261
|
it "should check for client tools and find them" do
|
165
|
-
|
262
|
+
@wizard.run_next_stage
|
263
|
+
output = $terminal.read
|
264
|
+
output.should match("Checking for git \.\.\. found")
|
166
265
|
end
|
167
266
|
|
168
267
|
it "should ask for a namespace" do
|
169
|
-
|
268
|
+
@wizard.stub_user_info
|
269
|
+
$terminal.write_line("testnamespace")
|
270
|
+
@wizard.run_next_stage
|
271
|
+
output = $terminal.read
|
272
|
+
output.should match("Checking for your namespace \.\.\. not found")
|
170
273
|
end
|
171
274
|
|
172
275
|
it "should show app creation commands" do
|
173
|
-
|
276
|
+
mock_carts = ['ruby', 'python', 'jbosseap']
|
277
|
+
RHC.stub(:get_cartridges_list) { mock_carts }
|
278
|
+
@wizard.stub_user_info
|
279
|
+
@wizard.run_next_stage
|
280
|
+
output = $terminal.read
|
281
|
+
mock_carts.each do |cart|
|
282
|
+
output.should match("\\* #{cart} - rhc app create -t #{cart} -a <app name>")
|
283
|
+
end
|
174
284
|
end
|
175
285
|
|
176
286
|
it "should show a thank you message" do
|
177
|
-
|
287
|
+
@wizard.run_next_stage
|
288
|
+
output = $terminal.read
|
289
|
+
output.should match ("Thank you")
|
178
290
|
end
|
179
291
|
end
|
180
292
|
|
181
293
|
context "Repeat run of rhc setup with config and ssh keys set" do
|
182
294
|
|
183
|
-
|
184
|
-
|
295
|
+
before(:all) do
|
296
|
+
@wizard = RerunWizardDriver.new
|
297
|
+
@wizard.setup_mock_config
|
298
|
+
@wizard.setup_mock_ssh(true)
|
299
|
+
@wizard.run_next_stage # we can skip testing the greeting
|
185
300
|
end
|
186
301
|
|
187
|
-
it "should ask for password input
|
302
|
+
it "should ask for password input with default login" do
|
303
|
+
@wizard.stub_rhc_client_new
|
304
|
+
@wizard.stub_user_info
|
305
|
+
|
306
|
+
$terminal.write_line("") # hit enter for default
|
307
|
+
$terminal.write_line "password"
|
308
|
+
|
309
|
+
@wizard.run_next_stage
|
310
|
+
|
311
|
+
output = $terminal.read
|
312
|
+
output.should match("|#{@wizard.mock_user}|")
|
313
|
+
end
|
188
314
|
|
315
|
+
it "should write out a config" do
|
316
|
+
File.exists?(@wizard.config_path).should be true
|
317
|
+
@wizard.run_next_stage
|
318
|
+
File.readable?(@wizard.config_path).should be true
|
319
|
+
cp = RHC::Vendor::ParseConfig.new @wizard.config_path
|
320
|
+
cp["default_rhlogin"].should == @wizard.mock_user
|
321
|
+
cp["libra_server"].should == @wizard.libra_server
|
189
322
|
end
|
190
323
|
|
191
|
-
it "should check for ssh
|
324
|
+
it "should check for ssh keys and find a match" do
|
325
|
+
key_data = @wizard.get_mock_key_data
|
326
|
+
RHC.stub(:get_ssh_keys) do
|
327
|
+
key_data
|
328
|
+
end
|
329
|
+
@wizard.run_next_stage # key config is pretty much a noop here
|
330
|
+
|
331
|
+
# run the key check stage
|
332
|
+
@wizard.run_next_stage
|
192
333
|
|
334
|
+
output = $terminal.read
|
335
|
+
output.should_not match("ssh key must be uploaded")
|
193
336
|
end
|
194
337
|
|
195
338
|
it "should check for client tools and find them" do
|
196
|
-
|
339
|
+
@wizard.run_next_stage
|
340
|
+
output = $terminal.read
|
341
|
+
output.should match("Checking for git \.\.\. found")
|
197
342
|
end
|
198
343
|
|
199
344
|
it "should ask for a namespace" do
|
200
|
-
|
345
|
+
@wizard.stub_user_info
|
346
|
+
$terminal.write_line("testnamespace")
|
347
|
+
@wizard.run_next_stage
|
348
|
+
output = $terminal.read
|
349
|
+
output.should match("Checking for your namespace \.\.\. not found")
|
201
350
|
end
|
202
351
|
|
203
352
|
it "should show app creation commands" do
|
204
|
-
|
353
|
+
mock_carts = ['ruby', 'python', 'jbosseap']
|
354
|
+
RHC.stub(:get_cartridges_list) { mock_carts }
|
355
|
+
@wizard.stub_user_info
|
356
|
+
@wizard.run_next_stage
|
357
|
+
output = $terminal.read
|
358
|
+
mock_carts.each do |cart|
|
359
|
+
output.should match("\\* #{cart} - rhc app create -t #{cart} -a <app name>")
|
360
|
+
end
|
205
361
|
end
|
206
362
|
|
207
363
|
it "should show a thank you message" do
|
208
|
-
|
364
|
+
@wizard.run_next_stage
|
365
|
+
output = $terminal.read
|
366
|
+
output.should match ("Thank you")
|
209
367
|
end
|
210
368
|
end
|
211
369
|
|
212
370
|
context "Repeat run of rhc setup with everything set" do
|
371
|
+
before(:all) do
|
372
|
+
@wizard = RerunWizardDriver.new
|
373
|
+
@wizard.setup_mock_config("old_mock_user@bar.baz")
|
374
|
+
@wizard.setup_mock_ssh(true)
|
375
|
+
@wizard.run_next_stage # we can skip testing the greeting
|
376
|
+
end
|
213
377
|
|
214
|
-
it "should
|
378
|
+
it "should ask password input with default login (use a different one)" do
|
379
|
+
@wizard.stub_rhc_client_new
|
380
|
+
@wizard.stub_user_info
|
381
|
+
$terminal.write_line(@wizard.mock_user)
|
382
|
+
$terminal.write_line "password"
|
215
383
|
|
216
|
-
|
384
|
+
@wizard.run_next_stage
|
217
385
|
|
218
|
-
|
386
|
+
output = $terminal.read
|
387
|
+
output.should match("|old_mock_user@bar.baz|")
|
388
|
+
end
|
219
389
|
|
390
|
+
it "should write out a config" do
|
391
|
+
File.exists?(@wizard.config_path).should be true
|
392
|
+
@wizard.run_next_stage
|
393
|
+
File.readable?(@wizard.config_path).should be true
|
394
|
+
cp = RHC::Vendor::ParseConfig.new @wizard.config_path
|
395
|
+
cp["default_rhlogin"].should == @wizard.mock_user
|
396
|
+
cp["libra_server"].should == @wizard.libra_server
|
220
397
|
end
|
221
398
|
|
222
399
|
it "should check for ssh keys and find they are uploaded" do
|
400
|
+
key_data = @wizard.get_mock_key_data
|
401
|
+
RHC.stub(:get_ssh_keys) do
|
402
|
+
key_data
|
403
|
+
end
|
404
|
+
|
405
|
+
@wizard.run_next_stage # key config is pretty much a noop here
|
406
|
+
|
407
|
+
# run the key check stage
|
408
|
+
@wizard.run_next_stage
|
223
409
|
|
410
|
+
output = $terminal.read
|
411
|
+
output.should_not match("ssh key must be uploaded")
|
224
412
|
end
|
225
413
|
|
226
414
|
it "should check for client tools and find them" do
|
227
|
-
|
415
|
+
@wizard.run_next_stage
|
416
|
+
output = $terminal.read
|
417
|
+
output.should match("Checking for git \.\.\. found")
|
228
418
|
end
|
229
419
|
|
230
420
|
it "should show namespace" do
|
231
|
-
|
421
|
+
@wizard.stub_user_info([{"namespace" => "setnamespace"}])
|
422
|
+
@wizard.run_next_stage
|
423
|
+
output = $terminal.read
|
424
|
+
output.should match("Checking for your namespace ... found namespace:")
|
425
|
+
output.should match("setnamespace")
|
232
426
|
end
|
233
427
|
|
234
428
|
it "should list apps" do
|
235
|
-
|
429
|
+
@wizard.stub_user_info([{"namespace" => "setnamespace"}],
|
430
|
+
{"test1" => {},
|
431
|
+
"test2" => {}
|
432
|
+
}
|
433
|
+
)
|
434
|
+
@wizard.run_next_stage
|
435
|
+
output = $terminal.read
|
436
|
+
output.should match("test1 - http://test1-setnamespace.#{@wizard.libra_server}/")
|
437
|
+
output.should match("test2 - http://test2-setnamespace.#{@wizard.libra_server}/")
|
236
438
|
end
|
237
439
|
|
238
440
|
it "should show a thank you message" do
|
239
|
-
|
441
|
+
@wizard.run_next_stage
|
442
|
+
output = $terminal.read
|
443
|
+
output.should match ("Thank you")
|
240
444
|
end
|
241
445
|
end
|
242
446
|
|
@@ -272,6 +476,28 @@ describe RHC::Wizard do
|
|
272
476
|
end
|
273
477
|
|
274
478
|
module WizardDriver
|
479
|
+
class MockDomain
|
480
|
+
attr_accessor :id
|
481
|
+
|
482
|
+
def initialize(id)
|
483
|
+
@id = id
|
484
|
+
end
|
485
|
+
end
|
486
|
+
class MockRestApi
|
487
|
+
def initialize(end_point, name, password)
|
488
|
+
@end_point = end_point
|
489
|
+
@name = name
|
490
|
+
@password = password
|
491
|
+
@domain_name = 'testnamespace'
|
492
|
+
end
|
493
|
+
|
494
|
+
def add_domain(domain_name)
|
495
|
+
raise "Error: domain name should be '#{@domain_name}' but got '#{domain_name}'" if domain_name != @domain_name
|
496
|
+
|
497
|
+
MockDomain.new(domain_name)
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
275
501
|
attr_accessor :mock_user, :libra_server, :config_path, :ssh_dir
|
276
502
|
def initialize
|
277
503
|
RHC::Config.home_dir = '/home/mock_user'
|
@@ -296,99 +522,31 @@ describe RHC::Wizard do
|
|
296
522
|
self.send stages[@current_wizard_stage]
|
297
523
|
end
|
298
524
|
|
299
|
-
def
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
"API" => {"optional_params" => [],
|
320
|
-
"rel" => "API entry point",
|
321
|
-
"method" => "GET",
|
322
|
-
"href" => "https => //#{libra_server}/broker/rest/api",
|
323
|
-
"required_params" => []
|
324
|
-
},
|
325
|
-
"LIST_CARTRIDGES" => {
|
326
|
-
"optional_params" => [],
|
327
|
-
"rel" => "List cartridges",
|
328
|
-
"method" => "GET","href" => "https => //@{libra_server}/broker/rest/cartridges",
|
329
|
-
"required_params" => []
|
330
|
-
},
|
331
|
-
"GET_USER" => {
|
332
|
-
"optional_params" => [],
|
333
|
-
"rel" => "Get user information",
|
334
|
-
"method" => "GET",
|
335
|
-
"href" => "https => //#{libra_server}/broker/rest/user",
|
336
|
-
"required_params" => []
|
337
|
-
},
|
338
|
-
"LIST_DOMAINS" => {
|
339
|
-
"optional_params" => [],
|
340
|
-
"rel" => "List domains",
|
341
|
-
"method" => "GET",
|
342
|
-
"href" => "https => //@libra_server/broker/rest/domains",
|
343
|
-
"required_params" => []
|
344
|
-
},
|
345
|
-
"LIST_TEMPLATES" => {
|
346
|
-
"optional_params" => [],
|
347
|
-
"rel" => "List application templates",
|
348
|
-
"method" => "GET",
|
349
|
-
"href" => "https => //@{libra_server}/broker/rest/application_template",
|
350
|
-
"required_params" => []
|
351
|
-
},
|
352
|
-
"ADD_DOMAIN" => {
|
353
|
-
"optional_params" => [],
|
354
|
-
"rel" => "Create new domain",
|
355
|
-
"method" => "POST",
|
356
|
-
"href" => "https => //@{libra_server}/broker/rest/domains",
|
357
|
-
"required_params" => [
|
358
|
-
{"description" => "Name of the domain",
|
359
|
-
"valid_options" => [],
|
360
|
-
"type" => "string",
|
361
|
-
"name" => "id"
|
362
|
-
}
|
363
|
-
]
|
364
|
-
}
|
365
|
-
},
|
366
|
-
"version" => "1.0",
|
367
|
-
"type" => "links",
|
368
|
-
"supported_api_versions" => ["1.0"],
|
369
|
-
"messages" => [],
|
370
|
-
"status" => "ok"
|
371
|
-
}
|
372
|
-
|
373
|
-
stub_request(:get, "https://mock_user%40foo.bar:password@mock.openshift.redhat.com/broker/rest/api").to_return(:status => 200, :body => RHC::json_encode(body), :headers => {})
|
374
|
-
end
|
375
|
-
|
376
|
-
def stub_ssh_keys
|
377
|
-
# TODO: add ssh keys if requests
|
378
|
-
data = {:ssh_key => "",
|
379
|
-
:keys => []
|
380
|
-
}
|
381
|
-
|
382
|
-
data = RHC::json_encode(data)
|
383
|
-
stub_request(:post, "https://#{@libra_server}/broker/ssh_keys").to_return(:status => 200, :body => RHC::json_encode({:data => data}))
|
384
|
-
end
|
385
|
-
|
386
|
-
def setup_mock_config
|
525
|
+
def stub_rhc_client_new
|
526
|
+
Rhc::Rest::Client.stub(:new) do |end_point, name, password|
|
527
|
+
MockRestApi.new(end_point, name, password)
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
def stub_user_info(domains=[], app_info=[], key_type="", key="", keys={})
|
532
|
+
RHC.stub(:get_user_info) do
|
533
|
+
{"ssh_key" => key,
|
534
|
+
"ssh_key_type" => key_type,
|
535
|
+
"keys" => keys,
|
536
|
+
"app_info" => app_info,
|
537
|
+
"user_info" => {"domains" => domains,
|
538
|
+
"rhc_domain" => @libra_server},
|
539
|
+
"domains" => domains,
|
540
|
+
"rhlogin" => @mock_user}
|
541
|
+
end
|
542
|
+
end
|
543
|
+
|
544
|
+
def setup_mock_config(rhlogin=@mock_user)
|
387
545
|
FileUtils.mkdir_p File.dirname(@config_path)
|
388
546
|
File.open(@config_path, "w") do |file|
|
389
547
|
file.puts <<EOF
|
390
548
|
# Default user login
|
391
|
-
default_rhlogin='#{
|
549
|
+
default_rhlogin='#{rhlogin}'
|
392
550
|
|
393
551
|
# Server API
|
394
552
|
libra_server = '#{@libra_server}'
|
@@ -399,21 +557,84 @@ EOF
|
|
399
557
|
def setup_mock_ssh(add_ssh_key=false)
|
400
558
|
FileUtils.mkdir_p @ssh_dir
|
401
559
|
if add_ssh_key
|
402
|
-
|
560
|
+
setup_mock_ssh_keys
|
403
561
|
end
|
404
562
|
end
|
405
563
|
|
564
|
+
def has_git(bool)
|
565
|
+
@mock_git_installed = bool
|
566
|
+
end
|
567
|
+
|
406
568
|
def has_git?
|
407
569
|
@mock_git_installed
|
408
570
|
end
|
409
571
|
|
410
|
-
def
|
572
|
+
def has_dbus_send?
|
411
573
|
@mock_package_kit_installed
|
412
574
|
end
|
413
575
|
|
414
576
|
def windows?
|
415
577
|
@platform_windows
|
416
578
|
end
|
579
|
+
|
580
|
+
def set_expected_key_name_and_action(key_name, action)
|
581
|
+
@expected_key_name = key_name
|
582
|
+
@expected_key_action = action
|
583
|
+
end
|
584
|
+
|
585
|
+
def add_or_update_key(action, key_name, pub_ssh_path, username, password)
|
586
|
+
raise "Error: Expected '#{@expected_key_action}' ssh key action but got '#{action}'" if @expected_key_action and action != @expected_key_action
|
587
|
+
raise "Error: Expected '#{@expected_key_name}' ssh key name but got '#{key_name}'" if @expected_key_name and key_name != @expected_key_name
|
588
|
+
true
|
589
|
+
end
|
590
|
+
|
591
|
+
def get_key_fingerprint
|
592
|
+
# returns the fingerprint and the short name used as the default
|
593
|
+
# key name
|
594
|
+
fingerprint = Net::SSH::KeyFactory.load_public_key(@ssh_pub_key_file_path).fingerprint
|
595
|
+
short_name = fingerprint[0, 12].gsub(/[^0-9a-zA-Z]/,'')
|
596
|
+
return fingerprint, short_name
|
597
|
+
end
|
598
|
+
|
599
|
+
def get_mock_key_data
|
600
|
+
key_data =
|
601
|
+
{"keys" => {
|
602
|
+
"cb490595" => {"fingerprint" => "cb:49:05:95:b4:42:1c:95:74:f7:2d:41:0d:f0:37:3b"},
|
603
|
+
"96d90241" => {"fingerprint" => "96:d9:02:41:e1:cb:0d:ce:e5:3b:fc:da:13:65:3e:32"},
|
604
|
+
"73ce2cc1" => {"fingerprint" => "73:ce:2c:c1:01:ea:79:cc:f6:be:86:45:67:96:7f:e3"}
|
605
|
+
},
|
606
|
+
"fingerprint" => "0f:97:4b:82:87:bb:c6:dc:40:a3:c1:bc:bb:55:1e:fa"}
|
607
|
+
end
|
608
|
+
|
609
|
+
def setup_mock_ssh_keys
|
610
|
+
private_key_file = File.join(@ssh_dir, "id_rsa")
|
611
|
+
public_key_file = File.join(@ssh_dir, "id_rsa.pub")
|
612
|
+
File.open(private_key_file, 'w') do |f|
|
613
|
+
f.write <<EOF
|
614
|
+
-----BEGIN RSA PRIVATE KEY-----
|
615
|
+
MIICWwIBAAKBgQDIXpBBs7g93z/5JqW5IJNJR8bG6DWhpL2vR2ROEfzGqDHLZ+Xb
|
616
|
+
saS/Ogc3nZNSav3juHWdiBFIc0unPpLdwmXtcL3tjN52CJqPgU/W0q061fL/tk77
|
617
|
+
fFqW2upluo0ZRZQdPc3vTI3tWWZcpyE2LPHHUOI3KN+lRqxgw0Y6z/3SfwIDAQAB
|
618
|
+
AoGAbMC+xZp5TsPEokOywWeH6cdWgZF5wpF7Dw7Nx34F2AFkfYWYAgVKaSxizHHv
|
619
|
+
i1VdFmOBGw7Gaq+BiXXyGwEvdpmgDoZDwvJrShZef5LwYnJ/NCqjZ8Xbb9z4VxCL
|
620
|
+
pkqMFFpEeNQcIDLZRF8Z1prRQnOL+Z498P6d3G/UWkR5NXkCQQDsGlpJzJwAPpwr
|
621
|
+
YZ98LgKT0n2WHeCrMQ9ZyJQl3Dz40qasQmIotB+mdIh87EFex7vvyiuzRC5rfcoX
|
622
|
+
CBHEkQpVAkEA2UFNBKgI1v5+16K0/CXPakQ25AlGODDv2VXlHwRPOayUG/Tn2joj
|
623
|
+
fj0T4/pu9AGhz0oVXFlz7iO8PEwFU+plgwJAKD2tmdp31ErXj0VKS34EDnHX2dgp
|
624
|
+
zMPF3AWlynYpJjexFLcTx+A7bMF76d7SnXbpf0sz+4/pYYTFBvvnG1ulKQJACJsR
|
625
|
+
lfGiCAIkvB3x1VsaEDeLhRTo9yjZF17TqJrfGIXBiCn3VSmgZku9EfbFllzKMA/b
|
626
|
+
MMFKWlCIEEtimqRaSQJAPVA1E7AiEvfUv0kRT73tDf4p/BRJ7p2YwjxrGpDBQhG1
|
627
|
+
YI+4NOhWtAG3Uips++8RhvmLjv8y+TNKU31J1EJmYA==
|
628
|
+
-----END RSA PRIVATE KEY-----
|
629
|
+
EOF
|
630
|
+
end
|
631
|
+
|
632
|
+
File.open(public_key_file, 'w') do |f|
|
633
|
+
f.write <<EOF
|
634
|
+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDIXpBBs7g93z/5JqW5IJNJR8bG6DWhpL2vR2ROEfzGqDHLZ+XbsaS/Ogc3nZNSav3juHWdiBFIc0unPpLdwmXtcL3tjN52CJqPgU/W0q061fL/tk77fFqW2upluo0ZRZQdPc3vTI3tWWZcpyE2LPHHUOI3KN+lRqxgw0Y6z/3Sfw== OpenShift-Key
|
635
|
+
EOF
|
636
|
+
end
|
637
|
+
end
|
417
638
|
end
|
418
639
|
|
419
640
|
class FirstRunWizardDriver < RHC::Wizard
|