diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-07-28 14:54:23 -0700 |
|---|---|---|
| committer | Jesse Wolfe <jes5199@gmail.com> | 2010-07-30 14:28:31 -0700 |
| commit | 6dbd4771265173a9d4c3e7756c35c9ca371ca394 (patch) | |
| tree | 835faf9ed49da69b9d2059ed1ebba8cde485d21d /spec | |
| parent | 871e6fd58223cad241bcc14f165b3ab1e6e257e6 (diff) | |
| download | puppet-6dbd4771265173a9d4c3e7756c35c9ca371ca394.tar.gz puppet-6dbd4771265173a9d4c3e7756c35c9ca371ca394.tar.xz puppet-6dbd4771265173a9d4c3e7756c35c9ca371ca394.zip | |
[#4397]+[#4344] Move type-name resolution out of Puppet::Resource into the AST resources.
Move type-name resolution out of Puppet::Resource into the AST resources.
Move find_resource_type out of Puppet::Resource into Scope
Thus, never pass unqualified type names to Puppet::Resource objects.
Thus, Puppet::Resource objects don't need the namespace property,
and Puppet::Resource objects never consult the harddrive to look for
.pp files that might contain their type definitions,
Thus, performance is improved.
Also removes the temporary fix for #4257 that caused #4397
(The code was too eager to look for a class in the topscope)
Paired-With: Paul Berry <paul@puppetlabs.com>
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/integration/parser/compiler_spec.rb | 43 | ||||
| -rwxr-xr-x | spec/unit/parser/ast/resource_reference_spec.rb | 5 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/require_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/tag_spec.rb | 1 | ||||
| -rwxr-xr-x | spec/unit/parser/resource_spec.rb | 12 | ||||
| -rwxr-xr-x | spec/unit/rails/resource_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/resource/catalog_spec.rb | 2 | ||||
| -rw-r--r-- | spec/unit/resource/type_collection_spec.rb | 27 | ||||
| -rwxr-xr-x | spec/unit/resource/type_spec.rb | 3 | ||||
| -rwxr-xr-x | spec/unit/resource_spec.rb | 36 | ||||
| -rwxr-xr-x | spec/unit/type/schedule_spec.rb | 2 |
11 files changed, 80 insertions, 55 deletions
diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb index 83bbf9500..9158ad1c2 100755 --- a/spec/integration/parser/compiler_spec.rb +++ b/spec/integration/parser/compiler_spec.rb @@ -26,4 +26,47 @@ describe Puppet::Parser::Compiler do @compiler.catalog.version.should == version end + + describe "when resolving class references" do + it "should favor local scope, even if there's an included class in topscope" do + Puppet[:code] = <<-PP + class experiment { + class baz { + } + notify {"x" : require => Class[Baz] } + } + class baz { + } + include baz + include experiment + include experiment::baz + PP + + catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) + + notify_resource = catalog.resource( "Notify[x]" ) + + notify_resource[:require].title.should == "Experiment::Baz" + end + + it "should favor local scope, even if there's an unincluded class in topscope" do + Puppet[:code] = <<-PP + class experiment { + class baz { + } + notify {"x" : require => Class[Baz] } + } + class baz { + } + include experiment + include experiment::baz + PP + + catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) + + notify_resource = catalog.resource( "Notify[x]" ) + + notify_resource[:require].title.should == "Experiment::Baz" + end + end end diff --git a/spec/unit/parser/ast/resource_reference_spec.rb b/spec/unit/parser/ast/resource_reference_spec.rb index 7b48119f4..93419d963 100755 --- a/spec/unit/parser/ast/resource_reference_spec.rb +++ b/spec/unit/parser/ast/resource_reference_spec.rb @@ -32,11 +32,6 @@ describe Puppet::Parser::AST::ResourceReference do ] end - it "should pass its scope's namespaces to all created resource references" do - @scope.add_namespace "foo" - newref("File", "/tmp/yay").evaluate(@scope).namespaces.should == ["foo"] - end - it "should return a correct representation when converting to string" do type = stub 'type', :is_a? => true, :to_s => "file" title = stub 'title', :is_a? => true, :to_s => "[/tmp/a, /tmp/b]" diff --git a/spec/unit/parser/functions/require_spec.rb b/spec/unit/parser/functions/require_spec.rb index bd42fa579..49c4bbf74 100755 --- a/spec/unit/parser/functions/require_spec.rb +++ b/spec/unit/parser/functions/require_spec.rb @@ -6,7 +6,7 @@ describe "the require function" do before :each do @catalog = stub 'catalog' - @compiler = stub 'compiler', :catalog => @catalog + @compiler = stub 'compiler', :catalog => @catalog, :environment => nil @scope = Puppet::Parser::Scope.new @scope.stubs(:findresource) diff --git a/spec/unit/parser/functions/tag_spec.rb b/spec/unit/parser/functions/tag_spec.rb index ff37badbb..dac134134 100755 --- a/spec/unit/parser/functions/tag_spec.rb +++ b/spec/unit/parser/functions/tag_spec.rb @@ -6,6 +6,7 @@ describe "the 'tag' function" do before :each do @scope = Puppet::Parser::Scope.new + @scope.stubs(:environment).returns(nil) end it "should exist" do diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb index da49940b0..dae22fcaa 100755 --- a/spec/unit/parser/resource_spec.rb +++ b/spec/unit/parser/resource_spec.rb @@ -58,23 +58,17 @@ describe Puppet::Parser::Resource do end it "should get its environment from its scope" do - scope = stub 'scope', :source => stub("source") - scope.expects(:environment).returns "foo" + scope = stub 'scope', :source => stub("source"), :namespaces => nil + scope.expects(:environment).returns("foo").at_least_once Puppet::Parser::Resource.new("file", "whatever", :scope => scope).environment.should == "foo" end - it "should get its namespaces from its scope" do - scope = stub 'scope', :source => stub("source") - scope.expects(:namespaces).returns %w{one two} - Puppet::Parser::Resource.new("file", "whatever", :scope => scope).namespaces.should == %w{one two} - end - it "should use the resource type collection helper module" do Puppet::Parser::Resource.ancestors.should be_include(Puppet::Resource::TypeCollectionHelper) end it "should use the scope's environment as its environment" do - @scope.expects(:environment).returns "myenv" + @scope.expects(:environment).returns("myenv").at_least_once Puppet::Parser::Resource.new("file", "whatever", :scope => @scope).environment.should == "myenv" end diff --git a/spec/unit/rails/resource_spec.rb b/spec/unit/rails/resource_spec.rb index 08deda65e..73c7f7af4 100755 --- a/spec/unit/rails/resource_spec.rb +++ b/spec/unit/rails/resource_spec.rb @@ -107,7 +107,7 @@ describe "Puppet::Rails::Resource" do describe "#to_resource" do it "should instantiate a Puppet::Parser::Resource" do - scope = stub "scope", :source => nil + scope = stub "scope", :source => nil, :environment => nil, :namespaces => nil @resource = Puppet::Rails::Resource.new @resource.stubs(:attributes).returns({ diff --git a/spec/unit/resource/catalog_spec.rb b/spec/unit/resource/catalog_spec.rb index 10cff91a3..2b6beb5e9 100755 --- a/spec/unit/resource/catalog_spec.rb +++ b/spec/unit/resource/catalog_spec.rb @@ -224,7 +224,7 @@ describe Puppet::Resource::Catalog, "when compiling" do end it "should convert parser resources to plain resources" do - resource = Puppet::Parser::Resource.new(:file, "foo", :scope => stub("scope"), :source => stub("source")) + resource = Puppet::Parser::Resource.new(:file, "foo", :scope => stub("scope", :environment => nil, :namespaces => nil), :source => stub("source")) catalog = Puppet::Resource::Catalog.new("whev") catalog.add_resource(resource) new = catalog.to_resource diff --git a/spec/unit/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb index 45fc05da0..577aea42b 100644 --- a/spec/unit/resource/type_collection_spec.rb +++ b/spec/unit/resource/type_collection_spec.rb @@ -258,6 +258,32 @@ describe Puppet::Resource::TypeCollection do loader.add instance loader.find("foo::bar", "eh", :hostclass).should be_nil end + + describe "when topscope has a class that has the same name as a local class" do + before do + @loader = Puppet::Resource::TypeCollection.new("env") + [ "foo::bar", "bar" ].each do |name| + @loader.add Puppet::Resource::Type.new(:hostclass, name) + end + end + + it "should favor the local class, if the name is unqualified" do + @loader.find("foo", "bar", :hostclass).name.should == 'foo::bar' + end + + it "should only look in the topclass, if the name is qualified" do + @loader.find("foo", "::bar", :hostclass).name.should == 'bar' + end + + end + + it "should not look in the local scope for classes when the name is qualified" do + @loader = Puppet::Resource::TypeCollection.new("env") + @loader.add Puppet::Resource::Type.new(:hostclass, "foo::bar") + + @loader.find("foo", "::bar", :hostclass).should == nil + end + end it "should use the generic 'find' method with an empty namespace to find nodes" do @@ -437,4 +463,5 @@ describe Puppet::Resource::TypeCollection do end end + end diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb index 0ef4a5166..4d3942c5c 100755 --- a/spec/unit/resource/type_spec.rb +++ b/spec/unit/resource/type_spec.rb @@ -369,7 +369,8 @@ describe Puppet::Resource::Type do end it "should cache a reference to the parent type" do - @code.expects(:hostclass).once.with("bar").returns @parent + @code.stubs(:hostclass).with("foo::bar").returns nil + @code.expects(:hostclass).with("bar").once.returns @parent @child.parent_type(@scope) @child.parent_type end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 204a2b02e..e65e8a13a 100755 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -123,18 +123,6 @@ describe Puppet::Resource do Puppet::Resource.new("file", "/my/file", :environment => :foo).environment.name.should == :foo end - it "should support specifying namespaces" do - Puppet::Resource.new("file", "/my/file", :namespaces => ["foo"]).namespaces.should == ["foo"] - end - - it "should convert namespaces to an array if not specified as one" do - Puppet::Resource.new("file", "/my/file", :namespaces => "foo").namespaces.should == ["foo"] - end - - it "should default to a single amespace of an empty string" do - Puppet::Resource.new("file", "/my/file").namespaces.should == [""] - end - describe "and munging its type and title" do describe "when modeling a builtin resource" do it "should be able to find the resource type" do @@ -164,16 +152,6 @@ describe Puppet::Resource do it "should set its title to the provided title" do Puppet::Resource.new("foo::bar", "/my/file").title.should == "/my/file" end - - describe "and the resource is unqualified and models a qualified resource type" do - it "should set its type to the fully qualified resource type" do - Puppet::Resource.new("bar", "/my/file", :namespaces => %w{foo}).type.should == "Foo::Bar" - end - - it "should be able to find the resource type" do - Puppet::Resource.new("bar", "/my/file", :namespaces => %w{foo}).resource_type.should equal(@type) - end - end end describe "that does not exist" do @@ -210,20 +188,6 @@ describe Puppet::Resource do it "should be able to find the resource type" do Puppet::Resource.new("class", "foo::bar").resource_type.should equal(@type) end - - describe "and the resource is unqualified and models a qualified class" do - it "should set its title to the fully qualified resource type" do - Puppet::Resource.new("class", "bar", :namespaces => %w{foo}).title.should == "Foo::Bar" - end - - it "should be able to find the resource type" do - Puppet::Resource.new("class", "bar", :namespaces => %w{foo}).resource_type.should equal(@type) - end - - it "should set its type to 'Class'" do - Puppet::Resource.new("class", "bar", :namespaces => %w{foo}).type.should == "Class" - end - end end describe "that does not exist" do diff --git a/spec/unit/type/schedule_spec.rb b/spec/unit/type/schedule_spec.rb index 6975529b2..420cffd44 100755 --- a/spec/unit/type/schedule_spec.rb +++ b/spec/unit/type/schedule_spec.rb @@ -41,7 +41,7 @@ end describe Puppet::Type.type(:schedule) do before :each do - Puppet.settings.stubs(:value).with(:ignoreschedules).returns(false) + Puppet[:ignoreschedules] = false @schedule = Puppet::Type.type(:schedule).new(:name => "testing") end |
