cucumber-chef 2.1.0.rc.15 → 3.0.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 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
+ module Cucumber
23
+ module Chef
24
+
25
+ class EcosystemError < Error; end
26
+
27
+ class Ecosystem < ZTK::DSL::Base
28
+ belongs_to :labfile, :class_name => "Cucumber::Chef:Labfile"
29
+ has_many :containers, :class_name => "Cucumber::Chef::Container"
30
+
31
+ attribute :name
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ ################################################################################
@@ -0,0 +1,34 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
+ # Author: Zachary Patten <zachary@jovelabs.com>
5
+ # Copyright: Copyright (c) 2011-2013 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
+ module Cucumber
23
+ module Chef
24
+
25
+ class LabfileError < Error; end
26
+
27
+ class Labfile < ZTK::DSL::Base
28
+ has_many :ecosystems, :class_name => "Cucumber::Chef::Ecosystem"
29
+ end
30
+
31
+ end
32
+ end
33
+
34
+ ################################################################################
@@ -47,12 +47,9 @@ module Cucumber
47
47
  wait_for_chef_server
48
48
 
49
49
  download_chef_credentials
50
- render_knife_rb
51
50
 
52
51
  upload_cookbook
53
52
  upload_role
54
- tag_node
55
- add_node_role
56
53
 
57
54
  chef_first_run
58
55
 
@@ -110,10 +107,10 @@ module Cucumber
110
107
 
111
108
  def download_chef_credentials
112
109
  ZTK::Benchmark.bench(:message => "Downloading chef-server credentials", :mark => "completed in %0.4f seconds.", :ui => @ui) do
113
- local_path = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s)
110
+ local_path = File.dirname(Cucumber::Chef.chef_identity)
114
111
  remote_path = File.join(Cucumber::Chef.lab_user_home_dir, ".chef")
115
112
 
116
- files = [ "#{Cucumber::Chef::Config[:user]}.pem", "validation.pem" ]
113
+ files = [ File.basename(Cucumber::Chef.chef_identity), "validation.pem" ]
117
114
  files.each do |file|
118
115
  @test_lab.bootstrap_ssh.download(File.join(remote_path, file), File.join(local_path, file))
119
116
  end
@@ -137,24 +134,6 @@ module Cucumber
137
134
  end
138
135
  end
139
136
 
140
- ################################################################################
141
-
142
- def render_knife_rb
143
- ZTK::Benchmark.bench(:message => "Building 'cc-knife' configuration", :mark => "completed in %0.4f seconds.", :ui => @ui) do
144
- template_file = File.join(Cucumber::Chef.root_dir, "lib", "cucumber", "chef", "templates", "cucumber-chef", "knife-rb.erb")
145
-
146
- context = {
147
- :chef_server => @test_lab.ip,
148
- :librarian_chef => Cucumber::Chef::Config.librarian_chef,
149
- :user => Cucumber::Chef::Config.user
150
- }
151
-
152
- File.open(Cucumber::Chef.knife_rb, 'w') do |f|
153
- f.puts(ZTK::Template.render(template_file, context))
154
- end
155
- end
156
- end
157
-
158
137
  ################################################################################
159
138
 
160
139
  def upload_cookbook
@@ -173,29 +152,13 @@ module Cucumber
173
152
  end
174
153
  end
175
154
 
176
- ################################################################################
177
-
178
- def tag_node
179
- @ui.logger.debug { "Tagging cucumber-chef test lab node..." }
180
- ZTK::Benchmark.bench(:message => "Tagging 'cucumber-chef' node", :mark => "completed in %0.4f seconds.", :ui => @ui) do
181
- @test_lab.knife_cli(%Q{tag create #{Cucumber::Chef.lab_hostname_full} #{Cucumber::Chef::Config.mode}}, :silence => true)
182
- end
183
- end
184
-
185
- ################################################################################
186
-
187
- def add_node_role
188
- @ui.logger.debug { "Setting up cucumber-chef test lab run list..." }
189
- ZTK::Benchmark.bench(:message => "Setting 'cucumber-chef' run list", :mark => "completed in %0.4f seconds.", :ui => @ui) do
190
- @test_lab.knife_cli(%Q{node run_list add #{Cucumber::Chef.lab_hostname_full} "role[test_lab]"}, :silence => true)
191
- end
192
- end
193
-
194
155
  ################################################################################
195
156
 
196
157
  def chef_first_run
197
158
  ZTK::Benchmark.bench(:message => "Performing chef-client run", :mark => "completed in %0.4f seconds.", :ui => @ui) do
198
- command = "/usr/bin/chef-client -j /etc/chef/first-boot.json -l debug"
159
+ log_level = (ENV['LOG_LEVEL'].downcase rescue (Cucumber::Chef.is_rc? ? "debug" : "info"))
160
+
161
+ command = "/usr/bin/chef-client -j /etc/chef/first-boot.json --log_level #{log_level} --once"
199
162
  command = "sudo #{command}"
200
163
  @test_lab.bootstrap_ssh.exec(command, :silence => true)
201
164
  end
@@ -21,7 +21,6 @@
21
21
 
22
22
  require 'cucumber/chef/steps/chef_steps'
23
23
  require 'cucumber/chef/steps/minitest_steps'
24
- require 'cucumber/chef/steps/provision_steps'
25
24
  require 'cucumber/chef/steps/ssh_steps'
26
25
 
27
26
  ################################################################################
@@ -75,9 +75,9 @@ end
75
75
 
76
76
  Then /^I should( not)? see the "([^\"]*)" of "([^\"]*)" in the output$/ do |boolean, key, name|
77
77
  if (!boolean)
78
- @output.should =~ /#{$test_lab.containers.to_a[name][key.downcase.to_sym]}/i
78
+ @output.should =~ /#{Cucumber::Chef::Containers.all.select{|c| c.name == name}.first.send(key.downcase.to_sym)}/i
79
79
  else
80
- @output.should_not =~ /#{$test_lab.containers.to_a[name][key.downcase.to_sym]}/i
80
+ @output.should_not =~ /#{Cucumber::Chef::Containers.all.select{|c| c.name == name}.first.send(key.downcase.to_sym)}/i
81
81
  end
82
82
  end
83
83
 
@@ -31,7 +31,10 @@ chef-solr chef-solr/amqp_password password <%= @amqp_password %>
31
31
  chef-server-webui chef-server-webui/admin_password password <%= @admin_password %>
32
32
  EOF
33
33
 
34
- apt-get -q -y --force-yes install chef chef-server
34
+ CHEF_VERSION=`apt-cache showpkg chef | tee | grep -m 1 "<%= @chef_version %>" | cut -c -<%= @chef_version.length + 3 %>`
35
+ CHEF_SERVER_VERSION=`apt-cache showpkg chef-server | tee | grep -m 1 "<%= @chef_version %>" | cut -c -<%= @chef_version.length + 3 %>`
36
+
37
+ apt-get -q -y --force-yes install chef=$CHEF_VERSION chef-server=$CHEF_SERVER_VERSION
35
38
 
36
39
  echo -n "Waiting on validation.pem and webui.pem to appear..."
37
40
  until [ -f /etc/chef/validation.pem ] && [ -f /etc/chef/webui.pem ]; do
@@ -1,2 +1,2 @@
1
1
  ---
2
- default: -c -v
2
+ default: --color --verbose --backtrace --exclude support/cookbooks --exclude support/data_bags --exclude support/environments --exclude support/keys --exclude support/roles --format pretty
@@ -19,7 +19,7 @@
19
19
  ################################################################################
20
20
 
21
21
  tag = Cucumber::Chef.tag("cucumber-chef")
22
- puts(" * #{tag}")
22
+ puts(">>> #{tag}")
23
23
  Cucumber::Chef.boot(tag)
24
24
 
25
25
  $ui = ZTK::UI.new(:logger => Cucumber::Chef.logger)
@@ -31,40 +31,53 @@ end
31
31
 
32
32
  if ENV['PURGE'] == 'YES'
33
33
  $ui.logger.warn { "PURGING CONTAINERS! Container attributes will be reset!" }
34
- $test_lab.containers.load
35
-
36
- $test_lab.containers.to_a.each do |name, value|
37
- $test_lab.containers.destroy(name)
34
+ $test_lab.containers.list.each do |name|
35
+ ZTK::Benchmark.bench(:message => ">>> Destroying container '#{name}'", :mark => "completed in %0.4f seconds.") do
36
+ $test_lab.containers.destroy(name)
37
+ end
38
38
  end
39
-
40
- File.exists?(Cucumber::Chef.containers_bin) && File.delete(Cucumber::Chef.containers_bin)
41
- $test_lab.containers.load
42
39
  else
43
40
  $ui.logger.info { "Allowing existing containers to persist." }
44
41
  end
45
42
 
46
- if ENV['PUSH'] == 'YES'
43
+ $test_lab.containers.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
44
+ :validation_client_name => "chef-validator")
45
+
46
+ if ENV['SETUP'] == 'YES'
47
47
  # Upload all of the chef-repo environments
48
- puts(" * Pushing chef-repo environments to test lab...")
49
- $test_lab.knife_cli(%Q{environment from file ./environments/*.rb --yes}, :silence => true)
48
+ ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo environments to the test lab", :mark => "completed in %0.4f seconds.") do
49
+ $test_lab.knife_cli(%Q{environment from file ./environments/*.rb}, :silence => true)
50
+ end
50
51
 
51
52
  # Upload all of the chef-repo cookbooks
52
- puts(" * Pushing chef-repo cookbooks to test lab...")
53
- cookbook_paths = ["./cookbooks"]
54
- cookbook_paths << "./site-cookbooks" if Cucumber::Chef::Config.librarian_chef
55
- $test_lab.knife_cli(%Q{cookbook upload --all --cookbook-path #{cookbook_paths.join(':')} --force --yes}, :silence => true)
53
+ ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo cookbooks to the test lab", :mark => "completed in %0.4f seconds.") do
54
+ cookbook_paths = ["./cookbooks"]
55
+ cookbook_paths << "./site-cookbooks" if Cucumber::Chef::Config.librarian_chef
56
+ $test_lab.knife_cli(%Q{cookbook upload --all --cookbook-path #{cookbook_paths.join(':')} --force}, :silence => true)
57
+ end
56
58
 
57
59
  # Upload all of the chef-repo roles
58
- puts(" * Pushing chef-repo roles to test lab...")
59
- $test_lab.knife_cli(%Q{role from file ./roles/*.rb --yes}, :silence => true)
60
+ ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo roles to the test lab", :mark => "completed in %0.4f seconds.") do
61
+ $test_lab.knife_cli(%Q{role from file ./roles/*.rb}, :silence => true)
62
+ end
60
63
 
61
64
  # Upload all of our chef-repo data bags
62
65
  Dir.glob("./data_bags/*").each do |data_bag_path|
63
66
  next if !File.directory?(data_bag_path)
64
- puts(" * Pushing chef-repo data bag '#{File.basename(data_bag_path)}' to test lab...")
65
- data_bag = File.basename(data_bag_path)
66
- $test_lab.knife_cli(%Q{data bag create "#{data_bag}" --yes}, :silence => true)
67
- $test_lab.knife_cli(%Q{data bag from file "#{data_bag}" "#{data_bag_path}" --yes}, :silence => true)
67
+ ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo data bag '#{File.basename(data_bag_path)}' to the test lab", :mark => "completed in %0.4f seconds.") do
68
+ data_bag = File.basename(data_bag_path)
69
+ $test_lab.knife_cli(%Q{data bag create "#{data_bag}"}, :silence => true)
70
+ $test_lab.knife_cli(%Q{data bag from file "#{data_bag}" "#{data_bag_path}"}, :silence => true)
71
+ end
72
+ end
73
+
74
+ Cucumber::Chef::Container.all.each do |container|
75
+ ZTK::Benchmark.bench(:message => ">>> Creating container '#{container.name}'", :mark => "completed in %0.4f seconds.") do
76
+ $test_lab.containers.create(container)
77
+ end
78
+ ZTK::Benchmark.bench(:message => ">>> Provisioning container '#{container.name}'", :mark => "completed in %0.4f seconds.") do
79
+ $test_lab.containers.chef_run_client(container)
80
+ end
68
81
  end
69
82
  end
70
83
 
@@ -74,21 +87,9 @@ end
74
87
  ################################################################################
75
88
 
76
89
  Before do |scenario|
77
- $scenario = scenario
78
-
79
- $test_lab.containers.load
80
-
81
- $test_lab.containers.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
82
- :validation_client_name => "chef-validator")
83
90
  end
84
91
 
85
92
  After do |scenario|
86
- $test_lab.containers.save
87
-
88
- $test_lab.containers.to_a.select{ |name, attributes| !attributes[:persist] }.each do |name, attributes|
89
- server_destroy(name)
90
- end
91
-
92
93
  @connection and @connection.ssh.shutdown!
93
94
  end
94
95
 
@@ -91,8 +91,11 @@ module Cucumber
91
91
 
92
92
  arguments = Array.new
93
93
  arguments << "--user #{Cucumber::Chef::Config.user}"
94
+ arguments << "--key #{Cucumber::Chef.chef_identity}"
94
95
  arguments << "--server-url #{self.chef_server_api}"
95
- arguments << "--config #{Cucumber::Chef.knife_rb}" if File.exists?(Cucumber::Chef.knife_rb)
96
+ arguments << "--disable-editing"
97
+ arguments << "--yes"
98
+ arguments << "-VV" if Cucumber::Chef.is_rc?
96
99
 
97
100
  command = Cucumber::Chef.build_command("knife", args, arguments)
98
101
  ZTK::Command.new.exec(command, options)
@@ -136,18 +136,30 @@ module Cucumber
136
136
 
137
137
  ################################################################################
138
138
 
139
- def knife_rb
140
- knife_rb = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s, "knife.rb")
141
- FileUtils.mkdir_p(File.dirname(knife_rb))
142
- knife_rb
139
+ def labfile
140
+ labfile = File.join(Cucumber::Chef.chef_repo, "Labfile")
141
+ FileUtils.mkdir_p(File.dirname(labfile))
142
+ labfile
143
143
  end
144
144
 
145
145
  ################################################################################
146
146
 
147
- def containers_bin
148
- containers_bin = File.join(Cucumber::Chef.home_dir, "containers.bin")
149
- FileUtils.mkdir_p(File.dirname(containers_bin))
150
- containers_bin
147
+ # def knife_rb
148
+ # knife_rb = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s, "knife.rb")
149
+ # FileUtils.mkdir_p(File.dirname(knife_rb))
150
+ # knife_rb
151
+ # end
152
+
153
+ ################################################################################
154
+
155
+ def chef_user
156
+ Cucumber::Chef::Config.user
157
+ end
158
+
159
+ def chef_identity
160
+ chef_identity = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s, "#{chef_user}.pem")
161
+ FileUtils.mkdir_p(File.dirname(chef_identity))
162
+ chef_identity
151
163
  end
152
164
 
153
165
  ################################################################################
@@ -236,26 +248,7 @@ module Cucumber
236
248
  name and logger.info { "loading #{name}" }
237
249
  logger.info { "boot(#{Cucumber::Chef.config_rb})" }
238
250
  Cucumber::Chef::Config.load
239
- load_chef_config
240
- end
241
-
242
- ################################################################################
243
- # Load Chef::Config
244
- ################################################################################
245
-
246
- def load_chef_config
247
- if File.exists?(Cucumber::Chef.knife_rb)
248
- logger.info { "load_chef_config(#{Cucumber::Chef.knife_rb})" }
249
- ::Chef::Config.from_file(Cucumber::Chef.knife_rb)
250
-
251
- if (test_lab = (Cucumber::Chef::TestLab.new rescue nil)) && test_lab.alive?
252
- chef_server_url = "http://#{test_lab.ip}:4000"
253
- logger.info { "chef_server_url(#{chef_server_url})" }
254
- ::Chef::Config[:chef_server_url] = chef_server_url
255
- end
256
- else
257
- logger.warn { "knife config '#{Cucumber::Chef.knife_rb}' was missing!" }
258
- end
251
+ Cucumber::Chef::Labfile.load(Cucumber::Chef.labfile)
259
252
  end
260
253
 
261
254
  ################################################################################
@@ -267,13 +260,11 @@ module Cucumber
267
260
 
268
261
  dependencies = {
269
262
  "cucumber_chef_version" => Cucumber::Chef::VERSION.inspect,
270
- "chef_version" => ::Chef::VERSION.inspect,
271
263
  "fog_version" => ::Fog::VERSION.inspect,
272
264
  "ruby_version" => RUBY_VERSION.inspect,
273
265
  "ruby_patchlevel" => RUBY_PATCHLEVEL.inspect,
274
266
  "ruby_platform" => RUBY_PLATFORM.inspect,
275
267
  "ztk_version" => ::ZTK::VERSION.inspect
276
- # "cucumber_version" => ::Cucumber::VERSION.inspect
277
268
  }
278
269
  if RUBY_VERSION >= "1.9"
279
270
  dependencies.merge!("ruby_engine" => RUBY_ENGINE.inspect)
@@ -285,8 +276,7 @@ module Cucumber
285
276
  "chef_repo" => chef_repo.inspect,
286
277
  "log_file" => log_file.inspect,
287
278
  "config_rb" => config_rb.inspect,
288
- "knife_rb" => knife_rb.inspect,
289
- "containers_bin" => containers_bin.inspect
279
+ "labfile" => labfile.inspect
290
280
  }
291
281
 
292
282
  max_key_length = [dependencies.keys.collect{ |key| key.to_s.length }.max, details.keys.collect{ |key| key.to_s.length }.max].max + 2
@@ -24,7 +24,7 @@ module Cucumber
24
24
 
25
25
  ################################################################################
26
26
 
27
- VERSION = "2.1.0.rc.15" unless const_defined?(:VERSION)
27
+ VERSION = "3.0.0.rc.0" unless const_defined?(:VERSION)
28
28
 
29
29
  ################################################################################
30
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.rc.15
4
+ version: 3.0.0.rc.0
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,24 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-11 00:00:00.000000000 Z
13
+ date: 2013-02-13 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: chef
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: 0.10.0
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: 0.10.0
31
15
  - !ruby/object:Gem::Dependency
32
16
  name: fog
33
17
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +131,7 @@ dependencies:
147
131
  requirements:
148
132
  - - ! '>='
149
133
  - !ruby/object:Gem::Version
150
- version: 1.0.2
134
+ version: 1.0.3
151
135
  type: :runtime
152
136
  prerelease: false
153
137
  version_requirements: !ruby/object:Gem::Requirement
@@ -155,7 +139,7 @@ dependencies:
155
139
  requirements:
156
140
  - - ! '>='
157
141
  - !ruby/object:Gem::Version
158
- version: 1.0.2
142
+ version: 1.0.3
159
143
  - !ruby/object:Gem::Dependency
160
144
  name: simplecov
161
145
  requirement: !ruby/object:Gem::Requirement
@@ -280,9 +264,12 @@ files:
280
264
  - lib/cucumber/chef.rb
281
265
  - lib/cucumber/chef/client.rb
282
266
  - lib/cucumber/chef/config.rb
267
+ - lib/cucumber/chef/container.rb
283
268
  - lib/cucumber/chef/containers.rb
269
+ - lib/cucumber/chef/ecosystem.rb
284
270
  - lib/cucumber/chef/helpers.rb
285
271
  - lib/cucumber/chef/helpers/chef.rb
272
+ - lib/cucumber/chef/labfile.rb
286
273
  - lib/cucumber/chef/provider.rb
287
274
  - lib/cucumber/chef/providers/aws.rb
288
275
  - lib/cucumber/chef/providers/vagrant.rb
@@ -290,12 +277,10 @@ files:
290
277
  - lib/cucumber/chef/steps.rb
291
278
  - lib/cucumber/chef/steps/chef_steps.rb
292
279
  - lib/cucumber/chef/steps/minitest_steps.rb
293
- - lib/cucumber/chef/steps/provision_steps.rb
294
280
  - lib/cucumber/chef/steps/ssh_steps.rb
295
281
  - lib/cucumber/chef/templates/bootstrap/ubuntu-precise-test-lab.erb
296
282
  - lib/cucumber/chef/templates/cucumber-chef/config-rb.erb
297
283
  - lib/cucumber/chef/templates/cucumber-chef/cucumber-yml.erb
298
- - lib/cucumber/chef/templates/cucumber-chef/knife-rb.erb
299
284
  - lib/cucumber/chef/templates/cucumber/cc-hooks.rb
300
285
  - lib/cucumber/chef/templates/cucumber/env.rb
301
286
  - lib/cucumber/chef/templates/cucumber/example_feature.erb