Example code: Testing relationships to base classes
I think I promised a while ago to start posting the example code I use for tests.
Here's the code I used to reproduce #1030:
class base {
notify { "This is the base class": }
}
class sub inherits base {
notify { "This is the sub class": }
}
include sub
notify { "This is the main class": require => Class[base] }
Sure enough, I get this exception:
luke@phage(0) $ test.pp Could not find dependency Class[base] for Notify[This is the main class] at /Users/luke/bin/test.pp:41 luke@phage(1) $
Turns out the problem is in lib/puppet/parser/compile.rb; or rather, the problem is that the code is in this file, instead of in lib/puppet/parser/ast/hostclass.rb. The Compile class creates a resource for every class it evaluates, which is how these relationships work, but it's that AST class that actually knows when base classes are evaluated by a subclass, so it needs to be creating these resources.
Thu, 07 Feb 2008 | Tags: puppet, example, code