[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5rc1-120-g2247c80

Paul Berry paul at puppetlabs.com
Mon Feb 7 06:40:30 UTC 2011


The following commit has been merged in the upstream branch:
commit 1a6fab2aacbc1499a00a9451654073181435afa1
Author: Paul Berry <paul at puppetlabs.com>
Date:   Thu Jan 13 12:18:37 2011 -0800

    (#5171) Made "puppet inspect" upload audited files to a file bucket
    
    This only occurs if the new setting :archive_files is set.  Another
    new setting, :archive_file_server, can be used to specify the server
    that files should be uploaded to.
    
    Paired-with: Nick Lewis <nick at puppetlabs.com>

diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb
index f2e03b5..b4d2635 100644
--- a/lib/puppet/application/inspect.rb
+++ b/lib/puppet/application/inspect.rb
@@ -1,5 +1,6 @@
 require 'puppet'
 require 'puppet/application'
+require 'puppet/file_bucket/dipper'
 
 class Puppet::Application::Inspect < Puppet::Application
 
@@ -55,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
@@ -77,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 4521a59..400d59f 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 b3224d5..0c7b61f 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

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list