lib/cucumber/chef/helpers/chef_client.rb in cucumber-chef-2.1.0.rc.2 vs lib/cucumber/chef/helpers/chef_client.rb in cucumber-chef-2.1.0.rc.3
- old
+ new
@@ -31,40 +31,46 @@
:chef_server_url => "https://api.opscode.com/organizations/#{config[:orgname]}",
:validation_client_name => "#{config[:orgname]}-validator",
:ssl_verify_mode => :verify_none,
:environment => nil # use default; i.e. set no value
}).merge(config)
- log("setting chef client config $#{@chef_client_config.inspect}$")
+ logger.info { "Setting chef client config '#{@chef_client_config.inspect}'." }
true
end
################################################################################
# call this before chef_run_client
def chef_set_client_attributes(name, attributes={})
- @servers[name] ||= Hash.new
- @servers[name][:chef_client] = (@servers[name][:chef_client] || {}).merge(attributes) { |k,o,n| (k = (o + n).uniq) }
- log("setting chef client attributes to $#{@servers[name][:chef_client].inspect}$ for container $#{name}$")
+ @containers[name] ||= Hash.new
+ @containers[name][:chef_client] = (@containers[name][:chef_client] || {}).merge(attributes) { |k,o,n| (k = (o + n).uniq) }
+ logger.info { "Setting chef client attributes to '#{@containers[name][:chef_client].inspect}' for container '#{name}'." }
true
end
################################################################################
- def chef_run_client(name,*args)
+ def chef_run_client(name, *args)
chef_config_client(name)
- log("removing artifacts #{Cucumber::Chef::Config[:artifacts].values.collect{|z| "$#{z}$" }.join(' ')}")
- (command_run_remote(name, "/bin/rm -fv #{Cucumber::Chef::Config[:artifacts].values.join(' ')}") rescue nil)
- log("running chef client on container $#{name}$")
+ logger.info { "Removing artifacts #{Cucumber::Chef::Config[:artifacts].values.collect{|z| "'#{z}'" }.join(' ')}." }
+ (command_run_chroot(name, "/bin/rm -fv #{Cucumber::Chef::Config[:artifacts].values.join(' ')}") rescue nil)
+ logger.info { "Running chef client on container '#{name}'." }
+
+ arguments = {
+ "--json-attributes" => File.join("/etc", "chef", "attributes.json").to_s,
+ "--log_level" => (ENV['LOG_LEVEL'] || "INFO").downcase
+ }.reject{ |k,v| v.nil? }.sort
+
output = nil
bm = ::Benchmark.realtime do
- output = command_run_remote(name, ["/usr/bin/chef-client --json-attributes /etc/chef/attributes.json --node-name #{name}", args].flatten.join(" "))
+ output = command_run_chroot(name, ["/usr/bin/chef-client", arguments, args].flatten.join(" "))
end
- log("chef client run on container $#{name}$ took %0.4f seconds" % bm)
+ logger.info { "Chef client run on container '#{name}' took %0.4f seconds." % bm }
output
end
################################################################################
@@ -88,11 +94,11 @@
end
attributes_json = File.join("/", container_root(name), "etc", "chef", "attributes.json")
FileUtils.mkdir_p(File.dirname(attributes_json))
File.open(attributes_json, 'w') do |f|
- f.puts((@servers[name][:chef_client] || {}).to_json)
+ f.puts((@containers[name][:chef_client] || {}).to_json)
end
# make sure our log location is there
log_location = File.join("/", container_root(name), @chef_client_config[:log_location])
FileUtils.mkdir_p(File.dirname(log_location))
@@ -106,33 +112,24 @@
def chef_client_artifacts(name)
# this is messy and needs to be refactored into a more configurable
# solution; but for now this should do the trick
- ssh = ZTK::SSH.new
+ ssh = $test_lab.proxy_ssh(name)
- ssh.config.proxy_host_name = $test_lab.ip
- ssh.config.proxy_port = $test_lab.port
- ssh.config.proxy_user = Cucumber::Chef.lab_user
- ssh.config.proxy_keys = Cucumber::Chef.lab_identity
-
- ssh.config.host_name = name
- ssh.config.user = Cucumber::Chef.lxc_user
- ssh.config.keys = Cucumber::Chef.lxc_identity
-
feature_file = $scenario.file_colon_line.split(":").first
feature_line = $scenario.file_colon_line.split(":").last
scenario_tag = $scenario.name.gsub(" ", "_")
feature_name = File.basename(feature_file, ".feature")
feature_dir = feature_file.split("/")[-2]
Cucumber::Chef::Config[:artifacts].each do |label, remote_path|
result = ssh.exec("/bin/bash -c '[[ -f #{remote_path} ]] ; echo $?'", :silence => true)
if (result.output =~ /0/)
- log("retrieving artifact $#{remote_path}$ from container $#{name}$")
+ logger.info { "Retrieving artifact '#{remote_path}' from container '#{name}'." }
- local_path = File.join(Cucumber::Chef.locate(:directory, ".cucumber-chef"), "artifacts", feature_dir, "#{feature_name}.txt")
+ local_path = File.join(Cucumber::Chef.artifacts_dir, feature_dir, "#{feature_name}.txt")
tmp_path = File.join("/tmp", label)
FileUtils.mkdir_p(File.dirname(local_path))
ssh.download(remote_path, tmp_path)
data = IO.read(tmp_path).chomp