diff options
Diffstat (limited to 'acceptance')
-rw-r--r-- | acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb b/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb index c8bcd4ab77..b6dab451c7 100644 --- a/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb +++ b/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb @@ -1,3 +1,5 @@ +require 'chef/mixin/shell_out' + module KitchenAcceptance class Kitchen < Chef::Resource resource_name :kitchen @@ -33,25 +35,30 @@ module KitchenAcceptance property :kitchen_options, String, default: lazy { ENV["PROJECT_NAME"] ? "-c -l debug" : "-c" } action :run do - execute "bundle exec kitchen #{command}#{instances ? " #{instances}" : ""}#{kitchen_options ? " #{kitchen_options}" : ""}" do - cwd kitchen_dir - env({ - "KITCHEN_DRIVER" => driver, - "KITCHEN_INSTANCES" => instances, - "KITCHEN_LOCAL_YAML" => ::File.expand_path("../../.kitchen.#{driver}.yml", __FILE__), - "KITCHEN_CHEF_PRODUCT" => chef_product, - "KITCHEN_CHEF_CHANNEL" => chef_channel, - "KITCHEN_CHEF_VERSION" => chef_version, - "ARTIFACTORY_USERNAME" => artifactory_username, - "ARTIFACTORY_PASSWORD" => artifactory_password - }.merge(new_resource.env)) - end + ruby_block "copy_kitchen_logs_to_data_path" do block do + cmd_env = { + "KITCHEN_DRIVER" => driver, + "KITCHEN_INSTANCES" => instances, + "KITCHEN_LOCAL_YAML" => ::File.expand_path("../../.kitchen.#{driver}.yml", __FILE__), + "KITCHEN_CHEF_PRODUCT" => chef_product, + "KITCHEN_CHEF_CHANNEL" => chef_channel, + "KITCHEN_CHEF_VERSION" => chef_version, + "ARTIFACTORY_USERNAME" => artifactory_username, + "ARTIFACTORY_PASSWORD" => artifactory_password + }.merge(new_resource.env) suite = kitchen_dir.split("/").last - kitchen_log_path = ENV["WORKSPACE"] ? "#{ENV["WORKSPACE"]}/chef-acceptance-data/logs" : "#{kitchen_dir}/../.acceptance_data/logs/kitchen" - FileUtils.mkdir_p("#{kitchen_log_path}/#{suite}") - FileUtils.cp_r("#{kitchen_dir}/.kitchen/logs/", "#{kitchen_log_path}/#{suite}") + kitchen_log_path = ENV["WORKSPACE"] ? "#{ENV["WORKSPACE"]}/chef-acceptance-data/logs" : "#{kitchen_dir}/../.acceptance_data/logs/" + + begin + shell_out!("bundle exec kitchen #{command}#{instances ? " #{instances}" : ""}#{kitchen_options ? " #{kitchen_options}" : ""}", + env: cmd_env, + cwd: kitchen_dir) + ensure + FileUtils.mkdir_p("#{kitchen_log_path}/#{suite}/#{command}") + FileUtils.cp_r("#{kitchen_dir}/.kitchen/logs/.", "#{kitchen_log_path}/#{suite}/#{command}") + end end end end |