cucumber-chef 2.1.0.rc.3 → 2.1.0.rc.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://secure.travis-ci.org/zpatten/cucumber-chef.png)](http://travis-ci.org/zpatten/cucumber-chef) [![Dependency Status](https://gemnasium.com/jovelabs/cucumber-chef.png)](https://gemnasium.com/jovelabs/cucumber-chef)
1
+ [![Build Status](https://secure.travis-ci.org/jovelabs/cucumber-chef.png)](http://travis-ci.org/jovelabs/cucumber-chef) [![Dependency Status](https://gemnasium.com/jovelabs/cucumber-chef.png)](https://gemnasium.com/jovelabs/cucumber-chef)
2
2
 
3
3
  Cucumber-chef is a library of tools to enable the emerging discipline of infrastructure as code to practice test driven development. It provides a testing platform within which Cucumber tests can be run which provision virtual machines, configure them by applying the appropriate Chef roles to them, and then run acceptance and integration tests against the environment.
4
4
 
data/bin/cc-knife CHANGED
@@ -13,13 +13,10 @@ if (test_lab = Cucumber::Chef::TestLab.new) && test_lab.alive?
13
13
 
14
14
  knife_rb = Cucumber::Chef.knife_rb
15
15
  if File.exists?(knife_rb)
16
- command = [knife, ARGV, "--server-url http://#{test_lab.ip}:4000", "--config #{knife_rb}", "2>&1"].flatten.compact.join(" ")
17
- puts(command)
18
- puts(%x(#{command}))
19
- exit($?.to_i)
16
+ test_lab.knife_cli([ARGV], :replace_current_process => true)
20
17
  else
21
18
  puts("Could not find your Cucumber-Chef 'knife.rb'. Did you setup your test lab?")
22
- exit(255)
19
+ exit(2)
23
20
  end
24
21
 
25
22
  else
data/bin/cucumber-chef CHANGED
@@ -205,8 +205,7 @@ class CucumberChef < Thor
205
205
  puts
206
206
 
207
207
  ZTK::Benchmark.bench(:message => "Start cc-server", :mark => "completed in %0.4f seconds.") do
208
- cc_server = Cucumber::Chef::Server.new(test_lab)
209
- cc_server.up(:silence => true)
208
+ test_lab.cc_client.up(:silence => true)
210
209
  end
211
210
 
212
211
  args.each do |container|
@@ -217,6 +216,11 @@ class CucumberChef < Thor
217
216
  test_lab.drb.save_containers
218
217
  end
219
218
  end
219
+
220
+ ZTK::Benchmark.bench(:message => "Stop cc-server", :mark => "completed in %0.4f seconds.") do
221
+ test_lab.cc_client.down
222
+ end
223
+
220
224
  else
221
225
  puts
222
226
  puts(set_color("Whew! That was close!", :green, true))
@@ -315,43 +319,49 @@ class CucumberChef < Thor
315
319
  if @options.containers?
316
320
  if test_lab.alive?
317
321
  ZTK::Benchmark.bench(:message => "Start cc-server", :mark => "completed in %0.4f seconds.") do
318
- test_lab.cc_server.up(:silence => true)
322
+ test_lab.cc_client.up(:silence => true)
319
323
  end
320
324
 
321
325
  test_lab.drb.load_containers
322
326
 
323
- headers = [:name, :alive, :arch, :distro, :ip, :mac, :"chef version", :persist]
324
- results = ZTK::Report.new.spreadsheet(test_lab.drb.containers, headers) do |name, detail|
325
- chef_version = "N/A"
326
- alive = (test_lab.drb.command_run_local(%Q{ping -n -c 1 -W 1 #{detail[:ip]}}, :ignore_exit_status => true).exit_code == 0)
327
- if alive
328
- chef_version = test_lab.drb.command_run_chroot(name, %Q{/usr/bin/env chef-client -v}, :ignore_exit_status => true).output.chomp
327
+ if test_lab.drb.containers.count > 0
328
+ headers = [:name, :alive, :arch, :distro, :ip, :mac, :"chef version", :persist]
329
+ results = ZTK::Report.new.spreadsheet(test_lab.drb.containers, headers) do |name, detail|
330
+ chef_version = "N/A"
331
+ alive = (test_lab.drb.command_run_local(%Q{ping -n -c 1 -W 1 #{detail[:ip]}}, :ignore_exit_status => true).exit_code == 0)
332
+ if alive
333
+ chef_version = test_lab.drb.command_run_chroot(name, %Q{/usr/bin/env chef-client -v}, :ignore_exit_status => true).output.chomp
334
+ end
335
+
336
+ OpenStruct.new(
337
+ :name => name,
338
+ :ip => detail[:ip],
339
+ :mac => detail[:mac],
340
+ :distro => detail[:distro],
341
+ :arch => detail[:arch],
342
+ :alive => alive,
343
+ :"chef version" => chef_version,
344
+ :persist => detail[:persist],
345
+ :chef_attributes => detail[:chef_client]
346
+ )
329
347
  end
330
348
 
331
- OpenStruct.new(
332
- :name => name,
333
- :ip => detail[:ip],
334
- :mac => detail[:mac],
335
- :distro => detail[:distro],
336
- :arch => detail[:arch],
337
- :alive => alive,
338
- :"chef version" => chef_version,
339
- :persist => detail[:persist],
340
- :chef_attributes => detail[:chef_client]
341
- )
342
- end
343
-
344
- if @options.attributes?
345
- results.rows.each do |result|
346
- puts
347
- puts("-" * results.width)
348
- puts("Chef-Client attributes for '#{result.name.to_s.downcase}':")
349
- puts("-" * results.width)
350
- puts(JSON.pretty_generate(result.chef_attributes))
349
+ if @options.attributes?
350
+ results.rows.each do |result|
351
+ puts
352
+ puts("-" * results.width)
353
+ puts("Chef-Client attributes for '#{result.name.to_s.downcase}':")
354
+ puts("-" * results.width)
355
+ puts(JSON.pretty_generate(result.chef_attributes))
356
+ end
351
357
  end
358
+ else
359
+ raise Cucumber::Chef::Error, "We could not find any containers!"
352
360
  end
353
361
 
354
- test_lab.cc_server.down
362
+ ZTK::Benchmark.bench(:message => "Stop cc-server", :mark => "completed in %0.4f seconds.") do
363
+ test_lab.cc_client.down
364
+ end
355
365
  else
356
366
  raise Cucumber::Chef::Error, "We could not find a running test lab."
357
367
  end
@@ -21,9 +21,9 @@
21
21
  module Cucumber
22
22
  module Chef
23
23
 
24
- class ServerError < Error; end
24
+ class ClientError < Error; end
25
25
 
26
- class Server
26
+ class Client
27
27
  attr_accessor :test_lab, :stdout, :stderr, :stdin, :logger
28
28
 
29
29
  ################################################################################
@@ -74,7 +74,7 @@ module Cucumber
74
74
  end
75
75
 
76
76
  ZTK::RescueRetry.try(:tries => 30) do
77
- self.ping
77
+ self.drb.ping
78
78
  end
79
79
 
80
80
  File.exists?(Cucumber::Chef.artifacts_dir) && FileUtils.rm_rf(Cucumber::Chef.artifacts_dir)
@@ -84,17 +84,17 @@ module Cucumber
84
84
 
85
85
  ################################################################################
86
86
 
87
- def ping
88
- @drb and DRb.stop_service
89
- @drb = DRbObject.new_with_uri("druby://#{@test_lab.ip}:8787")
90
- @drb and DRb.start_service
91
- @drb.ping
87
+ def down
88
+ (@test_lab.drb.shutdown rescue nil)
92
89
  end
93
90
 
94
91
  ################################################################################
95
92
 
96
- def down
97
- (@test_lab.drb.shutdown rescue nil)
93
+ def drb
94
+ @drb and DRb.stop_service
95
+ @drb = DRbObject.new_with_uri("druby://#{@test_lab.ip}:8787")
96
+ @drb and DRb.start_service
97
+ @drb
98
98
  end
99
99
 
100
100
  ################################################################################
@@ -60,6 +60,7 @@ module Cucumber::Chef::Helpers::ChefClient
60
60
  logger.info { "Running chef client on container '#{name}'." }
61
61
 
62
62
  arguments = {
63
+ "--node-name" => name,
63
64
  "--json-attributes" => File.join("/etc", "chef", "attributes.json").to_s,
64
65
  "--log_level" => (ENV['LOG_LEVEL'] || "INFO").downcase
65
66
  }.reject{ |k,v| v.nil? }.sort
@@ -80,18 +81,23 @@ module Cucumber::Chef::Helpers::ChefClient
80
81
  client_rb = File.join("/", container_root(name), "etc/chef/client.rb")
81
82
  FileUtils.mkdir_p(File.dirname(client_rb))
82
83
 
83
- max_key_size = @chef_client_config.keys.collect{ |z| z.to_s.size }.max
84
+ # Do not render out a chef-client config for now; we'll assume the user will
85
+ # use a cookbook/recipe to accomplish this to their liking.
84
86
 
85
- File.open(client_rb, 'w') do |f|
86
- f.puts(Cucumber::Chef.generate_do_not_edit_warning("Chef Client Configuration"))
87
- f.puts
88
- @chef_client_config.merge(:node_name => name).each do |(key,value)|
89
- next if value.nil?
90
- f.puts("%-#{max_key_size}s %s" % [key, value.inspect])
91
- end
92
- f.puts
93
- f.puts("Mixlib::Log::Formatter.show_time = true")
94
- end
87
+ # File.exists?(client_rb) && File.delete(client_rb)
88
+
89
+ # max_key_size = @chef_client_config.keys.collect{ |z| z.to_s.size }.max
90
+
91
+ # File.open(client_rb, 'w') do |f|
92
+ # f.puts(Cucumber::Chef.generate_do_not_edit_warning("Chef Client Configuration"))
93
+ # f.puts
94
+ # @chef_client_config.merge(:node_name => name).each do |(key,value)|
95
+ # next if value.nil?
96
+ # f.puts("%-#{max_key_size}s %s" % [key, value.inspect])
97
+ # end
98
+ # f.puts
99
+ # f.puts("Mixlib::Log::Formatter.show_time = true")
100
+ # end
95
101
 
96
102
  attributes_json = File.join("/", container_root(name), "etc", "chef", "attributes.json")
97
103
  FileUtils.mkdir_p(File.dirname(attributes_json))
@@ -35,91 +35,6 @@ module Cucumber::Chef::Helpers::ChefServer
35
35
  logger.info { "Destroyed chef client '#{name}'." }
36
36
  end
37
37
 
38
- ################################################################################
39
-
40
- def load_cookbook(cookbook, cookbook_path)
41
- if !File.exists?(cookbook_path)
42
- raise "Cookbook path does not exist!"
43
- end
44
- cookbook_repo = ::Chef::CookbookLoader.new(cookbook_path)
45
- cookbook_repo.each do |name, cbook|
46
- next if name != cookbook
47
- ::Chef::CookbookUploader.new(cbook, cookbook_path, :force => true).upload_cookbooks
48
- logger.info { "Uploaded chef cookbook '#{cookbook}' from '#{cookbook_path}'." }
49
- end
50
- end
51
-
52
- ################################################################################
53
-
54
- def load_role(role, role_path)
55
- expanded_role_path = File.expand_path(role_path)
56
- if !File.exists?(expanded_role_path)
57
- raise "Role path, '#{expanded_role_path}', does not exist!"
58
- end
59
- ::Chef::Config[:role_path] = expanded_role_path
60
- role = ::Chef::Role.from_disk(role)
61
- role.save
62
- logger.info { "Updated chef role '#{role}' from '#{role_path}'." }
63
- end
64
-
65
- ################################################################################
66
-
67
- def get_databag(databag)
68
- @rest ||= ::Chef::REST.new(Chef::Config[:chef_server_url])
69
- @rest.get_rest("data/#{databag}")
70
- rescue Net::HTTPServerException => e
71
- raise unless e.to_s =~ /^404/
72
- end
73
-
74
- def destroy_databag(databag)
75
- @rest ||= ::Chef::REST.new(Chef::Config[:chef_server_url])
76
- @rest.delete_rest("data/#{databag}")
77
- rescue Net::HTTPServerException => e
78
- raise unless e.to_s =~ /^404/
79
- end
80
-
81
- ################################################################################
82
-
83
- def create_databag(databag)
84
- @rest ||= ::Chef::REST.new(Chef::Config[:chef_server_url])
85
- @rest.post_rest("data", { "name" => databag })
86
- rescue Net::HTTPServerException => e
87
- raise unless e.to_s =~ /^409/
88
- end
89
-
90
- def load_databag_item(databag_item_path)
91
- ::Yajl::Parser.parse(IO.read(databag_item_path))
92
- end
93
-
94
- def load_databag(databag, databag_path)
95
- create_databag(databag)
96
- items = Dir.glob(File.expand_path(File.join(databag_path, "*.{json,rb}")))
97
- if (items.size == 0)
98
- raise "Could not find any of the data bags you defined!"
99
- end
100
- items.each do |item|
101
- next if File.directory?(item)
102
-
103
- item_name = %w(json rb).collect{ |ext| (item =~ /#{ext}/ ? File.basename(item, ".#{ext}") : nil) }.compact.first
104
- item_path = File.basename(item)
105
- databag_item_path = File.expand_path(File.join(databag_path, item_path))
106
-
107
- data_bag_item = ::Chef::DataBagItem.new
108
- data_bag_item.data_bag(databag)
109
- raw_data = load_databag_item(databag_item_path)
110
- data_bag_item.raw_data = raw_data.dup
111
- data_bag_item.save
112
-
113
- loop do
114
- chef_data = ::Chef::DataBagItem.load(databag, item_name).raw_data
115
- break if chef_data == raw_data
116
- logger.info { "Waiting on chef data bag to update; sleeping 1 second." }
117
- sleep(1)
118
- end
119
- logger.info { "Updated chef data bag item '#{databag}/#{item_path}' from '#{databag_path}'." }
120
- end
121
- end
122
-
123
38
  ################################################################################
124
39
 
125
40
  end
@@ -48,11 +48,11 @@ module Cucumber
48
48
  ################################################################################
49
49
 
50
50
  def chef_server_webui
51
- "http://#{ip}:4040/"
51
+ "http://#{ip}:4040"
52
52
  end
53
53
 
54
54
  def chef_server_api
55
- "http://#{ip}:4000/"
55
+ "http://#{ip}:4000"
56
56
  end
57
57
 
58
58
  def status
@@ -90,7 +90,7 @@ module Cucumber
90
90
  if Cucumber::Chef::Provider::PROXY_METHODS.include?(method_name.to_s)
91
91
  result = @provider.send(method_name.to_sym, *method_args)
92
92
  splat = [method_name, *method_args].flatten.compact
93
- Cucumber::Chef.logger.debug { "provider: #{splat.inspect} -> #{result.inspect}" }
93
+ Cucumber::Chef.logger.debug { "Provider: #{splat.inspect}=#{result.inspect}" }
94
94
  result
95
95
  else
96
96
  super(method_name, *method_args)
@@ -39,7 +39,6 @@ module Cucumber
39
39
  @stdout.sync = true if @stdout.respond_to?(:sync=)
40
40
 
41
41
  @env = ::Vagrant::Environment.new
42
- # @env = ::Vagrant::Environment.new(:ui_class => ::Vagrant::UI::Colored)
43
42
  @vm = @env.primary_vm
44
43
  end
45
44
 
@@ -49,7 +48,7 @@ module Cucumber
49
48
 
50
49
  def create
51
50
  ZTK::Benchmark.bench(:message => "Creating #{Cucumber::Chef::Config.provider.upcase} instance", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
52
- @env.cli("up")
51
+ self.vagrant_cli("up")
53
52
  ZTK::TCPSocketCheck.new(:host => self.ip, :port => self.port, :wait => 120).wait
54
53
  end
55
54
 
@@ -67,7 +66,7 @@ module Cucumber
67
66
 
68
67
  def destroy
69
68
  if exists?
70
- @env.cli("destroy", "--force")
69
+ self.vagrant_cli("destroy", "--force")
71
70
  else
72
71
  raise VagrantError, "We could not find a test lab!"
73
72
  end
@@ -84,7 +83,7 @@ module Cucumber
84
83
 
85
84
  def up
86
85
  if (exists? && dead?)
87
- @env.cli("up")
86
+ self.vagrant_cli("up")
88
87
  ZTK::TCPSocketCheck.new(:host => self.ip, :port => self.port, :wait => 120).wait
89
88
  else
90
89
  raise VagrantError, "We could not find a powered off test lab."
@@ -102,7 +101,7 @@ module Cucumber
102
101
 
103
102
  def halt
104
103
  if (exists? && alive?)
105
- @env.cli("halt")
104
+ self.vagrant_cli("halt")
106
105
  else
107
106
  raise AWSError, "We could not find a running test lab."
108
107
  end
@@ -119,7 +118,7 @@ module Cucumber
119
118
 
120
119
  def reload
121
120
  if (exists? && alive?)
122
- @env.cli("reload")
121
+ self.vagrant_cli("reload")
123
122
  else
124
123
  raise AWSError, "We could not find a running test lab."
125
124
  end
@@ -166,6 +165,13 @@ module Cucumber
166
165
  @vm.config.vm.forwarded_ports.select{ |fwd_port| (fwd_port[:name] == "ssh") }.first[:hostport].to_i
167
166
  end
168
167
 
168
+ ################################################################################
169
+
170
+ def vagrant_cli(*args)
171
+ command = Cucumber::Chef.build_command("vagrant", *args)
172
+ ZTK::Command.new.exec(command, :silence => true)
173
+ end
174
+
169
175
  ################################################################################
170
176
 
171
177
  end
@@ -27,9 +27,6 @@ module Cucumber
27
27
  class Provisioner
28
28
  attr_accessor :test_lab, :stdout, :stderr, :stdin
29
29
 
30
- HOSTNAME = "cucumber-chef.test-lab"
31
- PASSWORD = "p@ssw0rd1"
32
-
33
30
  ################################################################################
34
31
 
35
32
  def initialize(test_lab, stdout=STDOUT, stderr=STDERR, stdin=STDIN)
@@ -162,14 +159,7 @@ module Cucumber
162
159
  def upload_cookbook
163
160
  Cucumber::Chef.logger.debug { "Uploading cucumber-chef cookbooks..." }
164
161
  ZTK::Benchmark.bench(:message => "Uploading 'cucumber-chef' cookbooks", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
165
- Cucumber::Chef.load_chef_config
166
- cookbook_repo = ::Chef::CookbookLoader.new(@cookbooks_path)
167
- cookbook_repo.each do |name, cookbook|
168
- Cucumber::Chef.logger.debug { "::Chef::CookbookUploader(#{name}) ATTEMPT" }
169
- ::Chef::CookbookUploader.new(cookbook, @cookbooks_path, :force => true).upload_cookbooks
170
- Cucumber::Chef.logger.debug { "::Chef::CookbookUploader(#{name}) UPLOADED" }
171
- end
172
- #@command.knife([ "cookbook upload cucumber-chef", "-o", @cookbooks_path ], :silence => true)
162
+ @test_lab.knife_cli(%Q{cookbook upload cucumber-chef -o #{@cookbooks_path}}, :silence => true)
173
163
  end
174
164
  end
175
165
 
@@ -178,13 +168,7 @@ module Cucumber
178
168
  def upload_role
179
169
  Cucumber::Chef.logger.debug { "Uploading cucumber-chef test lab role..." }
180
170
  ZTK::Benchmark.bench(:message => "Uploading 'cucumber-chef' roles", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
181
- Cucumber::Chef.load_chef_config
182
- ::Chef::Config[:role_path] = @roles_path
183
- [ "test_lab" ].each do |name|
184
- role = ::Chef::Role.from_disk(name)
185
- role.save
186
- end
187
- #@command.knife([ "role from file", File.join(@roles_path, "test_lab.rb") ], :silence => true)
171
+ @test_lab.knife_cli(%Q{role from file #{File.join(@roles_path, "test_lab.rb")}}, :silence => true)
188
172
  end
189
173
  end
190
174
 
@@ -193,13 +177,7 @@ module Cucumber
193
177
  def tag_node
194
178
  Cucumber::Chef.logger.debug { "Tagging cucumber-chef test lab node..." }
195
179
  ZTK::Benchmark.bench(:message => "Tagging 'cucumber-chef' node", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
196
- Cucumber::Chef.load_chef_config
197
- node = ::Chef::Node.load(HOSTNAME)
198
- [ Cucumber::Chef::Config[:mode].to_s, Cucumber::Chef::Config[:user].to_s ].each do |tag|
199
- node.tags << tag
200
- node.save
201
- end
202
- #@command.knife([ "tag create", HOSTNAME, Cucumber::Chef::Config[:mode] ], :silence => true)
180
+ @test_lab.knife_cli(%Q{tag create #{Cucumber::Chef.lab_hostname_full} #{Cucumber::Chef::Config.mode}}, :silence => true)
203
181
  end
204
182
  end
205
183
 
@@ -208,13 +186,7 @@ module Cucumber
208
186
  def add_node_role
209
187
  Cucumber::Chef.logger.debug { "Setting up cucumber-chef test lab run list..." }
210
188
  ZTK::Benchmark.bench(:message => "Setting 'cucumber-chef' run list", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
211
- Cucumber::Chef.load_chef_config
212
- node = ::Chef::Node.load(HOSTNAME)
213
- [ "role[test_lab]" ].each do |entry|
214
- node.run_list << entry
215
- end
216
- node.save
217
- #@command.knife([ "node run_list add", HOSTNAME, "\"role[test_lab]\"" ], :silence => true)
189
+ @test_lab.knife_cli(%Q{node run_list add #{Cucumber::Chef.lab_hostname_full} "role[test_lab]"}, :silence => true)
218
190
  end
219
191
  end
220
192
 
@@ -19,20 +19,54 @@
19
19
  #
20
20
  ################################################################################
21
21
 
22
- And /^the following databags have been updated:$/ do |table|
22
+ And /^the following (databag|databags) (has|have) been (updated|uploaded):$/ do |ignore0, ignore1, ignore2, table|
23
23
  table.hashes.each do |entry|
24
- load_databag(entry['databag'], entry['databag_path'])
24
+ data_bag = entry['databag']
25
+ data_bag_path = entry['databag_path']
26
+
27
+ $test_lab.knife_cli(%Q{data bag from file #{data_bag} #{data_bag_path}}, :silence => true)
25
28
  end
26
29
  end
27
30
 
28
- And /^the following roles have been updated:$/ do |table|
31
+ And /^the following (role|roles) (has|have) been (updated|uploaded):$/ do |ignore0, ignore1, ignore2, table|
29
32
  table.hashes.each do |entry|
30
- load_role(entry['role'], entry['role_path'])
33
+ role = entry['role']
34
+ role_path = entry['role_path']
35
+
36
+ if File.extname(role).empty?
37
+ Dir.glob(File.join(role_path, "#{role}.*")).each do |role_file|
38
+ $test_lab.knife_cli(%Q{role from file #{role_file}}, :silence => true)
39
+ end
40
+ else
41
+ $test_lab.knife_cli(%Q{role from file #{File.join(role_path, role)}}, :silence => true)
42
+ end
31
43
  end
32
44
  end
33
45
 
34
- And /^the following cookbooks have been uploaded:$/ do |table|
46
+ And /^the following (cookbook|cookbooks) (has|have) been (updated|uploaded):$/ do |ignore0, ignore1, ignore2, table|
47
+ cookbooks = table.hashes.inject(Hash.new) do |memo, entry|
48
+ cookbook = entry['cookbook']
49
+ cookbook_path = entry['cookbook_path']
50
+
51
+ memo.merge(cookbook_path => [cookbook]) { |k,o,n| k = o << n }
52
+ end
53
+
54
+ cookbooks.each do |cookbook_path, cookbooks|
55
+ $test_lab.knife_cli(%Q{cookbook upload #{cookbooks.join(" ")} -o #{cookbook_path}}, :silence => true)
56
+ end
57
+ end
58
+
59
+ And /^the following (environment|environments) (has|have) been (updated|uploaded):$/ do |ignore0, ignore1, ignore2, table|
35
60
  table.hashes.each do |entry|
36
- load_cookbook(entry['cookbook'], entry['cookbook_path'])
61
+ environment = entry['environment']
62
+ environment_path = entry['environment_path']
63
+
64
+ if File.extname(environment).empty?
65
+ Dir.glob(File.join(environment_path, "#{environment}.*")).each do |environment_file|
66
+ $test_lab.knife_cli(%Q{environment from file #{environment_file}}, :silence => true)
67
+ end
68
+ else
69
+ $test_lab.knife_cli(%Q{environment from file #{File.join(environment_path, environment)}}, :silence => true)
70
+ end
37
71
  end
38
72
  end
@@ -23,8 +23,7 @@ puts(" * #{tag}")
23
23
  Cucumber::Chef.boot(tag)
24
24
 
25
25
  if (($test_lab = Cucumber::Chef::TestLab.new) && $test_lab.alive?)
26
- $cc_server = Cucumber::Chef::Server.new($test_lab)
27
- $cc_server.up
26
+ $test_lab.cc_client.up
28
27
  else
29
28
  message = "No running cucumber-chef test labs to connect to!"
30
29
  Cucumber::Chef.logger.fatal { message }
@@ -37,15 +36,16 @@ end
37
36
  ################################################################################
38
37
 
39
38
  Before do |scenario|
40
- $cc_server.before(scenario)
39
+ $test_lab.cc_client.before(scenario)
41
40
  end
42
41
 
43
42
  After do |scenario|
44
- $cc_server.after(scenario)
43
+ @connection and @connection.ssh.shutdown!
44
+ $test_lab.cc_client.after(scenario)
45
45
  end
46
46
 
47
47
  Kernel.at_exit do
48
- $cc_server.at_exit
48
+ $test_lab.cc_client.at_exit
49
49
  end
50
50
 
51
51
  ################################################################################
@@ -90,22 +90,38 @@ module Cucumber
90
90
  @proxy_ssh[container]
91
91
  end
92
92
 
93
+ ################################################################################
94
+
95
+ def cc_client
96
+ dead? and raise TestLabError, "The test lab must be running in order to start the cc-server/client session!"
97
+
98
+ @cc_client ||= Cucumber::Chef::Client.new(self, @stdout, @stderr, @stdin, @logger)
99
+ @cc_client
100
+ end
101
+
93
102
  ################################################################################
94
103
 
95
104
  def drb
96
105
  dead? and raise TestLabError, "The test lab must be running in order to start a Drb session!"
97
106
 
98
- # @drb and DRb.stop_service
99
- @drb ||= DRbObject.new_with_uri("druby://#{self.ip}:8787")
100
- @drb and DRb.start_service
101
- @drb
107
+ self.cc_client.drb
102
108
  end
103
109
 
104
110
  ################################################################################
105
111
 
106
- def cc_server
107
- @cc_server ||= Cucumber::Chef::Server.new(self, @stdout, @stderr, @stdin, @logger)
108
- @cc_server
112
+ def knife_cli(args, options={})
113
+ options = {:silence => true}.merge(options)
114
+
115
+ extracted_options = options.select{ |k,v| [:silence, :expected_exit_code].include?(k) }
116
+ options.reject!{ |k,v| [:silence, :expected_exit_code].include?(k) }
117
+
118
+ arguments = Array.new
119
+ arguments << "--user #{Cucumber::Chef::Config.user}"
120
+ arguments << "--server-url #{self.chef_server_api}"
121
+ arguments << "--config #{Cucumber::Chef.knife_rb}" if File.exists?(Cucumber::Chef.knife_rb)
122
+
123
+ command = Cucumber::Chef.build_command("knife", args, arguments)
124
+ ZTK::Command.new(options).exec(command, extracted_options)
109
125
  end
110
126
 
111
127
  ################################################################################
@@ -114,7 +130,7 @@ module Cucumber
114
130
  if Cucumber::Chef::Provider::PROXY_METHODS.include?(method_name.to_s)
115
131
  result = @provider.send(method_name.to_sym, *method_args)
116
132
  splat = [method_name, *method_args].flatten.compact
117
- Cucumber::Chef.logger.debug { "test_lab: #{splat.inspect} -> #{result.inspect}" }
133
+ Cucumber::Chef.logger.debug { "TestLab: #{splat.inspect}=#{result.inspect}" }
118
134
  result
119
135
  else
120
136
  super(method_name, *method_args)
@@ -216,6 +216,13 @@ module Cucumber
216
216
  [ name, "v#{Cucumber::Chef::VERSION}" ].compact.join(" ")
217
217
  end
218
218
 
219
+ ################################################################################
220
+
221
+ def build_command(name, *args)
222
+ executable = (Cucumber::Chef.locate(:file, "bin", name) rescue "/usr/bin/env #{name}")
223
+ [executable, args].flatten.compact.join(" ")
224
+ end
225
+
219
226
  ################################################################################
220
227
  # BOOT
221
228
  ################################################################################
@@ -24,7 +24,7 @@ module Cucumber
24
24
 
25
25
  ################################################################################
26
26
 
27
- VERSION = "2.1.0.rc.3" unless const_defined?(:VERSION)
27
+ VERSION = "2.1.0.rc.4" unless const_defined?(:VERSION)
28
28
 
29
29
  ################################################################################
30
30
 
data/lib/cucumber/chef.rb CHANGED
@@ -47,10 +47,10 @@ module Cucumber
47
47
 
48
48
  class Error < StandardError; end
49
49
 
50
+ autoload :Client, 'cucumber/chef/client'
50
51
  autoload :Config, 'cucumber/chef/config'
51
52
  autoload :Provider, 'cucumber/chef/provider'
52
53
  autoload :Provisioner, 'cucumber/chef/provisioner'
53
- autoload :Server, 'cucumber/chef/server'
54
54
  autoload :TestLab, 'cucumber/chef/test_lab'
55
55
 
56
56
  require 'cucumber/chef/utility'
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'cucumber'
3
+ require 'cucumber/rake/task'
4
+
5
+ Cucumber::Rake::Task.new(:"cucumber-chef") do |t|
6
+ feature_dirs = Array.new
7
+
8
+ feature_dir_glob = File.join(Dir.pwd, "*cookbook*", "*", "*feature*")
9
+ feature_dirs << Dir.glob(feature_dir_glob)
10
+
11
+ feature_dir_glob = File.join(Dir.pwd, "*feature*")
12
+ feature_dirs << Dir.glob(feature_dir_glob)
13
+
14
+ opts = [
15
+ "--exclude support/cookbooks",
16
+ "--exclude support/data_bags",
17
+ "--exclude support/environments",
18
+ "--exclude support/keys",
19
+ "--exclude support/roles",
20
+ feature_dirs
21
+ ].flatten.compact.join(" ")
22
+
23
+ t.cucumber_opts = opts
24
+ end
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.3
4
+ version: 2.1.0.rc.4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-25 00:00:00.000000000 Z
13
+ date: 2013-01-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: chef
@@ -296,7 +296,9 @@ files:
296
296
  - features/support/silent_system.rb
297
297
  - features/usage.feature
298
298
  - lib/cucumber-chef.rb
299
+ - lib/cucumber-chef/rake/task.rb
299
300
  - lib/cucumber/chef.rb
301
+ - lib/cucumber/chef/client.rb
300
302
  - lib/cucumber/chef/config.rb
301
303
  - lib/cucumber/chef/helpers.rb
302
304
  - lib/cucumber/chef/helpers/chef_client.rb
@@ -311,7 +313,6 @@ files:
311
313
  - lib/cucumber/chef/providers/aws.rb
312
314
  - lib/cucumber/chef/providers/vagrant.rb
313
315
  - lib/cucumber/chef/provisioner.rb
314
- - lib/cucumber/chef/server.rb
315
316
  - lib/cucumber/chef/steps.rb
316
317
  - lib/cucumber/chef/steps/chef_steps.rb
317
318
  - lib/cucumber/chef/steps/minitest_steps.rb