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.
- data/README.md +27 -1
- data/bin/rhc +15 -23
- data/bin/rhc-app +4 -1
- data/bin/rhc-chk +3 -0
- data/bin/rhc-create-app +3 -0
- data/bin/rhc-create-domain +3 -0
- data/bin/rhc-ctl-app +3 -0
- data/bin/rhc-ctl-domain +3 -0
- data/bin/rhc-domain +5 -2
- data/bin/rhc-domain-info +3 -0
- data/bin/rhc-port-forward +16 -18
- data/bin/rhc-snapshot +3 -0
- data/bin/rhc-sshkey +3 -0
- data/bin/rhc-tail-files +3 -0
- data/bin/rhc-user-info +1 -0
- data/features/README.md +70 -0
- data/features/lib/rhc_helper/app.rb +124 -0
- data/features/lib/rhc_helper/cartridge.rb +72 -0
- data/features/lib/rhc_helper/commandify.rb +154 -0
- data/features/lib/rhc_helper/domain.rb +50 -0
- data/features/lib/rhc_helper/httpify.rb +107 -0
- data/features/lib/rhc_helper/loggable.rb +39 -0
- data/features/lib/rhc_helper/persistable.rb +38 -0
- data/features/lib/rhc_helper/runnable.rb +41 -0
- data/features/lib/rhc_helper.rb +7 -0
- data/features/step_definitions/application_steps.rb +99 -0
- data/features/step_definitions/cartridge_steps.rb +42 -0
- data/features/step_definitions/client_steps.rb +32 -0
- data/features/step_definitions/domain_steps.rb +19 -0
- data/features/support/env.rb +99 -0
- data/features/verify.feature +123 -0
- data/lib/rhc/cli.rb +4 -1
- data/lib/rhc/commands/base.rb +28 -6
- data/lib/rhc/commands/server.rb +4 -1
- data/lib/rhc/commands/setup.rb +24 -0
- data/lib/rhc/commands.rb +10 -5
- data/lib/rhc/config.rb +90 -21
- data/lib/rhc/core_ext.rb +11 -2
- data/lib/rhc/coverage_helper.rb +35 -0
- data/lib/rhc/help_formatter.rb +30 -0
- data/lib/rhc/helpers.rb +41 -5
- data/lib/rhc/ssh_key_helpers.rb +72 -0
- data/lib/rhc/targz.rb +2 -8
- data/lib/rhc/wizard.rb +75 -58
- data/lib/rhc-common.rb +20 -13
- data/lib/rhc-rest.rb +3 -11
- data/spec/coverage_helper.rb +51 -0
- data/spec/rest_spec_helper.rb +86 -0
- data/spec/rhc/cli_spec.rb +19 -3
- data/spec/rhc/commands/server_spec.rb +2 -2
- data/spec/rhc/common_spec.rb +49 -0
- data/spec/rhc/config_spec.rb +328 -0
- data/spec/rhc/helpers_spec.rb +74 -1
- data/spec/rhc/rest_client_spec.rb +402 -0
- data/spec/rhc/rest_spec.rb +454 -0
- data/spec/rhc/targz_spec.rb +13 -0
- data/spec/rhc/wizard_spec.rb +305 -43
- data/spec/spec_helper.rb +30 -25
- metadata +124 -5
@@ -0,0 +1,99 @@
|
|
1
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
2
|
+
require 'rhc/coverage_helper'
|
3
|
+
SimpleCov.at_exit do
|
4
|
+
SimpleCov.result.format!
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rhc_helper'
|
8
|
+
require 'rhc-rest'
|
9
|
+
require 'rhc/config'
|
10
|
+
|
11
|
+
# Generate a random username in case one isn't set
|
12
|
+
chars = ("1".."9").to_a
|
13
|
+
random_username = "test" + Array.new(8, '').collect{chars[rand(chars.size)]}.join + "@example.com"
|
14
|
+
|
15
|
+
ENV["PATH"] = "#{ENV['RHC_LOCAL_PATH']}:#{ENV['PATH']}" if ENV['RHC_LOCAL_PATH']
|
16
|
+
|
17
|
+
# Generate a random username if one isn't specified (for unauthenticated systems)
|
18
|
+
$username = ENV['RHC_USERNAME'] || random_username
|
19
|
+
|
20
|
+
# Use a generic password if one isn't specific (for unauthenticated systems)
|
21
|
+
$password = ENV['RHC_PASSWORD'] || 'test'
|
22
|
+
|
23
|
+
# Default the domain to production unless a random username is used.
|
24
|
+
# In that case, use dev.rhcloud.com for the development DNS namespace
|
25
|
+
default_domain = ENV['RHC_USERNAME'] ? "rhcloud.com" : "dev.rhcloud.com"
|
26
|
+
$domain = ENV['RHC_DOMAIN'] || default_domain
|
27
|
+
|
28
|
+
# Default the endpoint to the production REST API's
|
29
|
+
$end_point = ENV['RHC_ENDPOINT'] || "https://openshift.redhat.com/broker/rest/api"
|
30
|
+
|
31
|
+
# Don't default the namespace to anything - the existance if checked to
|
32
|
+
# determine how the setup wizard is run
|
33
|
+
$namespace = ENV['RHC_NAMESPACE']
|
34
|
+
|
35
|
+
raise "Username not found in environment (RHC_USERNAME)" unless $username
|
36
|
+
raise "Password not found in environment (RHC_PASSWORD)" unless $password
|
37
|
+
|
38
|
+
puts "\n\n"
|
39
|
+
puts "--------------------------------------------------------------------------------------------------"
|
40
|
+
puts " Test Information"
|
41
|
+
puts "--------------------------------------------------------------------------------------------------"
|
42
|
+
puts " REST End Point: #{$end_point}"
|
43
|
+
puts " Domain: #{$domain}"
|
44
|
+
puts " Username: #{$username}"
|
45
|
+
puts " Creating New Namespace: #{$namespace.nil?}"
|
46
|
+
puts "--------------------------------------------------------------------------------------------------"
|
47
|
+
puts "\n\n"
|
48
|
+
|
49
|
+
unless ENV['NO_CLEAN']
|
50
|
+
puts "--------------------------------------------------------------------------------------------------"
|
51
|
+
puts " Resetting environment"
|
52
|
+
puts "--------------------------------------------------------------------------------------------------"
|
53
|
+
# Start with a clean config
|
54
|
+
puts " Replacing express.conf with the specified libra_server"
|
55
|
+
File.open(RHC::Config::local_config_path, 'w') {|f| f.write("libra_server=#{URI.parse($end_point).host}") }
|
56
|
+
|
57
|
+
puts " Cleaning up test applications..."
|
58
|
+
FileUtils.rm_rf RHCHelper::TEMP_DIR
|
59
|
+
|
60
|
+
# Cleanup all test applications
|
61
|
+
client = Rhc::Rest::Client.new($end_point, $username, $password)
|
62
|
+
client.domains.each do |domain|
|
63
|
+
domain.applications.each do |app|
|
64
|
+
if app.name.start_with?("test")
|
65
|
+
puts " Deleting application #{app.name}"
|
66
|
+
app.delete
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
puts " Application cleanup complete"
|
72
|
+
puts "--------------------------------------------------------------------------------------------------"
|
73
|
+
puts "\n\n"
|
74
|
+
end
|
75
|
+
|
76
|
+
AfterConfiguration do |config|
|
77
|
+
# Create the temporary space
|
78
|
+
FileUtils.mkdir_p RHCHelper::TEMP_DIR
|
79
|
+
|
80
|
+
# Persist the username used for the tests - in case it was auto-generated
|
81
|
+
File.open(File.join(RHCHelper::TEMP_DIR, 'username'), 'w') {|f| f.write($username)}
|
82
|
+
|
83
|
+
# Setup the logger
|
84
|
+
logger = Logger.new(File.join(RHCHelper::TEMP_DIR, "cucumber.log"))
|
85
|
+
logger.level = Logger::DEBUG
|
86
|
+
RHCHelper::Loggable.logger = logger
|
87
|
+
|
88
|
+
# Setup performance monitor logger
|
89
|
+
perf_logger = Logger.new(File.join(RHCHelper::TEMP_DIR, "perfmon.log"))
|
90
|
+
perf_logger.level = Logger::INFO
|
91
|
+
RHCHelper::Loggable.perf_logger = perf_logger
|
92
|
+
end
|
93
|
+
|
94
|
+
After do |s|
|
95
|
+
# Tell Cucumber to quit after this scenario is done - if it failed.
|
96
|
+
Cucumber.wants_to_quit = true if s.failed?
|
97
|
+
end
|
98
|
+
|
99
|
+
World(RHCHelper)
|
@@ -0,0 +1,123 @@
|
|
1
|
+
Feature: Client Integration Tests
|
2
|
+
@init
|
3
|
+
Scenario: Setup Wizard
|
4
|
+
Given the libra client tools
|
5
|
+
When the setup wizard is run
|
6
|
+
Then the client tools should be setup
|
7
|
+
|
8
|
+
@init
|
9
|
+
Scenario: Domain Creation
|
10
|
+
Given the libra client tools
|
11
|
+
When a new domain is needed and created
|
12
|
+
Then the domain should be reserved
|
13
|
+
|
14
|
+
@init
|
15
|
+
Scenario: Application Creation
|
16
|
+
Given the libra client tools
|
17
|
+
When 1 php-5.3 applications are created
|
18
|
+
Then the applications should be accessible
|
19
|
+
|
20
|
+
Scenario: Application Stopping
|
21
|
+
Given the libra client tools
|
22
|
+
And an existing php-5.3 application
|
23
|
+
When the application is stopped
|
24
|
+
Then the application should not be accessible
|
25
|
+
|
26
|
+
Scenario: Application Starting
|
27
|
+
Given the libra client tools
|
28
|
+
And an existing php-5.3 application
|
29
|
+
When the application is started
|
30
|
+
Then the application should be accessible
|
31
|
+
|
32
|
+
Scenario: Application Restarting
|
33
|
+
Given the libra client tools
|
34
|
+
And an existing php-5.3 application
|
35
|
+
When the application is restarted
|
36
|
+
Then the application should be accessible
|
37
|
+
|
38
|
+
Scenario: Application Snapshot
|
39
|
+
Given the libra client tools
|
40
|
+
And an existing php-5.3 application
|
41
|
+
When the application is snapshot
|
42
|
+
Then the snapshot should be found
|
43
|
+
|
44
|
+
Scenario: Application Tidy
|
45
|
+
Given the libra client tools
|
46
|
+
And an existing php-5.3 application
|
47
|
+
When the application is tidied
|
48
|
+
Then it should succeed
|
49
|
+
|
50
|
+
Scenario: Application Show
|
51
|
+
Given the libra client tools
|
52
|
+
And an existing php-5.3 application
|
53
|
+
When the application is shown
|
54
|
+
Then it should succeed
|
55
|
+
|
56
|
+
Scenario: Cartridge Add
|
57
|
+
Given the libra client tools
|
58
|
+
And an existing php-5.3 application
|
59
|
+
When the mysql-5.1 cartridge is added
|
60
|
+
Then the mysql-5.1 cartridge should be running
|
61
|
+
|
62
|
+
Scenario: Cartridge Stop
|
63
|
+
Given the libra client tools
|
64
|
+
And an existing php-5.3 application with an embedded mysql-5.1 cartridge
|
65
|
+
When the mysql-5.1 cartridge is stopped
|
66
|
+
Then the mysql-5.1 cartridge should be stopped
|
67
|
+
|
68
|
+
Scenario: Cartridge Start
|
69
|
+
Given the libra client tools
|
70
|
+
And an existing php-5.3 application with an embedded mysql-5.1 cartridge
|
71
|
+
When the mysql-5.1 cartridge is started
|
72
|
+
Then the mysql-5.1 cartridge should be running
|
73
|
+
|
74
|
+
Scenario: Cartridge Restart
|
75
|
+
Given the libra client tools
|
76
|
+
And an existing php-5.3 application with an embedded mysql-5.1 cartridge
|
77
|
+
When the mysql-5.1 cartridge is restarted
|
78
|
+
Then the mysql-5.1 cartridge should be running
|
79
|
+
|
80
|
+
Scenario: Supporting Cartridge Added
|
81
|
+
Given the libra client tools
|
82
|
+
And an existing php-5.3 application with an embedded mysql-5.1 cartridge
|
83
|
+
When the phpmyadmin-3.4 cartridge is added
|
84
|
+
Then the phpmyadmin-3.4 cartridge should be running
|
85
|
+
|
86
|
+
Scenario: Conflicting Cartridge Fails
|
87
|
+
Given the libra client tools
|
88
|
+
And an existing php-5.3 application with embedded mysql-5.1 and phpmyadmin-3.4 cartridges
|
89
|
+
Then adding the postgresql-8.5 cartridge should fail
|
90
|
+
|
91
|
+
Scenario: Cartridge Removed
|
92
|
+
Given the libra client tools
|
93
|
+
And an existing php-5.3 application with embedded mysql-5.1 and phpmyadmin-3.4 cartridges
|
94
|
+
When the phpmyadmin-3.4 cartridge is removed
|
95
|
+
When the mysql-5.1 cartridge is removed
|
96
|
+
Then the phpmyadmin-3.4 cartridge should be removed
|
97
|
+
Then the mysql-5.1 cartridge should be removed
|
98
|
+
|
99
|
+
Scenario: Add Alias
|
100
|
+
Scenario: Remove Alias
|
101
|
+
|
102
|
+
Scenario: Application Destroy
|
103
|
+
Given the libra client tools
|
104
|
+
And an existing php-5.3 application
|
105
|
+
When the application is destroyed
|
106
|
+
Then the application should not be accessible
|
107
|
+
|
108
|
+
@init
|
109
|
+
Scenario: Template Creation
|
110
|
+
Scenario: Domain Changed
|
111
|
+
Scenario: Template Deleted
|
112
|
+
Scenario: Domain Changed Again
|
113
|
+
Scenario: Domain Deleted
|
114
|
+
|
115
|
+
@init
|
116
|
+
Scenario: Key Added
|
117
|
+
Scenario: Additional Key Added
|
118
|
+
Scenario: Default Key Deleted
|
119
|
+
Scenario: Key Overwritten
|
120
|
+
Scenario: Key Deleted
|
121
|
+
|
122
|
+
@init
|
123
|
+
Scenario: Get Server Status
|
data/lib/rhc/cli.rb
CHANGED
@@ -3,6 +3,7 @@ require 'commander'
|
|
3
3
|
require 'commander/runner'
|
4
4
|
require 'commander/delegates'
|
5
5
|
require 'rhc/commands'
|
6
|
+
require 'rhc/help_formatter'
|
6
7
|
|
7
8
|
include Commander::UI
|
8
9
|
include Commander::UI::AskForClass
|
@@ -25,11 +26,13 @@ module RHC
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def self.start(args)
|
28
|
-
|
29
|
+
runner = Commander::Runner.new(args)
|
30
|
+
Commander::Runner.instance_variable_set :@singleton, runner
|
29
31
|
|
30
32
|
program :name, 'rhc'
|
31
33
|
program :version, '0.0.0' #FIXME pull from versions.rb
|
32
34
|
program :description, 'Command line interface for OpenShift.'
|
35
|
+
program :help_formatter, RHC::UsageHelpFormatter
|
33
36
|
|
34
37
|
RHC::Commands.load.to_commander
|
35
38
|
exit(run! || 0)
|
data/lib/rhc/commands/base.rb
CHANGED
@@ -4,15 +4,15 @@ require 'rhc/helpers'
|
|
4
4
|
|
5
5
|
class RHC::Commands::Base
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(args=[], options={})
|
10
|
-
@args, @options = args, options
|
7
|
+
def initialize(command=nil, args=[], options=OptionParser.new)
|
8
|
+
@command, @args, @options = command, args, options
|
11
9
|
end
|
12
10
|
|
13
11
|
protected
|
14
12
|
include RHC::Helpers
|
15
13
|
|
14
|
+
attr_reader :command, :args, :options
|
15
|
+
|
16
16
|
def application
|
17
17
|
#@application ||= ... identify current application or throw,
|
18
18
|
# indicating one is needed. Should check
|
@@ -33,6 +33,15 @@ class RHC::Commands::Base
|
|
33
33
|
# object).
|
34
34
|
end
|
35
35
|
|
36
|
+
def config
|
37
|
+
@config ||= begin
|
38
|
+
RHC::Config.set_opts_config(options.config) if options.config
|
39
|
+
RHC::Config.password = options.password if options.password
|
40
|
+
RHC::Config.opts_login = options.rhlogin if options.rhlogin
|
41
|
+
RHC::Config
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
36
45
|
class InvalidCommand < StandardError ; end
|
37
46
|
|
38
47
|
def self.inherited(klass)
|
@@ -49,11 +58,12 @@ class RHC::Commands::Base
|
|
49
58
|
name = [method_name]
|
50
59
|
name.unshift(self.object_name).compact!
|
51
60
|
raise InvalidCommand, "Either object_name must be set or a non default method defined" if name.empty?
|
52
|
-
RHC::Commands.add({
|
61
|
+
RHC::Commands.add((@options || {}).merge({
|
53
62
|
:name => name.join(' '),
|
54
63
|
:class => self,
|
55
64
|
:method => method,
|
56
|
-
});
|
65
|
+
}));
|
66
|
+
@options = nil
|
57
67
|
end
|
58
68
|
|
59
69
|
def self.object_name(value=nil)
|
@@ -64,4 +74,16 @@ class RHC::Commands::Base
|
|
64
74
|
value.to_s.downcase if value
|
65
75
|
end
|
66
76
|
end
|
77
|
+
|
78
|
+
def self.description(value)
|
79
|
+
options[:description] = value
|
80
|
+
end
|
81
|
+
def self.summary(value)
|
82
|
+
options[:summary] = value
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def self.options
|
87
|
+
@options ||= {}
|
88
|
+
end
|
67
89
|
end
|
data/lib/rhc/commands/server.rb
CHANGED
@@ -2,8 +2,11 @@ require 'rhc/commands/base'
|
|
2
2
|
|
3
3
|
module RHC::Commands
|
4
4
|
class Server < Base
|
5
|
+
|
6
|
+
summary "Display information about the status of the OpenShift service."
|
7
|
+
description "Retrieves any open issues or notices about the operation of the OpenShift service and displays them in the order they were opened."
|
5
8
|
def run
|
6
|
-
status = decode_json(RestClient.get("
|
9
|
+
status = decode_json(RestClient.get("#{openshift_url}/app/status/status.json").body)
|
7
10
|
open = status['open']
|
8
11
|
|
9
12
|
(success 'All systems running fine' and return 0) if open.blank?
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rhc/commands/base'
|
2
|
+
require 'rhc/wizard'
|
3
|
+
require 'rhc/config'
|
4
|
+
|
5
|
+
module RHC::Commands
|
6
|
+
class Setup < Base
|
7
|
+
|
8
|
+
summary "Runs the setup wizard to configure your OpenShift account."
|
9
|
+
|
10
|
+
def run
|
11
|
+
# TODO: make help subcommand global
|
12
|
+
if @args.include? 'help'
|
13
|
+
say Commander::Runner.instance.help_formatter.render_command(@command)
|
14
|
+
return 0
|
15
|
+
end
|
16
|
+
|
17
|
+
w = RHC::RerunWizard.new(config.config_path)
|
18
|
+
s = w.run
|
19
|
+
|
20
|
+
# exit 0 on success 1 otherwise
|
21
|
+
s ? 0 : 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/rhc/commands.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'rhc/config'
|
2
|
-
|
3
1
|
module RHC
|
4
2
|
module Commands
|
5
3
|
def self.load
|
@@ -11,13 +9,17 @@ module RHC
|
|
11
9
|
def self.add(opts)
|
12
10
|
commands[opts[:name]] = opts
|
13
11
|
end
|
12
|
+
def self.global_option(*args)
|
13
|
+
global_options << args
|
14
|
+
end
|
14
15
|
def self.to_commander(instance=Commander::Runner.instance)
|
16
|
+
global_options.each{ |args| instance.global_option *args }
|
15
17
|
commands.each_pair do |name, opts|
|
16
18
|
instance.command name do |c|
|
17
|
-
c.
|
19
|
+
c.description = opts[:description]
|
20
|
+
c.summary = opts[:summary]
|
18
21
|
c.when_called do |args, options|
|
19
|
-
|
20
|
-
opts[:class].new(args, options).send(opts[:method])
|
22
|
+
opts[:class].new(c, args, options).send(opts[:method])
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -28,5 +30,8 @@ module RHC
|
|
28
30
|
def self.commands
|
29
31
|
@commands ||= {}
|
30
32
|
end
|
33
|
+
def self.global_options
|
34
|
+
@options ||= []
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
data/lib/rhc/config.rb
CHANGED
@@ -3,37 +3,65 @@ require 'rhc/core_ext'
|
|
3
3
|
|
4
4
|
module RHC
|
5
5
|
module Config
|
6
|
-
|
6
|
+
# FIXME: Config shouldn't really exit
|
7
|
+
# stub this out for now so we can test it
|
8
|
+
def self.exit(code)
|
9
|
+
# :nocov:
|
10
|
+
Kernel.exit(code)
|
11
|
+
# :nocov:
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.read_config_files
|
15
|
+
@@global_config = RHC::Vendor::ParseConfig.new(@@global_config_path) if File.exists?(@@global_config_path)
|
16
|
+
@@local_config = RHC::Vendor::ParseConfig.new(File.expand_path(@@local_config_path)) if File.exists?(@@local_config_path)
|
17
|
+
rescue Errno::EACCES => e
|
18
|
+
say "Could not open config file: #{e.message}"
|
19
|
+
exit 253
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.set_defaults
|
7
23
|
@@defaults = RHC::Vendor::ParseConfig.new()
|
8
24
|
@@global_config = nil
|
9
25
|
@@local_config = nil
|
10
|
-
@@opts_config = nil
|
26
|
+
@@opts_config = nil # config file passed in the options
|
27
|
+
@@opts = RHC::Vendor::ParseConfig.new() # option switches that override config file
|
11
28
|
@@default_proxy = nil
|
12
29
|
@@env_config = RHC::Vendor::ParseConfig.new()
|
13
30
|
|
14
31
|
@@defaults.add('libra_server', 'openshift.redhat.com')
|
15
32
|
@@env_config.add('libra_server', ENV['LIBRA_SERVER']) if ENV['LIBRA_SERVER']
|
16
|
-
|
17
33
|
#
|
18
34
|
# Config paths... /etc/openshift/express.conf or $GEM/conf/express.conf -> ~/.openshift/express.conf
|
19
35
|
#
|
20
|
-
|
21
36
|
@@conf_name = 'express.conf'
|
22
|
-
_linux_cfg = '/etc/openshift/' + @@conf_name
|
23
|
-
_gem_cfg = File.join(File.expand_path(File.dirname(__FILE__) + "/../../conf"), @@conf_name)
|
24
|
-
|
25
|
-
config_path = File.exists?(_linux_cfg) ? _linux_cfg : _gem_cfg
|
26
37
|
@@home_dir = File.expand_path("~")
|
27
38
|
@@home_conf_path = File.join(@@home_dir, '.openshift')
|
28
39
|
@@local_config_path = File.join(@@home_conf_path, @@conf_name)
|
29
40
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
# config path passed in on the command line
|
42
|
+
@@opts_config_path = nil
|
43
|
+
|
44
|
+
# authoritive config path
|
45
|
+
# this can be @@local_config_path or @@opts_config_path
|
46
|
+
# @@opts_config_path trumps
|
47
|
+
# this is used to determine where config options should be written to
|
48
|
+
# when a script modifies the config such as in rhc setup
|
49
|
+
@@config_path = @@local_config_path
|
50
|
+
|
51
|
+
@@ssh_priv_key_file_path = "#{@@home_dir}/.ssh/id_rsa"
|
52
|
+
@@ssh_pub_key_file_path = "#{@@home_dir}/.ssh/id_rsa.pub"
|
53
|
+
|
54
|
+
@@_linux_cfg = '/etc/openshift/' + @@conf_name
|
55
|
+
@@global_config_path = @@_linux_cfg
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.initialize
|
59
|
+
set_defaults
|
60
|
+
|
61
|
+
_gem_cfg = File.join(File.expand_path(File.dirname(__FILE__) + "/../../conf"), @@conf_name)
|
62
|
+
@@global_config_path = File.exists?(@@_linux_cfg) ? @@_linux_cfg : _gem_cfg
|
63
|
+
|
64
|
+
read_config_files
|
37
65
|
end
|
38
66
|
|
39
67
|
self.initialize
|
@@ -43,11 +71,17 @@ module RHC
|
|
43
71
|
@@home_dir=home_dir
|
44
72
|
@@home_conf_path = File.join(@@home_dir, '.openshift')
|
45
73
|
@@local_config_path = File.join(@@home_conf_path, @@conf_name)
|
74
|
+
@@local_config = nil
|
75
|
+
@@local_config = RHC::Vendor::ParseConfig.new(File.expand_path(@@local_config_path)) if File.exists?(@@local_config_path)
|
76
|
+
@@ssh_priv_key_file_path = "#{@@home_dir}/.ssh/id_rsa"
|
77
|
+
@@ssh_pub_key_file_path = "#{@@home_dir}/.ssh/id_rsa.pub"
|
46
78
|
end
|
47
79
|
|
48
80
|
def self.[](key)
|
81
|
+
raise KeyError("Please use RHC::Config.password to access the password config") if key == "password"
|
82
|
+
|
49
83
|
# evaluate in cascading order
|
50
|
-
configs = [@@opts_config, @@env_config, @@local_config, @@global_config, @@defaults]
|
84
|
+
configs = [@@opts, @@opts_config, @@env_config, @@local_config, @@global_config, @@defaults]
|
51
85
|
result = nil
|
52
86
|
configs.each do |conf|
|
53
87
|
result = conf[key] if !conf.nil?
|
@@ -66,20 +100,37 @@ module RHC
|
|
66
100
|
@@defaults.add('default_rhlogin', username)
|
67
101
|
end
|
68
102
|
|
103
|
+
def self.opts_login=(username)
|
104
|
+
@@opts.add('default_rhlogin', username)
|
105
|
+
end
|
106
|
+
|
107
|
+
# password is not allowed in config files and can only be passed on comman line
|
108
|
+
def self.password=(password)
|
109
|
+
@@opts.add('password', password)
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.password
|
113
|
+
@@opts['password']
|
114
|
+
end
|
115
|
+
|
69
116
|
def self.set_local_config(confpath)
|
70
117
|
begin
|
71
|
-
@@
|
118
|
+
@@local_config_path = File.expand_path(confpath)
|
119
|
+
@@config_path = @@local_config_path if @@opts_config_path.nil?
|
120
|
+
@@local_config = RHC::Vendor::ParseConfig.new(@@local_config_path)
|
72
121
|
rescue Errno::EACCES => e
|
73
|
-
|
122
|
+
say "Could not open config file: #{e.message}"
|
74
123
|
exit 253
|
75
124
|
end
|
76
125
|
end
|
77
126
|
|
78
127
|
def self.set_opts_config(confpath)
|
79
128
|
begin
|
80
|
-
@@
|
129
|
+
@@opts_config_path = File.expand_path(confpath)
|
130
|
+
@@config_path = @@opts_config_path
|
131
|
+
@@opts_config = RHC::Vendor::ParseConfig.new(@@opts_config_path) if File.exists?(@@opts_config_path)
|
81
132
|
rescue Errno::EACCES => e
|
82
|
-
|
133
|
+
say "Could not open config file: #{e.message}"
|
83
134
|
exit 253
|
84
135
|
end
|
85
136
|
end
|
@@ -88,7 +139,7 @@ module RHC
|
|
88
139
|
unless opts["config"].nil?
|
89
140
|
opts_config_path = File.expand_path(opts["config"])
|
90
141
|
if !File.readable?(opts_config_path)
|
91
|
-
|
142
|
+
say "Could not open config file: #{@opts_config_path}"
|
92
143
|
exit 253
|
93
144
|
else
|
94
145
|
set_opts_config(opts_config_path)
|
@@ -113,6 +164,20 @@ module RHC
|
|
113
164
|
not (has_local_config? or has_opts_config?)
|
114
165
|
end
|
115
166
|
|
167
|
+
def self.should_run_ssh_wizard?
|
168
|
+
not File.exists? @@ssh_priv_key_file_path
|
169
|
+
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# config_path
|
173
|
+
#
|
174
|
+
# authoritive configuration path
|
175
|
+
# this is used to determine where config options should be written to
|
176
|
+
# when a script modifies the config such as in rhc setup
|
177
|
+
def self.config_path
|
178
|
+
@@config_path
|
179
|
+
end
|
180
|
+
|
116
181
|
def self.local_config_path
|
117
182
|
@@local_config_path
|
118
183
|
end
|
@@ -125,6 +190,10 @@ module RHC
|
|
125
190
|
@@home_dir
|
126
191
|
end
|
127
192
|
|
193
|
+
def self.ssh_pub_key_file_path
|
194
|
+
@@ssh_pub_key_file_path
|
195
|
+
end
|
196
|
+
|
128
197
|
def self.default_rhlogin
|
129
198
|
get_value('default_rhlogin')
|
130
199
|
end
|
data/lib/rhc/core_ext.rb
CHANGED
@@ -9,7 +9,16 @@ class Object
|
|
9
9
|
respond_to?(:empty?) ? empty? : !self
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
# Avoid a conflict if to_json is already defined
|
13
|
+
unless Object.new.respond_to? :to_json
|
14
|
+
def to_json(options=nil)
|
15
|
+
RHC::Json.encode(self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class File
|
21
|
+
def chunk(chunk_size=1024)
|
22
|
+
yield read(chunk_size) until eof?
|
14
23
|
end
|
15
24
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Must be the first module imported at entry points (executables that run
|
2
|
+
# in seperate processes from the test harness) otherwise coverage will be
|
3
|
+
# incomplete
|
4
|
+
|
5
|
+
if RUBY_VERSION >= '1.9' and ENV['RHC_FEATURE_COVERAGE']
|
6
|
+
require 'simplecov'
|
7
|
+
SimpleCov.start do
|
8
|
+
coverage_dir 'coverage/features/'
|
9
|
+
command_name 'Cucumber Features'
|
10
|
+
|
11
|
+
# Filters - these files will be ignored.
|
12
|
+
add_filter 'lib/rhc/vendor/' # vendored files should be taken directly and only
|
13
|
+
# namespaces changed
|
14
|
+
add_filter 'features/' # Don't report on the files that run the cucumber tests
|
15
|
+
add_filter 'lib/rhc-feature-coverage-helper.rb'
|
16
|
+
add_filter 'spec/' # Don't report on the files that run the spec tests
|
17
|
+
|
18
|
+
# Groups - general categories of test areas
|
19
|
+
add_group('Commands') { |src_file| src_file.filename.include?(File.join(%w[lib rhc commands])) }
|
20
|
+
add_group('RHC Lib') { |src_file| src_file.filename.include?(File.join(%w[lib rhc])) }
|
21
|
+
add_group('REST') { |src_file| src_file.filename.include?(File.join(%w[lib rhc-rest])) }
|
22
|
+
add_group('Legacy') { |src_file| src_file.filename.include?(File.join(%w[bin])) or
|
23
|
+
src_file.filename.include?(File.join(%w[lib rhc-common.rb])) }
|
24
|
+
add_group('Test') { |src_file| src_file.filename.include?(File.join(%w[features])) or
|
25
|
+
src_file.filename.include?(File.join(%w[spec])) }
|
26
|
+
|
27
|
+
use_merging = true
|
28
|
+
# Note, the #:nocov: coverage exclusion should only be used on external functions
|
29
|
+
# that cannot be nondestructively tested in a developer environment.
|
30
|
+
end
|
31
|
+
|
32
|
+
# suppress output
|
33
|
+
SimpleCov.at_exit do
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'commander/help_formatters/base'
|
2
|
+
|
3
|
+
module RHC
|
4
|
+
class UsageHelpFormatter < Commander::HelpFormatter::Base
|
5
|
+
def global_options_output
|
6
|
+
result = "Global Options:\n"
|
7
|
+
@runner.options.each { |o|
|
8
|
+
result += o[:switches].join('|')
|
9
|
+
result += "\t#{o[:description]}\n"
|
10
|
+
}
|
11
|
+
result
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
# TODO: render the rhc usage when we move 100% to using Commander
|
16
|
+
result = "#{@runner.program(:name)} - #{@runner.program(:description)}\n\n"
|
17
|
+
result += global_options_output
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_command command
|
22
|
+
result = ""
|
23
|
+
result = "Usage: #{@runner.program(:name)} #{command.name}\n"
|
24
|
+
result += "#{command.summary}\n\n"
|
25
|
+
result += global_options_output
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# TODO: class ManPageHelpFormatter
|
30
|
+
end
|