lib/beaker/dsl/helpers.rb in beaker-1.0.0 vs lib/beaker/dsl/helpers.rb in beaker-1.0.1.pre

- old
+ new

@@ -447,11 +447,15 @@ restore_puppet_conf_from_backup( host, backup_file ) if host.is_pe? bounce_service( host, 'pe-httpd' ) else - stop_puppet_from_source_on( host ) if puppet_master_started + if puppet_master_started + stop_puppet_from_source_on( host ) + else + dump_puppet_log(host) + end end rescue Exception => teardown_exception if original_exception logger.error("Raised during attempt to teardown with_puppet_running_on: #{teardown_exception}\n---\n") @@ -472,35 +476,55 @@ end # @!visibility private def restore_puppet_conf_from_backup( host, backup_file ) puppetpath = host['puppetpath'] + puppet_conf = File.join(puppetpath, "puppet.conf") - host.exec( Command.new( "if [ -f '#{backup_file}' ]; then " + - "cat '#{backup_file}' > " + - "'#{puppetpath}/puppet.conf'; " + - "rm -f '#{backup_file}'; " + - "fi" ) ) + if backup_file + host.exec( Command.new( "if [ -f '#{backup_file}' ]; then " + + "cat '#{backup_file}' > " + + "'#{puppet_conf}'; " + + "rm -f '#{backup_file}'; " + + "fi" ) ) + else + host.exec( Command.new( "rm -f '#{puppet_conf}'" )) + end + end + # Back up the given file in the current_dir to the new_dir + # # @!visibility private + # + # @param host [Beaker::Host] The target host + # @param current_dir [String] The directory containing the file to back up + # @param new_dir [String] The directory to copy the file to + # @param filename [String] The file to back up. Defaults to 'puppet.conf' + # + # @return [String, nil] The path to the file if the file exists, nil if it + # doesn't exist. def backup_the_file host, current_dir, new_dir, filename = 'puppet.conf' + old_location = current_dir + '/' + filename new_location = new_dir + '/' + filename + '.bak' - host.exec( Command.new( "cp #{old_location} #{new_location}" ) ) - - return new_location + if host.file_exist? old_location + host.exec( Command.new( "cp #{old_location} #{new_location}" ) ) + return new_location + else + logger.warn "Could not backup file '#{old_location}': no such file" + nil + end end # @!visibility private def start_puppet_from_source_on! host, args = '' host.exec( puppet( 'master', args ) ) logger.debug 'Waiting for the puppet master to start' unless port_open_within?( host, 8140, 10 ) - dump_puppet_log(host) raise Beaker::DSL::FailTest, 'Puppet master did not start in a timely fashion' end logger.debug 'The puppet master has started' return true end @@ -513,13 +537,10 @@ while host.exec( Command.new( "kill -0 #{pid}"), :acceptable_exit_codes => [0,1] ).exit_code == 0 do # until kill -0 finds no process and we know that puppet has finished cleaning up sleep 1 end end - rescue RuntimeError => e - dump_puppet_log host - raise e end # @!visibility private def dump_puppet_log(host) syslogfile = case host['platform'] @@ -830,9 +851,28 @@ #prompt the master to sign certs then check to confirm the cert for the default host is signed #@see #sign_certificate_for def sign_certificate sign_certificate_for(default) + end + + # Get a facter fact from a provided host + # + # @param [Host] host The host to query the fact for + # @param [String] name The name of the fact to query for + # @!macro common_opts + # + # @returns String The value of the fact 'name' on the provided host + # @raise [FailTest] Raises an exception if call to facter fails + def fact_on(host, name, opts = {}) + result = on host, facter(name, opts) + result.stdout.chomp if result.stdout + end + + # Get a facter fact from the default host + # @see #fact_on + def fact(name, opts = {}) + fact_on(default, name, opts) end end end end