summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/agent.rb30
-rw-r--r--lib/puppet/parser/interpreter.rb6
-rw-r--r--lib/puppet/resource/catalog.rb6
-rwxr-xr-xspec/unit/agent.rb74
-rwxr-xr-xspec/unit/parser/interpreter.rb13
5 files changed, 88 insertions, 41 deletions
diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb
index 0046ed317..240005e3f 100644
--- a/lib/puppet/agent.rb
+++ b/lib/puppet/agent.rb
@@ -110,28 +110,36 @@ class Puppet::Agent
result = nil
begin
duration = thinmark do
- result = catalog_class.get(name, :use_cache => false)
+ result = catalog_class.find(name, :use_cache => false)
end
rescue => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not retrieve catalog from remote server: %s" % detail
end
- begin
- duration = thinmark do
- result = catalog_class.get(name, :use_cache => true)
+ unless result
+ begin
+ duration = thinmark do
+ result = catalog_class.find(name, :use_cache => true)
+ end
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not retrieve catalog from cache: %s" % detail
end
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not retrieve catalog from cache: %s" % detail
end
return nil unless result
- result.retrieval_duration = duration
- result.host_config = true
- result.write_class_file
- return result
+ convert_catalog(result, duration)
+ end
+
+ # Convert a plain resource catalog into our full host catalog.
+ def convert_catalog(result, duration)
+ catalog = result.to_ral
+ catalog.retrieval_duration = duration
+ catalog.host_config = true
+ catalog.write_class_file
+ return catalog
end
# The code that actually runs the catalog.
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 423c34a4e..c728b54a2 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -26,10 +26,10 @@ class Puppet::Parser::Interpreter
def compile(node)
raise Puppet::ParseError, "Could not parse configuration; cannot compile on node %s" % node.name unless env_parser = parser(node.environment)
begin
- return Puppet::Parser::Compiler.new(node, env_parser).compile
+ return Puppet::Parser::Compiler.new(node, env_parser).compile.to_resource
rescue => detail
- puts detail.backtrace if Puppet[:trace]
- raise Puppet::Error, detail.to_s + " on node %s" % node.name
+ puts detail.backtrace if Puppet[:trace]
+ raise Puppet::Error, detail.to_s + " on node %s" % node.name
end
end
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 8f013e7db..e1341012c 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -485,7 +485,11 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
resource.catalog = result
end
- newres = resource.send(convert)
+ if resource.is_a?(Puppet::Resource) and convert.to_s == "to_resource"
+ newres = resource
+ else
+ newres = resource.send(convert)
+ end
# We can't guarantee that resources don't munge their names
# (like files do with trailing slashes), so we have to keep track
diff --git a/spec/unit/agent.rb b/spec/unit/agent.rb
index e0ae3689e..0d6ed952e 100755
--- a/spec/unit/agent.rb
+++ b/spec/unit/agent.rb
@@ -123,10 +123,12 @@ describe Puppet::Agent, "when retrieving a catalog" do
@agent = Puppet::Agent.new
@catalog = Puppet::Resource::Catalog.new
+
+ @agent.stubs(:convert_catalog).returns @catalog
end
it "should use the Catalog class to get its catalog" do
- Puppet::Resource::Catalog.expects(:get).returns @catalog
+ Puppet::Resource::Catalog.expects(:find).returns @catalog
@agent.retrieve_catalog
end
@@ -134,68 +136,90 @@ describe Puppet::Agent, "when retrieving a catalog" do
it "should use its Facter name to retrieve the catalog" do
Facter.stubs(:value).returns "eh"
Facter.expects(:value).with("hostname").returns "myhost"
- Puppet::Resource::Catalog.expects(:get).with { |name, options| name == "myhost" }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| name == "myhost" }.returns @catalog
@agent.retrieve_catalog
end
it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == false }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns @catalog
@agent.retrieve_catalog.should == @catalog
end
it "should return the cached catalog when no catalog can be retrieved from the server" do
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == false }.returns nil
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns nil
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.returns @catalog
+
+ @agent.retrieve_catalog.should == @catalog
+ end
+
+ it "should not look in the cache for a catalog if one is returned from the server" do
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.never
@agent.retrieve_catalog.should == @catalog
end
it "should return the cached catalog when retrieving the remote catalog throws an exception" do
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == false }.raises "eh"
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.raises "eh"
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.returns @catalog
@agent.retrieve_catalog.should == @catalog
end
it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == false }.returns nil
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == true }.returns nil
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns nil
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.returns nil
@agent.retrieve_catalog.should be_nil
end
- it "should record the retrieval time with the catalog" do
- @agent.expects(:thinmark).yields.then.returns 10
+ it "should convert the catalog before returning" do
+ Puppet::Resource::Catalog.stubs(:find).returns @catalog
- Puppet::Resource::Catalog.expects(:get).returns @catalog
+ @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
+ @agent.retrieve_catalog.should == "converted catalog"
+ end
- @catalog.expects(:retrieval_duration=).with 10
+ it "should return nil if there is an error while retrieving the catalog" do
+ Puppet::Resource::Catalog.expects(:find).raises "eh"
- @agent.retrieve_catalog
+ @agent.retrieve_catalog.should be_nil
end
+end
- it "should write the catalog's class file" do
- @catalog.expects(:write_class_file)
+describe Puppet::Agent, "when converting the catalog" do
+ before do
+ Puppet.settings.stubs(:use).returns(true)
+ @agent = Puppet::Agent.new
- Puppet::Resource::Catalog.expects(:get).returns @catalog
+ @catalog = Puppet::Resource::Catalog.new
+ @oldcatalog = stub 'old_catalog', :to_ral => @catalog
+ end
- @agent.retrieve_catalog
+ it "should convert the catalog to a RAL-formed catalog" do
+ @oldcatalog.expects(:to_ral).returns @catalog
+
+ @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog)
end
- it "should mark the catalog as a host catalog" do
- @catalog.expects(:host_config=).with true
+ it "should record the passed retrieval time with the RAL catalog" do
+ @catalog.expects(:retrieval_duration=).with 10
- Puppet::Resource::Catalog.expects(:get).returns @catalog
+ @agent.convert_catalog(@oldcatalog, 10)
+ end
- @agent.retrieve_catalog
+ it "should write the RAL catalog's class file" do
+ @catalog.expects(:write_class_file)
+
+ @agent.convert_catalog(@oldcatalog, 10)
end
- it "should return nil if there is an error while retrieving the catalog" do
- Puppet::Resource::Catalog.expects(:get).raises "eh"
+ it "should mark the RAL catalog as a host catalog" do
+ @catalog.expects(:host_config=).with true
- @agent.retrieve_catalog.should be_nil
+ @agent.convert_catalog(@oldcatalog, 10)
end
end
diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb
index 27cf7056d..211f42df0 100755
--- a/spec/unit/parser/interpreter.rb
+++ b/spec/unit/parser/interpreter.rb
@@ -112,7 +112,8 @@ describe Puppet::Parser::Interpreter do
end
it "should create a compile with the node and parser" do
- @compiler.expects(:compile).returns(:config)
+ catalog = stub 'catalog', :to_resource => nil
+ @compiler.expects(:compile).returns(catalog)
@interp.expects(:parser).with(:myenv).returns(@parser)
Puppet::Parser::Compiler.expects(:new).with(@node, @parser).returns(@compiler)
@interp.compile(@node)
@@ -123,6 +124,16 @@ describe Puppet::Parser::Interpreter do
@interp.expects(:parser).with(:myenv).returns(nil)
proc { @interp.compile(@node) }.should raise_error(Puppet::ParseError)
end
+
+ it "should return the results of the compile, converted to a plain resource catalog" do
+ catalog = mock 'catalog'
+ @compiler.expects(:compile).returns(catalog)
+ @interp.stubs(:parser).returns(@parser)
+ Puppet::Parser::Compiler.stubs(:new).returns(@compiler)
+
+ catalog.expects(:to_resource).returns "my_resource_catalog"
+ @interp.compile(@node).should == "my_resource_catalog"
+ end
end
describe "when returning catalog version" do