summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-01-13 14:33:40 -0800
committerPaul Berry <paul@puppetlabs.com>2011-01-13 14:33:40 -0800
commit8c60cebababafbacf031a4ad842a615e82910cf0 (patch)
tree9615f8b92976fbf90fd55aaa2a077a12237dd830
parent2274d5104f6e413a2b8899a3c3111a17bbb2f4d7 (diff)
parent1a6fab2aacbc1499a00a9451654073181435afa1 (diff)
downloadpuppet-8c60cebababafbacf031a4ad842a615e82910cf0.tar.gz
puppet-8c60cebababafbacf031a4ad842a615e82910cf0.tar.xz
puppet-8c60cebababafbacf031a4ad842a615e82910cf0.zip
Merge branch 'ticket/2.6.next/5171-upload-files-during-inspect' into 2.6.next
* ticket/2.6.next/5171-upload-files-during-inspect: (#5171) Made "puppet inspect" upload audited files to a file bucket Prep for #5171: Added a missing require to inspect application.
-rw-r--r--lib/puppet/application/inspect.rb12
-rw-r--r--lib/puppet/defaults.rb5
-rw-r--r--spec/unit/application/inspect_spec.rb84
3 files changed, 101 insertions, 0 deletions
diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb
index 07ee4c317..b4d263545 100644
--- a/lib/puppet/application/inspect.rb
+++ b/lib/puppet/application/inspect.rb
@@ -1,4 +1,6 @@
+require 'puppet'
require 'puppet/application'
+require 'puppet/file_bucket/dipper'
class Puppet::Application::Inspect < Puppet::Application
@@ -54,6 +56,10 @@ class Puppet::Application::Inspect < Puppet::Application
inspect_starttime = Time.now
@report.add_times("config_retrieval", inspect_starttime - retrieval_starttime)
+ if Puppet[:archive_files]
+ dipper = Puppet::FileBucket::Dipper.new(:Server => Puppet[:archive_file_server])
+ end
+
catalog.to_ral.resources.each do |ral_resource|
audited_attributes = ral_resource[:audit]
next unless audited_attributes
@@ -76,6 +82,12 @@ class Puppet::Application::Inspect < Puppet::Application
end
end
@report.add_resource_status(status)
+ if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content)
+ path = ral_resource[:path]
+ if File.readable?(path)
+ dipper.backup(path)
+ end
+ end
end
finishtime = Time.now
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 4521a5901..400d59f15 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -598,6 +598,11 @@ module Puppet
compression, but if it supports it, this setting might reduce performance on high-speed LANs."]
)
+ setdefaults(:inspect,
+ :archive_files => [false, "During an inspect run, whether to archive files whose contents are audited to a file bucket."],
+ :archive_file_server => ["$server", "During an inspect run, the file bucket server to archive files to if archive_files is set."]
+ )
+
# Plugin information.
setdefaults(
diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb
index b3224d577..0c7b61f59 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
@@ -113,6 +116,87 @@ 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
+ pending "see bug #5882"
+ 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
+ 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
end
after :all do