[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. puppet-0.24.5-rc3-1456-g2f0b1e5
James Turnbull
james at lovedthanlost.net
Tue Oct 27 17:05:40 UTC 2009
The following commit has been merged in the upstream branch:
commit d42bda1f22e3beca321700a78aab9c1399537c30
Author: Luke Kanies <luke at madstop.com>
Date: Sat Sep 19 21:33:34 2009 -0700
Fixing relationship metaparam backward compatibility
We broke some cases of metaparam compatibility in 0.25.
Most of it was pretty esoteric, but one thing that wasn't working
was relationship metaparams specified on defined resources.
This adds a compatibility method for older clients.
Signed-off-by: Luke Kanies <luke at madstop.com>
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 7218ac0..29b1fb1 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -17,7 +17,7 @@ class Puppet::Parser::Resource
include Puppet::Parser::YamlTrimmer
attr_accessor :source, :scope, :rails_id
- attr_accessor :virtual, :override, :translated
+ attr_accessor :virtual, :override, :translated, :catalog
attr_reader :exported, :evaluated, :params
@@ -304,23 +304,42 @@ class Puppet::Parser::Resource
end
end
+ def add_backward_compatible_relationship_param(name)
+ # Skip metaparams for which we get no value.
+ return unless val = scope.lookupvar(name.to_s, false) and val != :undefined
+
+ # The default case: just set the value
+ set_parameter(name, val) and return unless @params[name]
+
+ # For relationship params, though, join the values (a la #446).
+ @params[name].value = [@params[name].value, val].flatten
+ end
+
# Add any metaparams defined in our scope. This actually adds any metaparams
# from any parent scope, and there's currently no way to turn that off.
def add_metaparams
+ compat_mode = metaparam_compatibility_mode?
+
Puppet::Type.eachmetaparam do |name|
- next if self.class.relationship_parameter?(name)
- # Skip metaparams that we already have defined, unless they're relationship metaparams.
- # LAK:NOTE Relationship metaparams get treated specially -- we stack them, instead of
- # overriding.
+ if self.class.relationship_parameter?(name)
+ add_backward_compatible_relationship_param(name) if compat_mode
+ next
+ end
+
next if @params[name]
# Skip metaparams for which we get no value.
next unless val = scope.lookupvar(name.to_s, false) and val != :undefined
- set_parameter(name, val) and next unless @params[name]
+ set_parameter(name, val)
end
end
+ # Unless we're running >= 0.25, we're in compat mode.
+ def metaparam_compatibility_mode?
+ ! (catalog and version = catalog.client_version and version = version.split(".") and version[0] == "0" and version[1].to_i >= 25)
+ end
+
def add_scope_tags
if scope_resource = scope.resource
tag(*scope_resource.tags)
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 9eb8b13..0a67c4b 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -170,6 +170,24 @@ describe Puppet::Parser::Resource do
@resource[:owner].should == "other"
end
+ it "should be running in metaparam compatibility mode if running a version below 0.25" do
+ catalog = stub 'catalog', :client_version => "0.24.8"
+ @resource.stubs(:catalog).returns catalog
+ @resource.should be_metaparam_compatibility_mode
+ end
+
+ it "should be running in metaparam compatibility mode if running no client version is available" do
+ catalog = stub 'catalog', :client_version => nil
+ @resource.stubs(:catalog).returns catalog
+ @resource.should be_metaparam_compatibility_mode
+ end
+
+ it "should not be running in metaparam compatibility mode if running a version at or above 0.25" do
+ catalog = stub 'catalog', :client_version => "0.25.0"
+ @resource.stubs(:catalog).returns catalog
+ @resource.should_not be_metaparam_compatibility_mode
+ end
+
it "should copy metaparams from its scope" do
@scope.setvar("noop", "true")
@@ -187,14 +205,34 @@ describe Puppet::Parser::Resource do
@resource["noop"].should == "false"
end
- it "should not copy relationship metaparams" do
+ it "should not copy relationship metaparams when not in metaparam compatibility mode" do
@scope.setvar("require", "bar")
+ @resource.stubs(:metaparam_compatibility_mode?).returns false
@resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
@resource["require"].should be_nil
end
+ it "should copy relationship metaparams when in metaparam compatibility mode" do
+ @scope.setvar("require", "bar")
+
+ @resource.stubs(:metaparam_compatibility_mode?).returns true
+ @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
+
+ @resource["require"].should == "bar"
+ end
+
+ it "should stack relationship metaparams when in metaparam compatibility mode" do
+ @resource.set_parameter("require", "foo")
+ @scope.setvar("require", "bar")
+
+ @resource.stubs(:metaparam_compatibility_mode?).returns true
+ @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
+
+ @resource["require"].should == ["foo", "bar"]
+ end
+
it "should copy all metaparams that it finds" do
@scope.setvar("noop", "foo")
@scope.setvar("schedule", "bar")
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list