diff options
| author | Luke Kanies <luke@madstop.com> | 2009-01-22 16:05:43 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2009-02-06 18:08:40 -0600 |
| commit | 54faf7825bbffc5a4ca252389305dd23ae8d2d84 (patch) | |
| tree | c9d059cb83b3f0de52ddc52c33278eb53dd2edd7 /spec/unit/agent | |
| parent | 9d76b70c07c86f0041a0e6a1537227de1b619017 (diff) | |
| download | puppet-54faf7825bbffc5a4ca252389305dd23ae8d2d84.tar.gz puppet-54faf7825bbffc5a4ca252389305dd23ae8d2d84.tar.xz puppet-54faf7825bbffc5a4ca252389305dd23ae8d2d84.zip | |
Moving fact and plugin handling into modules
This doesn't change functionality, it just simplifies
the agent class.
I've also started the work to get the catalog handling
done using REST/the Indirector.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/agent')
| -rwxr-xr-x | spec/unit/agent/downloader.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/agent/fact_handler.rb | 117 | ||||
| -rwxr-xr-x | spec/unit/agent/plugin_handler.rb | 100 |
3 files changed, 218 insertions, 1 deletions
diff --git a/spec/unit/agent/downloader.rb b/spec/unit/agent/downloader.rb index 6b07e5bb4..28c5d030f 100755 --- a/spec/unit/agent/downloader.rb +++ b/spec/unit/agent/downloader.rb @@ -99,7 +99,7 @@ describe Puppet::Agent::Downloader do @dler.expects(:file).returns file - Puppet::Node::Catalog.expects(:new).returns catalog + Puppet::Resource::Catalog.expects(:new).returns catalog catalog.expects(:add_resource).with(file) @dler.catalog.should equal(catalog) diff --git a/spec/unit/agent/fact_handler.rb b/spec/unit/agent/fact_handler.rb new file mode 100755 index 000000000..b58f55ebc --- /dev/null +++ b/spec/unit/agent/fact_handler.rb @@ -0,0 +1,117 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/agent' +require 'puppet/agent/fact_handler' + +class FactHandlerTester + include Puppet::Agent::FactHandler +end + +describe Puppet::Agent::FactHandler do + before do + @facthandler = FactHandlerTester.new + end + + it "should have a method for downloading fact plugins" do + @facthandler.should respond_to(:download_fact_plugins) + end + + it "should have a boolean method for determining whether fact plugins should be downloaded" do + @facthandler.should respond_to(:download_fact_plugins?) + end + + it "should download fact plugins when :factsync is true" do + Puppet.settings.expects(:value).with(:factsync).returns true + @facthandler.should be_download_fact_plugins + end + + it "should not download fact plugins when :factsync is false" do + Puppet.settings.expects(:value).with(:factsync).returns false + @facthandler.should_not be_download_fact_plugins + end + + it "should not download fact plugins when downloading is disabled" do + Puppet::Agent::Downloader.expects(:new).never + @facthandler.expects(:download_fact_plugins?).returns false + @facthandler.download_fact_plugins + end + + it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download fact plugins when downloading is enabled" do + downloader = mock 'downloader' + + Puppet.settings.expects(:value).with(:factsource).returns "fsource" + Puppet.settings.expects(:value).with(:factdest).returns "fdest" + Puppet.settings.expects(:value).with(:factsignore).returns "fignore" + + Puppet::Agent::Downloader.expects(:new).with("fact", "fsource", "fdest", "fignore").returns downloader + + downloader.expects(:evaluate) + + @facthandler.expects(:download_fact_plugins?).returns true + @facthandler.download_fact_plugins + end + + it "should have a method for uploading facts" do + @facthandler.should respond_to(:upload_facts) + end + + it "should reload Facter and find local facts when asked to upload facts" do + @facthandler.expects(:reload_facter) + + Puppet.settings.expects(:value).with(:certname).returns "myhost" + Puppet::Node::Facts.expects(:find).with("myhost") + + @facthandler.upload_facts + end + + describe "when reloading Facter" do + before do + Facter.stubs(:clear) + Facter.stubs(:load) + Facter.stubs(:loadfacts) + end + + it "should clear Facter" do + Facter.expects(:clear) + @facthandler.reload_facter + end + + it "should load all Facter facts" do + Facter.expects(:loadfacts) + @facthandler.reload_facter + end + + it "should load all Puppet Fact plugins" do + @facthandler.expects(:load_fact_plugins) + @facthandler.reload_facter + end + end + + it "should load each directory in the Fact path when loading fact plugins" do + Puppet.settings.expects(:value).with(:factpath).returns("one%stwo" % File::PATH_SEPARATOR) + + @facthandler.expects(:load_facts_in_dir).with("one") + @facthandler.expects(:load_facts_in_dir).with("two") + + @facthandler.load_fact_plugins + end + + it "should skip files when asked to load a directory" do + FileTest.expects(:directory?).with("myfile").returns false + + @facthandler.load_facts_in_dir("myfile") + end + + it "should load each ruby file when asked to load a directory" do + FileTest.expects(:directory?).with("mydir").returns true + Dir.expects(:chdir).with("mydir").yields + + Dir.expects(:glob).with("*.rb").returns %w{a.rb b.rb} + + @facthandler.expects(:load).with("a.rb") + @facthandler.expects(:load).with("b.rb") + + @facthandler.load_facts_in_dir("mydir") + end +end diff --git a/spec/unit/agent/plugin_handler.rb b/spec/unit/agent/plugin_handler.rb new file mode 100755 index 000000000..44603bc6c --- /dev/null +++ b/spec/unit/agent/plugin_handler.rb @@ -0,0 +1,100 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/agent' +require 'puppet/agent/plugin_handler' + +class PluginHandlerTester + include Puppet::Agent::PluginHandler +end + +describe Puppet::Agent::PluginHandler do + before do + @pluginhandler = PluginHandlerTester.new + end + + it "should have a method for downloading plugins" do + @pluginhandler.should respond_to(:download_plugins) + end + + it "should have a boolean method for determining whether plugins should be downloaded" do + @pluginhandler.should respond_to(:download_plugins?) + end + + it "should download plugins when :pluginsync is true" do + Puppet.settings.expects(:value).with(:pluginsync).returns true + @pluginhandler.should be_download_plugins + end + + it "should not download plugins when :pluginsync is false" do + Puppet.settings.expects(:value).with(:pluginsync).returns false + @pluginhandler.should_not be_download_plugins + end + + it "should not download plugins when downloading is disabled" do + Puppet::Agent::Downloader.expects(:new).never + @pluginhandler.expects(:download_plugins?).returns false + @pluginhandler.download_plugins + end + + it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download plugins when downloading is enabled" do + downloader = mock 'downloader' + + Puppet.settings.expects(:value).with(:pluginsource).returns "psource" + Puppet.settings.expects(:value).with(:plugindest).returns "pdest" + Puppet.settings.expects(:value).with(:pluginsignore).returns "pignore" + + Puppet::Agent::Downloader.expects(:new).with("plugin", "psource", "pdest", "pignore").returns downloader + + downloader.expects(:evaluate).returns [] + + @pluginhandler.expects(:download_plugins?).returns true + @pluginhandler.download_plugins + end + + it "should be able to load plugins" do + @pluginhandler.should respond_to(:load_plugin) + end + + it "should load each downloaded file" do + downloader = mock 'downloader' + + Puppet::Agent::Downloader.expects(:new).returns downloader + + downloader.expects(:evaluate).returns %w{one two} + + @pluginhandler.expects(:download_plugins?).returns true + + @pluginhandler.expects(:load_plugin).with("one") + @pluginhandler.expects(:load_plugin).with("two") + + @pluginhandler.download_plugins + end + + it "should load plugins when asked to do so" do + @pluginhandler.expects(:load).with("foo") + + @pluginhandler.load_plugin("foo") + end + + it "should not try to load directories" do + FileTest.expects(:directory?).with("foo").returns true + @pluginhandler.expects(:load).never + + @pluginhandler.load_plugin("foo") + end + + it "should warn but not fail if loading a file raises an exception" do + @pluginhandler.expects(:load).with("foo").raises "eh" + + Puppet.expects(:err) + @pluginhandler.load_plugin("foo") + end + + it "should warn but not fail if loading a file raises a LoadError" do + @pluginhandler.expects(:load).with("foo").raises LoadError.new("eh") + + Puppet.expects(:err) + @pluginhandler.load_plugin("foo") + end +end |
