summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-08 15:58:45 -0600
committerLuke Kanies <luke@madstop.com>2007-11-08 15:58:45 -0600
commitba19989c6eab23f3897da20ed8a505ede9198d8b (patch)
tree4175bcb957d0aa74450624b81dd4d27aaad072cb
parentcf75168dc2f95a530dffb7971733a0db2ef70ba2 (diff)
downloadpuppet-ba19989c6eab23f3897da20ed8a505ede9198d8b.tar.gz
puppet-ba19989c6eab23f3897da20ed8a505ede9198d8b.tar.xz
puppet-ba19989c6eab23f3897da20ed8a505ede9198d8b.zip
Switching the class resource evaluation to only happen
when using :include, not (for example) when evaluating node classes.
-rw-r--r--lib/puppet/parser/compile.rb11
-rw-r--r--lib/puppet/parser/functions.rb4
-rwxr-xr-xspec/unit/parser/compile.rb18
-rwxr-xr-xtest/language/functions.rb2
4 files changed, 23 insertions, 12 deletions
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb
index 1b58eca42..f23b42a35 100644
--- a/lib/puppet/parser/compile.rb
+++ b/lib/puppet/parser/compile.rb
@@ -83,12 +83,12 @@ class Puppet::Parser::Compile
return @configuration
end
- # FIXME There are no tests for this.
+ # LAK:FIXME There are no tests for this.
def delete_collection(coll)
@collections.delete(coll) if @collections.include?(coll)
end
- # FIXME There are no tests for this.
+ # LAK:FIXME There are no tests for this.
def delete_resource(resource)
@resource_table.delete(resource.ref) if @resource_table.include?(resource.ref)
end
@@ -114,7 +114,7 @@ class Puppet::Parser::Compile
# find, just tag the configuration and move on. This method really just
# creates resource objects that point back to the classes, and then the
# resources are themselves evaluated later in the process.
- def evaluate_classes(classes, scope)
+ def evaluate_classes(classes, scope, lazy_evaluate = true)
unless scope.source
raise Puppet::DevError, "No source for scope passed to evaluate_classes"
end
@@ -126,7 +126,10 @@ class Puppet::Parser::Compile
# of resources.
resource = Puppet::Parser::Resource.new(:type => "class", :title => klass.classname, :scope => scope, :source => scope.source)
store_resource(scope, resource)
- resource.evaluate
+
+ # If they've disabled lazy evaluation (which the :include function does),
+ # then evaluate our resource immediately.
+ resource.evaluate unless lazy_evaluate
@configuration.tag(klass.classname)
found << name
else
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index 1d07122d4..a0e8da86f 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -109,7 +109,9 @@ module Functions
# Include the specified classes
newfunction(:include, :doc => "Evaluate one or more classes.") do |vals|
vals = [vals] unless vals.is_a?(Array)
- klasses = compile.evaluate_classes(vals, self)
+
+ # The 'false' disables lazy evaluation.
+ klasses = compile.evaluate_classes(vals, self, false)
missing = vals.find_all do |klass|
! klasses.include?(klass)
diff --git a/spec/unit/parser/compile.rb b/spec/unit/parser/compile.rb
index c7a367957..93c440417 100755
--- a/spec/unit/parser/compile.rb
+++ b/spec/unit/parser/compile.rb
@@ -88,7 +88,6 @@ describe Puppet::Parser::Compile, " when evaluating found classes" do
@compile.configuration.stubs(:tag)
@compile.stubs :store_resource
- @resource.stubs(:evaluate)
Puppet::Parser::Resource.expects(:new).with(:scope => @scope, :source => @scope.source, :title => "my::class", :type => "class").returns(@resource)
@compile.evaluate_classes(%w{myclass}, @scope)
@@ -98,7 +97,6 @@ describe Puppet::Parser::Compile, " when evaluating found classes" do
@compile.configuration.stubs(:tag)
@compile.expects(:store_resource).with(@scope, @resource)
- @resource.stubs(:evaluate)
Puppet::Parser::Resource.stubs(:new).returns(@resource)
@compile.evaluate_classes(%w{myclass}, @scope)
@@ -108,27 +106,35 @@ describe Puppet::Parser::Compile, " when evaluating found classes" do
@compile.configuration.expects(:tag).with("my::class")
@compile.stubs(:store_resource)
- @resource.stubs(:evaluate)
Puppet::Parser::Resource.stubs(:new).returns(@resource)
@compile.evaluate_classes(%w{myclass}, @scope)
end
- it "should immediately evaluate the resources created for found classes" do
+ it "should not evaluate the resources created for found classes unless asked" do
@compile.configuration.stubs(:tag)
@compile.stubs(:store_resource)
- @resource.expects(:evaluate)
+ @resource.expects(:evaluate).never
Puppet::Parser::Resource.stubs(:new).returns(@resource)
@compile.evaluate_classes(%w{myclass}, @scope)
end
- it "should return the list of found classes" do
+ it "should immediately evaluate the resources created for found classes when asked" do
@compile.configuration.stubs(:tag)
@compile.stubs(:store_resource)
@resource.expects(:evaluate)
+
+ Puppet::Parser::Resource.stubs(:new).returns(@resource)
+ @compile.evaluate_classes(%w{myclass}, @scope, false)
+ end
+
+ it "should return the list of found classes" do
+ @compile.configuration.stubs(:tag)
+
+ @compile.stubs(:store_resource)
@scope.stubs(:findclass).with("notfound").returns(nil)
Puppet::Parser::Resource.stubs(:new).returns(@resource)
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 3a7779d3d..2fc36f6cd 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -427,7 +427,7 @@ class TestLangFunctions < Test::Unit::TestCase
parser.newclass("myclass")
- scope.compile.expects(:evaluate_classes).with(%w{myclass otherclass}, scope).returns(%w{myclass otherclass})
+ scope.compile.expects(:evaluate_classes).with(%w{myclass otherclass}, scope, false).returns(%w{myclass otherclass})
assert_nothing_raised do
scope.function_include(["myclass", "otherclass"])