[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35
test branch
puppet-dev at googlegroups.com
Wed Jul 14 10:31:35 UTC 2010
The following commit has been merged in the upstream branch:
commit 2c2b3c27e242f7ee99354c7d4f0d2a18d5710f49
Author: Luke Kanies <luke at reductivelabs.com>
Date: Mon Jan 4 16:57:59 2010 -0800
Storing per-environment LoadedCode instances
This will soon replace all of the env/parser mungling
we have to do. A given process will only be able to
have one collection of code per environment in memory.
This is somewhat limiting, in theory, but some global means
of looking up code collection (LoadedCode instances) must
exist for the pure ruby stuff to work.
Signed-off-by: Luke Kanies <luke at reductivelabs.com>
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index df89ed7..77ee28f 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -194,8 +194,8 @@ class Puppet::Parser::Parser
end
def initialize(options = {})
- @loaded_code = options[:loaded_code] || Puppet::Parser::LoadedCode.new
@environment = options[:environment]
+ @loaded_code = options[:loaded_code] || Puppet::Parser::LoadedCode.new(@environment)
initvars()
end
diff --git a/spec/integration/parser/parser.rb b/spec/integration/parser/parser.rb
index 71ae136..cc6591c 100755
--- a/spec/integration/parser/parser.rb
+++ b/spec/integration/parser/parser.rb
@@ -4,8 +4,8 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Parser::Parser do
before :each do
- @loaded_code = Puppet::Parser::LoadedCode.new
- @parser = Puppet::Parser::Parser.new :environment => "development", :loaded_code => @loaded_code
+ @resource_type_collection = Puppet::Parser::ResourceTypeCollection.new("env")
+ @parser = Puppet::Parser::Parser.new :environment => "development", :resource_type_collection => @resource_type_collection
end
describe "when parsing comments before statement" do
diff --git a/spec/unit/parser/loaded_code.rb b/spec/unit/parser/loaded_code.rb
index 9b72dab..3a230f9 100644
--- a/spec/unit/parser/loaded_code.rb
+++ b/spec/unit/parser/loaded_code.rb
@@ -8,22 +8,31 @@ require 'puppet/parser/resource_type'
describe Puppet::Parser::LoadedCode do
before do
@instance = Puppet::Parser::ResourceType.new(:hostclass, "foo")
- @code = Puppet::Parser::LoadedCode.new
+ @code = Puppet::Parser::LoadedCode.new("env")
+ end
+
+ it "should require an environment at initialization" do
+ Puppet::Parser::LoadedCode.new("foo").environment.should == "foo"
+ end
+
+ it "should store itself as the environment-specific code collection in its class" do
+ code = Puppet::Parser::LoadedCode.new("foo")
+ Puppet::Parser::LoadedCode["foo"].should equal(code)
end
it "should be able to add a resource type" do
- Puppet::Parser::LoadedCode.new.should respond_to(:add)
+ Puppet::Parser::LoadedCode.new("env").should respond_to(:add)
end
it "should consider '<<' to be an alias to 'add' but should return self" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.expects(:add).with "foo"
loader.expects(:add).with "bar"
loader << "foo" << "bar"
end
it "should set itself as the code collection for added resource types" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
node = Puppet::Parser::ResourceType.new(:node, "foo")
@@ -56,48 +65,48 @@ describe Puppet::Parser::LoadedCode do
%w{hostclass node definition}.each do |data|
it "should have a method for adding a #{data}" do
- Puppet::Parser::LoadedCode.new.should respond_to("add_" + data)
+ Puppet::Parser::LoadedCode.new("env").should respond_to("add_" + data)
end
it "should use the name of the instance to add it" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.send("add_#{data}", @instance)
loader.send(data, @instance.name).should equal(@instance)
end
it "should fail to add a #{data} when one already exists" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.add @instance
lambda { loader.add(@instance) }.should raise_error(Puppet::ParseError)
end
it "should return the added #{data}" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.add(@instance).should equal(@instance)
end
it "should be able to retrieve #{data} by name" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(data, "bar")
loader.add instance
loader.send(data, "bar").should equal(instance)
end
it "should retrieve #{data} insensitive to case" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(data, "Bar")
loader.add instance
loader.send(data, "bAr").should equal(instance)
end
it "should return nil when asked for a #{data} that has not been added" do
- Puppet::Parser::LoadedCode.new.send(data, "foo").should be_nil
+ Puppet::Parser::LoadedCode.new("env").send(data, "foo").should be_nil
end
it "should be able to retrieve all #{data}s" do
plurals = { "hostclass" => "hostclasses", "node" => "nodes", "definition" => "definitions" }
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(data, "foo")
loader.add instance
loader.send(plurals[data]).should == { "foo" => instance }
@@ -106,54 +115,54 @@ describe Puppet::Parser::LoadedCode do
describe "when finding a qualified instance" do
it "should return any found instance if the instance name is fully qualified" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(:hostclass, "foo::bar")
loader.add instance
loader.find("namespace", "::foo::bar", :hostclass).should equal(instance)
end
it "should return nil if the instance name is fully qualified and no such instance exists" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.find("namespace", "::foo::bar", :hostclass).should be_nil
end
it "should return the partially qualified object if it exists in the provided namespace" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find("foo", "bar::baz", :hostclass).should equal(instance)
end
it "should return the unqualified object if it exists in the provided namespace" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(:hostclass, "foo::bar")
loader.add instance
loader.find("foo", "bar", :hostclass).should equal(instance)
end
it "should return the unqualified object if it exists in the parent namespace" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(:hostclass, "foo::bar")
loader.add instance
loader.find("foo::bar::baz", "bar", :hostclass).should equal(instance)
end
it "should should return the partially qualified object if it exists in the parent namespace" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find("foo::bar", "bar::baz", :hostclass).should equal(instance)
end
it "should return the qualified object if it exists in the root namespace" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find("foo::bar", "foo::bar::baz", :hostclass).should equal(instance)
end
it "should return nil if the object cannot be found" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
instance = Puppet::Parser::ResourceType.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find("foo::bar", "eh", :hostclass).should be_nil
@@ -161,36 +170,36 @@ describe Puppet::Parser::LoadedCode do
end
it "should use the generic 'find' method with an empty namespace to find nodes" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.expects(:find).with("", "bar", :node)
loader.find_node("bar")
end
it "should use the generic 'find' method to find hostclasses" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.expects(:find).with("foo", "bar", :hostclass)
loader.find_hostclass("foo", "bar")
end
it "should use the generic 'find' method to find definitions" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.expects(:find).with("foo", "bar", :definition)
loader.find_definition("foo", "bar")
end
it "should indicate whether any nodes are defined" do
- loader = Puppet::Parser::LoadedCode.new
+ loader = Puppet::Parser::LoadedCode.new("env")
loader.add_node(Puppet::Parser::ResourceType.new(:node, "foo"))
loader.should be_nodes
end
it "should indicate whether no nodes are defined" do
- Puppet::Parser::LoadedCode.new.should_not be_nodes
+ Puppet::Parser::LoadedCode.new("env").should_not be_nodes
end
describe "when finding nodes" do
before :each do
- @loader = Puppet::Parser::LoadedCode.new
+ @loader = Puppet::Parser::LoadedCode.new("env")
end
it "should return any node whose name exactly matches the provided node name" do
diff --git a/spec/unit/parser/resource_type.rb b/spec/unit/parser/resource_type.rb
index 3afab69..08f7e2a 100755
--- a/spec/unit/parser/resource_type.rb
+++ b/spec/unit/parser/resource_type.rb
@@ -275,7 +275,7 @@ describe Puppet::Parser::ResourceType do
describe "when describing and managing parent classes" do
before do
- @code = Puppet::Parser::LoadedCode.new
+ @code = Puppet::Parser::ResourceTypeCollection.new("env")
@parent = Puppet::Parser::ResourceType.new(:hostclass, "bar")
@code.add @parent
@@ -369,7 +369,7 @@ describe Puppet::Parser::ResourceType do
@top = Puppet::Parser::ResourceType.new :hostclass, "top"
@middle = Puppet::Parser::ResourceType.new :hostclass, "middle", :parent => "top"
- @code = Puppet::Parser::LoadedCode.new
+ @code = Puppet::Parser::ResourceTypeCollection.new("env")
@code.add @top
@code.add @middle
end
@@ -460,7 +460,7 @@ describe Puppet::Parser::ResourceType do
end
it "should fail if both classes have different parent classes" do
- code = Puppet::Parser::LoadedCode.new
+ code = Puppet::Parser::ResourceTypeCollection.new("env")
{"a" => "b", "c" => "d"}.each do |parent, child|
code.add Puppet::Parser::ResourceType.new(:hostclass, parent)
code.add Puppet::Parser::ResourceType.new(:hostclass, child, :parent => parent)
diff --git a/spec/unit/util/rdoc/parser.rb b/spec/unit/util/rdoc/parser.rb
index ce776da..c1b55a5 100755
--- a/spec/unit/util/rdoc/parser.rb
+++ b/spec/unit/util/rdoc/parser.rb
@@ -141,8 +141,8 @@ describe RDoc::Parser do
@definition = stub_everything 'definition', :file => "module/manifests/init.pp", :type => :definition, :name => "mydef"
@node = stub_everything 'node', :file => "module/manifests/init.pp", :type => :node, :name => "mynode"
- @loadedcode = Puppet::Parser::LoadedCode.new
- @parser.ast = @loadedcode
+ @resource_type_collection = Puppet::Parser::ResourceTypeCollection.new("env")
+ @parser.ast = @resource_type_collection
@container = stub_everything 'container'
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list