diff options
| author | Jacob Helwig <jacob@puppetlabs.com> | 2011-02-21 14:41:12 -0800 |
|---|---|---|
| committer | Jacob Helwig <jacob@puppetlabs.com> | 2011-02-21 14:41:12 -0800 |
| commit | 983c2420d47c83922a4417ec2b85af0740468029 (patch) | |
| tree | 1c96e6b743a4618d8016677ae1417a5091f0d26c /lib | |
| parent | 7e611714c56e3e28ff2077a024498acd26da0604 (diff) | |
| parent | 30fa41ddc3796e62a5bd1d0cf5116e14323992a3 (diff) | |
| download | puppet-983c2420d47c83922a4417ec2b85af0740468029.tar.gz puppet-983c2420d47c83922a4417ec2b85af0740468029.tar.xz puppet-983c2420d47c83922a4417ec2b85af0740468029.zip | |
Merge branch '2.6.x' into 2.6.next
* 2.6.x:
Updated CHANGELOG for 2.6.5rc5
(#6337) Fix Ruby warning on 1.8.6 about "future compatibility"
(#6353) Restore the ability to store paths in the filebucket
(#6126) Puppet inspect now reports status after run completes.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/application/inspect.rb | 116 | ||||
| -rw-r--r-- | lib/puppet/file_bucket/dipper.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/indirector/file_bucket_file/file.rb | 55 |
3 files changed, 104 insertions, 72 deletions
diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index 9e2aaed57..ce32c661c 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -98,79 +98,81 @@ Licensed under the GNU General Public License version 2 end def run_command - retrieval_starttime = Time.now + benchmark(:notice, "Finished inspection") do + retrieval_starttime = Time.now - unless catalog = Puppet::Resource::Catalog.find(Puppet[:certname]) - raise "Could not find catalog for #{Puppet[:certname]}" - end + unless catalog = Puppet::Resource::Catalog.find(Puppet[:certname]) + raise "Could not find catalog for #{Puppet[:certname]}" + end - @report.configuration_version = catalog.version + @report.configuration_version = catalog.version - inspect_starttime = Time.now - @report.add_times("config_retrieval", inspect_starttime - retrieval_starttime) + 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 + 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 + catalog.to_ral.resources.each do |ral_resource| + audited_attributes = ral_resource[:audit] + next unless audited_attributes - status = Puppet::Resource::Status.new(ral_resource) + status = Puppet::Resource::Status.new(ral_resource) - begin - audited_resource = ral_resource.to_resource - rescue StandardError => detail - puts detail.backtrace if Puppet[:trace] - ral_resource.err "Could not inspect #{ral_resource}; skipping: #{detail}" - audited_attributes.each do |name| - event = ral_resource.event( - :property => name, - :status => "failure", - :audited => true, - :message => "failed to inspect #{name}" - ) - status.add_event(event) - end - else - audited_attributes.each do |name| - next if audited_resource[name].nil? - # Skip :absent properties of :absent resources. Really, it would be nicer if the RAL returned nil for those, but it doesn't. ~JW - if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent + begin + audited_resource = ral_resource.to_resource + rescue StandardError => detail + puts detail.backtrace if Puppet[:trace] + ral_resource.err "Could not inspect #{ral_resource}; skipping: #{detail}" + audited_attributes.each do |name| event = ral_resource.event( - :previous_value => audited_resource[name], - :property => name, - :status => "audit", - :audited => true, - :message => "inspected value is #{audited_resource[name].inspect}" - ) + :property => name, + :status => "failure", + :audited => true, + :message => "failed to inspect #{name}" + ) status.add_event(event) end + else + audited_attributes.each do |name| + next if audited_resource[name].nil? + # Skip :absent properties of :absent resources. Really, it would be nicer if the RAL returned nil for those, but it doesn't. ~JW + if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent + event = ral_resource.event( + :previous_value => audited_resource[name], + :property => name, + :status => "audit", + :audited => true, + :message => "inspected value is #{audited_resource[name].inspect}" + ) + status.add_event(event) + end + end end - end - if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content) - path = ral_resource[:path] - if File.readable?(path) - begin - dipper.backup(path) - rescue StandardError => detail - Puppet.warning detail + if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content) + path = ral_resource[:path] + if File.readable?(path) + begin + dipper.backup(path) + rescue StandardError => detail + Puppet.warning detail + end end end + @report.add_resource_status(status) end - @report.add_resource_status(status) - end - finishtime = Time.now - @report.add_times("inspect", finishtime - inspect_starttime) - @report.finalize_report + finishtime = Time.now + @report.add_times("inspect", finishtime - inspect_starttime) + @report.finalize_report - begin - @report.save - rescue => detail - puts detail.backtrace if Puppet[:trace] - Puppet.err "Could not send report: #{detail}" + begin + @report.save + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Could not send report: #{detail}" + end end end end diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb index f4bef28a8..de4c01b78 100644 --- a/lib/puppet/file_bucket/dipper.rb +++ b/lib/puppet/file_bucket/dipper.rb @@ -34,11 +34,12 @@ class Puppet::FileBucket::Dipper contents = ::File.read(file) begin file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path) - dest_path = "#{@rest_path}#{file_bucket_file.name}" + files_original_path = absolutize_path(file) + dest_path = "#{@rest_path}#{file_bucket_file.name}#{files_original_path}" # Make a HEAD request for the file so that we don't waste time # uploading it if it already exists in the bucket. - unless Puppet::FileBucket::File.head("#{@rest_path}#{file_bucket_file.checksum_type}/#{file_bucket_file.checksum_data}") + unless Puppet::FileBucket::File.head("#{@rest_path}#{file_bucket_file.checksum_type}/#{file_bucket_file.checksum_data}#{files_original_path}") file_bucket_file.save(dest_path) end diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb index 8bea2d767..0fd8a914f 100644 --- a/lib/puppet/indirector/file_bucket_file/file.rb +++ b/lib/puppet/indirector/file_bucket_file/file.rb @@ -14,10 +14,12 @@ module Puppet::FileBucketFile end def find( request ) - checksum = request_to_checksum( request ) - file_path = path_for(request.options[:bucket_path], checksum, 'contents') + checksum, files_original_path = request_to_checksum_and_path( request ) + dir_path = path_for(request.options[:bucket_path], checksum) + file_path = ::File.join(dir_path, 'contents') return nil unless ::File.exists?(file_path) + return nil unless path_match(dir_path, files_original_path) if request.options[:diff_with] hash_protocol = sumtype(checksum) @@ -32,32 +34,47 @@ module Puppet::FileBucketFile end def head(request) - checksum = request_to_checksum(request) - file_path = path_for(request.options[:bucket_path], checksum, 'contents') - ::File.exists?(file_path) + checksum, files_original_path = request_to_checksum_and_path(request) + dir_path = path_for(request.options[:bucket_path], checksum) + + ::File.exists?(::File.join(dir_path, 'contents')) and path_match(dir_path, files_original_path) end def save( request ) instance = request.instance + checksum, files_original_path = request_to_checksum_and_path(request) - save_to_disk(instance) + save_to_disk(instance, files_original_path) instance.to_s end private - def save_to_disk( bucket_file ) + def path_match(dir_path, files_original_path) + return true unless files_original_path # if no path was provided, it's a match + paths_path = ::File.join(dir_path, 'paths') + return false unless ::File.exists?(paths_path) + ::File.open(paths_path) do |f| + f.each do |line| + return true if line.chomp == files_original_path + end + end + return false + end + + def save_to_disk( bucket_file, files_original_path ) filename = path_for(bucket_file.bucket_path, bucket_file.checksum_data, 'contents') - dirname = path_for(bucket_file.bucket_path, bucket_file.checksum_data) + dir_path = path_for(bucket_file.bucket_path, bucket_file.checksum_data) + paths_path = ::File.join(dir_path, 'paths') # If the file already exists, do nothing. if ::File.exist?(filename) verify_identical_file!(bucket_file) else # Make the directories if necessary. - unless ::File.directory?(dirname) + unless ::File.directory?(dir_path) Puppet::Util.withumask(0007) do - ::FileUtils.mkdir_p(dirname) + ::FileUtils.mkdir_p(dir_path) end end @@ -68,15 +85,27 @@ module Puppet::FileBucketFile ::File.open(filename, ::File::WRONLY|::File::CREAT, 0440) do |of| of.print bucket_file.contents end + ::File.open(paths_path, ::File::WRONLY|::File::CREAT, 0640) do |of| + # path will be written below + end + end + end + + unless path_match(dir_path, files_original_path) + ::File.open(paths_path, 'a') do |f| + f.puts(files_original_path) end end end - def request_to_checksum( request ) - checksum_type, checksum, path = request.key.split(/\//, 3) # Note: we ignore path if present. + def request_to_checksum_and_path( request ) + checksum_type, checksum, path = request.key.split(/\//, 3) + if path == '' # Treat "md5/<checksum>/" like "md5/<checksum>" + path = nil + end raise "Unsupported checksum type #{checksum_type.inspect}" if checksum_type != 'md5' raise "Invalid checksum #{checksum.inspect}" if checksum !~ /^[0-9a-f]{32}$/ - checksum + [checksum, path] end def path_for(bucket_path, digest, subfile = nil) |
