cucumber-chef 3.0.0.rc.0 → 3.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cucumber-chef CHANGED
@@ -128,7 +128,7 @@ class CucumberChef < Thor
128
128
  # SETUP
129
129
  ################################################################################
130
130
 
131
- desc "setup", "Setup cucumber-chef test lab in Amazon EC2"
131
+ desc "setup", "Setup the cucumber-chef test lab"
132
132
  method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY"
133
133
  def setup
134
134
  boot
@@ -166,7 +166,7 @@ class CucumberChef < Thor
166
166
  # DESTROY
167
167
  ################################################################################
168
168
 
169
- desc "destroy [container]", "Destroy the cucumber-chef test lab in Amazon EC2 or a test lab [container] if specified."
169
+ desc "destroy [container] [...]", "Destroy the cucumber-chef test lab or a single or multiple containers if specified"
170
170
  method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY"
171
171
  def destroy(*args)
172
172
  boot
@@ -207,9 +207,7 @@ class CucumberChef < Thor
207
207
 
208
208
  args.each do |container|
209
209
  ZTK::Benchmark.bench(:message => "Destroy container '#{container}'", :mark => "completed in %0.4f seconds.") do
210
- test_lab.containers.load
211
210
  test_lab.containers.destroy(container)
212
- test_lab.containers.save
213
211
  end
214
212
  end
215
213
 
@@ -234,7 +232,7 @@ class CucumberChef < Thor
234
232
  # UP
235
233
  ################################################################################
236
234
 
237
- desc "up", "Startup the cucumber-chef test lab"
235
+ desc "up", "Power up the cucumber-chef test lab"
238
236
  def up
239
237
  boot
240
238
 
@@ -253,16 +251,16 @@ class CucumberChef < Thor
253
251
  end
254
252
 
255
253
  ################################################################################
256
- # HALT
254
+ # DOWN
257
255
  ################################################################################
258
256
 
259
- desc "halt", "Power off the cucumber-chef test lab"
260
- def halt
257
+ desc "down", "Power off the cucumber-chef test lab"
258
+ def down
261
259
  boot
262
260
 
263
261
  if (test_lab = Cucumber::Chef::TestLab.new) && test_lab.alive?
264
- ZTK::Benchmark.bench(:message => "Halting #{Cucumber::Chef::Config.provider.upcase} instance '#{test_lab.id}'", :mark => "completed in %0.4f seconds.") do
265
- test_lab.halt
262
+ ZTK::Benchmark.bench(:message => "Downing #{Cucumber::Chef::Config.provider.upcase} instance '#{test_lab.id}'", :mark => "completed in %0.4f seconds.") do
263
+ test_lab.down
266
264
  end
267
265
  else
268
266
  raise Cucumber::Chef::Error, "We could not find a running test lab."
@@ -296,14 +294,14 @@ class CucumberChef < Thor
296
294
  fatal(e)
297
295
  end
298
296
 
299
- desc "genmac", "Generate a private MAC address"
297
+ desc "genmac", "Generate an RFC compliant private MAC address"
300
298
  def genmac
301
299
  boot
302
300
 
303
301
  puts Cucumber::Chef::Containers.generate_mac
304
302
  end
305
303
 
306
- desc "genip", "Generate a private IP address"
304
+ desc "genip", "Generate an RFC compliant private IP address"
307
305
  def genip
308
306
  boot
309
307
 
@@ -329,13 +327,13 @@ class CucumberChef < Thor
329
327
  headers = [:name, :alive, :distro, :ip, :mac, :"chef version", :persist]
330
328
  results = ZTK::Report.new.spreadsheet(Cucumber::Chef::Container.all, headers) do |container|
331
329
  chef_version = "N/A"
332
- alive = (test_lab.bootstrap_ssh(:ignore_exit_status => true).exec(%Q{ping -n -c 1 -W 1 #{container.ip}}, :silence => true).exit_code == 0)
330
+ alive = (test_lab.bootstrap_ssh(:ignore_exit_status => true).exec(%(ping -n -c 1 -W 1 #{container.ip}), :silence => true).exit_code == 0)
333
331
  if alive
334
- chef_version = test_lab.proxy_ssh(container.name, :ignore_exit_status => true).exec(%Q{/usr/bin/env chef-client -v}, :silence => true).output.chomp
332
+ chef_version = test_lab.proxy_ssh(container.id, :ignore_exit_status => true).exec(%(/usr/bin/env chef-client -v), :silence => true).output.chomp
335
333
  end
336
334
 
337
335
  OpenStruct.new(
338
- :name => container.name,
336
+ :name => container.id,
339
337
  :ip => container.ip,
340
338
  :mac => container.mac,
341
339
  :distro => container.distro,
@@ -378,8 +376,8 @@ class CucumberChef < Thor
378
376
  # SSH
379
377
  ################################################################################
380
378
 
381
- desc "ssh [container]", "SSH to cucumber-chef test lab or [container] if specified."
382
- method_option :bootstrap, :type => :boolean, :desc => "Use the bootstrap settings.", :default => false
379
+ desc "ssh [container]", "SSH to cucumber-chef test lab or [container] if specified"
380
+ method_option :bootstrap, :type => :boolean, :desc => "Use the bootstrap settings", :default => false
383
381
  def ssh(*args)
384
382
  boot
385
383
 
@@ -571,8 +569,7 @@ class CucumberChef < Thor
571
569
  depreciated_tasks = {
572
570
  "teardown" => "You should execute the 'destroy' task instead.",
573
571
  "info" => "You should execute the 'status' task instead.",
574
- "test" => "You should execute 'cucumber' or 'rspec' directly.",
575
- "down" => "You should execute the 'halt' task instead."
572
+ "test" => "You should execute 'cucumber' or 'rspec' directly."
576
573
  }
577
574
 
578
575
  depreciated_tasks.each do |old_task, message|
@@ -46,7 +46,7 @@ Gem::Specification.new do |s|
46
46
  s.add_dependency("rake", ">= 0.9.2")
47
47
  s.add_dependency("thor", ">= 0.15.2")
48
48
  s.add_dependency("ubuntu_ami", ">= 0.4.0")
49
- s.add_dependency("ztk", ">= 1.0.3")
49
+ s.add_dependency("ztk", ">= 1.0.8")
50
50
 
51
51
  s.add_development_dependency("simplecov", ">= 0.6.4")
52
52
  s.add_development_dependency("pry", ">= 0")
@@ -28,78 +28,94 @@ module Cucumber
28
28
 
29
29
  ################################################################################
30
30
 
31
- def initialize(test_lab, ui=ZTK::UI.new)
32
- @test_lab = test_lab
33
- @ui = ui
34
- end
31
+ def initialize
32
+ tag = Cucumber::Chef.tag("cucumber-chef")
33
+ puts(">>> #{tag}")
34
+ Cucumber::Chef.boot(tag)
35
35
 
36
- ################################################################################
36
+ @ui = ZTK::UI.new(:logger => Cucumber::Chef.logger)
37
37
 
38
- def up(options={})
39
- # user = Cucumber::Chef.lab_user
40
- # home_dir = Cucumber::Chef.lab_user_home_dir
41
- # provider = Cucumber::Chef::Config.provider.to_s
42
- # @test_lab.ssh.exec("sudo mkdir -p #{File.join(home_dir, ".cucumber-chef", provider)}")
43
- # @test_lab.ssh.exec("sudo cp -f #{File.join(home_dir, ".chef", "knife.rb")} #{File.join(home_dir, ".cucumber-chef", provider, "knife.rb")}")
44
- # @test_lab.ssh.exec("sudo chown -R #{user}:#{user} #{File.join(home_dir, ".cucumber-chef")}")
45
-
46
- # local_file = Cucumber::Chef.config_rb
47
- # remote_file = File.join(home_dir, ".cucumber-chef", "config.rb")
48
- # @test_lab.ssh.upload(local_file, remote_file)
49
-
50
- # begin
51
- # self.ping
52
- # rescue
53
- # @background = ZTK::Background.new
54
- # @background.process do
55
- # self.down
56
-
57
- # environment = Array.new
58
- # %w(PURGE VERBOSE LOG_LEVEL).each do |env_var|
59
- # environment << "#{env_var}=#{ENV[env_var].inspect}" if (!ENV[env_var].nil? && !ENV[env_var].empty?)
60
- # end
61
- # environment = environment.join(" ")
62
- # external_ip = Cucumber::Chef.external_ip
63
-
64
- # command = %Q{nohup sudo #{environment} /usr/bin/env cc-server #{external_ip} &}
65
-
66
- # @test_lab.ssh.exec(command, options)
67
- # end
68
-
69
- # Kernel.at_exit do
70
- # self.at_exit
71
- # end
72
- # end
73
-
74
- # ZTK::RescueRetry.try(:tries => 30) do
75
- # self.drb.ping
76
- # end
38
+ if !((@test_lab = Cucumber::Chef::TestLab.new(@ui)) && @test_lab.alive?)
39
+ message = "No running cucumber-chef test labs to connect to!"
40
+ @ui.logger.fatal { message }
41
+ raise message
42
+ end
77
43
 
78
- true
79
44
  end
80
45
 
81
46
  ################################################################################
82
47
 
83
- def down
84
- # (@test_lab.drb.shutdown rescue nil)
85
- end
48
+ def up(options={})
86
49
 
87
- ################################################################################
50
+ # PUSH CHEF-REPO
51
+ #################
52
+ if environment_variable_set?("PUSH")
53
+ # Upload all of the chef-repo environments
54
+ ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo environments to the test lab", :mark => "completed in %0.4f seconds.") do
55
+ @test_lab.knife_cli(%(environment from file ./environments/*.rb), :silence => true)
56
+ end
57
+
58
+ # Upload all of the chef-repo cookbooks
59
+ ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo cookbooks to the test lab", :mark => "completed in %0.4f seconds.") do
60
+ cookbook_paths = ["./cookbooks"]
61
+ cookbook_paths << "./site-cookbooks" if Cucumber::Chef::Config.librarian_chef
62
+ @test_lab.knife_cli(%(cookbook upload --all --cookbook-path #{cookbook_paths.join(':')} --force), :silence => true)
63
+ end
64
+
65
+ # Upload all of the chef-repo roles
66
+ ZTK::Benchmark.bench(:message => ">>> Pushing chef-repo roles to the test lab", :mark => "completed in %0.4f seconds.") do
67
+ @test_lab.knife_cli(%(role from file ./roles/*.rb), :silence => true)
68
+ end
69
+
70
+ # Upload all of our chef-repo data bags
71
+ Dir.glob("./data_bags/*").each do |data_bag_path|
72
+ next if !File.directory?(data_bag_path)
73
+ 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
74
+ data_bag = File.basename(data_bag_path)
75
+ @test_lab.knife_cli(%(data bag create "#{data_bag}"), :silence => true)
76
+ @test_lab.knife_cli(%(data bag from file "#{data_bag}" "#{data_bag_path}"), :silence => true)
77
+ end
78
+ end
79
+ end
80
+
81
+ # PURGE CONTAINERS
82
+ ###################
83
+ if environment_variable_set?("PURGE")
84
+ @ui.logger.warn { "PURGING CONTAINERS! Container attributes will be reset!" }
85
+ @test_lab.containers.list.each do |name|
86
+ ZTK::Benchmark.bench(:message => ">>> Destroying container '#{name}'", :mark => "completed in %0.4f seconds.") do
87
+ @test_lab.containers.destroy(name)
88
+ end
89
+ end
90
+ else
91
+ @ui.logger.info { "Allowing existing containers to persist." }
92
+ end
93
+
94
+ # CREATE CONTAINERS
95
+ ####################
96
+ Cucumber::Chef::Container.all.each do |container|
97
+ ZTK::Benchmark.bench(:message => ">>> Creating container '#{container.id}'", :mark => "completed in %0.4f seconds.") do
98
+ @test_lab.containers.create(container)
99
+ end
100
+ end
101
+
102
+ # PROVISION CONTAINERS
103
+ #######################
104
+ @test_lab.containers.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
105
+ :validation_client_name => "chef-validator")
106
+ Cucumber::Chef::Container.all.each do |container|
107
+ ZTK::Benchmark.bench(:message => ">>> Provisioning container '#{container.id}'", :mark => "completed in %0.4f seconds.") do
108
+ @test_lab.containers.provision(container)
109
+ end
110
+ end
88
111
 
89
- # def drb
90
- # @drb and DRb.stop_service
91
- # @drb = DRbObject.new_with_uri("druby://#{@test_lab.ip}:8787")
92
- # @drb and DRb.start_service
93
- # @drb
94
- # end
112
+ true
113
+ end
95
114
 
96
115
  ################################################################################
97
116
 
98
117
  def before(scenario)
99
- # store the current scenario here; espcially since I don't know a better way to get at this information
100
- # we use various aspects of the scenario to name our artifacts
101
118
  $scenario = scenario
102
-
103
119
  end
104
120
 
105
121
  ################################################################################
@@ -109,13 +125,20 @@ module Cucumber
109
125
 
110
126
  ################################################################################
111
127
 
112
- # def at_exit
113
- # @ui.logger.fatal { "Waiting for cc-server to shutdown." }
114
- # self.down
115
- # @background.wait
116
- # end
128
+ def at_exit
129
+ end
117
130
 
118
131
  ################################################################################
132
+ private
133
+ ################################################################################
134
+
135
+ def environment_variable_set?(variable_name)
136
+ raise "You must supply an environment variable name!" if variable_name.nil?
137
+
138
+ variable_name = variable_name.strip.upcase
139
+
140
+ (!ENV[variable_name].nil? && ((ENV[variable_name] == '1') || (ENV[variable_name].strip.upcase == 'YES')))
141
+ end
119
142
 
120
143
  end
121
144
 
@@ -43,7 +43,7 @@ module Cucumber
43
43
 
44
44
  def create(container)
45
45
  # if this is a new or non-persistent container destroy it
46
- destroy(container.name) if !container.persist
46
+ destroy(container.id) if !container.persist
47
47
 
48
48
  container.ip ||= self.generate_ip
49
49
  container.mac ||= self.generate_mac
@@ -52,26 +52,26 @@ module Cucumber
52
52
  container.release ||= "lucid"
53
53
  container.arch = detect_arch(container.distro || "ubuntu")
54
54
 
55
- if running?(container.name)
56
- @ui.logger.info { "Container '#{container.name}' is already running." }
55
+ if running?(container.id)
56
+ @ui.logger.info { "Container '#{container.id}' is already running." }
57
57
  else
58
58
  @ui.logger.info { "Please wait, creating container #{container.inspect}." }
59
59
  bm = ::Benchmark.realtime do
60
60
  test_lab_config_dhcpd
61
61
  config_network(container)
62
- _create(container.name, container.distro, container.release, container.arch)
62
+ _create(container.id, container.distro, container.release, container.arch)
63
63
  end
64
- @ui.logger.info { "Container '#{container.name}' creation took %0.4f seconds." % bm }
64
+ @ui.logger.info { "Container '#{container.id}' creation took %0.4f seconds." % bm }
65
65
 
66
66
  bm = ::Benchmark.realtime do
67
67
  ZTK::RescueRetry.try(:tries => 32) do
68
- @test_lab.ssh.exec("host #{container.name}", :silence => true)
68
+ @test_lab.ssh.exec("host #{container.id}", :silence => true)
69
69
  end
70
70
  ZTK::RescueRetry.try(:tries => 32) do
71
- @test_lab.proxy_ssh(container.name).exec("uptime", :silence => true)
71
+ @test_lab.proxy_ssh(container.id).exec("uptime", :silence => true)
72
72
  end
73
73
  end
74
- @ui.logger.info { "Container '#{container.name}' SSHD responded after %0.4f seconds." % bm }
74
+ @ui.logger.info { "Container '#{container.id}' SSHD responded after %0.4f seconds." % bm }
75
75
  end
76
76
  end
77
77
 
@@ -89,11 +89,17 @@ module Cucumber
89
89
  end
90
90
  end
91
91
 
92
+ ################################################################################
93
+
94
+ def provision(container, *args)
95
+ @test_lab.containers.chef_run_client(container, *args)
96
+ end
97
+
92
98
  ################################################################################
93
99
 
94
100
  def chef_set_client_config(config={})
95
101
  @chef_client_config = (@chef_client_config || {
96
- :log_level => :info,
102
+ :log_level => :debug,
97
103
  :log_location => "/var/log/chef/client.log",
98
104
  :chef_server_url => "https://api.opscode.com/organizations/#{config[:orgname]}",
99
105
  :validation_client_name => "#{config[:orgname]}-validator",
@@ -112,12 +118,12 @@ module Cucumber
112
118
  chef_config_client(container)
113
119
 
114
120
  @ui.logger.info { "Removing artifacts #{Cucumber::Chef::Config[:artifacts].values.collect{|z| "'#{z}'" }.join(' ')}." }
115
- (@test_lab.proxy_ssh(container.name).exec("/bin/rm -fv #{Cucumber::Chef::Config[:artifacts].values.join(' ')}", :silence => true) rescue nil)
121
+ (@test_lab.proxy_ssh(container.id).exec("/bin/rm -fv #{Cucumber::Chef::Config[:artifacts].values.join(' ')}", :silence => true) rescue nil)
116
122
 
117
- @ui.logger.info { "Running chef client on container '#{container.name}'." }
123
+ @ui.logger.info { "Running chef client on container '#{container.id}'." }
118
124
 
119
125
  arguments = {
120
- "--node-name" => container.name,
126
+ "--node-name" => container.id,
121
127
  "--json-attributes" => File.join("/etc", "chef", "attributes.json").to_s,
122
128
  "--log_level" => @chef_client_config[:log_level],
123
129
  "--logfile" => @chef_client_config[:log_location],
@@ -127,9 +133,9 @@ module Cucumber
127
133
 
128
134
  output = nil
129
135
  bm = ::Benchmark.realtime do
130
- output = @test_lab.proxy_ssh(container.name).exec(["/usr/bin/chef-client", arguments, args, "--once"].flatten.join(" "), :silence => true)
136
+ output = @test_lab.proxy_ssh(container.id).exec(["/usr/bin/chef-client", arguments, args, "--once"].flatten.join(" "), :silence => true, :ignore_exit_status => true)
131
137
  end
132
- @ui.logger.info { "Chef client run on container '#{container.name}' took %0.4f seconds." % bm }
138
+ @ui.logger.info { "Chef client run on container '#{container.id}' took %0.4f seconds." % bm }
133
139
 
134
140
  chef_client_artifacts(container)
135
141
 
@@ -190,7 +196,7 @@ module Cucumber
190
196
  ################################################################################
191
197
 
192
198
  def list
193
- @test_lab.bootstrap_ssh.exec("sudo lxc-ls 2>&1", :silence => true).output.split("\n").uniq
199
+ @test_lab.bootstrap_ssh.exec("sudo lxc-ls 2>&1", :silence => true).output.strip.split(" ").uniq
194
200
  end
195
201
 
196
202
  ################################################################################
@@ -213,37 +219,37 @@ module Cucumber
213
219
  omnibus_chef_client = File.join("/", "opt", "chef", "bin", "chef-client")
214
220
  omnibus_cache = File.join(cache_rootfs, omnibus_chef_client)
215
221
  @ui.logger.info { "looking for omnibus cache in #{omnibus_cache}" }
216
- if @test_lab.bootstrap_ssh.exec(%Q{sudo /bin/bash -c '[[ -f #{omnibus_cache} ]] ; echo $? ; true'}, :silence => true).output.chomp =~ /1/
222
+ if @test_lab.bootstrap_ssh.exec(%(sudo /bin/bash -c '[[ -f #{omnibus_cache} ]]'), :silence => true, :ignore_exit_status => true).exit_code == 1
217
223
  case distro.downcase
218
224
  when "ubuntu" then
219
- @test_lab.bootstrap_ssh.exec(%Q{sudo chroot #{cache_rootfs} /bin/bash -c 'DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install wget'}, :silence => true)
225
+ @test_lab.bootstrap_ssh.exec(%(sudo chroot #{cache_rootfs} /bin/bash -c 'DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install wget'), :silence => true)
220
226
  when "fedora" then
221
- @test_lab.bootstrap_ssh.exec(%Q{sudo yum --nogpgcheck --installroot=#{cache_rootfs} -y install wget openssh-server}, :silence => true)
227
+ @test_lab.bootstrap_ssh.exec(%(sudo yum --nogpgcheck --installroot=#{cache_rootfs} -y install wget openssh-server), :silence => true)
222
228
  end
223
- @test_lab.bootstrap_ssh.exec(%Q{sudo chroot #{cache_rootfs} /bin/bash -c 'locale-gen'}, :silence => true)
224
- @test_lab.bootstrap_ssh.exec(%Q{sudo chroot #{cache_rootfs} /bin/bash -c 'locale-gen en_US'}, :silence => true)
225
- @test_lab.bootstrap_ssh.exec(%Q{sudo chroot #{cache_rootfs} /bin/bash -c 'wget http://www.opscode.com/chef/install.sh'}, :silence => true)
226
- @test_lab.bootstrap_ssh.exec(%Q{sudo chroot #{cache_rootfs} /bin/bash -c 'bash install.sh -v #{Cucumber::Chef::Config.chef[:version]}'}, :silence => true)
229
+ @test_lab.bootstrap_ssh.exec(%(sudo chroot #{cache_rootfs} /bin/bash -c 'locale-gen'), :silence => true)
230
+ @test_lab.bootstrap_ssh.exec(%(sudo chroot #{cache_rootfs} /bin/bash -c 'locale-gen en_US'), :silence => true)
231
+ @test_lab.bootstrap_ssh.exec(%(sudo chroot #{cache_rootfs} /bin/bash -c 'wget http://www.opscode.com/chef/install.sh'), :silence => true)
232
+ @test_lab.bootstrap_ssh.exec(%(sudo chroot #{cache_rootfs} /bin/bash -c 'bash install.sh -v #{Cucumber::Chef::Config.chef[:version]}'), :silence => true)
227
233
  if distro.downcase == "fedora"
228
- @test_lab.bootstrap_ssh.exec(%Q{sudo chroot #{cache_rootfs} /bin/bash -c 'rpm -Uvh --nodeps /tmp/*rpm'}, :silence => true)
234
+ @test_lab.bootstrap_ssh.exec(%(sudo chroot #{cache_rootfs} /bin/bash -c 'rpm -Uvh --nodeps /tmp/*rpm'), :silence => true)
229
235
  end
230
- @test_lab.bootstrap_ssh.exec(%Q{sudo lxc-destroy -n #{name}}, :silence => true)
231
- @test_lab.bootstrap_ssh.exec(%Q{sudo #{create_command(name, distro, release, arch)}}, :silence => true)
236
+ @test_lab.bootstrap_ssh.exec(%(sudo lxc-destroy -n #{name}), :silence => true)
237
+ @test_lab.bootstrap_ssh.exec(%(sudo #{create_command(name, distro, release, arch)}), :silence => true)
232
238
  end
233
239
 
234
240
  lab_ssh_path = File.join(Cucumber::Chef.lab_user_home_dir, ".ssh")
235
241
  ssh_path = File.join(root(name), Cucumber::Chef.lxc_user_home_dir, ".ssh")
236
242
  motd_path = File.join(root(name), "etc", "motd")
237
243
 
238
- @test_lab.bootstrap_ssh.exec(%Q{sudo mkdir -vp #{ssh_path}}, :silence => true)
239
- @test_lab.bootstrap_ssh.exec(%Q{sudo chmod 0700 #{ssh_path}}, :silence => true)
240
- @test_lab.bootstrap_ssh.exec(%Q{sudo cat #{File.join(lab_ssh_path, "id_rsa.pub")} | sudo tee -a #{File.join(ssh_path, "authorized_keys")}}, :silence => true)
244
+ @test_lab.bootstrap_ssh.exec(%(sudo mkdir -vp #{ssh_path}), :silence => true)
245
+ @test_lab.bootstrap_ssh.exec(%(sudo chmod 0700 #{ssh_path}), :silence => true)
246
+ @test_lab.bootstrap_ssh.exec(%(sudo cat #{File.join(lab_ssh_path, "id_rsa.pub")} | sudo tee -a #{File.join(ssh_path, "authorized_keys")}), :silence => true)
241
247
 
242
- @test_lab.bootstrap_ssh.exec(%Q{sudo rm -vf #{motd_path}}, :silence => true)
243
- @test_lab.bootstrap_ssh.exec(%Q{sudo cp -v /etc/motd #{motd_path}}, :silence => true)
244
- @test_lab.bootstrap_ssh.exec(%Q{echo " You are now logged in to the "#{name}" container!\n" | sudo tee -a #{motd_path}}, :silence => true)
245
- @test_lab.bootstrap_ssh.exec(%Q{echo "127.0.0.1 #{name}.#{Cucumber::Chef::Config.test_lab[:tld]} #{name}" | sudo tee -a #{File.join(root(name), "etc", "hosts")}}, :silence => true)
246
- @test_lab.bootstrap_ssh.exec(%Q{echo "#{name}.test-lab" | sudo tee #{File.join(root(name), "etc", "hostname")}}, :silence => true)
248
+ @test_lab.bootstrap_ssh.exec(%(sudo rm -vf #{motd_path}), :silence => true)
249
+ @test_lab.bootstrap_ssh.exec(%(sudo cp -v /etc/motd #{motd_path}), :silence => true)
250
+ @test_lab.bootstrap_ssh.exec(%(echo " You are now logged in to the "#{name}" container!\n" | sudo tee -a #{motd_path}), :silence => true)
251
+ @test_lab.bootstrap_ssh.exec(%(echo "127.0.0.1 #{name}.#{Cucumber::Chef::Config.test_lab[:tld]} #{name}" | sudo tee -a #{File.join(root(name), "etc", "hosts")}), :silence => true)
252
+ @test_lab.bootstrap_ssh.exec(%(echo "#{name}.test-lab" | sudo tee #{File.join(root(name), "etc", "hostname")}), :silence => true)
247
253
  end
248
254
  start(name)
249
255
  end
@@ -251,26 +257,26 @@ module Cucumber
251
257
  ################################################################################
252
258
 
253
259
  def start(name)
254
- status = @test_lab.bootstrap_ssh.exec("sudo lxc-info -n #{name}", :silence => true).output
260
+ status = @test_lab.bootstrap_ssh.exec(%(sudo lxc-info -n #{name}), :silence => true).output
255
261
  if status.include?("STOPPED")
256
- @test_lab.bootstrap_ssh.exec("sudo lxc-start -d -n #{name}", :silence => true)
262
+ @test_lab.bootstrap_ssh.exec(%(sudo lxc-start -d -n #{name}), :silence => true)
257
263
  end
258
264
  end
259
265
 
260
266
  def stop(name)
261
- status = @test_lab.bootstrap_ssh.exec("sudo lxc-info -n #{name}", :silence => true).output
267
+ status = @test_lab.bootstrap_ssh.exec(%(sudo lxc-info -n #{name}), :silence => true).output
262
268
  if status.include?("RUNNING")
263
- @test_lab.bootstrap_ssh.exec("sudo lxc-stop -n #{name}", :silence => true)
269
+ @test_lab.bootstrap_ssh.exec(%(sudo lxc-stop -n #{name}), :silence => true)
264
270
  end
265
271
  end
266
272
 
267
273
  ################################################################################
268
274
 
269
275
  def chef_config_client(container)
270
- tempfile = Tempfile.new(container.name)
271
- client_rb = File.join("/", root(container.name), "etc/chef/client.rb")
276
+ tempfile = Tempfile.new(container.id)
277
+ client_rb = File.join("/", root(container.id), "etc/chef/client.rb")
272
278
 
273
- @test_lab.bootstrap_ssh.exec(%Q{sudo mkdir -pv #{File.dirname(client_rb)}}, :silence => true)
279
+ @test_lab.bootstrap_ssh.exec(%(sudo mkdir -pv #{File.dirname(client_rb)}), :silence => true)
274
280
 
275
281
  if Cucumber::Chef::Config.chef[:render_client_rb]
276
282
  max_key_size = @chef_client_config.keys.collect{ |z| z.to_s.size }.max
@@ -278,7 +284,7 @@ module Cucumber
278
284
  File.open(tempfile, 'w') do |f|
279
285
  f.puts(Cucumber::Chef.generate_do_not_edit_warning("Chef Client Configuration"))
280
286
  f.puts
281
- @chef_client_config.merge(:node_name => container.name).each do |(key,value)|
287
+ @chef_client_config.merge(:node_name => container.id).each do |(key,value)|
282
288
  next if value.nil?
283
289
  f.puts("%-#{max_key_size}s %s" % [key, value.inspect])
284
290
  end
@@ -286,25 +292,25 @@ module Cucumber
286
292
  f.puts("Mixlib::Log::Formatter.show_time = true")
287
293
  end
288
294
  @test_lab.bootstrap_ssh.upload(tempfile.path, File.basename(tempfile.path))
289
- @test_lab.bootstrap_ssh.exec(%Q{sudo mv -v #{File.basename(tempfile.path)} #{client_rb}}, :silence => true)
295
+ @test_lab.bootstrap_ssh.exec(%(sudo mv -v #{File.basename(tempfile.path)} #{client_rb}), :silence => true)
290
296
  else
291
- @test_lab.bootstrap_ssh.exec(%Q{sudo /bin/bash -c '[[ -f #{client_rb} ]] && rm -fv #{client_rb}'}, :silence => true, :ignore_exit_status => true)
297
+ @test_lab.bootstrap_ssh.exec(%(sudo /bin/bash -c '[[ -f #{client_rb} ]] && rm -fv #{client_rb}'), :silence => true, :ignore_exit_status => true)
292
298
  end
293
299
 
294
- tempfile = Tempfile.new(container.name)
295
- attributes_json = File.join("/", root(container.name), "etc", "chef", "attributes.json")
296
- @test_lab.bootstrap_ssh.exec(%Q{sudo mkdir -pv #{File.dirname(attributes_json)}}, :silence => true)
300
+ tempfile = Tempfile.new(container.id)
301
+ attributes_json = File.join("/", root(container.id), "etc", "chef", "attributes.json")
302
+ @test_lab.bootstrap_ssh.exec(%(sudo mkdir -pv #{File.dirname(attributes_json)}), :silence => true)
297
303
  File.open(tempfile, 'w') do |f|
298
304
  f.puts((container.chef_client || {}).to_json)
299
305
  end
300
306
  @test_lab.bootstrap_ssh.upload(tempfile.path, File.basename(tempfile.path))
301
- @test_lab.bootstrap_ssh.exec(%Q{sudo mv -v #{File.basename(tempfile.path)} #{attributes_json}}, :silence => true)
307
+ @test_lab.bootstrap_ssh.exec(%(sudo mv -v #{File.basename(tempfile.path)} #{attributes_json}), :silence => true)
302
308
 
303
309
  # make sure our log location is there
304
- log_location = File.join("/", root(container.name), @chef_client_config[:log_location])
305
- @test_lab.bootstrap_ssh.exec(%Q{sudo mkdir -pv #{File.dirname(log_location)}}, :silence => true)
310
+ log_location = File.join("/", root(container.id), @chef_client_config[:log_location])
311
+ @test_lab.bootstrap_ssh.exec(%(sudo mkdir -pv #{File.dirname(log_location)}), :silence => true)
306
312
 
307
- @test_lab.bootstrap_ssh.exec(%Q{sudo cp /etc/chef/validation.pem #{root(container.name)}/etc/chef/}, :silence => true)
313
+ @test_lab.bootstrap_ssh.exec(%(sudo cp /etc/chef/validation.pem #{root(container.id)}/etc/chef/), :silence => true)
308
314
 
309
315
  true
310
316
  end
@@ -312,14 +318,14 @@ module Cucumber
312
318
  ################################################################################
313
319
 
314
320
  def chef_client_artifacts(container)
315
- ssh = @test_lab.proxy_ssh(container.name)
321
+ ssh = @test_lab.proxy_ssh(container.id)
316
322
 
317
323
  Cucumber::Chef::Config[:artifacts].each do |label, remote_path|
318
- result = ssh.exec("sudo /bin/bash -c '[[ -f #{remote_path} ]] ; echo $? ; true'", :silence => true)
324
+ result = ssh.exec(%(sudo /bin/bash -c '[[ -f #{remote_path} ]] ; echo $? ; true'), :silence => true)
319
325
  if (result.output =~ /0/)
320
- @ui.logger.info { "Retrieving artifact '#{remote_path}' from container '#{container.name}'." }
326
+ @ui.logger.info { "Retrieving artifact '#{remote_path}' from container '#{container.id}'." }
321
327
 
322
- local_path = File.join(Cucumber::Chef.artifacts_dir, "#{container.name}.log")
328
+ local_path = File.join(Cucumber::Chef.artifacts_dir, "#{container.id}-#{File.basename(remote_path)}")
323
329
  tmp_path = File.join("/tmp", label)
324
330
 
325
331
  FileUtils.mkdir_p(File.dirname(local_path))
@@ -339,8 +345,8 @@ module Cucumber
339
345
  ################################################################################
340
346
 
341
347
  def config_network(container)
342
- tempfile = Tempfile.new(container.name)
343
- lxc_network_config = File.join("/etc/lxc", container.name)
348
+ tempfile = Tempfile.new(container.id)
349
+ lxc_network_config = File.join("/etc/lxc", container.id)
344
350
  File.open(tempfile, 'w') do |f|
345
351
  f.puts(Cucumber::Chef.generate_do_not_edit_warning("LXC Container Configuration"))
346
352
  f.puts("")
@@ -352,7 +358,7 @@ module Cucumber
352
358
  f.puts("lxc.network.ipv4 = 0.0.0.0")
353
359
  end
354
360
  @test_lab.bootstrap_ssh.upload(tempfile.path, File.basename(tempfile.path))
355
- @test_lab.bootstrap_ssh.exec(%Q{sudo mv -v #{File.basename(tempfile.path)} #{lxc_network_config}}, :silence => true)
361
+ @test_lab.bootstrap_ssh.exec(%(sudo mv -v #{File.basename(tempfile.path)} #{lxc_network_config}), :silence => true)
356
362
  end
357
363
 
358
364
  ################################################################################
@@ -366,17 +372,17 @@ module Cucumber
366
372
  next if [container.mac, container.ip].any?{ |z| z.nil? }
367
373
 
368
374
  f.puts
369
- f.puts("host #{container.name} {")
375
+ f.puts("host #{container.id} {")
370
376
  f.puts(" hardware ethernet #{container.mac};")
371
377
  f.puts(" fixed-address #{container.ip};")
372
- f.puts(" ddns-hostname \"#{container.name}\";")
378
+ f.puts(" ddns-hostname \"#{container.id}\";")
373
379
  f.puts("}")
374
380
  end
375
381
  f.flush
376
382
  f.close
377
383
  end
378
384
  @test_lab.bootstrap_ssh.upload(tempfile.path, File.basename(tempfile.path))
379
- @test_lab.bootstrap_ssh.exec(%Q{sudo mv -v #{File.basename(tempfile.path)} #{dhcpd_config}}, :silence => true)
385
+ @test_lab.bootstrap_ssh.exec(%(sudo mv -v #{File.basename(tempfile.path)} #{dhcpd_config}), :silence => true)
380
386
 
381
387
  @test_lab.bootstrap_ssh.exec("sudo service isc-dhcp-server restart", :silence => true)
382
388
  @test_lab.bootstrap_ssh.exec("sudo service bind9 restart", :silence => true)
@@ -397,14 +403,14 @@ module Cucumber
397
403
  ################################################################################
398
404
 
399
405
  def running?(name)
400
- status = @test_lab.bootstrap_ssh.exec("sudo lxc-info -n #{name}", :silence => true).output.chomp
406
+ status = @test_lab.bootstrap_ssh.exec(%(sudo lxc-info -n #{name}), :silence => true).output.chomp
401
407
  status.include?("RUNNING")
402
408
  end
403
409
 
404
410
  ################################################################################
405
411
 
406
412
  def exists?(name)
407
- (@test_lab.bootstrap_ssh.exec("sudo /bin/bash -c '[[ -d #{root(name)} ]] ; echo $? ; true'", :silence => true).output.chomp =~ /0/)
413
+ (@test_lab.bootstrap_ssh.exec(%(sudo /bin/bash -c '[[ -d #{root(name)} ]] ; echo $? ; true'), :silence => true).output.chomp =~ /0/)
408
414
  end
409
415
 
410
416
  ################################################################################
@@ -429,9 +435,9 @@ module Cucumber
429
435
  def create_command(name, distro, release, arch)
430
436
  case distro.downcase
431
437
  when "ubuntu" then
432
- "sudo DEBIAN_FRONTEND=noninteractive lxc-create -n #{name} -f /etc/lxc/#{name} -t #{distro} -- --release #{release} --arch #{arch}"
438
+ %(sudo DEBIAN_FRONTEND=noninteractive lxc-create -n #{name} -f /etc/lxc/#{name} -t #{distro} -- --release #{release} --arch #{arch})
433
439
  when "fedora" then
434
- "sudo lxc-create -n #{name} -f /etc/lxc/#{name} -t #{distro} -- --release #{release}"
440
+ %(sudo lxc-create -n #{name} -f /etc/lxc/#{name} -t #{distro} -- --release #{release})
435
441
  end
436
442
  end
437
443