[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:13 UTC 2011


The following commit has been merged in the experimental branch:
commit c2715c0f20d916de0284e2d161eb5de32e508244
Author: Luke Kanies <luke at puppetlabs.com>
Date:   Tue Feb 22 17:13:52 2011 -0800

    Splitting the Application base class
    
    We now have an indirection_base class along
    with interface_base.
    
    I've also added some basic tests for most
    of the interfaces.
    
    Signed-off-by: Luke Kanies <luke at puppetlabs.com>

diff --git a/lib/puppet/application/catalog.rb b/lib/puppet/application/catalog.rb
index 0151781..10ce05b 100644
--- a/lib/puppet/application/catalog.rb
+++ b/lib/puppet/application/catalog.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Catalog < Puppet::Application::InterfaceBase
+class Puppet::Application::Catalog < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/certificate.rb b/lib/puppet/application/certificate.rb
index 5033372..4a2b3ef 100644
--- a/lib/puppet/application/certificate.rb
+++ b/lib/puppet/application/certificate.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Certificate < Puppet::Application::InterfaceBase
+class Puppet::Application::Certificate < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/certificate_request.rb b/lib/puppet/application/certificate_request.rb
index f92876e..1b1b083 100644
--- a/lib/puppet/application/certificate_request.rb
+++ b/lib/puppet/application/certificate_request.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Certificate_request < Puppet::Application::InterfaceBase
+class Puppet::Application::Certificate_request < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/certificate_revocation_list.rb b/lib/puppet/application/certificate_revocation_list.rb
index 9dd3bbb..60b9d97 100644
--- a/lib/puppet/application/certificate_revocation_list.rb
+++ b/lib/puppet/application/certificate_revocation_list.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Certificate_revocation_list < Puppet::Application::InterfaceBase
+class Puppet::Application::Certificate_revocation_list < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/facts.rb b/lib/puppet/application/facts.rb
index dfded58..d18b21e 100644
--- a/lib/puppet/application/facts.rb
+++ b/lib/puppet/application/facts.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Facts < Puppet::Application::InterfaceBase
+class Puppet::Application::Facts < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/file.rb b/lib/puppet/application/file.rb
index abf6230..32a81c7 100644
--- a/lib/puppet/application/file.rb
+++ b/lib/puppet/application/file.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::File < Puppet::Application::InterfaceBase
+class Puppet::Application::File < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/indirection_base.rb b/lib/puppet/application/indirection_base.rb
new file mode 100644
index 0000000..3e90769
--- /dev/null
+++ b/lib/puppet/application/indirection_base.rb
@@ -0,0 +1,27 @@
+require 'puppet/application/interface_base'
+require 'puppet/interface'
+
+class Puppet::Application::IndirectionBase < Puppet::Application::InterfaceBase
+  option("--from TERMINUS", "-f") do |arg|
+    @from = arg
+  end
+
+  attr_accessor :from, :indirection
+
+  def main
+    # Call the method associated with the provided action (e.g., 'find').
+    result = interface.send(verb, name, *arguments)
+    render_method = Puppet::Network::FormatHandler.format(format).render_method
+    puts result.send(render_method) if result
+  end
+
+  def setup
+    super
+
+    if interface.respond_to?(:indirection)
+      raise "Could not find data type #{type} for application #{self.class.name}" unless interface.indirection
+
+      interface.set_terminus(from) if from
+    end
+  end
+end
diff --git a/lib/puppet/application/interface_base.rb b/lib/puppet/application/interface_base.rb
index 9a6c8d9..9e8ea99 100644
--- a/lib/puppet/application/interface_base.rb
+++ b/lib/puppet/application/interface_base.rb
@@ -21,28 +21,10 @@ class Puppet::Application::InterfaceBase < Puppet::Application
     Puppet::Util::Log.level = :info
   end
 
-  option("--from TERMINUS", "-f") do |arg|
-    @from = arg
-  end
-
   option("--format FORMAT") do |arg|
     @format = arg.to_sym
   end
 
-  # XXX this doesn't work, I think
-  option("--list") do
-    indirections.each do |ind|
-      begin
-        classes = terminus_classes(ind.to_sym)
-      rescue => detail
-        $stderr.puts "Could not load terminuses for #{ind}: #{detail}"
-        next
-      end
-      puts "%-30s: #{classes.join(", ")}" % ind
-    end
-    exit(0)
-  end
-
   option("--mode RUNMODE", "-r") do |arg|
     raise "Invalid run mode #{arg}; supported modes are user, agent, master" unless %w{user agent master}.include?(arg)
     self.class.run_mode(arg.to_sym)
@@ -50,7 +32,7 @@ class Puppet::Application::InterfaceBase < Puppet::Application
   end
 
 
-  attr_accessor :interface, :from, :type, :verb, :name, :arguments, :indirection, :format
+  attr_accessor :interface, :type, :verb, :name, :arguments, :format
 
   def main
     # Call the method associated with the provided action (e.g., 'find').
@@ -60,7 +42,6 @@ class Puppet::Application::InterfaceBase < Puppet::Application
   end
 
   def setup
-
     Puppet::Util::Log.newdestination :console
 
     @verb, @name, @arguments = command_line.args
@@ -71,13 +52,9 @@ class Puppet::Application::InterfaceBase < Puppet::Application
     unless @interface = Puppet::Interface.interface(@type)
       raise "Could not find interface '#{@type}'"
     end
-    @format ||= @interface.default_format || :pson
+    @format ||= @interface.default_format
 
     validate
-
-    raise "Could not find data type #{type} for application #{self.class.name}" unless interface.indirection
-
-    @interface.set_terminus(from) if from
   end
 
   def validate
diff --git a/lib/puppet/application/inventory.rb b/lib/puppet/application/inventory.rb
deleted file mode 100644
index 8a7e466..0000000
--- a/lib/puppet/application/inventory.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'puppet/application/interface_base'
-
-class Puppet::Application::Inventory < Puppet::Application::InterfaceBase
-end
diff --git a/lib/puppet/application/key.rb b/lib/puppet/application/key.rb
index 1458b94..57835b6 100644
--- a/lib/puppet/application/key.rb
+++ b/lib/puppet/application/key.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Key < Puppet::Application::InterfaceBase
+class Puppet::Application::Key < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/node.rb b/lib/puppet/application/node.rb
index b5f566e..38c1f86 100644
--- a/lib/puppet/application/node.rb
+++ b/lib/puppet/application/node.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Node < Puppet::Application::InterfaceBase
+class Puppet::Application::Node < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/report.rb b/lib/puppet/application/report.rb
index 994bc9e..f7f961e 100644
--- a/lib/puppet/application/report.rb
+++ b/lib/puppet/application/report.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Report < Puppet::Application::InterfaceBase
+class Puppet::Application::Report < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/resource_type.rb b/lib/puppet/application/resource_type.rb
index ecc9f11..5959426 100644
--- a/lib/puppet/application/resource_type.rb
+++ b/lib/puppet/application/resource_type.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Resource_type < Puppet::Application::InterfaceBase
+class Puppet::Application::Resource_type < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/application/status.rb b/lib/puppet/application/status.rb
index c34b890..1c3ca05 100644
--- a/lib/puppet/application/status.rb
+++ b/lib/puppet/application/status.rb
@@ -1,4 +1,4 @@
-require 'puppet/application/interface_base'
+require 'puppet/application/indirection_base'
 
-class Puppet::Application::Status < Puppet::Application::InterfaceBase
+class Puppet::Application::Status < Puppet::Application::IndirectionBase
 end
diff --git a/lib/puppet/interface/file.rb b/lib/puppet/interface/file.rb
index 9060c40..859f92c 100644
--- a/lib/puppet/interface/file.rb
+++ b/lib/puppet/interface/file.rb
@@ -1,5 +1,5 @@
 require 'puppet/interface/indirector'
 
-class Puppet::Interface::Indirector.new(:file) do
+Puppet::Interface::Indirector.new(:file) do
   set_indirection_name :file_bucket_file
 end
diff --git a/lib/puppet/interface/inventory.rb b/lib/puppet/interface/inventory.rb
deleted file mode 100644
index 9b597c6..0000000
--- a/lib/puppet/interface/inventory.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'puppet/interface/indirector'
-
-Puppet::Interface::Indirector.new(:inventory) do
-end
diff --git a/spec/unit/application/indirection_base_spec.rb b/spec/unit/application/indirection_base_spec.rb
new file mode 100644
index 0000000..2e7bd65
--- /dev/null
+++ b/spec/unit/application/indirection_base_spec.rb
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/application/indirection_base'
+
+describe Puppet::Application::IndirectionBase do
+  it "should support a 'from' terminus"
+
+  describe "setup" do
+    it "should fail if its interface does not support an indirection"
+  end
+end
diff --git a/spec/unit/application/interface_base_spec.rb b/spec/unit/application/interface_base_spec.rb
new file mode 100644
index 0000000..ca1353d
--- /dev/null
+++ b/spec/unit/application/interface_base_spec.rb
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/application/interface_base'
+
+describe Puppet::Application::InterfaceBase do
+  describe "during setup" do
+  end
+end
diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb
new file mode 100644
index 0000000..8eb0040
--- /dev/null
+++ b/spec/unit/interface/catalog_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/catalog'
+
+describe Puppet::Interface.interface(:catalog) do
+  before do
+    @interface = Puppet::Interface.interface(:catalog)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'catalog' indirection" do
+    @interface.indirection.name.should == :catalog
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb
new file mode 100644
index 0000000..8a613e5
--- /dev/null
+++ b/spec/unit/interface/certificate_request_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/certificate_request'
+
+describe Puppet::Interface.interface(:certificate_request) do
+  before do
+    @interface = Puppet::Interface.interface(:certificate_request)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'certificate_request' indirection" do
+    @interface.indirection.name.should == :certificate_request
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb
new file mode 100644
index 0000000..8ee341b
--- /dev/null
+++ b/spec/unit/interface/certificate_revocation_list_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/certificate_revocation_list'
+
+describe Puppet::Interface.interface(:certificate_revocation_list) do
+  before do
+    @interface = Puppet::Interface.interface(:certificate_revocation_list)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'certificate_revocation_list' indirection" do
+    @interface.indirection.name.should == :certificate_revocation_list
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb
new file mode 100644
index 0000000..47ddcb5
--- /dev/null
+++ b/spec/unit/interface/certificate_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/certificate'
+
+describe Puppet::Interface.interface(:certificate) do
+  before do
+    @interface = Puppet::Interface.interface(:certificate)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'certificate' indirection" do
+    @interface.indirection.name.should == :certificate
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb
new file mode 100644
index 0000000..fc7accf
--- /dev/null
+++ b/spec/unit/interface/file_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/file'
+
+describe Puppet::Interface.interface(:file) do
+  before do
+    @interface = Puppet::Interface.interface(:file)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'file' indirection" do
+    @interface.indirection.name.should == :file_bucket_file
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb
index 1e5ee30..645c599 100644
--- a/spec/unit/interface/indirector_spec.rb
+++ b/spec/unit/interface/indirector_spec.rb
@@ -29,8 +29,6 @@ describe Puppet::Interface::Indirector do
   end
 
   describe "as an instance" do
-    after { Puppet::Interface.unload_interface(:catalog) }
-
     it "should be able to determine its indirection" do
       # Loading actions here an get, um, complicated
       Puppet::Interface.stubs(:load_actions)
diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb
new file mode 100644
index 0000000..93a7c93
--- /dev/null
+++ b/spec/unit/interface/key_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/key'
+
+describe Puppet::Interface.interface(:key) do
+  before do
+    @interface = Puppet::Interface.interface(:key)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'key' indirection" do
+    @interface.indirection.name.should == :key
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb
new file mode 100644
index 0000000..afb609d
--- /dev/null
+++ b/spec/unit/interface/node_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/node'
+
+describe Puppet::Interface.interface(:node) do
+  before do
+    @interface = Puppet::Interface.interface(:node)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'node' indirection" do
+    @interface.indirection.name.should == :node
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb
new file mode 100644
index 0000000..b5bee1a
--- /dev/null
+++ b/spec/unit/interface/report_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/report'
+
+describe Puppet::Interface.interface(:report) do
+  before do
+    @interface = Puppet::Interface.interface(:report)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'report' indirection" do
+    @interface.indirection.name.should == :report
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb
new file mode 100644
index 0000000..cad45b6
--- /dev/null
+++ b/spec/unit/interface/resource_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/resource'
+
+describe Puppet::Interface.interface(:resource) do
+  before do
+    @interface = Puppet::Interface.interface(:resource)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'resource' indirection" do
+    @interface.indirection.name.should == :resource
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end
diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb
new file mode 100644
index 0000000..6c437c4
--- /dev/null
+++ b/spec/unit/interface/resource_type_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+require 'puppet/interface/resource_type'
+
+describe Puppet::Interface.interface(:resource_type) do
+  before do
+    @interface = Puppet::Interface.interface(:resource_type)
+  end
+
+  it "should be a subclass of 'Indirection'" do
+    @interface.should be_instance_of(Puppet::Interface::Indirector)
+  end
+
+  it "should refer to the 'resource_type' indirection" do
+    @interface.indirection.name.should == :resource_type
+  end
+
+  [:find, :save, :search, :save].each do |method|
+    it "should have  #{method} action defined" do
+      @interface.should be_action(method)
+    end
+  end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list