summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-04-02 18:56:53 -0500
committerLuke Kanies <luke@madstop.com>2009-04-02 18:56:53 -0500
commit6e79cc00965a50c44f215fd1e553281cfd2b87c9 (patch)
tree56c496df9ad6ab66dfb16993910eb5ff1c34d065
parent62dad7a5f87f8d6285650ab1b727819db27cf2a7 (diff)
parentc62c19370bfba881819c1a3d9da2f8e6fb52e5d9 (diff)
downloadpuppet-6e79cc00965a50c44f215fd1e553281cfd2b87c9.tar.gz
puppet-6e79cc00965a50c44f215fd1e553281cfd2b87c9.tar.xz
puppet-6e79cc00965a50c44f215fd1e553281cfd2b87c9.zip
Merge branch '0.24.x'
Conflicts: bin/ralsh lib/puppet/executables/client/certhandler.rb lib/puppet/parser/functions/versioncmp.rb lib/puppet/parser/resource/reference.rb lib/puppet/provider/augeas/augeas.rb lib/puppet/provider/nameservice/directoryservice.rb lib/puppet/provider/ssh_authorized_key/parsed.rb lib/puppet/type.rb lib/puppet/type/file/checksum.rb spec/integration/defaults.rb spec/integration/transaction/report.rb spec/unit/executables/client/certhandler.rb spec/unit/indirector/ssl_rsa/file.rb spec/unit/node/catalog.rb spec/unit/provider/augeas/augeas.rb spec/unit/rails.rb spec/unit/type/ssh_authorized_key.rb spec/unit/type/tidy.rb test/executables/filebucket.rb test/executables/puppetbin.rb
-rw-r--r--CHANGELOG18
-rw-r--r--ext/dbfix.sql132
-rw-r--r--ext/logcheck/puppet1
-rwxr-xr-xinstall.rb4
-rw-r--r--lib/puppet.rb2
-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
-rwxr-xr-xspec/integration/checksum.rb1
-rwxr-xr-xspec/integration/defaults.rb9
-rwxr-xr-xspec/integration/reports.rb4
-rwxr-xr-xspec/integration/transaction/report.rb5
-rwxr-xr-xspec/integration/type/package.rb7
-rwxr-xr-xspec/unit/file_collection.rb53
-rwxr-xr-xspec/unit/file_collection/lookup.rb46
-rwxr-xr-xspec/unit/indirector/node/ldap.rb20
-rwxr-xr-xspec/unit/other/transbucket.rb8
-rw-r--r--spec/unit/parser/ast.rb6
-rwxr-xr-xspec/unit/parser/resource.rb4
-rwxr-xr-xspec/unit/parser/resource/reference.rb4
-rw-r--r--spec/unit/property/list.rb4
-rw-r--r--spec/unit/provider/augeas/augeas.rb77
-rwxr-xr-xspec/unit/provider/mount/parsed.rb1
-rwxr-xr-xspec/unit/provider/ssh_authorized_key/parsed.rb82
-rwxr-xr-xspec/unit/rails.rb3
-rwxr-xr-xspec/unit/transaction.rb15
-rwxr-xr-xspec/unit/type/file.rb2
-rwxr-xr-xspec/unit/type/group.rb3
-rwxr-xr-xspec/unit/type/noop_metaparam.rb1
-rwxr-xr-xspec/unit/type/ssh_authorized_key.rb39
-rwxr-xr-xspec/unit/type/tidy.rb15
-rwxr-xr-xspec/unit/type/user.rb3
-rw-r--r--tasks/rake/reductive.rb6
-rwxr-xr-xtest/lib/puppettest.rb3
56 files changed, 880 insertions, 230 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 1bc13f303..99a69c676 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -22,6 +22,24 @@
Fixed #1840 - Bug fixes and improvements for Emacs puppet-mode.el
0.24.8
+ Fixed #2077 - ralsh user broken on OSX
+
+ Fixed #2004 - ssh_authorized_key fails if no target is defined
+
+ Fixed #1629 - incorrect permissions on ssh_authorized_keys created files
+
+ Fixed #2000 - No default specified for checksum
+
+ Fixed #2026 - Red Hat ignoring stop method
+
+ Added ext/dbfix.sql script - fixes common errors in stored configuration databases
+
+ Fixed #1963 - Failing to read /proc/mounts for selinux kills file downloads
+
+ Fixed #2025 - gentoo service provider handle only default init level
+
+ Fixed #1910 - updated logcheck
+
Fixed #1871 - Sensitive information leaked in log reports
Fixed #1956 - Cleaned up variable names to be more sane, clarified error messages
diff --git a/ext/dbfix.sql b/ext/dbfix.sql
new file mode 100644
index 000000000..960369117
--- /dev/null
+++ b/ext/dbfix.sql
@@ -0,0 +1,132 @@
+-- MySQL DB consistency check/fix
+--
+-- Usage:
+-- cat dbfix.sql | mysql -u user -p puppet
+--
+-- WARNING: perform a database backup before running this script
+
+-- Remove duplicate resources, and keep the latest one
+DELETE bad_rows.*
+FROM resources AS bad_rows
+ INNER JOIN (
+ SELECT title,restype,host_id, MAX(id) as max_id
+ FROM resources
+ GROUP BY title,restype,host_id
+ HAVING count(*) > 1
+ ) AS good_rows
+ ON
+ good_rows.title = bad_rows.title AND
+ good_rows.restype = bad_rows.restype AND
+ good_rows.host_id = bad_rows.host_id AND
+ good_rows.max_id <> bad_rows.id;
+
+-- Remove duplicate param_values, and keep the latest one
+DELETE bad_rows.*
+FROM param_values AS bad_rows
+ INNER JOIN (
+ SELECT value,param_name_id,resource_id, MAX(id) as max_id
+ FROM param_values
+ GROUP BY value,param_name_id,resource_id
+ HAVING count(*) > 1
+ ) AS good_rows
+ ON
+ good_rows.value = bad_rows.value AND
+ good_rows.param_name_id = bad_rows.param_name_id AND
+ good_rows.resource_id = bad_rows.resource_id AND
+ good_rows.max_id <> bad_rows.id;
+
+-- rewrite param_values that points to duplicated param_names
+-- to point to the highest param_name id.
+UPDATE
+ param_values v
+ INNER JOIN
+ param_names n
+ ON n.id = v.param_name_id
+ INNER JOIN
+ (
+ SELECT name, MAX(id) as max_id
+ FROM param_names
+ GROUP BY name
+ HAVING count(*) > 1
+ ) nmax ON n.name = nmax.name
+SET
+ v.param_name_id = nmax.max_id;
+
+-- Remove duplicate param_names, and keep the latest one
+DELETE bad_rows.*
+FROM param_names AS bad_rows
+ INNER JOIN (
+ SELECT name, MAX(id) as max_id
+ FROM param_names
+ GROUP BY name
+ HAVING count(*) > 1
+ ) AS good_rows
+ ON
+ good_rows.name = bad_rows.name AND
+ good_rows.max_id <> bad_rows.id;
+
+-- Remove duplicate resource_tags, and keep the highest one
+DELETE bad_rows.*
+FROM resource_tags AS bad_rows
+ INNER JOIN (
+ SELECT resource_id,puppet_tag_id, MAX(id) as max_id
+ FROM resource_tags
+ GROUP BY resource_id,puppet_tag_id
+ HAVING count(*) > 1
+ ) AS good_rows
+ ON
+ good_rows.resource_id = bad_rows.resource_id AND
+ good_rows.puppet_tag_id = bad_rows.puppet_tag_id AND
+ good_rows.max_id <> bad_rows.id;
+
+-- rewrite resource_tags that points to duplicated puppet_tags
+-- to point to the highest puppet_tags id.
+UPDATE
+ resource_tags v
+ INNER JOIN
+ puppet_tags n
+ ON n.id = v.puppet_tag_id
+ INNER JOIN
+ (
+ SELECT name, MAX(id) as max_id
+ FROM puppet_tags
+ GROUP BY name
+ HAVING count(*) > 1
+ ) nmax ON n.name = nmax.name
+SET
+ v.puppet_tag_id = nmax.max_id;
+
+-- Remove duplicate puppet_tags, and keep the highest one
+DELETE bad_rows.*
+FROM puppet_tags AS bad_rows
+ INNER JOIN (
+ SELECT name, MAX(id) as max_id
+ FROM puppet_tags
+ GROUP BY name
+ HAVING count(*) > 1
+ ) AS good_rows
+ ON
+ good_rows.name = bad_rows.name AND
+ good_rows.max_id <> bad_rows.id;
+
+-- Fix dangling resources
+-- note: we use a table to not exceed the number of InnoDB locks if there are two much
+-- rows to delete.
+-- this is an alternative to: DELETE resources FROM resources r LEFT JOIN hosts h ON h.id=r.host_id WHERE h.id IS NULL;
+--
+CREATE TABLE resources_c LIKE resources;
+INSERT INTO resources_c SELECT r.* FROM resources r INNER JOIN hosts h ON h.id=r.host_id;
+RENAME TABLE resources TO resources_old, resources_c TO resources;
+DROP TABLE resources_old;
+
+-- Fix dangling param_values
+CREATE TABLE param_values_c LIKE param_values;
+INSERT INTO param_values_c SELECT v.* FROM param_values v INNER JOIN resources r ON r.id=v.resource_id;
+RENAME TABLE param_values TO param_values_old, param_values_c TO param_values;
+DROP TABLE param_values_old;
+
+-- Fix dangling resource_tags
+CREATE TABLE resource_tags_c LIKE resource_tags;
+INSERT INTO resource_tags_c SELECT t.* FROM resource_tags t INNER JOIN resources r ON r.id=t.resource_id;
+RENAME TABLE resource_tags TO resource_tags_old, resource_tags_c TO resource_tags;
+DROP TABLE resource_tags_old;
diff --git a/ext/logcheck/puppet b/ext/logcheck/puppet
index 528eb42ce..d1b1b27bd 100644
--- a/ext/logcheck/puppet
+++ b/ext/logcheck/puppet
@@ -1,3 +1,4 @@
+^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetmasterd\[[0-9]+\]: (Handled resources in|Resource comparison took|Searched for (host|resources|resource params and tags) in) [0-9.]+ seconds
^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetmasterd\[[0-9]+\]: Starting Puppet server version [.0-9]+$
^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetmasterd\[[0-9]+\]: Compiled catalog for [._[:alnum:]-]+ in [.0-9]+ seconds$
^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetmasterd\[[0-9]+\]: Caught TERM; shutting down$
diff --git a/install.rb b/install.rb
index c99d7dacd..bc7df98b3 100755
--- a/install.rb
+++ b/install.rb
@@ -94,7 +94,7 @@ def do_libs(libs, strip = 'lib/')
op = File.dirname(olf)
File.makedirs(op, true)
File.chmod(0755, op)
- File.install(lf, olf, 0755, true)
+ File.install(lf, olf, 0644, true)
end
end
@@ -179,7 +179,7 @@ def prepare_installation
opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri|
InstallOptions.ri = onri
end
- opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman|
+ opts.on('--[no-]man', 'Prevents the creation of man pages.', 'Default on.') do |onman|
InstallOptions.man = onman
end
opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest|
diff --git a/lib/puppet.rb b/lib/puppet.rb
index e9ba2f2be..7bd3ed1bc 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -24,7 +24,7 @@ require 'puppet/util/suidmanager'
# it's also a place to find top-level commands like 'debug'
module Puppet
- PUPPETVERSION = '0.24.7'
+ PUPPETVERSION = '0.24.8'
def Puppet.version
return PUPPETVERSION
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
diff --git a/spec/integration/checksum.rb b/spec/integration/checksum.rb
index c94f3e47e..49ae8d2b7 100755
--- a/spec/integration/checksum.rb
+++ b/spec/integration/checksum.rb
@@ -9,6 +9,7 @@ require 'puppet/checksum'
describe Puppet::Checksum, " when using the file terminus" do
before do
+ Puppet.settings.stubs(:use)
Puppet::Checksum.terminus_class = :file
@content = "this is some content"
@sum = Puppet::Checksum.new(@content)
diff --git a/spec/integration/defaults.rb b/spec/integration/defaults.rb
index b3f3a7066..46b5fd64e 100755
--- a/spec/integration/defaults.rb
+++ b/spec/integration/defaults.rb
@@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/defaults'
describe "Puppet defaults" do
+ include Puppet::Util::Execution
after { Puppet.settings.clear }
describe "when setting the :factpath" do
@@ -83,4 +84,12 @@ describe "Puppet defaults" do
Puppet.settings.element(setting).should be_instance_of(Puppet::Util::Settings::CElement)
end
end
+
+ it "should add /usr/sbin and /sbin to the path if they're not there" do
+ withenv("PATH" => "/usr/bin:/usr/local/bin") do
+ Puppet.settings[:path] = "none" # this causes it to ignore the setting
+ ENV["PATH"].split(File::PATH_SEPARATOR).should be_include("/usr/sbin")
+ ENV["PATH"].split(File::PATH_SEPARATOR).should be_include("/sbin")
+ end
+ end
end
diff --git a/spec/integration/reports.rb b/spec/integration/reports.rb
index 7351c3da1..cc4ae8f4c 100755
--- a/spec/integration/reports.rb
+++ b/spec/integration/reports.rb
@@ -8,6 +8,10 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/reports'
describe Puppet::Reports, " when using report types" do
+ before do
+ Puppet.settings.stubs(:use)
+ end
+
it "should load report types as modules" do
Puppet::Reports.report(:store).should be_instance_of(Module)
end
diff --git a/spec/integration/transaction/report.rb b/spec/integration/transaction/report.rb
index 68533b503..b704e56b8 100755
--- a/spec/integration/transaction/report.rb
+++ b/spec/integration/transaction/report.rb
@@ -7,7 +7,10 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Transaction::Report do
describe "when using the indirector" do
- after { Puppet::Util::Cacher.expire }
+ after do
+ Puppet::Util::Cacher.expire
+ Puppet.settings.stubs(:use)
+ end
it "should be able to delegate to the :processor terminus" do
Puppet::Transaction::Report.indirection.stubs(:terminus_class).returns :processor
diff --git a/spec/integration/type/package.rb b/spec/integration/type/package.rb
index def44ad97..a3d8eb278 100755
--- a/spec/integration/type/package.rb
+++ b/spec/integration/type/package.rb
@@ -9,7 +9,7 @@ describe Puppet::Type.type(:package), "when choosing a default package provider"
end
def provider_name(os)
- {"Debian" => :apt, "Darwin" => :apple, "RedHat" => :up2date, "Fedora" => :yum, "FreeBSD" => :ports, "OpenBSD" => :openbsd, "Solaris" => :sun}[os]
+ {"Ubuntu" => :apt, "Debian" => :apt, "Darwin" => :apple, "RedHat" => :up2date, "Fedora" => :yum, "FreeBSD" => :ports, "OpenBSD" => :openbsd, "Solaris" => :sun}[os]
end
it "should have a default provider" do
@@ -17,6 +17,9 @@ describe Puppet::Type.type(:package), "when choosing a default package provider"
end
it "should choose the correct provider each platform" do
- Puppet::Type.type(:package).defaultprovider.name.should == provider_name(Facter.value(:operatingsystem))
+ unless default_provider = provider_name(Facter.value(:operatingsystem))
+ pending("No default provider specified in this test for %s" % Facter.value(:operatingsystem))
+ end
+ Puppet::Type.type(:package).defaultprovider.name.should == default_provider
end
end
diff --git a/spec/unit/file_collection.rb b/spec/unit/file_collection.rb
new file mode 100755
index 000000000..81bcc2d2d
--- /dev/null
+++ b/spec/unit/file_collection.rb
@@ -0,0 +1,53 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+require 'puppet/file_collection'
+
+describe Puppet::FileCollection do
+ before do
+ @collection = Puppet::FileCollection.new
+ end
+
+ it "should be able to convert a file name into an index" do
+ @collection.index("/my/file").should be_instance_of(Fixnum)
+ end
+
+ it "should be able to convert an index into a file name" do
+ index = @collection.index("/path/to/file")
+ @collection.path(index).should == "/path/to/file"
+ end
+
+ it "should always give the same file name for a given index" do
+ index = @collection.index("/path/to/file")
+ @collection.path(index).should == @collection.path(index)
+ end
+
+ it "should always give the same index for a given file name" do
+ @collection.index("/my/file").should == @collection.index("/my/file")
+ end
+
+ it "should always correctly relate a file name and its index even when multiple files are in the collection" do
+ indexes = %w{a b c d e f}.inject({}) do |hash, letter|
+ hash[letter] = @collection.index("/path/to/file/%s" % letter)
+ hash
+ end
+
+ indexes.each do |letter, index|
+ @collection.index("/path/to/file/%s" % letter).should == indexes[letter]
+ @collection.path(index).should == @collection.path(index)
+ end
+ end
+
+ it "should return nil as the file name when an unknown index is provided" do
+ @collection.path(50).should be_nil
+ end
+
+ it "should provide a global collection" do
+ Puppet::FileCollection.collection.should be_instance_of(Puppet::FileCollection)
+ end
+
+ it "should reuse the global collection" do
+ Puppet::FileCollection.collection.should equal(Puppet::FileCollection.collection)
+ end
+end
diff --git a/spec/unit/file_collection/lookup.rb b/spec/unit/file_collection/lookup.rb
new file mode 100755
index 000000000..81cc61872
--- /dev/null
+++ b/spec/unit/file_collection/lookup.rb
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'puppet/file_collection/lookup'
+
+class LookupTester
+ include Puppet::FileCollection::Lookup
+end
+
+describe Puppet::FileCollection::Lookup do
+ before do
+ @tester = LookupTester.new
+
+ @file_collection = mock 'file_collection'
+ Puppet::FileCollection.stubs(:collection).returns @file_collection
+ end
+
+ it "should use the file collection to determine the index of the file name" do
+ @file_collection.expects(:index).with("/my/file").returns 50
+
+ @tester.file = "/my/file"
+ @tester.file_index.should == 50
+ end
+
+ it "should return nil as the file name if no index is set" do
+ @tester.file.should be_nil
+ end
+
+ it "should use the file collection to convert the index to a file name" do
+ @file_collection.expects(:path).with(25).returns "/path/to/file"
+
+ @tester.file_index = 25
+
+ @tester.file.should == "/path/to/file"
+ end
+
+ it "should support a line attribute" do
+ @tester.line = 50
+ @tester.line.should == 50
+ end
+
+ it "should default to the global file collection" do
+ Puppet::FileCollection.expects(:collection).returns "collection"
+ @tester.file_collection.should == "collection"
+ end
+end
diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb
index ed8809e73..d407796c6 100755
--- a/spec/unit/indirector/node/ldap.rb
+++ b/spec/unit/indirector/node/ldap.rb
@@ -91,6 +91,26 @@ describe Puppet::Node::Ldap do
@searcher.entry2hash(@entry)[:parameters]["foo"].should == "one"
end
+ it "should convert 'true' values to the boolean 'true'" do
+ @entry.stubs(:to_hash).returns({"one" => ["true"]})
+ @searcher.entry2hash(@entry)[:parameters]["one"].should == true
+ end
+
+ it "should convert 'false' values to the boolean 'false'" do
+ @entry.stubs(:to_hash).returns({"one" => ["false"]})
+ @searcher.entry2hash(@entry)[:parameters]["one"].should == false
+ end
+
+ it "should convert 'true' values to the boolean 'true' inside an array" do
+ @entry.stubs(:to_hash).returns({"one" => ["true", "other"]})
+ @searcher.entry2hash(@entry)[:parameters]["one"].should == [true, "other"]
+ end
+
+ it "should convert 'false' values to the boolean 'false' inside an array" do
+ @entry.stubs(:to_hash).returns({"one" => ["false", "other"]})
+ @searcher.entry2hash(@entry)[:parameters]["one"].should == [false, "other"]
+ end
+
it "should add the parent's name if present" do
@entry.stubs(:vals).with("parentnode").returns(%w{foo})
@searcher.entry2hash(@entry)[:parent].should == "foo"
diff --git a/spec/unit/other/transbucket.rb b/spec/unit/other/transbucket.rb
index 63de962e5..63b5137b5 100755
--- a/spec/unit/other/transbucket.rb
+++ b/spec/unit/other/transbucket.rb
@@ -70,20 +70,20 @@ describe Puppet::TransBucket, " when generating a catalog" do
@bottom = Puppet::TransBucket.new
@bottom.type = "fake"
@bottom.name = "bottom"
- @bottomobj = Puppet::TransObject.new("bottom", "user")
+ @bottomobj = Puppet::TransObject.new("bottom", "notify")
@bottom.push @bottomobj
@middle = Puppet::TransBucket.new
@middle.type = "fake"
@middle.name = "middle"
- @middleobj = Puppet::TransObject.new("middle", "user")
+ @middleobj = Puppet::TransObject.new("middle", "notify")
@middle.push(@middleobj)
@middle.push(@bottom)
@top = Puppet::TransBucket.new
@top.type = "fake"
@top.name = "top"
- @topobj = Puppet::TransObject.new("top", "user")
+ @topobj = Puppet::TransObject.new("top", "notify")
@top.push(@topobj)
@top.push(@middle)
@@ -94,7 +94,7 @@ describe Puppet::TransBucket, " when generating a catalog" do
it "should convert all transportable objects to RAL resources" do
@catalog = @top.to_catalog
@users.each do |name|
- @catalog.vertices.find { |r| r.class.name == :user and r.title == name }.should be_instance_of(Puppet::Type.type(:user))
+ @catalog.vertices.find { |r| r.class.name == :notify and r.title == name }.should be_instance_of(Puppet::Type.type(:notify))
end
end
diff --git a/spec/unit/parser/ast.rb b/spec/unit/parser/ast.rb
index 513943725..35e2b1eff 100644
--- a/spec/unit/parser/ast.rb
+++ b/spec/unit/parser/ast.rb
@@ -5,6 +5,10 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/parser/ast'
describe Puppet::Parser::AST do
+
+ it "should use the file lookup module" do
+ Puppet::Parser::AST.ancestors.should be_include(Puppet::FileCollection::Lookup)
+ end
it "should have a doc accessor" do
ast = Puppet::Parser::AST.new({})
@@ -34,4 +38,4 @@ describe Puppet::Parser::AST do
end
end
-end \ No newline at end of file
+end
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 92699e040..a042b4e72 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -44,6 +44,10 @@ describe Puppet::Parser::Resource do
end
end
+ it "should use the file lookup module" do
+ Puppet::Parser::Resource.ancestors.should be_include(Puppet::FileCollection::Lookup)
+ end
+
it "should be isomorphic if it is builtin and models an isomorphic type" do
Puppet::Type.type(:file).expects(:isomorphic?).returns(true)
@resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true
diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb
index bb1452692..6284e67cc 100755
--- a/spec/unit/parser/resource/reference.rb
+++ b/spec/unit/parser/resource/reference.rb
@@ -7,6 +7,10 @@ describe Puppet::Parser::Resource::Reference do
@type = Puppet::Parser::Resource::Reference
end
+ it "should use the file lookup module" do
+ Puppet::Parser::Resource::Reference.ancestors.should be_include(Puppet::FileCollection::Lookup)
+ end
+
it "should require a type" do
proc { @type.new(:title => "yay") }.should raise_error(Puppet::DevError)
end
diff --git a/spec/unit/property/list.rb b/spec/unit/property/list.rb
index 2fab868db..854ab4874 100644
--- a/spec/unit/property/list.rb
+++ b/spec/unit/property/list.rb
@@ -36,6 +36,10 @@ describe list_class do
@property.is_to_s(["foo","bar"]).should == "foo,bar"
end
+ it "should be able to correctly convert ':absent' to a string" do
+ @property.is_to_s(:absent).should == "absent"
+ end
+
describe "when adding should to current" do
it "should add the arrays when current is an array" do
@property.add_should_with_current(["foo"], ["bar"]).should == ["foo", "bar"]
diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb
index affc66676..284145657 100644
--- a/spec/unit/provider/augeas/augeas.rb
+++ b/spec/unit/provider/augeas/augeas.rb
@@ -133,14 +133,14 @@ describe provider_class do
tokens[0][0].should == "set"
tokens[0][1].should == 'Jar Jar'
tokens[0][2].should == "Binks is my copilot"
- end
+ end
end
describe "get filters" do
before do
augeas_stub = stub("augeas", :get => "value")
@provider = provider_class.new()
- @provider.stubs(:open_augeas).returns(augeas_stub)
+ @provider.aug= augeas_stub
end
it "should return false for a = nonmatch" do
@@ -168,7 +168,7 @@ describe provider_class do
before do
augeas_stub = stub("augeas", :match => ["set", "of", "values"])
@provider = provider_class.new()
- @provider.stubs(:open_augeas).returns(augeas_stub)
+ @provider.aug= augeas_stub
end
it "should return true for size match" do
@@ -202,53 +202,82 @@ describe provider_class do
end
end
- describe "need_to_run" do
+ describe "need to run" do
it "should handle no filters" do
- resource = stub("resource", :[] => "")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("")
+ augeas_stub = stub("augeas", :match => ["set", "of", "values"])
+ augeas_stub.stubs("close")
provider = provider_class.new(resource)
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == true
end
it "should return true when a get filter matches" do
- resource = stub("resource", :[] => "get path == value")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("get path == value")
provider = provider_class.new(resource)
augeas_stub = stub("augeas", :get => "value")
- provider.stubs(:open_augeas).returns(augeas_stub)
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == true
end
it "should return false when a get filter does not match" do
- resource = stub("resource", :[] => "get path == another value")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("get path == another value")
provider = provider_class.new(resource)
augeas_stub = stub("augeas", :get => "value")
- provider.stubs(:open_augeas).returns(augeas_stub)
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == false
end
it "should return true when a match filter matches" do
- resource = stub("resource", :[] => "match path size == 3")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("match path size == 3")
provider = provider_class.new(resource)
augeas_stub = stub("augeas", :match => ["set", "of", "values"])
- provider.stubs(:open_augeas).returns(augeas_stub)
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == true
end
it "should return false when a match filter does not match" do
- resource = stub("resource", :[] => "match path size == 2")
+ resource = stub("resource")
+ resource.stubs(:[]).returns(false).then.returns("match path size == 2")
+ provider = provider_class.new(resource)
+ augeas_stub = stub("augeas", :match => ["set", "of", "values"])
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
+ provider.need_to_run?.should == false
+ end
+
+ #This is a copy of the last one, with setting the force to true
+ it "setting force should not change the above logic" do
+ resource = stub("resource")
+ resource.stubs(:[]).returns(true).then.returns("match path size == 2")
provider = provider_class.new(resource)
augeas_stub = stub("augeas", :match => ["set", "of", "values"])
- provider.stubs(:open_augeas).returns(augeas_stub)
+ augeas_stub.stubs("close")
+ provider.aug= augeas_stub
+ provider.stubs(:get_augeas_version).returns("0.3.5")
provider.need_to_run?.should == false
end
end
- describe "augeas integration" do
+ describe "augeas execution integration" do
before do
@resource = stub("resource")
@provider = provider_class.new(@resource)
@augeas = stub("augeas")
- @provider.stubs(:open_augeas).returns(@augeas)
+ @provider.aug= @augeas
+ @provider.stubs(:get_augeas_version).returns("0.3.5")
end
it "should handle set commands" do
@@ -257,6 +286,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:set).with("/some/path/Jar/Jar", "Binks")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -266,6 +296,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:rm).with("/Jar/Jar")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -275,6 +306,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:rm).with("/Jar/Jar")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -284,9 +316,10 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:clear).with("/foo/Jar/Jar")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
- end
-
+ end
+
it "should handle ins commands with before" do
command = [["ins", "Binks", "before /Jar/Jar"]]
@@ -294,6 +327,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", true)
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -303,6 +337,7 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false)
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
@@ -312,16 +347,18 @@ describe provider_class do
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/Jar/Jar", "Binks", false)
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
- end
-
+ end
+
it "should handle multiple commands" do
command = [["ins", "Binks", "after /Jar/Jar"], ["clear", "/Jar/Jar"]]
context = "/foo"
@resource.expects(:[]).times(2).returns(command).then.returns(context)
@augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false)
- @augeas.expects(:clear).with("/foo/Jar/Jar")
+ @augeas.expects(:clear).with("/foo/Jar/Jar")
@augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
@provider.execute_changes.should == :executed
end
end
diff --git a/spec/unit/provider/mount/parsed.rb b/spec/unit/provider/mount/parsed.rb
index d2c992f33..364e145be 100755
--- a/spec/unit/provider/mount/parsed.rb
+++ b/spec/unit/provider/mount/parsed.rb
@@ -130,6 +130,7 @@ describe provider_class do
describe provider_class, " when modifying the filesystem tab" do
include ParsedMountTesting
before do
+ Puppet.settings.stubs(:use)
# Never write to disk, only to RAM.
@provider_class.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram))
diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb
index ec8f2b96a..18f3be126 100755
--- a/spec/unit/provider/ssh_authorized_key/parsed.rb
+++ b/spec/unit/provider/ssh_authorized_key/parsed.rb
@@ -72,32 +72,76 @@ describe provider_class do
genkey(key).should == "from=\"192.168.1.1\",no-pty,no-X11-forwarding ssh-rsa AAAAfsfddsjldjgksdflgkjsfdlgkj root@localhost\n"
end
- it "should prefetch ~user/.ssh/authorized_keys when user is given" do
- key = Puppet::Type.type(:ssh_authorized_key).create(
- :name => "Test",
- :key => "AA",
- :type => "rsa",
- :ensure => :present,
- :user => "root")
- prov = @provider.new key
+ it "'s parse_options method should be able to parse options containing commas" do
+ options = %w{from="host1.reductlivelabs.com,host.reductivelabs.com" command="/usr/local/bin/run" ssh-pty}
+ optionstr = options.join(", ")
- prov.prefetch
- prov.target.should == File.expand_path("~root/.ssh/authorized_keys")
+ @provider.parse_options(optionstr).should == options
end
+end
- it "should create destination dir" do
- # No idea how to test the flush method
+describe provider_class do
+ before :each do
+ @resource = stub("resource", :name => "foo")
+ @resource.stubs(:[]).returns "foo"
+ @provider = provider_class.new(@resource)
end
- it "should set correct default permissions" do
- # No idea how to test the flush method
- end
+ describe "when flushing" do
+ before :each do
+ # Stub file and directory operations
+ Dir.stubs(:mkdir)
+ File.stubs(:chmod)
+ File.stubs(:chown)
+ end
- it "'s parse_options method should be able to parse options containing commas" do
- options = %w{from="host1.reductlivelabs.com,host.reductivelabs.com" command="/usr/local/bin/run" ssh-pty}
- optionstr = options.join(", ")
+ describe "and a user has been specified" do
+ before :each do
+ @resource.stubs(:should).with(:user).returns "nobody"
+ target = File.expand_path("~nobody/.ssh/authorized_keys")
+ @resource.stubs(:should).with(:target).returns target
+ end
+
+ it "should create the directory" do
+ Dir.expects(:mkdir).with(File.expand_path("~nobody/.ssh"), 0700)
+ @provider.flush
+ end
+
+ it "should chown the directory to the user" do
+ uid = Puppet::Util.uid("nobody")
+ File.expects(:chown).with(uid, nil, File.expand_path("~nobody/.ssh"))
+ @provider.flush
+ end
+
+ it "should chown the key file to the user" do
+ uid = Puppet::Util.uid("nobody")
+ File.expects(:chown).with(uid, nil, File.expand_path("~nobody/.ssh/authorized_keys"))
+ @provider.flush
+ end
+
+ it "should chmod the key file to 0600" do
+ File.chmod(0600, File.expand_path("~nobody/.ssh/authorized_keys"))
+ @provider.flush
+ end
+ end
+
+ describe "and a target has been specified" do
+ before :each do
+ @resource.stubs(:should).with(:user).returns nil
+ @resource.stubs(:should).with(:target).returns "/tmp/.ssh/authorized_keys"
+ end
+
+ it "should make the directory" do
+ Dir.expects(:mkdir).with("/tmp/.ssh", 0755)
+ @provider.flush
+ end
+
+ it "should chmod the key file to 0644" do
+ File.expects(:chmod).with(0644, "/tmp/.ssh/authorized_keys")
+ @provider.flush
+ end
+ end
- @provider.parse_options(optionstr).should == options
end
end
diff --git a/spec/unit/rails.rb b/spec/unit/rails.rb
index f0ba2b942..48e0ab321 100755
--- a/spec/unit/rails.rb
+++ b/spec/unit/rails.rb
@@ -7,7 +7,8 @@ describe Puppet::Rails, "when initializing any connection" do
confine "Cannot test without ActiveRecord" => Puppet.features.rails?
before do
- @logger = stub 'logger', :level= => nil
+ Puppet.settings.stubs(:use)
+ @logger = mock 'logger'
@logger.stub_everything
Logger.stubs(:new).returns(@logger)
diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb
index 554d20ce9..efd071231 100755
--- a/spec/unit/transaction.rb
+++ b/spec/unit/transaction.rb
@@ -4,6 +4,21 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/transaction'
+describe Puppet::Transaction do
+ it "should match resources by name, not title, when prefetching" do
+ @catalog = Puppet::Node::Catalog.new
+ @transaction = Puppet::Transaction.new(@catalog)
+
+ # Have both a title and name
+ resource = Puppet::Type.type(:sshkey).create :title => "foo", :name => "bar", :type => :dsa, :key => "eh"
+ @catalog.add_resource resource
+
+ resource.provider.class.expects(:prefetch).with("bar" => resource)
+
+ @transaction.prefetch
+ end
+end
+
describe Puppet::Transaction, " when determining tags" do
before do
@config = Puppet::Resource::Catalog.new
diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb
index 0187cc41d..094596966 100755
--- a/spec/unit/type/file.rb
+++ b/spec/unit/type/file.rb
@@ -4,6 +4,8 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Type.type(:file) do
before do
+ Puppet.settings.stubs(:use)
+
@path = Tempfile.new("puppetspec")
pathname = @path.path
@path.close!()
diff --git a/spec/unit/type/group.rb b/spec/unit/type/group.rb
index c9a7fc904..fad7a0c48 100755
--- a/spec/unit/type/group.rb
+++ b/spec/unit/type/group.rb
@@ -4,6 +4,9 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Type.type(:group) do
before do
+ unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
+ ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin"
+ end
@class = Puppet::Type.type(:group)
end
diff --git a/spec/unit/type/noop_metaparam.rb b/spec/unit/type/noop_metaparam.rb
index 98cb0409e..2c4b6dc49 100755
--- a/spec/unit/type/noop_metaparam.rb
+++ b/spec/unit/type/noop_metaparam.rb
@@ -6,6 +6,7 @@ require 'puppet/type'
describe Puppet::Type.type(:file).attrclass(:noop) do
before do
+ Puppet.settings.stubs(:use)
@file = Puppet::Type.newfile :path => "/what/ever"
end
diff --git a/spec/unit/type/ssh_authorized_key.rb b/spec/unit/type/ssh_authorized_key.rb
index 9a2389eef..db389864e 100755
--- a/spec/unit/type/ssh_authorized_key.rb
+++ b/spec/unit/type/ssh_authorized_key.rb
@@ -89,13 +89,36 @@ describe ssh_authorized_key do
@class.attrtype(:target).should == :property
end
- it "should raise an error when neither user nor target is given" do
- proc do
- @class.new(
- :name => "Test",
- :key => "AAA",
- :type => "ssh-rsa",
- :ensure => :present)
- end.should raise_error(Puppet::Error)
+ describe "when neither user nor target is specified" do
+ it "should raise an error" do
+ proc do
+ @class.create(
+ :name => "Test",
+ :key => "AAA",
+ :type => "ssh-rsa",
+ :ensure => :present)
+ end.should raise_error(Puppet::Error)
+ end
+ end
+
+ describe "when both target and user are specified" do
+ it "should use target" do
+ resource = @class.create(
+ :name => "Test",
+ :user => "root",
+ :target => "/tmp/blah")
+ resource.should(:target).should == "/tmp/blah"
+ end
+ end
+
+
+ describe "when user is specified" do
+ it "should determine target" do
+ resource = @class.create(
+ :name => "Test",
+ :user => "root")
+ target = File.expand_path("~root/.ssh/authorized_keys")
+ resource.should(:target).should == target
+ end
end
end
diff --git a/spec/unit/type/tidy.rb b/spec/unit/type/tidy.rb
index 72f6b0f10..e17f65de4 100755
--- a/spec/unit/type/tidy.rb
+++ b/spec/unit/type/tidy.rb
@@ -2,13 +2,26 @@
require File.dirname(__FILE__) + '/../../spec_helper'
-describe Puppet::Type.type(:tidy) do
+tidy = Puppet::Type.type(:tidy)
+
+describe tidy do
+ before do
+ Puppet.settings.stubs(:use)
+ end
+
it "should use :lstat when stating a file" do
tidy = Puppet::Type.type(:tidy).new :path => "/foo/bar", :age => "1d"
stat = mock 'stat'
File.expects(:lstat).with("/foo/bar").returns stat
tidy.stat("/foo/bar").should == stat
end
+
+ it "should be in sync if the targeted file does not exist" do
+ File.expects(:lstat).with("/tmp/foonesslaters").raises Errno::ENOENT
+ @tidy = tidy.create :path => "/tmp/foonesslaters", :age => "100d"
+
+ @tidy.property(:ensure).must be_insync({})
+ end
[:age, :size, :path, :matches, :type, :recurse, :rmdirs].each do |param|
it "should have a %s parameter" % param do
diff --git a/spec/unit/type/user.rb b/spec/unit/type/user.rb
index 57af7f093..bf2af23ab 100755
--- a/spec/unit/type/user.rb
+++ b/spec/unit/type/user.rb
@@ -6,6 +6,9 @@ user = Puppet::Type.type(:user)
describe user do
before do
+ unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
+ ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin"
+ end
@provider = stub 'provider'
@resource = stub 'resource', :resource => nil, :provider => @provider, :line => nil, :file => nil
end
diff --git a/tasks/rake/reductive.rb b/tasks/rake/reductive.rb
index fb0921768..4a3e18bc1 100644
--- a/tasks/rake/reductive.rb
+++ b/tasks/rake/reductive.rb
@@ -457,10 +457,10 @@ class Rake::RedLabProject < Rake::TaskLib
desc "Run all unit tests."
task :alltests do
- if FileTest.exists?("test/Rakefile")
- sh %{cd test; rake}
+ if FileTest.exists?("spec/Rakefile")
+ sh %{cd spec; rake}
else
- Dir.chdir("test") do
+ Dir.chdir("spec") do
Dir.entries(".").find_all { |f| f =~ /\.rb/ }.each do |f|
sh %{ruby #{f}}
end
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index 3c6083fa6..2f84a6c28 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -166,6 +166,9 @@ module PuppetTest
end
def setup
+ unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
+ ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin"
+ end
@memoryatstart = Puppet::Util.memory
if defined? @@testcount
@@testcount += 1