Skip to content

Commit

Permalink
(PUP-2302) Fix issue with Resource Defaults for qualified names
Browse files Browse the repository at this point in the history
When defaults were set using future evaluator and the resource has
a qualified name, the registration of the default was not recognized
because scope requires every segment of a qualified name to be upper
cased.

This adds upper casing of every segment. An integration test checks
that the capitalization works.
  • Loading branch information
hlindberg committed Apr 23, 2014
1 parent d549294 commit 7fb506f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/puppet/pops/evaluator/runtime3_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ def create_resources(o, scope, virtual, exported, type_name, resource_titles, ev
# TODO: Revisit and possible improve the accuracy.
#
file, line = extract_file_line(o)

# Build a resource for each title
resource_titles.map do |resource_title|
resource = Puppet::Parser::Resource.new(
Expand Down Expand Up @@ -312,7 +311,13 @@ def create_resource_defaults(o, scope, type_name, evaluated_parameters)
# for the type of the name.
# Note, locations are available per parameter.
#
scope.define_settings(type_name.capitalize, evaluated_parameters)
scope.define_settings(capitalize_qualified_name(type_name), evaluated_parameters)
end

# Capitalizes each segment of a qualified name
#
def capitalize_qualified_name(name)
name.split(/::/).map(&:capitalize).join('::')
end

# Creates resource overrides for all resource type objects in evaluated_resources. The same set of
Expand Down
15 changes: 15 additions & 0 deletions spec/integration/parser/future_compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ class bar
catalog.resource("Notify[bar_notify]").should_not be_nil
end

it 'applies defaults for defines with qualified names (PUP-2302)' do
Puppet[:code] = <<-CODE
define my::thing($msg = 'foo') { notify {'check_me': message => $msg } }
My::Thing { msg => 'evoe' }
my::thing { 'name': }
CODE

node = Puppet::Node.new("testnodex")
catalog = Puppet::Parser::Compiler.compile(node)
node.classes = nil
the_notify = catalog.resource("Notify[check_me]")
expect(the_notify).to_not be(nil)
expect(the_notify[:message]).to eql('evoe')
end

describe "when resolving class references" do
it "should favor local scope, even if there's an included class in topscope" do
Puppet[:code] = <<-PP
Expand Down

0 comments on commit 7fb506f

Please sign in to comment.