Skip to content

Commit

Permalink
(PUP-7484) Ensure that generated resources get defaults assigned
Browse files Browse the repository at this point in the history
The fix in PUP-25, where the assignment of resource parameter default
values was moved to take place before resource generators was evaluated,
resulted in that no defaults were assigned to the generated resources.

This commit ensures that resources created during the evaluation of
generators will get their parameter defaults assigned.
  • Loading branch information
thallgren committed May 1, 2017
1 parent b687cc4 commit 8d61e38
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/puppet/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def add_resource(scope, resource)
end
end

# A resource added as the result of evaluating a definition must have its defaults set
resource.add_defaults if @evaluating_generators
@resources << resource

# Note that this will fail if the resource is not unique.
Expand Down Expand Up @@ -552,22 +554,27 @@ def evaluate_definitions
# be defined resources.
def evaluate_generators
count = 0
loop do
done = true

Puppet::Util::Profiler.profile(_("Iterated (%{count}) on generators") % { count: count + 1 }, [:compiler, :iterate_on_generators]) do
# Call collections first, then definitions.
done = false if evaluate_collections
done = false if evaluate_definitions
end
@evaluating_generators = true
begin
loop do
done = true

Puppet::Util::Profiler.profile(_("Iterated (%{count}) on generators") % { count: count + 1 }, [:compiler, :iterate_on_generators]) do
# Call collections first, then definitions.
done = false if evaluate_collections
done = false if evaluate_definitions
end

break if done
break if done

count += 1
count += 1

if count > 1000
raise Puppet::ParseError, _("Somehow looped more than 1000 times while evaluating host catalog")
if count > 1000
raise Puppet::ParseError, _("Somehow looped more than 1000 times while evaluating host catalog")
end
end
ensure
@evaluating_generators = false
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/parser/environment_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def prune_env_catalog
end

def add_resource(scope, resource)
# A resource added as the result of evaluating a generator (collector or definition) must have its defaults set
resource.add_defaults if @evaluating_generators
@resources << resource
@catalog.add_resource(resource)

Expand Down

0 comments on commit 8d61e38

Please sign in to comment.