summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-11 17:33:12 -0600
committerLuke Kanies <luke@madstop.com>2008-02-11 17:33:12 -0600
commite247b56d9941b4a636d3a3d9935d6b9cd9b199ea (patch)
tree97bf0cff97633125ed2fd76b14b8555723b296f3
parent6a4cf6c978e8c8aebba4ed0f16d3de7bb31a0ce0 (diff)
downloadpuppet-e247b56d9941b4a636d3a3d9935d6b9cd9b199ea.tar.gz
puppet-e247b56d9941b4a636d3a3d9935d6b9cd9b199ea.tar.xz
puppet-e247b56d9941b4a636d3a3d9935d6b9cd9b199ea.zip
Changing some methods in the Compile class to
be more internally consistent (switched store_resource to add_resource, and store_override to add_override).
-rw-r--r--lib/puppet/parser/ast/definition.rb2
-rw-r--r--lib/puppet/parser/ast/resource.rb2
-rw-r--r--lib/puppet/parser/ast/resource_override.rb2
-rw-r--r--lib/puppet/parser/collector.rb2
-rw-r--r--lib/puppet/parser/compile.rb46
-rwxr-xr-xspec/unit/parser/collector.rb10
-rwxr-xr-xspec/unit/parser/compile.rb40
-rwxr-xr-xtest/language/ast.rb2
-rwxr-xr-xtest/language/functions.rb4
9 files changed, 55 insertions, 55 deletions
diff --git a/lib/puppet/parser/ast/definition.rb b/lib/puppet/parser/ast/definition.rb
index e3f6414c3..992bb1f5e 100644
--- a/lib/puppet/parser/ast/definition.rb
+++ b/lib/puppet/parser/ast/definition.rb
@@ -31,7 +31,7 @@ class Puppet::Parser::AST::Definition < Puppet::Parser::AST::Branch
scope.catalog.tag(*resource.tags)
- scope.compile.store_resource(scope, resource)
+ scope.compile.add_resource(scope, resource)
return resource
end
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 606beb537..2dadf9ed6 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -51,7 +51,7 @@ class Resource < AST::ResourceReference
# And then store the resource in the compile.
# At some point, we need to switch all of this to return
# objects instead of storing them like this.
- scope.compile.store_resource(scope, obj)
+ scope.compile.add_resource(scope, obj)
obj
end
}.reject { |obj| obj.nil? }
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
index d15f68608..db0986a8e 100644
--- a/lib/puppet/parser/ast/resource_override.rb
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -42,7 +42,7 @@ class Puppet::Parser::AST
# Now we tell the scope that it's an override, and it behaves as
# necessary.
- scope.compile.store_override(obj)
+ scope.compile.add_override(obj)
obj
end
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index b8165a84f..efd64a320 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -150,7 +150,7 @@ class Puppet::Parser::Collector
resource.exported = false
- scope.compile.store_resource(scope, resource)
+ scope.compile.add_resource(scope, resource)
return resource
end
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb
index bceead271..f68796843 100644
--- a/lib/puppet/parser/compile.rb
+++ b/lib/puppet/parser/compile.rb
@@ -17,6 +17,28 @@ class Puppet::Parser::Compile
@collections << coll
end
+ # Store a resource override.
+ def add_override(override)
+ # If possible, merge the override in immediately.
+ if resource = @catalog.resource(override.ref)
+ resource.merge(override)
+ else
+ # Otherwise, store the override for later; these
+ # get evaluated in Resource#finish.
+ @resource_overrides[override.ref] << override
+ end
+ end
+
+ # Store a resource in our resource table.
+ def add_resource(scope, resource)
+ @catalog.add_resource(resource)
+
+ # And in the resource graph. At some point, this might supercede
+ # the global resource table, but the table is a lot faster
+ # so it makes sense to maintain for now.
+ @catalog.add_edge!(scope.resource, resource)
+ end
+
# Do we use nodes found in the code, vs. the external node sources?
def ast_nodes?
parser.nodes.length > 0
@@ -186,28 +208,6 @@ class Puppet::Parser::Compile
@catalog.vertices
end
- # Store a resource override.
- def store_override(override)
- # If possible, merge the override in immediately.
- if resource = @catalog.resource(override.ref)
- resource.merge(override)
- else
- # Otherwise, store the override for later; these
- # get evaluated in Resource#finish.
- @resource_overrides[override.ref] << override
- end
- end
-
- # Store a resource in our resource table.
- def store_resource(scope, resource)
- @catalog.add_resource(resource)
-
- # And in the resource graph. At some point, this might supercede
- # the global resource table, but the table is a lot faster
- # so it makes sense to maintain for now.
- @catalog.add_edge!(scope.resource, resource)
- end
-
# The top scope is usually the top-level scope, but if we're using AST nodes,
# then it is instead the node's scope.
def topscope
@@ -233,7 +233,7 @@ class Puppet::Parser::Compile
# Create a resource to model this node, and then add it to the list
# of resources.
resource = Puppet::Parser::Resource.new(:type => "node", :title => astnode.classname, :scope => topscope, :source => topscope.source)
- store_resource(topscope, resource)
+ add_resource(topscope, resource)
@catalog.tag(astnode.classname)
resource.evaluate
diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb
index 9b5eab1f4..aedbe1b9a 100755
--- a/spec/unit/parser/collector.rb
+++ b/spec/unit/parser/collector.rb
@@ -271,7 +271,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@compile.stubs(:resources).returns([])
@scope.stubs(:findresource).returns(nil)
- @compile.stubs(:store_resource)
+ @compile.stubs(:add_resource)
@collector.evaluate.should == [resource]
end
@@ -291,7 +291,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@compile.stubs(:resources).returns([])
@scope.stubs(:findresource).returns(nil)
- @compile.expects(:store_resource).with(@scope, resource)
+ @compile.expects(:add_resource).with(@scope, resource)
@collector.evaluate.should == [resource]
end
@@ -312,7 +312,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@compile.stubs(:resources).returns([])
@scope.stubs(:findresource).returns(nil)
- @compile.stubs(:store_resource)
+ @compile.stubs(:add_resource)
@collector.evaluate
end
@@ -331,7 +331,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@compile.stubs(:resources).returns([])
@scope.stubs(:findresource).returns(inmemory)
- @compile.stubs(:store_resource)
+ @compile.stubs(:add_resource)
proc { @collector.evaluate }.should raise_error(Puppet::ParseError)
end
@@ -350,7 +350,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@compile.stubs(:resources).returns([])
@scope.stubs(:findresource).returns(inmemory)
- @compile.stubs(:store_resource)
+ @compile.stubs(:add_resource)
proc { @collector.evaluate }.should_not raise_error(Puppet::ParseError)
end
diff --git a/spec/unit/parser/compile.rb b/spec/unit/parser/compile.rb
index ff205f7a5..65e7befca 100755
--- a/spec/unit/parser/compile.rb
+++ b/spec/unit/parser/compile.rb
@@ -162,7 +162,7 @@ describe Puppet::Parser::Compile, " when compiling" do
it "should ignore builtin resources" do
resource = stub 'builtin', :ref => "File[testing]", :builtin? => true
- @compile.store_resource(@scope, resource)
+ @compile.add_resource(@scope, resource)
resource.expects(:evaluate).never
@compile.compile
@@ -170,7 +170,7 @@ describe Puppet::Parser::Compile, " when compiling" do
it "should evaluate unevaluated resources" do
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false
- @compile.store_resource(@scope, resource)
+ @compile.add_resource(@scope, resource)
# We have to now mark the resource as evaluated
resource.expects(:evaluate).with { |*whatever| resource.stubs(:evaluated?).returns true }
@@ -180,7 +180,7 @@ describe Puppet::Parser::Compile, " when compiling" do
it "should not evaluate already-evaluated resources" do
resource = stub 'already_evaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => true
- @compile.store_resource(@scope, resource)
+ @compile.add_resource(@scope, resource)
resource.expects(:evaluate).never
@compile.compile
@@ -188,12 +188,12 @@ describe Puppet::Parser::Compile, " when compiling" do
it "should evaluate unevaluated resources created by evaluating other resources" do
resource = stub 'notevaluated', :ref => "File[testing]", :builtin? => false, :evaluated? => false
- @compile.store_resource(@scope, resource)
+ @compile.add_resource(@scope, resource)
resource2 = stub 'created', :ref => "File[other]", :builtin? => false, :evaluated? => false
# We have to now mark the resource as evaluated
- resource.expects(:evaluate).with { |*whatever| resource.stubs(:evaluated?).returns(true); @compile.store_resource(@scope, resource2) }
+ resource.expects(:evaluate).with { |*whatever| resource.stubs(:evaluated?).returns(true); @compile.add_resource(@scope, resource2) }
resource2.expects(:evaluate).with { |*whatever| resource2.stubs(:evaluated?).returns(true) }
@@ -205,19 +205,19 @@ describe Puppet::Parser::Compile, " when compiling" do
resource = Puppet::Parser::Resource.new :scope => @scope, :type => "file", :title => "finish"
resource.expects(:finish)
- @compile.store_resource(@scope, resource)
+ @compile.add_resource(@scope, resource)
# And one that does not
dnf = stub "dnf", :ref => "File[dnf]"
- @compile.store_resource(@scope, dnf)
+ @compile.add_resource(@scope, dnf)
@compile.send(:finish)
end
it "should add resources that do not conflict with existing resources" do
resource = stub "noconflict", :ref => "File[yay]"
- @compile.store_resource(@scope, resource)
+ @compile.add_resource(@scope, resource)
@compile.catalog.should be_vertex(resource)
end
@@ -229,19 +229,19 @@ describe Puppet::Parser::Compile, " when compiling" do
resource1 = stub "iso1conflict", :ref => "Mytype[yay]", :type => "mytype", :file => "eh", :line => 0
resource2 = stub "iso2conflict", :ref => "Mytype[yay]", :type => "mytype", :file => "eh", :line => 0
- @compile.store_resource(@scope, resource1)
- lambda { @compile.store_resource(@scope, resource2) }.should raise_error(ArgumentError)
+ @compile.add_resource(@scope, resource1)
+ lambda { @compile.add_resource(@scope, resource2) }.should raise_error(ArgumentError)
end
it "should have a method for looking up resources" do
resource = stub 'resource', :ref => "Yay[foo]"
- @compile.store_resource(@scope, resource)
+ @compile.add_resource(@scope, resource)
@compile.findresource("Yay[foo]").should equal(resource)
end
it "should be able to look resources up by type and title" do
resource = stub 'resource', :ref => "Yay[foo]"
- @compile.store_resource(@scope, resource)
+ @compile.add_resource(@scope, resource)
@compile.findresource("Yay", "foo").should equal(resource)
end
end
@@ -349,7 +349,7 @@ describe Puppet::Parser::Compile, " when evaluating found classes" do
@compile.expects(:class_scope).with(@class).returns("something")
- @compile.expects(:store_resource).never
+ @compile.expects(:add_resource).never
@resource.expects(:evaluate).never
@@ -360,7 +360,7 @@ describe Puppet::Parser::Compile, " when evaluating found classes" do
it "should return the list of found classes" do
@compile.catalog.stubs(:tag)
- @compile.stubs(:store_resource)
+ @compile.stubs(:add_resource)
@scope.stubs(:findclass).with("notfound").returns(nil)
Puppet::Parser::Resource.stubs(:new).returns(@resource)
@@ -493,14 +493,14 @@ describe Puppet::Parser::Compile, "when managing resource overrides" do
end
it "should be able to store overrides" do
- lambda { @compile.store_override(@override) }.should_not raise_error
+ lambda { @compile.add_override(@override) }.should_not raise_error
end
it "should apply overrides to the appropriate resources" do
- @compile.store_resource(@scope, @resource)
+ @compile.add_resource(@scope, @resource)
@resource.expects(:merge).with(@override)
- @compile.store_override(@override)
+ @compile.add_override(@override)
@compile.compile
end
@@ -509,17 +509,17 @@ describe Puppet::Parser::Compile, "when managing resource overrides" do
@resource.expects(:merge).with(@override)
# First store the override
- @compile.store_override(@override)
+ @compile.add_override(@override)
# Then the resource
- @compile.store_resource(@scope, @resource)
+ @compile.add_resource(@scope, @resource)
# And compile, so they get resolved
@compile.compile
end
it "should fail if the compile is finished and resource overrides have not been applied" do
- @compile.store_override(@override)
+ @compile.add_override(@override)
lambda { @compile.compile }.should raise_error(Puppet::ParseError)
end
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 9b1c1c1dc..9b8c74cfb 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -57,7 +57,7 @@ class TestAST < Test::Unit::TestCase
end
Puppet::Parser::Resource.expects(:new).with { |o| o.is_a?(Hash) }.returns(:override)
- scope.compile.expects(:store_override).with(:override)
+ scope.compile.expects(:add_override).with(:override)
ret = nil
assert_nothing_raised do
ret = ref.evaluate scope
diff --git a/test/language/functions.rb b/test/language/functions.rb
index edb39e9a7..b8f7d4313 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -318,7 +318,7 @@ class TestLangFunctions < Test::Unit::TestCase
virtual = mkresource(:type => type, :title => title,
:virtual => true, :params => {}, :scope => scope)
- scope.compile.store_resource(scope, virtual)
+ scope.compile.add_resource(scope, virtual)
ref = Puppet::Parser::Resource::Reference.new(
:type => type, :title => title,
@@ -385,7 +385,7 @@ class TestLangFunctions < Test::Unit::TestCase
"Multiple falses were somehow true")
# Now make sure we can test resources
- scope.compile.store_resource(scope, mkresource(:type => "file", :title => "/tmp/rahness",
+ scope.compile.add_resource(scope, mkresource(:type => "file", :title => "/tmp/rahness",
:scope => scope, :source => scope.source,
:params => {:owner => "root"}))