(#14985) Enable calling_class and calling_module for defined types#1497
Merged
zaphod42 merged 12 commits intopuppetlabs:masterfrom Apr 5, 2013
Merged
Conversation
The nested definition of the recurse_for_hostclass method caused that method to be created lazily and as a public method. By pulling it out to be declared outside the calling method it can be made private and created only once. It has also been renamed to show the intention instead of the mechanism (recursion).
When the hiera tests were run alone the puppet_backend_spec.rb issued a warning: /Users/andy/work/puppet/spec/unit/hiera/backend/puppet_backend_spec.rb:25: warning: toplevel constant Config referenced by Hiera::Config The warning was caused by a reference to Hiera::Config where Hiera was defined, but Hiera::Config was not. This resulted in getting the top level Config constant and a warning being issued. By requiring hiera/config this problem is avoided.
Using the real scope is completely possible in these tests since it has no dependencies on the outside world and is essentially a value object. Therefore it should be used in the tests to make them more comprehensive.
The original tests for calling_module and calling_class used a mock, when this is really just a value that can be setup. It also didn't separate out and describe the behavior of the two pieces in the variations in which they can come up. Specifically the difference between a `define` and a `class` for the meaning of calling_class.
The lookup rules for variables in the puppet language have always been a bit hard for me to understand. I knew the rules as the current scope => inherited => node => topscope but the code never seemed to express that clearly. This refactors the `lookupvar` method to extract out a few pieces to make that clearer. Specifically the mechanism for walking from a class to the enclosing node (which is why this gets the name "two-step" by some people) has been called out as a lookup of the `enclosing_scope`. Calling out the enclosing scope as a specific lookup allows for getting rid of the `:origin` part of the options hash, which was to provide a mechanism for skipping over some scope objects. This also tries to remove some duplication that was occurring because there was not a consistent symbol table concept. It turns out that the existing `Ephemeral` fits that nicely and so it now used as the scope's symbol table as well as for the ephemeral variables.
The initial fix for looked up values downcased everything that was being returned. This causes problems when the data is not a string that the previous behavior was to only do this for the calling_class and calling_module. This commit us returns to that behavior.
|
CLA Signed by zaphod42 on 2012-06-10 21:00:00 -0700 |
Contributor
Author
|
@avishai-ish-shalom After fixing this up a little, I still don't understand the change from |
Contributor
|
It's been a while since i've worked on this, but if memory serves me .resource didn't behave consistently between class and resources and there was some issue with defined types. |
Contributor
|
What's the use-case for this? This sounds like a language feature that's going to tie the language in knots down the road. |
Contributor
|
as far as i recall i originally patched hiera with puppet 2.7.x and couldn't make it work with .resource. if this isn't the case then by all means change it. |
The new implementation of calling_module turned out to be the same as puppet's own module_name. This makes it simply and alias so that we keep that as the definition of calling_module.
zaphod42
added a commit
that referenced
this pull request
Apr 5, 2013
…-vars (#14985) Enable calling_class and calling_module for defined types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This enables calling_class and calling_module for defined resource types. The
code had been disconnected when puppet started using
[]onPuppet::Parser::Scope, and has been re-enabled. In addition it now uses themechanism for finding the calling module by using similar information as used
by the scope for the
$caller_module_namevariable (introduced in commit50a626d).
In order to understand how to test this and if it was relying on the correct
information some refactors to the variable lookup code was also done to attempt
to make it easier to understand the rules of lookup as expressed in the code.