rhc 0.98.16 → 1.0.4

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 (94) hide show
  1. data/bin/rhc +7 -49
  2. data/bin/rhc-app +14 -3
  3. data/bin/rhc-chk +16 -16
  4. data/bin/rhc-create-app +2 -0
  5. data/bin/rhc-create-domain +1 -2
  6. data/bin/rhc-ctl-app +12 -3
  7. data/bin/rhc-ctl-domain +1 -2
  8. data/bin/rhc-domain +1 -2
  9. data/bin/rhc-domain-info +1 -2
  10. data/bin/rhc-port-forward +1 -2
  11. data/bin/rhc-snapshot +3 -0
  12. data/bin/rhc-sshkey +1 -2
  13. data/bin/rhc-tail-files +1 -1
  14. data/bin/rhc-user-info +1 -3
  15. data/features/application.feature +4 -1
  16. data/features/domain.feature +0 -4
  17. data/features/geared_application.feature +11 -0
  18. data/features/lib/rhc_helper/app.rb +16 -5
  19. data/features/lib/rhc_helper/cartridge.rb +25 -9
  20. data/features/lib/rhc_helper/commandify.rb +34 -7
  21. data/features/lib/rhc_helper/domain.rb +2 -2
  22. data/features/lib/rhc_helper/httpify.rb +24 -14
  23. data/features/lib/rhc_helper/persistable.rb +1 -1
  24. data/features/lib/rhc_helper/sshkey.rb +11 -7
  25. data/features/lib/rhc_helper.rb +5 -3
  26. data/features/multiple_cartridge.feature +1 -1
  27. data/features/scaled_application.feature +48 -0
  28. data/features/sshkey.feature +37 -31
  29. data/features/step_definitions/application_steps.rb +18 -7
  30. data/features/step_definitions/cartridge_steps.rb +29 -3
  31. data/features/step_definitions/domain_steps.rb +2 -2
  32. data/features/step_definitions/sshkey_steps.rb +34 -34
  33. data/features/support/assumptions.rb +21 -9
  34. data/features/support/before_hooks.rb +24 -6
  35. data/features/support/env.rb +45 -19
  36. data/lib/rhc/cartridge_helper.rb +27 -0
  37. data/lib/rhc/cli.rb +1 -1
  38. data/lib/rhc/command_runner.rb +31 -3
  39. data/lib/rhc/commands/alias.rb +38 -0
  40. data/lib/rhc/commands/app.rb +478 -0
  41. data/lib/rhc/commands/base.rb +42 -12
  42. data/lib/rhc/commands/cartridge.rb +189 -0
  43. data/lib/rhc/commands/domain.rb +11 -49
  44. data/lib/rhc/commands/port-forward.rb +0 -1
  45. data/lib/rhc/commands/setup.rb +2 -1
  46. data/lib/rhc/commands/snapshot.rb +118 -0
  47. data/lib/rhc/commands/sshkey.rb +24 -38
  48. data/lib/rhc/commands/tail.rb +24 -0
  49. data/lib/rhc/commands/threaddump.rb +16 -0
  50. data/lib/rhc/commands.rb +33 -7
  51. data/lib/rhc/config.rb +28 -12
  52. data/lib/rhc/context_helper.rb +19 -5
  53. data/lib/rhc/core_ext.rb +86 -0
  54. data/lib/rhc/exceptions.rb +44 -0
  55. data/lib/rhc/git_helper.rb +59 -0
  56. data/lib/rhc/helpers.rb +86 -5
  57. data/lib/rhc/output_helpers.rb +213 -0
  58. data/lib/rhc/rest/application.rb +134 -67
  59. data/lib/rhc/rest/base.rb +48 -0
  60. data/lib/rhc/rest/cartridge.rb +40 -44
  61. data/lib/rhc/rest/client.rb +127 -59
  62. data/lib/rhc/rest/domain.rb +29 -39
  63. data/lib/rhc/rest/gear_group.rb +10 -0
  64. data/lib/rhc/rest/key.rb +8 -23
  65. data/lib/rhc/rest/user.rb +8 -24
  66. data/lib/rhc/rest.rb +22 -11
  67. data/lib/rhc/ssh_key_helpers.rb +47 -0
  68. data/lib/rhc/usage_templates/help.erb +0 -1
  69. data/lib/rhc/version.rb +3 -3
  70. data/lib/rhc/wizard.rb +123 -225
  71. data/lib/rhc-common.rb +43 -62
  72. data/spec/rest_spec_helper.rb +159 -36
  73. data/spec/rhc/cli_spec.rb +29 -1
  74. data/spec/rhc/command_spec.rb +32 -35
  75. data/spec/rhc/commands/alias_spec.rb +123 -0
  76. data/spec/rhc/commands/app_spec.rb +414 -0
  77. data/spec/rhc/commands/cartridge_spec.rb +342 -0
  78. data/spec/rhc/commands/domain_spec.rb +8 -8
  79. data/spec/rhc/commands/setup_spec.rb +17 -6
  80. data/spec/rhc/commands/snapshot_spec.rb +140 -0
  81. data/spec/rhc/commands/sshkey_spec.rb +26 -4
  82. data/spec/rhc/commands/tail_spec.rb +34 -0
  83. data/spec/rhc/commands/threaddump_spec.rb +83 -0
  84. data/spec/rhc/config_spec.rb +39 -13
  85. data/spec/rhc/context_spec.rb +51 -0
  86. data/spec/rhc/helpers_spec.rb +52 -12
  87. data/spec/rhc/rest_application_spec.rb +16 -3
  88. data/spec/rhc/rest_client_spec.rb +144 -36
  89. data/spec/rhc/rest_spec.rb +1 -1
  90. data/spec/rhc/wizard_spec.rb +133 -232
  91. data/spec/spec_helper.rb +4 -3
  92. metadata +56 -31
  93. data/features/support/ssh.sh +0 -2
  94. data/spec/rhc/common_spec.rb +0 -49
@@ -1,29 +1,33 @@
1
1
  require "rhc/rest"
2
2
 
3
3
  module RHCHelper
4
-
4
+
5
5
  class Sshkey
6
6
  extend Runnable
7
7
  extend Commandify
8
-
8
+
9
9
  class << self
10
10
  attr_accessor :sshkey_output, :exitcode
11
11
  end
12
-
12
+
13
13
  def self.list(*args)
14
14
  rhc_sshkey_list args
15
15
  end
16
-
16
+
17
17
  def self.show(*args)
18
18
  rhc_sshkey_show args
19
19
  end
20
-
20
+
21
21
  def self.add(*args)
22
22
  rhc_sshkey_add args
23
23
  end
24
-
24
+
25
25
  def self.remove(*args)
26
26
  rhc_sshkey_remove args
27
27
  end
28
+
29
+ def self.keyfile_path(name)
30
+ File.expand_path(File.join(File.dirname(__FILE__),'..','..','support',name))
31
+ end
28
32
  end
29
- end
33
+ end
@@ -5,8 +5,10 @@ require 'tmpdir'
5
5
  ### Some shared constant declarations
6
6
  module RHCHelper
7
7
  TEMP_DIR = File.join(Dir.tmpdir, "rhc") unless const_defined?(:TEMP_DIR)
8
- # The regex to parse the ssh output from the create app results
9
- SSH_OUTPUT_PATTERN = %r|ssh://([^@]+)@([^/]+)| unless const_defined?(:SSH_OUTPUT_PATTERN)
8
+ # The regex to parse the UUID output from the create app results
9
+ UUID_OUTPUT_PATTERN = %r|UUID\s*=\s*(.+)| unless const_defined?(:UUID_OUTPUT_PATTERN)
10
+ # The regex to parse the Gear Profile output from the create app results
11
+ GEAR_PROFILE_OUTPUT_PATTERN = %r|Application Info.*Gear Size\s*=\s*(\w+)|m unless const_defined?(:GEAR_PROFILE_OUTPUT_PATTERN)
10
12
  # Regex to parse passwords out of logging messages
11
13
  PASSWORD_REGEX = / -p [^\s]* / unless const_defined?(:PASSWORD_REGEX)
12
14
  end
@@ -18,4 +20,4 @@ require 'rhc_helper/persistable'
18
20
  require 'rhc_helper/runnable'
19
21
  require 'rhc_helper/app'
20
22
  require 'rhc_helper/domain'
21
- require 'rhc_helper/sshkey'
23
+ require 'rhc_helper/sshkey'
@@ -1,4 +1,4 @@
1
- @multiple_cartridge @domain_required
1
+ @multiple_cartridge @domain_required @clean
2
2
  Feature: Multiple Cartridge Tests
3
3
 
4
4
  @init
@@ -0,0 +1,48 @@
1
+ @scaled_application @domain_required
2
+ Feature: Scaled Application Operations
3
+
4
+ @init
5
+ Scenario: Scaled Application Creation
6
+ When a scaled php-5.3 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-5.3 | min | 3 |
38
+ | php-5.3 | max | 5 |
39
+ | php-5.3 | 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-5.3 | min | a | 1 |
@@ -2,57 +2,63 @@
2
2
  Feature: SSH key Management
3
3
  As an OpenShift user, I want to manage SSH keys with 'rhc sshkey' commands.
4
4
 
5
- @sshkey_list
5
+ @sshkey_list @key1
6
6
  Scenario: SSH key is listed
7
- Given the SSH key "key1" already exists
8
- When 'rhc sshkey list' is run
7
+ When a new SSH key "key1.pub" is added as "key1"
8
+ And the existing keys are listed
9
9
  Then the output includes the key information
10
-
11
- @sshkey_show
10
+
11
+ @sshkey_show @key1
12
12
  Scenario: SSH key is shown individually
13
- Given the SSH key "key1" already exists
14
- When 'rhc sshkey show "key1"' is run
13
+ When the key "key1" is shown
15
14
  Then the output includes the key information for "key1"
16
-
15
+
17
16
  @sshkey_show
18
17
  Scenario: Requested SSH key does not exist
19
- Given the SSH key "key2" does not exist
20
- When 'rhc sshkey show "key2"' command is run
18
+ When the key "key2" is shown
21
19
  Then the command exits with status code 118
22
-
20
+
23
21
  @sshkey_add
24
22
  Scenario: SSH key is added successfully
25
- Given the SSH key "key1" does not exist
26
- When a new SSH key "features/support/key1.pub" is added as "key1"
27
- Then the key "key1" should exist
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"
28
26
  And the command exits with status code 0
29
-
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 128
32
+
30
33
  @sshkey_add
31
34
  Scenario: invalid SSH key is added
32
- Given the SSH key "key1" does not exist
33
- When a new SSH key "features/support/key3.pub" is added as "key3"
35
+ When a new SSH key "key3.pub" is added as "key3"
34
36
  Then the command exits with status code 128
35
-
37
+
36
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
37
44
  Scenario: SSH key with the same name already exists
38
- Given the SSH key "key1" already exists
39
- When a new SSH key "features/support/key2.pub" is added as "key1"
45
+ When a new SSH key "key2.pub" is added as "key1"
40
46
  Then the command exits with status code 128
41
-
47
+
42
48
  @sshkey_add
43
49
  Scenario: SSH key with the identical content already exists
44
- Given an SSH key "key2" with the same content as "key1" exists
45
- And the SSH key "key1" does not exist
46
- When 'rhc sshkey add "key1" "features/support/key1.pub"' is run
50
+ Given a new SSH key "key1.pub" is added as "key1"
51
+ And a new SSH key "key1.pub" is added as "key2"
47
52
  Then the command exits with status code 128
48
53
 
49
- @sshkey_remove
54
+
55
+ @sshkey_remove @key1
50
56
  Scenario: SSH key is deleted successfully
51
- When 'rhc sshkey remove "key1"' is run
52
- Then the SSH key "key1" is deleted
53
-
57
+ When the key "key1" is removed
58
+ And the key "key1" is shown
59
+ Then the output does not include the key information for "key1"
60
+
54
61
  @sshkey_remove
55
62
  Scenario: SSH key requested to be deleted does not exist
56
- Given the SSH key "key1" does not exist
57
- When 'rhc sshkey remove "key1"' is run
58
- Then the command exits with status code 118
63
+ When the key "key1" is removed
64
+ Then the command exits with status code 118
@@ -16,16 +16,18 @@ Transform /^application with(.*)$/ do |embed_type|
16
16
  end
17
17
 
18
18
  # Use the transformed array so we can reuse this step for all combinations
19
- Given /^an existing (or new )?(.+) (application with.*)$/ do |create,type, embeds|
19
+ Given /^an existing (or new )?(scaled )?(.+) (application with.*)$/ do |create, scaled, type, embeds|
20
20
  options = { :type => type }
21
21
  options[:embed] = embeds if embeds
22
-
22
+ options[:scalable] = scaled if scaled
23
23
  @app = App.find_on_fs(options)
24
24
 
25
+ @app = nil if @app.nil? or not @app.is_created?
26
+
25
27
  if create && @app.nil?
26
- step "a #{type} application is created"
28
+ When "a #{scaled}#{type} application is created"
27
29
  embeds.each do |embed|
28
- step "the #{embed} cartridge is added"
30
+ When "the #{embed} cartridge is added"
29
31
  end
30
32
  end
31
33
 
@@ -49,8 +51,8 @@ When /^(\d+) (.+) applications are created$/ do |app_count, type|
49
51
  @app = old_app
50
52
  end
51
53
 
52
- When /^a (.+) application is created$/ do |type|
53
- @app = App.create_unique(type)
54
+ When /^a (scaled )?(.+) application is created(?: with a (.*) gear)?$/ do |scaled, type, gear_profile|
55
+ @app = App.create_unique(type, scaled, gear_profile)
54
56
  @app.rhc_app_create
55
57
  end
56
58
 
@@ -67,7 +69,8 @@ When /^the application is (\w+)$/ do |command|
67
69
  :stopped => :stop,
68
70
  :shown => :show,
69
71
  :tidied => :tidy,
70
- :snapshot => :snapshot_save
72
+ :snapshot => :snapshot_save,
73
+ :deleted => :delete
71
74
  }
72
75
 
73
76
  # Use an alias if it exists, or just remove 'ed' (like from started)
@@ -105,3 +108,11 @@ end
105
108
 
106
109
  Then /^it should succeed$/ do
107
110
  end
111
+
112
+ Then /^the application should be scalable/ do
113
+ Then "the haproxy-1.4 cartridge should be running"
114
+ end
115
+
116
+ Then /^the application should have a (.*) gear$/ do |gear_profile|
117
+ @app.gear_profile.should match("#{gear_profile}")
118
+ end
@@ -26,11 +26,11 @@ end
26
26
  Then /^the (.+) cartridge should be (.*)$/ do |name,status|
27
27
  expected = case status.to_sym
28
28
  when :running
29
- "RESULT:\n(.+) is running|RESULT:\n(\n|.)+Uptime:"
29
+ "(.+) is running|Uptime:"
30
30
  when :stopped
31
- "RESULT:\n(.+) stopped"
31
+ "(.+) stopped"
32
32
  when :removed
33
- "Response code was 400"
33
+ "Invalid cartridge specified: '#{name}'"
34
34
  end
35
35
  @app.cartridge(name).status.should match(expected)
36
36
  end
@@ -38,3 +38,29 @@ end
38
38
  Then /^adding the (.+) cartridge should fail$/ do |name|
39
39
  @app.add_cartridge(name).should == 154
40
40
  end
41
+
42
+ When /^we are updating the (.+) cartridge$/ do |cart|
43
+ @cartridge_name = cart
44
+ end
45
+
46
+ When /^the (\w+) scaling value is set to (.*)$/ do |minmax,value|
47
+ @exitcode = @app.cartridge(@cartridge_name).send(:scale,"--#{minmax} #{value}")
48
+ end
49
+
50
+ Then /^the (\w+) scaling value should be (.*)$/ do |minmax,value|
51
+ expected = {
52
+ :min => "Minimum",
53
+ :max => "Maximum"
54
+ }[minmax.to_sym]
55
+
56
+ value = (value == "-1" ? "available gears" : value)
57
+
58
+ match_string = [expected,value].join(" = ")
59
+ regex = Regexp.new(/\s+#{match_string}/)
60
+
61
+ @app.cartridge(@cartridge_name).send(:show).should match(regex)
62
+ end
63
+
64
+ Then /^it should fail with code (\d+)$/ do |code|
65
+ @exitcode.should == code.to_i
66
+ end
@@ -30,8 +30,8 @@ end
30
30
  Then /^the default domain action output should equal the show action output$/ do
31
31
  Domain.domain_output.should match($namespace)
32
32
 
33
- domain_output = Domain.domain_output.lines
34
- domain_show_output = Domain.domain_show_output.lines
33
+ domain_output = Domain.domain_output.lines.sort
34
+ domain_show_output = Domain.domain_show_output.lines.sort
35
35
 
36
36
  # check line by line while ignoring debug output which is timestamped
37
37
  domain_output.zip(domain_show_output) do |a, b|
@@ -1,10 +1,5 @@
1
1
  include RHCHelper
2
2
 
3
- Before do
4
- Sshkey.remove "key1"
5
- Sshkey.remove "key2"
6
- end
7
-
8
3
  When /^'rhc sshkey (\S+)( .*?)?'(?: command)? is run$/ do |subcommand, rest|
9
4
  if subcommand =~ /^(list|show|add|remove|delete|update)$/
10
5
  Sshkey.send subcommand.to_sym, rest
@@ -13,40 +8,23 @@ When /^'rhc sshkey (\S+)( .*?)?'(?: command)? is run$/ do |subcommand, rest|
13
8
  end
14
9
  end
15
10
 
16
- Given /^the SSH key "(.*?)" does not exist$/ do |key|
17
- Sshkey.remove "key"
18
- end
19
-
20
- Given /^the SSH key "(.*?)" already exists$/ do |key|
21
- keyfile = File.join(File.dirname(__FILE__), '..', 'support', key + '.pub')
22
- step "'rhc sshkey add #{key} #{keyfile}' is run"
11
+ Given "the existing keys are listed" do
12
+ When "'rhc sshkey list' is run"
23
13
  end
24
14
 
25
- Given /^an SSH key "(.*?)" with the same content as "(.*?)" exists$/ do |existing_key, new_key|
26
- keyfile = File.join(File.dirname(__FILE__), '..', 'support', new_key + '.pub')
27
- step "a new SSH key \"#{keyfile}\" is added as \"#{existing_key}\""
15
+ Given /^the key "(.*?)" is (.*)$/ do |key,cmd|
16
+ cmd = case cmd
17
+ when "shown"
18
+ "show"
19
+ when "removed"
20
+ "remove"
21
+ end
22
+ When "'rhc sshkey #{cmd} \"#{key}\"' is run"
28
23
  end
29
24
 
30
25
  When /^a new SSH key "(.*?)" is added as "(.*)"$/ do |keyfile, name|
31
- step "'rhc sshkey add #{name} #{keyfile}' is run"
32
- end
33
-
34
- Then /^the output includes the key information for "(.*?)"$/ do |key|
35
- @sshkey_output.should match /Name: #{key}/
36
- end
37
-
38
- Then /^the key "(.*?)" should exist$/ do |key|
39
- Sshkey.show "#{key}"
40
- Sshkey.sshkey_output.should =~ /Name: #{key}/
41
- end
42
-
43
- Then /^the SSH key "(.*?)" is deleted$/ do |key|
44
- Sshkey.show "#{key}"
45
- Sshkey.sshkey_output.should_not =~ /Name: #{key}/
46
- end
47
-
48
- Then /^the output includes the key information$/ do
49
- @sshkey_output.should match /Name:.*Type:.*Fingerprint:/m
26
+ keyfile = Sshkey.keyfile_path(keyfile)
27
+ When "'rhc sshkey add #{name} #{keyfile}' is run"
50
28
  end
51
29
 
52
30
  Then /^the command exits with status code (\d+)$/ do |arg1|
@@ -54,3 +32,25 @@ Then /^the command exits with status code (\d+)$/ do |arg1|
54
32
  @exitcode.should == code
55
33
  end
56
34
 
35
+ Then /^the output (does not include|includes) (.*)$/ do |includes,str|
36
+ regex = case str
37
+ when /^the key information for "(.*?)"$/
38
+ /Name: #{$1}/
39
+ when "deprecation warning"
40
+ /deprecated/
41
+ when "the key information"
42
+ /Name:.*Type:.*Fingerprint:/m
43
+ end
44
+ includes = case includes
45
+ when "does not"
46
+ false
47
+ when "includes"
48
+ true
49
+ end
50
+
51
+ if includes
52
+ @sshkey_output.should match regex
53
+ else
54
+ @sshkey_output.should_not match regex
55
+ end
56
+ end
@@ -1,11 +1,17 @@
1
1
  Given 'we have the client tools setup' do
2
- step 'the libra client tools'
3
- step 'the client tools should be setup if needed'
2
+ When 'the libra client tools'
3
+ When 'the client tools should be setup if needed'
4
4
  end
5
5
 
6
6
  Given 'we have an existing domain' do
7
- step 'we have the client tools setup'
8
- step 'a new domain is needed and created'
7
+ When 'we have the client tools setup'
8
+ When 'a new domain is needed and created'
9
+ begin
10
+ When 'the key "key1" is shown'
11
+ Then 'the output includes the key information for "key1"'
12
+ rescue Spec::Expectations::ExpectationNotMetError
13
+ Given 'a new SSH key "key1.pub" is added as "key1"'
14
+ end
9
15
  end
10
16
 
11
17
  Given /^we have a (.*) (.*) cartridge$/ do |status,type|
@@ -20,18 +26,24 @@ Given /^we have a (.*) (.*) cartridge$/ do |status,type|
20
26
  # only try once
21
27
  retried = false
22
28
  begin
23
- step "the #{type} cartridge should be #{status}"
29
+ When "the #{type} cartridge should be #{status}"
24
30
  rescue Spec::Expectations::ExpectationNotMetError
25
- step "the #{type} cartridge is #{cmd}"
31
+ When "the #{type} cartridge is #{cmd}"
26
32
  (retried = true && retry) unless retried
27
33
  end
28
34
  end
29
35
 
30
36
  Given /^we have a (stopped|running) application$/ do |state|
37
+ (before,after) = case state
38
+ when "stopped"
39
+ ["not be accessible","stopped"]
40
+ when "running"
41
+ ["be accessible","started"]
42
+ end
43
+
31
44
  begin
32
- step "the application should not be accessible"
33
- step "the application is started" if state == "running"
45
+ When "the application should #{before}"
34
46
  rescue Spec::Expectations::ExpectationNotMetError
35
- step "the application is stopped" if state == "stopped"
47
+ When "the application is #{after}"
36
48
  end
37
49
  end
@@ -1,25 +1,43 @@
1
+ Before('@clean') do
2
+ clean_applications(true)
3
+ end
4
+
5
+ Before('@sshkey') do
6
+ Sshkey.remove "key1"
7
+ Sshkey.remove "key2"
8
+ end
9
+
10
+ Before('@sshkey','@key1') do
11
+ Given 'a new SSH key "key1.pub" is added as "key1"'
12
+ end
13
+
1
14
  # Defined the required hooks first so we make sure we have everything we need
15
+ Before('@geared_user_required') do
16
+ $username = "user_with_multiple_gear_sizes@test.com"
17
+ end
18
+
2
19
  Before('@domain_required') do
3
- step 'we have an existing domain'
20
+ When 'we have an existing domain'
4
21
  end
5
22
 
6
23
  Before('@client_tools_required') do
7
- step 'we have the client tools setup'
24
+ When 'we have the client tools setup'
8
25
  end
9
26
 
10
27
  Before('@single_cartridge','@init') do
11
- step 'an existing or new php-5.3 application without an embedded cartridge'
28
+ When 'an existing or new php-5.3 application without an embedded cartridge'
12
29
  end
13
30
 
14
31
  # These assumptions help to ensure any steps that are run independently have the same state as after the @init step
15
32
  {
16
33
  :application => 'an existing or new php-5.3 application without an embedded cartridge',
34
+ :scaled_application => 'an existing or new scaled php-5.3 application without an embedded cartridge',
17
35
  :domain => 'we have an existing domain',
18
36
  :client => 'we have the client tools setup',
19
37
  :single_cartridge => 'an existing or new php-5.3 application with an embedded mysql-5.1 cartridge',
20
38
  :multiple_cartridge => 'an existing or new php-5.3 application with embedded mysql-5.1 and phpmyadmin-3.4 cartridges',
21
39
  }.each do |tag,assumption|
22
- Before("@#{tag}",'~@init') do
23
- step assumption
40
+ Before("@#{tag}",'~@init') do
41
+ When assumption
42
+ end
24
43
  end
25
- end
@@ -6,6 +6,7 @@ SimpleCov.at_exit{ SimpleCov.result.format! } if defined? SimpleCov
6
6
  require 'rhc_helper'
7
7
  require 'rhc/rest'
8
8
  require 'rhc/config'
9
+ require 'rhc/helpers'
9
10
 
10
11
  def set_path
11
12
  ENV["PATH"] = "#{ENV['RHC_LOCAL_PATH']}:#{ENV['PATH']}" if ENV['RHC_LOCAL_PATH']
@@ -52,11 +53,6 @@ def set_endpoint
52
53
  $end_point = ENV['RHC_ENDPOINT']
53
54
  end
54
55
 
55
- # This env variable needs to be set so the git commands can bypass host key authenticity checking
56
- def set_ssh
57
- ENV['GIT_SSH'] ||= File.expand_path(File.join(File.dirname(__FILE__),'ssh.sh'))
58
- end
59
-
60
56
  ### Run initialization commands
61
57
  # Set the PATH env variable
62
58
  set_path
@@ -64,12 +60,16 @@ set_path
64
60
  set_creds
65
61
  # Set the endpoint to test against
66
62
  set_endpoint
67
- # Set the ssh env variable
68
- set_ssh
69
63
 
70
64
  raise "Username not found in environment (RHC_USERNAME)" unless $username
71
65
  raise "Password not found in environment (RHC_PASSWORD)" unless $password
72
66
 
67
+ $user_register_script_format = "/usr/bin/ss-register-user -l admin -p admin --username %s --userpass %s"
68
+ if ENV['REGISTER_USER']
69
+ command = $user_register_script_format % [$username,$password]
70
+ %x[#{command}]
71
+ end
72
+
73
73
  def _log(msg)
74
74
  puts msg unless ENV['QUIET']
75
75
  end
@@ -85,6 +85,28 @@ _log " Creating New Namespace: #{$namespace.nil?}"
85
85
  _log "--------------------------------------------------------------------------------------------------"
86
86
  _log "\n\n"
87
87
 
88
+ def clean_applications(leave_domain = false)
89
+ return if ENV['NO_CLEAN']
90
+ users = [$username,'user_with_multiple_gear_sizes@test.com']
91
+
92
+ _log " Cleaning up test applications..."
93
+
94
+ users.each do |user|
95
+ _log "\tUser: #{user}"
96
+ client = RHC::Rest::Client.new($end_point, user, $password)
97
+ client.domains.each do |domain|
98
+ _log "\t\tDomain: #{domain.id}"
99
+ domain.applications.each do |app|
100
+ if app.name.start_with?("test")
101
+ _log "\t\t\tApplication: #{app.name}"
102
+ app.delete
103
+ end
104
+ end
105
+ domain.delete unless leave_domain
106
+ end
107
+ end
108
+ end
109
+
88
110
  unless ENV['NO_CLEAN']
89
111
  _log "--------------------------------------------------------------------------------------------------"
90
112
  _log " Resetting environment"
@@ -97,21 +119,12 @@ unless ENV['NO_CLEAN']
97
119
  _log " Replacing express.conf with the specified libra_server"
98
120
  File.open(RHC::Config::local_config_path, 'w') {|f| f.write("libra_server=#{URI.parse($end_point).host}") }
99
121
 
100
- _log " Cleaning up test applications..."
122
+ # Clean up temp dir
101
123
  FileUtils.rm_rf RHCHelper::TEMP_DIR
102
124
 
103
- # Cleanup all test applications
104
- client = RHC::Rest::Client.new($end_point, $username, $password)
105
- client.domains.each do |domain|
106
- domain.applications.each do |app|
107
- if app.name.start_with?("test")
108
- _log " Deleting application #{app.name}"
109
- app.delete
110
- end
111
- end
112
- end
125
+ # Clean up applications
126
+ clean_applications
113
127
 
114
- _log " Application cleanup complete"
115
128
  _log "--------------------------------------------------------------------------------------------------"
116
129
  _log "\n\n"
117
130
  end
@@ -123,6 +136,19 @@ AfterConfiguration do |config|
123
136
  # Persist the username used for the tests - in case it was auto-generated
124
137
  File.open(File.join(RHCHelper::TEMP_DIR, 'username'), 'w') {|f| f.write($username)}
125
138
 
139
+ # Modify the .ssh/config so the git and ssh commands can succeed
140
+ keyfile = RHCHelper::Sshkey.keyfile_path('key1')
141
+ begin
142
+ File.open('/root/.ssh/config','w',0600) do |f|
143
+ f.puts "Host *"
144
+ f.puts "\tStrictHostKeyChecking no"
145
+ f.puts "\tIdentityFile #{keyfile}"
146
+ f.puts "\tIdentityFile /root/.ssh/id_rsa"
147
+ end
148
+ rescue Errno::ENOENT, Errno::EACCES
149
+ end
150
+ File.chmod(0600,keyfile)
151
+
126
152
  # Setup the logger
127
153
  logger = Logger.new(File.join(RHCHelper::TEMP_DIR, "cucumber.log"))
128
154
  logger.level = Logger::DEBUG
@@ -0,0 +1,27 @@
1
+ module RHC
2
+ module CartridgeHelpers
3
+ def find_cartridge(rest_obj, cartridge_name, type="embedded")
4
+ carts = rest_obj.find_cartridges :regex => cart_regex(cartridge_name), :type => type
5
+
6
+ if carts.length == 0
7
+ valid_carts = rest_obj.cartridges.collect { |c| c.name if c.type == type }.compact
8
+ if valid_carts.length > 0
9
+ msg = "Valid cartridges are (#{valid_carts.join(', ')})."
10
+ else
11
+ msg = "No cartridges have been added to this app."
12
+ end
13
+ raise RHC::CartridgeNotFoundException, "Invalid cartridge specified: '#{cartridge_name}'. #{msg}"
14
+ elsif carts.length > 1
15
+ msg = "Multiple cartridge versions match your criteria. Please specify one."
16
+ carts.each { |cart| msg += "\n #{cart.name}" }
17
+ raise RHC::MultipleCartridgesException, msg
18
+ end
19
+
20
+ carts[0]
21
+ end
22
+
23
+ def cart_regex(cart)
24
+ "^#{cart.rstrip}(-[0-9\.]+){0,1}$"
25
+ end
26
+ end
27
+ end
data/lib/rhc/cli.rb CHANGED
@@ -20,7 +20,7 @@ module RHC
20
20
  extend Commander::Delegates
21
21
 
22
22
  def self.set_terminal
23
- $terminal.wrap_at = HighLine::SystemExtensions.terminal_size.first - 5 rescue 80 if $stdin.tty?
23
+ $terminal.wrap_at = HighLine::SystemExtensions.terminal_size.first rescue 80 if $stdin.tty?
24
24
  # FIXME: ANSI terminals are not default on windows but we may just be
25
25
  # hitting a bug in highline if windows does support another method.
26
26
  # This is a safe fix for now but needs more research.