summaryrefslogtreecommitdiffstats
path: root/spec/unit/application
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-07-23 19:10:29 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-07-31 16:41:41 +1000
commit76fc2b177a026e49d8370de2092f77108769110a (patch)
tree1df20a9c74a2fd9431c9e8c31918462489ff45f4 /spec/unit/application
parent832b6ff1e18cf403213cbeb42646b5740669e6a5 (diff)
downloadpuppet-76fc2b177a026e49d8370de2092f77108769110a.tar.gz
puppet-76fc2b177a026e49d8370de2092f77108769110a.tar.xz
puppet-76fc2b177a026e49d8370de2092f77108769110a.zip
Fixing #2440 - catalogs can now be compiled on demand
This uses the locally cached yaml facts and prints the catalog in json. It's meant to be used one-time, but you have to use puppetmasterd since we assume it's the executable correctly configured for compilation. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/application')
-rw-r--r--spec/unit/application/puppetmasterd.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/unit/application/puppetmasterd.rb b/spec/unit/application/puppetmasterd.rb
index 000b2d602..a4875c713 100644
--- a/spec/unit/application/puppetmasterd.rb
+++ b/spec/unit/application/puppetmasterd.rb
@@ -32,6 +32,10 @@ describe "PuppetMaster" do
@puppetmasterd.should respond_to(:parseonly)
end
+ it "should declare a compile command" do
+ @puppetmasterd.should respond_to(:compile)
+ end
+
it "should declare a preinit block" do
@puppetmasterd.should respond_to(:run_preinit)
end
@@ -237,8 +241,14 @@ describe "PuppetMaster" do
@puppetmasterd.get_command.should == :parseonly
end
+ it "should dispatch to compile if called with --compile" do
+ @puppetmasterd.options[:node] = "foo"
+ @puppetmasterd.get_command.should == :compile
+ end
+
it "should dispatch to main if parseonly is not set" do
Puppet.stubs(:[]).with(:parseonly).returns(false)
+ @puppetmasterd.options[:node] = nil
@puppetmasterd.get_command.should == :main
end
@@ -276,6 +286,59 @@ describe "PuppetMaster" do
end
+ describe "the compile command" do
+ before do
+ Puppet.stubs(:[]).with(:environment)
+ Puppet.stubs(:[]).with(:manifest).returns("site.pp")
+ @interpreter = stub_everything
+ Puppet.stubs(:err)
+ @puppetmasterd.stubs(:exit)
+ Puppet::Parser::Interpreter.stubs(:new).returns(@interpreter)
+ Puppet.features.stubs(:json?).returns true
+ end
+
+ it "should fail if json isn't available" do
+ Puppet.features.expects(:json?).returns false
+ lambda { @puppetmasterd.compile }.should raise_error
+ end
+
+ it "should compile a catalog for the specified node" do
+ @puppetmasterd.options[:node] = "foo"
+ Puppet::Resource::Catalog.expects(:find).with("foo").returns Puppet::Resource::Catalog.new
+ $stdout.stubs(:puts)
+
+ @puppetmasterd.compile
+ end
+
+ it "should render the catalog to json and print the output" do
+ @puppetmasterd.options[:node] = "foo"
+ catalog = Puppet::Resource::Catalog.new
+ catalog.expects(:render).with(:json).returns "myjson"
+ Puppet::Resource::Catalog.expects(:find).returns catalog
+
+ $stdout.expects(:puts).with("myjson")
+ @puppetmasterd.compile
+ end
+
+ it "should exit with error code 30 if no catalog can be found" do
+ @puppetmasterd.options[:node] = "foo"
+ Puppet::Resource::Catalog.expects(:find).returns nil
+ @puppetmasterd.expects(:exit).with(30)
+ $stderr.expects(:puts)
+
+ @puppetmasterd.compile
+ end
+
+ it "should exit with error code 30 if there's a failure" do
+ @puppetmasterd.options[:node] = "foo"
+ Puppet::Resource::Catalog.expects(:find).raises ArgumentError
+ @puppetmasterd.expects(:exit).with(30)
+ $stderr.expects(:puts)
+
+ @puppetmasterd.compile
+ end
+ end
+
describe "the main command" do
before :each do
@puppetmasterd.run_preinit