summaryrefslogtreecommitdiffstats
path: root/spec/unit/application
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-01-19 17:36:23 -0800
committerMatt Robinson <matt@puppetlabs.com>2011-01-19 17:36:23 -0800
commit6d9cae2e9ca6a56506f679db02ba9abb30a4df91 (patch)
tree854c260815825a8d5368296aecf7bc86f8ea8ff9 /spec/unit/application
parent27abd84611564ac573c5fde8abb6b98e6bd3d9b7 (diff)
parent517c6794606e9adde7f2912d3b949cfcc18a446a (diff)
downloadpuppet-6d9cae2e9ca6a56506f679db02ba9abb30a4df91.tar.gz
puppet-6d9cae2e9ca6a56506f679db02ba9abb30a4df91.tar.xz
puppet-6d9cae2e9ca6a56506f679db02ba9abb30a4df91.zip
Merge branch '2.6.x' into next
* 2.6.x: (21 commits) (#5900) Include ResourceStatus#failed in serialized reports (#5882) Added error-handling for bucketing files in puppet inspect (#5882) Added error-handling to puppet inspect when auditing (#5171) Made "puppet inspect" upload audited files to a file bucket Prep for #5171: Added a missing require to inspect application. Locked Puppet license to GPLv2 (#5838) Support paths as part of file bucket requests. (#5838) Improve the quality of file bucket specs. (#5838) Make file bucket dipper efficient when saving a file that already exists (#5838) Implemented the "head" method for FileBucketFile::File terminus. (#5838) Reworked file dipper spec to perform less stubbing. (#5838) Added support for HEAD requests to the indirector. (#5838) Refactored error handling logic into find_in_cache. (#5838) Refactored Puppet::Network::Rights#fail_on_deny maint: Remove unused Rakefile in spec directory (#5171) Made filebucket able to perform diffs (#5710) Removed unnecessary calls to insync? Prep for fixing #5710: Refactor stub provider in resource harness spec Maint: test partial resource failure maint: Inspect reports should have audited = true on events ... Manually Resolved Conflicts: lib/puppet/file_bucket/dipper.rb lib/puppet/indirector.rb lib/puppet/network/rest_authconfig.rb spec/unit/file_bucket/dipper_spec.rb spec/unit/file_bucket/file_spec.rb spec/unit/indirector_spec.rb
Diffstat (limited to 'spec/unit/application')
-rw-r--r--spec/unit/application/inspect_spec.rb178
1 files changed, 177 insertions, 1 deletions
diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb
index b931708c3..1d99c6ca9 100644
--- a/spec/unit/application/inspect_spec.rb
+++ b/spec/unit/application/inspect_spec.rb
@@ -6,8 +6,11 @@ require 'puppet/application/inspect'
require 'puppet/resource/catalog'
require 'puppet/indirector/catalog/yaml'
require 'puppet/indirector/report/rest'
+require 'puppet/indirector/file_bucket_file/rest'
describe Puppet::Application::Inspect do
+ include PuppetSpec::Files
+
before :each do
@inspect = Puppet::Application[:inspect]
end
@@ -29,7 +32,7 @@ describe Puppet::Application::Inspect do
describe "when executing" do
before :each do
Puppet[:report] = true
- Puppet::Util::Log.stubs(:newdestination)
+ @inspect.options[:logset] = true
Puppet::Transaction::Report::Rest.any_instance.stubs(:save)
@inspect.setup
end
@@ -72,6 +75,26 @@ describe Puppet::Application::Inspect do
properties.has_key?("target").should == false
end
+ it "should set audited to true for all events" do
+ catalog = Puppet::Resource::Catalog.new
+ file = Tempfile.new("foo")
+ resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
+ catalog.add_resource(resource)
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
+
+ events = nil
+
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
+ events = request.instance.resource_statuses.values.first.events
+ end
+
+ @inspect.run_command
+
+ events.each do |event|
+ event.audited.should == true
+ end
+ end
+
it "should not report irrelevent attributes if the resource is absent" do
catalog = Puppet::Resource::Catalog.new
file = Tempfile.new("foo")
@@ -93,6 +116,159 @@ describe Puppet::Application::Inspect do
end
properties.should == {"ensure" => :absent}
end
+
+ describe "when archiving to a bucket" do
+ before :each do
+ Puppet[:archive_files] = true
+ Puppet[:archive_file_server] = "filebucketserver"
+ @catalog = Puppet::Resource::Catalog.new
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(@catalog)
+ end
+
+ describe "when auditing files" do
+ before :each do
+ @file = tmpfile("foo")
+ @resource = Puppet::Resource.new(:file, @file, :parameters => {:audit => "content"})
+ @catalog.add_resource(@resource)
+ end
+
+ it "should send an existing file to the file bucket" do
+ File.open(@file, 'w') { |f| f.write('stuff') }
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).with do |request|
+ request.server == Puppet[:archive_file_server]
+ end.returns(false)
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).with do |request|
+ request.server == Puppet[:archive_file_server] and request.instance.contents == 'stuff'
+ end
+ @inspect.run_command
+ end
+
+ it "should not send unreadable files" do
+ File.open(@file, 'w') { |f| f.write('stuff') }
+ File.chmod(0, @file)
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
+ @inspect.run_command
+ end
+
+ it "should not try to send non-existent files" do
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
+ @inspect.run_command
+ end
+
+ it "should not try to send files whose content we are not auditing" do
+ @resource[:audit] = "group"
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
+ @inspect.run_command
+ end
+
+ it "should continue if bucketing a file fails" do
+ File.open(@file, 'w') { |f| f.write('stuff') }
+ Puppet::FileBucketFile::Rest.any_instance.stubs(:head).returns false
+ Puppet::FileBucketFile::Rest.any_instance.stubs(:save).raises "failure"
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
+ @report = request.instance
+ end
+
+ @inspect.run_command
+
+ @report.logs.count.should == 1
+ @report.logs.first.message.should =~ /Could not back up/
+ end
+ end
+
+ describe "when auditing non-files" do
+ before :each do
+ Puppet::Type.newtype(:stub_type) do
+ newparam(:name) do
+ desc "The name var"
+ isnamevar
+ end
+
+ newproperty(:content) do
+ desc "content"
+ def retrieve
+ :whatever
+ end
+ end
+ end
+
+ @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
+ @catalog.add_resource(@resource)
+ end
+
+ after :each do
+ Puppet::Type.rmtype(:stub_type)
+ end
+
+ it "should not try to send non-files" do
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
+ @inspect.run_command
+ end
+ end
+ end
+
+ describe "when there are failures" do
+ before :each do
+ Puppet::Type.newtype(:stub_type) do
+ newparam(:name) do
+ desc "The name var"
+ isnamevar
+ end
+
+ newproperty(:content) do
+ desc "content"
+ def retrieve
+ raise "failed"
+ end
+ end
+ end
+
+ @catalog = Puppet::Resource::Catalog.new
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(@catalog)
+
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
+ @report = request.instance
+ end
+ end
+
+ after :each do
+ Puppet::Type.rmtype(:stub_type)
+ end
+
+ it "should mark the report failed and create failed events for each property" do
+ @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
+ @catalog.add_resource(@resource)
+
+ @inspect.run_command
+
+ @report.status.should == "failed"
+ @report.logs.select{|log| log.message =~ /Could not inspect/}.count.should == 1
+ @report.resource_statuses.count.should == 1
+ @report.resource_statuses['Stub_type[foo]'].events.count.should == 1
+
+ event = @report.resource_statuses['Stub_type[foo]'].events.first
+ event.property.should == "content"
+ event.status.should == "failure"
+ event.audited.should == true
+ event.instance_variables.should_not include("@previous_value")
+ end
+
+ it "should continue to the next resource" do
+ @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
+ @other_resource = Puppet::Resource.new(:stub_type, 'bar', :parameters => {:audit => "all"})
+ @catalog.add_resource(@resource)
+ @catalog.add_resource(@other_resource)
+
+ @inspect.run_command
+
+ @report.resource_statuses.count.should == 2
+ @report.resource_statuses.keys.should =~ ['Stub_type[foo]', 'Stub_type[bar]']
+ end
+ end
end
after :all do