summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/defaults.rb4
-rw-r--r--lib/puppet/indirector/indirection.rb2
-rw-r--r--lib/puppet/indirector/node/exec.rb7
-rw-r--r--lib/puppet/indirector/node/ldap.rb4
-rw-r--r--lib/puppet/indirector/yaml.rb5
-rw-r--r--lib/puppet/metatype/evaluation.rb6
-rw-r--r--lib/puppet/metatype/metaparams.rb6
-rw-r--r--lib/puppet/network/client/master.rb14
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb49
-rw-r--r--lib/puppet/network/handler/master.rb2
-rw-r--r--lib/puppet/node.rb2
-rwxr-xr-xlib/puppet/provider/package/ports.rb3
-rwxr-xr-xlib/puppet/provider/service/debian.rb3
-rw-r--r--lib/puppet/provider/user/useradd.rb2
-rw-r--r--lib/puppet/reports/tagmail.rb2
-rw-r--r--lib/puppet/transportable.rb48
-rw-r--r--lib/puppet/type.rb2
-rwxr-xr-xlib/puppet/type/exec.rb5
-rwxr-xr-xlib/puppet/type/host.rb6
-rwxr-xr-xlib/puppet/util/filetype.rb6
-rw-r--r--lib/puppet/util/settings.rb49
21 files changed, 103 insertions, 124 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 2f5992d22..8dcc46a8e 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -327,8 +327,8 @@ module Puppet
:masterport => [8140, "Which port puppetmasterd listens on."],
:parseonly => [false, "Just check the syntax of the manifests."],
:node_name => ["cert", "How the puppetmaster determines the client's identity
- and sets the 'hostname' fact for use in the manifest, in particular
- for determining which 'node' statement applies to the client.
+ and sets the 'hostname', 'fqdn' and 'domain' facts for use in the manifest,
+ in particular for determining which 'node' statement applies to the client.
Possible values are 'cert' (use the subject's CN in the client's
certificate) and 'facter' (use the hostname that the client
reported in its facts)"],
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 129676e9c..d47433c60 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -162,7 +162,7 @@ class Puppet::Indirector::Indirection
# See if our instance is in the cache and up to date.
if cache? and cache.has_most_recent?(key, terminus(terminus_name).version(key))
- Puppet.info "Using cached %s %s" % [self.name, key]
+ Puppet.debug "Using cached %s %s" % [self.name, key]
return cache.find(key, *args)
end
diff --git a/lib/puppet/indirector/node/exec.rb b/lib/puppet/indirector/node/exec.rb
index 71f4fa8e1..dcfc625b2 100644
--- a/lib/puppet/indirector/node/exec.rb
+++ b/lib/puppet/indirector/node/exec.rb
@@ -24,6 +24,13 @@ class Puppet::Node::Exec < Puppet::Indirector::Exec
return create_node(name, result)
end
+ # Use the version of the facts, since we assume that's the main thing
+ # that changes. If someone wants their own way of defining version,
+ # they can easily provide their own, um, version of this class.
+ def version(name)
+ Puppet::Node::Facts.version(name)
+ end
+
private
# Turn our outputted objects into a Puppet::Node instance.
diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb
index 9320f3ba1..8537e1cf3 100644
--- a/lib/puppet/indirector/node/ldap.rb
+++ b/lib/puppet/indirector/node/ldap.rb
@@ -122,4 +122,8 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
end
filter
end
+
+ def version(name)
+ Puppet::Node::Facts.version(name)
+ end
end
diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb
index 16816d941..4baeb38db 100644
--- a/lib/puppet/indirector/yaml.rb
+++ b/lib/puppet/indirector/yaml.rb
@@ -40,6 +40,11 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
end
end
+ def version(name)
+ return nil unless FileTest.exist?(path(name))
+ return File.stat(path(name)).mtime
+ end
+
private
def from_yaml(text)
diff --git a/lib/puppet/metatype/evaluation.rb b/lib/puppet/metatype/evaluation.rb
index 08756e988..36328c537 100644
--- a/lib/puppet/metatype/evaluation.rb
+++ b/lib/puppet/metatype/evaluation.rb
@@ -108,7 +108,11 @@ class Puppet::Type
# Are we running in noop mode?
def noop?
- @noop || Puppet[:noop]
+ if defined?(@noop)
+ @noop
+ else
+ Puppet[:noop]
+ end
end
def noop
diff --git a/lib/puppet/metatype/metaparams.rb b/lib/puppet/metatype/metaparams.rb
index 9983c34d2..edd594114 100644
--- a/lib/puppet/metatype/metaparams.rb
+++ b/lib/puppet/metatype/metaparams.rb
@@ -375,7 +375,7 @@ class Puppet::Type
}
service { nagios:
running => true,
- subscribe => file[nagconf]
+ subscribe => File[nagconf]
}
}
@@ -392,7 +392,7 @@ class Puppet::Type
file { "/var/nagios/configuration":
source => "...",
recurse => true,
- before => exec["nagios-rebuid"]
+ before => Exec["nagios-rebuid"]
}
exec { "nagios-rebuild":
@@ -410,7 +410,7 @@ class Puppet::Type
file { "/etc/sshd_config":
source => "....",
- notify => service[sshd]
+ notify => Service[sshd]
}
service { sshd:
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb
index 913c51b3d..e914d5c69 100644
--- a/lib/puppet/network/client/master.rb
+++ b/lib/puppet/network/client/master.rb
@@ -320,7 +320,8 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
:group => Process.gid,
:purge => true,
:force => true,
- :backup => false
+ :backup => false,
+ :noop => false
}
if args[:ignore]
@@ -331,9 +332,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
Puppet.info "Retrieving #{args[:name]}s"
- noop = Puppet[:noop]
- Puppet[:noop] = false
-
files = []
begin
Timeout::timeout(self.timeout) do
@@ -355,14 +353,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
downconfig.clear
return files
- ensure
- # I can't imagine why this is necessary, but apparently at last one person has had problems with noop
- # being nil here.
- if noop.nil?
- Puppet[:noop] = false
- else
- Puppet[:noop] = noop
- end
end
# Retrieve facts from the central server.
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index 751a77220..3e62cdbd9 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -429,55 +429,6 @@ class Puppet::Network::Handler
Puppet::Util.logmethods(self, true)
- def getfileobject(dir, links, client = nil)
- unless path_exists?(dir, client)
- self.debug "File source %s does not exist" % dir
- return nil
- end
-
- return fileobj(dir, links, client)
- end
-
- # Run 'retrieve' on a file. This gets the actual parameters, so
- # we can pass them to the client.
- def check(obj)
- # Retrieval is enough here, because we don't want to cache
- # any information in the state file, and we don't want to generate
- # any state changes or anything. We don't even need to sync
- # the checksum, because we're always going to hit the disk
- # directly.
-
- # We're now caching file data, using the LoadedFile to check the
- # disk no more frequently than the :filetimeout.
- path = obj[:path]
- sync = sync(path)
- unless data = @@files[path]
- data = {}
- sync.synchronize(Sync::EX) do
- @@files[path] = data
- data[:loaded_obj] = Puppet::Util::LoadedFile.new(path)
- data[:values] = properties(obj)
- return data[:values]
- end
- end
-
- changed = nil
- sync.synchronize(Sync::SH) do
- changed = data[:loaded_obj].changed?
- end
-
- if changed
- sync.synchronize(Sync::EX) do
- data[:values] = properties(obj)
- return data[:values]
- end
- else
- sync.synchronize(Sync::SH) do
- return data[:values]
- end
- end
- end
-
# Create a map for a specific client.
def clientmap(client)
{
diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb
index 8d84fe8b8..3e004046e 100644
--- a/lib/puppet/network/handler/master.rb
+++ b/lib/puppet/network/handler/master.rb
@@ -81,6 +81,8 @@ class Puppet::Network::Handler
clientip = facts["ipaddress"]
if Puppet[:node_name] == 'cert'
if name
+ facts["fqdn"] = client
+ facts["hostname"], facts["domain"] = client.split('.', 2)
client = name
end
if ip
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb
index 252ab961e..1091e5056 100644
--- a/lib/puppet/node.rb
+++ b/lib/puppet/node.rb
@@ -10,7 +10,7 @@ class Puppet::Node
extend Puppet::Indirector
# Use the node source as the indirection terminus.
- indirects :node, :terminus_setting => :node_terminus, :doc => "Where to find node information.
+ indirects :node, :terminus_setting => :node_terminus, :cache_class => :yaml, :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
diff --git a/lib/puppet/provider/package/ports.rb b/lib/puppet/provider/package/ports.rb
index 8c7f79e0a..1cff30039 100755
--- a/lib/puppet/provider/package/ports.rb
+++ b/lib/puppet/provider/package/ports.rb
@@ -1,6 +1,5 @@
Puppet::Type.type(:package).provide :ports, :parent => :freebsd, :source => :freebsd do
- desc "Support for FreeBSD's ports. Again, this still mixes packages
- and ports."
+ desc "Support for FreeBSD's ports. Again, this still mixes packages and ports."
commands :portupgrade => "/usr/local/sbin/portupgrade",
:portversion => "/usr/local/sbin/portversion",
diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb
index e54fb13df..f0f6fe1ef 100755
--- a/lib/puppet/provider/service/debian.rb
+++ b/lib/puppet/provider/service/debian.rb
@@ -14,7 +14,7 @@ Puppet::Type.type(:service).provide :debian, :parent => :init do
# Remove the symlinks
def disable
update "-f", @resource[:name], "remove"
- update @resource[:name], "stop 1 2 3 4 5 6 ."
+ update @resource[:name], "stop", "00", "1", "2", "3", "4", "5", "6", "."
end
def enabled?
@@ -34,4 +34,3 @@ Puppet::Type.type(:service).provide :debian, :parent => :init do
update @resource[:name], "defaults"
end
end
-
diff --git a/lib/puppet/provider/user/useradd.rb b/lib/puppet/provider/user/useradd.rb
index 9ecaad87d..e64601ee0 100644
--- a/lib/puppet/provider/user/useradd.rb
+++ b/lib/puppet/provider/user/useradd.rb
@@ -1,7 +1,7 @@
require 'puppet/provider/nameservice/objectadd'
Puppet::Type.type(:user).provide :useradd, :parent => Puppet::Provider::NameService::ObjectAdd do
- desc "User management via ``useradd`` and its ilk. Note that you'll have to install the ``Shadow Password`` library to manage user passwords."
+ desc "User management via ``useradd`` and its ilk. Note that you will need to install the ``Shadow Password`` Ruby library often known as ruby-libshadow to manage user passwords."
commands :add => "useradd", :delete => "userdel", :modify => "usermod"
diff --git a/lib/puppet/reports/tagmail.rb b/lib/puppet/reports/tagmail.rb
index 9b3711148..102647c66 100644
--- a/lib/puppet/reports/tagmail.rb
+++ b/lib/puppet/reports/tagmail.rb
@@ -35,8 +35,6 @@ Puppet::Reports.register_report(:tagmail) do
"
- Puppet.settings.use(:tagmail)
-
# Find all matching messages.
def match(taglists)
reports = []
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index f686fbb78..3ad084b3b 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -83,14 +83,11 @@ module Puppet
end
def to_type
- retobj = nil
if typeklass = Puppet::Type.type(self.type)
return typeklass.create(self)
else
return to_component
end
-
- return retobj
end
end
@@ -179,28 +176,39 @@ module Puppet
end
# Create a resource graph from our structure.
- def to_catalog
- catalog = Puppet::Node::Catalog.new(Facter.value("hostname")) do |config|
- delver = proc do |obj|
- obj.catalog = config
- unless container = config.resource(obj.to_ref)
- container = obj.to_type
- config.add_resource container
+ def to_catalog(clear_on_failure = true)
+ catalog = Puppet::Node::Catalog.new(Facter.value("hostname"))
+
+ # This should really use the 'delve' method, but this
+ # whole class is going away relatively soon, hopefully,
+ # so it's not worth it.
+ delver = proc do |obj|
+ obj.catalog = catalog
+ unless container = catalog.resource(obj.to_ref)
+ container = obj.to_type
+ catalog.add_resource container
+ end
+ obj.each do |child|
+ child.catalog = catalog
+ unless resource = catalog.resource(child.to_ref)
+ resource = child.to_type
+ catalog.add_resource resource
end
- obj.each do |child|
- child.catalog = config
- unless resource = config.resource(child.to_ref)
- next unless resource = child.to_type
- config.add_resource resource
- end
- config.add_edge(container, resource)
- if child.is_a?(self.class)
- delver.call(child)
- end
+
+ catalog.add_edge(container, resource)
+ if child.is_a?(self.class)
+ delver.call(child)
end
end
+ end
+ begin
delver.call(self)
+ catalog.finalize
+ rescue => detail
+ # This is important until we lose the global resource references.
+ catalog.clear if (clear_on_failure)
+ raise
end
return catalog
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 09003e8f5..f8949ec90 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -155,8 +155,6 @@ class Type
@parameters = {}
end
- # set defalts
- @noop = false
# keeping stats for the total number of changes, and how many were
# completely sync'ed
# this isn't really sufficient either, because it adds lots of special
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 2772b54a8..d7c3a8a39 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -390,6 +390,11 @@ module Puppet
Note that this command follows the same rules as the main command,
which is to say that it must be fully qualified if the path is not set.
+
+ Also note that onlyif can take an array as its value, eg:
+ onlyif => [\"test -f /tmp/file1\", \"test -f /tmp/file2\"]
+
+ This will only run the exec if /all/ conditions in the array return true.
"
validate do |cmds|
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb
index 3e34c0b60..868e41629 100755
--- a/lib/puppet/type/host.rb
+++ b/lib/puppet/type/host.rb
@@ -87,8 +87,10 @@ module Puppet
isnamevar
validate do |value|
- unless value =~ /^\w+-?[\w+]?\.?[\w+.{1}]*\w+$/
- raise Puppet::Error, "Invalid host name"
+ value.split('.').each do |hostpart|
+ unless hostpart =~ /^([\d\w]+|[\d\w][\d\w\-]+[\d\w])$/
+ raise Puppet::Error, "Invalid host name"
+ end
end
end
end
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index bbc837e75..8dcb67286 100755
--- a/lib/puppet/util/filetype.rb
+++ b/lib/puppet/util/filetype.rb
@@ -104,7 +104,11 @@ class Puppet::Util::FileType
# Overwrite the file.
def write(text)
backup()
- File.open(@path, "w") { |f| f.print text; f.flush }
+ require "tempfile"
+ tf = Tempfile.new("puppet")
+ tf.print text; tf.flush
+ FileUtils.cp(tf.path, @path)
+ tf.close
end
end
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index f4055c304..089389a09 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -44,19 +44,6 @@ class Puppet::Util::Settings
return value
end
- # A simplified equality operator.
- # LAK: For some reason, this causes mocha to not be able to mock
- # the 'value' method, and it's not used anywhere.
-# def ==(other)
-# self.each { |myname, myobj|
-# unless other[myname] == value(myname)
-# return false
-# end
-# }
-#
-# return true
-# end
-
# Generate the list of valid arguments, in a format that GetoptLong can
# understand, and add them to the passed option list.
def addargs(options)
@@ -225,6 +212,9 @@ class Puppet::Util::Settings
# A central concept of a name.
@name = nil
+
+ # The list of sections we've used.
+ @used = []
end
# Return a given object's file metadata.
@@ -575,23 +565,36 @@ Generated on #{Time.now}.
# you can 'use' a section as many times as you want.
def use(*sections)
@@sync.synchronize do # yay, thread-safe
- unless defined? @used
- @used = []
- end
+ sections = sections.reject { |s| @used.include?(s.to_sym) }
+
+ return if sections.empty?
bucket = to_transportable(*sections)
- config = bucket.to_catalog
- config.host_config = false
- config.apply do |transaction|
- if failures = transaction.any_failed?
- raise "Could not configure for running; got %s failure(s)" % failures
+ begin
+ catalog = bucket.to_catalog
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not create resources for managing Puppet's files and directories: %s" % detail
+
+ # We need some way to get rid of any resources created during the catalog creation
+ # but not cleaned up.
+ return
+ end
+
+ begin
+ catalog.host_config = false
+ catalog.apply do |transaction|
+ if failures = transaction.any_failed?
+ raise "Could not configure for running; got %s failure(s)" % failures
+ end
end
+ ensure
+ catalog.clear
end
- config.clear
sections.each { |s| @used << s }
- @used.uniq
+ @used.uniq!
end
end