Please review pull request #138: tweaked default parameters for with_master_running_on opened by (cprice-puppet)

Description:

This pull request is a re-submission of my earlier one after discussing with Justin and removing
all of the controversial bits. It includes the following:

  • New defaults for with_master_running_on:
    • will automatically add "--daemonize" if you haven't specified either that or --no-daemonize
    • will automatically add "--logdest=/log/puppetmaster.log" if you don't specify a logdest; sending acceptance framework log messages to syslog didn't seem very useful
    • will automatically add "--dns_alt_names" if you don't specify it
    • will automatically add "--autosign" if you don't specify it
    • no longer deletes log dir between executions of master
  • Log a readable version of the backtrace if a test calls "flunk"

  • Opened: Thu Feb 09 23:14:36 UTC 2012
  • Based on: puppetlabs:master (726475cc7db081611c240173aed43dafd4b43200)
  • Requested merge: cprice-puppet:default-args-for-with-master (ba57ee5c9088fdaa0708b2d2baefd27650e0c159)

Diff follows:

diff --git a/lib/log.rb b/lib/log.rb
index 75fe62d..a2a2e8c 100644
--- a/lib/log.rb
+++ b/lib/log.rb
@@ -78,5 +78,42 @@ def error(*args)
         print NORMAL if color
       end
     end
+
+
+
+    # utility method to get the current call stack and format it to a human-readable string (which some IDEs/editors
+    # will recognize as links to the line numbers in the trace)
+    def pretty_backtrace()
+
+      caller(1).collect do |line|
+        file_path, line_num = line.split(":")
+        file_path = expand_symlinks(File.expand_path(file_path))
+
+        file_path + ":" + line_num
+      end .join("\n")
+
+    end
+
+    # utility method that takes a path as input, checks each component of the path to see if it is a symlink, and expands
+    # it if it is.  returns the expanded path.
+    def expand_symlinks(file_path)
+      file_path.split("/").inject do |full_path, next_dir|
+        next_path = full_path + "/" + next_dir
+        if File.symlink?(next_path) then
+          link = File.readlink(next_path)
+          next_path =
+              case link
+                when /^\// then link
+                else
+                  File.expand_path(full_path + "/" + link)
+              end
+        end
+        next_path
+      end
+    end
+    private :expand_symlinks
+
+
+
   end
 end
diff --git a/lib/test_case.rb b/lib/test_case.rb
index 16d289b..2007015 100644
--- a/lib/test_case.rb
+++ b/lib/test_case.rb
@@ -123,7 +123,7 @@ def skip_test(msg)
     @test_status = :skip
   end
   def fail_test(msg)
-    assert(false, msg)
+    flunk(msg + "\n" + Log.pretty_backtrace() + "\n")
   end
   #
   # result access
@@ -257,11 +257,37 @@ def run_cron_on(host, action, user, entry="", &block)
     end
   end
 
+  # This method performs the following steps:
+  # 1. issues start command for puppet master on specified host
+  # 2. polls until it determines that the master has started successfully
+  # 3. yields to a block of code passed by the caller
+  # 4. runs a "kill" command on the master's pid (on the specified host)
+  # 5. polls until it determines that the master has shut down successfully.
+  #
+  # Parameters:
+  # [host] the master host
+  # [arg] a string containing all of the command line arguments that you would like for the puppet master to
+  #     be started with.  Defaults to '--daemonize'.  NOTE: the following values will be added to the argument list
+  #     if they are not explicitly set in your 'args' parameter:
+  # * --daemonize
+  # * --logdest="#{host['puppetvardir']}/log/puppetmaster.log"
+  # * --dns_alt_names="puppet, $(hostname -s), $(hostname -f)"
+  # * --autosign=true
   def with_master_running_on(host, arg='--daemonize', &block)
+    # they probably want to run with daemonize.  If they pass some other arg/args but forget to re-include
+    # daemonize, we'll check and make sure they didn't explicitly specify "no-daemonize", and, failing that,
+    # we'll add daemonize to the arg string
+    if (arg !~ /(?:--daemonize)|(?:--no-daemonize)/) then arg << " --daemonize" end
+
+    if (arg !~ /--logdest/) then arg << " --logdest=\"#{master['puppetvardir']}/log/puppetmaster.log\"" end
+    if (arg !~ /--dns_alt_names/) then arg << " --dns_alt_names=\"puppet, $(hostname -s), $(hostname -f)\"" end
+    if (arg !~ /--autosign/) then arg << " --autosign=true" end
+
     on hosts, host_command('rm -rf #{host["puppetpath"]}/ssl')
     agents.each do |agent|
-      if vardir = agent['puppetvardir']
-        on agent, "rm -rf #{vardir}/*"
+      if ((vardir = agent['puppetvardir']) && File.exists?(vardir))
+        # we want to remove everything except the log directory
+        on agent, "for f in #{vardir}/*; do if [ \"$f\" != \"#{vardir}/log\" ]; then rm -r \"$f\"; fi; done"
       end
     end
 
@@ -331,4 +357,5 @@ def with_standard_output_to_logs
 
     return result
   end
+
 end

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to