lib/cucumber/chef/provisioner.rb in cucumber-chef-2.1.0.rc.6 vs lib/cucumber/chef/provisioner.rb in cucumber-chef-2.1.0.rc.7
- old
+ new
@@ -23,19 +23,19 @@
module Chef
class ProvisionerError < Error; end
class Provisioner
- attr_accessor :test_lab, :stdout, :stderr, :stdin
+ attr_accessor :test_lab
################################################################################
- def initialize(test_lab, stdout=STDOUT, stderr=STDERR, stdin=STDIN)
- @stdout, @stderr, @stdin = stdout, stderr, stdin
- @stdout.sync = true if @stdout.respond_to?(:sync=)
+ def initialize(test_lab, ui=ZTK::UI.new)
+ test_lab.nil? and raise ProvisionerError, "You must supply a test lab!"
@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")
@bootstrap_template = File.join(Cucumber::Chef.root_dir, "lib", "cucumber", "chef", "templates", "bootstrap", "ubuntu-precise-test-lab.erb")
end
@@ -67,11 +67,11 @@
################################################################################
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.", :stdout => @stdout) do
+ 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" => "role[test_lab]",
"cucumber_chef" => {
"version" => Cucumber::Chef::VERSION,
"prerelease" => Cucumber::Chef::Config.prerelease
@@ -84,11 +84,12 @@
:chef_client_attributes => chef_client_attributes,
:amqp_password => Cucumber::Chef::Config.chef[:amqp_password],
:admin_password => Cucumber::Chef::Config.chef[:admin_password],
:user => Cucumber::Chef::Config.user,
:hostname_short => Cucumber::Chef.lab_hostname_short,
- :hostname_full => Cucumber::Chef.lab_hostname_full
+ :hostname_full => Cucumber::Chef.lab_hostname_full,
+ :chef_version => Cucumber::Chef::Config.chef[:version]
}
local_bootstrap_file = Tempfile.new("bootstrap")
local_bootstrap_filename = local_bootstrap_file.path
local_bootstrap_file.write(::ZTK::Template.render(@bootstrap_template, context))
@@ -106,11 +107,11 @@
end
################################################################################
def download_chef_credentials
- ZTK::Benchmark.bench(:message => "Downloading chef-server credentials", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ ZTK::Benchmark.bench(:message => "Downloading chef-server credentials", :mark => "completed in %0.4f seconds.", :ui => @ui) do
local_path = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s)
remote_path = File.join(Cucumber::Chef.lab_user_home_dir, ".chef")
files = [ "#{Cucumber::Chef::Config[:user]}.pem", "validation.pem" ]
files.each do |file|
@@ -120,11 +121,11 @@
end
################################################################################
def download_proxy_ssh_credentials
- ZTK::Benchmark.bench(:message => "Downloading proxy SSH credentials", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ ZTK::Benchmark.bench(:message => "Downloading proxy SSH credentials", :mark => "completed in %0.4f seconds.", :ui => @ui) do
local_path = File.join(Cucumber::Chef.home_dir, Cucumber::Chef::Config.provider.to_s)
remote_path = File.join(Cucumber::Chef.lab_user_home_dir, ".ssh")
files = { "id_rsa" => "id_rsa-#{@test_lab.bootstrap_ssh.config.user}" }
files.each do |remote_file, local_file|
@@ -137,11 +138,11 @@
end
################################################################################
def render_knife_rb
- ZTK::Benchmark.bench(:message => "Building 'cc-knife' configuration", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ ZTK::Benchmark.bench(:message => "Building 'cc-knife' configuration", :mark => "completed in %0.4f seconds.", :ui => @ui) do
template_file = File.join(Cucumber::Chef.root_dir, "lib", "cucumber", "chef", "templates", "cucumber-chef", "knife-rb.erb")
context = {
:chef_server => @test_lab.ip,
:librarian_chef => Cucumber::Chef::Config.librarian_chef,
@@ -155,68 +156,68 @@
end
################################################################################
def upload_cookbook
- Cucumber::Chef.logger.debug { "Uploading cucumber-chef cookbooks..." }
- ZTK::Benchmark.bench(:message => "Uploading 'cucumber-chef' cookbooks", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ @ui.logger.debug { "Uploading cucumber-chef cookbooks..." }
+ ZTK::Benchmark.bench(:message => "Uploading 'cucumber-chef' cookbooks", :mark => "completed in %0.4f seconds.", :ui => @ui) do
@test_lab.knife_cli(%Q{cookbook upload cucumber-chef -o #{@cookbooks_path}}, :silence => true)
end
end
################################################################################
def upload_role
- Cucumber::Chef.logger.debug { "Uploading cucumber-chef test lab role..." }
- ZTK::Benchmark.bench(:message => "Uploading 'cucumber-chef' roles", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ @ui.logger.debug { "Uploading cucumber-chef test lab role..." }
+ ZTK::Benchmark.bench(:message => "Uploading 'cucumber-chef' roles", :mark => "completed in %0.4f seconds.", :ui => @ui) do
@test_lab.knife_cli(%Q{role from file #{File.join(@roles_path, "test_lab.rb")}}, :silence => true)
end
end
################################################################################
def tag_node
- Cucumber::Chef.logger.debug { "Tagging cucumber-chef test lab node..." }
- ZTK::Benchmark.bench(:message => "Tagging 'cucumber-chef' node", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ @ui.logger.debug { "Tagging cucumber-chef test lab node..." }
+ ZTK::Benchmark.bench(:message => "Tagging 'cucumber-chef' node", :mark => "completed in %0.4f seconds.", :ui => @ui) do
@test_lab.knife_cli(%Q{tag create #{Cucumber::Chef.lab_hostname_full} #{Cucumber::Chef::Config.mode}}, :silence => true)
end
end
################################################################################
def add_node_role
- Cucumber::Chef.logger.debug { "Setting up cucumber-chef test lab run list..." }
- ZTK::Benchmark.bench(:message => "Setting 'cucumber-chef' run list", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ @ui.logger.debug { "Setting up cucumber-chef test lab run list..." }
+ ZTK::Benchmark.bench(:message => "Setting 'cucumber-chef' run list", :mark => "completed in %0.4f seconds.", :ui => @ui) do
@test_lab.knife_cli(%Q{node run_list add #{Cucumber::Chef.lab_hostname_full} "role[test_lab]"}, :silence => true)
end
end
################################################################################
def chef_first_run
- ZTK::Benchmark.bench(:message => "Performing chef-client run", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ ZTK::Benchmark.bench(:message => "Performing chef-client run", :mark => "completed in %0.4f seconds.", :ui => @ui) do
command = "/usr/bin/chef-client -j /etc/chef/first-boot.json -l debug"
command = "sudo #{command}"
@test_lab.bootstrap_ssh.exec(command, :silence => true)
end
end
################################################################################
def wait_for_chef_server
- ZTK::Benchmark.bench(:message => "Waiting for the chef-server", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ 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.", :stdout => @stdout) do
+ 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
end
################################################################################
def reboot_test_lab
- ZTK::Benchmark.bench(:message => "Rebooting the test lab", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ ZTK::Benchmark.bench(:message => "Rebooting the test lab", :mark => "completed in %0.4f seconds.", :ui => @ui) do
command = "sudo reboot"
@test_lab.bootstrap_ssh.exec(command, :silence => true)
ZTK::TCPSocketCheck.new(:host => @test_lab.ip, :port => @test_lab.port, :wait => 120).wait
end