rhc 1.14.7 → 1.15.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/autocomplete/rhc_bash +260 -124
  2. data/features/core_feature.rb +143 -0
  3. data/features/domains_feature.rb +49 -0
  4. data/features/members_feature.rb +131 -0
  5. data/lib/rhc/auth/token_store.rb +2 -0
  6. data/lib/rhc/command_runner.rb +7 -5
  7. data/lib/rhc/commands.rb +111 -68
  8. data/lib/rhc/commands/account.rb +3 -4
  9. data/lib/rhc/commands/alias.rb +10 -15
  10. data/lib/rhc/commands/app.rb +36 -64
  11. data/lib/rhc/commands/authorization.rb +1 -1
  12. data/lib/rhc/commands/base.rb +13 -8
  13. data/lib/rhc/commands/cartridge.rb +21 -29
  14. data/lib/rhc/commands/domain.rb +96 -47
  15. data/lib/rhc/commands/env.rb +11 -15
  16. data/lib/rhc/commands/git_clone.rb +2 -3
  17. data/lib/rhc/commands/member.rb +148 -0
  18. data/lib/rhc/commands/port_forward.rb +2 -3
  19. data/lib/rhc/commands/setup.rb +8 -8
  20. data/lib/rhc/commands/snapshot.rb +23 -20
  21. data/lib/rhc/commands/ssh.rb +12 -17
  22. data/lib/rhc/commands/tail.rb +2 -3
  23. data/lib/rhc/commands/threaddump.rb +2 -3
  24. data/lib/rhc/config.rb +1 -0
  25. data/lib/rhc/context_helper.rb +94 -19
  26. data/lib/rhc/core_ext.rb +6 -0
  27. data/lib/rhc/coverage_helper.rb +1 -1
  28. data/lib/rhc/exceptions.rb +24 -0
  29. data/lib/rhc/git_helpers.rb +5 -6
  30. data/lib/rhc/helpers.rb +23 -6
  31. data/lib/rhc/highline_extensions.rb +3 -2
  32. data/lib/rhc/output_helpers.rb +9 -6
  33. data/lib/rhc/rest.rb +1 -0
  34. data/lib/rhc/rest/application.rb +10 -4
  35. data/lib/rhc/rest/attributes.rb +4 -0
  36. data/lib/rhc/rest/base.rb +2 -1
  37. data/lib/rhc/rest/cartridge.rb +4 -0
  38. data/lib/rhc/rest/client.rb +41 -25
  39. data/lib/rhc/rest/domain.rb +29 -9
  40. data/lib/rhc/rest/membership.rb +105 -0
  41. data/lib/rhc/rest/mock.rb +45 -12
  42. data/lib/rhc/rest/user.rb +5 -1
  43. data/lib/rhc/ssh_helpers.rb +14 -0
  44. data/lib/rhc/usage_templates/command_syntax_help.erb +2 -0
  45. data/lib/rhc/wizard.rb +3 -3
  46. data/spec/coverage_helper.rb +31 -9
  47. data/spec/direct_execution_helper.rb +256 -0
  48. data/spec/rhc/command_spec.rb +86 -15
  49. data/spec/rhc/commands/account_spec.rb +2 -1
  50. data/spec/rhc/commands/alias_spec.rb +7 -0
  51. data/spec/rhc/commands/app_spec.rb +73 -90
  52. data/spec/rhc/commands/cartridge_spec.rb +61 -59
  53. data/spec/rhc/commands/domain_spec.rb +179 -43
  54. data/spec/rhc/commands/member_spec.rb +228 -0
  55. data/spec/rhc/commands/port_forward_spec.rb +7 -7
  56. data/spec/rhc/commands/snapshot_spec.rb +45 -24
  57. data/spec/rhc/commands/ssh_spec.rb +16 -3
  58. data/spec/rhc/commands/tail_spec.rb +1 -1
  59. data/spec/rhc/helpers_spec.rb +9 -0
  60. data/spec/rhc/rest_client_spec.rb +75 -7
  61. data/spec/rhc/rest_spec.rb +1 -1
  62. metadata +57 -107
  63. data/features/README.md +0 -198
  64. data/features/application.feature +0 -28
  65. data/features/cartridge.feature +0 -48
  66. data/features/client.feature +0 -11
  67. data/features/domain.feature +0 -30
  68. data/features/env.feature +0 -35
  69. data/features/geared_application.feature +0 -8
  70. data/features/lib/rhc_helper.rb +0 -21
  71. data/features/lib/rhc_helper/api.rb +0 -7
  72. data/features/lib/rhc_helper/app.rb +0 -137
  73. data/features/lib/rhc_helper/cartridge.rb +0 -97
  74. data/features/lib/rhc_helper/commandify.rb +0 -251
  75. data/features/lib/rhc_helper/domain.rb +0 -65
  76. data/features/lib/rhc_helper/env.rb +0 -29
  77. data/features/lib/rhc_helper/httpify.rb +0 -186
  78. data/features/lib/rhc_helper/loggable.rb +0 -37
  79. data/features/lib/rhc_helper/persistable.rb +0 -51
  80. data/features/lib/rhc_helper/runnable.rb +0 -55
  81. data/features/lib/rhc_helper/sshkey.rb +0 -33
  82. data/features/multiple_cartridge.feature +0 -19
  83. data/features/scaled_application.feature +0 -48
  84. data/features/sshkey.feature +0 -63
  85. data/features/step_definitions/application_steps.rb +0 -120
  86. data/features/step_definitions/cartridge_steps.rb +0 -95
  87. data/features/step_definitions/client_steps.rb +0 -41
  88. data/features/step_definitions/domain_steps.rb +0 -73
  89. data/features/step_definitions/env_steps.rb +0 -32
  90. data/features/step_definitions/sshkey_steps.rb +0 -56
  91. data/features/support/assumptions.rb +0 -49
  92. data/features/support/before_hooks.rb +0 -81
  93. data/features/support/env.rb +0 -208
  94. data/features/support/key1 +0 -27
  95. data/features/support/key1.pub +0 -1
  96. data/features/support/key2 +0 -27
  97. data/features/support/key2.pub +0 -1
  98. data/features/support/key3.pub +0 -1
  99. data/features/support/platform_support.rb +0 -29
  100. data/features/verify.feature +0 -18
  101. data/spec/rhc/context_spec.rb +0 -53
@@ -1,37 +0,0 @@
1
- require 'logger'
2
-
3
- module RHCHelper
4
- module Loggable
5
- def logger
6
- Loggable.logger
7
- end
8
-
9
- def perf_logger
10
- Loggable.perf_logger
11
- end
12
-
13
- def self.logger
14
- @logger ||= Logger.new($stdout)
15
- end
16
-
17
- def self.logger=(logger)
18
- @logger = logger
19
- original_formatter = Logger::Formatter.new
20
- @logger.formatter = proc { |severity, datetime, progname, msg|
21
- # Filter out any passwords
22
- #filter_msg = msg.gsub(PASSWORD_REGEX, " -p ***** ")
23
-
24
- # Format with the original formatter
25
- original_formatter.call(severity, datetime, progname, msg)
26
- }
27
- end
28
-
29
- def self.perf_logger
30
- @perf_logger ||= Logger.new($stdout)
31
- end
32
-
33
- def self.perf_logger=(logger)
34
- @perf_logger = logger
35
- end
36
- end
37
- end
@@ -1,51 +0,0 @@
1
- require 'active_support/json'
2
- require 'active_support/core_ext/object/to_json'
3
-
4
- module RHCHelper
5
- module Persistable
6
- include ActiveSupport::JSON
7
- include Loggable
8
-
9
- def find_on_fs(options = {})
10
- # Find all apps
11
- apps = Dir.glob("#{RHCHelper::TEMP_DIR}/*.json").collect {|f| App.from_file(f)}
12
-
13
- if options.empty?
14
- apps.first
15
- else
16
- apps.find do |app|
17
- # Loop through all options and then run AND on all of the results
18
- options.map{|name,expected| app.send(name) == expected }.inject(&:&)
19
- end
20
- end
21
- end
22
-
23
- def from_file(filename)
24
- App.from_json(ActiveSupport::JSON.decode(File.open(filename, "r") {|f| f.readlines}[0]))
25
- end
26
-
27
- def from_json(json)
28
- app = App.new(json['type'], json['name'], json['scalable'])
29
- app.embed = json['embed']
30
- app.mysql_user = json['mysql_user']
31
- app.mysql_password = json['mysql_password']
32
- app.mysql_hostname = json['mysql_hostname']
33
- app.uid = json['uid']
34
- # Strip off any version info for the type
35
- app.type = app.type.split('-').first
36
-
37
- app
38
- end
39
- end
40
-
41
- module Persistify
42
- include ActiveSupport::JSON
43
-
44
- attr_accessor :file
45
-
46
- def persist
47
- json = self.to_json(:except => [:logger, :perf_logger])
48
- File.open(@file, "w") {|f| f.puts json}
49
- end
50
- end
51
- end
@@ -1,55 +0,0 @@
1
- require 'open4'
2
- require 'timeout'
3
-
4
- module RHCHelper
5
- module Runnable
6
- include Loggable
7
-
8
- class StringTee < StringIO
9
- attr_reader :tee
10
- def initialize(other)
11
- @tee = other
12
- super()
13
- end
14
- def <<(buf)
15
- tee << buf
16
- super
17
- end
18
- end
19
-
20
- def iconv_handler
21
- @iconv ||= Iconv.new('UTF-8//IGNORE', 'UTF-8')
22
- end
23
-
24
- def run(cmd, arg=nil, input=[])
25
- logger.info("Running: #{cmd} #{arg}")
26
-
27
- exit_code = -1
28
- output = nil
29
-
30
- # Don't let a command run more than 5 minutes
31
- Timeout::timeout(240) do
32
-
33
- stdout, stderr = (ENV['VERBOSE'] ? [$stdout, $stderr] : [logger, logger]).map{ |t| StringTee.new(t) }
34
- stdin = input.inject(StringIO.new){ |io, s| io.puts s; io }
35
- stdin.close_write
36
- stdin.rewind
37
- status = Open4.spawn(cmd, 'stdout' => stdout, 'stderr' => stderr, 'stdin' => stdin, 'quiet' => true)
38
- out, err = [stdout, stderr].map(&:string)
39
-
40
- stdout.close
41
- stderr.close
42
-
43
- # Allow a caller to pass in a block to process the output
44
- yield status.exitstatus, out, err, arg if block_given?
45
- exit_code = status.exitstatus
46
- end
47
-
48
- if exit_code != 0
49
- logger.error("(#{$$}): Execution failed #{cmd} with exit_code: #{exit_code.to_s}")
50
- end
51
-
52
- exit_code
53
- end
54
- end
55
- end
@@ -1,33 +0,0 @@
1
- require "rhc/rest"
2
-
3
- module RHCHelper
4
-
5
- class Sshkey
6
- extend Runnable
7
- extend Commandify
8
-
9
- class << self
10
- attr_accessor :sshkey_output, :exitcode
11
- end
12
-
13
- def self.list(*args)
14
- rhc_sshkey_list args
15
- end
16
-
17
- def self.show(*args)
18
- rhc_sshkey_show args
19
- end
20
-
21
- def self.add(*args)
22
- rhc_sshkey_add args
23
- end
24
-
25
- def self.remove(*args)
26
- rhc_sshkey_remove args
27
- end
28
-
29
- def self.keyfile_path(name)
30
- File.expand_path(File.join(File.dirname(__FILE__),'..','..','support',name))
31
- end
32
- end
33
- end
@@ -1,19 +0,0 @@
1
- @multiple_cartridge @domain_required @clean
2
- Feature: Multiple Cartridge Tests
3
-
4
- @init
5
- Scenario: Supporting Cartridge Added
6
- Given an existing or new php application with an embedded mysql cartridge
7
- When the phpmyadmin cartridge is added
8
- Then the phpmyadmin cartridge should be running
9
-
10
- @not-origin
11
- Scenario: Multiple DBs Allowed
12
- When the postgresql cartridge is added
13
- Then the postgresql cartridge should be running
14
-
15
- Scenario: Cartridge Removed
16
- When the phpmyadmin cartridge is removed
17
- When the mysql cartridge is removed
18
- Then the phpmyadmin cartridge should be removed
19
- Then the mysql cartridge should be removed
@@ -1,48 +0,0 @@
1
- @scaled_application @domain_required
2
- Feature: Scaled Application Operations
3
-
4
- @init
5
- Scenario: Scaled Application Creation
6
- When a scaled php application is created
7
- Then the application should be accessible
8
- Then the application should be scalable
9
-
10
- # The state in these examples should be able to be broken into before hooks when we update cucumber
11
- Scenario Outline: Running Scaled Application Commands
12
- Given we have a <state> application
13
- When the application is <command>
14
- Then <what> should <status>
15
-
16
- # Breaking these examples up so they can flow logically, but also be run individually
17
- Examples:
18
- | state | command | what | status |
19
- | running | restarted | the application | be accessible |
20
- | running | snapshot | the snapshot | be found |
21
- | running | tidied | it | succeed |
22
- | running | shown | it | succeed |
23
- | running | stopped | the application | not be accessible |
24
- | stopped | started | the application | be accessible |
25
- # After the app is deleted, it is resolving to the OpenShift server
26
- # I think it's because of US2108
27
- # TODO: This needs to be fixed by "not exist" checking DNS instead of HTTP
28
- | running | deleted | it | succeed |
29
-
30
- Scenario Outline: Changing Scaling Value
31
- When we are updating the <cart> cartridge
32
- And the <type> scaling value is set to <value>
33
- Then the <type> scaling value should be <value>
34
-
35
- Examples:
36
- | cart | type | value |
37
- | php | min | 1 |
38
- | php | max | 5 |
39
- | php | max | -1 |
40
-
41
- Scenario Outline: Invalid Scaling Values
42
- When we are updating the <cart> cartridge
43
- And the <type> scaling value is set to <value>
44
- Then it should fail with code <code>
45
-
46
- Examples:
47
- | cart | type | value | code |
48
- | php | min | a | 1 |
@@ -1,63 +0,0 @@
1
- @sshkey @client_tools_required
2
- Feature: SSH key Management
3
- As an OpenShift user, I want to manage SSH keys with 'rhc sshkey' commands.
4
-
5
- @sshkey_list @key1
6
- Scenario: SSH key is listed
7
- When a new SSH key "key1.pub" is added as "key1"
8
- And the existing keys are listed
9
- Then the output includes the key information
10
-
11
- @sshkey_show @key1
12
- Scenario: SSH key is shown individually
13
- When the key "key1" is shown
14
- Then the output includes the key information for "key1"
15
-
16
- @sshkey_show
17
- Scenario: Requested SSH key does not exist
18
- When the key "key2" is shown
19
- Then the command exits with status code 118
20
-
21
- @sshkey_add
22
- Scenario: SSH key is added successfully
23
- When a new SSH key "key1.pub" is added as "key1"
24
- And the key "key1" is shown
25
- Then the output includes the key information for "key1"
26
- And the command exits with status code 0
27
-
28
- @sshkey_add
29
- Scenario: invalid key name is given
30
- When a new SSH key "key1.pub" is added as "blah\\ss"
31
- Then the command exits with status code 1
32
-
33
- @sshkey_add
34
- Scenario: invalid SSH key is added
35
- When a new SSH key "key3.pub" is added as "key3"
36
- Then the command exits with status code 128
37
-
38
- @sshkey_add
39
- Scenario: a valid private SSH key is added
40
- When a new SSH key "key1" is added as "key1"
41
- Then the command exits with status code 128
42
-
43
- @sshkey_add @key1
44
- Scenario: SSH key with the same name already exists
45
- When a new SSH key "key2.pub" is added as "key1"
46
- Then the command exits with status code 1
47
-
48
- @sshkey_add
49
- Scenario: SSH key with the identical content already exists
50
- Given a new SSH key "key1.pub" is added as "key1"
51
- And a new SSH key "key1.pub" is added as "key2"
52
- Then the command exits with status code 1
53
-
54
- @sshkey_remove @key1
55
- Scenario: SSH key is deleted successfully
56
- When the key "key1" is removed
57
- And the key "key1" is shown
58
- Then the output does not include the key information for "key1"
59
-
60
- @sshkey_remove
61
- Scenario: SSH key requested to be deleted does not exist
62
- When the key "key1" is removed
63
- Then the command exits with status code 118
@@ -1,120 +0,0 @@
1
- require 'fileutils'
2
- require 'rhc/config'
3
-
4
- include RHCHelper
5
-
6
- # This can transform any application cartridge requirements into an array
7
- Transform /^application with(.*)$/ do |embed_type|
8
- case embed_type.strip
9
- when /^out an embedded cartridge/
10
- []
11
- when /^an embedded (.*) cartridge$/
12
- [$1]
13
- when /^embedded (.*) and (.*) cartridges$/
14
- [$1,$2]
15
- end
16
- end
17
-
18
- # Use the transformed array so we can reuse this step for all combinations
19
- Given /^an existing (or new )?(scaled )?(.+) (application with.*)$/ do |create, scaled, type, embeds|
20
- options = { :type => type }
21
- options[:embed] = embeds.map{ |c| map_cartridge_type(c) } if embeds
22
- options[:scalable] = scaled if scaled
23
- @app = App.find_on_fs(options)
24
-
25
- @app = nil if @app.nil? or not @app.is_created?
26
-
27
- if create && @app.nil?
28
- step "a #{scaled}#{type} application is created"
29
- embeds.each do |embed|
30
- step "the #{embed} cartridge is added"
31
- end
32
- end
33
-
34
- @app.should_not be_nil, "No existing %s applications %sfound. Check the creation scenarios for failures." % [
35
- type,
36
- embeds ? '' : "w/ [#{embeds.join(',')}]"
37
- ]
38
- end
39
-
40
- # Mark this step as pending so we make sure to explicitly require apps without embeds
41
- Given /^an existing (or new )?(.+) application$/ do |create,type|
42
- pending
43
- end
44
-
45
- When /^(\d+) (.+) applications are created$/ do |app_count, type|
46
- old_app = @app
47
- @apps = app_count.to_i.times.collect do
48
- step "a #{type} application is created"
49
- @app
50
- end
51
- @app = old_app
52
- end
53
-
54
- When /^a (scaled )?(.+) application is created(?: with a (.*) gear)?$/ do |scaled, type, gear_profile|
55
- type = map_cartridge_type(type)
56
- @app = App.create_unique(type, scaled, gear_profile)
57
- @app.rhc_app_create
58
- end
59
-
60
- When /^the application is (\w+)$/ do |command|
61
- # Do any pre-check setup we may need
62
- case command
63
- when 'snapshot'
64
- @snapshot = File.join(RHCHelper::TEMP_DIR, "snapshot.tar.gz")
65
- @app.snapshot = @snapshot
66
- end
67
-
68
- # Set up aliases for any irregular commands
69
- aliases = {
70
- :stopped => :stop,
71
- :shown => :show,
72
- :tidied => :tidy,
73
- :snapshot => :snapshot_save,
74
- :deleted => :delete,
75
- :visualized => :show_gears,
76
- }
77
-
78
- # Use an alias if it exists, or just remove 'ed' (like from started)
79
- cmd = aliases[command.to_sym] || command.gsub(/ed$/,'').to_sym
80
-
81
- # Send the specified command to the application
82
- @app.send("rhc_app_#{cmd}")
83
- end
84
-
85
- Then /^the snapshot should be found$/ do
86
- File.exist?(@snapshot).should be_true
87
- (File.size(@snapshot) > 0).should be_true
88
- end
89
-
90
- Then /^the applications should be accessible?$/ do
91
- old_app = @app
92
- @apps.each do |app|
93
- step "the application should be accessible"
94
- end
95
- @app = old_app
96
- end
97
-
98
- Then /^the application should be accessible$/ do
99
- @app.is_accessible?.should be_true
100
- @app.is_accessible?({:use_https => true}).should be_true, "Application was not accessible and should be"
101
- end
102
-
103
- Then /^the application should not be accessible$/ do
104
- @app.is_inaccessible?.should be_true, "Application was still accessible when it shouldn't be"
105
- end
106
-
107
- Then /^the application should not exist$/ do
108
- @app.doesnt_exist?.should be_true, "Application still exists when it shouldn't"
109
- end
110
-
111
- Then /^it should succeed$/ do
112
- end
113
-
114
- Then /^the application should be scalable/ do
115
- step "the haproxy cartridge should be running"
116
- end
117
-
118
- Then /^the application should have a (.*) gear$/ do |gear_profile|
119
- @app.gear_profile.should match("#{gear_profile}")
120
- end
@@ -1,95 +0,0 @@
1
- require 'fileutils'
2
- require 'rhc/config'
3
-
4
- include RHCHelper
5
-
6
- When /^the (.+) cartridge is added$/ do |name|
7
- name = map_cartridge_type(name)
8
- @app.add_cartridge name
9
- end
10
-
11
- When /^the (.+) cartridge is removed$/ do |name|
12
- name = map_cartridge_type(name)
13
- @app.remove_cartridge name
14
- end
15
-
16
- When /^the (.+) cartridge is (stopped|(?:re)?started)$/ do |name,command|
17
- name = map_cartridge_type(name)
18
- cmd = case command.to_sym
19
- when :stopped
20
- 'stop'
21
- when :started
22
- 'start'
23
- when :restarted
24
- 'restart'
25
- else
26
- raise "Unrecognized command type #{status}"
27
- end
28
- @app.cartridge(name).send(cmd)
29
- end
30
-
31
- Then /^the (.+) cartridge should be (.*)$/ do |name,status|
32
- name = map_cartridge_type(name)
33
- expected = case status.to_sym
34
- when :running
35
- "(.+) is running|Uptime:"
36
- when :stopped
37
- "(.+) stopped"
38
- when :removed
39
- "There are no cartridges that match '#{name}'"
40
- else
41
- raise "Unrecognized status type #{status}"
42
- end
43
- @app.cartridge(name).status.should match(expected)
44
- end
45
-
46
- Then /^adding the (.+) cartridge should fail$/ do |name|
47
- name = map_cartridge_type(name)
48
- @app.add_cartridge(name).should == 154
49
- end
50
-
51
- When /^we are updating the (.+) cartridge$/ do |cart|
52
- cart = map_cartridge_type(cart)
53
- @cartridge_name = cart
54
- end
55
-
56
- When /^the (\w+) scaling value is set to (.*)$/ do |minmax,value|
57
- @exitcode = @app.cartridge(@cartridge_name).send(:scale,"--#{minmax} #{value}")
58
- end
59
-
60
- When /^we list cartridges$/ do
61
- @exitcode, @cartridge_output = Cartridge.list
62
- end
63
-
64
- When /^we (.+) storage for the (.+) cartridge$/ do |storage_action,cartridge|
65
- @output = @app.cartridge(@cartridge_name).send(:storage, cartridge, "--#{storage_action}")
66
- end
67
-
68
- Then /^the (\w+) scaling value should be (.*)$/ do |minmax,value|
69
- expected = {
70
- :min => "minimum",
71
- :max => "maximum"
72
- }[minmax.to_sym]
73
-
74
- value = (value == "-1" ? "available" : value)
75
-
76
- match_string = [expected,value].join(": ")
77
- regex = Regexp.new(/\b#{match_string}/)
78
-
79
- @app.cartridge(@cartridge_name).send(:show).should match(regex)
80
- end
81
-
82
- Then /^the additional cartridge storage amount should be (\w+)$/ do |value|
83
- @output.should == value
84
- end
85
-
86
- Then /^it should fail with code (\d+)$/ do |code|
87
- @exitcode.should == code.to_i
88
- end
89
-
90
- Then /^the list should contain the cartridge ([^\s]+) with display name$/ do |name|
91
- display_name = map_cartridge_name(name)
92
- line = @cartridge_output.each_line.find{ |s| s.include?(name) }
93
- line.should_not be_nil
94
- line.should match(display_name)
95
- end