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

Pieter van de Bruggen pieter at puppetlabs.com
Tue May 10 08:07:46 UTC 2011


The following commit has been merged in the experimental branch:
commit 1187a0eb2550f04d9b6c3dcfdcacdfbb32de0e56
Author: Pieter van de Bruggen <pieter at puppetlabs.com>
Date:   Wed Mar 23 13:59:44 2011 -0700

    (#6770) Add basic versioning for interfaces.
    
    Reviewed-By: Nick Lewis

diff --git a/lib/puppet/application/configurer.rb b/lib/puppet/application/configurer.rb
index 3783644..a76aaaf 100644
--- a/lib/puppet/application/configurer.rb
+++ b/lib/puppet/application/configurer.rb
@@ -17,7 +17,7 @@ class Puppet::Application::Configurer < Puppet::Application
   end
 
   def run_command
-    report = Puppet::Interface.interface(:configurer).synchronize(Puppet[:certname])
-    Puppet::Interface.interface(:report).submit(report)
+    report = Puppet::Interface.interface(:configurer, 1).synchronize(Puppet[:certname])
+    Puppet::Interface.interface(:report, 1).submit(report)
   end
 end
diff --git a/lib/puppet/application/interface.rb b/lib/puppet/application/interface.rb
index 10823e9..99c10dc 100644
--- a/lib/puppet/application/interface.rb
+++ b/lib/puppet/application/interface.rb
@@ -81,7 +81,7 @@ class Puppet::Application::Interface < Puppet::Application
   end
 
   def actions(indirection)
-    return [] unless interface = Puppet::Interface.interface(indirection)
+    return [] unless interface = Puppet::Interface.interface(indirection, 1)
     interface.load_actions
     return interface.actions.sort { |a,b| a.to_s <=> b.to_s }
   end
diff --git a/lib/puppet/application/interface_base.rb b/lib/puppet/application/interface_base.rb
index 7a31ce3..7877283 100644
--- a/lib/puppet/application/interface_base.rb
+++ b/lib/puppet/application/interface_base.rb
@@ -71,10 +71,11 @@ class Puppet::Application::InterfaceBase < Puppet::Application
 
     @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym
 
-    unless Puppet::Interface.interface?(@type)
-      raise "Could not find interface '#{@type}'"
+    # TODO: These should be configurable versions.
+    unless Puppet::Interface.interface?(@type, 1)
+      raise "Could not find version #{1} of interface '#{@type}'"
     end
-    @interface = Puppet::Interface.interface(@type)
+    @interface = Puppet::Interface.interface(@type, 1)
     @format ||= @interface.default_format
 
     # We copy all of the app options to the interface.
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index f82d623..7f208f5 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -10,8 +10,6 @@ class Puppet::Interface
 
   include Puppet::Util
 
-  @interfaces = {}
-
   # This is just so we can search for actions.  We only use its
   # list of directories to search.
   # Can't we utilize an external autoloader, or simply use the $LOAD_PATH? -pvb
@@ -23,20 +21,20 @@ class Puppet::Interface
     Puppet::Interface::InterfaceCollection.interfaces
   end
 
-  def self.interface?(name)
-    Puppet::Interface::InterfaceCollection.interface?(name)
+  def self.interface?(name, version)
+    Puppet::Interface::InterfaceCollection.interface?(name, version)
   end
 
   def self.register(instance)
     Puppet::Interface::InterfaceCollection.register(instance)
   end
 
-  def self.interface(name, &blk)
-    if interface?(name)
-      interface = Puppet::Interface::InterfaceCollection[name]
+  def self.interface(name, version, &blk)
+    if interface?(name, version)
+      interface = Puppet::Interface::InterfaceCollection[name, version]
       interface.instance_eval(&blk) if blk
     else
-      interface = new(name, &blk)
+      interface = self.new(name, :version => version, &blk)
       Puppet::Interface::InterfaceCollection.register(interface)
       interface.load_actions
     end
@@ -49,10 +47,14 @@ class Puppet::Interface
     self.default_format = format.to_sym
   end
 
-  attr_accessor :type, :verb, :arguments, :options
+  attr_accessor :type, :verb, :version, :arguments, :options
   attr_reader :name
 
   def initialize(name, options = {}, &block)
+    unless options[:version]
+      raise ArgumentError, "Interface #{name} declared without version!"
+    end
+
     @name = Puppet::Interface::InterfaceCollection.underscorize(name)
 
     @default_format = :pson
@@ -86,6 +88,6 @@ class Puppet::Interface
   end
 
   def to_s
-    "Puppet::Interface(#{name})"
+    "Puppet::Interface(#{name}, :version => #{version.inspect})"
   end
 end
diff --git a/lib/puppet/interface/certificate.rb b/lib/puppet/interface/certificate.rb
deleted file mode 100644
index 09da0a6..0000000
--- a/lib/puppet/interface/certificate.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'puppet/interface/indirector'
-
-Puppet::Interface::Indirector.interface(:certificate) do
-end
diff --git a/lib/puppet/interface/certificate_request.rb b/lib/puppet/interface/certificate_request.rb
deleted file mode 100644
index b85c15f..0000000
--- a/lib/puppet/interface/certificate_request.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'puppet/interface/indirector'
-
-Puppet::Interface::Indirector.interface(:certificate_request) do
-end
diff --git a/lib/puppet/interface/configurer.rb b/lib/puppet/interface/configurer.rb
deleted file mode 100644
index 0d21c4d..0000000
--- a/lib/puppet/interface/configurer.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'puppet/interface'
-
-Puppet::Interface.interface(:configurer) do
-  action(:synchronize) do
-    invoke do |certname|
-      facts = Puppet::Interface.interface(:facts).find(certname)
-      catalog = Puppet::Interface.interface(:catalog).download(certname, facts)
-      report = Puppet::Interface.interface(:catalog).apply(catalog)
-      report
-    end
-  end
-end
diff --git a/lib/puppet/interface/interface_collection.rb b/lib/puppet/interface/interface_collection.rb
index 47ed702..d626c4f 100644
--- a/lib/puppet/interface/interface_collection.rb
+++ b/lib/puppet/interface/interface_collection.rb
@@ -1,7 +1,7 @@
 require 'puppet/interface'
 
 module Puppet::Interface::InterfaceCollection
-  @interfaces = {}
+  @interfaces = Hash.new { |hash, key| hash[key] = {} }
 
   def self.interfaces
     unless @loaded
@@ -24,20 +24,22 @@ module Puppet::Interface::InterfaceCollection
     return @interfaces.keys
   end
 
-  def self.[](name)
-    @interfaces[underscorize(name)] if interface?(name)
+  def self.[](name, version)
+    @interfaces[underscorize(name)][version] if interface?(name, version)
   end
 
-  def self.interface?(name)
+  def self.interface?(name, version)
     name = underscorize(name)
-    require "puppet/interface/#{name}" unless @interfaces.has_key? name
-    return @interfaces.has_key? name
+    unless @interfaces.has_key?(name) && @interfaces[name].has_key?(version)
+      require "puppet/interface/v#{version}/#{name}"
+    end
+    return @interfaces.has_key?(name) && @interfaces[name].has_key?(version)
   rescue LoadError
     return false
   end
 
   def self.register(interface)
-    @interfaces[underscorize(interface.name)] = interface
+    @interfaces[underscorize(interface.name)][interface.version] = interface
   end
 
   def self.underscorize(name)
diff --git a/lib/puppet/interface/key.rb b/lib/puppet/interface/key.rb
deleted file mode 100644
index 5751988..0000000
--- a/lib/puppet/interface/key.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'puppet/interface/indirector'
-
-Puppet::Interface::Indirector.interface(:key) do
-end
diff --git a/lib/puppet/interface/resource.rb b/lib/puppet/interface/resource.rb
deleted file mode 100644
index 130f40f..0000000
--- a/lib/puppet/interface/resource.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'puppet/interface/indirector'
-
-Puppet::Interface::Indirector.interface(:resource) do
-end
diff --git a/lib/puppet/interface/resource_type.rb b/lib/puppet/interface/resource_type.rb
deleted file mode 100644
index 70bf3b9..0000000
--- a/lib/puppet/interface/resource_type.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'puppet/interface/indirector'
-
-Puppet::Interface::Indirector.interface(:resource_type) do
-end
diff --git a/lib/puppet/interface/status.rb b/lib/puppet/interface/status.rb
deleted file mode 100644
index 432d1ce..0000000
--- a/lib/puppet/interface/status.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'puppet/interface/indirector'
-
-Puppet::Interface::Indirector.interface(:status) do
-end
diff --git a/lib/puppet/interface/catalog.rb b/lib/puppet/interface/v1/catalog.rb
similarity index 87%
rename from lib/puppet/interface/catalog.rb
rename to lib/puppet/interface/v1/catalog.rb
index defe321..2ba6420 100644
--- a/lib/puppet/interface/catalog.rb
+++ b/lib/puppet/interface/v1/catalog.rb
@@ -1,6 +1,6 @@
 require 'puppet/interface/indirector'
 
-Puppet::Interface::Indirector.interface(:catalog) do
+Puppet::Interface::Indirector.interface(:catalog, 1) do
   action(:apply) do
     invoke do |catalog|
       report = Puppet::Transaction::Report.new("apply")
@@ -28,7 +28,7 @@ Puppet::Interface::Indirector.interface(:catalog) do
       facts_to_upload = {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(facts.render(:b64_zlib_yaml))}
       catalog = nil
       retrieval_duration = thinmark do
-        catalog = Puppet::Interface.interface(:catalog).find(certname, facts_to_upload)
+        catalog = Puppet::Interface.interface(:catalog, 1).find(certname, facts_to_upload)
       end
       catalog = catalog.to_ral
       catalog.finalize
diff --git a/lib/puppet/interface/catalog/select.rb b/lib/puppet/interface/v1/catalog/select.rb
similarity index 85%
rename from lib/puppet/interface/catalog/select.rb
rename to lib/puppet/interface/v1/catalog/select.rb
index 32d9b7c..e37c841 100644
--- a/lib/puppet/interface/catalog/select.rb
+++ b/lib/puppet/interface/v1/catalog/select.rb
@@ -1,5 +1,5 @@
 # Select and show a list of resources of a given type.
-Puppet::Interface.interface(:catalog) do
+Puppet::Interface.interface(:catalog, 1) do
   action :select do
     invoke do |host,type|
       catalog = Puppet::Resource::Catalog.indirection.find(host)
diff --git a/lib/puppet/interface/v1/certificate.rb b/lib/puppet/interface/v1/certificate.rb
new file mode 100644
index 0000000..9a88c62
--- /dev/null
+++ b/lib/puppet/interface/v1/certificate.rb
@@ -0,0 +1,4 @@
+require 'puppet/interface/indirector'
+
+Puppet::Interface::Indirector.interface(:certificate, 1) do
+end
diff --git a/lib/puppet/interface/v1/certificate_request.rb b/lib/puppet/interface/v1/certificate_request.rb
new file mode 100644
index 0000000..868933e
--- /dev/null
+++ b/lib/puppet/interface/v1/certificate_request.rb
@@ -0,0 +1,4 @@
+require 'puppet/interface/indirector'
+
+Puppet::Interface::Indirector.interface(:certificate_request, 1) do
+end
diff --git a/lib/puppet/interface/certificate_revocation_list.rb b/lib/puppet/interface/v1/certificate_revocation_list.rb
similarity index 89%
rename from lib/puppet/interface/certificate_revocation_list.rb
rename to lib/puppet/interface/v1/certificate_revocation_list.rb
index 956fb64..09efd8c 100644
--- a/lib/puppet/interface/certificate_revocation_list.rb
+++ b/lib/puppet/interface/v1/certificate_revocation_list.rb
@@ -1,4 +1,4 @@
 require 'puppet/interface/indirector'
 
-Puppet::Interface::Indirector.interface(:certificate_revocation_list) do
+Puppet::Interface::Indirector.interface(:certificate_revocation_list, 1) do
 end
diff --git a/lib/puppet/interface/config.rb b/lib/puppet/interface/v1/config.rb
similarity index 81%
rename from lib/puppet/interface/config.rb
rename to lib/puppet/interface/v1/config.rb
index 79d2ee7..a072e70 100644
--- a/lib/puppet/interface/config.rb
+++ b/lib/puppet/interface/v1/config.rb
@@ -1,6 +1,6 @@
 require 'puppet/interface'
 
-Puppet::Interface.interface(:config) do
+Puppet::Interface.interface(:config, 1) do
   action(:print) do
     invoke do |*args|
       Puppet.settings[:configprint] = args.join(",")
diff --git a/lib/puppet/interface/v1/configurer.rb b/lib/puppet/interface/v1/configurer.rb
new file mode 100644
index 0000000..1deffce
--- /dev/null
+++ b/lib/puppet/interface/v1/configurer.rb
@@ -0,0 +1,12 @@
+require 'puppet/interface'
+
+Puppet::Interface.interface(:configurer, 1) do
+  action(:synchronize) do
+    invoke do |certname|
+      facts = Puppet::Interface.interface(:facts, 1).find(certname)
+      catalog = Puppet::Interface.interface(:catalog, 1).download(certname, facts)
+      report = Puppet::Interface.interface(:catalog, 1).apply(catalog)
+      report
+    end
+  end
+end
diff --git a/lib/puppet/interface/facts.rb b/lib/puppet/interface/v1/facts.rb
similarity index 90%
rename from lib/puppet/interface/facts.rb
rename to lib/puppet/interface/v1/facts.rb
index 97e2271..0be23b7 100644
--- a/lib/puppet/interface/facts.rb
+++ b/lib/puppet/interface/v1/facts.rb
@@ -1,7 +1,7 @@
 require 'puppet/interface/indirector'
 require 'puppet/node/facts'
 
-Puppet::Interface::Indirector.interface(:facts) do
+Puppet::Interface::Indirector.interface(:facts, 1) do
   set_default_format :yaml
 
   # Upload our facts to the server
diff --git a/lib/puppet/interface/file.rb b/lib/puppet/interface/v1/file.rb
similarity index 61%
rename from lib/puppet/interface/file.rb
rename to lib/puppet/interface/v1/file.rb
index f38af2b..430413a 100644
--- a/lib/puppet/interface/file.rb
+++ b/lib/puppet/interface/v1/file.rb
@@ -1,5 +1,5 @@
 require 'puppet/interface/indirector'
 
-Puppet::Interface::Indirector.interface(:file) do
+Puppet::Interface::Indirector.interface(:file, 1) do
   set_indirection_name :file_bucket_file
 end
diff --git a/lib/puppet/interface/v1/key.rb b/lib/puppet/interface/v1/key.rb
new file mode 100644
index 0000000..fc82f4d
--- /dev/null
+++ b/lib/puppet/interface/v1/key.rb
@@ -0,0 +1,4 @@
+require 'puppet/interface/indirector'
+
+Puppet::Interface::Indirector.interface(:key, 1) do
+end
diff --git a/lib/puppet/interface/node.rb b/lib/puppet/interface/v1/node.rb
similarity index 56%
rename from lib/puppet/interface/node.rb
rename to lib/puppet/interface/v1/node.rb
index 8940fd7..c3e5278 100644
--- a/lib/puppet/interface/node.rb
+++ b/lib/puppet/interface/v1/node.rb
@@ -1,5 +1,5 @@
 require 'puppet/interface/indirector'
 
-Puppet::Interface::Indirector.interface(:node) do
+Puppet::Interface::Indirector.interface(:node, 1) do
   set_default_format :yaml
 end
diff --git a/lib/puppet/interface/report.rb b/lib/puppet/interface/v1/report.rb
similarity index 85%
rename from lib/puppet/interface/report.rb
rename to lib/puppet/interface/v1/report.rb
index 56a58f6..fdc2e2c 100644
--- a/lib/puppet/interface/report.rb
+++ b/lib/puppet/interface/v1/report.rb
@@ -1,6 +1,6 @@
 require 'puppet/interface/indirector'
 
-Puppet::Interface::Indirector.interface(:report) do
+Puppet::Interface::Indirector.interface(:report, 1) do
   action(:submit) do
     invoke do |report|
       begin
diff --git a/lib/puppet/interface/v1/resource.rb b/lib/puppet/interface/v1/resource.rb
new file mode 100644
index 0000000..20dc283
--- /dev/null
+++ b/lib/puppet/interface/v1/resource.rb
@@ -0,0 +1,4 @@
+require 'puppet/interface/indirector'
+
+Puppet::Interface::Indirector.interface(:resource, 1) do
+end
diff --git a/lib/puppet/interface/v1/resource_type.rb b/lib/puppet/interface/v1/resource_type.rb
new file mode 100644
index 0000000..f180dc5
--- /dev/null
+++ b/lib/puppet/interface/v1/resource_type.rb
@@ -0,0 +1,4 @@
+require 'puppet/interface/indirector'
+
+Puppet::Interface::Indirector.interface(:resource_type, 1) do
+end
diff --git a/lib/puppet/interface/v1/status.rb b/lib/puppet/interface/v1/status.rb
new file mode 100644
index 0000000..a2493b5
--- /dev/null
+++ b/lib/puppet/interface/v1/status.rb
@@ -0,0 +1,4 @@
+require 'puppet/interface/indirector'
+
+Puppet::Interface::Indirector.interface(:status, 1) do
+end
diff --git a/spec/unit/application/interface_base_spec.rb b/spec/unit/application/interface_base_spec.rb
index 3e7c04f..6aa9558 100644
--- a/spec/unit/application/interface_base_spec.rb
+++ b/spec/unit/application/interface_base_spec.rb
@@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
 require 'puppet/application/interface_base'
 require 'puppet/application/interface_base'
 
-base_interface = Puppet::Interface.interface(:basetest)
+base_interface = Puppet::Interface.interface(:basetest, 1)
 class Puppet::Application::InterfaceBase::Basetest < Puppet::Application::InterfaceBase
 end
 
diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb
index 39b2386..ba6618f 100644
--- a/spec/unit/interface/action_builder_spec.rb
+++ b/spec/unit/interface/action_builder_spec.rb
@@ -13,7 +13,7 @@ describe Puppet::Interface::ActionBuilder do
     end
 
     it "should define a method on the interface which invokes the action" do
-      interface = Puppet::Interface.new(:action_builder_test_interface)
+      interface = Puppet::Interface.new(:action_builder_test_interface, :version => 1)
       action = Puppet::Interface::ActionBuilder.build(interface, :foo) do
         invoke do
           "invoked the method"
diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb
index e74fa9f..5be6665 100644
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@ -24,7 +24,7 @@ describe Puppet::Interface::Action do
 
   describe "when invoking" do
     it "should be able to call other actions on the same object" do
-      interface = Puppet::Interface.new(:my_interface) do
+      interface = Puppet::Interface.new(:my_interface, :version => 1) do
         action(:foo) do
           invoke { 25 }
         end
@@ -56,7 +56,7 @@ describe Puppet::Interface::Action do
         end
       end
 
-      interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface) do
+      interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, :version => 1) do
         action(:baz) do
           invoke { "the value of foo in baz is '#{foo}'" }
         end
diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb
index 78d6211..a59f9c9 100644
--- a/spec/unit/interface/catalog_spec.rb
+++ b/spec/unit/interface/catalog_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/catalog'
 
-describe Puppet::Interface::Indirector.interface(:catalog) do
+describe Puppet::Interface.interface(:catalog, 1) do
 end
diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb
index a6ab8d1..e818c30 100644
--- a/spec/unit/interface/certificate_request_spec.rb
+++ b/spec/unit/interface/certificate_request_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/certificate_request'
 
-describe Puppet::Interface::Indirector.interface(:certificate_request) do
+describe Puppet::Interface.interface(:certificate_request, 1) do
 end
diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb
index a98b48d..0979eda 100644
--- a/spec/unit/interface/certificate_revocation_list_spec.rb
+++ b/spec/unit/interface/certificate_revocation_list_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/certificate_revocation_list'
 
-describe Puppet::Interface::Indirector.interface(:certificate_revocation_list) do
+describe Puppet::Interface.interface(:certificate_revocation_list, 1) do
 end
diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb
index 6a32534..51b79e6 100644
--- a/spec/unit/interface/certificate_spec.rb
+++ b/spec/unit/interface/certificate_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/certificate'
 
-describe Puppet::Interface::Indirector.interface(:certificate) do
+describe Puppet::Interface.interface(:certificate, 1) do
 end
diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb
index e8aafd4..e1238b9 100644
--- a/spec/unit/interface/config_spec.rb
+++ b/spec/unit/interface/config_spec.rb
@@ -1,9 +1,8 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/config'
 
-describe Puppet::Interface.interface(:config) do
+describe Puppet::Interface.interface(:config, 1) do
   it "should use Settings#print_config_options when asked to print" do
     Puppet.settings.stubs(:puts)
     Puppet.settings.expects(:print_config_options)
diff --git a/spec/unit/interface/configurer_spec.rb b/spec/unit/interface/configurer_spec.rb
index 4b3532c..b592a85 100644
--- a/spec/unit/interface/configurer_spec.rb
+++ b/spec/unit/interface/configurer_spec.rb
@@ -1,11 +1,10 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/configurer'
 require 'puppet/indirector/catalog/rest'
 require 'tempfile'
 
-describe Puppet::Interface.interface(:configurer) do
+describe Puppet::Interface.interface(:configurer, 1) do
   describe "#synchronize" do
     it "should retrieve and apply a catalog and return a report" do
       dirname = Dir.mktmpdir("puppetdir")
@@ -16,7 +15,7 @@ describe Puppet::Interface.interface(:configurer) do
       @catalog.add_resource(@file)
       Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog)
 
-      report = Puppet::Interface.interface(:configurer).synchronize("foo")
+      report = subject.synchronize("foo")
 
       report.kind.should   == "apply"
       report.status.should == "changed"
diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb
index d0f87d3..2b5731d 100644
--- a/spec/unit/interface/facts_spec.rb
+++ b/spec/unit/interface/facts_spec.rb
@@ -1,9 +1,8 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/facts'
 
-describe Puppet::Interface::Indirector.interface(:facts) do
+describe Puppet::Interface.interface(:facts, 1) do
   it "should define an 'upload' fact" do
     subject.should be_action(:upload)
   end
diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb
index 54427a2..754b228 100644
--- a/spec/unit/interface/file_spec.rb
+++ b/spec/unit/interface/file_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/file'
 
-describe Puppet::Interface::Indirector.interface(:file) do
+describe Puppet::Interface.interface(:file, 1) do
 end
diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb
index 0eb7a9a..abbff15 100644
--- a/spec/unit/interface/indirector_spec.rb
+++ b/spec/unit/interface/indirector_spec.rb
@@ -5,7 +5,7 @@ require 'puppet/interface/indirector'
 
 describe Puppet::Interface::Indirector do
   before do
-    @instance = Puppet::Interface::Indirector.new(:test)
+    @instance = Puppet::Interface::Indirector.new(:test, :version => 1)
 
     @indirection = stub 'indirection', :name => :stub_indirection
 
@@ -24,7 +24,7 @@ describe Puppet::Interface::Indirector do
     it "should be able to determine its indirection" do
       # Loading actions here an get, um, complicated
       Puppet::Interface.stubs(:load_actions)
-      Puppet::Interface::Indirector.new(:catalog).indirection.should equal(Puppet::Resource::Catalog.indirection)
+      Puppet::Interface::Indirector.new(:catalog, :version => 1).indirection.should equal(Puppet::Resource::Catalog.indirection)
     end
   end
 
diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb
index 536e694..ae684ca 100644
--- a/spec/unit/interface/interface_collection_spec.rb
+++ b/spec/unit/interface/interface_collection_spec.rb
@@ -1,14 +1,18 @@
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+#!/usr/bin/env ruby
 
-require 'puppet/interface/interface_collection'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
 
 describe Puppet::Interface::InterfaceCollection do
+  before :all do
+    @interfaces = subject.instance_variable_get("@interfaces").dup
+  end
+
   before :each do
-    subject.instance_variable_set("@interfaces", {})
+    subject.instance_variable_get("@interfaces").clear
   end
 
   after :all do
-    subject.instance_variable_set("@interfaces", {})
+    subject.instance_variable_set("@interfaces", @interfaces)
   end
 
   describe "::interfaces" do
@@ -16,56 +20,56 @@ describe Puppet::Interface::InterfaceCollection do
 
   describe "::[]" do
     before :each do
-      subject.instance_variable_set("@interfaces", {:foo => 10})
+      subject.instance_variable_get("@interfaces")[:foo][1] = 10
     end
 
     it "should return the interface with the given name" do
-      subject["foo"].should == 10
+      subject["foo", 1].should == 10
     end
 
     it "should attempt to load the interface if it isn't found" do
-      subject.expects(:require).with('puppet/interface/bar')
-      subject["bar"]
+      subject.expects(:require).with('puppet/interface/v1/bar')
+      subject["bar", 1]
     end
   end
 
   describe "::interface?" do
     before :each do
-      subject.instance_variable_set("@interfaces", {:foo => 10})
+      subject.instance_variable_get("@interfaces")[:foo][1] = 10
     end
 
     it "should return true if the interface specified is registered" do
-      subject.interface?("foo").should == true
+      subject.interface?("foo", 1).should == true
     end
 
     it "should attempt to require the interface if it is not registered" do
-      subject.expects(:require).with('puppet/interface/bar')
-      subject.interface?("bar")
+      subject.expects(:require).with('puppet/interface/v1/bar')
+      subject.interface?("bar", 1)
     end
 
     it "should return true if requiring the interface registered it" do
       subject.stubs(:require).with do
-        subject.instance_variable_set("@interfaces", {:bar => 20})
+        subject.instance_variable_get("@interfaces")[:bar][1] = 20
       end
-      subject.interface?("bar").should == true
+      subject.interface?("bar", 1).should == true
     end
 
     it "should return false if the interface is not registered" do
       subject.stubs(:require).returns(true)
-      subject.interface?("bar").should == false
+      subject.interface?("bar", 1).should == false
     end
 
     it "should return false if there is a LoadError requiring the interface" do
       subject.stubs(:require).raises(LoadError)
-      subject.interface?("bar").should == false
+      subject.interface?("bar", 1).should == false
     end
   end
 
   describe "::register" do
     it "should store the interface by name" do
-      interface = Puppet::Interface.new(:my_interface)
+      interface = Puppet::Interface.new(:my_interface, :version => 1)
       subject.register(interface)
-      subject.instance_variable_get("@interfaces").should == {:my_interface => interface}
+      subject.instance_variable_get("@interfaces").should == {:my_interface => {1 => interface}}
     end
   end
 
diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb
index 4b331d1..395fbef 100644
--- a/spec/unit/interface/key_spec.rb
+++ b/spec/unit/interface/key_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/key'
 
-describe Puppet::Interface::Indirector.interface(:key) do
+describe Puppet::Interface.interface(:key, 1) do
 end
diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb
index b1b4ad4..bd4bc9f 100644
--- a/spec/unit/interface/node_spec.rb
+++ b/spec/unit/interface/node_spec.rb
@@ -1,9 +1,8 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/node'
 
-describe Puppet::Interface::Indirector.interface(:node) do
+describe Puppet::Interface.interface(:node, 1) do
   it "should set its default format to :yaml" do
     subject.default_format.should == :yaml
   end
diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb
index c424880..0dd3cac 100644
--- a/spec/unit/interface/report_spec.rb
+++ b/spec/unit/interface/report_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/report'
 
-describe Puppet::Interface::Indirector.interface(:report) do
+describe Puppet::Interface.interface(:report, 1) do
 end
diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb
index aab2753..5101ddb 100644
--- a/spec/unit/interface/resource_spec.rb
+++ b/spec/unit/interface/resource_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/resource'
 
-describe Puppet::Interface::Indirector.interface(:resource) do
+describe Puppet::Interface.interface(:resource, 1) do
 end
diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb
index 6e973c9..84afa30 100644
--- a/spec/unit/interface/resource_type_spec.rb
+++ b/spec/unit/interface/resource_type_spec.rb
@@ -1,7 +1,6 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'puppet/interface/resource_type'
 
-describe Puppet::Interface::Indirector.interface(:resource_type) do
+describe Puppet::Interface.interface(:resource_type, 1) do
 end
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb
index e35da6b..b78a9f8 100755
--- a/spec/unit/interface_spec.rb
+++ b/spec/unit/interface_spec.rb
@@ -1,22 +1,43 @@
 #!/usr/bin/env ruby
 
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
-require 'puppet/interface'
 
 describe Puppet::Interface do
+  before :all do
+    @interfaces = Puppet::Interface::InterfaceCollection.instance_variable_get("@interfaces").dup
+  end
+
+  before :each do
+    Puppet::Interface::InterfaceCollection.instance_variable_get("@interfaces").clear
+  end
+
+  after :all do
+    Puppet::Interface::InterfaceCollection.instance_variable_set("@interfaces", @interfaces)
+  end
+
   describe "#interface" do
     it "should register the interface" do
-      interface = Puppet::Interface.interface(:interface_test_register)
-      interface.should == Puppet::Interface.interface(:interface_test_register)
+      interface = Puppet::Interface.interface(:interface_test_register, 1)
+      interface.should == Puppet::Interface.interface(:interface_test_register, 1)
     end
 
     it "should load actions" do
       Puppet::Interface.any_instance.expects(:load_actions)
-      Puppet::Interface.interface(:interface_test_load_actions)
+      Puppet::Interface.interface(:interface_test_load_actions, 1)
+    end
+
+    it "should require a version number" do
+      proc { Puppet::Interface.interface(:no_version) }.should raise_error(ArgumentError)
+    end
+  end
+
+  describe "#initialize" do
+    it "should require a version number" do
+      proc { Puppet::Interface.new(:no_version) }.should raise_error(/declared without version/)
     end
 
     it "should instance-eval any provided block" do
-      face = Puppet::Interface.new(:interface_test_block) do
+      face = Puppet::Interface.new(:interface_test_block, :version => 1) do
         action(:something) do
           invoke { "foo" }
         end
@@ -27,21 +48,21 @@ describe Puppet::Interface do
   end
 
   it "should have a name" do
-    Puppet::Interface.new(:me).name.should == :me
+    Puppet::Interface.new(:me, :version => 1).name.should == :me
   end
 
   it "should stringify with its own name" do
-    Puppet::Interface.new(:me).to_s.should =~ /\bme\b/
+    Puppet::Interface.new(:me, :version => 1).to_s.should =~ /\bme\b/
   end
 
   it "should allow overriding of the default format" do
-    face = Puppet::Interface.new(:me)
+    face = Puppet::Interface.new(:me, :version => 1)
     face.set_default_format :foo
     face.default_format.should == :foo
   end
 
   it "should default to :pson for its format" do
-    Puppet::Interface.new(:me).default_format.should == :pson
+    Puppet::Interface.new(:me, :version => 1).default_format.should == :pson
   end
 
   # Why?
@@ -50,12 +71,12 @@ describe Puppet::Interface do
   end
 
   it "should set any provided options" do
-    Puppet::Interface.new(:me, :verb => "foo").verb.should == "foo"
+    Puppet::Interface.new(:me, :version => 1, :verb => "foo").verb.should == "foo"
   end
 
   it "should try to require interfaces that are not known" do
-    Puppet::Interface::InterfaceCollection.expects(:require).with "puppet/interface/foo"
-    Puppet::Interface.interface(:foo)
+    Puppet::Interface::InterfaceCollection.expects(:require).with "puppet/interface/v1/foo"
+    Puppet::Interface.interface(:foo, 1)
   end
 
   it "should be able to load all actions in all search paths"

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list