[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Luke Kanies luke at puppetlabs.com
Tue May 10 08:05:16 UTC 2011


The following commit has been merged in the experimental branch:
commit bec807e5a12e24c11aedb40a997b154f1bed62c0
Author: Luke Kanies <luke at puppetlabs.com>
Date:   Tue Feb 22 23:04:45 2011 -0800

    Fixing 'puppet interface list'
    
    Also added a test to hopefully confirm it won't
    break again.
    
    Signed-off-by: Luke Kanies <luke at puppetlabs.com>

diff --git a/lib/puppet/application/interface.rb b/lib/puppet/application/interface.rb
index 8f26658..10823e9 100644
--- a/lib/puppet/application/interface.rb
+++ b/lib/puppet/application/interface.rb
@@ -1,4 +1,5 @@
 require 'puppet/application'
+require 'puppet/interface'
 
 class Puppet::Application::Interface < Puppet::Application
 
@@ -24,6 +25,7 @@ class Puppet::Application::Interface < Puppet::Application
           terms = terminus_classes(name.to_sym)
           str << "\tTerminuses: #{terms.join(", ")}\n"
         rescue => detail
+          puts detail.backtrace if Puppet[:trace]
           $stderr.puts "Could not load terminuses for #{name}: #{detail}"
         end
       end
@@ -33,13 +35,13 @@ class Puppet::Application::Interface < Puppet::Application
           actions = actions(name.to_sym)
           str << "\tActions: #{actions.join(", ")}\n"
         rescue => detail
+          puts detail.backtrace if Puppet[:trace]
           $stderr.puts "Could not load actions for #{name}: #{detail}"
         end
       end
 
       print str
     end
-    exit(0)
   end
 
   attr_accessor :verb, :name, :arguments
@@ -71,31 +73,7 @@ class Puppet::Application::Interface < Puppet::Application
   end
 
   def interfaces
-    # Load all of the interfaces
-    unless @interfaces
-      $LOAD_PATH.each do |dir|
-        next unless FileTest.directory?(dir)
-        Dir.chdir(dir) do
-          Dir.glob("puppet/interface/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file|
-            begin
-              require file
-            rescue Error => detail
-              puts detail.backtrace if Puppet[:trace]
-              raise "Could not load #{file}: #{detail}"
-            end
-          end
-        end
-      end
-
-      @interfaces = []
-      Puppet::Interface.constants.each do |name|
-        klass = Puppet::Interface.const_get(name)
-        next if klass.abstract? # skip base classes
-
-        @interfaces << name.downcase
-      end
-    end
-    @interfaces
+    Puppet::Interface.interfaces
   end
 
   def terminus_classes(indirection)
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 70356de..f8791e5 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -12,6 +12,27 @@ class Puppet::Interface
     @autoloader ||= Puppet::Util::Autoload.new(:application, "puppet/interface")
   end
 
+  def self.interfaces
+    unless @loaded
+      @loaded = true
+      $LOAD_PATH.each do |dir|
+        next unless FileTest.directory?(dir)
+        Dir.chdir(dir) do
+          Dir.glob("puppet/interface/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file|
+            iname = file.sub(/\.rb/, '')
+            begin
+              require iname
+            rescue Exception => detail
+              puts detail.backtrace if Puppet[:trace]
+              raise "Could not load #{iname} from #{dir}/#{file}: #{detail}"
+            end
+          end
+        end
+      end
+    end
+    @interfaces.keys
+  end
+
   # Return an interface by name, loading from disk if necessary.
   def self.interface(name)
     @interfaces ||= {}
@@ -24,21 +45,6 @@ class Puppet::Interface
     $stderr.puts "Unable to find interface '#{name.to_s}': #{detail}."
   end
 
-  # Try to find actions defined in other files.
-  def self.load_actions(name)
-    path = "puppet/interface/#{name}"
-
-    autoloader.search_directories.each do |dir|
-      fdir = ::File.join(dir, path)
-      next unless FileTest.directory?(fdir)
-
-      Dir.glob("#{fdir}/*.rb").each do |file|
-        Puppet.info "Loading actions for '#{name}' from '#{file}'"
-        require file
-      end
-    end
-  end
-
   def self.register_interface(name, instance)
     @interfaces ||= {}
     @interfaces[unify_name(name)] = instance
@@ -97,13 +103,31 @@ class Puppet::Interface
     # subclasses.
     Puppet::Interface.register_interface(name, self)
 
-    Puppet::Interface.load_actions(name)
+    load_actions
 
     if block_given?
       instance_eval(&block)
     end
   end
 
+  # Try to find actions defined in other files.
+  def load_actions
+    path = "puppet/interface/#{name}"
+
+    self.class.autoloader.search_directories.each do |dir|
+      fdir = ::File.join(dir, path)
+      next unless FileTest.directory?(fdir)
+
+      Dir.chdir(fdir) do
+        Dir.glob("*.rb").each do |file|
+          aname = file.sub(/\.rb/, '')
+          Puppet.debug "Loading action '#{aname}' for '#{name}' from '#{fdir}/#{file}'"
+          require "#{path}/#{aname}"
+        end
+      end
+    end
+  end
+
   def to_s
     name.to_s
   end
diff --git a/spec/unit/application/interface_spec.rb b/spec/unit/application/interface_spec.rb
new file mode 100644
index 0000000..153e9bd
--- /dev/null
+++ b/spec/unit/application/interface_spec.rb
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/application/interface'
+
+describe Puppet::Application::Interface do
+  it "should be an application" do
+    Puppet::Application::Interface.superclass.should equal(Puppet::Application)
+  end
+end
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb
index 5d25623..774c0bd 100644
--- a/spec/unit/interface_spec.rb
+++ b/spec/unit/interface_spec.rb
@@ -19,7 +19,7 @@ describe Puppet::Interface do
     end
 
     it "should load actions" do
-      Puppet::Interface.expects(:load_actions).with(:me)
+      Puppet::Interface.any_instance.expects(:load_actions)
       Puppet::Interface.new(:me)
     end
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list