Please review pull request #772: (#14468) get rid of "metaparam compatibility mode" opened by (cprice-puppet)
Description:
This involves some backward-compatibility hacks targeted at
versions of puppet older than 0.25; These are no longer
needed.
- Opened: Mon May 14 19:13:59 UTC 2012
- Based on: puppetlabs:master (639f995c91289b3be9ca5347865247907c7dcb5c)
- Requested merge: cprice-puppet:feature/master/14468-get-rid-of-metarparam-compat (388e2ec82dbd18dcb4f959ad31fcdcc78d5c5057)
Diff follows:
diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb
index 6428530..ff97bac 100644
--- a/lib/puppet/parser/functions/require.rb
+++ b/lib/puppet/parser/functions/require.rb
@@ -32,26 +32,22 @@ class otherstuff {
method = Puppet::Parser::Functions.function(:include)
send(method, vals)
- if resource.metaparam_compatibility_mode?
- warning "The 'require' function is only compatible with clients at 0.25 and above; including class but not adding dependency"
- else
- vals = [vals] unless vals.is_a?(Array)
-
- vals.each do |klass|
- # lookup the class in the scopes
- if classobj = find_hostclass(klass)
- klass = classobj.name
- else
- raise Puppet::ParseError, "Could not find class #{klass}"
- end
-
- # This is a bit hackish, in some ways, but it's the only way
- # to configure a dependency that will make it to the client.
- # The 'obvious' way is just to add an edge in the catalog,
- # but that is considered a containment edge, not a dependency
- # edge, so it usually gets lost on the client.
- ref = Puppet::Resource.new(:class, klass)
- resource.set_parameter(:require, [resource[:require]].flatten.compact << ref)
+ vals = [vals] unless vals.is_a?(Array)
+
+ vals.each do |klass|
+ # lookup the class in the scopes
+ if classobj = find_hostclass(klass)
+ klass = classobj.name
+ else
+ raise Puppet::ParseError, "Could not find class #{klass}"
end
+
+ # This is a bit hackish, in some ways, but it's the only way
+ # to configure a dependency that will make it to the client.
+ # The 'obvious' way is just to add an edge in the catalog,
+ # but that is considered a containment edge, not a dependency
+ # edge, so it usually gets lost on the client.
+ ref = Puppet::Resource.new(:class, klass)
+ resource.set_parameter(:require, [resource[:require]].flatten.compact << ref)
end
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index ee1a8c4..6edea5e 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -109,7 +109,6 @@ def finish
return if finished?
@finished = true
add_defaults
- add_metaparams
add_scope_tags
validate
end
@@ -150,11 +149,6 @@ def merge(resource)
end
end
- # Unless we're running >= 0.25, we're in compat mode.
- def metaparam_compatibility_mode?
- ! (catalog and ver = (catalog.client_version||'0.0.0').split(".") and (ver[0] > "0" or ver[1].to_i >= 25))
- end
-
def name
self[:name] || self.title
end
@@ -248,29 +242,6 @@ def add_defaults
end
end
- def add_backward_compatible_relationship_param(name)
- # Skip metaparams for which we get no value.
- return unless scope.include?(name.to_s)
- val = scope[name.to_s]
-
- # The default case: just set the value
- set_parameter(name, val) and return unless @parameters[name]
-
- # For relationship params, though, join the values (a la #446).
- @parameters[name].value = [@parameters[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 unless self.class.relationship_parameter?(name)
- add_backward_compatible_relationship_param(name) if compat_mode
- end
- end
-
def add_scope_tags
if scope_resource = scope.resource
tag(*scope_resource.tags)
diff --git a/spec/unit/parser/functions/require_spec.rb b/spec/unit/parser/functions/require_spec.rb
index 692b353..c9c4689 100755
--- a/spec/unit/parser/functions/require_spec.rb
+++ b/spec/unit/parser/functions/require_spec.rb
@@ -17,7 +17,6 @@
@scope.stubs(:find_hostclass).returns(@klass)
@resource = Puppet::Parser::Resource.new(:file, "/my/file", :scope => @scope, :source => "source")
- @resource.stubs(:metaparam_compatibility_mode?).returns false
@scope.stubs(:resource).returns @resource
end
@@ -45,15 +44,6 @@
@scope.function_require("myclass")
end
- it "should include the class but not add a dependency if used on a client not at least version 0.25" do
- @resource.expects(:metaparam_compatibility_mode?).returns true
- @scope.expects(:warning)
- @resource.expects(:set_parameter).never
- @scope.expects(:function_include)
-
- @scope.function_require("myclass")
- end
-
it "should lookup the absolute class path" do
@scope.stubs(:function_include)
diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb
index 59513a1..a4a1d2e 100755
--- a/spec/unit/parser/resource_spec.rb
+++ b/spec/unit/parser/resource_spec.rb
@@ -297,51 +297,6 @@ class { alpha: stage => before }
@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 not copy relationship metaparams when not in metaparam compatibility mode" do
- @scope['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['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['require'] = "bar"
-
- @resource.stubs(:metaparam_compatibility_mode?).returns true
- @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
-
- @resource["require"].should == ["foo", "bar"]
- end
end
describe "when being tagged" do
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
