From 86f8ff4fb5fa69dc59afeea4260d1a875f37d483 Mon Sep 17 00:00:00 2001 From: Andrew Shafer Date: Sat, 14 Jun 2008 09:38:36 -0600 Subject: Removed the unless condition in query, because the issue is a stale cached value and added comments that query will now always do so. The query method is only called in two places, from inside 'install' in yum.rb and from inside 'uninstall' in rpm. This behavior only happens when you have a lower version than the one you are 'ensuring'. Since the right package actually gets installed, the system is in sync next time, but the event of installation is lost and subscribing resources will never get it. --- lib/puppet/provider/package/rpm.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/package/rpm.rb b/lib/puppet/provider/package/rpm.rb index 35684e11d..a303da4e2 100755 --- a/lib/puppet/provider/package/rpm.rb +++ b/lib/puppet/provider/package/rpm.rb @@ -43,19 +43,20 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr # a hash with entries :instance => fully versioned package name, and # :ensure => version-release def query - unless @property_hash[:epoch] - cmd = ["-q", @resource[:name], "--nosignature", "--nodigest", "--qf", "#{NEVRAFORMAT}\n"] - - begin - output = rpm(*cmd) - rescue Puppet::ExecutionFailure - return nil - end - - # FIXME: We could actually be getting back multiple packages - # for multilib - @property_hash.update(self.class.nevra_to_hash(output)) + #NOTE: Prior to a fix for issue 1243, this method potentially returned a cached value + #IF YOU CALL THIS METHOD, IT WILL CALL RPM + #Use get(:property) to check if cached values are available + cmd = ["-q", @resource[:name], "--nosignature", "--nodigest", "--qf", "#{NEVRAFORMAT}\n"] + + begin + output = rpm(*cmd) + rescue Puppet::ExecutionFailure + return nil end + + # FIXME: We could actually be getting back multiple packages + # for multilib + @property_hash.update(self.class.nevra_to_hash(output)) return @property_hash.dup end -- cgit From 98e38a659a6eb9cdf0ee9e7ba6ff692483f25613 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sun, 15 Jun 2008 12:31:23 +1000 Subject: Adds support for keepconfig for the dpkg provider fixes #234 --- lib/puppet/provider/package/dpkg.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb index 512170a73..b67cd2b76 100755 --- a/lib/puppet/provider/package/dpkg.rb +++ b/lib/puppet/provider/package/dpkg.rb @@ -53,7 +53,22 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package unless file = @resource[:source] raise ArgumentError, "You cannot install dpkg packages without a source" end - dpkg "-i", file + + args = [] + + if config = @resource[:configfiles] + case config + when :keep + args << '--force-confold' + when :replace + args << '--force-confnew' + else + raise Puppet::Error, "Invalid 'configfiles' value %s" % config + end + end + args << '-i' << file + + dpkg(*args) end def update -- cgit From b7bd427eb98001fb051f0d8910a0a87d1b810c15 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 10 Jun 2008 00:32:56 -0500 Subject: Converting the Node.node_names class method into an instance method. This effectively removes the ability to search node termini for multiple names; only the parser will use these names. Temporarily retaining the 'find_by_any_name' method; it will be removed in a later commit. --- lib/puppet/node.rb | 100 ++++++++++++++++++++--------------------------------- 1 file changed, 37 insertions(+), 63 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index 576e2265d..a2024e6b5 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -17,32 +17,7 @@ class Puppet::Node # thrown in for kicks. def self.find_by_any_name(key) return nil unless key - - node = nil - names = node_names(key) - names.each do |name| - name = name.to_s if name.is_a?(Symbol) - break if node = find(name) - end - - # If they made it this far, we haven't found anything, so look for a - # default node. - unless node or names.include?("default") - if node = find("default") - Puppet.notice "Using default node for %s" % key - end - end - - return nil unless node - - node.names = names - - # This is critical, because it forces our node's name to always - # be the key, which is nearly always the node's certificate. - # This is how the node instance is linked to the Facts instance, - # so it quite matters. - node.name = key - return node + find(key) end private @@ -56,45 +31,9 @@ class Puppet::Node end end - # Calculate the list of node names we should use for looking - # up our node. - def self.node_names(key, facts = nil) - facts ||= node_facts(key) - names = [] - - # First, get the fqdn - unless fqdn = facts["fqdn"] - if domain = facts["domain"] - fqdn = facts["hostname"] + "." + facts["domain"] - end - end - - # Now that we (might) have the fqdn, add each piece to the name - # list to search, in order of longest to shortest. - if fqdn - list = fqdn.split(".") - tmp = [] - list.each_with_index do |short, i| - tmp << list[0..i].join(".") - end - names += tmp.reverse - end - - # And make sure the key is first, since that's the most - # likely usage. - # The key is usually the Certificate CN, but it can be - # set to the 'facter' hostname instead. - if Puppet[:node_name] == 'cert' - names.unshift key - else - names.unshift facts["hostname"] - end - names.uniq - end - public - attr_accessor :name, :classes, :parameters, :source, :ipaddress, :names + attr_accessor :name, :classes, :parameters, :source, :ipaddress attr_reader :time # Set the environment, making sure that it's valid. @@ -165,4 +104,39 @@ class Puppet::Node @parameters[name] = value unless @parameters.include?(name) end end + + # Calculate the list of names we might use for looking + # up our node. This is only used for AST nodes. + def names + names = [] + + # First, get the fqdn + unless fqdn = parameters["fqdn"] + if domain = parameters["domain"] + fqdn = parameters["hostname"] + "." + parameters["domain"] + end + end + + # Now that we (might) have the fqdn, add each piece to the name + # list to search, in order of longest to shortest. + if fqdn + list = fqdn.split(".") + tmp = [] + list.each_with_index do |short, i| + tmp << list[0..i].join(".") + end + names += tmp.reverse + end + + # And make sure the node name is first, since that's the most + # likely usage. + # The name is usually the Certificate CN, but it can be + # set to the 'facter' hostname instead. + if Puppet[:node_name] == 'cert' + names.unshift name + else + names.unshift parameters["hostname"] + end + names.uniq + end end -- cgit From 317af3608caae060d15b407fe0b78304f355c106 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 10 Jun 2008 00:33:39 -0500 Subject: Removing the now-obsolete Node.node_facts method. --- lib/puppet/node.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index a2024e6b5..75b7197fd 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -20,19 +20,6 @@ class Puppet::Node find(key) end - private - - # Look up the node facts so we can generate the node names to use. - def self.node_facts(key) - if facts = Puppet::Node::Facts.find(key) - facts.values - else - {} - end - end - - public - attr_accessor :name, :classes, :parameters, :source, :ipaddress attr_reader :time -- cgit From fb4e84321d47c5ebe31d257e1f7e0037a9ff34c1 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 10 Jun 2008 00:45:41 -0500 Subject: Refactoring the 'find' method a bit in the LDAP Node terminus. This just splits the method into smaller pieces, so it's a bit easier to maintain. --- lib/puppet/indirector/node/ldap.rb | 102 +++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 45 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index bc58908fd..5cf560e86 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -19,51 +19,7 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap node = Puppet::Node.new(name) - information[:stacked_parameters] = {} - - parent_info = nil - parent = information[:parent] - parents = [name] - while parent - if parents.include?(parent) - raise ArgumentError, "Found loop in LDAP node parents; %s appears twice" % parent - end - parents << parent - - ldapsearch(parent) { |entry| parent_info = process(parent, entry) } - - unless parent_info - raise Puppet::Error.new("Could not find parent node '%s'" % parent) - end - information[:classes] += parent_info[:classes] - parent_info[:stacked].each do |value| - param = value.split('=', 2) - information[:stacked_parameters][param[0]] = param[1] - end - parent_info[:parameters].each do |param, value| - # Specifically test for whether it's set, so false values are handled - # correctly. - information[:parameters][param] = value unless information[:parameters].include?(param) - end - - information[:environment] ||= parent_info[:environment] - - parent = parent_info[:parent] - end - - information[:stacked].each do |value| - param = value.split('=', 2) - information[:stacked_parameters][param[0]] = param[1] - end - - information[:stacked_parameters].each do |param, value| - information[:parameters][param] = value unless information[:parameters].include?(param) - end - - node.classes = information[:classes].uniq unless information[:classes].empty? - node.parameters = information[:parameters] unless information[:parameters].empty? - node.environment = information[:environment] if information[:environment] - node.fact_merge + add_to_node(node, information) return node end @@ -155,4 +111,60 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap end filter end + + private + + # Add our hash of ldap information to the node instance. + def add_to_node(node, information) + information[:stacked_parameters] = {} + + parent_info = nil + parent = information[:parent] + parents = [node.name] + while parent + if parents.include?(parent) + raise ArgumentError, "Found loop in LDAP node parents; %s appears twice" % parent + end + parents << parent + parent = find_and_merge_parent(parent, information) + end + + information[:stacked].each do |value| + param = value.split('=', 2) + information[:stacked_parameters][param[0]] = param[1] + end + + information[:stacked_parameters].each do |param, value| + information[:parameters][param] = value unless information[:parameters].include?(param) + end + + node.classes = information[:classes].uniq unless information[:classes].empty? + node.parameters = information[:parameters] unless information[:parameters].empty? + node.environment = information[:environment] if information[:environment] + node.fact_merge + end + + # Find information for our parent and merge it into the current info. + def find_and_merge_parent(parent, information) + parent_info = nil + ldapsearch(parent) { |entry| parent_info = process(parent, entry) } + + unless parent_info + raise Puppet::Error.new("Could not find parent node '%s'" % parent) + end + information[:classes] += parent_info[:classes] + parent_info[:stacked].each do |value| + param = value.split('=', 2) + information[:stacked_parameters][param[0]] = param[1] + end + parent_info[:parameters].each do |param, value| + # Specifically test for whether it's set, so false values are handled + # correctly. + information[:parameters][param] = value unless information[:parameters].include?(param) + end + + information[:environment] ||= parent_info[:environment] + + parent_info[:parent] + end end -- cgit From 51e1ba8c02f1bd9085ef15138c4828accbb29dec Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 14 Jun 2008 14:37:33 -0500 Subject: The LDAP Node terminus now searches for the fqdn, short name, and default. This provides something like the multiple name scenario previously used by the parser but now implemented in each terminus. --- lib/puppet/indirector/ldap.rb | 12 +++++++----- lib/puppet/indirector/node/ldap.rb | 34 +++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/ldap.rb b/lib/puppet/indirector/ldap.rb index 07ad38933..695d38a95 100644 --- a/lib/puppet/indirector/ldap.rb +++ b/lib/puppet/indirector/ldap.rb @@ -1,14 +1,16 @@ require 'puppet/indirector/terminus' class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus - # Perform our ldap search and process the result. - def find(request) + # We split this apart so it's easy to call multiple times with different names. + def entry2hash(name) # We have to use 'yield' here because the LDAP::Entry objects # get destroyed outside the scope of the search, strangely. - ldapsearch(request.key) { |entry| return process(request.key, entry) } + ldapsearch(name) { |entry| return process(name, entry) } + end - # Return nil if we haven't found something. - return nil + # Perform our ldap search and process the result. + def find(request) + return entry2hash(request.key) || nil end # Process the found entry. We assume that we don't just want the diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index 5cf560e86..4ed053eff 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -3,7 +3,9 @@ require 'puppet/indirector/ldap' class Puppet::Node::Ldap < Puppet::Indirector::Ldap desc "Search in LDAP for node configuration information. See - the `LdapNodes`:trac: page for more information." + the `LdapNodes`:trac: page for more information. This will first + search for whatever the certificate name is, then (if that name + contains a '.') for the short name, then 'default'." # The attributes that Puppet class information is stored in. def class_attributes @@ -13,7 +15,17 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap # Look for our node in ldap. def find(request) - return nil unless information = super + names = [request.key] + if request.key.include?(".") # we assume it's an fqdn + names << request.key.sub(/\..+/, '') + end + names << "default" + + information = nil + names.each do |name| + break if information = entry2hash(name) + end + return nil unless information name = request.key @@ -129,17 +141,21 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap parent = find_and_merge_parent(parent, information) end - information[:stacked].each do |value| - param = value.split('=', 2) - information[:stacked_parameters][param[0]] = param[1] + if information[:stacked] + information[:stacked].each do |value| + param = value.split('=', 2) + information[:stacked_parameters][param[0]] = param[1] + end end - information[:stacked_parameters].each do |param, value| - information[:parameters][param] = value unless information[:parameters].include?(param) + if information[:stacked_parameters] + information[:stacked_parameters].each do |param, value| + information[:parameters][param] = value unless information[:parameters].include?(param) + end end - node.classes = information[:classes].uniq unless information[:classes].empty? - node.parameters = information[:parameters] unless information[:parameters].empty? + node.classes = information[:classes].uniq unless information[:classes].nil? or information[:classes].empty? + node.parameters = information[:parameters] unless information[:parameters].nil? or information[:parameters].empty? node.environment = information[:environment] if information[:environment] node.fact_merge end -- cgit From 1f19453dddf0f3a7822c21157f6f8d06c388cdb8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 15 Jun 2008 13:58:37 -0500 Subject: Removing the Node.find_by_name method. We just use the regular Node.find method now, since the nodes don't need to do any magical naming. --- lib/puppet/indirector/catalog/compiler.rb | 2 +- lib/puppet/node.rb | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index 2b5e8d912..455a92cc7 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -89,7 +89,7 @@ class Puppet::Node::Catalog::Compiler < Puppet::Indirector::Code # key = client #end - return nil unless node = Puppet::Node.find_by_any_name(key) + return nil unless node = Puppet::Node.find(key) # Add any external data to the node. add_node_data(node) diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index 75b7197fd..14d0f6ac7 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -13,13 +13,6 @@ class Puppet::Node indirects :node, :terminus_setting => :node_terminus, :doc => "Where to find node information. A node is composed of its name, its facts, and its environment." - # Retrieve a node from the node source, with some additional munging - # thrown in for kicks. - def self.find_by_any_name(key) - return nil unless key - find(key) - end - attr_accessor :name, :classes, :parameters, :source, :ipaddress attr_reader :time -- cgit From ac7f59618a80b6a4aac777f6184e7fa6a0614079 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 15 Jun 2008 14:39:45 -0500 Subject: Fixed #1201 - all external node attributes are converted to strings. --- lib/puppet/indirector/node/exec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/node/exec.rb b/lib/puppet/indirector/node/exec.rb index 52cbc370c..029a35c4f 100644 --- a/lib/puppet/indirector/node/exec.rb +++ b/lib/puppet/indirector/node/exec.rb @@ -30,6 +30,13 @@ class Puppet::Node::Exec < Puppet::Indirector::Exec def create_node(name, result) node = Puppet::Node.new(name) set = false + if current = result[:parameters] + result[:parameters] = current.inject({}) do |strings, ary| + param, value = ary + strings[param] = value.to_s + strings + end + end [:parameters, :classes, :environment].each do |param| if value = result[param] node.send(param.to_s + "=", value) -- cgit