Skip to content

(#14985) Enable calling_class and calling_module for defined types#1497

Merged
zaphod42 merged 12 commits intopuppetlabs:masterfrom
zaphod42:issue/master/16688-hiera-extra-vars
Apr 5, 2013
Merged

(#14985) Enable calling_class and calling_module for defined types#1497
zaphod42 merged 12 commits intopuppetlabs:masterfrom
zaphod42:issue/master/16688-hiera-extra-vars

Conversation

@zaphod42
Copy link
Contributor

This enables calling_class and calling_module for defined resource types. The
code had been disconnected when puppet started using [] on
Puppet::Parser::Scope, and has been re-enabled. In addition it now uses the
mechanism for finding the calling module by using similar information as used
by the scope for the $caller_module_name variable (introduced in commit
50a626d).

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.

nukemberg and others added 10 commits February 25, 2013 15:16
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.
@puppetcla
Copy link

CLA Signed by zaphod42 on 2012-06-10 21:00:00 -0700

@zaphod42
Copy link
Contributor Author

@avishai-ish-shalom After fixing this up a little, I still don't understand the change from resource to source. Could you explain why that is needed?

@nukemberg
Copy link
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.

@djmitche
Copy link
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.

@nukemberg
Copy link
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
@zaphod42 zaphod42 merged commit 44e79d0 into puppetlabs:master Apr 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants