summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/defaults.rb9
-rw-r--r--lib/puppet/file_collection.rb30
-rw-r--r--lib/puppet/file_collection/lookup.rb20
-rw-r--r--lib/puppet/indirector/node/ldap.rb114
-rw-r--r--lib/puppet/parser/ast.rb7
-rw-r--r--lib/puppet/parser/ast/leaf.rb2
-rw-r--r--lib/puppet/parser/ast/resource_override.rb4
-rw-r--r--lib/puppet/parser/resource.rb6
-rw-r--r--lib/puppet/parser/resource/param.rb6
-rw-r--r--lib/puppet/parser/resource/reference.rb5
-rw-r--r--lib/puppet/property/list.rb6
-rw-r--r--lib/puppet/provider/augeas/augeas.rb119
-rw-r--r--lib/puppet/provider/nameservice/directoryservice.rb4
-rw-r--r--lib/puppet/provider/service/gentoo.rb2
-rwxr-xr-xlib/puppet/provider/service/redhat.rb8
-rw-r--r--lib/puppet/provider/ssh_authorized_key/parsed.rb33
-rw-r--r--lib/puppet/provider/user/useradd.rb2
-rw-r--r--lib/puppet/rails/host.rb54
-rw-r--r--lib/puppet/reference/report.rb1
-rw-r--r--lib/puppet/transaction.rb2
-rw-r--r--lib/puppet/type.rb4
-rw-r--r--lib/puppet/type/augeas.rb34
-rwxr-xr-xlib/puppet/type/file/checksum.rb42
-rw-r--r--lib/puppet/type/ssh_authorized_key.rb14
-rw-r--r--lib/puppet/util/selinux.rb4
25 files changed, 365 insertions, 167 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 06469431d..fcd4346fb 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -89,8 +89,17 @@ module Puppet
:path => {:default => "none",
:desc => "The shell search path. Defaults to whatever is inherited
from the parent process.",
+ :call_on_define => true, # Call our hook with the default value, so we always get the libdir set.
:hook => proc do |value|
ENV["PATH"] = value unless value == "none"
+
+ paths = ENV["PATH"].split(File::PATH_SEPARATOR)
+ %w{/usr/sbin /sbin}.each do |path|
+ unless paths.include?(path)
+ ENV["PATH"] += File::PATH_SEPARATOR + path
+ end
+ end
+ value
end
},
:libdir => {:default => "$vardir/lib",
diff --git a/lib/puppet/file_collection.rb b/lib/puppet/file_collection.rb
new file mode 100644
index 000000000..7db2600c0
--- /dev/null
+++ b/lib/puppet/file_collection.rb
@@ -0,0 +1,30 @@
+# A simple way to turn file names into singletons,
+# so we don't have tons of copies of each file path around.
+class Puppet::FileCollection
+ require 'puppet/file_collection/lookup'
+
+ def self.collection
+ @collection
+ end
+
+ def initialize
+ @paths = []
+ @inverse = {}
+ end
+
+ def index(path)
+ if i = @inverse[path]
+ return i
+ else
+ @paths << path
+ i = @inverse[path] = @paths.length - 1
+ return i
+ end
+ end
+
+ def path(index)
+ @paths[index]
+ end
+
+ @collection = self.new
+end
diff --git a/lib/puppet/file_collection/lookup.rb b/lib/puppet/file_collection/lookup.rb
new file mode 100644
index 000000000..ddb0c8431
--- /dev/null
+++ b/lib/puppet/file_collection/lookup.rb
@@ -0,0 +1,20 @@
+require 'puppet/file_collection'
+
+# A simple module for looking up file paths and indexes
+# in a file collection.
+module Puppet::FileCollection::Lookup
+ attr_accessor :line, :file_index
+
+ def file_collection
+ Puppet::FileCollection.collection
+ end
+
+ def file=(path)
+ @file_index = file_collection.index(path)
+ end
+
+ def file
+ return nil unless file_index
+ file_collection.path(file_index)
+ end
+end
diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb
index 01010a2af..ab5d47b1c 100644
--- a/lib/puppet/indirector/node/ldap.rb
+++ b/lib/puppet/indirector/node/ldap.rb
@@ -81,45 +81,10 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
def entry2hash(entry)
result = {}
result[:name] = entry.dn.split(',')[0].split("=")[1]
- if pattr = parent_attribute
- if values = entry.vals(pattr)
- if values.length > 1
- raise Puppet::Error,
- "Node entry %s specifies more than one parent: %s" % [entry.dn, values.inspect]
- end
- unless values.empty?
- result[:parent] = values.shift
- end
- end
- end
-
- result[:classes] = []
- class_attributes.each { |attr|
- if values = entry.vals(attr)
- values.each do |v| result[:classes] << v end
- end
- }
- result[:classes].uniq!
-
- result[:stacked] = []
- stacked_params = stacked_attributes
- stacked_params.each { |attr|
- if values = entry.vals(attr)
- result[:stacked] = result[:stacked] + values
- end
- }
-
-
- result[:parameters] = entry.to_hash.inject({}) do |hash, ary|
- unless stacked_params.include?(ary[0]) # don't add our stacked parameters to the main param list
- if ary[1].length == 1
- hash[ary[0]] = ary[1].shift
- else
- hash[ary[0]] = ary[1]
- end
- end
- hash
- end
+ result[:parent] = get_parent_from_entry(entry) if parent_attribute
+ result[:classes] = get_classes_from_entry(entry)
+ result[:stacked] = get_stacked_values_from_entry(entry)
+ result[:parameters] = get_parameters_from_entry(entry)
result[:environment] = result[:parameters]["environment"] if result[:parameters]["environment"]
@@ -138,6 +103,8 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
end
end
+ result[:parameters] = convert_parameters(result[:parameters])
+
result
end
@@ -178,6 +145,29 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
node.environment = information[:environment] if information[:environment]
end
+ def convert_parameters(parameters)
+ result = {}
+ parameters.each do |param, value|
+ if value.is_a?(Array)
+ result[param] = value.collect { |v| convert(v) }
+ else
+ result[param] = convert(value)
+ end
+ end
+ result
+ end
+
+ # Convert any values if necessary.
+ def convert(value)
+ case value
+ when Integer, Fixnum, Bignum; value
+ when "true"; true
+ when "false"; false
+ else
+ value
+ end
+ end
+
# Find information for our parent and merge it into the current info.
def find_and_merge_parent(parent, information)
unless parent_info = name2hash(parent)
@@ -224,4 +214,50 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
return info
end
+
+ def get_classes_from_entry(entry)
+ result = class_attributes.inject([]) do |array, attr|
+ if values = entry.vals(attr)
+ values.each do |v| array << v end
+ end
+ array
+ end
+ result.uniq
+ end
+
+ def get_parameters_from_entry(entry)
+ stacked_params = stacked_attributes
+ entry.to_hash.inject({}) do |hash, ary|
+ unless stacked_params.include?(ary[0]) # don't add our stacked parameters to the main param list
+ if ary[1].length == 1
+ hash[ary[0]] = ary[1].shift
+ else
+ hash[ary[0]] = ary[1]
+ end
+ end
+ hash
+ end
+ end
+
+ def get_parent_from_entry(entry)
+ pattr = parent_attribute
+
+ return nil unless values = entry.vals(pattr)
+
+ if values.length > 1
+ raise Puppet::Error,
+ "Node entry %s specifies more than one parent: %s" % [entry.dn, values.inspect]
+ end
+ return nil if values.empty?
+ return values.shift
+ end
+
+ def get_stacked_values_from_entry(entry)
+ stacked_attributes.inject([]) do |result, attr|
+ if values = entry.vals(attr)
+ result += values
+ end
+ result
+ end
+ end
end
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
index 303d75bac..ab23dd1f8 100644
--- a/lib/puppet/parser/ast.rb
+++ b/lib/puppet/parser/ast.rb
@@ -2,6 +2,7 @@
require 'puppet'
require 'puppet/util/autoload'
+require 'puppet/file_collection/lookup'
# The base class for all of the objects that make up the parse trees.
# Handles things like file name, line #, and also does the initialization
@@ -10,11 +11,13 @@ class Puppet::Parser::AST
# Do this so I don't have to type the full path in all of the subclasses
AST = Puppet::Parser::AST
+ include Puppet::FileCollection::Lookup
+
include Puppet::Util::Errors
include Puppet::Util::MethodHelper
include Puppet::Util::Docs
- attr_accessor :line, :file, :parent, :scope
+ attr_accessor :parent, :scope
# don't fetch lexer comment by default
def use_docs
@@ -82,8 +85,6 @@ class Puppet::Parser::AST
# method for them. This is probably pretty inefficient and should
# likely be changed at some point.
def initialize(args)
- @file = nil
- @line = nil
set_options(args)
end
end
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index c545c1e47..dba9812a7 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -36,7 +36,7 @@ class Puppet::Parser::AST
# Interpolate the string looking for variables, and then return
# the result.
def evaluate(scope)
- return scope.strinterp(@value, @file, @line)
+ return scope.strinterp(@value, file, line)
end
end
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
index 5c4a2410f..f8cf3a81e 100644
--- a/lib/puppet/parser/ast/resource_override.rb
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -40,8 +40,8 @@ class Puppet::Parser::AST
:type => r.type,
:title => r.title,
:params => params,
- :file => @file,
- :line => @line,
+ :file => file,
+ :line => line,
:source => scope.source,
:scope => scope
)
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 47dc798b3..e016a3047 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -4,13 +4,17 @@ class Puppet::Parser::Resource
require 'puppet/parser/resource/param'
require 'puppet/parser/resource/reference'
require 'puppet/util/tagging'
+ require 'puppet/file_collection/lookup'
+
+ include Puppet::FileCollection::Lookup
+
include Puppet::Util
include Puppet::Util::MethodHelper
include Puppet::Util::Errors
include Puppet::Util::Logging
include Puppet::Util::Tagging
- attr_accessor :source, :line, :file, :scope, :rails_id
+ attr_accessor :source, :scope, :rails_id
attr_accessor :virtual, :override, :translated
attr_reader :exported, :evaluated, :params
diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb
index 1a5cfe8fb..7ce58f4c4 100644
--- a/lib/puppet/parser/resource/param.rb
+++ b/lib/puppet/parser/resource/param.rb
@@ -1,10 +1,14 @@
+require 'puppet/file_collection/lookup'
+
# The parameters we stick in Resources.
class Puppet::Parser::Resource::Param
- attr_accessor :name, :value, :source, :line, :file, :add
+ attr_accessor :name, :value, :source, :add
include Puppet::Util
include Puppet::Util::Errors
include Puppet::Util::MethodHelper
+ include Puppet::FileCollection::Lookup
+
def initialize(hash)
set_options(hash)
requiredopts(:name, :value, :source)
diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb
index a37f8400d..cf7e997d8 100644
--- a/lib/puppet/parser/resource/reference.rb
+++ b/lib/puppet/parser/resource/reference.rb
@@ -1,7 +1,10 @@
-require 'puppet/resource/reference'
+# A reference to a resource. Mostly just the type and title.
+require 'puppet/resource_reference'
+require 'puppet/file_collection/lookup'
# A reference to a resource. Mostly just the type and title.
class Puppet::Parser::Resource::Reference < Puppet::Resource::Reference
+ include Puppet::FileCollection::Lookup
include Puppet::Util::MethodHelper
include Puppet::Util::Errors
diff --git a/lib/puppet/property/list.rb b/lib/puppet/property/list.rb
index 0c933f164..b7db8b42a 100644
--- a/lib/puppet/property/list.rb
+++ b/lib/puppet/property/list.rb
@@ -10,7 +10,11 @@ module Puppet
end
def is_to_s(currentvalue)
- currentvalue.join(delimiter)
+ if currentvalue == :absent
+ return "absent"
+ else
+ return currentvalue.join(delimiter)
+ end
end
def membership
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index efa8c2a3c..841bdc6c1 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -20,13 +20,17 @@
require 'augeas' if Puppet.features.augeas?
Puppet::Type.type(:augeas).provide(:augeas) do
-#class Puppet::Provider::Augeas < Puppet::Provider
include Puppet::Util
confine :true => Puppet.features.augeas?
has_features :parse_commands, :need_to_run?,:execute_changes
+ SAVE_NOOP = "noop"
+ SAVE_OVERWRITE = "overwrite"
+
+ attr_accessor :aug
+
# Extracts an 2 dimensional array of commands which are in the
# form of command path value.
# The input can be
@@ -72,13 +76,29 @@ Puppet::Type.type(:augeas).provide(:augeas) do
return commands
end
+
def open_augeas
- flags = 0
- (flags = 1 << 2 ) if self.resource[:type_check] == :true
- root = self.resource[:root]
- load_path = self.resource[:load_path]
- debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
- Augeas.open(root, load_path,flags)
+ if (@aug.nil?)
+ flags = 0
+ (flags = 1 << 2 ) if self.resource[:type_check] == :true
+ root = self.resource[:root]
+ load_path = self.resource[:load_path]
+ debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
+ @aug = Augeas.open(root, load_path,flags)
+
+ if (self.get_augeas_version() >= "0.3.6")
+ debug("Augeas version #{self.get_augeas_version()} is installed")
+ end
+ end
+ @aug
+ end
+
+ def close_augeas
+ if (!@aug.nil?)
+ @aug.close()
+ debug("Closed the augeas connection")
+ @aug = nil;
+ end
end
# Used by the need_to_run? method to process get filters. Returns
@@ -95,8 +115,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
arg = cmd_array.join(" ")
#check the value in augeas
- aug = open_augeas()
- result = aug.get(path) || ''
+ result = @aug.get(path) || ''
unless result.nil?
case comparator
when "!="
@@ -124,10 +143,9 @@ Puppet::Type.type(:augeas).provide(:augeas) do
verb = cmd_array.shift()
#Get the values from augeas
- aug = open_augeas()
- result = aug.match(path) || ''
+ result = @aug.match(path) || ''
# Now do the work
- if (!result.nil?)
+ unless (result.nil?)
case verb
when "size"
fail("Invalid command: #{cmd_array.join(" ")}") if cmd_array.length != 2
@@ -150,9 +168,24 @@ Puppet::Type.type(:augeas).provide(:augeas) do
return_value
end
+ def get_augeas_version
+ return @aug.get("/augeas/version") || ""
+ end
+
+ def set_augeas_save_mode(mode)
+ return @aug.set("/augeas/save", mode)
+ end
+
+ def files_changed?
+ saved_files = @aug.match("/augeas/events/saved")
+ return saved_files.size() > 0
+ end
+
# Determines if augeas acutally needs to run.
def need_to_run?
+ force = resource[:force]
return_value = true
+ self.open_augeas()
filter = resource[:onlyif]
unless (filter == "")
cmd_array = filter.split
@@ -168,15 +201,53 @@ Puppet::Type.type(:augeas).provide(:augeas) do
fail("Error sending command '#{command}' with params #{cmd_array[1..-1].inspect}/#{e.message}")
end
end
- return_value
+
+ unless (force)
+ # If we have a verison of augeas which is at least 0.3.6 then we
+ # can make the changes now, see if changes were made, and
+ # actually do the save.
+ if ((return_value) and (self.get_augeas_version() >= "0.3.6"))
+ debug("Will attempt to save and only run if files changed")
+ self.set_augeas_save_mode(SAVE_NOOP)
+ self.do_execute_changes()
+ save_result = @aug.save()
+ saved_files = @aug.match("/augeas/events/saved")
+ if ((save_result) and (not files_changed?))
+ debug("Skipping becuase no files were changed")
+ return_value = false
+ else
+ debug("Files changed, should execute")
+ end
+ end
+ end
+ self.close_augeas()
+ return return_value
end
- # Actually execute the augeas changes.
def execute_changes
- aug = open_augeas
- commands = resource[:changes]
+ # Re-connect to augeas, and re-execute the changes
+ self.open_augeas()
+ if (self.get_augeas_version() >= "0.3.6")
+ self.set_augeas_save_mode(SAVE_OVERWRITE)
+ end
+
+ self.do_execute_changes()
+
+ success = @aug.save()
+ if (success != true)
+ fail("Save failed with return code #{success}")
+ end
+ self.close_augeas()
+
+ return :executed
+ end
+
+ # Actually execute the augeas changes.
+ def do_execute_changes
+ commands = resource[:changes].clone()
context = resource[:context]
commands.each do |cmd_array|
+ cmd_array = cmd_array.clone()
fail("invalid command #{cmd_array.join[" "]}") if cmd_array.length < 2
command = cmd_array[0]
cmd_array.shift()
@@ -192,23 +263,22 @@ Puppet::Type.type(:augeas).provide(:augeas) do
aug.rm(cmd_array[0])
when "clear"
cmd_array[0]=File.join(context, cmd_array[0])
- debug("sending command '#{command}' with params #{cmd_array.inspect}")
- aug.clear(cmd_array[0])
+ debug("sending command '#{command}' with params #{cmd_array.inspect}")
+ @aug.clear(cmd_array[0])
when "insert", "ins"
-
ext_array = cmd_array[1].split(" ") ;
if cmd_array.size < 2 or ext_array.size < 2
fail("ins requires 3 parameters")
end
label = cmd_array[0]
where = ext_array[0]
- path = File.join(context, ext_array[1])
+ path = File.join(context, ext_array[1])
case where
when "before"; before = true
when "after"; before = false
else fail("Invalid value '#{where}' for where param")
end
- debug("sending command '#{command}' with params #{[label, where, path].inspect()}")
+ debug("sending command '#{command}' with params #{[label, where, path].inspect()}")
aug.insert(path, label, before)
else fail("Command '#{command}' is not supported")
end
@@ -216,12 +286,5 @@ Puppet::Type.type(:augeas).provide(:augeas) do
fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}")
end
end
- success = aug.save()
- if (success != true)
- fail("Save failed with return code #{success}")
- end
-
- return :executed
end
-
end
diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb
index 07b01bbe0..cd1e442d5 100644
--- a/lib/puppet/provider/nameservice/directoryservice.rb
+++ b/lib/puppet/provider/nameservice/directoryservice.rb
@@ -320,14 +320,14 @@ class DirectoryService < Puppet::Provider::NameService
def self.get_password(guid)
password_hash = nil
password_hash_file = "#{@@password_hash_dir}/#{guid}"
- if File.exists?(password_hash_file)
+ if File.exists?(password_hash_file) and File.file?(password_hash_file)
if not File.readable?(password_hash_file)
raise Puppet::Error("Could not read password hash file at #{password_hash_file} for #{@resource[:name]}")
end
f = File.new(password_hash_file)
password_hash = f.read
f.close
- end
+ end
password_hash
end
diff --git a/lib/puppet/provider/service/gentoo.rb b/lib/puppet/provider/service/gentoo.rb
index 4067dee5e..d62df1a38 100644
--- a/lib/puppet/provider/service/gentoo.rb
+++ b/lib/puppet/provider/service/gentoo.rb
@@ -38,7 +38,7 @@ Puppet::Type.type(:service).provide :gentoo, :parent => :init do
return :false unless line
# If it's enabled then it will print output showing service | runlevel
- if output =~ /#{@resource[:name]}\s*\|\s*default/
+ if output =~ /#{@resource[:name]}\s*\|\s*(boot|default)/
return :true
else
return :false
diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb
index 031db46c1..f31903e84 100755
--- a/lib/puppet/provider/service/redhat.rb
+++ b/lib/puppet/provider/service/redhat.rb
@@ -73,12 +73,12 @@ Puppet::Type.type(:service).provide :redhat, :parent => :init do
end
end
- def start
- service(@resource[:name], "start")
+ def startcmd
+ [command(:service), @resource[:name], "start"]
end
- def stop
- service(@resource[:name], "stop")
+ def stopcmd
+ [command(:service), @resource[:name], "stop"]
end
end
diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb
index 5604ba32a..6df7f8ae0 100644
--- a/lib/puppet/provider/ssh_authorized_key/parsed.rb
+++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb
@@ -36,13 +36,34 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed,
:rts => /^\s+/,
:match => /^(?:(.+) )?(\d+) (\d+) (\d+)(?: (.+))?$/
- def prefetch
- # This was done in the type class but path expansion was failing for
- # not yet existing users, the only workaround I found was to move that
- # in the provider.
- @resource[:target] = target
+ def target
+ @resource.should(:target)
+ end
- super
+ def user
+ @resource.should(:user)
+ end
+
+ def dir_perm
+ # Determine correct permission for created directory and file
+ # we can afford more restrictive permissions when the user is known
+ if target
+ if user
+ 0700
+ else
+ 0755
+ end
+ end
+ end
+
+ def file_perm
+ if target
+ if user
+ 0600
+ else
+ 0644
+ end
+ end
end
def target
diff --git a/lib/puppet/provider/user/useradd.rb b/lib/puppet/provider/user/useradd.rb
index 6996dd69a..15b3b1379 100644
--- a/lib/puppet/provider/user/useradd.rb
+++ b/lib/puppet/provider/user/useradd.rb
@@ -31,7 +31,7 @@ Puppet::Type.type(:user).provide :useradd, :parent => Puppet::Provider::NameServ
cmd = []
if @resource.managehome?
cmd << "-m"
- elsif %w{Fedora RedHat}.include?(Facter.value("operatingsystem"))
+ elsif %w{Fedora RedHat CentOS OEL OVS}.include?(Facter.value("operatingsystem"))
cmd << "-M"
end
cmd
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb
index a429cbfb1..851cc21d9 100644
--- a/lib/puppet/rails/host.rb
+++ b/lib/puppet/rails/host.rb
@@ -3,8 +3,6 @@ require 'puppet/rails/fact_name'
require 'puppet/rails/source_file'
require 'puppet/util/rails/collection_merger'
-Puppet::TIME_DEBUG = true
-
class Puppet::Rails::Host < ActiveRecord::Base
include Puppet::Util
include Puppet::Util::CollectionMerger
@@ -36,7 +34,7 @@ class Puppet::Rails::Host < ActiveRecord::Base
host = new(:name => node.name)
end
}
- Puppet.notice("Searched for host in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG)
+ Puppet.debug("Searched for host in %0.2f seconds" % seconds)
if ip = node.parameters["ipaddress"]
host.ip = ip
end
@@ -51,7 +49,7 @@ class Puppet::Rails::Host < ActiveRecord::Base
seconds = Benchmark.realtime {
host.setresources(resources)
}
- Puppet.notice("Handled resources in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG)
+ Puppet.debug("Handled resources in %0.2f seconds" % seconds)
host.last_compile = Time.now
@@ -115,26 +113,26 @@ class Puppet::Rails::Host < ActiveRecord::Base
# Set our resources.
def setresources(list)
- existing = nil
+ resource_by_id = nil
seconds = Benchmark.realtime {
- existing = find_resources()
+ resource_by_id = find_resources()
}
- Puppet.notice("Searched for resources in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG)
+ Puppet.debug("Searched for resources in %0.2f seconds" % seconds)
seconds = Benchmark.realtime {
- find_resources_parameters_tags(existing)
+ find_resources_parameters_tags(resource_by_id)
} if id
- Puppet.notice("Searched for resource params and tags in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG)
+ Puppet.debug("Searched for resource params and tags in %0.2f seconds" % seconds)
seconds = Benchmark.realtime {
- compare_to_catalog(existing, list)
+ compare_to_catalog(resource_by_id, list)
}
- Puppet.notice("Resource comparison took %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG)
+ Puppet.debug("Resource comparison took %0.2f seconds" % seconds)
end
def find_resources
resources.find(:all, :include => :source_file).inject({}) do | hash, resource |
- hash[resource.ref] = resource
+ hash[resource.id] = resource
hash
end
end
@@ -145,20 +143,29 @@ class Puppet::Rails::Host < ActiveRecord::Base
resource.params_hash = []
end
- resources_by_id = resources.inject({}) do |hash, res|
- hash[res[1]['id']] = res[1]
+ find_resources_parameters(resources)
+ find_resources_tags(resources)
+ end
+
+ # it seems that it can happen (see bug #2010) some resources are duplicated in the
+ # database (ie logically corrupted database), in which case we remove the extraneous
+ # entries.
+ def compare_to_catalog(existing, list)
+ extra_db_resources = []
+ resources = existing.inject({}) do |hash, res|
+ resource = res[1]
+ if hash.include?(resource.ref)
+ extra_db_resources << hash[resource.ref]
+ end
+ hash[resource.ref] = resource
hash
end
- find_resources_parameters(resources_by_id)
- find_resources_tags(resources_by_id)
- end
-
- def compare_to_catalog(resources, list)
compiled = list.inject({}) do |hash, resource|
hash[resource.ref] = resource
hash
end
+
ar_hash_merge(resources, compiled,
:create => Proc.new { |ref, resource|
resource.to_rails(self)
@@ -167,6 +174,11 @@ class Puppet::Rails::Host < ActiveRecord::Base
}, :modify => Proc.new { |db, mem|
mem.modify_rails(db)
})
+
+ # fix-up extraneous resources
+ extra_db_resources.each do |resource|
+ self.resources.delete(resource)
+ end
end
def find_resources_parameters(resources)
@@ -174,7 +186,7 @@ class Puppet::Rails::Host < ActiveRecord::Base
# assign each loaded parameters/tags to the resource it belongs to
params.each do |param|
- resources[param['resource_id']].add_param_to_hash(param)
+ resources[param['resource_id']].add_param_to_hash(param) if resources.include?(param['resource_id'])
end
end
@@ -182,7 +194,7 @@ class Puppet::Rails::Host < ActiveRecord::Base
tags = Puppet::Rails::ResourceTag.find_all_tags_from_host(self)
tags.each do |tag|
- resources[tag['resource_id']].add_tag_to_hash(tag)
+ resources[tag['resource_id']].add_tag_to_hash(tag) if resources.include?(tag['resource_id'])
end
end
diff --git a/lib/puppet/reference/report.rb b/lib/puppet/reference/report.rb
index be8e64751..2ea00b6d6 100644
--- a/lib/puppet/reference/report.rb
+++ b/lib/puppet/reference/report.rb
@@ -20,4 +20,5 @@ reports must be comma-separated. You can also specify ``none`` to disable
reports entirely.
Puppet provides multiple report handlers that will process client reports:
+
"
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 884206b4c..bb5adc383 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -450,7 +450,7 @@ class Transaction
@catalog.vertices.each do |resource|
if provider = resource.provider and provider.class.respond_to?(:prefetch)
prefetchers[provider.class] ||= {}
- prefetchers[provider.class][resource.title] = resource
+ prefetchers[provider.class][resource.name] = resource
end
end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 0fa1697d1..0c7266c92 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -11,6 +11,7 @@ require 'puppet/util/log_paths'
require 'puppet/util/logging'
require 'puppet/resource/reference'
require 'puppet/util/cacher'
+require 'puppet/file_collection/lookup'
# see the bottom of the file for the rest of the inclusions
@@ -21,6 +22,7 @@ class Type
include Puppet::Util::LogPaths
include Puppet::Util::Logging
include Puppet::Util::Cacher
+ include Puppet::FileCollection::Lookup
###############################
# Code related to resource type attributes.
@@ -1804,8 +1806,6 @@ class Type
# In naming methods, I have tried to consistently name the method so
# that it is clear whether it operates on all attributes (thus has 'attr' in
# the method name, or whether it operates on a specific type of attributes.
- attr_accessor :file, :line
-
attr_writer :title
attr_writer :noop
diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb
index c89400b5e..da9cff369 100644
--- a/lib/puppet/type/augeas.rb
+++ b/lib/puppet/type/augeas.rb
@@ -19,10 +19,10 @@
Puppet::Type.newtype(:augeas) do
include Puppet::Util
-
+
feature :parse_commands, "Parse the command string"
feature :need_to_run?, "If the command should run"
- feature :execute_changes, "Actually make the changes"
+ feature :execute_changes, "Actually make the changes"
@doc = "Apply the changes (single or array of changes) to the filesystem
via the augeas tool.
@@ -59,7 +59,7 @@ Puppet::Type.newtype(:augeas) do
newparam (:context) do
desc "Optional context path. This value is pre-pended to the paths of all changes"
- defaultto ""
+ defaultto ""
end
newparam (:onlyif) do
@@ -81,7 +81,7 @@ Puppet::Type.newtype(:augeas) do
AN_ARRAY is in the form ['a string', 'another']"
defaultto ""
end
-
+
newparam(:changes) do
desc "The changes which should be applied to the filesystem. This
@@ -92,14 +92,13 @@ Puppet::Type.newtype(:augeas) do
rm [PATH] Removes the node at location PATH
remove [PATH] Synonym for rm
clear [PATH] Keeps the node at PATH, but removes the value.
- ins [LABEL] [WHERE] [PATH]
+ ins [LABEL] [WHERE] [PATH]
Inserts an empty node LABEL either [WHERE={before|after}] PATH.
- insert [LABEL] [WHERE] [PATH]
+ insert [LABEL] [WHERE] [PATH]
Synonym for ins
-
If the parameter 'context' is set that value is prepended to PATH"
- munge do |value|
+ munge do |value|
provider.parse_commands(value)
end
end
@@ -115,6 +114,13 @@ Puppet::Type.newtype(:augeas) do
defaultto ""
end
+ newparam(:force) do
+ desc "Optional command to force the augeas type to execute even if it thinks changes
+ will not be made. This does not overide the only setting. If onlyif is set, then the
+ foce setting will not override that result"
+
+ defaultto false
+ end
newparam(:type_check) do
desc "Set to true if augeas should perform typechecking. Optional, defaults to false"
@@ -122,7 +128,7 @@ Puppet::Type.newtype(:augeas) do
defaultto :false
end
-
+
# This is the acutal meat of the code. It forces
# augeas to be run and fails or not based on the augeas return
# code.
@@ -131,12 +137,12 @@ Puppet::Type.newtype(:augeas) do
desc "The expected return code from the augeas command. Should not be set"
defaultto 0
-
+
# Make output a bit prettier
def change_to_s(currentvalue, newvalue)
return "executed successfully"
- end
-
+ end
+
# if the onlyif resource is provided, then the value is parsed.
# a return value of 0 will stop exection becuase it matches the
# default value.
@@ -146,12 +152,12 @@ Puppet::Type.newtype(:augeas) do
else
0
end
- end
+ end
# Actually execute the command.
def sync
@resource.provider.execute_changes()
end
- end
+ end
end
diff --git a/lib/puppet/type/file/checksum.rb b/lib/puppet/type/file/checksum.rb
index 76e27e55d..54d1c463b 100755
--- a/lib/puppet/type/file/checksum.rb
+++ b/lib/puppet/type/file/checksum.rb
@@ -11,11 +11,13 @@ Puppet::Type.type(:file).newproperty(:checksum) do
like Tripwire without managing the file contents in any way. You can
specify that a file's checksum should be monitored and then subscribe to
the file from another object and receive events to signify
- checksum changes, for instance.
-
+ checksum changes, for instance.
+
There are a number of checksum types available including MD5 hashing (and
an md5lite variation that only hashes the first 500 characters of the
- file."
+ file.
+
+ The default checksum parameter, if checksums are enabled, is md5."
@event = :file_changed
@@ -41,11 +43,6 @@ Puppet::Type.type(:file).newproperty(:checksum) do
handlesum()
end
- newvalue(:nosum) do
- # nothing
- :nochange
- end
-
# If they pass us a sum type, behave normally, but if they pass
# us a sum type + sum, stick the sum in the cache.
munge do |value|
@@ -134,35 +131,6 @@ Puppet::Type.type(:file).newproperty(:checksum) do
cache(checktype())
end
- # Retrieve the cached sum
- def getcachedsum
- hash = nil
- unless hash = @resource.cached(:checksums)
- hash = {}
- @resource.cache(:checksums, hash)
- end
-
- sumtype = self.should
-
- if hash.include?(sumtype)
- #self.notice "Found checksum %s for %s" %
- # [hash[sumtype] ,@resource[:path]]
- sum = hash[sumtype]
-
- unless sum =~ /^\{\w+\}/
- sum = "{%s}%s" % [sumtype, sum]
- end
- return sum
- elsif hash.empty?
- #self.notice "Could not find sum of type %s" % sumtype
- return :nosum
- else
- #self.notice "Found checksum for %s but not of type %s" %
- # [@resource[:path],sumtype]
- return :nosum
- end
- end
-
# Calculate the sum from disk.
def getsum(checktype, file = nil)
sum = ""
diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb
index 66cf3e733..997afb81e 100644
--- a/lib/puppet/type/ssh_authorized_key.rb
+++ b/lib/puppet/type/ssh_authorized_key.rb
@@ -31,6 +31,20 @@ module Puppet
newproperty(:target) do
desc "The file in which to store the SSH key."
+
+ defaultto :absent
+
+ def should
+ if defined? @should and @should[0] != :absent
+ return super
+ end
+
+ if user = resource[:user]
+ return File.expand_path("~%s/.ssh/authorized_keys" % user)
+ end
+
+ return nil
+ end
end
newproperty(:options, :array_matching => :all) do
diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb
index 70f244507..cd3b2ac1a 100644
--- a/lib/puppet/util/selinux.rb
+++ b/lib/puppet/util/selinux.rb
@@ -153,7 +153,9 @@ module Puppet::Util::SELinux
# Internal helper function to read and parse /proc/mounts
def read_mounts
begin
- mounts = File.read("/proc/mounts")
+ mountfh = File.open("/proc/mounts", NONBLOCK)
+ mounts = mountfh.read
+ mountfh.close
rescue
return nil
end