lib/cucumber/chef/helpers/command.rb in cucumber-chef-2.1.0.rc.2 vs lib/cucumber/chef/helpers/command.rb in cucumber-chef-2.1.0.rc.3

- old
+ new

@@ -21,50 +21,37 @@ module Cucumber::Chef::Helpers::Command ################################################################################ - def command_run_remote(name, command, expected_exit_code=0) - command = %Q(ssh -i #{File.join(Cucumber::Chef.lab_user_home_dir, ".ssh", "id_rsa")} #{name} #{command} 2>&1) - logger.info { "command_run_remote(#{command})" } - output = %x(#{command}) - if !expected_exit_code.nil? && ($? != expected_exit_code) - message = "command_run_remote(#{command}) failed (code=#{$?},output='#{output.chomp}')" - logger.fatal { message } - logger.fatal { "output(#{output.chomp})" } - raise message - end - output + def command_run_remote(name, command, options={}) + expected_exit_code = (options[:expected_exit_code] || 0) + options.reject!{ |k,v| k == :expected_exit_code } + + identity_file = File.join(Cucumber::Chef.lab_user_home_dir, ".ssh", "id_rsa") + + command = %W(/usr/bin/ssh #{ENV['LOG_LEVEL'] == 'DEBUG' ? "-v" : nil} -i #{identity_file} #{name} #{command}) + ::ZTK::Command.new({:timeout => Cucumber::Chef::Config.command_timeout}.merge(options)).exec(command.compact.join(" "), :silence => true, :exit_code => expected_exit_code) end ################################################################################ - def command_run_chroot(name, command, expected_exit_code=0) - command = %Q(chroot #{container_root(name)} /bin/bash -c '#{command.gsub("'", '"')}' 2>&1) - logger.info { "command_run_chroot(#{command})" } - output = %x(#{command}) - if !expected_exit_code.nil? && ($? != expected_exit_code) - message = "command_run_chroot(#{command}) failed (#{$?})" - logger.fatal { message } - logger.fatal { "output(#{output.chomp})" } - raise message - end - output + def command_run_chroot(name, command, options={}) + expected_exit_code = (options[:expected_exit_code] || 0) + options.reject!{ |k,v| k == :expected_exit_code } + + command = %Q(/usr/sbin/chroot #{container_root(name)} /bin/bash -c '#{command.gsub("'", '"')}') + ::ZTK::Command.new({:timeout => Cucumber::Chef::Config.command_timeout}.merge(options)).exec(command, :silence => true, :exit_code => expected_exit_code) end ################################################################################ - def command_run_local(command, expected_exit_code=0) - command = %Q(/bin/bash -c '#{command.gsub("'", '"')}' 2>&1) - logger.info { "command_run_local(#{command})" } - output = %x(#{command}) - if !expected_exit_code.nil? && ($? != expected_exit_code) - message = "command_run_local(#{command}) failed (#{$?})" - logger.fatal { message } - logger.fatal { "output(#{output.chomp})" } - raise message - end - output + def command_run_local(command, options={}) + expected_exit_code = (options[:expected_exit_code] || 0) + options.reject!{ |k,v| k == :expected_exit_code } + + command = %Q(/bin/bash -c '#{command.gsub("'", '"')}') + ::ZTK::Command.new({:timeout => Cucumber::Chef::Config.command_timeout}.merge(options)).exec(command, :silence => true, :exit_code => expected_exit_code) end ################################################################################ end