lib/cucumber/chef/provisioner.rb in cucumber-chef-3.0.0.rc.4 vs lib/cucumber/chef/provisioner.rb in cucumber-chef-3.0.0.rc.5
- old
+ new
@@ -35,14 +35,10 @@
@test_lab = test_lab
@ui = ui
@cookbooks_path = File.join(Cucumber::Chef.root_dir, "chef_repo", "cookbooks")
@roles_path = File.join(Cucumber::Chef.root_dir, "chef_repo", "roles")
-
- @chef_pre_11 = Cucumber::Chef::Config.chef_pre_11
- bootstrap_template_file = (@chef_pre_11 ? 'ubuntu-precise-apt.erb' : 'ubuntu-precise-omnibus.erb')
- @bootstrap_template = File.join(Cucumber::Chef.root_dir, "lib", "cucumber", "chef", "templates", "bootstrap", bootstrap_template_file)
end
################################################################################
def build
@@ -67,37 +63,56 @@
@ui.logger.debug { "local_path == #{local_path.inspect}" }
remote_path = File.join("/tmp", "chef-solo")
@ui.logger.debug { "remote_path == #{remote_path.inspect}" }
- @test_lab.bootstrap_ssh.exec(%(rm -rf #{remote_path} ; mkdir -p #{remote_path}))
- @test_lab.bootstrap_ssh.upload(local_path, remote_path)
-
- # %w(Gemfile Gemfile.lock).each do |file|
- # local_file = File.join(Cucumber::Chef.chef_repo, file)
- # remote_file = File.join(remote_path, file)
-
- # @test_lab.bootstrap_ssh.upload(local_file, remote_file)
- # end
+ # FIXME!
+ # there seems to be a major difference between net-sftp v2.0.5 and
+ # v2.1.1; under v2.0.5 the remote_path is expected to exist already so
+ # if it is not in place mkdir fails with Net::SFTP::StatusException on
+ # the Net::SFTP mkdir internal call triggered by a Net::SFTP upload
+ # call
+ @test_lab.bootstrap_ssh.exec(%(rm -rf #{remote_path}))
+ begin
+ @test_lab.bootstrap_ssh.upload(local_path, remote_path)
+ rescue Net::SFTP::StatusException => e
+ @test_lab.bootstrap_ssh.exec(%(mkdir -p #{remote_path}))
+ retry
+ end
end
end
################################################################################
def bootstrap
raise ProvisionerError, "You must have the environment variable 'USER' set." if !Cucumber::Chef::Config.user
ZTK::Benchmark.bench(:message => "Bootstrapping #{Cucumber::Chef::Config.provider.upcase} instance", :mark => "completed in %0.4f seconds.", :ui => @ui) do
- chef_client_attributes = {
- "run_list" => %w(role[test_lab]),
- "cucumber_chef" => {
- "version" => Cucumber::Chef::VERSION,
- "prerelease" => Cucumber::Chef::Config.prerelease
- },
- "lab_user" => Cucumber::Chef.lab_user,
- "lxc_user" => Cucumber::Chef.lxc_user
- }
+ chef_client_attributes = if Cucumber::Chef.chef_pre_11
+ {
+ "run_list" => %w(role[test_lab] recipe[chef-server::default] recipe[chef-server::apache-proxy] recipe[chef-client]),
+ "cucumber_chef" => {
+ "version" => Cucumber::Chef::VERSION,
+ "prerelease" => Cucumber::Chef::Config.prerelease,
+ "lab_user" => Cucumber::Chef.lab_user,
+ "lxc_user" => Cucumber::Chef.lxc_user
+ },
+ "chef-server" => {
+ "webui_enabled" => true
+ }
+ }
+ else
+ {
+ "run_list" => %w(role[test_lab]),
+ "cucumber_chef" => {
+ "version" => Cucumber::Chef::VERSION,
+ "prerelease" => Cucumber::Chef::Config.prerelease,
+ "lab_user" => Cucumber::Chef.lab_user,
+ "lxc_user" => Cucumber::Chef.lxc_user
+ }
+ }
+ end
context = {
:chef_client_attributes => chef_client_attributes,
:amqp_password => Cucumber::Chef::Config.chef[:amqp_password],
:admin_password => Cucumber::Chef::Config.chef[:admin_password],
@@ -106,16 +121,19 @@
:hostname_full => Cucumber::Chef.lab_hostname_full,
:chef_server_version => Cucumber::Chef::Config.chef[:server_version],
:chef_client_version => Cucumber::Chef::Config.chef[:client_version]
}
+ bootstrap_template_file = (Cucumber::Chef.chef_pre_11 ? 'ubuntu-precise-apt.erb' : 'ubuntu-precise-omnibus.erb')
+ bootstrap_template = File.join(Cucumber::Chef.root_dir, "lib", "cucumber", "chef", "templates", "bootstrap", bootstrap_template_file)
+
local_bootstrap_file = Tempfile.new("bootstrap")
local_bootstrap_filename = local_bootstrap_file.path
- local_bootstrap_file.write(::ZTK::Template.render(@bootstrap_template, context))
+ local_bootstrap_file.write(::ZTK::Template.render(bootstrap_template, context))
local_bootstrap_file.close
- remote_bootstrap_filename = File.join(Cucumber::Chef.lab_user_home_dir, "cucumber-chef-bootstrap.sh")
+ remote_bootstrap_filename = File.join('/tmp', 'cucumber-chef-bootstrap.sh')
@test_lab.bootstrap_ssh.upload(local_bootstrap_filename, remote_bootstrap_filename)
local_bootstrap_file.unlink
@@ -133,11 +151,11 @@
remote_path = File.join(Cucumber::Chef.lab_user_home_dir, ".chef")
@ui.logger.debug { "remote_path == #{remote_path.inspect}" }
files = [ File.basename(Cucumber::Chef.chef_identity) ]
- if (@chef_pre_11 == true)
+ if (Cucumber::Chef.chef_pre_11 == true)
files << "validation.pem"
else
files << "chef-validator.pem"
end
files.each do |file|
@@ -178,20 +196,20 @@
end
################################################################################
def wait_for_chef_server
- if (@chef_pre_11 == true)
+ if (Cucumber::Chef.chef_pre_11 == true)
ZTK::Benchmark.bench(:message => "Waiting for the chef-server", :mark => "completed in %0.4f seconds.", :ui => @ui) do
ZTK::TCPSocketCheck.new(:host => @test_lab.ip, :port => 4000, :data => "GET", :wait => 120).wait
end
ZTK::Benchmark.bench(:message => "Waiting for the chef-server-webui", :mark => "completed in %0.4f seconds.", :ui => @ui) do
ZTK::TCPSocketCheck.new(:host => @test_lab.ip, :port => 4040, :data => "GET", :wait => 120).wait
end
else
ZTK::Benchmark.bench(:message => "Waiting for the chef-server nginx daemon", :mark => "completed in %0.4f seconds.", :ui => @ui) do
- ZTK::TCPSocketCheck.new(:host => @test_lab.ip, :port => 8080, :data => "GET", :wait => 120).wait
+ ZTK::TCPSocketCheck.new(:host => @test_lab.ip, :port => 80, :data => "GET", :wait => 120).wait
end
end
end
################################################################################