rhc 1.25.3 → 1.26.9

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.
@@ -10,6 +10,7 @@ describe RHC::Commands::Setup do
10
10
  before{ described_class.send(:public, *described_class.protected_instance_methods) }
11
11
  before{ FakeFS::FileSystem.clear }
12
12
  before{ RHC::Config.stub(:home_dir).and_return('/home/mock_user') }
13
+ before{ RHC::Servers.any_instance.stub(:load) }
13
14
 
14
15
  describe '#run' do
15
16
  it{ expects_running('setup').should call(:run).on(instance).with(no_args) }
@@ -0,0 +1,191 @@
1
+ require 'net/http'
2
+ require 'spec_helper'
3
+ require 'rhc/config'
4
+ require 'rhc/servers'
5
+
6
+ describe RHC::Servers do
7
+ before do
8
+ FakeFS.activate!
9
+ FakeFS::FileSystem.clear
10
+ end
11
+
12
+ after do
13
+ FakeFS.deactivate!
14
+ end
15
+
16
+ describe "servers class" do
17
+ subject do
18
+ RHC::Servers.new.tap do |s|
19
+ s.stub(:path).and_return('/home/mock_user/servers.yml')
20
+ s.stub(:load)
21
+ s.instance_variable_set(:@servers, [
22
+ RHC::Server.new(
23
+ 'openshift.server.com',
24
+ :nickname => 'online',
25
+ :login => 'user1',
26
+ :use_authorization_tokens => true,
27
+ :insecure => false)
28
+ ])
29
+ end
30
+ end
31
+
32
+ context "when finding server" do
33
+ it "should find by nickname or hostname" do
34
+ subject.send(:exists?, 'online').should be_true
35
+ subject.send(:exists?, 'whatever').should be_false
36
+ subject.send(:hostname_exists?, 'online').should be_false
37
+ subject.send(:hostname_exists?, 'openshift.server.com').should be_true
38
+ subject.send(:nickname_exists?, 'online').should be_true
39
+ subject.send(:nickname_exists?, 'openshift.server.com').should be_false
40
+ subject.send(:exists?, 'online').hostname.should == 'openshift.server.com'
41
+ subject.send(:exists?, 'openshift.server.com').nickname.should == 'online'
42
+ subject.send(:exists?, 'online').insecure.should == false
43
+ subject.send(:exists?, 'online').use_authorization_tokens.should == true
44
+ subject.find('online').should be_true
45
+ subject.find('openshift.server.com').should be_true
46
+ expect { subject.find('whatever') }.to raise_exception(RHC::ServerNotConfiguredException)
47
+ end
48
+ end
49
+
50
+ context "when adding a new server" do
51
+ before{ subject.add('another.server.com', :nickname => 'another', :login => 'user2', :use_authorization_tokens => false, :insecure => true) }
52
+ it { subject.instance_variable_get(:@servers).length.should == 2 }
53
+ it { subject.find('another').should be_true }
54
+ it { subject.find('another.server.com').should be_true }
55
+ it { subject.find('another').login.should == 'user2' }
56
+ it { subject.find('another').insecure.should == true }
57
+ it { subject.find('another').use_authorization_tokens.should == false }
58
+ end
59
+
60
+ context "when suggesting a nickname for unknown server" do
61
+ before{ subject.add('another.server.com') }
62
+ it { subject.find('server1').should be_true }
63
+ it { subject.find('another.server.com').should be_true }
64
+ it { subject.find('another.server.com').nickname.should == 'server1' }
65
+ end
66
+
67
+ context "when suggesting a nickname for an openshift subdomain" do
68
+ before{ subject.add('some.openshift.redhat.com') }
69
+ it { subject.find('some').should be_true }
70
+ it { subject.find('some.openshift.redhat.com').should be_true }
71
+ it { subject.find('some.openshift.redhat.com').nickname.should == 'some' }
72
+ end
73
+
74
+ context "when adding a new server with port and http scheme" do
75
+ before{ subject.add('http://another.server.com:4000', :nickname => 'another', :login => 'user2') }
76
+ it { subject.instance_variable_get(:@servers).length.should == 2 }
77
+ it { subject.find('another').should be_true }
78
+ it { subject.find('http://another.server.com:4000').should be_true }
79
+ it { subject.find('another').login.should == 'user2' }
80
+ it { expect { subject.find('another.server.com').to raise_exception(RHC::ServerNotConfiguredException) } }
81
+ it { expect { subject.find('https://another.server.com:4000').to raise_exception(RHC::ServerNotConfiguredException) } }
82
+ it { expect { subject.find('http://another.server.com').to raise_exception(RHC::ServerNotConfiguredException) } }
83
+ end
84
+
85
+ context "when adding an existing server" do
86
+ it "should error accordingly" do
87
+ expect { subject.add('openshift.server.com') }.to raise_exception(RHC::ServerHostnameExistsException)
88
+ expect { subject.add('openshift.server.com', :nickname => 'another') }.to raise_exception(RHC::ServerHostnameExistsException)
89
+ expect { subject.add('third.server.com', :nickname => 'online') }.to raise_exception(RHC::ServerNicknameExistsException)
90
+ end
91
+ end
92
+
93
+ context "when updating an existing server" do
94
+ before{ subject.update('online', :hostname => 'openshift2.server.com', :nickname => 'online2', :login => 'user2', :use_authorization_tokens => false, :insecure => true) }
95
+ it { subject.list.length.should == 1 }
96
+ it { subject.find('online2').hostname.should == 'openshift2.server.com' }
97
+ it { subject.find('online2').nickname.should == 'online2' }
98
+ it { subject.find('online2').login.should == 'user2' }
99
+ it { subject.find('online2').insecure.should == true }
100
+ it { subject.find('online2').use_authorization_tokens.should == false }
101
+ it { expect { subject.find('online') }.to raise_exception(RHC::ServerNotConfiguredException) }
102
+ end
103
+
104
+ context "when adding or updating a server" do
105
+ before{ subject.add_or_update('openshift.server.com', :nickname => 'online2', :login => 'user2', :use_authorization_tokens => false, :insecure => true) }
106
+ it { subject.list.length.should == 1 }
107
+ it { subject.find('openshift.server.com').hostname.should == 'openshift.server.com' }
108
+ it { subject.find('openshift.server.com').nickname.should == 'online2' }
109
+ it { subject.find('openshift.server.com').login.should == 'user2' }
110
+ it { subject.find('openshift.server.com').insecure.should == true }
111
+ it { subject.find('openshift.server.com').use_authorization_tokens.should == false }
112
+ it { expect { subject.find('online') }.to raise_exception(RHC::ServerNotConfiguredException) }
113
+ end
114
+
115
+ context "when removing an existing server" do
116
+ before{ subject.remove('online') }
117
+ it { subject.list.length.should == 0 }
118
+ it { expect { subject.find('online') }.to raise_exception(RHC::ServerNotConfiguredException) }
119
+ end
120
+
121
+ context "when finding the default server" do
122
+ it "should take the first if no default defined" do
123
+ subject.default.nickname.should == 'online'
124
+ subject.default.hostname.should == 'openshift.server.com'
125
+ end
126
+ end
127
+
128
+ context "when finding the default server" do
129
+ before do
130
+ s = subject.add('another.server.com', :nickname => 'another', :login => 'user2', :use_authorization_tokens => false, :insecure => true)
131
+ s.default = true
132
+ end
133
+ it "should take the one marked as default" do
134
+ subject.default.nickname.should == 'another'
135
+ subject.default.hostname.should == 'another.server.com'
136
+ end
137
+ end
138
+
139
+ context "when sync from config" do
140
+ before do
141
+ c = RHC::Config.new
142
+ c.instance_variable_set(:@opts, RHC::Vendor::ParseConfig.new.tap do |v|
143
+ v.add('libra_server', 'openshift.server.com')
144
+ v.add('default_rhlogin', 'user3')
145
+ end)
146
+ c.stub(:has_configs_from_files?).and_return(true)
147
+ subject.sync_from_config(c)
148
+ end
149
+ it { subject.list.length.should == 1 }
150
+ it { subject.default.hostname.should == 'openshift.server.com' }
151
+ it { subject.default.login.should == 'user3' }
152
+ end
153
+ end
154
+
155
+ describe "server class" do
156
+ subject do
157
+ RHC::Server.from_yaml_hash({
158
+ 'hostname' => 'https://foo.com/bar',
159
+ 'login' => 'user@foo.com',
160
+ 'use_authorization_tokens' => 'true',
161
+ 'insecure' => 'false'
162
+ })
163
+ end
164
+
165
+ context "when creating from yaml hash" do
166
+ it { subject.hostname.should == 'foo.com' }
167
+ it { subject.nickname.should == nil }
168
+ it { subject.login.should == 'user@foo.com' }
169
+ it { subject.use_authorization_tokens.should be_true }
170
+ it { subject.insecure.should be_false }
171
+ end
172
+
173
+ context "when checking server attributes" do
174
+ it { subject.designation.should == 'foo.com' }
175
+ it { subject.default?.should be_false }
176
+ it { subject.to_yaml_hash.should == { 'hostname' => 'foo.com', 'login' => 'user@foo.com', 'use_authorization_tokens' => true, 'insecure' => false } }
177
+ it { subject.to_config.should be_a(RHC::Vendor::ParseConfig) }
178
+ it { subject.to_config['default_rhlogin'].should == 'user@foo.com' }
179
+ it { subject.to_config['libra_server'].should == 'foo.com' }
180
+ it { subject.to_s.should == 'foo.com' }
181
+ end
182
+
183
+ context "when openshift online" do
184
+ let(:server){ RHC::Server.from_yaml_hash({'hostname' => 'https://openshift.redhat.com', 'nickname' => 'online'}) }
185
+ it { server.hostname.should == 'openshift.redhat.com' }
186
+ it { server.nickname.should == 'online' }
187
+ it { server.designation.should == 'online' }
188
+ it { server.to_s.should == 'online (openshift.redhat.com)' }
189
+ end
190
+ end
191
+ end
@@ -3,6 +3,7 @@ require 'rest_spec_helper'
3
3
  require 'rhc/wizard'
4
4
  require 'rhc/vendor/parseconfig'
5
5
  require 'rhc/config'
6
+ require 'rhc/servers'
6
7
  require 'ostruct'
7
8
  require 'rest_spec_helper'
8
9
  require 'wizard_spec_helper'
@@ -15,10 +16,12 @@ describe RHC::Wizard do
15
16
 
16
17
  def mock_config
17
18
  RHC::Config.stub(:home_dir).and_return('/home/mock_user')
19
+ RHC::Servers.stub(:home_dir).and_return('/home/mock_user')
18
20
  end
19
21
 
20
22
  let(:options){ (o = Commander::Command::Options.new).default(default_options); o }
21
23
  let(:config){ RHC::Config.new.tap{ |c| c.stub(:home_dir).and_return('/home/mock_user') } }
24
+ let(:servers){ RHC::Servers.new.tap{|c| c.stub(:home_dir).and_return('/home/mock_user') } }
22
25
  let(:default_options){ {} }
23
26
 
24
27
  describe "#finalize_stage" do
@@ -254,8 +257,8 @@ describe RHC::Wizard do
254
257
  #after{ FileUtils.rm_rf(@tmpdir) if @tmpdir }
255
258
  let(:home_dir){ '/home/mock_user' }#@tmpdir = Dir.mktmpdir }
256
259
  let(:config){ RHC::Config.new.tap{ |c| c.stub(:home_dir).and_return(home_dir) } }
257
-
258
260
  let(:options){ (o = Commander::Command::Options.new).default(default_options); o }
261
+ let(:servers){ RHC::Servers.new.tap{|c| c.stub(:home_dir).and_return(home_dir) } }
259
262
  let(:default_options){ {:server => mock_uri} }
260
263
  let(:username){ mock_user }
261
264
  let(:password){ 'password' }
@@ -282,6 +285,7 @@ describe RHC::Wizard do
282
285
 
283
286
  it "should execute the minimal path" do
284
287
  should_greet_user
288
+ should_configure_server(mock_uri)
285
289
  should_challenge_for(username, password)
286
290
  should_write_config
287
291
  should_create_an_ssh_keypair
@@ -297,6 +301,7 @@ describe RHC::Wizard do
297
301
  before{ subject.stub(:windows?).and_return(true) }
298
302
  it "should display windows info" do
299
303
  should_greet_user
304
+ should_configure_server(mock_uri)
300
305
  should_challenge_for(username, password)
301
306
  should_write_config
302
307
  should_create_an_ssh_keypair
@@ -320,6 +325,7 @@ describe RHC::Wizard do
320
325
  end
321
326
  it "should create the domain" do
322
327
  should_greet_user
328
+ should_configure_server(mock_uri)
323
329
  should_challenge_for(username, password)
324
330
  should_write_config
325
331
  should_create_an_ssh_keypair
@@ -335,6 +341,7 @@ describe RHC::Wizard do
335
341
  before{ stub_api_request(:get, 'broker/rest/user', :user => username, :password => 'invalid').to_return(:status => 401).times(1).to_return(simple_user(username)) }
336
342
  it "should prompt them again" do
337
343
  should_greet_user
344
+ should_configure_server(mock_uri)
338
345
 
339
346
  input_line username
340
347
  input_line 'invalid'
@@ -353,6 +360,7 @@ describe RHC::Wizard do
353
360
  before{ stub_one_key('a'); stub_update_key('a') }
354
361
  it "should prompt for the new key" do
355
362
  should_greet_user
363
+ should_configure_server(mock_uri)
356
364
  should_challenge_for(username, password)
357
365
  should_write_config
358
366
  should_create_an_ssh_keypair
@@ -378,6 +386,7 @@ describe RHC::Wizard do
378
386
  end
379
387
  it "should give the user a name the key" do
380
388
  should_greet_user
389
+ should_configure_server(mock_uri)
381
390
  should_challenge_for(username, password)
382
391
  should_write_config
383
392
  should_not_create_an_ssh_keypair
@@ -402,6 +411,7 @@ describe RHC::Wizard do
402
411
 
403
412
  it "should prompt for the new key" do
404
413
  should_greet_user
414
+ should_configure_server(mock_uri)
405
415
  should_challenge_for(username, password)
406
416
  should_write_config
407
417
  should_not_create_an_ssh_keypair
@@ -434,6 +444,7 @@ describe RHC::Wizard do
434
444
 
435
445
  it "should skip steps that have already been completed" do
436
446
  should_greet_user
447
+ should_configure_server(mock_uri)
437
448
  should_challenge_for(nil, password)
438
449
  should_write_config
439
450
  should_create_an_ssh_keypair
@@ -451,6 +462,7 @@ describe RHC::Wizard do
451
462
 
452
463
  it "should overwrite the config" do
453
464
  should_greet_user
465
+ should_configure_server(mock_uri)
454
466
  should_challenge_for(nil, password)
455
467
  should_overwrite_config
456
468
  end
@@ -548,6 +560,7 @@ describe RHC::Wizard do
548
560
 
549
561
  it "should match ssh key fallback fingerprint to net::ssh fingerprint" do
550
562
  # we need to write to a live file system so ssh-keygen can find it
563
+ RHC::Servers.any_instance.stub(:save!)
551
564
  FakeFS.deactivate!
552
565
  Dir.mktmpdir do |dir|
553
566
  setup_mock_ssh_keys(dir)
@@ -614,7 +627,7 @@ describe RHC::Wizard do
614
627
  attr_accessor :mock_user, :rest_client
615
628
  def initialize(*args)
616
629
  if args.empty?
617
- args = [RHC::Config.new, Commander::Command::Options.new]
630
+ args = [RHC::Config.new, Commander::Command::Options.new, RHC::Servers.new]
618
631
  args[1].default(args[0].to_options)
619
632
  end
620
633
  super *args
@@ -746,6 +759,10 @@ EOF
746
759
  end
747
760
  end
748
761
 
762
+ class ServerWizardDriver < RHC::Wizard
763
+ include WizardDriver
764
+ end
765
+
749
766
  describe RHC::DomainWizard do
750
767
  context "with a rest client" do
751
768
  let(:rest_client){ double }
@@ -366,6 +366,7 @@ module ClassSpecHelpers
366
366
  def base_config(&block)
367
367
  config = RHC::Config.new
368
368
  config.stub(:load_config_files)
369
+ config.stub(:load_servers)
369
370
  defaults = config.instance_variable_get(:@defaults)
370
371
  yield config, defaults if block_given?
371
372
  RHC::Config.stub(:default).and_return(config)
@@ -390,6 +391,25 @@ module ClassSpecHelpers
390
391
  end
391
392
  end
392
393
 
394
+ def local_config
395
+ user = respond_to?(:local_config_username) ? self.local_config_username : 'test_user'
396
+ password = respond_to?(:local_config_password) ? self.local_config_password : 'test pass'
397
+ server = respond_to?(:local_config_server) ? self.local_config_server : nil
398
+
399
+ c = base_config
400
+
401
+ local_config = RHC::Vendor::ParseConfig.new
402
+ local_config.add('default_rhlogin', user) if user
403
+ local_config.add('password', password) if password
404
+ local_config.add('libra_server', server) if server
405
+
406
+ c.instance_variable_set(:@local_config, local_config)
407
+ opts = c.to_options
408
+ opts[:rhlogin].should == user
409
+ opts[:password].should == password
410
+ opts[:server].should == server if server
411
+ end
412
+
393
413
  def expect_multi_ssh(command, hosts, check_error=false)
394
414
  require 'net/ssh/multi'
395
415
 
@@ -9,6 +9,19 @@ module WizardStepsHelper
9
9
  end
10
10
  end
11
11
 
12
+ def should_configure_server(server=nil)
13
+ server = 'openshift.redhat.com' if server.nil?
14
+ input_line server
15
+ next_stage.should_not be_nil
16
+
17
+ last_output do |s|
18
+ s.should match(/If you have your own OpenShift server, you can specify it now/)
19
+ s.should match(/Just hit enter to use: #{server}/)
20
+ s.should match(/Enter server address: |#{server}|/)
21
+ s.should match(/You can add more servers later using 'rhc server'/)
22
+ end
23
+ end
24
+
12
25
  def should_challenge_for(username, password)
13
26
  input_line username.to_s if username
14
27
  input_line password.to_s if password
@@ -34,10 +47,20 @@ module WizardStepsHelper
34
47
  last_output.should match("Saving configuration to #{current_config_path}")
35
48
 
36
49
  File.readable?(current_config_path).should be true
37
- RHC::Vendor::ParseConfig.new(current_config_path).tap do |cp|
38
- cp["default_rhlogin"].should == username
39
- cp["libra_server"].should == mock_uri
40
- cp["use_authorization_tokens"].should == 'false'
50
+
51
+ if present
52
+ RHC::Vendor::ParseConfig.new(current_config_path)["libra_server"].should == mock_uri
53
+ RHC::Servers.new.tap do |s|
54
+ s.list.length.should == 2
55
+ s.list.last.login.should == username
56
+ s.list.last.use_authorization_tokens.should be false
57
+ end
58
+ else
59
+ RHC::Vendor::ParseConfig.new(current_config_path).tap do |cp|
60
+ cp["default_rhlogin"].should == username
61
+ cp["libra_server"].should == mock_uri
62
+ cp["use_authorization_tokens"].should == 'false'
63
+ end
41
64
  end
42
65
  end
43
66
 
@@ -317,7 +340,7 @@ EOF
317
340
  default_rhlogin='a_different_user'
318
341
 
319
342
  # Server API
320
- libra_server = 'a_different_server.com'
343
+ libra_server = 'a-different-server.com'
321
344
  EOF
322
345
  end
323
346
  path
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 117
4
+ hash: 109
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 25
9
- - 3
10
- version: 1.25.3
8
+ - 26
9
+ - 9
10
+ version: 1.26.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Red Hat
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-06-09 00:00:00 Z
18
+ date: 2014-06-24 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: net-ssh
@@ -270,6 +270,7 @@ files:
270
270
  - lib/rhc/rest.rb
271
271
  - lib/rhc/autocomplete.rb
272
272
  - lib/rhc/git_helpers.rb
273
+ - lib/rhc/servers.rb
273
274
  - lib/rhc/command_runner.rb
274
275
  - lib/rhc/context_helper.rb
275
276
  - lib/rhc/config.rb
@@ -302,6 +303,7 @@ files:
302
303
  - lib/rhc/commands.rb
303
304
  - lib/rhc/ssh_helpers.rb
304
305
  - lib/rhc/output_helpers.rb
306
+ - lib/rhc/server_helpers.rb
305
307
  - lib/rhc/coverage_helper.rb
306
308
  - lib/rhc/help_formatter.rb
307
309
  - lib/rhc/rest/team.rb
@@ -359,6 +361,7 @@ files:
359
361
  - spec/rhc/rest_spec.rb
360
362
  - spec/rhc/targz_spec.rb
361
363
  - spec/rhc/wizard_spec.rb
364
+ - spec/rhc/servers_spec.rb
362
365
  - spec/rhc/rest_client_spec.rb
363
366
  - spec/rhc/commands/sshkey_spec.rb
364
367
  - spec/rhc/commands/apps_spec.rb
@@ -396,6 +399,7 @@ files:
396
399
  - spec/rhc/helpers_spec.rb
397
400
  - spec/rhc/rest_application_spec.rb
398
401
  - spec/rhc/command_spec.rb
402
+ - features/server_feature.rb
399
403
  - features/members_feature.rb
400
404
  - features/assets/deploy.tar.gz
401
405
  - features/deployments_feature.rb
@@ -456,6 +460,7 @@ test_files:
456
460
  - spec/rhc/rest_spec.rb
457
461
  - spec/rhc/targz_spec.rb
458
462
  - spec/rhc/wizard_spec.rb
463
+ - spec/rhc/servers_spec.rb
459
464
  - spec/rhc/rest_client_spec.rb
460
465
  - spec/rhc/commands/sshkey_spec.rb
461
466
  - spec/rhc/commands/apps_spec.rb
@@ -493,6 +498,7 @@ test_files:
493
498
  - spec/rhc/helpers_spec.rb
494
499
  - spec/rhc/rest_application_spec.rb
495
500
  - spec/rhc/command_spec.rb
501
+ - features/server_feature.rb
496
502
  - features/members_feature.rb
497
503
  - features/assets/deploy.tar.gz
498
504
  - features/deployments_feature.rb