cucumber-chef 2.0.7 → 2.1.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.md +1 -1
  2. data/Rakefile +1 -1
  3. data/bin/cc-knife +2 -5
  4. data/bin/cc-push +50 -26
  5. data/bin/cc-server +9 -10
  6. data/bin/cucumber-chef +65 -71
  7. data/chef_repo/cookbooks/cucumber-chef/attributes/default.rb +1 -1
  8. data/chef_repo/cookbooks/cucumber-chef/recipes/default.rb +1 -1
  9. data/chef_repo/cookbooks/cucumber-chef/recipes/lxc.rb +34 -36
  10. data/chef_repo/cookbooks/cucumber-chef/recipes/test_lab.rb +64 -47
  11. data/chef_repo/cookbooks/cucumber-chef/templates/default/solrconfig.erb +650 -0
  12. data/cucumber-chef.gemspec +5 -5
  13. data/lib/cucumber/chef/bootstrap.rb +10 -10
  14. data/lib/cucumber/chef/config.rb +15 -15
  15. data/lib/cucumber/chef/helpers/chef_client.rb +88 -14
  16. data/lib/cucumber/chef/helpers/chef_server.rb +39 -16
  17. data/lib/cucumber/chef/helpers/command.rb +28 -12
  18. data/lib/cucumber/chef/helpers/container.rb +29 -26
  19. data/lib/cucumber/chef/helpers/minitest.rb +1 -1
  20. data/lib/cucumber/chef/helpers/server.rb +37 -18
  21. data/lib/cucumber/chef/helpers/test_lab.rb +1 -1
  22. data/lib/cucumber/chef/helpers/utility.rb +23 -3
  23. data/lib/cucumber/chef/helpers.rb +10 -8
  24. data/lib/cucumber/chef/provisioner.rb +22 -21
  25. data/lib/cucumber/chef/steps/chef_steps.rb +1 -1
  26. data/lib/cucumber/chef/steps/minitest_steps.rb +3 -3
  27. data/lib/cucumber/chef/steps/provision_steps.rb +7 -6
  28. data/lib/cucumber/chef/steps/ssh_steps.rb +31 -2
  29. data/lib/cucumber/chef/steps.rb +1 -1
  30. data/lib/cucumber/chef/templates/cucumber/cc-hooks.rb +111 -0
  31. data/lib/cucumber/chef/templates/cucumber/env.rb +0 -87
  32. data/lib/cucumber/chef/templates/cucumber/readme-environments.erb +1 -0
  33. data/lib/cucumber/chef/templates/cucumber/readme-roles.erb +1 -1
  34. data/lib/cucumber/chef/templates/cucumber-chef/config-rb.erb +5 -0
  35. data/lib/cucumber/chef/test_lab.rb +70 -23
  36. data/lib/cucumber/chef/utility.rb +121 -31
  37. data/lib/cucumber/chef/version.rb +2 -2
  38. data/lib/cucumber/chef.rb +1 -1
  39. data/lib/cucumber-chef.rb +1 -1
  40. data/spec/cucumber/chef/config_spec.rb +1 -1
  41. data/spec/cucumber/chef/provisioner_spec.rb +1 -1
  42. data/spec/cucumber/chef/test_lab_spec.rb +1 -1
  43. data/spec/spec_helper.rb +1 -1
  44. metadata +8 -5
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,20 +23,14 @@ module Cucumber::Chef::Helpers::Server
23
23
 
24
24
  ################################################################################
25
25
 
26
- def detect_arch(distro)
27
- case distro.downcase
28
- when "ubuntu" then
29
- ((RUBY_PLATFORM =~ /x86_64/) ? "amd64" : "i386")
30
- when "fedora" then
31
- ((RUBY_PLATFORM =~ /x86_64/) ? "amd64" : "i686")
32
- end
33
- end
34
-
35
26
  def server_create(name, attributes={})
36
27
  if ((attributes[:persist] && @servers[name]) || (@servers[name] && @servers[name][:persist]))
37
28
  attributes = @servers[name]
29
+ log("using existing attributes for container $#{name} #{server_tag(name)}$")
38
30
  else
39
- server_destroy(name) if (container_exists?(name) && (ENV['DESTROY'] == "1"))
31
+ if (container_exists?(name) && (ENV['DESTROY'] == "1"))
32
+ server_destroy(name)
33
+ end
40
34
  attributes = { :ip => generate_ip,
41
35
  :mac => generate_mac,
42
36
  :persist => true,
@@ -47,18 +41,26 @@ module Cucumber::Chef::Helpers::Server
47
41
  @servers = (@servers || Hash.new(nil)).merge(name => attributes)
48
42
  $current_server = @servers[name][:ip]
49
43
  if !server_running?(name)
50
- log(name, "is being provisioned") if @servers[name]
44
+ log("please wait, creating container $#{name} #{server_tag(name)}$")
45
+ bm = ::Benchmark.realtime do
46
+ test_lab_config_dhcpd
47
+ container_config_network(name)
48
+ container_create(name, @servers[name][:distro], @servers[name][:release], @servers[name][:arch])
49
+ end
50
+ log("container $#{name}$ creation took %0.4f seconds" % bm)
51
51
 
52
- test_lab_config_dhcpd
53
- container_config_network(name)
54
- container_create(name, @servers[name][:distro], @servers[name][:release], @servers[name][:arch])
55
- ZTK::TCPSocketCheck.new(:host => @servers[name][:ip], :port => 22).wait
52
+ bm = ::Benchmark.realtime do
53
+ ZTK::TCPSocketCheck.new(:host => @servers[name][:ip], :port => 22).wait
54
+ end
55
+ log("container $#{name}$ SSHD responded after %0.4f seconds" % bm)
56
+ else
57
+ log("container $#{name}$ is already running")
56
58
  end
57
59
  end
58
60
 
59
- def server_destroy(name)
60
- log(name, "is being destroyed") if @servers[name]
61
+ ################################################################################
61
62
 
63
+ def server_destroy(name)
62
64
  container_destroy(name)
63
65
  end
64
66
 
@@ -74,6 +76,23 @@ module Cucumber::Chef::Helpers::Server
74
76
  containers
75
77
  end
76
78
 
79
+ ################################################################################
80
+
81
+ def server_tag(name)
82
+ @servers[name].inspect.to_s
83
+ end
84
+
85
+ ################################################################################
86
+
87
+ def detect_arch(distro)
88
+ case distro.downcase
89
+ when "ubuntu" then
90
+ ((RUBY_PLATFORM =~ /x86_64/) ? "amd64" : "i386")
91
+ when "fedora" then
92
+ ((RUBY_PLATFORM =~ /x86_64/) ? "amd64" : "i686")
93
+ end
94
+ end
95
+
77
96
  ################################################################################
78
97
 
79
98
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,9 +23,29 @@ module Cucumber::Chef::Helpers::Utility
23
23
 
24
24
  ################################################################################
25
25
 
26
- def log(name, message)
27
- STDOUT.puts("\033[34m >>> \033[1m#{name}\033[0m\033[34m #{message}\033[0m")
26
+ def log(message)
27
+ Cucumber::Chef.logger.info { message.gsub("$", "'") }
28
+ return if !(ENV['VERBOSE'] == "1")
29
+
30
+ pattern = [ "\033[0m\033[36m", "\033[1m" ]
31
+
32
+ result = [ " \033[0m\033[34m[\033[1mCC\033[0m\033[34m] \033[36m" ]
33
+ result << pattern.first
34
+
35
+ sanity = message.split('').count{ |z| (z == "$") }
36
+ raise "You have a log message with an odd number of highlight markup characters! '#{message}' -> (sanity=#{sanity.inspect}) " if (sanity.modulo(2) != 0)
37
+
38
+ chunks = message.split("$")
39
+ chunks.each_with_index do |chunk, index|
40
+ result << pattern[index.modulo(pattern.length)]
41
+ result << chunk
42
+ end
43
+ result << "\033[0m"
44
+
45
+ STDOUT.puts(result.join)
28
46
  STDOUT.flush if STDOUT.respond_to?(:flush)
47
+
48
+ true
29
49
  end
30
50
 
31
51
  ################################################################################
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +26,8 @@ module Cucumber
26
26
  # definitions.
27
27
  module Helpers
28
28
 
29
+ require 'benchmark'
30
+
29
31
  require 'cucumber/chef/helpers/chef_client'
30
32
  require 'cucumber/chef/helpers/chef_server'
31
33
  require 'cucumber/chef/helpers/command'
@@ -35,13 +37,13 @@ module Cucumber
35
37
  require 'cucumber/chef/helpers/utility'
36
38
 
37
39
  def self.included(base)
38
- base.send(:include, Cucumber::Chef::Helpers::ChefClient)
39
- base.send(:include, Cucumber::Chef::Helpers::ChefServer)
40
- base.send(:include, Cucumber::Chef::Helpers::Command)
41
- base.send(:include, Cucumber::Chef::Helpers::Container)
42
- base.send(:include, Cucumber::Chef::Helpers::Server)
43
- base.send(:include, Cucumber::Chef::Helpers::TestLab)
44
- base.send(:include, Cucumber::Chef::Helpers::Utility)
40
+ base.send(:include, ::Cucumber::Chef::Helpers::ChefClient)
41
+ base.send(:include, ::Cucumber::Chef::Helpers::ChefServer)
42
+ base.send(:include, ::Cucumber::Chef::Helpers::Command)
43
+ base.send(:include, ::Cucumber::Chef::Helpers::Container)
44
+ base.send(:include, ::Cucumber::Chef::Helpers::Server)
45
+ base.send(:include, ::Cucumber::Chef::Helpers::TestLab)
46
+ base.send(:include, ::Cucumber::Chef::Helpers::Utility)
45
47
  end
46
48
 
47
49
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,7 +39,7 @@ module Cucumber
39
39
 
40
40
  @ssh = ZTK::SSH.new(:stdout => @stdout, :stderr => @stderr, :stdin => @stdin)
41
41
  @ssh.config.host_name = @server.public_ip_address
42
- @ssh.config.user = "ubuntu"
42
+ @ssh.config.user = Cucumber::Chef::Config[:lab_user]
43
43
  @ssh.config.keys = Cucumber::Chef::Config[:aws][:identity_file]
44
44
 
45
45
  # @command = Cucumber::Chef::Command.new(@stdout, @stderr, @stdin)
@@ -91,7 +91,7 @@ module Cucumber
91
91
 
92
92
  bootstrap = Cucumber::Chef::Bootstrap.new(@stdout, @stderr, @stdin)
93
93
  bootstrap.config[:host] = @server.public_ip_address
94
- bootstrap.config[:ssh_user] = "ubuntu"
94
+ bootstrap.config[:ssh_user] = Cucumber::Chef::Config[:lab_user]
95
95
  bootstrap.config[:use_sudo] = true
96
96
  bootstrap.config[:identity_file] = Cucumber::Chef::Config[:aws][:identity_file]
97
97
  bootstrap.config[:template_file] = template_file
@@ -130,9 +130,10 @@ module Cucumber
130
130
  local_path = Cucumber::Chef.locate(:directory, ".cucumber-chef")
131
131
  remote_path = File.join("/", "home", @ssh.config.user, ".ssh")
132
132
 
133
- files = { "id_rsa" => "id_rsa-ubuntu" }
133
+ files = { "id_rsa" => "id_rsa-#{Cucumber::Chef::Config[:lab_user]}" }
134
134
  files.each do |remote_file, local_file|
135
135
  local = File.join(local_path, local_file)
136
+ File.exists?(local) and File.delete(local)
136
137
  @ssh.download(File.join(remote_path, remote_file), local)
137
138
  File.chmod(0600, local)
138
139
  end
@@ -164,32 +165,32 @@ module Cucumber
164
165
  ################################################################################
165
166
 
166
167
  def upload_cookbook
167
- $logger.debug { "Uploading cucumber-chef cookbooks..." }
168
+ Cucumber::Chef.logger.debug { "Uploading cucumber-chef cookbooks..." }
168
169
  @stdout.print("Uploading cucumber-chef cookbooks...")
169
170
 
170
171
  Cucumber::Chef.spinner do
171
- Cucumber::Chef.load_knife_config
172
+ Cucumber::Chef.load_knife
172
173
  cookbook_repo = ::Chef::CookbookLoader.new(@cookbooks_path)
173
174
  cookbook_repo.each do |name, cookbook|
174
- $logger.debug { "::Chef::CookbookUploader(#{name}) ATTEMPT" }
175
+ Cucumber::Chef.logger.debug { "::Chef::CookbookUploader(#{name}) ATTEMPT" }
175
176
  ::Chef::CookbookUploader.new(cookbook, @cookbooks_path, :force => true).upload_cookbooks
176
- $logger.debug { "::Chef::CookbookUploader(#{name}) UPLOADED" }
177
+ Cucumber::Chef.logger.debug { "::Chef::CookbookUploader(#{name}) UPLOADED" }
177
178
  end
178
179
  #@command.knife([ "cookbook upload cucumber-chef", "-o", @cookbooks_path ], :silence => true)
179
180
  end
180
181
 
181
182
  @stdout.print("done.\n")
182
- $logger.debug { "Successfully uploaded cucumber-chef test lab cookbooks." }
183
+ Cucumber::Chef.logger.debug { "Successfully uploaded cucumber-chef test lab cookbooks." }
183
184
  end
184
185
 
185
186
  ################################################################################
186
187
 
187
188
  def upload_role
188
- $logger.debug { "Uploading cucumber-chef test lab role..." }
189
+ Cucumber::Chef.logger.debug { "Uploading cucumber-chef test lab role..." }
189
190
  @stdout.print("Uploading cucumber-chef test lab role...")
190
191
 
191
192
  Cucumber::Chef.spinner do
192
- Cucumber::Chef.load_knife_config
193
+ Cucumber::Chef.load_knife
193
194
  ::Chef::Config[:role_path] = @roles_path
194
195
  [ "test_lab" ].each do |name|
195
196
  role = ::Chef::Role.from_disk(name)
@@ -199,17 +200,17 @@ module Cucumber
199
200
  end
200
201
 
201
202
  @stdout.print("done.\n")
202
- $logger.debug { "Successfully uploaded cucumber-chef test lab roles."}
203
+ Cucumber::Chef.logger.debug { "Successfully uploaded cucumber-chef test lab roles."}
203
204
  end
204
205
 
205
206
  ################################################################################
206
207
 
207
208
  def tag_node
208
- $logger.debug { "Tagging cucumber-chef test lab node..." }
209
+ Cucumber::Chef.logger.debug { "Tagging cucumber-chef test lab node..." }
209
210
  @stdout.print("Tagging cucumber-chef test lab node...")
210
211
 
211
212
  Cucumber::Chef.spinner do
212
- Cucumber::Chef.load_knife_config
213
+ Cucumber::Chef.load_knife
213
214
  node = ::Chef::Node.load(HOSTNAME)
214
215
  [ Cucumber::Chef::Config[:mode].to_s, Cucumber::Chef::Config[:user].to_s ].each do |tag|
215
216
  node.tags << tag
@@ -219,17 +220,17 @@ module Cucumber
219
220
  end
220
221
 
221
222
  @stdout.print("done.\n")
222
- $logger.debug { "Successfully tagged cucumber-chef test lab node."}
223
+ Cucumber::Chef.logger.debug { "Successfully tagged cucumber-chef test lab node."}
223
224
  end
224
225
 
225
226
  ################################################################################
226
227
 
227
228
  def add_node_role
228
- $logger.debug { "Setting up cucumber-chef test lab run list..." }
229
+ Cucumber::Chef.logger.debug { "Setting up cucumber-chef test lab run list..." }
229
230
  @stdout.print("Setting up cucumber-chef test lab run list...")
230
231
 
231
232
  Cucumber::Chef.spinner do
232
- Cucumber::Chef.load_knife_config
233
+ Cucumber::Chef.load_knife
233
234
  node = ::Chef::Node.load(HOSTNAME)
234
235
  [ "role[test_lab]" ].each do |entry|
235
236
  node.run_list << entry
@@ -238,7 +239,7 @@ module Cucumber
238
239
  #@command.knife([ "node run_list add", HOSTNAME, "\"role[test_lab]\"" ], :silence => true)
239
240
  end
240
241
 
241
- $logger.debug { "Successfully added roles to cucumber-chef test lab."}
242
+ Cucumber::Chef.logger.debug { "Successfully added roles to cucumber-chef test lab."}
242
243
  @stdout.print("done.\n")
243
244
  end
244
245
 
@@ -259,13 +260,13 @@ module Cucumber
259
260
  def wait_for_chef_server
260
261
  @stdout.print("Waiting for Chef-Server...")
261
262
  Cucumber::Chef.spinner do
262
- ZTK::TCPSocketCheck.new(:host => @server.public_ip_address, :port => 4000, :data => "GET").wait
263
+ ZTK::TCPSocketCheck.new(:host => @server.public_ip_address, :port => 4000, :data => "GET", :wait => 120).wait
263
264
  end
264
265
  @stdout.puts("done.\n")
265
266
 
266
267
  @stdout.print("Waiting for Chef-WebUI...")
267
268
  Cucumber::Chef.spinner do
268
- ZTK::TCPSocketCheck.new(:host => @server.public_ip_address, :port => 4040, :data => "GET").wait
269
+ ZTK::TCPSocketCheck.new(:host => @server.public_ip_address, :port => 4040, :data => "GET", :wait => 120).wait
269
270
  end
270
271
  @stdout.puts("done.\n")
271
272
  end
@@ -283,7 +284,7 @@ module Cucumber
283
284
 
284
285
  @stdout.print("Waiting for SSHD...")
285
286
  Cucumber::Chef.spinner do
286
- ZTK::TCPSocketCheck.new(:host => @server.public_ip_address, :port => 22).wait
287
+ ZTK::TCPSocketCheck.new(:host => @server.public_ip_address, :port => 22, :wait => 120).wait
287
288
  end
288
289
  @stdout.puts("done.\n")
289
290
 
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,10 +20,10 @@
20
20
  ################################################################################
21
21
 
22
22
  When /^I enable the running of MiniTest suites for "(.*?)"$/ do |name|
23
- $drb_test_lab.enable_minitest(name)
23
+ $test_lab.drb.enable_minitest(name)
24
24
  end
25
25
 
26
26
  Then /^the tests should run and pass on "(.*?)"$/ do |name|
27
- results = $drb_test_lab.run_minitests(name)
27
+ results = $test_lab.drb.run_minitests(name)
28
28
  results.last.scan(/assertions.*(\d).*failures.*(\d).*errors.*(\d).*skips/).flatten.map { |v| v.to_i }.should == [0,0,0]
29
29
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,21 +44,22 @@ And /^"([^\"]*)" has a MAC address of "([^\"]*)"$/ do |name, mac|
44
44
  end
45
45
 
46
46
  And /^"([^\"]*)" has been provisioned$/ do |name|
47
- $drb_test_lab.server_create(name, @servers[name])
47
+ $test_lab.drb.server_create(name, @servers[name])
48
48
  end
49
49
 
50
50
  And /^the "([^\"]*)" role has been added to the "([^\"]*)" run list$/ do |role, name|
51
- $drb_test_lab.chef_set_client_attributes(@servers[name], :run_list => ["role[#{role}]"])
51
+ $test_lab.drb.chef_set_client_attributes(name, :run_list => ["role[#{role}]"])
52
52
  end
53
53
 
54
54
  And /^the "([^\"]*)" recipe has been added to the "([^\"]*)" run list$/ do |recipe, name|
55
- $drb_test_lab.chef_set_client_attributes(@servers[name], :run_list => ["recipe[#{recipe}]"])
55
+ $test_lab.drb.chef_set_client_attributes(name, :run_list => ["recipe[#{recipe}]"])
56
56
  end
57
57
 
58
58
  And /^"([^\"]*)" is in the "([^\"]*)" environment$/ do |name, environment|
59
- $drb_test_lab.chef_set_client_config(:environment => environment)
59
+ $test_lab.drb.chef_set_client_config(:environment => environment)
60
60
  end
61
61
 
62
62
  And /^the chef-client has been run on "([^\"]*)"$/ do |name|
63
- $drb_test_lab.chef_run_client(name)
63
+ $test_lab.drb.chef_run_client(name)
64
+ chef_client_artifacts(name)
64
65
  end
@@ -1,7 +1,35 @@
1
+ ################################################################################
2
+
3
+ # | id | hostname | username | keyfile |
4
+ # | root | chef-client | root | keyfile |
5
+
6
+ When /^I have the following SSH sessions:$/ do |table|
7
+ lambda {
8
+ @ssh_sessions ||= Hash.new
9
+ table.hashes.each do |hash|
10
+ id = hash["id"]
11
+ @ssh_sessions[id] and !@ssh_sessions[id].closed? and @ssh_sessions[id].close
12
+ @ssh_sessions[id] = ZTK::SSH.new
13
+
14
+ @ssh_sessions[id].config.proxy_host_name = $test_lab.labs_running.first.public_ip_address
15
+ @ssh_sessions[id].config.proxy_user = "ubuntu"
16
+ @ssh_sessions[id].config.proxy_keys = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{@ssh_sessions[id].config.proxy_user}")
17
+
18
+ hash['hostname'] and (@ssh_sessions[id].config.host_name = hash['hostname'])
19
+ hash['username'] and (@ssh_sessions[id].config.user = hash['username'])
20
+ hash['password'] and (@ssh_sessions[id].config.password = hash['password'])
21
+ hash['keyfile'] and (@ssh_sessions[id].config.keys = hash['keyfile'])
22
+ end
23
+ }.should_not raise_error
24
+ end
25
+
26
+ ################################################################################
27
+
1
28
  When /^I ssh to "([^\"]*)" with the following credentials:$/ do |hostname, table|
2
29
  session = table.hashes.first
3
30
  lambda {
4
31
 
32
+ @connection and !@connection.ssh.closed? and @connection.ssh.close
5
33
  @connection = ZTK::SSH.new
6
34
 
7
35
  @connection.config.proxy_host_name = $test_lab.labs_running.first.public_ip_address
@@ -18,6 +46,7 @@ end
18
46
 
19
47
  And /^I run "([^\"]*)"$/ do |command|
20
48
  @output = @connection.exec(command, :silence => true).output
49
+ Cucumber::Chef.logger.info { @output.chomp }
21
50
  end
22
51
 
23
52
  Then /^I should( not)? see "([^\"]*)" in the output$/ do |boolean, string|
@@ -30,9 +59,9 @@ end
30
59
 
31
60
  Then /^I should( not)? see the "([^\"]*)" of "([^\"]*)" in the output$/ do |boolean, key, name|
32
61
  if (!boolean)
33
- @output.should =~ /#{$drb_test_lab.servers[name][key.downcase.to_sym]}/i
62
+ @output.should =~ /#{$test_lab.drb.servers[name][key.downcase.to_sym]}/i
34
63
  else
35
- @output.should_not =~ /#{$drb_test_lab.servers[name][key.downcase.to_sym]}/i
64
+ @output.should_not =~ /#{$test_lab.drb.servers[name][key.downcase.to_sym]}/i
36
65
  end
37
66
  end
38
67
 
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
4
4
  # Author: Zachary Patten <zachary@jovelabs.com>
5
- # Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
5
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
6
6
  # License: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -0,0 +1,111 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary@jovelabs.com>
4
+ # Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
5
+ # License: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ ################################################################################
20
+
21
+ tag = Cucumber::Chef.tag("cucumber-chef")
22
+ puts(" * #{tag}")
23
+ Cucumber::Chef.load_config(tag)
24
+
25
+ if ($test_lab = Cucumber::Chef::TestLab.new) && ($test_lab.labs_running.count > 0)
26
+ $test_lab.ssh.exec("sudo mkdir -p /home/#{$test_lab.ssh.config.user}/.cucumber-chef")
27
+ $test_lab.ssh.exec("sudo cp -f /home/#{$test_lab.ssh.config.user}/.chef/knife.rb /home/#{$test_lab.ssh.config.user}/.cucumber-chef/knife.rb")
28
+ $test_lab.ssh.exec("sudo chown -R #{$test_lab.ssh.config.user}:#{$test_lab.ssh.config.user} /home/#{$test_lab.ssh.config.user}/.cucumber-chef")
29
+
30
+ local_file = Cucumber::Chef.config_rb
31
+ remote_file = File.join("/", "home", $test_lab.ssh.config.user, ".cucumber-chef", "config.rb")
32
+ $test_lab.ssh.upload(local_file, remote_file)
33
+
34
+ $cc_server_thread = Thread.new do
35
+ $test_lab.ssh.exec("sudo pkill -9 -f cc-server")
36
+
37
+ destroy = (ENV['DESTROY'] == '1' ? 'DESTROY="1"' : nil)
38
+ verbose = (ENV['VERBOSE'] == '1' ? 'VERBOSE="1"' : nil)
39
+ command = ["sudo", destroy, verbose, "cc-server", Cucumber::Chef.external_ip].compact.join(" ")
40
+ $test_lab.ssh.exec(command, :silence => false)
41
+
42
+ Kernel.at_exit do
43
+ $test_lab.ssh.close
44
+ end
45
+ end
46
+
47
+ ZTK::TCPSocketCheck.new(:host => $test_lab.labs_running.first.public_ip_address, :port => 8787, :data => "\n\n").wait
48
+
49
+ FileUtils.rm_rf(File.join(Cucumber::Chef.locate(:directory, ".cucumber-chef"), "artifacts"))
50
+ else
51
+ message = "No running cucumber-chef test labs to connect to!"
52
+ Cucumber::Chef.logger.fatal { message }
53
+ raise message
54
+ end
55
+
56
+
57
+ ################################################################################
58
+ # BEFORE HOOK
59
+ ################################################################################
60
+
61
+ Before do |scenario|
62
+ # store the current scenario here; espcially since I don't know a better way to get at this information
63
+ # we use various aspects of the scenario to name our artifacts
64
+ $scenario = scenario
65
+
66
+ # cleanup previous lxc containers if asked
67
+ if ENV['DESTROY']
68
+ log("$containers$ are being destroyed")
69
+ $test_lab.drb.servers.each do |name, value|
70
+ $test_lab.drb.server_destroy(name)
71
+ end
72
+ File.exists?(Cucumber::Chef.servers_bin) && File.delete(Cucumber::Chef.servers_bin)
73
+ else
74
+ log("$containers$ are being persisted")
75
+ end
76
+
77
+ if File.exists?(Cucumber::Chef.servers_bin)
78
+ $test_lab.drb.servers = (Marshal.load(IO.read(Cucumber::Chef.servers_bin)) rescue Hash.new(nil))
79
+ end
80
+
81
+ $test_lab.drb.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
82
+ :validation_client_name => "chef-validator")
83
+ end
84
+
85
+
86
+ ################################################################################
87
+ # AFTER HOOK
88
+ ################################################################################
89
+
90
+ After do |scenario|
91
+ File.open(Cucumber::Chef.servers_bin, 'w') do |f|
92
+ f.puts(Marshal.dump($test_lab.drb.servers))
93
+ end
94
+
95
+ # cleanup non-persistent lxc containers between tests
96
+ $test_lab.drb.servers.select{ |name, attributes| !attributes[:persist] }.each do |name, attributes|
97
+ $test_lab.drb.server_destroy(name)
98
+ end
99
+ end
100
+
101
+
102
+ ################################################################################
103
+ # EXIT HOOK
104
+ ################################################################################
105
+
106
+ Kernel.at_exit do
107
+ $test_lab.drb.shutdown
108
+ $cc_server_thread.kill
109
+ end
110
+
111
+ ################################################################################
@@ -11,90 +11,3 @@ end
11
11
  World do
12
12
  CustomWorld.new
13
13
  end
14
-
15
- ################################################################################
16
-
17
- $logger = ZTK::Logger.new(Cucumber::Chef.log_file)
18
- Cucumber::Chef.is_rc? and ($logger.level = ZTK::Logger::DEBUG)
19
-
20
- message = "cucumber-chef v#{Cucumber::Chef::VERSION}"
21
- print(" * #{message}")
22
- $logger.info { message }
23
-
24
- Cucumber::Chef::Config.load
25
- if ($test_lab = Cucumber::Chef::TestLab.new) && ($test_lab.labs_running.count > 0)
26
-
27
- # fire up our drb server
28
- ssh = ZTK::SSH.new
29
- ssh.config.host_name = $test_lab.labs_running.first.public_ip_address
30
- ssh.config.user = "ubuntu"
31
- ssh.config.keys = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{ssh.config.user}")
32
- ssh.exec("nohup sudo pkill -9 -f cc-server")
33
- ssh.exec("nohup sudo BACKGROUND=yes cc-server #{Cucumber::Chef.external_ip}")
34
- Cucumber::Chef.spinner do
35
- ZTK::TCPSocketCheck.new(:host => $test_lab.labs_running.first.public_ip_address, :port => 8787, :data => "\n\n").wait
36
- end
37
-
38
- # load our test lab knife config
39
- knife_rb = Cucumber::Chef.locate(:file, ".cucumber-chef", "knife.rb")
40
- Chef::Config.from_file(knife_rb)
41
-
42
- # initialize our drb object
43
- $drb_test_lab ||= DRbObject.new_with_uri("druby://#{$test_lab.labs_running.first.public_ip_address}:8787")
44
- $drb_test_lab and DRb.start_service
45
- $drb_test_lab.servers = Hash.new(nil)
46
-
47
- else
48
- puts("No running cucumber-chef test labs to connect to!")
49
- exit(1)
50
- end
51
-
52
- puts(" - connected to test lab")
53
-
54
- ################################################################################
55
-
56
- Before do
57
- $servers_bin ||= (File.join(Cucumber::Chef.locate(:directory, ".cucumber-chef"), "servers.bin") rescue File.expand_path(File.join(ENV['HOME'], "servers.bin")))
58
-
59
- # cleanup previous lxc containers if asked
60
- if ENV['DESTROY']
61
- log("servers", "are being destroyed")
62
- $drb_test_lab.servers.each do |name|
63
- $drb_test_lab.server_destroy(name)
64
- end
65
- File.exists?($servers_bin) && File.delete($servers_bin)
66
- else
67
- log("servers", "are being preserved")
68
- end
69
-
70
- if File.exists?($servers_bin)
71
- $drb_test_lab.servers = (Marshal.load(IO.read($servers_bin)) rescue Hash.new(nil))
72
- end
73
-
74
- $drb_test_lab.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
75
- :validation_client_name => "chef-validator")
76
- end
77
-
78
- ################################################################################
79
-
80
- After do |scenario|
81
- File.open($servers_bin, 'w') do |f|
82
- f.puts(Marshal.dump($drb_test_lab.servers))
83
- end
84
-
85
- Kernel.exit if scenario.failed?
86
-
87
- # cleanup non-persistent lxc containers between tests
88
- $drb_test_lab.servers.select{ |name, attributes| !attributes[:persist] }.each do |name, attributes|
89
- $drb_test_lab.server_destroy(name)
90
- end
91
-
92
- end
93
-
94
- ################################################################################
95
-
96
- Kernel.at_exit do
97
- $drb_test_lab.shutdown
98
- end
99
-
100
- ################################################################################