Please review pull request #142: (#12565 & #12566) `--pre SCRIPT` and help usage opened by (justinstoller)

Description:

Prior to this you would only get the usage banner if you used -h or --help this makes the usage banner printed when no arguments are supplied as well. (Ticket #12565)

This commit adds the ability to pass a --pre PATH/TO/SCRIPT option. When passed the this flag will script that is given as an argument will be executed prior to any other setup tasks. This allows altering the state of the machine for one off tests or suites of edge cases that we do not want to code into the harness. (Ticket #12566)

Since these two tickets are relatively minor code changes, do not affect the DSL, and both primarily target lib/options_parsing.rb I combined them with approval.

  • Opened: Fri Feb 10 23:16:58 UTC 2012
  • Based on: puppetlabs:master (5c1e171912a62e8135a0de2319e22a412ddbcf8e)
  • Requested merge: justinstoller:pre_and_help (79d9d399dad3c7ef97d81090a287e01f92328a36)

Diff follows:

diff --git a/lib/options_parsing.rb b/lib/options_parsing.rb
index 3728db7..5007d3b 100644
--- a/lib/options_parsing.rb
+++ b/lib/options_parsing.rb
@@ -4,6 +4,8 @@ class Options
   def self.parse_args
     return @options if @options
 
+    @no_args = ARGV.empty? ? true : false
+
     @options = {}
     optparse = OptionParser.new do|opts|
       # Set a banner
@@ -171,8 +173,20 @@ def self.parse_args
         puts opts
         exit
       end
+
+      @options[:pre_script] = false
+      opts.on('--pre PATH/TO/SCRIPT', 'Pass steps to be run prior to setup') do |step|
+        @options[:pre_script] = step
+      end
     end
+
     optparse.parse!
+
+    # We have use the @no_args var because OptParse consumes ARGV as it parses
+    # so we have to check the value of ARGV at the begining of the method,
+    # let the options be set, then output usage.
+    puts optparse if @no_args
+
     raise ArgumentError.new("Must specify the --type argument") unless @options[:type]
 
     @options[:tests] << 'tests' if @options[:tests].empty?
diff --git a/systest.rb b/systest.rb
index 0b5bcba..11566e5 100755
--- a/systest.rb
+++ b/systest.rb
@@ -54,6 +54,14 @@
 # Generate hosts
 hosts = config['HOSTS'].collect { |name,overrides| Host.create(name,overrides,config['CONFIG']) }
 begin
+
+  # Run any pre-flight scripts
+  if options[:pre_script]
+    pre_opts = options.merge({ :random => false,
+                                  :tests => [ options[:pre_script] ] })
+    TestSuite.new('pre-setup', hosts, pre_opts, config, TRUE).run_and_exit_on_failure
+  end
+
   # Run the harness for install
   TestSuite.new('setup', hosts, setup_options, config, TRUE).run_and_exit_on_failure
 

    

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

Reply via email to