rhc 0.94.8 → 0.95.13

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.
Files changed (59) hide show
  1. data/README.md +27 -1
  2. data/bin/rhc +15 -23
  3. data/bin/rhc-app +4 -1
  4. data/bin/rhc-chk +3 -0
  5. data/bin/rhc-create-app +3 -0
  6. data/bin/rhc-create-domain +3 -0
  7. data/bin/rhc-ctl-app +3 -0
  8. data/bin/rhc-ctl-domain +3 -0
  9. data/bin/rhc-domain +5 -2
  10. data/bin/rhc-domain-info +3 -0
  11. data/bin/rhc-port-forward +16 -18
  12. data/bin/rhc-snapshot +3 -0
  13. data/bin/rhc-sshkey +3 -0
  14. data/bin/rhc-tail-files +3 -0
  15. data/bin/rhc-user-info +1 -0
  16. data/features/README.md +70 -0
  17. data/features/lib/rhc_helper/app.rb +124 -0
  18. data/features/lib/rhc_helper/cartridge.rb +72 -0
  19. data/features/lib/rhc_helper/commandify.rb +154 -0
  20. data/features/lib/rhc_helper/domain.rb +50 -0
  21. data/features/lib/rhc_helper/httpify.rb +107 -0
  22. data/features/lib/rhc_helper/loggable.rb +39 -0
  23. data/features/lib/rhc_helper/persistable.rb +38 -0
  24. data/features/lib/rhc_helper/runnable.rb +41 -0
  25. data/features/lib/rhc_helper.rb +7 -0
  26. data/features/step_definitions/application_steps.rb +99 -0
  27. data/features/step_definitions/cartridge_steps.rb +42 -0
  28. data/features/step_definitions/client_steps.rb +32 -0
  29. data/features/step_definitions/domain_steps.rb +19 -0
  30. data/features/support/env.rb +99 -0
  31. data/features/verify.feature +123 -0
  32. data/lib/rhc/cli.rb +4 -1
  33. data/lib/rhc/commands/base.rb +28 -6
  34. data/lib/rhc/commands/server.rb +4 -1
  35. data/lib/rhc/commands/setup.rb +24 -0
  36. data/lib/rhc/commands.rb +10 -5
  37. data/lib/rhc/config.rb +90 -21
  38. data/lib/rhc/core_ext.rb +11 -2
  39. data/lib/rhc/coverage_helper.rb +35 -0
  40. data/lib/rhc/help_formatter.rb +30 -0
  41. data/lib/rhc/helpers.rb +41 -5
  42. data/lib/rhc/ssh_key_helpers.rb +72 -0
  43. data/lib/rhc/targz.rb +2 -8
  44. data/lib/rhc/wizard.rb +75 -58
  45. data/lib/rhc-common.rb +20 -13
  46. data/lib/rhc-rest.rb +3 -11
  47. data/spec/coverage_helper.rb +51 -0
  48. data/spec/rest_spec_helper.rb +86 -0
  49. data/spec/rhc/cli_spec.rb +19 -3
  50. data/spec/rhc/commands/server_spec.rb +2 -2
  51. data/spec/rhc/common_spec.rb +49 -0
  52. data/spec/rhc/config_spec.rb +328 -0
  53. data/spec/rhc/helpers_spec.rb +74 -1
  54. data/spec/rhc/rest_client_spec.rb +402 -0
  55. data/spec/rhc/rest_spec.rb +454 -0
  56. data/spec/rhc/targz_spec.rb +13 -0
  57. data/spec/rhc/wizard_spec.rb +305 -43
  58. data/spec/spec_helper.rb +30 -25
  59. metadata +124 -5
data/lib/rhc/helpers.rb CHANGED
@@ -1,7 +1,18 @@
1
1
  require 'commander/user_interaction'
2
2
  require 'rhc/config'
3
+ require 'rhc/commands'
4
+
5
+ OptionParser.accept(URI) {|s,| URI.parse(s) if s}
3
6
 
4
7
  module RHC
8
+
9
+ module Helpers
10
+ private
11
+ def self.global_option(*args)
12
+ RHC::Commands.global_option *args
13
+ end
14
+ end
15
+
5
16
  module Helpers
6
17
 
7
18
  # helpers always have Commander UI available
@@ -28,15 +39,40 @@ module RHC
28
39
  # Replace with d = DateTime.rfc3339(s)
29
40
  end
30
41
 
42
+
43
+ #
44
+ # Global config
45
+ #
46
+
47
+ global_option '-c', '--config FILE', "Path of a different config file"
48
+ def config
49
+ raise "Operations requiring configuration must define a config accessor"
50
+ end
51
+
52
+ global_option '-l', '--rhlogin login', "Red Hat login (RHN or OpenShift login with OpenShift access)"
53
+ global_option '-p', '--password password', "RHLogin password"
54
+
31
55
  def openshift_server
32
- RHC::Config.get_value('libra_server')
56
+ config.get_value('libra_server')
33
57
  end
58
+ def openshift_url
59
+ "https://#{openshift_server}"
60
+ end
61
+
34
62
 
35
- def success(*args)
36
- args.each{ |a| say color(a, :green) }
63
+ #
64
+ # Output helpers
65
+ #
66
+
67
+ def say(msg)
68
+ super
69
+ msg
70
+ end
71
+ def success(msg, *args)
72
+ say color(msg, :green)
37
73
  end
38
- def warn(*args)
39
- args.each{ |a| say color(a, :yellow) }
74
+ def warn(msg, *args)
75
+ say color(msg, :yellow)
40
76
  end
41
77
 
42
78
  def color(s, color)
@@ -0,0 +1,72 @@
1
+ ###
2
+ # ssh_key_helpers.rb - methods to help manipulate ssh keys
3
+ #
4
+ # Copyright 2012 Red Hat, Inc. and/or its affiliates.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'net/ssh'
19
+ require 'rhc/vendor/sshkey'
20
+
21
+
22
+ module RHC
23
+ module SSHKeyHelpers
24
+ # Public: Generate an SSH key and store it in ~/.ssh/id_rsa
25
+ #
26
+ # type - The String type RSA or DSS.
27
+ # bits - The Integer value for number of bits.
28
+ # comment - The String comment for the key
29
+ #
30
+ # Examples
31
+ #
32
+ # generate_ssh_key_ruby()
33
+ # # => /home/user/.ssh/id_rsa.pub
34
+ #
35
+ # Returns nil on failure or public key location as a String on success
36
+ def generate_ssh_key_ruby(type="RSA", bits = 2048, comment = "OpenShift-Key")
37
+ key = RHC::Vendor::SSHKey.generate(:type => type,
38
+ :bits => bits,
39
+ :comment => comment)
40
+ ssh_dir = "#{RHC::Config.home_dir}/.ssh"
41
+ if File.exists?("#{ssh_dir}/id_rsa")
42
+ puts "SSH key already exists: #{ssh_dir}/id_rsa. Reusing..."
43
+ return nil
44
+ else
45
+ unless File.exists?(ssh_dir)
46
+ FileUtils.mkdir_p(ssh_dir)
47
+ File.chmod(0700, ssh_dir)
48
+ end
49
+ File.open("#{ssh_dir}/id_rsa", 'w') {|f| f.write(key.private_key)}
50
+ File.chmod(0600, "#{ssh_dir}/id_rsa")
51
+ File.open("#{ssh_dir}/id_rsa.pub", 'w') {|f| f.write(key.ssh_public_key)}
52
+
53
+ ssh_add if exe?('ssh-add')
54
+ end
55
+ "#{ssh_dir}/id_rsa.pub"
56
+ end
57
+
58
+ def exe?(executable)
59
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory|
60
+ File.executable?(File.join(directory, executable.to_s))
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def ssh_add
67
+ #:nocov:
68
+ `ssh-add 2&>1`
69
+ #:nocov:
70
+ end
71
+ end
72
+ end
data/lib/rhc/targz.rb CHANGED
@@ -3,13 +3,7 @@ require 'rhc/vendor/zliby'
3
3
  require 'archive/tar/minitar'
4
4
  include Archive::Tar
5
5
 
6
- if File.executable?('/usr/bin/gnutar') then
7
- #:nocov:
8
- TAR_BIN = '/usr/bin/gnutar'
9
- #:nocov:
10
- else
11
- TAR_BIN = 'tar'
12
- end
6
+ TAR_BIN = File.executable?('/usr/bin/gnutar') ? '/usr/bin/gnutar' : 'tar'
13
7
 
14
8
  module RHC
15
9
 
@@ -20,7 +14,7 @@ module RHC
20
14
  return false if ! (File.file? filename and File.basename(filename).downcase =~ /.\.tar\.gz$/i)
21
15
 
22
16
  contains = false
23
- if RHC::Helpers.windows? or force_ruby then
17
+ if RHC::Helpers.windows? or force_ruby
24
18
  search = /#{search.to_s}/ if ! search.is_a?(Regexp)
25
19
  begin
26
20
  RHC::Vendor::Zlib::GzipReader.open(filename) do |gz|
data/lib/rhc/wizard.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rhc-common'
2
2
  require 'rhc/helpers'
3
+ require 'rhc/ssh_key_helpers'
3
4
  require 'highline/system_extensions'
4
5
  require 'net/ssh'
5
6
  require 'fileutils'
@@ -8,19 +9,28 @@ module RHC
8
9
  class Wizard
9
10
  include HighLine::SystemExtensions
10
11
  include RHC::Helpers
11
-
12
- @@stages = [:greeting_stage,
13
- :login_stage,
14
- :create_config_stage,
15
- :config_ssh_key_stage,
16
- :upload_ssh_key_stage,
17
- :install_client_tools_stage,
18
- :config_namespace_stage,
19
- :show_app_info_stage,
20
- :finalize_stage]
12
+ include RHC::SSHKeyHelpers
13
+
14
+ STAGES = [:greeting_stage,
15
+ :login_stage,
16
+ :create_config_stage,
17
+ :config_ssh_key_stage,
18
+ :upload_ssh_key_stage,
19
+ :install_client_tools_stage,
20
+ :config_namespace_stage,
21
+ :show_app_info_stage,
22
+ :finalize_stage]
23
+ def stages
24
+ STAGES
25
+ end
21
26
 
22
27
  def initialize(config_path)
23
28
  @config_path = config_path
29
+ if @libra_server.nil?
30
+ @libra_server = get_var('libra_server')
31
+ # if not set, set to default
32
+ @libra_server = @libra_server ? @libra_server : "openshift.redhat.com"
33
+ end
24
34
  end
25
35
 
26
36
  # Public: Runs the setup wizard to make sure ~/.openshift and ~/.ssh are correct
@@ -32,7 +42,7 @@ module RHC
32
42
  #
33
43
  # Returns nil on failure or true on success
34
44
  def run
35
- @@stages.each do |stage|
45
+ stages.each do |stage|
36
46
  # FIXME: cleanup if we fail
37
47
  if (self.send stage).nil?
38
48
  return nil
@@ -43,10 +53,6 @@ module RHC
43
53
 
44
54
  private
45
55
 
46
- def stages
47
- @@stages
48
- end
49
-
50
56
  def greeting_stage
51
57
  paragraph do
52
58
  say "Starting Interactive Setup for OpenShift's command line interface"
@@ -68,18 +74,14 @@ module RHC
68
74
  end
69
75
 
70
76
  def login_stage
71
- if @libra_server.nil?
72
- @libra_server = get_var('libra_server')
73
- # if not set, set to default
74
- @libra_server = @libra_server ? @libra_server : "openshift.redhat.com"
75
- end
76
-
77
77
  # get_password adds an extra untracked newline so set :bottom to -1
78
78
  section(:top => 1, :bottom => -1) do
79
79
  @username = ask("To connect to #{@libra_server} enter your OpenShift login (email or Red Hat login id): ") do |q|
80
80
  q.default = RHC::Config.default_rhlogin
81
81
  end
82
- @password = RHC::get_password
82
+
83
+ @password = RHC::Config.password
84
+ @password = RHC::get_password if @password.nil?
83
85
  end
84
86
 
85
87
  # Confirm username / password works:
@@ -121,29 +123,31 @@ EOF
121
123
  end
122
124
 
123
125
  def config_ssh_key_stage
124
- @ssh_priv_key_file_path = "#{RHC::Config.home_dir}/.ssh/id_rsa"
125
- @ssh_pub_key_file_path = "#{RHC::Config.home_dir}/.ssh/id_rsa.pub"
126
- unless File.exists? @ssh_priv_key_file_path
126
+ if RHC::Config.should_run_ssh_wizard?
127
127
  paragraph do
128
128
  say "No SSH keys were found. We will generate a pair of keys for you."
129
129
  end
130
- @ssh_pub_key_file_path = generate_ssh_key_ruby()
130
+ ssh_pub_key_file_path = generate_ssh_key_ruby()
131
131
  paragraph do
132
- say " Created: #{@ssh_pub_key_file_path}\n\n"
132
+ say " Created: #{ssh_pub_key_file_path}\n\n"
133
133
  end
134
134
  end
135
135
  true
136
136
  end
137
137
 
138
+ def ssh_keygen_fallback(ssh_pub_key_file_path)
139
+ `ssh-keygen -lf #{ssh_pub_key_file_path} 2>&1`.split(' ')[1]
140
+ end
141
+
138
142
  def ssh_key_uploaded?
139
143
  @ssh_keys = RHC::get_ssh_keys(@libra_server, @username, @password, RHC::Config.default_proxy)
140
144
  additional_ssh_keys = @ssh_keys['keys']
141
145
 
142
146
  local_fingerprint = nil
143
147
  begin
144
- local_fingerprint = Net::SSH::KeyFactory.load_public_key(@ssh_pub_key_file_path).fingerprint
148
+ local_fingerprint = Net::SSH::KeyFactory.load_public_key(RHC::Config.ssh_pub_key_file_path).fingerprint
145
149
  rescue NoMethodError #older net/ssh (mac for example)
146
- local_fingerprint = `ssh-keygen -lf #{@ssh_pub_key_file_path}`.split(' ')[1]
150
+ local_fingerprint = ssh_keygen_fallback RHC::Config.ssh_pub_key_file_path
147
151
  end
148
152
 
149
153
  return true if @ssh_keys['fingerprint'] == local_fingerprint
@@ -192,20 +196,19 @@ EOF
192
196
  key_fingerprint = nil
193
197
  key_valid = true
194
198
  begin
195
- key_fingerprint = Net::SSH::KeyFactory.load_public_key(@ssh_pub_key_file_path).fingerprint
199
+ key_fingerprint = Net::SSH::KeyFactory.load_public_key(RHC::Config.ssh_pub_key_file_path).fingerprint
196
200
  rescue NoMethodError #older net/ssh (mac for example)
197
- key_fingerprint = `ssh-keygen -lf #{@ssh_pub_key_file_path}`.split(' ')[1]
201
+ key_fingerprint = ssh_keygen_fallback RHC::Config.ssh_pub_key_file_path
198
202
  if $?.exitstatus != 0
199
203
  key_valid = false
200
204
  end
201
- rescue Net::SSH::Exception
202
- rescue NotImplementedError
205
+ rescue Net::SSH::Exception, NotImplementedError
203
206
  key_valid = false
204
207
  end
205
208
 
206
209
  if ! key_valid
207
210
  paragraph do
208
- say "Your ssh public key at #{@ssh_pub_key_file_path} can not be read. " \
211
+ say "Your ssh public key at #{RHC::Config.ssh_pub_key_file_path} can not be read. " \
209
212
  "The setup can not continue until you manually remove or fix both of your " \
210
213
  "public and private keys id_rsa keys."
211
214
  end
@@ -224,12 +227,12 @@ EOF
224
227
  if known_keys.include?(key_name)
225
228
  section do
226
229
  say "Key already exists! Updating key #{key_name} .. "
227
- add_or_update_key('update', key_name, @ssh_pub_key_file_path, @username, @password)
230
+ add_or_update_key('update', key_name, RHC::Config.ssh_pub_key_file_path, @username, @password)
228
231
  end
229
232
  else
230
233
  section do
231
234
  say "Sending new key #{key_name} .. "
232
- add_or_update_key('add', key_name, @ssh_pub_key_file_path, @username, @password)
235
+ add_or_update_key('add', key_name, RHC::Config.ssh_pub_key_file_path, @username, @password)
233
236
  end
234
237
  end
235
238
  true
@@ -382,35 +385,41 @@ EOF
382
385
  "applications without first creating a namespace."
383
386
  end
384
387
 
385
- namespace = nil
386
- paragraph do
387
- namespace = ask "Please enter a namespace or leave this blank if you wish to skip this step:" do |q|
388
- q.validate = lambda { |p| RHC::check_namespace p }
389
- end
390
- end
391
-
392
- while !config_namespace namespace do
388
+ # Ask for a namespace at least once, configure the namespace if a valid,
389
+ # non-blank string is provided.
390
+ namespace = nil
391
+ first_pass = true
392
+ while first_pass or !config_namespace namespace do
393
+ first_pass = false
393
394
  paragraph do
394
395
  namespace = ask "Please enter a namespace or leave this blank if you wish to skip this step:" do |q|
395
- q.validate = lambda { |p| RHC::check_namespace p }
396
+ q.validate = lambda{ |p| RHC::check_namespace p }
397
+ q.responses[:not_valid] = 'The namespace value must contain only letters and/or numbers (A-Za-z0-9):'
398
+ q.responses[:ask_on_error] = ''
396
399
  end
397
400
  end
398
401
  end
399
402
  end
400
403
 
401
- def dbus_send_session_method(name, service, obj_path, iface, stringafied_params, wait_for_reply=true)
404
+ def dbus_send_exec(name, service, obj_path, iface, stringafied_params, wait_for_reply)
405
+ # :nocov: dbus_send_exec is not safe to run on a test system
402
406
  method = "#{iface}.#{name}"
403
407
  print_reply = ""
404
408
  print_reply = "--print-reply" if wait_for_reply
409
+
405
410
  cmd = "dbus-send --session #{print_reply} --type=method_call \
406
411
  --dest=#{service} #{obj_path} #{method} #{stringafied_params}"
407
- output = `#{cmd} 2>&1`
412
+ `cmd 2>&1`
413
+ # :nocov:
414
+ end
408
415
 
416
+ def dbus_send_session_method(name, service, obj_path, iface, stringafied_params, wait_for_reply=true)
417
+ output = dbus_send_exec(name, service, obj_path, iface, stringafied_params, wait_for_reply)
409
418
  raise output if output.start_with?('Error') and !$?.success?
410
419
 
411
420
  # parse the output
412
421
  results = []
413
- output.each_with_index do |line, i|
422
+ output.split('\n').each_with_index do |line, i|
414
423
  if i != 0 # discard first line
415
424
  param_type, value = line.chomp.split(" ", 2)
416
425
 
@@ -420,7 +429,7 @@ EOF
420
429
  when "string"
421
430
  results << value
422
431
  else
423
- puts "unknown type #{param_type} - treating as string"
432
+ say "unknown type #{param_type} - treating as string"
424
433
  results << value
425
434
  end
426
435
  end
@@ -513,18 +522,12 @@ We recommend these free applications:
513
522
  EOF
514
523
  end
515
524
 
516
- def exe?(executable)
517
- ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory|
518
- File.executable?(File.join(directory, executable.to_s))
519
- end
525
+ def git_version_exec
526
+ `git --version 2>&1`
520
527
  end
521
528
 
522
529
  def has_git?
523
- begin
524
- %x{ git --version }
525
- rescue
526
- end
527
-
530
+ git_version_exec
528
531
  $?.success?
529
532
  rescue
530
533
  false
@@ -581,4 +584,18 @@ EOF
581
584
  true
582
585
  end
583
586
  end
587
+
588
+ class SSHWizard < Wizard
589
+ STAGES = [:config_ssh_key_stage,
590
+ :upload_ssh_key_stage]
591
+ def stages
592
+ STAGES
593
+ end
594
+
595
+ def initialize(username, password)
596
+ @username = username
597
+ @password = password
598
+ super("")
599
+ end
600
+ end
584
601
  end
data/lib/rhc-common.rb CHANGED
@@ -176,15 +176,15 @@ end
176
176
  regex_failed_error='contains non-alphanumeric characters!')
177
177
  if field
178
178
  if field =~ val_regex
179
- puts "#{type} " + regex_failed_error
179
+ say "#{type} " + regex_failed_error
180
180
  return false
181
181
  end
182
182
  if max != 0 && field.length > max
183
- puts "maximum #{type} size is #{max} characters"
183
+ say "maximum #{type} size is #{max} characters"
184
184
  return false
185
185
  end
186
186
  else
187
- puts "#{type} is required"
187
+ say "#{type} is required"
188
188
  return false
189
189
  end
190
190
  field
@@ -306,9 +306,13 @@ end
306
306
 
307
307
  # Inject public fingerprint into key.
308
308
  begin
309
- ssh_keys['fingerprint'] = \
310
- Net::SSH::KeyFactory.load_data_public_key(
311
- "#{ssh_keys['ssh_type']} #{ssh_keys['ssh_key']}").fingerprint
309
+ if ssh_keys['ssh_type'].nil? or ssh_keys['ssh_type'].empty?
310
+ ssh_keys['fingerprint'] = nil
311
+ else
312
+ ssh_keys['fingerprint'] = \
313
+ Net::SSH::KeyFactory.load_data_public_key(
314
+ "#{ssh_keys['ssh_type']} #{ssh_keys['ssh_key']}").fingerprint
315
+ end
312
316
  rescue NoMethodError
313
317
  #older net/ssh (mac for example)
314
318
  tempfile = `mktemp /tmp/openshift.XXXXXXXX`
@@ -532,6 +536,9 @@ end
532
536
  rescue Rhc::Rest::ValidationException => e
533
537
  validation_error_code = (e.code.nil?) ? 406 : e.code
534
538
  print_response_err(Struct::FakeResponse.new(e.message, validation_error_code))
539
+ rescue Rhc::Rest::ServerErrorException => e
540
+ error_code = (e.code.nil?) ? 500 : e.code
541
+ print_response_err(Struct::FakeResponse.new(e.message, error_code))
535
542
  end
536
543
  else
537
544
  json_data = generate_json(data)
@@ -864,7 +871,7 @@ LOOKSGOOD
864
871
  end
865
872
  end
866
873
  rescue Exception => e
867
- puts e.message
874
+ puts e.backtrace if debug
868
875
  puts "Error in trying to save snapshot. You can try to save manually by running:"
869
876
  puts
870
877
  puts ssh_cmd
@@ -877,7 +884,7 @@ LOOKSGOOD
877
884
  def self.snapshot_restore(rhc_domain, namespace, app_name, app_uuid, filename, debug=false)
878
885
  if File.exists? filename
879
886
 
880
- if ! RHC::TarGz.contains filename, './*/' + app_name
887
+ if ! RHC::Helpers.windows? and ! RHC::TarGz.contains filename, './*/' + app_name
881
888
 
882
889
  puts "Archive at #{filename} does not contain the target application: ./*/#{app_name}"
883
890
  puts "If you created this archive rather than exported with rhc-snapshot, be sure"
@@ -887,7 +894,7 @@ LOOKSGOOD
887
894
 
888
895
  else
889
896
 
890
- include_git = RHC::TarGz.contains filename, './*/git'
897
+ include_git = RHC::Helpers.windows? ? false : RHC::TarGz.contains(filename, './*/git')
891
898
 
892
899
  ssh_cmd = "cat #{filename} | ssh #{app_uuid}@#{app_name}-#{namespace}.#{rhc_domain} 'restore#{include_git ? ' INCLUDE_GIT' : ''}'"
893
900
  puts "Restoring from snapshot #{filename}..."
@@ -919,8 +926,8 @@ LOOKSGOOD
919
926
  puts "Terminating..."
920
927
  end
921
928
  File.open(filename, 'rb') do |file|
922
- while (line = file.gets)
923
- channel.send_data line
929
+ file.chunk(1024) do |chunk|
930
+ channel.send_data chunk
924
931
  end
925
932
  end
926
933
  channel.eof!
@@ -929,7 +936,7 @@ LOOKSGOOD
929
936
  ssh.loop
930
937
  end
931
938
  rescue Exception => e
932
- puts e.message if debug
939
+ puts e.backtrace
933
940
  puts "Error in trying to restore snapshot. You can try to restore manually by running:"
934
941
  puts
935
942
  puts ssh_cmd
@@ -1235,7 +1242,7 @@ end
1235
1242
  #
1236
1243
  def default_setup_wizard
1237
1244
  if RHC::Config.should_run_wizard?
1238
- w = RHC::Wizard.new(RHC::Config.local_config_path)
1245
+ w = RHC::Wizard.new(RHC::Config.local_config_path)
1239
1246
  return w.run
1240
1247
  end
1241
1248
 
data/lib/rhc-rest.rb CHANGED
@@ -8,17 +8,12 @@ require 'rhc-rest/domain'
8
8
  require 'rhc-rest/key'
9
9
  require 'rhc-rest/user'
10
10
 
11
- @@end_point = ""
12
- @@headers = {:accept => :json}
13
-
14
11
  module Rhc
15
12
  module Rest
13
+ @@headers = {:accept => :json}
14
+
16
15
  def logger
17
- if defined?Rails.logger
18
- Rails.logger
19
- else
20
- Logger.new(STDOUT)
21
- end
16
+ Logger.new(STDOUT)
22
17
  end
23
18
 
24
19
  def parse_response(response)
@@ -67,15 +62,12 @@ module Rhc
67
62
 
68
63
  def send(request)
69
64
  begin
70
- #puts request.headers
71
65
  response = request.execute
72
66
  #set cookie
73
67
  rh_sso = response.cookies['rh_sso']
74
- #puts response.cookies
75
68
  if not rh_sso.nil?
76
69
  @@headers["cookie"] = "rh_sso=#{rh_sso}"
77
70
  end
78
- #puts "#{response}"
79
71
  return parse_response(response) unless response.nil? or response.code == 204
80
72
  rescue RestClient::RequestTimeout, RestClient::ServerBrokeConnection, RestClient::SSLCertificateNotVerified => e
81
73
  raise ResourceAccessException.new("Failed to access resource: #{e.message}")
@@ -0,0 +1,51 @@
1
+ unless RUBY_VERSION < '1.9'
2
+ require 'simplecov'
3
+
4
+ # Patch to get correct coverage count, filed
5
+ # https://github.com/colszowka/simplecov/issues/146 upstream.
6
+ class SimpleCov::Result
7
+ def missed_lines
8
+ return @missed_lines if defined? @missed_lines
9
+ @missed_lines = 0
10
+ @files.each do |file|
11
+ @missed_lines += file.missed_lines.count
12
+ end
13
+ @missed_lines
14
+ end
15
+ end
16
+
17
+ original_stderr = $stderr # in case helpers don't properly cleanup
18
+ SimpleCov.at_exit do
19
+ SimpleCov.result.format!
20
+ if SimpleCov.result.covered_percent < 100.0
21
+ original_stderr.puts "Coverage not 100%, build failed."
22
+ exit 1
23
+ end
24
+ end
25
+
26
+ SimpleCov.start do
27
+ coverage_dir 'coverage/spec/'
28
+
29
+ # Filters - these files will be ignored.
30
+ add_filter 'lib/rhc/vendor/' # vendored files should be taken directly and only
31
+ # namespaces changed
32
+ add_filter 'lib/rhc-rest/' # REST coverage is not yet 100%
33
+ add_filter 'lib/bin/' # This is just for safety; simplecov isn't picking these up.
34
+ add_filter 'lib/rhc-common.rb' # deprecated, functionality moved into client or rhc/helpers.rb
35
+ add_filter 'features/' # Don't report on the files that run the cucumber tests
36
+ add_filter 'lib/rhc-feature-coverage-helper.rb'
37
+ add_filter 'spec/' # Don't report on the files that run the spec tests
38
+
39
+ # Groups - general categories of test areas
40
+ add_group('Commands') { |src_file| src_file.filename.include?(File.join(%w[lib rhc commands])) }
41
+ add_group('RHC Lib') { |src_file| src_file.filename.include?(File.join(%w[lib rhc])) }
42
+ add_group('REST') { |src_file| src_file.filename.include?(File.join(%w[lib rhc-rest])) }
43
+ add_group('Legacy') { |src_file| src_file.filename.include?(File.join(%w[bin])) or
44
+ src_file.filename.include?(File.join(%w[lib rhc-common.rb])) }
45
+ add_group('Test') { |src_file| src_file.filename.include?(File.join(%w[features])) or
46
+ src_file.filename.include?(File.join(%w[spec])) }
47
+
48
+ # Note, the #:nocov: coverage exclusion should only be used on external functions
49
+ # that cannot be nondestructively tested in a developer environment.
50
+ end
51
+ end