Skip to content

Commit

Permalink
Fixed #997 -- virtual defined types are no longer evaluated.
Browse files Browse the repository at this point in the history
NOTE: This introduces a behaviour change, in that you previously
could realize a resource within a virtual defined resource, and now
you must realize the entire defined resource, rather than just
the contained resource.
  • Loading branch information
lak committed Feb 12, 2008
1 parent 9b66251 commit 7e45553
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Fixed #997 -- virtual defined types are no longer evaluated.
NOTE: This introduces a behaviour change, in that you previously
could realize a resource within a virtual defined resource, and now
you must realize the entire defined resource, rather than just
the contained resource.

Fixed #1030 - class and definition evaluation has been significantly
refactored, fixing this problem and making the whole interplay
between the classes, definitions, and nodes, and the Compile class much
Expand Down
17 changes: 13 additions & 4 deletions spec/unit/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def compile_stub(*except)
end

it "should evaluate unevaluated resources" do
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false, :virtual? => false
@compiler.add_resource(@scope, resource)

# We have to now mark the resource as evaluated
Expand All @@ -179,18 +179,18 @@ def compile_stub(*except)
end

it "should not evaluate already-evaluated resources" do
resource = stub 'already_evaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => true
resource = stub 'already_evaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => true, :virtual? => false
@compiler.add_resource(@scope, resource)
resource.expects(:evaluate).never

@compiler.compile
end

it "should evaluate unevaluated resources created by evaluating other resources" do
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false, :virtual? => false
@compiler.add_resource(@scope, resource)

resource2 = stub 'created', :ref => "File[other]", :builtin? => false, :evaluated? => false
resource2 = stub 'created', :ref => "File[other]", :builtin? => false, :evaluated? => false, :virtual? => false

# We have to now mark the resource as evaluated
resource.expects(:evaluate).with { |*whatever| resource.stubs(:evaluated?).returns(true); @compiler.add_resource(@scope, resource2) }
Expand Down Expand Up @@ -244,6 +244,15 @@ def compile_stub(*except)
@compiler.add_resource(@scope, resource)
@compiler.findresource("Yay", "foo").should equal(resource)
end

it "should not evaluate virtual defined resources" do
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false, :virtual? => true
@compiler.add_resource(@scope, resource)

resource.expects(:evaluate).never

@compiler.compile
end
end

describe Puppet::Parser::Compiler, " when evaluating collections" do
Expand Down
20 changes: 20 additions & 0 deletions test/data/snippets/collection_within_virtual_definitions.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
define test($name) {
file {"/tmp/collection_within_virtual_definitions1_$name.txt":
content => "File name $name\n"
}
Test2 <||>
}

define test2() {
file {"/tmp/collection_within_virtual_definitions2_$name.txt":
content => "This is a test\n"
}
}

node default {
@test {"foo":
name => "foo"
}
@test2 {"foo2": }
Test <||>
}
13 changes: 0 additions & 13 deletions test/data/snippets/realize_defined_types.pp

This file was deleted.

34 changes: 9 additions & 25 deletions test/language/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,9 @@ def test_truth
"undef considered true")
end

if defined? ActiveRecord
# Verify that we recursively mark as exported the results of collectable
# components.
def test_exportedcomponents
def test_virtual_definitions_do_not_get_evaluated
config = mkcompiler
parser = config.parser

Expand All @@ -348,35 +347,19 @@ def test_exportedcomponents
:children => [nameobj("arg")]
)

# Create a top-level component
# Create a top-level define
parser.newdefine "one", :arguments => [%w{arg}],
:code => AST::ASTArray.new(
:children => [
resourcedef("file", "/tmp", {"owner" => varref("arg")})
]
)

# And a component that calls it
parser.newdefine "two", :arguments => [%w{arg}],
:code => AST::ASTArray.new(
:children => [
resourcedef("one", "ptest", {"arg" => varref("arg")})
]
)

# And then a third component that calls the second
parser.newdefine "three", :arguments => [%w{arg}],
:code => AST::ASTArray.new(
:children => [
resourcedef("two", "yay", {"arg" => varref("arg")})
]
)

# lastly, create an object that calls our third component
obj = resourcedef("three", "boo", {"arg" => "parentfoo"})
# create a resource that calls our third define
obj = resourcedef("one", "boo", {"arg" => "parentfoo"})

# And mark it as exported
obj.exported = true
# And mark it as virtual
obj.virtual = true

# And then evaluate it
obj.evaluate config.topscope
Expand All @@ -385,12 +368,13 @@ def test_exportedcomponents
config.send(:evaluate_generators)

%w{File}.each do |type|
objects = config.resources.find_all { |r| r.type == type and r.exported }
objects = config.resources.find_all { |r| r.type == type and r.virtual }

assert(!objects.empty?, "Did not get an exported %s" % type)
assert(objects.empty?, "Virtual define got evaluated")
end
end

if defined? ActiveRecord
# Verify that we can both store and collect an object in the same
# run, whether it's in the same scope as a collection or a different
# scope.
Expand Down
5 changes: 5 additions & 0 deletions test/language/snippets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ def snippet_realize_defined_types
assert_file("/tmp/realize_defined_test2")
end

def snippet_collection_within_virtual_definitions
assert_file("/tmp/collection_within_virtual_definitions1_foo.txt")
assert_file("/tmp/collection_within_virtual_definitions2_foo2.txt")
end

def snippet_fqparents
assert_file("/tmp/fqparent1", "Did not make file from parent class")
assert_file("/tmp/fqparent2", "Did not make file from subclass")
Expand Down

0 comments on commit 7e45553

Please sign in to comment.