[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:33:47 UTC 2010


The following commit has been merged in the upstream branch:
commit 8f4d644210e7a6afc9e08d65a0c60987171747c6
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Wed May 12 15:19:33 2010 -0700

    Feature #2935: lazify require graph for applications
    
    Because environments have to declare their mode before puppet tries to
    load defaults.rb, it reduces the complexity considerably to have
    application classes to load their lib dependencies at the last possible
    moment.
    
    Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>

diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index ca01572..97d2c95 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -1,4 +1,3 @@
-require 'puppet'
 require 'optparse'
 
 # This class handles all the aspects of a Puppet application/executable
@@ -114,7 +113,9 @@ require 'optparse'
 #          process_member(member)
 #      end
 #  end
-class Puppet::Application
+module Puppet
+class Application
+    require 'puppet/util'
     include Puppet::Util
 
     BINDIRS = %w{sbin bin}.map{|dir| File.expand_path(File.dirname(__FILE__)) + "/../../#{dir}/*"}.join(" ")
@@ -263,6 +264,7 @@ class Puppet::Application
     end
 
     def initialize(command_line = nil)
+        require 'puppet/util/command_line'
         @command_line = command_line || Puppet::Util::CommandLine.new
         @mode = self.class.mode
         @options = {}
@@ -384,3 +386,4 @@ class Puppet::Application
         end
     end
 end
+end
diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index 093e5b9..8a8e3ca 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -1,9 +1,4 @@
-require 'puppet'
 require 'puppet/application'
-require 'puppet/agent'
-require 'puppet/daemon'
-require 'puppet/configurer'
-require 'puppet/network/client'
 
 class Puppet::Application::Agent < Puppet::Application
 
@@ -39,6 +34,7 @@ class Puppet::Application::Agent < Puppet::Application
 
         @explicit_waitforcert = false
         @args = {}
+        require 'puppet/daemon'
         @daemon = Puppet::Daemon.new
         @daemon.argv = ARGV.dup
     end
@@ -255,6 +251,8 @@ class Puppet::Application::Agent < Puppet::Application
 
         # We need tomake the client either way, we just don't start it
         # if --no-client is set.
+        require 'puppet/agent'
+        require 'puppet/configurer'
         @agent = Puppet::Agent.new(Puppet::Configurer)
 
         enable_disable_client(@agent) if options[:enable] or options[:disable]
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index fde0c9b..b6ce5aa 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -1,8 +1,4 @@
-require 'puppet'
 require 'puppet/application'
-require 'puppet/configurer'
-require 'puppet/network/handler'
-require 'puppet/network/client'
 
 class Puppet::Application::Apply < Puppet::Application
 
@@ -41,8 +37,6 @@ class Puppet::Application::Apply < Puppet::Application
     end
 
     def apply
-        require 'puppet/configurer'
-
         if options[:catalog] == "-"
             text = $stdin.read
         else
@@ -60,6 +54,7 @@ class Puppet::Application::Apply < Puppet::Application
 
         catalog = catalog.to_ral
 
+        require 'puppet/configurer'
         configurer = Puppet::Configurer.new
         configurer.run :catalog => catalog
     end
@@ -127,6 +122,7 @@ class Puppet::Application::Apply < Puppet::Application
 
             catalog.retrieval_duration = Time.now - starttime
 
+            require 'puppet/configurer'
             configurer = Puppet::Configurer.new
             configurer.execute_prerun_command
 
diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb
index 80ccc46..33410ee 100644
--- a/lib/puppet/application/cert.rb
+++ b/lib/puppet/application/cert.rb
@@ -1,6 +1,4 @@
-require 'puppet'
 require 'puppet/application'
-require 'puppet/ssl/certificate_authority'
 
 class Puppet::Application::Cert < Puppet::Application
 
@@ -9,6 +7,7 @@ class Puppet::Application::Cert < Puppet::Application
     attr_accessor :mode, :all, :ca, :digest, :signed
 
     def find_mode(opt)
+        require 'puppet/ssl/certificate_authority'
         modes = Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS
         tmp = opt.sub("--", '').to_sym
         @mode = modes.include?(tmp) ? tmp : nil
@@ -34,6 +33,7 @@ class Puppet::Application::Cert < Puppet::Application
         Puppet::Util::Log.level = :debug
     end
 
+    require 'puppet/ssl/certificate_authority/interface'
     Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject {|m| m == :destroy }.each do |method|
         option("--#{method}", "-%s" % method.to_s[0,1] ) do
             find_mode("--#{method}")
diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb
index 74cde98..326265e 100644
--- a/lib/puppet/application/doc.rb
+++ b/lib/puppet/application/doc.rb
@@ -1,11 +1,4 @@
-require 'puppet'
 require 'puppet/application'
-require 'puppet/util/reference'
-require 'puppet/network/handler'
-require 'puppet/util/rdoc'
-
-$tab = "    "
-Reference = Puppet::Util::Reference
 
 class Puppet::Application::Doc < Puppet::Application
 
@@ -28,7 +21,8 @@ class Puppet::Application::Doc < Puppet::Application
 
     option("--format FORMAT", "-f") do |arg|
         method = "to_%s" % arg
-        if Reference.method_defined?(method)
+        require 'puppet/util/reference'
+        if Puppet::Util::Reference.method_defined?(method)
             options[:format] = method
         else
             raise "Invalid output format %s" % arg
@@ -36,7 +30,8 @@ class Puppet::Application::Doc < Puppet::Application
     end
 
     option("--mode MODE", "-m") do |arg|
-        if Reference.modes.include?(arg) or arg.intern==:rdoc
+        require 'puppet/util/reference'
+        if Puppet::Util::Reference.modes.include?(arg) or arg.intern==:rdoc
             options[:mode] = arg.intern
         else
             raise "Invalid output mode %s" % arg
@@ -44,7 +39,8 @@ class Puppet::Application::Doc < Puppet::Application
     end
 
     option("--list", "-l") do |arg|
-        puts Reference.references.collect { |r| Reference.reference(r).doc }.join("\n")
+        require 'puppet/util/reference'
+        puts Puppet::Util::Reference.references.collect { |r| Puppet::Util::Reference.reference(r).doc }.join("\n")
         exit(0)
     end
 
@@ -77,6 +73,7 @@ class Puppet::Application::Doc < Puppet::Application
         )
         Puppet.settings[:document_all] = options[:all] || false
         begin
+            require 'puppet/util/rdoc'
             if @manifest
                 Puppet::Util::RDoc.manifestdoc(files)
             else
@@ -94,6 +91,7 @@ class Puppet::Application::Doc < Puppet::Application
     end
 
     def trac
+        require 'puppet/util/reference'
         options[:references].each do |name|
             section = Puppet::Util::Reference.reference(name) or raise "Could not find section %s" % name
             unless options[:mode] == :pdf
@@ -106,6 +104,7 @@ class Puppet::Application::Doc < Puppet::Application
         text = ""
         with_contents = false
         exit_code = 0
+        require 'puppet/util/reference'
         options[:references].sort { |a,b| a.to_s <=> b.to_s }.each do |name|
             raise "Could not find reference %s" % name unless section = Puppet::Util::Reference.reference(name)
 
@@ -135,6 +134,7 @@ class Puppet::Application::Doc < Puppet::Application
             with_contents = true
         end
         exit_code = 0
+        require 'puppet/util/reference'
         options[:references].sort { |a,b| a.to_s <=> b.to_s }.each do |name|
             raise "Could not find reference %s" % name unless section = Puppet::Util::Reference.reference(name)
 
@@ -182,8 +182,9 @@ class Puppet::Application::Doc < Puppet::Application
     def setup_reference
         if options[:all]
             # Don't add dynamic references to the "all" list.
-            options[:references] = Reference.references.reject do |ref|
-                Reference.reference(ref).dynamic?
+            require 'puppet/util/reference'
+            options[:references] = Puppet::Util::Reference.references.reject do |ref|
+                Puppet::Util::Reference.reference(ref).dynamic?
             end
         end
 
diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb
index 8e930f5..8f9e917 100644
--- a/lib/puppet/application/filebucket.rb
+++ b/lib/puppet/application/filebucket.rb
@@ -1,6 +1,4 @@
-require 'puppet'
 require 'puppet/application'
-require 'puppet/file_bucket/dipper'
 
 class Puppet::Application::Filebucket < Puppet::Application
 
@@ -72,6 +70,7 @@ class Puppet::Application::Filebucket < Puppet::Application
                 exit(Puppet.settings.print_configs ? 0 : 1)
         end
 
+        require 'puppet/file_bucket/dipper'
         begin
             if options[:local] or options[:bucket]
                 path = options[:bucket] || Puppet[:bucketdir]
diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb
index 37d3e53..0dd4d39 100644
--- a/lib/puppet/application/kick.rb
+++ b/lib/puppet/application/kick.rb
@@ -1,9 +1,5 @@
-require 'puppet'
 require 'puppet/application'
 
-Puppet.warning "RubyGems not installed" unless Puppet.features.rubygems?
-Puppet.warning "Failed to load ruby LDAP library. LDAP functionality will not be available" unless Puppet.features.ldap?
-
 class Puppet::Application::Kick < Puppet::Application
 
     should_not_parse_config
@@ -52,6 +48,8 @@ class Puppet::Application::Kick < Puppet::Application
 
     def main
         require 'puppet/network/client'
+
+        Puppet.warning "Failed to load ruby LDAP library. LDAP functionality will not be available" unless Puppet.features.ldap?
         require 'puppet/util/ldap/connection'
 
         todo = @hosts.dup
diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb
index 44c8c02..993d7df 100644
--- a/lib/puppet/application/master.rb
+++ b/lib/puppet/application/master.rb
@@ -1,8 +1,4 @@
-require 'puppet'
 require 'puppet/application'
-require 'puppet/daemon'
-require 'puppet/network/server'
-require 'puppet/network/http/rack' if Puppet.features.rack?
 
 class Puppet::Application::Master < Puppet::Application
 
@@ -37,6 +33,7 @@ class Puppet::Application::Master < Puppet::Application
         end
 
         # Create this first-off, so we have ARGV
+        require 'puppet/daemon'
         @daemon = Puppet::Daemon.new
         @daemon.argv = ARGV.dup
     end
@@ -108,6 +105,7 @@ class Puppet::Application::Master < Puppet::Application
         end
 
         unless options[:rack]
+            require 'puppet/network/server'
             @daemon.server = Puppet::Network::Server.new(:xmlrpc_handlers => xmlrpc_handlers)
             @daemon.daemonize if Puppet[:daemonize]
         else
diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb
index 4b3aa57..ce53235 100644
--- a/lib/puppet/application/queue.rb
+++ b/lib/puppet/application/queue.rb
@@ -1,8 +1,4 @@
-require 'puppet'
-require 'puppet/daemon'
 require 'puppet/application'
-require 'puppet/resource/catalog'
-require 'puppet/indirector/catalog/queue'
 require 'puppet/util'
 
 class Puppet::Application::Queue < Puppet::Application
@@ -11,6 +7,7 @@ class Puppet::Application::Queue < Puppet::Application
     attr_accessor :daemon
 
     def preinit
+        require 'puppet/daemon'
         @daemon = Puppet::Daemon.new
         @daemon.argv = ARGV.dup
         Puppet::Util::Log.newdestination(:console)
@@ -82,6 +79,7 @@ class Puppet::Application::Queue < Puppet::Application
             exit(Puppet.settings.print_configs ? 0 : 1)
         end
 
+        require 'puppet/resource/catalog'
         Puppet::Resource::Catalog.terminus_class = :active_record
 
         daemon.daemonize if Puppet[:daemonize]
diff --git a/lib/puppet/ssl/certificate_authority/interface.rb b/lib/puppet/ssl/certificate_authority/interface.rb
index b60834a..ffae66d 100644
--- a/lib/puppet/ssl/certificate_authority/interface.rb
+++ b/lib/puppet/ssl/certificate_authority/interface.rb
@@ -1,132 +1,138 @@
 # This class is basically a hidden class that knows how to act
 # on the CA.  It's only used by the 'puppetca' executable, and its
 # job is to provide a CLI-like interface to the CA class.
-class Puppet::SSL::CertificateAuthority::Interface
-    INTERFACE_METHODS = [:destroy, :list, :revoke, :generate, :sign, :print, :verify, :fingerprint]
-
-    class InterfaceError < ArgumentError; end
-
-    attr_reader :method, :subjects, :digest
-
-    # Actually perform the work.
-    def apply(ca)
-        unless subjects or method == :list
-            raise ArgumentError, "You must provide hosts or :all when using %s" % method
-        end
-
-        begin
-            if respond_to?(method)
-                return send(method, ca)
-            end
-
-            (subjects == :all ? ca.list : subjects).each do |host|
-                ca.send(method, host)
-            end
-        rescue InterfaceError
-            raise
-        rescue => detail
-            puts detail.backtrace if Puppet[:trace]
-            Puppet.err "Could not call %s: %s" % [method, detail]
-        end
-    end
-
-    def generate(ca)
-        raise InterfaceError, "It makes no sense to generate all hosts; you must specify a list" if subjects == :all
-
-        subjects.each do |host|
-            ca.generate(host)
-        end
-    end
-
-    def initialize(method, options)
-        self.method = method
-        self.subjects = options[:to]
-        @digest = options[:digest] || :MD5
-    end
-
-    # List the hosts.
-    def list(ca)
-        unless subjects
-            puts ca.waiting?.join("\n")
-            return nil
-        end
-
-        signed = ca.list
-        requests = ca.waiting?
-
-        if subjects == :all
-            hosts = [signed, requests].flatten
-        elsif subjects == :signed
-            hosts = signed.flatten
-        else
-            hosts = subjects
-        end
-
-        hosts.uniq.sort.each do |host|
-            invalid = false
-            begin
-                ca.verify(host) unless requests.include?(host)
-            rescue Puppet::SSL::CertificateAuthority::CertificateVerificationError => details
-                invalid = details.to_s
-            end
-            if not invalid and signed.include?(host)
-                puts "+ #{host} (#{ca.fingerprint(host, @digest)})"
-            elsif invalid
-                puts "- #{host} (#{ca.fingerprint(host, @digest)}) (#{invalid})"
-            else
-                puts "#{host} (#{ca.fingerprint(host, @digest)})"
+module Puppet
+    module SSL
+        class CertificateAuthority
+            class Interface
+                INTERFACE_METHODS = [:destroy, :list, :revoke, :generate, :sign, :print, :verify, :fingerprint]
+
+                class InterfaceError < ArgumentError; end
+
+                attr_reader :method, :subjects, :digest
+
+                # Actually perform the work.
+                def apply(ca)
+                    unless subjects or method == :list
+                        raise ArgumentError, "You must provide hosts or :all when using %s" % method
+                    end
+
+                    begin
+                        if respond_to?(method)
+                            return send(method, ca)
+                        end
+
+                        (subjects == :all ? ca.list : subjects).each do |host|
+                            ca.send(method, host)
+                        end
+                    rescue InterfaceError
+                        raise
+                    rescue => detail
+                        puts detail.backtrace if Puppet[:trace]
+                        Puppet.err "Could not call %s: %s" % [method, detail]
+                    end
+                end
+
+                def generate(ca)
+                    raise InterfaceError, "It makes no sense to generate all hosts; you must specify a list" if subjects == :all
+
+                    subjects.each do |host|
+                        ca.generate(host)
+                    end
+                end
+
+                def initialize(method, options)
+                    self.method = method
+                    self.subjects = options[:to]
+                    @digest = options[:digest] || :MD5
+                end
+
+                # List the hosts.
+                def list(ca)
+                    unless subjects
+                        puts ca.waiting?.join("\n")
+                        return nil
+                    end
+
+                    signed = ca.list
+                    requests = ca.waiting?
+
+                    if subjects == :all
+                        hosts = [signed, requests].flatten
+                    elsif subjects == :signed
+                        hosts = signed.flatten
+                    else
+                        hosts = subjects
+                    end
+
+                    hosts.uniq.sort.each do |host|
+                        invalid = false
+                        begin
+                            ca.verify(host) unless requests.include?(host)
+                        rescue Puppet::SSL::CertificateAuthority::CertificateVerificationError => details
+                            invalid = details.to_s
+                        end
+                        if not invalid and signed.include?(host)
+                            puts "+ #{host} (#{ca.fingerprint(host, @digest)})"
+                        elsif invalid
+                            puts "- #{host} (#{ca.fingerprint(host, @digest)}) (#{invalid})"
+                        else
+                            puts "#{host} (#{ca.fingerprint(host, @digest)})"
+                        end
+                    end
+                end
+
+                # Set the method to apply.
+                def method=(method)
+                    raise ArgumentError, "Invalid method %s to apply" % method unless INTERFACE_METHODS.include?(method)
+                    @method = method
+                end
+
+                # Print certificate information.
+                def print(ca)
+                    (subjects == :all ? ca.list  : subjects).each do |host|
+                        if value = ca.print(host)
+                            puts value
+                        else
+                            Puppet.err "Could not find certificate for %s" % host
+                        end
+                    end
+                end
+
+                # Print certificate information.
+                def fingerprint(ca)
+                    (subjects == :all ? ca.list + ca.waiting?: subjects).each do |host|
+                        if value = ca.fingerprint(host, @digest)
+                            puts "#{host} #{value}"
+                        else
+                            Puppet.err "Could not find certificate for %s" % host
+                        end
+                    end
+                end
+
+                # Sign a given certificate.
+                def sign(ca)
+                    list = subjects == :all ? ca.waiting? : subjects
+                    raise InterfaceError, "No waiting certificate requests to sign" if list.empty?
+                    list.each do |host|
+                        ca.sign(host)
+                    end
+                end
+
+                # Set the list of hosts we're operating on.  Also supports keywords.
+                def subjects=(value)
+                    unless value == :all or value == :signed or value.is_a?(Array)
+                        raise ArgumentError, "Subjects must be an array or :all; not %s" % value
+                    end
+
+                    if value.is_a?(Array) and value.empty?
+                        value = nil
+                    end
+
+                    @subjects = value
+                end
             end
         end
     end
-
-    # Set the method to apply.
-    def method=(method)
-        raise ArgumentError, "Invalid method %s to apply" % method unless INTERFACE_METHODS.include?(method)
-        @method = method
-    end
-
-    # Print certificate information.
-    def print(ca)
-        (subjects == :all ? ca.list  : subjects).each do |host|
-            if value = ca.print(host)
-                puts value
-            else
-                Puppet.err "Could not find certificate for %s" % host
-            end
-        end
-    end
-
-    # Print certificate information.
-    def fingerprint(ca)
-        (subjects == :all ? ca.list + ca.waiting?: subjects).each do |host|
-            if value = ca.fingerprint(host, @digest)
-                puts "#{host} #{value}"
-            else
-                Puppet.err "Could not find certificate for %s" % host
-            end
-        end
-    end
-
-    # Sign a given certificate.
-    def sign(ca)
-        list = subjects == :all ? ca.waiting? : subjects
-        raise InterfaceError, "No waiting certificate requests to sign" if list.empty?
-        list.each do |host|
-            ca.sign(host)
-        end
-    end
-
-    # Set the list of hosts we're operating on.  Also supports keywords.
-    def subjects=(value)
-        unless value == :all or value == :signed or value.is_a?(Array)
-            raise ArgumentError, "Subjects must be an array or :all; not %s" % value
-        end
-
-        if value.is_a?(Array) and value.empty?
-            value = nil
-        end
-
-        @subjects = value
-    end
 end
 
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index e06d6e6..1069552 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -6,6 +6,7 @@ require 'puppet/external/lock'
 
 module Puppet
     # A command failed to execute.
+    require 'puppet/error'
     class ExecutionFailure < Puppet::Error
     end
 module Util
diff --git a/lib/puppet/util/package.rb b/lib/puppet/util/package.rb
index 9beed3d..874e782 100644
--- a/lib/puppet/util/package.rb
+++ b/lib/puppet/util/package.rb
@@ -1,5 +1,3 @@
-require 'puppet'
-
 module Puppet::Util::Package
     def versioncmp(version_a, version_b)
         vre = /[-.]|\d+|[^-.\d]+/
diff --git a/spec/unit/application/agent.rb b/spec/unit/application/agent.rb
index 2439fea..fcf01e0 100755
--- a/spec/unit/application/agent.rb
+++ b/spec/unit/application/agent.rb
@@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/agent'
 require 'puppet/network/server'
+require 'puppet/daemon'
 
 describe Puppet::Application::Agent do
     before :each do
diff --git a/spec/unit/application/doc.rb b/spec/unit/application/doc.rb
index c118492..c224b0d 100755
--- a/spec/unit/application/doc.rb
+++ b/spec/unit/application/doc.rb
@@ -3,6 +3,8 @@
 require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/doc'
+require 'puppet/util/reference'
+require 'puppet/util/rdoc'
 
 describe Puppet::Application::Doc do
     before :each do
@@ -163,9 +165,9 @@ describe Puppet::Application::Doc do
                 @doc.options.stubs(:[]).with(:references).returns([])
                 static = stub 'static', :dynamic? => false
                 dynamic = stub 'dynamic', :dynamic? => true
-                Reference.stubs(:reference).with(:static).returns(static)
-                Reference.stubs(:reference).with(:dynamic).returns(dynamic)
-                Reference.stubs(:references).returns([:static,:dynamic])
+                Puppet::Util::Reference.stubs(:reference).with(:static).returns(static)
+                Puppet::Util::Reference.stubs(:reference).with(:dynamic).returns(dynamic)
+                Puppet::Util::Reference.stubs(:references).returns([:static,:dynamic])
 
                 @doc.options.stubs(:[]=).with(:references, [:static])
 
@@ -346,6 +348,7 @@ describe Puppet::Application::Doc do
                 reference = stub 'reference'
                 @doc.options.stubs(:[]).with(:mode).returns(:none)
                 @doc.options.stubs(:[]).with(:references).returns([:ref])
+                require 'puppet/util/reference'
                 Puppet::Util::Reference.expects(:reference).with(:ref).returns(reference)
                 @doc.options.stubs(:[]).with(:format).returns(:format)
                 @doc.stubs(:exit)

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list