cucumber-chef 1.0.3 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gitignore +8 -35
  2. data/.rspec +1 -0
  3. data/.rvmrc.template +2 -0
  4. data/.travis.yml +22 -0
  5. data/Gemfile +2 -15
  6. data/LICENSE +202 -201
  7. data/NOTICE +9 -0
  8. data/README.md +696 -92
  9. data/Rakefile +39 -25
  10. data/TODO.md +28 -0
  11. data/bin/cc-knife +32 -0
  12. data/bin/cucumber-chef +409 -79
  13. data/chef_repo/cookbooks/cucumber-chef/LICENSE +202 -0
  14. data/chef_repo/cookbooks/cucumber-chef/README.md +69 -0
  15. data/chef_repo/cookbooks/cucumber-chef/attributes/default.rb +27 -0
  16. data/chef_repo/cookbooks/cucumber-chef/metadata.rb +13 -0
  17. data/chef_repo/cookbooks/cucumber-chef/recipes/default.rb +23 -0
  18. data/chef_repo/cookbooks/cucumber-chef/recipes/lxc.rb +315 -0
  19. data/chef_repo/cookbooks/cucumber-chef/recipes/test_lab.rb +146 -0
  20. data/chef_repo/cookbooks/cucumber-chef/templates/default/db-168-192.erb +15 -0
  21. data/chef_repo/cookbooks/cucumber-chef/templates/default/db-test-lab.erb +15 -0
  22. data/chef_repo/cookbooks/cucumber-chef/templates/default/dhcpd-conf.erb +44 -0
  23. data/chef_repo/cookbooks/cucumber-chef/templates/default/gemrc.erb +10 -0
  24. data/{cookbooks/cucumber-chef/files/default/cucumber-net → chef_repo/cookbooks/cucumber-chef/templates/default/lxc-initializer-config.erb} +1 -1
  25. data/chef_repo/cookbooks/cucumber-chef/templates/default/lxc-install-chef.erb +3 -0
  26. data/chef_repo/cookbooks/cucumber-chef/templates/default/motd.erb +10 -0
  27. data/chef_repo/cookbooks/cucumber-chef/templates/default/named-conf-local.erb +25 -0
  28. data/{cookbooks/cucumber-chef/files/default/permissive-ssh-config → chef_repo/cookbooks/cucumber-chef/templates/default/ssh-config.erb} +3 -1
  29. data/chef_repo/roles/test_lab.rb +24 -0
  30. data/cucumber-chef.gemspec +50 -123
  31. data/examples/README.md +7 -0
  32. data/examples/users_add.feature +51 -0
  33. data/examples/users_auto_remove.feature +50 -0
  34. data/features/support/env.rb +3 -2
  35. data/lib/cucumber/chef/bootstrap.rb +94 -0
  36. data/lib/cucumber/chef/command.rb +78 -0
  37. data/lib/cucumber/chef/config.rb +143 -93
  38. data/lib/cucumber/chef/helpers/chef_client.rb +87 -0
  39. data/lib/cucumber/chef/helpers/chef_server.rb +90 -0
  40. data/lib/cucumber/chef/helpers/command.rb +57 -0
  41. data/lib/cucumber/chef/helpers/container.rb +154 -0
  42. data/lib/cucumber/chef/helpers/minitest.rb +35 -0
  43. data/lib/cucumber/chef/helpers/server.rb +81 -0
  44. data/lib/cucumber/chef/helpers/test_lab.rb +46 -0
  45. data/lib/cucumber/chef/helpers/utility.rb +73 -0
  46. data/lib/cucumber/chef/helpers.rb +56 -0
  47. data/lib/cucumber/chef/logger.rb +90 -0
  48. data/lib/cucumber/chef/provisioner.rb +275 -69
  49. data/lib/cucumber/chef/ssh.rb +190 -0
  50. data/lib/cucumber/chef/steps/chef_steps.rb +32 -0
  51. data/lib/cucumber/chef/steps/minitest_steps.rb +29 -0
  52. data/lib/cucumber/chef/steps/provision_steps.rb +60 -0
  53. data/lib/cucumber/chef/steps/ssh_steps.rb +95 -0
  54. data/lib/cucumber/chef/steps.rb +27 -0
  55. data/lib/cucumber/chef/tcp_socket.rb +83 -0
  56. data/lib/cucumber/chef/template.rb +57 -0
  57. data/lib/cucumber/chef/templates/bootstrap/ubuntu-precise-test-lab.erb +99 -0
  58. data/lib/cucumber/chef/templates/cucumber/env.rb +56 -0
  59. data/lib/cucumber/chef/templates/cucumber/example_feature.erb +49 -0
  60. data/lib/cucumber/chef/templates/cucumber/example_steps.erb +11 -0
  61. data/lib/cucumber/chef/templates/cucumber/readme-data_bags.erb +1 -0
  62. data/lib/cucumber/chef/templates/cucumber/readme-keys.erb +1 -0
  63. data/lib/cucumber/chef/templates/cucumber/readme-roles.erb +1 -0
  64. data/lib/cucumber/chef/templates/cucumber/readme.erb +18 -0
  65. data/lib/cucumber/chef/templates/cucumber-chef/config-rb.erb +33 -0
  66. data/lib/cucumber/chef/templates/cucumber-chef/cucumber-yml.erb +2 -0
  67. data/lib/cucumber/chef/templates/cucumber-chef/knife-rb.erb +18 -0
  68. data/lib/cucumber/chef/test_lab.rb +308 -52
  69. data/lib/cucumber/chef/test_runner.rb +86 -15
  70. data/lib/cucumber/chef/utility.rb +128 -0
  71. data/lib/cucumber/chef/version.rb +30 -1
  72. data/lib/cucumber/chef.rb +53 -20
  73. data/lib/cucumber-chef.rb +24 -1
  74. data/spec/cucumber/chef/config_spec.rb +144 -78
  75. data/spec/cucumber/chef/provisioner_spec.rb +60 -16
  76. data/spec/cucumber/chef/test_lab_spec.rb +62 -19
  77. data/spec/spec_helper.rb +30 -26
  78. data/todo.org +17 -0
  79. metadata +267 -163
  80. data/.document +0 -5
  81. data/VERSION +0 -1
  82. data/cookbooks/cucumber-chef/README.rdoc +0 -8
  83. data/cookbooks/cucumber-chef/files/default/add-git-identity +0 -2
  84. data/cookbooks/cucumber-chef/files/default/controller-first-boot +0 -1
  85. data/cookbooks/cucumber-chef/files/default/cucumber-private-key +0 -27
  86. data/cookbooks/cucumber-chef/files/default/cucumber-run_list +0 -1
  87. data/cookbooks/cucumber-chef/files/default/git-private-key +0 -27
  88. data/cookbooks/cucumber-chef/files/default/install-chef +0 -1
  89. data/cookbooks/cucumber-chef/files/default/lxc-controller-network-config +0 -5
  90. data/cookbooks/cucumber-chef/files/default/lxc-lucid-chef +0 -378
  91. data/cookbooks/cucumber-chef/metadata.rb +0 -6
  92. data/cookbooks/cucumber-chef/recipes/controller.rb +0 -51
  93. data/cookbooks/cucumber-chef/recipes/lxc.rb +0 -35
  94. data/cookbooks/cucumber-chef/recipes/test_lab.rb +0 -23
  95. data/cookbooks/cucumber-chef/recipes/testrunner.rb +0 -46
  96. data/cookbooks/cucumber-chef/roles/controller.rb +0 -7
  97. data/cookbooks/cucumber-chef/roles/test_lab_test.rb +0 -9
  98. data/cookbooks/cucumber-chef/templates/default/controller-client.erb +0 -5
  99. data/cookbooks/cucumber-chef/templates/default/lxc-lucid-chef +0 -385
  100. data/lib/cucumber/chef/handy.rb +0 -90
  101. data/lib/cucumber/chef/templates/controller.erb +0 -35
  102. data/lib/cucumber/chef/templates/env.rb +0 -16
  103. data/lib/cucumber/chef/templates/example_feature.erb +0 -11
  104. data/lib/cucumber/chef/templates/example_step.erb +0 -19
  105. data/lib/cucumber/chef/templates/readme.erb +0 -14
  106. data/lib/cucumber/chef/templates/ubuntu10.04-gems.erb +0 -43
  107. data/lib/cucumber/ec2_server_create.rb +0 -99
  108. data/website/website.html +0 -385
data/lib/cucumber/chef.rb CHANGED
@@ -1,33 +1,66 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
1
22
  require 'readline'
2
23
  require 'socket'
3
24
  require 'stringio'
4
25
 
26
+ ################################################################################
27
+
5
28
  require 'chef'
6
29
  require 'chef/cookbook_uploader'
7
- require 'chef/knife'
8
- require 'chef/knife/bootstrap'
9
- require 'chef/knife/core/bootstrap_context'
10
- require 'chef/knife/ssh'
30
+ require 'erubis'
11
31
  require 'fog'
12
- require 'net/scp'
13
- require 'net/ssh/multi'
32
+ require 'json'
33
+ require 'mixlib/config'
34
+ require 'net/ssh'
35
+ require 'net/ssh/proxy/command'
36
+ require 'net/sftp'
37
+ require 'ubuntu_ami'
38
+
39
+ ################################################################################
14
40
 
15
41
  module Cucumber
16
42
  module Chef
17
- class Error < StandardError ; end
18
-
19
- autoload :Config, "cucumber/chef/config"
20
- autoload :Provisioner, "cucumber/chef/provisioner"
21
- autoload :TestLab, "cucumber/chef/test_lab"
22
- autoload :TestRunner, "cucumber/chef/test_runner"
43
+
44
+ class Error < StandardError; end
45
+
46
+ require 'cucumber/chef/utility'
47
+ extend(Cucumber::Chef::Utility)
48
+
23
49
  end
24
50
  end
25
51
 
26
- begin
27
- require 'cucumber/chef/version'
28
- rescue LoadError => e
29
- dep = e.message.split.last
30
- puts "You don't appear to have #{dep} installed."
31
- puts "Perhaps run `gem bundle` or `gem install #{dep}`?"
32
- exit 2
33
- end
52
+ ################################################################################
53
+
54
+ require 'cucumber/chef/bootstrap'
55
+ require 'cucumber/chef/command'
56
+ require 'cucumber/chef/config'
57
+ require 'cucumber/chef/logger'
58
+ require 'cucumber/chef/provisioner'
59
+ require 'cucumber/chef/ssh'
60
+ require 'cucumber/chef/tcp_socket'
61
+ require 'cucumber/chef/template'
62
+ require 'cucumber/chef/test_lab'
63
+ require 'cucumber/chef/test_runner'
64
+ require 'cucumber/chef/version'
65
+
66
+ ################################################################################
data/lib/cucumber-chef.rb CHANGED
@@ -1 +1,24 @@
1
- require 'cucumber/chef' # compat
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ require 'cucumber/chef'
23
+
24
+ ################################################################################
@@ -1,114 +1,180 @@
1
- require File.join(File.dirname(__FILE__), "../../spec_helper.rb")
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ require 'spec_helper'
23
+
24
+ VALID_RELEASES = %w( precise )
25
+ VALID_REGIONS = %w( us-west-1 us-east-1 eu-west-1 )
26
+ VALID_ARCHS = %w( i386 amd64 )
27
+ VALID_DISK_STORES = %w( instance-store ebs )
2
28
 
3
29
  describe Cucumber::Chef::Config do
4
- before(:all) do
5
- @orgname = ENV["ORGNAME"]
6
- @opscode_user = ENV["OPSCODE_USER"]
30
+
31
+ ################################################################################
32
+
33
+ before(:each) do
34
+ load File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "cucumber", "chef", "config.rb"))
7
35
  end
8
36
 
9
37
  after(:each) do
10
- ENV["ORGNAME"] = @orgname
11
- ENV["OPSCODE_USER"] = @opscode_user
38
+ load File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb"))
12
39
  end
13
40
 
14
- describe "verification" do
15
- describe "when ORGNAME is not set" do
16
- it "should raise" do
17
- ENV["ORGNAME"] = ""
18
- expect {
19
- subject.verify
20
- }.to raise_error(Cucumber::Chef::ConfigError, /ORGNAME/)
21
- end
41
+ ################################################################################
42
+
43
+ describe "Cucumber::Chef::Config default values" do
44
+
45
+ it "Cucumber::Chef::Config[:mode] defaults to :user" do
46
+ Cucumber::Chef::Config[:mode].should == :user
22
47
  end
23
48
 
24
- describe "when OPSCODE_USER is not set" do
25
- it "should raise" do
26
- ENV["OPSCODE_USER"] = ""
27
- expect {
28
- subject.verify
29
- }.to raise_error(Cucumber::Chef::ConfigError, /OPSCODE_USER/)
30
- end
49
+ it "Cucumber::Chef::Config[:provider] defaults to :aws" do
50
+ Cucumber::Chef::Config[:provider].should == :aws
31
51
  end
32
52
 
33
- describe "when configuration is invalid" do
34
- it "should complain about missing keys" do
35
- subject.config[:chef_server_url] = nil
36
- subject.config[:knife][:aws_access_key_id] = nil
37
- expect {
38
- subject.verify
39
- }.to raise_error(Cucumber::Chef::ConfigError, /chef_server_url.*aws_access_key_id/)
53
+ context "Cucumber::Chef::Config[:aws] default values" do
54
+
55
+ it "Cucumber::Chef::Config[:aws][:aws_security_group] defaults to 'cucumber-chef'" do
56
+ Cucumber::Chef::Config[:aws][:aws_security_group].should == "cucumber-chef"
40
57
  end
41
-
42
- describe "when node name is invalid" do
43
- it "should raise" do
44
- ENV["OPSCODE_USER"] = "REALLYBOGUSORGNAME"
45
- expect {
46
- subject.verify
47
- }.to raise_error(Cucumber::Chef::ConfigError, /Opscode platform credentials/)
48
- end
58
+
59
+ it "Cucumber::Chef::Config[:aws][:ubuntu_release] defaults to 'precise'" do
60
+ Cucumber::Chef::Config[:aws][:ubuntu_release].should == "precise"
49
61
  end
50
-
51
- describe "when aws_access_key_id is empty" do
52
- it "should raise" do
53
- subject.config[:knife][:aws_access_key_id] = "bogus"
54
- expect {
55
- subject.verify
56
- }.to raise_error(Cucumber::Chef::ConfigError, /AWS credentials/)
57
- end
62
+
63
+ it "Cucumber::Chef::Config[:aws][:aws_instance_arch] defaults to 'i386'" do
64
+ Cucumber::Chef::Config[:aws][:aws_instance_arch].should == "i386"
65
+ end
66
+
67
+ it "Cucumber::Chef::Config[:aws][:aws_instance_disk_store] defaults to 'ebs'" do
68
+ Cucumber::Chef::Config[:aws][:aws_instance_disk_store].should == "ebs"
58
69
  end
59
- end
60
70
 
61
- describe "when configuration is valid" do
62
- it "should not raise" do
63
- subject.verify
71
+ it "Cucumber::Chef::Config[:aws][:aws_instance_type] defaults to 'm1.small'" do
72
+ Cucumber::Chef::Config[:aws][:aws_instance_type].should == "m1.small"
64
73
  end
74
+
65
75
  end
76
+
66
77
  end
67
78
 
68
- describe "when knife.rb is missing" do
69
- it "should raise" do
70
- begin
71
- chef_dir = Pathname("~/.chef").expand_path
72
- (chef_dir + "knife.rb").rename(chef_dir + "knife.rb.bak")
73
- config_file = chef_dir + "knife.rb"
74
- expect { subject.config }.to raise_error(Cucumber::Chef::ConfigError)
75
- ensure
76
- (chef_dir + "knife.rb.bak").rename(chef_dir + "knife.rb")
79
+ ################################################################################
80
+
81
+ describe "class method: aws_image_id" do
82
+
83
+ it "should return ami_image_id if Cucumber::Chef::Config[:aws][:aws_image_id] is set" do
84
+ aws_image_id = "ami-12345678"
85
+ Cucumber::Chef::Config[:aws][:aws_image_id] = aws_image_id
86
+ Cucumber::Chef::Config.aws_image_id.should == aws_image_id
87
+ end
88
+
89
+ VALID_RELEASES.each do |release|
90
+ VALID_REGIONS.each do |region|
91
+ VALID_ARCHS.each do |arch|
92
+ VALID_DISK_STORES.each do |disk_store|
93
+
94
+ it "should return an ami_image_id if release='#{release}', region='#{region}', arch='#{arch}', disk_store='#{disk_store}'" do
95
+ Cucumber::Chef::Config[:aws][:ubuntu_release] = release
96
+ Cucumber::Chef::Config[:aws][:region] = region
97
+ Cucumber::Chef::Config[:aws][:aws_instance_arch] = arch
98
+ Cucumber::Chef::Config[:aws][:aws_instance_disk_store] = disk_store
99
+
100
+ expect{ Cucumber::Chef::Config.aws_image_id }.to_not raise_error(Cucumber::Chef::ConfigError)
101
+ end
102
+
103
+ end
104
+ end
77
105
  end
78
106
  end
107
+
79
108
  end
80
109
 
110
+ ################################################################################
111
+
81
112
  describe "when configuration is valid" do
82
- it "should list the configuration values" do
83
- output = subject.list.join("\n")
84
- output.should match(/node_name:/)
85
- output.should match(/knife\[:aws_secret_access_key\]:/)
86
- end
87
113
 
88
- it "should return the configuration values" do
89
- subject[:node_name].should == @opscode_user
90
- subject[:knife][:ssh_user].should == "ubuntu"
114
+ it "should allow changing providers" do
115
+ Cucumber::Chef::Config[:provider] = :aws
116
+ expect{ Cucumber::Chef::Config.verify_keys }.to_not raise_error(Cucumber::Chef::ConfigError)
117
+
118
+ Cucumber::Chef::Config[:provider] = :vagrant
119
+ expect{ Cucumber::Chef::Config.verify_keys }.to_not raise_error(Cucumber::Chef::ConfigError)
91
120
  end
92
121
 
93
- it "should allow setting configuration values" do
94
- subject[:mode] = "blah"
95
- subject[:knife][:aws_access_key_id] = "bogus"
96
- subject[:mode].should == "blah"
97
- subject[:knife][:aws_access_key_id].should == "bogus"
122
+ it "should allow changing modes" do
123
+ Cucumber::Chef::Config[:mode] = :test
124
+ expect{ Cucumber::Chef::Config.verify_keys }.to_not raise_error(Cucumber::Chef::ConfigError)
125
+
126
+ Cucumber::Chef::Config[:mode] = :user
127
+ expect{ Cucumber::Chef::Config.verify_keys }.to_not raise_error(Cucumber::Chef::ConfigError)
98
128
  end
99
129
 
100
- it "should provide a method for getting a test mode configuration" do
101
- config = Cucumber::Chef::Config.test_config
102
- config[:mode].should == "test"
130
+ # this explodes in CI because we won't have our secret values set
131
+ context "when provider is aws" do
132
+ it "should verify the configuration" do
133
+ user = ENV['OPSCODE_USER'] || ENV['USER']
134
+ Cucumber::Chef::Config[:provider] = :aws
135
+ Cucumber::Chef::Config[:aws][:aws_access_key_id] = ENV['AWS_ACCESS_KEY_ID']
136
+ Cucumber::Chef::Config[:aws][:aws_secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']
137
+ Cucumber::Chef::Config[:aws][:aws_ssh_key_id] = ENV['AWS_SSH_KEY_ID'] || user
138
+ Cucumber::Chef::Config[:aws][:identity_file] = "#{ENV['HOME']}/.chef/#{user}.pem"
139
+ Cucumber::Chef::Config[:aws][:region] = "us-west-2"
140
+ Cucumber::Chef::Config[:aws][:availability_zone] = "us-west-2a"
141
+ expect{ Cucumber::Chef::Config.verify }.to_not raise_error(Cucumber::Chef::ConfigError)
142
+ end
143
+ end if !ENV['CI'] && !ENV['TRAVIS']
144
+
145
+ end
146
+
147
+ ################################################################################
148
+
149
+ describe "when configuration is invalid" do
150
+
151
+ it "should complain about missing configuration keys" do
152
+ Cucumber::Chef::Config[:provider] = nil
153
+ expect{ Cucumber::Chef::Config.verify_keys }.to raise_error(Cucumber::Chef::ConfigError)
154
+
155
+ Cucumber::Chef::Config[:mode] = nil
156
+ expect{ Cucumber::Chef::Config.verify_keys }.to raise_error(Cucumber::Chef::ConfigError)
103
157
  end
104
158
 
105
- it "should know it is in test mode" do
106
- Cucumber::Chef::Config.test_config.test_mode?.should be
159
+ it "should complain about invalid configuration key values" do
160
+ Cucumber::Chef::Config[:provider] = :awss
161
+ expect{ Cucumber::Chef::Config.verify_keys }.to raise_error(Cucumber::Chef::ConfigError)
162
+
163
+ Cucumber::Chef::Config[:mode] = :userr
164
+ expect{ Cucumber::Chef::Config.verify_keys }.to raise_error(Cucumber::Chef::ConfigError)
107
165
  end
108
166
 
109
- it "should know it is not in test_mode" do
110
- Cucumber::Chef::Config.new.test_mode?.should_not be
167
+ describe "when provider is aws" do
168
+
169
+ it "should complain about missing provider configuration keys" do
170
+ Cucumber::Chef::Config[:provider] = :aws
171
+ expect{ Cucumber::Chef::Config.verify_provider_keys }.to raise_error(Cucumber::Chef::ConfigError)
172
+ end
173
+
111
174
  end
175
+
112
176
  end
113
- end
114
177
 
178
+ ################################################################################
179
+
180
+ end
@@ -1,10 +1,35 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ require 'spec_helper'
23
+ =begin
1
24
  require File.join(File.dirname(__FILE__), "../../spec_helper.rb")
2
25
 
3
26
  describe Cucumber::Chef::Provisioner do
4
27
  before(:all) do
5
- @config = Cucumber::Chef::Config.test_config
28
+ @config = Cucumber::Chef::Config.test_config(StringIO.new, StringIO.new, StringIO.new)
6
29
  end
7
30
 
31
+ subject { Cucumber::Chef::Provisioner.new(@config, StringIO.new, StringIO.new, StringIO.new) }
32
+
8
33
  describe "upload_cookbook" do
9
34
  before(:each) do
10
35
  begin
@@ -18,7 +43,7 @@ describe Cucumber::Chef::Provisioner do
18
43
  end
19
44
 
20
45
  it "should upload the cucumber-chef cookbook" do
21
- subject.upload_cookbook(@config)
46
+ subject.upload_cookbook
22
47
  ::Chef::CookbookVersion.list["cucumber-chef"].should be
23
48
  end
24
49
  end
@@ -28,38 +53,57 @@ describe Cucumber::Chef::Provisioner do
28
53
  begin
29
54
  role_path = File.expand_path("cookbooks/cucumber-chef/roles")
30
55
  ::Chef::Config[:role_path] = role_path
31
- role = ::Chef::Role.from_disk("test_lab_test")
56
+ role = ::Chef::Role.from_disk("test_lab")
32
57
  role.destroy
33
58
  rescue Net::HTTPServerException => err
34
59
  end
35
60
  end
36
61
 
37
62
  it "should upload the test_lab role" do
38
- subject.upload_role(@config)
39
- ::Chef::Role.list["test_lab_test"].should be
63
+ subject.upload_role
64
+ ::Chef::Role.list["test_lab"].should be
40
65
  end
41
66
  end
42
67
 
43
68
  describe "bootstrap_node" do
69
+ before(:all) do
70
+ subject.upload_cookbook
71
+ subject.upload_role
72
+ end
73
+
44
74
  before(:each) do
45
- @test_lab = Cucumber::Chef::TestLab.new(@config)
75
+ @test_lab = Cucumber::Chef::TestLab.new(@config, StringIO.new, StringIO.new, StringIO.new)
46
76
  @test_lab.destroy
47
- server = subject.build_test_lab(@config, StringIO.new)
48
- @dns_name = server.dns_name
49
- sleep(10)
50
- subject.upload_cookbook(@config)
51
- subject.upload_role(@config)
77
+ begin
78
+ @server = @test_lab.create
79
+ rescue
80
+ puts("Output from #create:")
81
+ subject.stdout.rewind
82
+ puts(subject.stdout.read)
83
+ raise
84
+ end
52
85
  end
53
-
86
+
54
87
  after(:each) do
55
88
  @test_lab.destroy
56
89
  end
57
90
 
58
- it "should assign a random name to the node" do
59
- subject.bootstrap_node(@dns_name, @config)
60
- @test_lab.nodes.detect do |node|
91
+ it "should assign a random name to the node", :slow => true do
92
+ begin
93
+ subject.bootstrap_node(@server)
94
+ rescue
95
+ subject.stdout.rewind; subject.stderr.rewind
96
+ puts("Output from #bootstrap_node:")
97
+ puts(" STDOUT:\n", subject.stdout.read, "\n\n")
98
+ puts(" STDERR:\n", subject.stderr.read, "\n\n")
99
+ raise
100
+ end
101
+ sleep(30)
102
+ found_node = !!@test_lab.nodes.detect do |node|
61
103
  node.name.match /^cucumber-chef-[0-9a-f]{8}$/
62
- end.should be
104
+ end
105
+ found_node.should be
63
106
  end
64
107
  end
65
108
  end
109
+ =end
@@ -1,47 +1,90 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
21
+
22
+ require 'spec_helper'
23
+ =begin
1
24
  require File.join(File.dirname(__FILE__), "../../spec_helper.rb")
2
25
 
3
26
  describe Cucumber::Chef::TestLab do
4
27
  before(:all) do
5
- @config = Cucumber::Chef::Config.test_config
28
+ @config = Cucumber::Chef::Config.test_config(StringIO.new, StringIO.new, StringIO.new)
29
+ end
30
+
31
+ subject { Cucumber::Chef::TestLab.new(@config, StringIO.new, StringIO.new, StringIO.new) }
32
+
33
+ it "should create a cucumber-chef security group" do
34
+ existing_group = subject.connection.security_groups.get("cucumber-chef")
35
+ existing_group && existing_group.destroy
36
+ subject.connection.security_groups.get("cucumber-chef").should_not be
37
+ lab = Cucumber::Chef::TestLab.new(@config, StringIO.new, StringIO.new, StringIO.new)
38
+ permissions = lab.connection.security_groups.get("cucumber-chef").ip_permissions
39
+ permissions.size.should == 1
40
+ permissions.first["fromPort"].should == 22
41
+ permissions.first["toPort"].should == 22
42
+ permissions.first["fromPort"].should == 4000
43
+ permissions.first["toPort"].should == 4000
44
+ permissions.first["fromPort"].should == 4040
45
+ permissions.first["toPort"].should == 4040
6
46
  end
7
47
 
8
- subject { Cucumber::Chef::TestLab.new(@config) }
9
-
10
48
  describe "with no running labs" do
11
49
  it "should not return any info" do
12
- subject.info.should == ""
50
+ subject.info
51
+ subject.stdout.rewind
52
+ subject.stdout.read.should match(/no test labs/)
13
53
  end
14
54
  end
15
55
 
16
- describe "build" do
56
+ describe "create" do
17
57
  after(:each) { subject.destroy }
18
58
 
19
59
  it "should spin up an ec2 instance", :slow => true do
20
- output = StringIO.new
21
- subject.build(output)
22
- output.rewind
23
- output.read.should match(/Platform provisioned/)
60
+ subject.create
61
+ subject.stdout.rewind
62
+ subject.stdout.read.should match(/Instance provisioned/)
24
63
  end
25
64
 
26
- it "should only spin up one ec2 instance", :slow => true do
27
- subject.build(StringIO.new)
28
- expect {
29
- subject.build(StringIO.new)
30
- }.to raise_error(Cucumber::Chef::TestLabError)
65
+ it "should attempt reprovision if ec2 instance already exists", :slow => true do
66
+ subject.create
67
+ subject.stdout.truncate(0)
68
+ subject.create
69
+ subject.stdout.rewind
70
+ subject.stdout.read.should match(/attempting to reprovision/)
31
71
  end
32
72
 
33
73
  it "should report its public ip address", :slow => true do
34
- server = subject.build(StringIO.new)
35
- subject.info.should == server.public_ip_address
74
+ server = subject.create
75
+ subject.info
76
+ subject.stdout.rewind
77
+ subject.stdout.read.should match(/#{server.public_ip_address}/)
36
78
  end
37
79
  end
38
80
 
39
81
  describe "destroy" do
40
82
  it "should destroy the running ec2 instance", :slow => true do
41
- subject.build(StringIO.new)
83
+ server = subject.create
42
84
  subject.destroy
43
- subject.exists?.should_not be
85
+ subject.stdout.rewind
86
+ subject.stdout.read.should match(/Destroying Server: #{server.public_ip_address}/)
44
87
  end
45
88
  end
46
89
  end
47
-
90
+ =end
data/spec/spec_helper.rb CHANGED
@@ -1,28 +1,32 @@
1
- require "rubygems"
2
- require "bundler/setup"
3
- require File.join(File.dirname(__FILE__), "../lib/cucumber-chef")
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
6
+ # License: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ ################################################################################
4
21
 
5
- def tcp_test_ssh(hostname)
6
- tcp_socket = TCPSocket.new(hostname, 22)
7
- IO.select([tcp_socket], nil, nil, 5)
8
- rescue Errno::ETIMEDOUT
9
- false
10
- rescue Errno::EPERM
11
- false
12
- rescue Errno::ECONNREFUSED
13
- sleep 2
14
- false
15
- # This happens on EC2 quite often
16
- rescue Errno::EHOSTUNREACH
17
- sleep 2
18
- false
19
- ensure
20
- tcp_socket && tcp_socket.close
21
- end
22
+ require 'cucumber-chef'
22
23
 
23
- %w{ORGNAME OPSCODE_USER}.each do |var|
24
- if ENV[var].nil? || ENV[var].empty?
25
- warn "Specs require the environment variables $ORGNAME and $OPSCODE_USER to be set."
26
- exit 1
27
- end
28
- end
24
+ dev_null = File.open("/dev/null", "w")
25
+ $logger = Cucumber::Chef::Logger.new(dev_null)
26
+
27
+ require 'simplecov'
28
+ SimpleCov.start do
29
+ add_filter '/spec/'
30
+ end if ENV["COVERAGE"]
31
+
32
+ ################################################################################