diff options
-rwxr-xr-x | bin/puppetdoc | 4 | ||||
-rw-r--r-- | lib/puppet/application/agent.rb (renamed from lib/puppet/application/puppetd.rb) | 2 | ||||
-rw-r--r-- | lib/puppet/application/ca.rb (renamed from lib/puppet/application/puppetca.rb) | 2 | ||||
-rw-r--r-- | lib/puppet/application/doc.rb (renamed from lib/puppet/application/puppetdoc.rb) | 2 | ||||
-rw-r--r-- | lib/puppet/application/queue.rb (renamed from lib/puppet/application/puppetqd.rb) | 2 | ||||
-rw-r--r-- | lib/puppet/application/resource.rb (renamed from lib/puppet/application/ralsh.rb) | 2 | ||||
-rw-r--r-- | lib/puppet/application/run.rb (renamed from lib/puppet/application/puppetrun.rb) | 2 | ||||
-rw-r--r-- | lib/puppet/application/server.rb (renamed from lib/puppet/application/puppetmasterd.rb) | 2 | ||||
-rwxr-xr-x | sbin/puppetca | 4 | ||||
-rwxr-xr-x | sbin/puppetd | 4 | ||||
-rwxr-xr-x | sbin/puppetmasterd | 4 | ||||
-rwxr-xr-x | sbin/puppetqd | 4 | ||||
-rwxr-xr-x | sbin/puppetrun | 4 | ||||
-rwxr-xr-x | spec/unit/application/agent.rb (renamed from spec/unit/application/puppetd.rb) | 6 | ||||
-rw-r--r-- | spec/unit/application/ca.rb (renamed from spec/unit/application/puppetca.rb) | 54 | ||||
-rwxr-xr-x | spec/unit/application/doc.rb (renamed from spec/unit/application/puppetdoc.rb) | 170 | ||||
-rwxr-xr-x | spec/unit/application/puppetrun.rb | 162 | ||||
-rwxr-xr-x | spec/unit/application/queue.rb (renamed from spec/unit/application/puppetqd.rb) | 78 | ||||
-rwxr-xr-x | spec/unit/application/resource.rb (renamed from spec/unit/application/ralsh.rb) | 95 | ||||
-rw-r--r-- | spec/unit/application/server.rb (renamed from spec/unit/application/puppetmasterd.rb) | 162 |
20 files changed, 384 insertions, 381 deletions
diff --git a/bin/puppetdoc b/bin/puppetdoc index a69d169c9..e17b014b3 100755 --- a/bin/puppetdoc +++ b/bin/puppetdoc @@ -61,5 +61,5 @@ # Copyright (c) 2005-2007 Reductive Labs, LLC # Licensed under the GNU Public License -require 'puppet/application/puppetdoc' -Puppet::Application[:puppetdoc].run +require 'puppet/application/doc' +Puppet::Application[:doc].run diff --git a/lib/puppet/application/puppetd.rb b/lib/puppet/application/agent.rb index ed2c450ee..ec6fc8088 100644 --- a/lib/puppet/application/puppetd.rb +++ b/lib/puppet/application/agent.rb @@ -5,7 +5,7 @@ require 'puppet/daemon' require 'puppet/configurer' require 'puppet/network/client' -Puppet::Application.new(:puppetd) do +Puppet::Application.new(:agent) do should_parse_config diff --git a/lib/puppet/application/puppetca.rb b/lib/puppet/application/ca.rb index 7362f2a18..ab7f607ee 100644 --- a/lib/puppet/application/puppetca.rb +++ b/lib/puppet/application/ca.rb @@ -2,7 +2,7 @@ require 'puppet' require 'puppet/application' require 'puppet/ssl/certificate_authority' -Puppet::Application.new(:puppetca) do +Puppet::Application.new(:ca) do should_parse_config diff --git a/lib/puppet/application/puppetdoc.rb b/lib/puppet/application/doc.rb index e0033277f..32f9ba75c 100644 --- a/lib/puppet/application/puppetdoc.rb +++ b/lib/puppet/application/doc.rb @@ -7,7 +7,7 @@ require 'puppet/util/rdoc' $tab = " " Reference = Puppet::Util::Reference -Puppet::Application.new(:puppetdoc) do +Puppet::Application.new(:doc) do should_not_parse_config diff --git a/lib/puppet/application/puppetqd.rb b/lib/puppet/application/queue.rb index c9c62c068..13fb3e107 100644 --- a/lib/puppet/application/puppetqd.rb +++ b/lib/puppet/application/queue.rb @@ -5,7 +5,7 @@ require 'puppet/resource/catalog' require 'puppet/indirector/catalog/queue' require 'puppet/util' -Puppet::Application.new(:puppetqd) do +Puppet::Application.new(:queue) do extend Puppet::Util should_parse_config diff --git a/lib/puppet/application/ralsh.rb b/lib/puppet/application/resource.rb index b9f7a587c..f914a1b53 100644 --- a/lib/puppet/application/ralsh.rb +++ b/lib/puppet/application/resource.rb @@ -2,7 +2,7 @@ require 'puppet' require 'puppet/application' require 'facter' -Puppet::Application.new(:ralsh) do +Puppet::Application.new(:resource) do should_not_parse_config diff --git a/lib/puppet/application/puppetrun.rb b/lib/puppet/application/run.rb index 4febcf524..f08fade8d 100644 --- a/lib/puppet/application/puppetrun.rb +++ b/lib/puppet/application/run.rb @@ -4,7 +4,7 @@ require 'puppet/application' Puppet.warning "RubyGems not installed" unless Puppet.features.rubygems? Puppet.warning "Failed to load ruby LDAP library. LDAP functionality will not be available" unless Puppet.features.ldap? -Puppet::Application.new(:puppetrun) do +Puppet::Application.new(:run) do should_not_parse_config diff --git a/lib/puppet/application/puppetmasterd.rb b/lib/puppet/application/server.rb index 9b0bf30ce..57d29e0ee 100644 --- a/lib/puppet/application/puppetmasterd.rb +++ b/lib/puppet/application/server.rb @@ -4,7 +4,7 @@ require 'puppet/daemon' require 'puppet/network/server' require 'puppet/network/http/rack' if Puppet.features.rack? -Puppet::Application.new(:puppetmasterd) do +Puppet::Application.new(:server) do should_parse_config diff --git a/sbin/puppetca b/sbin/puppetca index eab594ba6..71cb6c930 100755 --- a/sbin/puppetca +++ b/sbin/puppetca @@ -107,5 +107,5 @@ # Copyright (c) 2005 Reductive Labs, LLC # Licensed under the GNU Public License -require 'puppet/application/puppetca' -Puppet::Application[:puppetca].run +require 'puppet/application/ca' +Puppet::Application[:ca].run diff --git a/sbin/puppetd b/sbin/puppetd index fd78dc631..5886100b8 100755 --- a/sbin/puppetd +++ b/sbin/puppetd @@ -181,5 +181,5 @@ # Copyright (c) 2005, 2006 Reductive Labs, LLC # Licensed under the GNU Public License -require 'puppet/application/puppetd' -Puppet::Application[:puppetd].run +require 'puppet/application/agent' +Puppet::Application[:agent].run diff --git a/sbin/puppetmasterd b/sbin/puppetmasterd index 9f12f678c..c38c64828 100755 --- a/sbin/puppetmasterd +++ b/sbin/puppetmasterd @@ -62,5 +62,5 @@ # Copyright (c) 2005 Reductive Labs, LLC # Licensed under the GNU Public License -require 'puppet/application/puppetmasterd' -Puppet::Application[:puppetmasterd].run +require 'puppet/application/server' +Puppet::Application[:server].run diff --git a/sbin/puppetqd b/sbin/puppetqd index 5487a324f..4cf8d4f02 100755 --- a/sbin/puppetqd +++ b/sbin/puppetqd @@ -49,5 +49,5 @@ # Copyright (c) 2009 Reductive Labs, LLC # Licensed under the GNU Public License -require 'puppet/application/puppetqd' -Puppet::Application[:puppetqd].run +require 'puppet/application/queue' +Puppet::Application[:queue].run diff --git a/sbin/puppetrun b/sbin/puppetrun index d3b2630af..6dc8fd25a 100755 --- a/sbin/puppetrun +++ b/sbin/puppetrun @@ -125,6 +125,6 @@ # Copyright (c) 2005 Reductive Labs, LLC # Licensed under the GNU Public License -require 'puppet/application/puppetrun' -Puppet::Application[:puppetrun].run +require 'puppet/application/run' +Puppet::Application[:run].run diff --git a/spec/unit/application/puppetd.rb b/spec/unit/application/agent.rb index 246c39958..cbfd2d72a 100755 --- a/spec/unit/application/puppetd.rb +++ b/spec/unit/application/agent.rb @@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/application/puppetd' +require 'puppet/application/agent' require 'puppet/network/server' -describe "puppetd" do +describe Puppet::Application[:agent] do before :each do - @puppetd = Puppet::Application[:puppetd] + @puppetd = Puppet::Application[:agent] @puppetd.stubs(:puts) @daemon = stub_everything 'daemon' Puppet::Daemon.stubs(:new).returns(@daemon) diff --git a/spec/unit/application/puppetca.rb b/spec/unit/application/ca.rb index 132a03c1f..b9a716e3f 100644 --- a/spec/unit/application/puppetca.rb +++ b/spec/unit/application/ca.rb @@ -2,26 +2,26 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/application/puppetca' +require 'puppet/application/ca' describe "PuppetCA" do before :each do - @puppetca = Puppet::Application[:puppetca] + @ca_app = Puppet::Application[:ca] Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) end it "should ask Puppet::Application to parse Puppet configuration file" do - @puppetca.should_parse_config?.should be_true + @ca_app.should_parse_config?.should be_true end it "should declare a main command" do - @puppetca.should respond_to(:main) + @ca_app.should respond_to(:main) end Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject{ |m| m == :destroy }.each do |method| it "should declare option --#{method}" do - @puppetca.should respond_to("handle_#{method}".to_sym) + @ca_app.should respond_to("handle_#{method}".to_sym) end end @@ -29,14 +29,14 @@ describe "PuppetCA" do Puppet::Log.expects(:level=).with(:info) - @puppetca.handle_verbose(0) + @ca_app.handle_verbose(0) end it "should set log level to debug with the --debug option" do Puppet::Log.expects(:level=).with(:debug) - @puppetca.handle_debug(0) + @ca_app.handle_debug(0) end it "should set the fingerprint digest with the --digest option" do @@ -46,20 +46,20 @@ describe "PuppetCA" do end it "should set mode to :destroy for --clean" do - @puppetca.handle_clean(0) - @puppetca.mode.should == :destroy + @ca_app.handle_clean(0) + @ca_app.mode.should == :destroy end it "should set all to true for --all" do - @puppetca.handle_all(0) - @puppetca.all.should be_true + @ca_app.handle_all(0) + @ca_app.all.should be_true end Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject { |m| m == :destroy }.each do |method| it "should set mode to #{method} with option --#{method}" do - @puppetca.send("handle_#{method}".to_sym, nil) + @ca_app.send("handle_#{method}".to_sym, nil) - @puppetca.mode.should == method + @ca_app.mode.should == method end end @@ -74,57 +74,57 @@ describe "PuppetCA" do it "should set console as the log destination" do Puppet::Log.expects(:newdestination).with(:console) - @puppetca.run_setup + @ca_app.run_setup end it "should print puppet config if asked to in Puppet config" do - @puppetca.stubs(:exit) + @ca_app.stubs(:exit) Puppet.settings.stubs(:print_configs?).returns(true) Puppet.settings.expects(:print_configs) - @puppetca.run_setup + @ca_app.run_setup end it "should exit after printing puppet config if asked to in Puppet config" do Puppet.settings.stubs(:print_configs?).returns(true) - lambda { @puppetca.run_setup }.should raise_error(SystemExit) + lambda { @ca_app.run_setup }.should raise_error(SystemExit) end it "should set the CA location to 'only'" do Puppet::SSL::Host.expects(:ca_location=).with(:only) - @puppetca.run_setup + @ca_app.run_setup end it "should create a new certificate authority" do Puppet::SSL::CertificateAuthority.expects(:new) - @puppetca.run_setup + @ca_app.run_setup end end describe "when running" do before :each do - @puppetca.all = false + @ca_app.all = false @ca = stub_everything 'ca' - @puppetca.ca = @ca + @ca_app.ca = @ca ARGV.stubs(:collect).returns([]) end it "should delegate to the CertificateAuthority" do @ca.expects(:apply) - @puppetca.main + @ca_app.main end it "should delegate with :all if option --all was given" do - @puppetca.handle_all(0) + @ca_app.handle_all(0) @ca.expects(:apply).with { |mode,to| to[:to] == :all } - @puppetca.main + @ca_app.main end it "should delegate to ca.apply with the hosts given on command line" do @@ -132,7 +132,7 @@ describe "PuppetCA" do @ca.expects(:apply).with { |mode,to| to[:to] == ["host"]} - @puppetca.main + @ca_app.main end it "should send the currently set digest" do @@ -145,12 +145,12 @@ describe "PuppetCA" do end it "should delegate to ca.apply with current set mode" do - @puppetca.mode = "currentmode" + @ca_app.mode = "currentmode" ARGV.stubs(:collect).returns(["host"]) @ca.expects(:apply).with { |mode,to| mode == "currentmode" } - @puppetca.main + @ca_app.main end it "should revoke cert if mode is clean" do diff --git a/spec/unit/application/puppetdoc.rb b/spec/unit/application/doc.rb index 413fa1186..e5d7e1aa5 100755 --- a/spec/unit/application/puppetdoc.rb +++ b/spec/unit/application/doc.rb @@ -2,105 +2,105 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/application/puppetdoc' +require 'puppet/application/doc' -describe "puppetdoc" do +describe "doc" do before :each do - @puppetdoc = Puppet::Application[:puppetdoc] - @puppetdoc.stubs(:puts) - @puppetdoc.run_preinit + @doc = Puppet::Application[:doc] + @doc.stubs(:puts) + @doc.run_preinit Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) end it "should ask Puppet::Application to not parse Puppet configuration file" do - @puppetdoc.should_parse_config?.should be_false + @doc.should_parse_config?.should be_false end it "should declare a other command" do - @puppetdoc.should respond_to(:other) + @doc.should respond_to(:other) end it "should declare a rdoc command" do - @puppetdoc.should respond_to(:rdoc) + @doc.should respond_to(:rdoc) end it "should declare a trac command" do - @puppetdoc.should respond_to(:trac) + @doc.should respond_to(:trac) end it "should declare a fallback for unknown options" do - @puppetdoc.should respond_to(:handle_unknown) + @doc.should respond_to(:handle_unknown) end it "should declare a preinit block" do - @puppetdoc.should respond_to(:run_preinit) + @doc.should respond_to(:run_preinit) end describe "in preinit" do it "should set references to []" do - @puppetdoc.run_preinit + @doc.run_preinit - @puppetdoc.options[:references].should == [] + @doc.options[:references].should == [] end it "should init mode to text" do - @puppetdoc.run_preinit + @doc.run_preinit - @puppetdoc.options[:mode].should == :text + @doc.options[:mode].should == :text end it "should init format to to_rest" do - @puppetdoc.run_preinit + @doc.run_preinit - @puppetdoc.options[:format].should == :to_rest + @doc.options[:format].should == :to_rest end end describe "when handling options" do [:all, :outputdir, :verbose, :debug].each do |option| it "should declare handle_#{option} method" do - @puppetdoc.should respond_to("handle_#{option}".to_sym) + @doc.should respond_to("handle_#{option}".to_sym) end it "should store argument value when calling handle_#{option}" do - @puppetdoc.options.expects(:[]=).with(option, 'arg') - @puppetdoc.send("handle_#{option}".to_sym, 'arg') + @doc.options.expects(:[]=).with(option, 'arg') + @doc.send("handle_#{option}".to_sym, 'arg') end end it "should store the format if valid" do Puppet::Util::Reference.stubs(:method_defined?).with('to_format').returns(true) - @puppetdoc.options.expects(:[]=).with(:format, 'to_format') + @doc.options.expects(:[]=).with(:format, 'to_format') - @puppetdoc.handle_format('format') + @doc.handle_format('format') end it "should raise an error if the format is not valid" do Puppet::Util::Reference.stubs(:method_defined?).with('to_format').returns(false) - lambda { @puppetdoc.handle_format('format') } + lambda { @doc.handle_format('format') } end it "should store the mode if valid" do Puppet::Util::Reference.stubs(:modes).returns(stub('mode', :include? => true)) - @puppetdoc.options.expects(:[]=).with(:mode, :mode) + @doc.options.expects(:[]=).with(:mode, :mode) - @puppetdoc.handle_mode('mode') + @doc.handle_mode('mode') end it "should store the mode if :rdoc" do Puppet::Util::Reference.modes.stubs(:include?).with('rdoc').returns(false) - @puppetdoc.options.expects(:[]=).with(:mode, :rdoc) + @doc.options.expects(:[]=).with(:mode, :rdoc) - @puppetdoc.handle_mode('rdoc') + @doc.handle_mode('rdoc') end it "should raise an error if the mode is not valid" do Puppet::Util::Reference.modes.stubs(:include?).with('unknown').returns(false) - lambda { @puppetdoc.handle_mode('unknown') } + lambda { @doc.handle_mode('unknown') } end it "should list all references on list and exit" do @@ -110,17 +110,17 @@ describe "puppetdoc" do Puppet::Util::Reference.expects(:reference).with(reference).returns(ref) ref.expects(:doc) - @puppetdoc.expects(:exit) + @doc.expects(:exit) - @puppetdoc.handle_list(nil) + @doc.handle_list(nil) end it "should add reference to references list with --reference" do - @puppetdoc.options[:references] = [:ref1] + @doc.options[:references] = [:ref1] - @puppetdoc.handle_reference('ref2') + @doc.handle_reference('ref2') - @puppetdoc.options[:references].should == [:ref1,:ref2] + @doc.options[:references].should == [:ref1,:ref2] end end @@ -133,53 +133,53 @@ describe "puppetdoc" do it "should default to rdoc mode if there are command line arguments" do ARGV.stubs(:size).returns(1) - @puppetdoc.stubs(:setup_rdoc) + @doc.stubs(:setup_rdoc) - @puppetdoc.options.expects(:[]=).with(:mode,:rdoc) + @doc.options.expects(:[]=).with(:mode,:rdoc) - @puppetdoc.run_setup + @doc.run_setup end it "should call setup_rdoc in rdoc mode" do - @puppetdoc.options.stubs(:[]).with(:mode).returns(:rdoc) + @doc.options.stubs(:[]).with(:mode).returns(:rdoc) - @puppetdoc.expects(:setup_rdoc) + @doc.expects(:setup_rdoc) - @puppetdoc.run_setup + @doc.run_setup end it "should call setup_reference if not rdoc" do - @puppetdoc.options.stubs(:[]).with(:mode).returns(:test) + @doc.options.stubs(:[]).with(:mode).returns(:test) - @puppetdoc.expects(:setup_reference) + @doc.expects(:setup_reference) - @puppetdoc.run_setup + @doc.run_setup end describe "in non-rdoc mode" do it "should get all non-dynamic reference if --all" do - @puppetdoc.options.stubs(:[]).with(:all).returns(true) - @puppetdoc.options.stubs(:[]).with(:references).returns([]) + @doc.options.stubs(:[]).with(:all).returns(true) + @doc.options.stubs(:[]).with(:references).returns([]) static = stub 'static', :dynamic? => false dynamic = stub 'dynamic', :dynamic? => true Reference.stubs(:reference).with(:static).returns(static) Reference.stubs(:reference).with(:dynamic).returns(dynamic) Reference.stubs(:references).returns([:static,:dynamic]) - @puppetdoc.options.stubs(:[]=).with(:references, [:static]) + @doc.options.stubs(:[]=).with(:references, [:static]) - @puppetdoc.setup_reference + @doc.setup_reference end it "should default to :type if no references" do - @puppetdoc.options.stubs(:[]).with(:all).returns(false) + @doc.options.stubs(:[]).with(:all).returns(false) array = stub 'array', :empty? => true - @puppetdoc.options.stubs(:[]).with(:references).returns(array) + @doc.options.stubs(:[]).with(:references).returns(array) array.expects(:<<).with(:type) - @puppetdoc.setup_reference + @doc.setup_reference end end @@ -187,7 +187,7 @@ describe "puppetdoc" do describe "in rdoc mode" do before :each do - @puppetdoc.options.stubs(:[]).returns(false) + @doc.options.stubs(:[]).returns(false) Puppet.stubs(:[]=).with(:name, "puppetmasterd") Puppet.stubs(:parse_config) Puppet::Util::Log.stubs(:level=) @@ -197,71 +197,71 @@ describe "puppetdoc" do describe "when there are unknown args" do it "should expand --modulepath if any" do - @puppetdoc.unknown_args = [ { :opt => "--modulepath", :arg => "path" } ] + @doc.unknown_args = [ { :opt => "--modulepath", :arg => "path" } ] Puppet.settings.stubs(:handlearg) File.expects(:expand_path).with("path") - @puppetdoc.setup_rdoc + @doc.setup_rdoc end it "should expand --manifestdir if any" do - @puppetdoc.unknown_args = [ { :opt => "--manifestdir", :arg => "path" } ] + @doc.unknown_args = [ { :opt => "--manifestdir", :arg => "path" } ] Puppet.settings.stubs(:handlearg) File.expects(:expand_path).with("path") - @puppetdoc.setup_rdoc + @doc.setup_rdoc end it "should give them to Puppet.settings" do - @puppetdoc.unknown_args = [ { :opt => :option, :arg => :argument } ] + @doc.unknown_args = [ { :opt => :option, :arg => :argument } ] Puppet.settings.expects(:handlearg).with(:option,:argument) - @puppetdoc.setup_rdoc + @doc.setup_rdoc end end it "should pretend to be puppetmasterd" do Puppet.expects(:[]=).with(:name, "puppetmasterd") - @puppetdoc.setup_rdoc + @doc.setup_rdoc end it "should parse puppet configuration" do Puppet.expects(:parse_config) - @puppetdoc.setup_rdoc + @doc.setup_rdoc end it "should set log level to debug if --debug" do - @puppetdoc.options.stubs(:[]).with(:debug).returns(true) + @doc.options.stubs(:[]).with(:debug).returns(true) Puppet::Util::Log.expects(:level=).with(:debug) - @puppetdoc.setup_rdoc + @doc.setup_rdoc end it "should set log level to info if --verbose" do - @puppetdoc.options.stubs(:[]).with(:verbose).returns(true) + @doc.options.stubs(:[]).with(:verbose).returns(true) Puppet::Util::Log.expects(:level=).with(:info) - @puppetdoc.setup_rdoc + @doc.setup_rdoc end it "should set log destination to console if --verbose" do - @puppetdoc.options.stubs(:[]).with(:verbose).returns(true) + @doc.options.stubs(:[]).with(:verbose).returns(true) Puppet::Util::Log.expects(:newdestination).with(:console) - @puppetdoc.setup_rdoc + @doc.setup_rdoc end it "should set log destination to console if --debug" do - @puppetdoc.options.stubs(:[]).with(:debug).returns(true) + @doc.options.stubs(:[]).with(:debug).returns(true) Puppet::Util::Log.expects(:newdestination).with(:console) - @puppetdoc.setup_rdoc + @doc.setup_rdoc end end @@ -276,30 +276,34 @@ describe "puppetdoc" do it "should call trac for each reference" do ref = stub 'ref' Puppet::Util::Reference.stubs(:reference).with(:ref).returns(ref) - @puppetdoc.options.stubs(:[]).with(:references).returns([:ref]) - @puppetdoc.options.stubs(:[]).with(:mode).returns(:trac) + @doc.options.stubs(:[]).with(:references).returns([:ref]) + @doc.options.stubs(:[]).with(:mode).returns(:trac) ref.expects(:trac) - @puppetdoc.trac + @doc.trac end end describe "in rdoc mode" do before :each do - @puppetdoc.manifest = false + @doc.manifest = false Puppet.stubs(:info) Puppet.stubs(:[]).with(:trace).returns(false) @env = stub 'env' Puppet::Node::Environment.stubs(:new).returns(@env) @env.stubs(:modulepath).returns(['modules']) @env.stubs(:[]).with(:manifest).returns('manifests/site.pp') - @puppetdoc.options.stubs(:[]).with(:all).returns(false) - @puppetdoc.options.stubs(:[]).with(:outputdir).returns('doc') + Puppet.stubs(:[]).with(:modulepath).returns('modules') + Puppet.stubs(:[]).with(:manifestdir).returns('manifests') + @doc.options.stubs(:[]).with(:all).returns(false) + @doc.options.stubs(:[]).with(:outputdir).returns('doc') Puppet.settings.stubs(:[]=).with(:document_all, false) Puppet.settings.stubs(:setdefaults) Puppet::Util::RDoc.stubs(:rdoc) - @puppetdoc.stubs(:exit) + @doc.stubs(:exit) + File.stubs(:expand_path).with('modules').returns('modules') + File.stubs(:expand_path).with('manifests').returns('manifests') @old = ARGV.dup ARGV.clear end @@ -309,15 +313,15 @@ describe "puppetdoc" do end it "should set document_all on --all" do - @puppetdoc.options.expects(:[]).with(:all).returns(true) + @doc.options.expects(:[]).with(:all).returns(true) Puppet.settings.expects(:[]=).with(:document_all, true) - @puppetdoc.rdoc + @doc.rdoc end it "should call Puppet::Util::RDoc.rdoc in full mode" do Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests']) - @puppetdoc.rdoc + @doc.rdoc end it "should call Puppet::Util::RDoc.rdoc in full mode with outputdir set to doc if no --outputdir" do @@ -327,9 +331,9 @@ describe "puppetdoc" do end it "should call Puppet::Util::RDoc.manifestdoc in manifest mode" do - @puppetdoc.manifest = true + @doc.manifest = true Puppet::Util::RDoc.expects(:manifestdoc) - @puppetdoc.rdoc + @doc.rdoc end it "should get modulepath and manifestdir values from the environment" do @@ -345,14 +349,14 @@ describe "puppetdoc" do describe "in the other modes" do it "should get reference in given format" do reference = stub 'reference' - @puppetdoc.options.stubs(:[]).with(:mode).returns(:none) - @puppetdoc.options.stubs(:[]).with(:references).returns([:ref]) + @doc.options.stubs(:[]).with(:mode).returns(:none) + @doc.options.stubs(:[]).with(:references).returns([:ref]) Puppet::Util::Reference.expects(:reference).with(:ref).returns(reference) - @puppetdoc.options.stubs(:[]).with(:format).returns(:format) - @puppetdoc.stubs(:exit) + @doc.options.stubs(:[]).with(:format).returns(:format) + @doc.stubs(:exit) reference.expects(:send).with { |format,contents| format == :format }.returns('doc') - @puppetdoc.other + @doc.other end end diff --git a/spec/unit/application/puppetrun.rb b/spec/unit/application/puppetrun.rb index 26811f0db..13b61b90e 100755 --- a/spec/unit/application/puppetrun.rb +++ b/spec/unit/application/puppetrun.rb @@ -3,71 +3,71 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/util/ldap/connection' -require 'puppet/application/puppetrun' +require 'puppet/application/run' -describe "puppetrun" do +describe "run" do before :each do Puppet::Util::Ldap::Connection.stubs(:new).returns(stub_everything) - @puppetrun = Puppet::Application[:puppetrun] + @run = Puppet::Application[:run] Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) end it "should ask Puppet::Application to not parse Puppet configuration file" do - @puppetrun.should_parse_config?.should be_false + @run.should_parse_config?.should be_false end it "should declare a main command" do - @puppetrun.should respond_to(:main) + @run.should respond_to(:main) end it "should declare a test command" do - @puppetrun.should respond_to(:test) + @run.should respond_to(:test) end it "should declare a preinit block" do - @puppetrun.should respond_to(:run_preinit) + @run.should respond_to(:run_preinit) end describe "during preinit" do before :each do - @puppetrun.stubs(:trap) + @run.stubs(:trap) end it "should catch INT and TERM" do - @puppetrun.stubs(:trap).with { |arg,block| arg == :INT or arg == :TERM } + @run.stubs(:trap).with { |arg,block| arg == :INT or arg == :TERM } - @puppetrun.run_preinit + @run.run_preinit end it "should set parallel option to 1" do - @puppetrun.run_preinit + @run.run_preinit - @puppetrun.options[:parallel].should == 1 + @run.options[:parallel].should == 1 end it "should set verbose by default" do - @puppetrun.run_preinit + @run.run_preinit - @puppetrun.options[:verbose].should be_true + @run.options[:verbose].should be_true end it "should set fqdn by default" do - @puppetrun.run_preinit + @run.run_preinit - @puppetrun.options[:fqdn].should be_true + @run.options[:fqdn].should be_true end it "should set ignoreschedules to 'false'" do - @puppetrun.run_preinit + @run.run_preinit - @puppetrun.options[:ignoreschedules].should be_false + @run.options[:ignoreschedules].should be_false end it "should set foreground to 'false'" do - @puppetrun.run_preinit + @run.run_preinit - @puppetrun.options[:foreground].should be_false + @run.options[:foreground].should be_false end end @@ -75,68 +75,68 @@ describe "puppetrun" do [:all, :foreground, :debug, :ping, :test].each do |option| it "should declare handle_#{option} method" do - @puppetrun.should respond_to("handle_#{option}".to_sym) + @run.should respond_to("handle_#{option}".to_sym) end it "should store argument value when calling handle_#{option}" do - @puppetrun.options.expects(:[]=).with(option, 'arg') - @puppetrun.send("handle_#{option}".to_sym, 'arg') + @run.options.expects(:[]=).with(option, 'arg') + @run.send("handle_#{option}".to_sym, 'arg') end end it "should add to the host list with the host option" do - @puppetrun.handle_host('host') + @run.handle_host('host') - @puppetrun.hosts.should == ['host'] + @run.hosts.should == ['host'] end it "should add to the tag list with the tag option" do - @puppetrun.handle_tag('tag') + @run.handle_tag('tag') - @puppetrun.tags.should == ['tag'] + @run.tags.should == ['tag'] end it "should add to the class list with the class option" do - @puppetrun.handle_class('class') + @run.handle_class('class') - @puppetrun.classes.should == ['class'] + @run.classes.should == ['class'] end end describe "during setup" do before :each do - @puppetrun.classes = [] - @puppetrun.tags = [] - @puppetrun.hosts = [] + @run.classes = [] + @run.tags = [] + @run.hosts = [] Puppet::Log.stubs(:level=) - @puppetrun.stubs(:trap) - @puppetrun.stubs(:puts) + @run.stubs(:trap) + @run.stubs(:puts) Puppet.stubs(:parse_config) - @puppetrun.options.stubs(:[]).with(any_parameters) + @run.options.stubs(:[]).with(any_parameters) end it "should set log level to debug if --debug was passed" do - @puppetrun.options.stubs(:[]).with(:debug).returns(true) + @run.options.stubs(:[]).with(:debug).returns(true) Puppet::Log.expects(:level=).with(:debug) - @puppetrun.run_setup + @run.run_setup end it "should set log level to info if --verbose was passed" do - @puppetrun.options.stubs(:[]).with(:verbose).returns(true) + @run.options.stubs(:[]).with(:verbose).returns(true) Puppet::Log.expects(:level=).with(:info) - @puppetrun.run_setup + @run.run_setup end it "should Parse puppet config" do Puppet.expects(:parse_config) - @puppetrun.run_setup + @run.run_setup end describe "when using the ldap node terminus" do @@ -155,59 +155,59 @@ describe "puppetrun" do end it "should search for all nodes if --all" do - @puppetrun.options.stubs(:[]).with(:all).returns(true) - @puppetrun.stubs(:puts) + @run.options.stubs(:[]).with(:all).returns(true) + @run.stubs(:puts) Puppet::Node.expects(:search).with("whatever",:fqdn => nil).returns([]) - @puppetrun.run_setup + @run.run_setup end it "should search for nodes including given classes" do - @puppetrun.options.stubs(:[]).with(:all).returns(false) - @puppetrun.stubs(:puts) - @puppetrun.classes = ['class'] + @run.options.stubs(:[]).with(:all).returns(false) + @run.stubs(:puts) + @run.classes = ['class'] Puppet::Node.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([]) - @puppetrun.run_setup + @run.run_setup end end describe "when using regular nodes" do it "should fail if some classes have been specified" do $stderr.stubs(:puts) - @puppetrun.classes = ['class'] + @run.classes = ['class'] - @puppetrun.expects(:exit).with(24) + @run.expects(:exit).with(24) - @puppetrun.run_setup + @run.run_setup end end end describe "when running" do before :each do - @puppetrun.stubs(:puts) + @run.stubs(:puts) end it "should dispatch to test if --test is used" do - @puppetrun.options.stubs(:[]).with(:test).returns(true) + @run.options.stubs(:[]).with(:test).returns(true) - @puppetrun.get_command.should == :test + @run.get_command.should == :test end it "should dispatch to main if --test is not used" do - @puppetrun.options.stubs(:[]).with(:test).returns(false) + @run.options.stubs(:[]).with(:test).returns(false) - @puppetrun.get_command.should == :main + @run.get_command.should == :main end describe "the test command" do it "should exit with exit code 0 " do - @puppetrun.expects(:exit).with(0) + @run.expects(:exit).with(0) - @puppetrun.test + @run.test end end @@ -216,72 +216,72 @@ describe "puppetrun" do @client = stub_everything 'client' @client.stubs(:run).returns("success") Puppet::Network::Client.runner.stubs(:new).returns(@client) - @puppetrun.options.stubs(:[]).with(:parallel).returns(1) - @puppetrun.options.stubs(:[]).with(:ping).returns(false) - @puppetrun.options.stubs(:[]).with(:ignoreschedules).returns(false) - @puppetrun.options.stubs(:[]).with(:foreground).returns(false) - @puppetrun.stubs(:print) - @puppetrun.stubs(:exit) + @run.options.stubs(:[]).with(:parallel).returns(1) + @run.options.stubs(:[]).with(:ping).returns(false) + @run.options.stubs(:[]).with(:ignoreschedules).returns(false) + @run.options.stubs(:[]).with(:foreground).returns(false) + @run.stubs(:print) + @run.stubs(:exit) $stderr.stubs(:puts) end it "should create as much childs as --parallel" do - @puppetrun.options.stubs(:[]).with(:parallel).returns(3) - @puppetrun.hosts = ['host1', 'host2', 'host3'] - @puppetrun.stubs(:exit).raises(SystemExit) + @run.options.stubs(:[]).with(:parallel).returns(3) + @run.hosts = ['host1', 'host2', 'host3'] + @run.stubs(:exit).raises(SystemExit) Process.stubs(:wait).returns(1).then.returns(2).then.returns(3).then.raises(Errno::ECHILD) - @puppetrun.expects(:fork).times(3).returns(1).then.returns(2).then.returns(3) + @run.expects(:fork).times(3).returns(1).then.returns(2).then.returns(3) - lambda { @puppetrun.main }.should raise_error + lambda { @run.main }.should raise_error end it "should delegate to run_for_host per host" do - @puppetrun.hosts = ['host1', 'host2'] - @puppetrun.stubs(:exit).raises(SystemExit) - @puppetrun.stubs(:fork).returns(1).yields + @run.hosts = ['host1', 'host2'] + @run.stubs(:exit).raises(SystemExit) + @run.stubs(:fork).returns(1).yields Process.stubs(:wait).returns(1).then.raises(Errno::ECHILD) - @puppetrun.expects(:run_for_host).times(2) + @run.expects(:run_for_host).times(2) - lambda { @puppetrun.main }.should raise_error + lambda { @run.main }.should raise_error end describe "during call of run_for_host" do it "should create a Runner Client per given host" do Puppet::Network::Client.runner.expects(:new).returns(@client) - @puppetrun.run_for_host('host') + @run.run_for_host('host') end it "should call Client.run for the given host" do @client.expects(:run) - @puppetrun.run_for_host('host') + @run.run_for_host('host') end it "should exit the child with 0 on success" do @client.stubs(:run).returns("success") - @puppetrun.expects(:exit).with(0) + @run.expects(:exit).with(0) - @puppetrun.run_for_host('host') + @run.run_for_host('host') end it "should exit the child with 3 on running" do @client.stubs(:run).returns("running") - @puppetrun.expects(:exit).with(3) + @run.expects(:exit).with(3) - @puppetrun.run_for_host('host') + @run.run_for_host('host') end it "should exit the child with 12 on unknown answer" do @client.stubs(:run).returns("whatever") - @puppetrun.expects(:exit).with(12) + @run.expects(:exit).with(12) - @puppetrun.run_for_host('host') + @run.run_for_host('host') end end end diff --git a/spec/unit/application/puppetqd.rb b/spec/unit/application/queue.rb index dd9efba38..e761aece6 100755 --- a/spec/unit/application/puppetqd.rb +++ b/spec/unit/application/queue.rb @@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/application/puppetqd' +require 'puppet/application/queue' -describe "puppetqd" do +describe "queue" do before :each do - @puppetqd = Puppet::Application[:puppetqd] - @puppetqd.stubs(:puts) + @queue = Puppet::Application[:queue] + @queue.stubs(:puts) @daemon = stub_everything 'daemon', :daemonize => nil Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) @@ -16,38 +16,38 @@ describe "puppetqd" do end it "should ask Puppet::Application to parse Puppet configuration file" do - @puppetqd.should_parse_config?.should be_true + @queue.should_parse_config?.should be_true end it "should declare a main command" do - @puppetqd.should respond_to(:main) + @queue.should respond_to(:main) end it "should declare a preinit block" do - @puppetqd.should respond_to(:run_preinit) + @queue.should respond_to(:run_preinit) end describe "in preinit" do before :each do - @puppetqd.stubs(:trap) + @queue.stubs(:trap) end it "should catch INT" do - @puppetqd.expects(:trap).with { |arg,block| arg == :INT } + @queue.expects(:trap).with { |arg,block| arg == :INT } - @puppetqd.run_preinit + @queue.run_preinit end it "should init :verbose to false" do - @puppetqd.run_preinit + @queue.run_preinit - @puppetqd.options[:verbose].should be_false + @queue.options[:verbose].should be_false end it "should init :debug to false" do - @puppetqd.run_preinit + @queue.run_preinit - @puppetqd.options[:debug].should be_false + @queue.options[:debug].should be_false end it "should create a Daemon instance and copy ARGV to it" do @@ -55,7 +55,7 @@ describe "puppetqd" do daemon = mock("daemon") daemon.expects(:argv=).with("eh") Puppet::Daemon.expects(:new).returns daemon - @puppetqd.run_preinit + @queue.run_preinit end end @@ -63,20 +63,20 @@ describe "puppetqd" do [:debug, :verbose].each do |option| it "should declare handle_#{option} method" do - @puppetqd.should respond_to("handle_#{option}".to_sym) + @queue.should respond_to("handle_#{option}".to_sym) end it "should store argument value when calling handle_#{option}" do - @puppetqd.options.expects(:[]=).with(option, 'arg') - @puppetqd.send("handle_#{option}".to_sym, 'arg') + @queue.options.expects(:[]=).with(option, 'arg') + @queue.send("handle_#{option}".to_sym, 'arg') end end end describe "during setup" do before :each do - @puppetqd.options.stubs(:[]) - @puppetqd.daemon.stubs(:daemonize) + @queue.options.stubs(:[]) + @queue.daemon.stubs(:daemonize) Puppet.stubs(:info) Puppet.features.stubs(:stomp?).returns true Puppet::Resource::Catalog.stubs(:terminus_class=) @@ -87,27 +87,27 @@ describe "puppetqd" do it "should fail if the stomp feature is missing" do Puppet.features.expects(:stomp?).returns false - lambda { @puppetqd.run_setup }.should raise_error(ArgumentError) + lambda { @queue.run_setup }.should raise_error(ArgumentError) end it "should print puppet config if asked to in Puppet config" do - @puppetqd.stubs(:exit) + @queue.stubs(:exit) Puppet.settings.stubs(:print_configs?).returns(true) Puppet.settings.expects(:print_configs) - @puppetqd.run_setup + @queue.run_setup end it "should exit after printing puppet config if asked to in Puppet config" do Puppet.settings.stubs(:print_configs?).returns(true) - lambda { @puppetqd.run_setup }.should raise_error(SystemExit) + lambda { @queue.run_setup }.should raise_error(SystemExit) end it "should call setup_logs" do - @puppetqd.expects(:setup_logs) - @puppetqd.run_setup + @queue.expects(:setup_logs) + @queue.run_setup end describe "when setting up logs" do @@ -116,28 +116,28 @@ describe "puppetqd" do end it "should set log level to debug if --debug was passed" do - @puppetqd.options.stubs(:[]).with(:debug).returns(true) + @queue.options.stubs(:[]).with(:debug).returns(true) Puppet::Util::Log.expects(:level=).with(:debug) - @puppetqd.setup_logs + @queue.setup_logs end it "should set log level to info if --verbose was passed" do - @puppetqd.options.stubs(:[]).with(:verbose).returns(true) + @queue.options.stubs(:[]).with(:verbose).returns(true) Puppet::Util::Log.expects(:level=).with(:info) - @puppetqd.setup_logs + @queue.setup_logs end [:verbose, :debug].each do |level| it "should set console as the log destination with level #{level}" do - @puppetqd.options.stubs(:[]).with(level).returns(true) + @queue.options.stubs(:[]).with(level).returns(true) Puppet::Util::Log.expects(:newdestination).with(:console) - @puppetqd.setup_logs + @queue.setup_logs end end end @@ -145,28 +145,28 @@ describe "puppetqd" do it "should configure the Catalog class to use ActiveRecord" do Puppet::Resource::Catalog.expects(:terminus_class=).with(:active_record) - @puppetqd.run_setup + @queue.run_setup end it "should daemonize if needed" do Puppet.expects(:[]).with(:daemonize).returns(true) - @puppetqd.daemon.expects(:daemonize) + @queue.daemon.expects(:daemonize) - @puppetqd.run_setup + @queue.run_setup end end describe "when running" do before :each do - @puppetqd.stubs(:sleep_forever) + @queue.stubs(:sleep_forever) Puppet::Resource::Catalog::Queue.stubs(:subscribe) Thread.list.each { |t| t.stubs(:join) } end it "should subscribe to the queue" do Puppet::Resource::Catalog::Queue.expects(:subscribe) - @puppetqd.main + @queue.main end it "should log and save each catalog passed by the queue" do @@ -175,12 +175,12 @@ describe "puppetqd" do Puppet::Resource::Catalog::Queue.expects(:subscribe).yields(catalog) Puppet.expects(:notice).times(2) - @puppetqd.main + @queue.main end it "should join all of the running threads" do Thread.list.each { |t| t.expects(:join) } - @puppetqd.main + @queue.main end end end diff --git a/spec/unit/application/ralsh.rb b/spec/unit/application/resource.rb index b0fa3bdc2..98b4485ed 100755 --- a/spec/unit/application/ralsh.rb +++ b/spec/unit/application/resource.rb @@ -2,55 +2,55 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/application/ralsh' +require 'puppet/application/resource' -describe "ralsh" do +describe "resource" do before :each do - @ralsh = Puppet::Application[:ralsh] + @resource = Puppet::Application[:resource] Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) end it "should ask Puppet::Application to not parse Puppet configuration file" do - @ralsh.should_parse_config?.should be_false + @resource.should_parse_config?.should be_false end it "should declare a main command" do - @ralsh.should respond_to(:main) + @resource.should respond_to(:main) end it "should declare a host option" do - @ralsh.should respond_to(:handle_host) + @resource.should respond_to(:handle_host) end it "should declare a types option" do - @ralsh.should respond_to(:handle_types) + @resource.should respond_to(:handle_types) end it "should declare a param option" do - @ralsh.should respond_to(:handle_param) + @resource.should respond_to(:handle_param) end it "should declare a preinit block" do - @ralsh.should respond_to(:run_preinit) + @resource.should respond_to(:run_preinit) end describe "in preinit" do it "should set hosts to nil" do - @ralsh.run_preinit + @resource.run_preinit - @ralsh.host.should be_nil + @resource.host.should be_nil end it "should init extra_params to empty array" do - @ralsh.run_preinit + @resource.run_preinit - @ralsh.extra_params.should == [] + @resource.extra_params.should == [] end it "should load Facter facts" do Facter.expects(:loadfacts).once - @ralsh.run_preinit + @resource.run_preinit end end @@ -58,19 +58,19 @@ describe "ralsh" do [:debug, :verbose, :edit].each do |option| it "should declare handle_#{option} method" do - @ralsh.should respond_to("handle_#{option}".to_sym) + @resource.should respond_to("handle_#{option}".to_sym) end it "should store argument value when calling handle_#{option}" do - @ralsh.options.expects(:[]=).with(option, 'arg') - @ralsh.send("handle_#{option}".to_sym, 'arg') + @resource.options.expects(:[]=).with(option, 'arg') + @resource.send("handle_#{option}".to_sym, 'arg') end end it "should set options[:host] to given host" do - @ralsh.handle_host(:whatever) + @resource.handle_host(:whatever) - @ralsh.host.should == :whatever + @resource.host.should == :whatever end it "should load an display all types with types option" do @@ -78,17 +78,17 @@ describe "ralsh" do type2 = stub_everything 'type2', :name => :type2 Puppet::Type.stubs(:loadall) Puppet::Type.stubs(:eachtype).multiple_yields(type1,type2) - @ralsh.stubs(:exit) + @resource.stubs(:exit) - @ralsh.expects(:puts).with(['type1','type2']) - @ralsh.handle_types(nil) + @resource.expects(:puts).with(['type1','type2']) + @resource.handle_types(nil) end it "should add param to extra_params list" do - @ralsh.extra_params = [ :param1 ] - @ralsh.handle_param("whatever") + @resource.extra_params = [ :param1 ] + @resource.handle_param("whatever") - @ralsh.extra_params.should == [ :param1, :whatever ] + @resource.extra_params.should == [ :param1, :whatever ] end end @@ -103,30 +103,30 @@ describe "ralsh" do it "should set console as the log destination" do Puppet::Log.expects(:newdestination).with(:console) - @ralsh.run_setup + @resource.run_setup end it "should set log level to debug if --debug was passed" do - @ralsh.options.stubs(:[]).with(:debug).returns(true) + @resource.options.stubs(:[]).with(:debug).returns(true) Puppet::Log.expects(:level=).with(:debug) - @ralsh.run_setup + @resource.run_setup end it "should set log level to info if --verbose was passed" do - @ralsh.options.stubs(:[]).with(:debug).returns(false) - @ralsh.options.stubs(:[]).with(:verbose).returns(true) + @resource.options.stubs(:[]).with(:debug).returns(false) + @resource.options.stubs(:[]).with(:verbose).returns(true) Puppet::Log.expects(:level=).with(:info) - @ralsh.run_setup + @resource.run_setup end it "should Parse puppet config" do Puppet.expects(:parse_config) - @ralsh.run_setup + @resource.run_setup end end @@ -158,27 +158,27 @@ describe "ralsh" do it "should raise an error if no type is given" do push_args - lambda { @ralsh.main }.should raise_error + lambda { @resource.main }.should raise_error pop_args end it "should raise an error when editing a remote host" do - @ralsh.options.stubs(:[]).with(:edit).returns(true) - @ralsh.host = 'host' + @resource.options.stubs(:[]).with(:edit).returns(true) + @resource.host = 'host' - lambda { @ralsh.main }.should raise_error + lambda { @resource.main }.should raise_error end it "should raise an error if the type is not found" do Puppet::Type.stubs(:type).returns(nil) - lambda { @ralsh.main }.should raise_error + lambda { @resource.main }.should raise_error end describe "with a host" do before :each do - @ralsh.stubs(:puts) - @ralsh.host = 'host' + @resource.stubs(:puts) + @resource.host = 'host' @client = stub_everything 'client' @client.stubs(:read_cert).returns(true) @client.stubs(:instances).returns([]) @@ -187,39 +187,39 @@ describe "ralsh" do it "should connect to it" do Puppet::Network::Client.resource.expects(:new).with { |h| h[:Server] == 'host' }.returns(@client) - @ralsh.main + @resource.main end it "should raise an error if there are no certs" do @client.stubs(:read_cert).returns(nil) - lambda { @ralsh.main }.should raise_error + lambda { @resource.main }.should raise_error end it "should retrieve all the instances if there is no name" do @client.expects(:instances).returns([]) - @ralsh.main + @resource.main end it "should describe the given resource" do push_args('type','name') @client.expects(:describe).returns(stub_everything) - @ralsh.main + @resource.main pop_args end end describe "without a host" do before :each do - @ralsh.stubs(:puts) - @ralsh.host = nil + @resource.stubs(:puts) + @resource.host = nil end it "should retrieve all the instances if there is no name" do @type.expects(:instances).returns([]) - @ralsh.main + @resource.main end describe 'but with a given name' do @@ -236,7 +236,6 @@ describe "ralsh" do pending end - it "should create a stub instance if it doesn't exist" do pending end @@ -245,7 +244,7 @@ describe "ralsh" do push_args('type','name','param=temp') pending @object.expects(:[]=).with('param','temp') - @ralsh.main + @resource.main pop_args end end diff --git a/spec/unit/application/puppetmasterd.rb b/spec/unit/application/server.rb index f522fccc1..53de19f5b 100644 --- a/spec/unit/application/puppetmasterd.rb +++ b/spec/unit/application/server.rb @@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/application/puppetmasterd' +require 'puppet/application/server' describe "PuppetMaster" do before :each do - @puppetmasterd = Puppet::Application[:puppetmasterd] + @server_app = Puppet::Application[:server] @daemon = stub_everything 'daemon' Puppet::Daemon.stubs(:new).returns(@daemon) Puppet::Util::Log.stubs(:newdestination) @@ -21,40 +21,40 @@ describe "PuppetMaster" do end it "should ask Puppet::Application to parse Puppet configuration file" do - @puppetmasterd.should_parse_config?.should be_true + @server_app.should_parse_config?.should be_true end it "should declare a main command" do - @puppetmasterd.should respond_to(:main) + @server_app.should respond_to(:main) end it "should declare a parseonly command" do - @puppetmasterd.should respond_to(:parseonly) + @server_app.should respond_to(:parseonly) end it "should declare a compile command" do - @puppetmasterd.should respond_to(:compile) + @server_app.should respond_to(:compile) end it "should declare a preinit block" do - @puppetmasterd.should respond_to(:run_preinit) + @server_app.should respond_to(:run_preinit) end describe "during preinit" do before :each do - @puppetmasterd.stubs(:trap) + @server_app.stubs(:trap) end it "should catch INT" do - @puppetmasterd.stubs(:trap).with { |arg,block| arg == :INT } + @server_app.stubs(:trap).with { |arg,block| arg == :INT } - @puppetmasterd.run_preinit + @server_app.run_preinit end it "should create a Puppet Daemon" do Puppet::Daemon.expects(:new).returns(@daemon) - @puppetmasterd.run_preinit + @server_app.run_preinit end it "should give ARGV to the Daemon" do @@ -62,19 +62,19 @@ describe "PuppetMaster" do ARGV.stubs(:dup).returns(argv) @daemon.expects(:argv=).with(argv) - @puppetmasterd.run_preinit + @server_app.run_preinit end end [:debug,:verbose].each do |option| it "should declare handle_#{option} method" do - @puppetmasterd.should respond_to("handle_#{option}".to_sym) + @server_app.should respond_to("handle_#{option}".to_sym) end it "should store argument value when calling handle_#{option}" do - @puppetmasterd.options.expects(:[]=).with(option, 'arg') - @puppetmasterd.send("handle_#{option}".to_sym, 'arg') + @server_app.options.expects(:[]=).with(option, 'arg') + @server_app.send("handle_#{option}".to_sym, 'arg') end end @@ -92,13 +92,13 @@ describe "PuppetMaster" do it "should set the log destination with --logdest" do Puppet::Log.expects(:newdestination).with("console") - @puppetmasterd.handle_logdest("console") + @server_app.handle_logdest("console") end it "should put the setdest options to true" do - @puppetmasterd.options.expects(:[]=).with(:setdest,true) + @server_app.options.expects(:[]=).with(:setdest,true) - @puppetmasterd.handle_logdest("console") + @server_app.handle_logdest("console") end it "should parse the log destination from ARGV" do @@ -106,7 +106,7 @@ describe "PuppetMaster" do Puppet::Util::Log.expects(:newdestination).with("/my/file") - @puppetmasterd.parse_options + @server_app.parse_options end end @@ -120,78 +120,78 @@ describe "PuppetMaster" do Puppet::SSL::CertificateAuthority.stubs(:ca?) Puppet.settings.stubs(:use) - @puppetmasterd.options.stubs(:[]).with(any_parameters) + @server_app.options.stubs(:[]).with(any_parameters) end it "should set log level to debug if --debug was passed" do - @puppetmasterd.options.stubs(:[]).with(:debug).returns(true) + @server_app.options.stubs(:[]).with(:debug).returns(true) Puppet::Log.expects(:level=).with(:debug) - @puppetmasterd.run_setup + @server_app.run_setup end it "should set log level to info if --verbose was passed" do - @puppetmasterd.options.stubs(:[]).with(:verbose).returns(true) + @server_app.options.stubs(:[]).with(:verbose).returns(true) Puppet::Log.expects(:level=).with(:info) - @puppetmasterd.run_setup + @server_app.run_setup end it "should set console as the log destination if no --logdest and --daemonize" do - @puppetmasterd.stubs(:[]).with(:daemonize).returns(:false) + @server_app.stubs(:[]).with(:daemonize).returns(:false) Puppet::Log.expects(:newdestination).with(:syslog) - @puppetmasterd.run_setup + @server_app.run_setup end it "should set syslog as the log destination if no --logdest and not --daemonize" do Puppet::Log.expects(:newdestination).with(:syslog) - @puppetmasterd.run_setup + @server_app.run_setup end it "should set syslog as the log destination if --rack" do - @puppetmasterd.options.stubs(:[]).with(:rack).returns(:true) + @server_app.options.stubs(:[]).with(:rack).returns(:true) Puppet::Log.expects(:newdestination).with(:syslog) - @puppetmasterd.run_setup + @server_app.run_setup end it "should print puppet config if asked to in Puppet config" do - @puppetmasterd.stubs(:exit) + @server_app.stubs(:exit) Puppet.settings.stubs(:print_configs?).returns(true) Puppet.settings.expects(:print_configs) - @puppetmasterd.run_setup + @server_app.run_setup end it "should exit after printing puppet config if asked to in Puppet config" do Puppet.settings.stubs(:print_configs?).returns(true) - lambda { @puppetmasterd.run_setup }.should raise_error(SystemExit) + lambda { @server_app.run_setup }.should raise_error(SystemExit) end - it "should tell Puppet.settings to use :main,:ssl and :puppetmasterd category" do - Puppet.settings.expects(:use).with(:main,:puppetmasterd,:ssl) + it "should tell Puppet.settings to use :main,:ssl and :server_app category" do + Puppet.settings.expects(:use).with(:main,:server_app,:ssl) - @puppetmasterd.run_setup + @server_app.run_setup end it "should set node facst terminus to yaml" do Puppet::Node::Facts.expects(:terminus_class=).with(:yaml) - @puppetmasterd.run_setup + @server_app.run_setup end it "should cache class in yaml" do Puppet::Node.expects(:cache_class=).with(:yaml) - @puppetmasterd.run_setup + @server_app.run_setup end describe "with no ca" do @@ -199,7 +199,7 @@ describe "PuppetMaster" do it "should set the ca_location to none" do Puppet::SSL::Host.expects(:ca_location=).with(:none) - @puppetmasterd.run_setup + @server_app.run_setup end end @@ -213,19 +213,19 @@ describe "PuppetMaster" do it "should set the ca_location to local" do Puppet::SSL::Host.expects(:ca_location=).with(:local) - @puppetmasterd.run_setup + @server_app.run_setup end it "should tell Puppet.settings to use :ca category" do Puppet.settings.expects(:use).with(:ca) - @puppetmasterd.run_setup + @server_app.run_setup end it "should instantiate the CertificateAuthority singleton" do Puppet::SSL::CertificateAuthority.expects(:instance) - @puppetmasterd.run_setup + @server_app.run_setup end @@ -237,21 +237,21 @@ describe "PuppetMaster" do it "should dispatch to parseonly if parseonly is set" do Puppet.stubs(:[]).with(:parseonly).returns(true) - @puppetmasterd.options[:node] = nil + @server_app.options[:node] = nil - @puppetmasterd.get_command.should == :parseonly + @server_app.get_command.should == :parseonly end it "should dispatch to compile if called with --compile" do - @puppetmasterd.options[:node] = "foo" - @puppetmasterd.get_command.should == :compile + @server_app.options[:node] = "foo" + @server_app.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 + @server_app.options[:node] = nil - @puppetmasterd.get_command.should == :main + @server_app.get_command.should == :main end describe "the parseonly command" do @@ -260,7 +260,7 @@ describe "PuppetMaster" do Puppet.stubs(:[]).with(:manifest).returns("site.pp") @interpreter = stub_everything Puppet.stubs(:err) - @puppetmasterd.stubs(:exit) + @server_app.stubs(:exit) Puppet::Parser::Interpreter.stubs(:new).returns(@interpreter) end @@ -268,21 +268,21 @@ describe "PuppetMaster" do @interpreter.expects(:parser) - @puppetmasterd.parseonly + @server_app.parseonly end it "should exit with exit code 0 if no error" do - @puppetmasterd.expects(:exit).with(0) + @server_app.expects(:exit).with(0) - @puppetmasterd.parseonly + @server_app.parseonly end it "should exit with exit code 1 if error" do @interpreter.stubs(:parser).raises(Puppet::ParseError) - @puppetmasterd.expects(:exit).with(1) + @server_app.expects(:exit).with(1) - @puppetmasterd.parseonly + @server_app.parseonly end end @@ -293,56 +293,56 @@ describe "PuppetMaster" do Puppet.stubs(:[]).with(:manifest).returns("site.pp") @interpreter = stub_everything Puppet.stubs(:err) - @puppetmasterd.stubs(:exit) + @server_app.stubs(:exit) Puppet::Parser::Interpreter.stubs(:new).returns(@interpreter) Puppet.features.stubs(:pson?).returns true end it "should fail if pson isn't available" do Puppet.features.expects(:pson?).returns false - lambda { @puppetmasterd.compile }.should raise_error + lambda { @server_app.compile }.should raise_error end it "should compile a catalog for the specified node" do - @puppetmasterd.options[:node] = "foo" + @server_app.options[:node] = "foo" Puppet::Resource::Catalog.expects(:find).with("foo").returns Puppet::Resource::Catalog.new $stdout.stubs(:puts) - @puppetmasterd.compile + @server_app.compile end it "should render the catalog to pson and print the output" do - @puppetmasterd.options[:node] = "foo" + @server_app.options[:node] = "foo" catalog = Puppet::Resource::Catalog.new catalog.expects(:render).with(:pson).returns "mypson" Puppet::Resource::Catalog.expects(:find).returns catalog $stdout.expects(:puts).with("mypson") - @puppetmasterd.compile + @server_app.compile end it "should exit with error code 30 if no catalog can be found" do - @puppetmasterd.options[:node] = "foo" + @server_app.options[:node] = "foo" Puppet::Resource::Catalog.expects(:find).returns nil - @puppetmasterd.expects(:exit).with(30) + @server_app.expects(:exit).with(30) $stderr.expects(:puts) - @puppetmasterd.compile + @server_app.compile end it "should exit with error code 30 if there's a failure" do - @puppetmasterd.options[:node] = "foo" + @server_app.options[:node] = "foo" Puppet::Resource::Catalog.expects(:find).raises ArgumentError - @puppetmasterd.expects(:exit).with(30) + @server_app.expects(:exit).with(30) $stderr.expects(:puts) - @puppetmasterd.compile + @server_app.compile end end describe "the main command" do before :each do - @puppetmasterd.run_preinit + @server_app.run_preinit @server = stub_everything 'server' Puppet::Network::Server.stubs(:new).returns(@server) @app = stub_everything 'app' @@ -358,32 +358,32 @@ describe "PuppetMaster" do it "should create a Server" do Puppet::Network::Server.expects(:new) - @puppetmasterd.main + @server_app.main end it "should give the server to the daemon" do @daemon.expects(:server=).with(@server) - @puppetmasterd.main + @server_app.main end it "should create the server with the right XMLRPC handlers" do Puppet::Network::Server.expects(:new).with { |args| args[:xmlrpc_handlers] == [:Status, :FileServer, :Master, :Report, :Filebucket]} - @puppetmasterd.main + @server_app.main end it "should create the server with a :ca xmlrpc handler if needed" do Puppet.stubs(:[]).with(:ca).returns(true) Puppet::Network::Server.expects(:new).with { |args| args[:xmlrpc_handlers].include?(:CA) } - @puppetmasterd.main + @server_app.main end it "should generate a SSL cert for localhost" do Puppet::SSL::Host.expects(:localhost) - @puppetmasterd.main + @server_app.main end it "should make sure to *only* hit the CA for data" do @@ -391,7 +391,7 @@ describe "PuppetMaster" do Puppet::SSL::Host.expects(:ca_location=).with(:only) - @puppetmasterd.main + @server_app.main end it "should drop privileges if running as root" do @@ -399,7 +399,7 @@ describe "PuppetMaster" do Puppet::Util.expects(:chuser) - @puppetmasterd.main + @server_app.main end it "should daemonize if needed" do @@ -407,13 +407,13 @@ describe "PuppetMaster" do @daemon.expects(:daemonize) - @puppetmasterd.main + @server_app.main end it "should start the service" do @daemon.expects(:start) - @puppetmasterd.main + @server_app.main end describe "with --rack" do @@ -425,28 +425,28 @@ describe "PuppetMaster" do end it "it should create the app with REST and XMLRPC support" do - @puppetmasterd.options.stubs(:[]).with(:rack).returns(:true) + @server_app.options.stubs(:[]).with(:rack).returns(:true) Puppet::Network::HTTP::Rack.expects(:new).with { |args| args[:xmlrpc_handlers] == [:Status, :FileServer, :Master, :Report, :Filebucket] and args[:protocols] == [:rest, :xmlrpc] } - @puppetmasterd.main + @server_app.main end it "it should not start a daemon" do - @puppetmasterd.options.stubs(:[]).with(:rack).returns(:true) + @server_app.options.stubs(:[]).with(:rack).returns(:true) @daemon.expects(:start).never - @puppetmasterd.main + @server_app.main end it "it should return the app" do - @puppetmasterd.options.stubs(:[]).with(:rack).returns(:true) + @server_app.options.stubs(:[]).with(:rack).returns(:true) - app = @puppetmasterd.main + app = @server_app.main app.should equal(@app) end |