summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppetlabs.com>2011-08-19 14:03:56 -0700
committerJosh Cooper <josh@puppetlabs.com>2011-08-19 14:03:56 -0700
commit384302af6dec8c51442f2f29a4c7c555379cd297 (patch)
tree27680b19648100058c752e5fa4136a88a73d7a4f
parent71e190bf255f98e900f7ddd55db393d448df3274 (diff)
parent2091cbeade9d69a18689609f407f9d7f0304dc04 (diff)
downloadpuppet-384302af6dec8c51442f2f29a4c7c555379cd297.tar.gz
puppet-384302af6dec8c51442f2f29a4c7c555379cd297.tar.xz
puppet-384302af6dec8c51442f2f29a4c7c555379cd297.zip
Merge branch 'backport-windows-work-to-2.7' into 2.7.x
* backport-windows-work-to-2.7: (60 commits) maint: Fix build break due to recent merge from 2.7.x to master Fix posix exec provider spec failures on Windows (#5495) Remove dead Windows-specific code from posix exec provider Stop trying to make config directories in Windows specs (#8272) Add missing tests for Windows service provider methods. (#8409) Add a default group provider for Windows (#8408) Add a default user provider for Windows (#8408/8409) Add a Windows ADSI helper module (#8663) Exclude exec timeout test on Windows (#8663) Exclude git rev-parse HEAD spec test on Windows Check for the appropriate permissions in File type tests on Windows Remove :fails_on_windows from file type tests that no longer fail on Windows Disable file bucket diffing tests on Windows Always put a slash between the checksum and path in filebucket URLs Treat Windows absolute paths as absolute paths Consolidate test logic determining if a registered file is in the temp directory Clarify logic and error messages when initializing Puppet::FileBucket::File Disable symlink related file tests on Windows (#8644) Host provider on Windows (#8660) Fix destdir option on Windows ...
-rwxr-xr-xinstall.rb29
-rw-r--r--lib/puppet/application/master.rb2
-rw-r--r--lib/puppet/configurer.rb4
-rw-r--r--lib/puppet/defaults.rb16
-rw-r--r--lib/puppet/feature/base.rb14
-rw-r--r--lib/puppet/file_bucket/dipper.rb5
-rw-r--r--lib/puppet/file_bucket/file.rb6
-rw-r--r--lib/puppet/file_serving/base.rb5
-rw-r--r--lib/puppet/file_serving/configuration.rb16
-rw-r--r--lib/puppet/file_serving/fileset.rb9
-rw-r--r--lib/puppet/file_serving/indirection_hooks.rb1
-rw-r--r--lib/puppet/file_serving/mount.rb1
-rw-r--r--lib/puppet/file_serving/mount/file.rb21
-rw-r--r--lib/puppet/indirector/facts/facter.rb4
-rw-r--r--lib/puppet/indirector/file_server.rb2
-rw-r--r--lib/puppet/indirector/indirection.rb8
-rw-r--r--lib/puppet/indirector/request.rb4
-rw-r--r--lib/puppet/network/client.rb5
-rw-r--r--lib/puppet/network/http_pool.rb56
-rw-r--r--lib/puppet/node/environment.rb20
-rw-r--r--lib/puppet/parameter.rb6
-rw-r--r--lib/puppet/parser/type_loader.rb3
-rw-r--r--lib/puppet/provider/group/windows_adsi.rb48
-rw-r--r--lib/puppet/provider/host/parsed.rb3
-rw-r--r--lib/puppet/provider/service/windows.rb110
-rw-r--r--lib/puppet/provider/user/windows_adsi.rb71
-rw-r--r--lib/puppet/resource/catalog.rb20
-rw-r--r--lib/puppet/ssl/certificate_authority.rb12
-rw-r--r--lib/puppet/ssl/host.rb13
-rw-r--r--lib/puppet/type.rb8
-rw-r--r--lib/puppet/type/file.rb43
-rwxr-xr-xlib/puppet/type/file/source.rb23
-rw-r--r--lib/puppet/type/service.rb10
-rw-r--r--lib/puppet/util/adsi.rb278
-rw-r--r--lib/puppet/util/autoload.rb2
-rw-r--r--lib/puppet/util/cacher.rb82
-rw-r--r--lib/puppet/util/rdoc/parser.rb4
-rw-r--r--lib/puppet/util/run_mode.rb4
-rw-r--r--lib/puppet/util/settings.rb9
-rw-r--r--lib/puppet/util/settings/file_setting.rb2
-rwxr-xr-xspec/integration/application/doc_spec.rb2
-rwxr-xr-xspec/integration/defaults_spec.rb10
-rwxr-xr-xspec/integration/file_serving/content_spec.rb2
-rwxr-xr-xspec/integration/file_serving/metadata_spec.rb2
-rwxr-xr-xspec/integration/file_serving/terminus_helper_spec.rb2
-rwxr-xr-xspec/integration/indirector/direct_file_server_spec.rb8
-rwxr-xr-xspec/integration/indirector/file_content/file_server_spec.rb4
-rwxr-xr-xspec/integration/indirector/file_metadata/file_server_spec.rb2
-rwxr-xr-xspec/integration/network/server/webrick_spec.rb15
-rwxr-xr-xspec/integration/node/facts_spec.rb2
-rwxr-xr-xspec/integration/parser/compiler_spec.rb3
-rwxr-xr-xspec/integration/provider/mount_spec.rb2
-rwxr-xr-xspec/integration/provider/package_spec.rb2
-rwxr-xr-x[-rw-r--r--]spec/integration/provider/ssh_authorized_key_spec.rb2
-rwxr-xr-xspec/integration/resource/catalog_spec.rb1
-rwxr-xr-xspec/integration/ssl/certificate_authority_spec.rb16
-rwxr-xr-xspec/integration/ssl/certificate_request_spec.rb23
-rwxr-xr-xspec/integration/ssl/certificate_revocation_list_spec.rb17
-rwxr-xr-xspec/integration/ssl/host_spec.rb18
-rwxr-xr-xspec/integration/transaction/report_spec.rb1
-rwxr-xr-xspec/integration/transaction_spec.rb24
-rwxr-xr-xspec/integration/type/file_spec.rb32
-rwxr-xr-xspec/integration/type/tidy_spec.rb2
-rwxr-xr-xspec/integration/util/settings_spec.rb4
-rwxr-xr-xspec/lib/puppet_spec/files.rb28
-rwxr-xr-xspec/shared_behaviours/file_server_terminus.rb2
-rwxr-xr-xspec/unit/application/device_spec.rb14
-rwxr-xr-xspec/unit/application/inspect_spec.rb3
-rwxr-xr-xspec/unit/application/master_spec.rb9
-rwxr-xr-xspec/unit/application/queue_spec.rb2
-rwxr-xr-xspec/unit/application/resource_spec.rb7
-rwxr-xr-xspec/unit/configurer/downloader_spec.rb7
-rwxr-xr-xspec/unit/daemon_spec.rb4
-rwxr-xr-xspec/unit/face/ca_spec.rb2
-rwxr-xr-xspec/unit/file_bucket/dipper_spec.rb8
-rwxr-xr-xspec/unit/file_bucket/file_spec.rb12
-rwxr-xr-xspec/unit/file_serving/configuration_spec.rb63
-rwxr-xr-xspec/unit/file_serving/fileset_spec.rb126
-rwxr-xr-xspec/unit/file_serving/mount/file_spec.rb332
-rwxr-xr-xspec/unit/indirector/certificate_request/ca_spec.rb2
-rwxr-xr-xspec/unit/indirector/certificate_status/file_spec.rb2
-rwxr-xr-xspec/unit/indirector/file_bucket_file/file_spec.rb6
-rwxr-xr-xspec/unit/indirector/file_server_spec.rb2
-rwxr-xr-xspec/unit/indirector/indirection_spec.rb4
-rwxr-xr-xspec/unit/indirector/resource/ral_spec.rb2
-rwxr-xr-xspec/unit/indirector/resource_type/parser_spec.rb6
-rwxr-xr-xspec/unit/indirector/ssl_file_spec.rb4
-rwxr-xr-xspec/unit/module_spec.rb4
-rwxr-xr-xspec/unit/network/client_spec.rb41
-rwxr-xr-xspec/unit/network/handler/fileserver_spec.rb10
-rwxr-xr-xspec/unit/network/http/webrick_spec.rb10
-rwxr-xr-xspec/unit/network/http_pool_spec.rb75
-rwxr-xr-xspec/unit/node/environment_spec.rb49
-rwxr-xr-xspec/unit/node/facts_spec.rb4
-rwxr-xr-xspec/unit/node_spec.rb2
-rwxr-xr-xspec/unit/other/selinux_spec.rb4
-rwxr-xr-xspec/unit/parameter_spec.rb10
-rwxr-xr-xspec/unit/parser/compiler_spec.rb4
-rwxr-xr-xspec/unit/parser/files_spec.rb11
-rwxr-xr-xspec/unit/parser/functions/extlookup_spec.rb9
-rwxr-xr-xspec/unit/parser/functions/sprintf_spec.rb3
-rwxr-xr-xspec/unit/parser/type_loader_spec.rb14
-rwxr-xr-xspec/unit/property_spec.rb2
-rwxr-xr-xspec/unit/provider/exec/shell_spec.rb2
-rw-r--r--spec/unit/provider/group/windows_adsi_spec.rb79
-rwxr-xr-xspec/unit/provider/macauthorization_spec.rb5
-rwxr-xr-xspec/unit/provider/mount/parsed_spec.rb2
-rwxr-xr-xspec/unit/provider/service/smf_spec.rb1
-rwxr-xr-xspec/unit/provider/service/windows_spec.rb166
-rwxr-xr-xspec/unit/provider/ssh_authorized_key/parsed_spec.rb4
-rwxr-xr-xspec/unit/provider/user/user_role_add_spec.rb2
-rwxr-xr-xspec/unit/provider/user/useradd_spec.rb2
-rw-r--r--spec/unit/provider/user/windows_adsi_spec.rb110
-rwxr-xr-xspec/unit/resource/catalog_spec.rb37
-rwxr-xr-xspec/unit/resource/status_spec.rb6
-rwxr-xr-xspec/unit/resource_spec.rb3
-rwxr-xr-xspec/unit/ssl/certificate_authority_spec.rb4
-rwxr-xr-xspec/unit/ssl/host_spec.rb25
-rwxr-xr-xspec/unit/ssl/inventory_spec.rb4
-rwxr-xr-xspec/unit/sslcertificates/ca_spec.rb16
-rwxr-xr-xspec/unit/transaction/event_manager_spec.rb6
-rwxr-xr-xspec/unit/transaction/event_spec.rb4
-rwxr-xr-xspec/unit/transaction/report_spec.rb8
-rwxr-xr-xspec/unit/transaction/resource_harness_spec.rb14
-rwxr-xr-xspec/unit/transaction_spec.rb4
-rwxr-xr-xspec/unit/type/cron_spec.rb2
-rwxr-xr-xspec/unit/type/exec_spec.rb62
-rwxr-xr-xspec/unit/type/file/checksum_spec.rb17
-rwxr-xr-xspec/unit/type/file/content_spec.rb3
-rwxr-xr-xspec/unit/type/file/selinux_spec.rb18
-rwxr-xr-xspec/unit/type/file/source_spec.rb54
-rwxr-xr-xspec/unit/type/file_spec.rb381
-rwxr-xr-xspec/unit/type/group_spec.rb2
-rwxr-xr-xspec/unit/type/mount_spec.rb10
-rwxr-xr-xspec/unit/type/noop_metaparam_spec.rb4
-rwxr-xr-xspec/unit/type/resources_spec.rb4
-rwxr-xr-xspec/unit/type/service_spec.rb15
-rwxr-xr-xspec/unit/type/ssh_authorized_key_spec.rb6
-rwxr-xr-xspec/unit/type/tidy_spec.rb4
-rwxr-xr-xspec/unit/type/user_spec.rb2
-rwxr-xr-xspec/unit/type_spec.rb57
-rw-r--r--spec/unit/util/adsi_spec.rb202
-rwxr-xr-xspec/unit/util/autoload_spec.rb42
-rwxr-xr-xspec/unit/util/backups_spec.rb29
-rwxr-xr-xspec/unit/util/cacher_spec.rb205
-rwxr-xr-xspec/unit/util/execution_stub_spec.rb2
-rwxr-xr-xspec/unit/util/log_spec.rb6
-rwxr-xr-xspec/unit/util/logging_spec.rb4
-rwxr-xr-xspec/unit/util/network_device/config_spec.rb8
-rwxr-xr-xspec/unit/util/rdoc/parser_spec.rb8
-rwxr-xr-xspec/unit/util/run_mode_spec.rb8
-rwxr-xr-xspec/unit/util/settings/file_setting_spec.rb9
-rwxr-xr-xspec/unit/util/settings_spec.rb24
-rwxr-xr-xspec/unit/util/storage_spec.rb2
-rwxr-xr-xspec/unit/util/suidmanager_spec.rb3
-rwxr-xr-xtest/lib/puppettest.rb1
-rwxr-xr-xtest/network/handler/master.rb5
-rwxr-xr-xtest/network/server/webrick.rb27
-rwxr-xr-xtest/ral/type/filesources.rb1
159 files changed, 2270 insertions, 1535 deletions
diff --git a/install.rb b/install.rb
index dcff82403..3d109b9a7 100755
--- a/install.rb
+++ b/install.rb
@@ -243,6 +243,9 @@ def prepare_installation
if not InstallOptions.configdir.nil?
configdir = InstallOptions.configdir
+ elsif $operatingsystem == "windows"
+ require 'win32/dir'
+ configdir = File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "etc")
else
configdir = "/etc/puppet"
end
@@ -283,18 +286,18 @@ def prepare_installation
if not InstallOptions.destdir.nil?
destdir = InstallOptions.destdir
# To be deprecated once people move over to using --destdir option
- elsif ENV['DESTDIR'] != nil?
+ elsif not ENV['DESTDIR'].nil?
destdir = ENV['DESTDIR']
warn "DESTDIR is deprecated. Use --destdir instead."
else
destdir = ''
end
- configdir = "#{destdir}#{configdir}"
- bindir = "#{destdir}#{bindir}"
- sbindir = "#{destdir}#{sbindir}"
- mandir = "#{destdir}#{mandir}"
- sitelibdir = "#{destdir}#{sitelibdir}"
+ configdir = join(destdir, configdir)
+ bindir = join(destdir, bindir)
+ sbindir = join(destdir, sbindir)
+ mandir = join(destdir, mandir)
+ sitelibdir = join(destdir, sitelibdir)
FileUtils.makedirs(configdir) if InstallOptions.configs
FileUtils.makedirs(bindir)
@@ -314,6 +317,16 @@ def prepare_installation
end
##
+# Join two paths. On Windows, dir must be converted to a relative path,
+# by stripping the drive letter, but only if the basedir is not empty.
+#
+def join(basedir, dir)
+ return "#{basedir}#{dir[2..-1]}" if $operatingsystem == "windows" and basedir.length > 0 and dir.length > 2
+
+ "#{basedir}#{dir}"
+end
+
+##
# Build the rdoc documentation. Also, try to build the RI documentation.
#
def build_rdoc(files)
@@ -405,8 +418,10 @@ def install_binfile(from, op_file, target)
if not installed_wrapper
tmp_file2 = File.join(tmp_dir, '_tmp_wrapper')
cwn = File.join(Config::CONFIG['bindir'], op_file)
- cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } )
+ regex_safe_ruby = Regexp.escape(ruby.gsub(%r{/}) { "\\" })
+ regex_safe_cwn = Regexp.escape(cwn.gsub(%r{/}) { "\\" })
+ cwv = CMD_WRAPPER.gsub('<ruby>', regex_safe_ruby).gsub('<command>', regex_safe_cwn)
File.open(tmp_file2, "wb") { |cw| cw.puts cwv }
FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb
index 18425c8bc..b4da770f0 100644
--- a/lib/puppet/application/master.rb
+++ b/lib/puppet/application/master.rb
@@ -206,6 +206,8 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
end
def setup
+ raise Puppet::Error.new("Puppet master is not supported on Microsoft Windows") if Puppet.features.microsoft_windows?
+
# Handle the logging settings.
if options[:debug] or options[:verbose]
if options[:debug]
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index 3d6e8557c..5581917a1 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -161,10 +161,6 @@ class Puppet::Configurer
# Make sure we forget the retained module_directories of any autoload
# we might have used.
Thread.current[:env_module_directories] = nil
-
- # Now close all of our existing http connections, since there's no
- # reason to leave them lying open.
- Puppet::Network::HttpPool.clear_http_instances
end
ensure
Puppet::Util::Log.close(report)
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index d714305b3..106e94b02 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -47,10 +47,14 @@ module Puppet
exits. Comma-separate multiple values. For a list of all values,
specify 'all'. This feature is only available in Puppet versions
higher than 0.18.4."],
- :color => ["ansi", "Whether to use colors when logging to the console.
+ :color => {
+ :default => (Puppet.features.microsoft_windows? ? "false" : "ansi"),
+ :type => :setting,
+ :desc => "Whether to use colors when logging to the console.
Valid values are `ansi` (equivalent to `true`), `html` (mostly
used during testing with TextMate), and `false`, which produces
- no color."],
+ no color.",
+ },
:mkusers => [false,
"Whether to create the necessary user and group that puppet agent will
run as."],
@@ -437,9 +441,11 @@ module Puppet
authorization system for `puppet master`."
],
:ca => [true, "Wether the master should function as a certificate authority."],
- :modulepath => {:default => "$confdir/modules:/usr/share/puppet/modules",
- :desc => "The search path for modules as a colon-separated list of
- directories.", :type => :setting }, # We don't want this to be considered a file, since it's multiple files.
+ :modulepath => {
+ :default => "$confdir/modules#{File::PATH_SEPARATOR}/usr/share/puppet/modules",
+ :desc => "The search path for modules as a list of directories separated by the '#{File::PATH_SEPARATOR}' character.",
+ :type => :setting # We don't want this to be considered a file, since it's multiple files.
+ },
:ssl_client_header => ["HTTP_X_CLIENT_DN", "The header containing an authenticated
client's SSL DN. Only used with Mongrel. This header must be set by the proxy
to the authenticated client's SSL DN (e.g., `/CN=puppet.puppetlabs.com`).
diff --git a/lib/puppet/feature/base.rb b/lib/puppet/feature/base.rb
index fb73df019..2eddadb7a 100644
--- a/lib/puppet/feature/base.rb
+++ b/lib/puppet/feature/base.rb
@@ -40,7 +40,19 @@ Puppet.features.add(:posix) do
end
# We can use Microsoft Windows functions
-Puppet.features.add(:microsoft_windows, :libs => ["sys/admin", "win32/process", "win32/dir"])
+Puppet.features.add(:microsoft_windows) do
+ begin
+ require 'sys/admin'
+ require 'win32/process'
+ require 'win32/dir'
+ require 'win32/service'
+ require 'win32ole'
+ require 'win32/api'
+ true
+ rescue LoadError => err
+ warn "Cannot run on Microsoft Windows without the sys-admin, win32-process, win32-dir & win32-service gems: #{err}" unless Puppet.features.posix?
+ end
+end
raise Puppet::Error,"Cannot determine basic system flavour" unless Puppet.features.posix? or Puppet.features.microsoft_windows?
diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb
index d6f6a3747..870c50eec 100644
--- a/lib/puppet/file_bucket/dipper.rb
+++ b/lib/puppet/file_bucket/dipper.rb
@@ -35,11 +35,12 @@ class Puppet::FileBucket::Dipper
begin
file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path)
files_original_path = absolutize_path(file)
- dest_path = "#{@rest_path}#{file_bucket_file.name}#{files_original_path}"
+ dest_path = "#{@rest_path}#{file_bucket_file.name}/#{files_original_path}"
+ file_bucket_path = "#{@rest_path}#{file_bucket_file.checksum_type}/#{file_bucket_file.checksum_data}/#{files_original_path}"
# Make a HEAD request for the file so that we don't waste time
# uploading it if it already exists in the bucket.
- unless Puppet::FileBucket::File.indirection.head("#{@rest_path}#{file_bucket_file.checksum_type}/#{file_bucket_file.checksum_data}#{files_original_path}")
+ unless Puppet::FileBucket::File.indirection.head(file_bucket_path)
Puppet::FileBucket::File.indirection.save(file_bucket_file, dest_path)
end
diff --git a/lib/puppet/file_bucket/file.rb b/lib/puppet/file_bucket/file.rb
index 08c0329f1..2a0558fde 100644
--- a/lib/puppet/file_bucket/file.rb
+++ b/lib/puppet/file_bucket/file.rb
@@ -15,11 +15,11 @@ class Puppet::FileBucket::File
attr :bucket_path
def initialize( contents, options = {} )
- raise ArgumentError if !contents.is_a?(String)
- @contents = contents
+ raise ArgumentError.new("contents must be a String, got a #{contents.class}") unless contents.is_a?(String)
+ @contents = contents
@bucket_path = options.delete(:bucket_path)
- raise ArgumentError if options != {}
+ raise ArgumentError.new("Unknown option(s): #{options.keys.join(', ')}") unless options.empty?
end
def checksum_type
diff --git a/lib/puppet/file_serving/base.rb b/lib/puppet/file_serving/base.rb
index 1927b95d6..e936b5e75 100644
--- a/lib/puppet/file_serving/base.rb
+++ b/lib/puppet/file_serving/base.rb
@@ -49,7 +49,10 @@ class Puppet::FileServing::Base
# Set our base path.
attr_reader :path
def path=(path)
- raise ArgumentError.new("Paths must be fully qualified") unless path =~ /^#{::File::SEPARATOR}/
+ unless path =~ /^#{::File::SEPARATOR}/ or path =~ /^[a-z]:[\/\\]/i
+ raise ArgumentError.new("Paths must be fully qualified")
+ end
+
@path = path
end
diff --git a/lib/puppet/file_serving/configuration.rb b/lib/puppet/file_serving/configuration.rb
index 387f16667..02bca1bea 100644
--- a/lib/puppet/file_serving/configuration.rb
+++ b/lib/puppet/file_serving/configuration.rb
@@ -1,26 +1,24 @@
+require 'monitor'
require 'puppet'
require 'puppet/file_serving'
require 'puppet/file_serving/mount'
require 'puppet/file_serving/mount/file'
require 'puppet/file_serving/mount/modules'
require 'puppet/file_serving/mount/plugins'
-require 'puppet/util/cacher'
class Puppet::FileServing::Configuration
require 'puppet/file_serving/configuration/parser'
- class << self
- include Puppet::Util::Cacher
- cached_attr(:configuration) { new }
+ extend MonitorMixin
+
+ def self.configuration
+ synchronize do
+ @configuration ||= new
+ end
end
Mount = Puppet::FileServing::Mount
- # Create our singleton configuration.
- def self.create
- configuration
- end
-
private_class_method :new
attr_reader :mounts
diff --git a/lib/puppet/file_serving/fileset.rb b/lib/puppet/file_serving/fileset.rb
index 30fad8d1f..8bc5e256d 100644
--- a/lib/puppet/file_serving/fileset.rb
+++ b/lib/puppet/file_serving/fileset.rb
@@ -55,8 +55,13 @@ class Puppet::FileServing::Fileset
end
def initialize(path, options = {})
- path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
- raise ArgumentError.new("Fileset paths must be fully qualified") unless File.expand_path(path) == path
+ if Puppet.features.microsoft_windows?
+ # REMIND: UNC path
+ path = path.chomp(File::SEPARATOR) unless path =~ /^[A-Za-z]:\/$/
+ else
+ path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
+ end
+ raise ArgumentError.new("Fileset paths must be fully qualified: #{path}") unless File.expand_path(path) == path
@path = path
diff --git a/lib/puppet/file_serving/indirection_hooks.rb b/lib/puppet/file_serving/indirection_hooks.rb
index 499767c41..bdcc8865e 100644
--- a/lib/puppet/file_serving/indirection_hooks.rb
+++ b/lib/puppet/file_serving/indirection_hooks.rb
@@ -13,6 +13,7 @@ module Puppet::FileServing::IndirectionHooks
# Short-circuit to :file if it's a fully-qualified path or specifies a 'file' protocol.
return PROTOCOL_MAP["file"] if request.key =~ /^#{::File::SEPARATOR}/
+ return PROTOCOL_MAP["file"] if request.key =~ /^[a-z]:[\/\\]/i
return PROTOCOL_MAP["file"] if request.protocol == "file"
# We're heading over the wire the protocol is 'puppet' and we've got a server name or we're not named 'apply' or 'puppet'
diff --git a/lib/puppet/file_serving/mount.rb b/lib/puppet/file_serving/mount.rb
index 130d6aeb7..da7102fd8 100644
--- a/lib/puppet/file_serving/mount.rb
+++ b/lib/puppet/file_serving/mount.rb
@@ -1,6 +1,5 @@
require 'puppet/network/authstore'
require 'puppet/util/logging'
-require 'puppet/util/cacher'
require 'puppet/file_serving'
require 'puppet/file_serving/metadata'
require 'puppet/file_serving/content'
diff --git a/lib/puppet/file_serving/mount/file.rb b/lib/puppet/file_serving/mount/file.rb
index 7d622e4bf..7f5af7f52 100644
--- a/lib/puppet/file_serving/mount/file.rb
+++ b/lib/puppet/file_serving/mount/file.rb
@@ -1,18 +1,15 @@
-require 'puppet/util/cacher'
-
require 'puppet/file_serving/mount'
class Puppet::FileServing::Mount::File < Puppet::FileServing::Mount
- class << self
- include Puppet::Util::Cacher
-
- cached_attr(:localmap) do
- { "h" => Facter.value("hostname"),
- "H" => [Facter.value("hostname"),
- Facter.value("domain")].join("."),
- "d" => Facter.value("domain")
- }
- end
+ def self.localmap
+ @localmap ||= {
+ "h" => Facter.value("hostname"),
+ "H" => [
+ Facter.value("hostname"),
+ Facter.value("domain")
+ ].join("."),
+ "d" => Facter.value("domain")
+ }
end
def complete_path(relative_path, node)
diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb
index ab7378a34..6312a95fb 100644
--- a/lib/puppet/indirector/facts/facter.rb
+++ b/lib/puppet/indirector/facts/facter.rb
@@ -9,12 +9,12 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
def self.load_fact_plugins
# Add any per-module fact directories to the factpath
- module_fact_dirs = Puppet[:modulepath].split(":").collect do |d|
+ module_fact_dirs = Puppet[:modulepath].split(File::PATH_SEPARATOR).collect do |d|
["lib", "plugins"].map do |subdirectory|
Dir.glob("#{d}/*/#{subdirectory}/facter")
end
end.flatten
- dirs = module_fact_dirs + Puppet[:factpath].split(":")
+ dirs = module_fact_dirs + Puppet[:factpath].split(File::PATH_SEPARATOR)
x = dirs.each do |dir|
load_facts_in_dir(dir)
end
diff --git a/lib/puppet/indirector/file_server.rb b/lib/puppet/indirector/file_server.rb
index a1a5c0a44..9516a404c 100644
--- a/lib/puppet/indirector/file_server.rb
+++ b/lib/puppet/indirector/file_server.rb
@@ -60,6 +60,6 @@ class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus
# Our fileserver configuration, if needed.
def configuration
- Puppet::FileServing::Configuration.create
+ Puppet::FileServing::Configuration.configuration
end
end
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index d958a82ac..20b260b83 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -1,13 +1,11 @@
require 'puppet/util/docs'
require 'puppet/indirector/envelope'
require 'puppet/indirector/request'
-require 'puppet/util/cacher'
# The class that connects functional classes with their different collection
# back-ends. Each indirection has a set of associated terminus classes,
# each of which is a subclass of Puppet::Indirector::Terminus.
class Puppet::Indirector::Indirection
- include Puppet::Util::Cacher
include Puppet::Util::Docs
@@indirections = []
@@ -33,6 +31,8 @@ class Puppet::Indirector::Indirection
attr_accessor :name, :model
+ attr_reader :termini
+
# Create and return our cache terminus.
def cache
raise(Puppet::DevError, "Tried to cache when no cache class was set") unless cache_class
@@ -88,6 +88,7 @@ class Puppet::Indirector::Indirection
def initialize(model, name, options = {})
@model = model
@name = name
+ @termini = {}
@cache_class = nil
@terminus_class = nil
@@ -313,7 +314,4 @@ class Puppet::Indirector::Indirection
end
klass.new
end
-
- # Cache our terminus instances indefinitely, but make it easy to clean them up.
- cached_attr(:termini) { Hash.new }
end
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index fd8d654dd..0388bd31a 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -76,7 +76,9 @@ class Puppet::Indirector::Request
# because it rewrites the key. We could otherwise strip server/port/etc
# info out in the REST class, but it seemed bad design for the REST
# class to rewrite the key.
- if key.to_s =~ /^\w+:\/\// # it's a URI
+ if key.to_s =~ /^[a-z]:[\/\\]/i # It's an absolute path for Windows.
+ @key = key
+ elsif key.to_s =~ /^\w+:\/\// # it's a URI
set_uri_key(key)
else
@key = key
diff --git a/lib/puppet/network/client.rb b/lib/puppet/network/client.rb
index c56b21393..f9c4c5fea 100644
--- a/lib/puppet/network/client.rb
+++ b/lib/puppet/network/client.rb
@@ -82,11 +82,6 @@ class Puppet::Network::Client
self.read_cert
- # We have to start the HTTP connection manually before we start
- # sending it requests or keep-alive won't work. Note that with #1010,
- # we don't currently actually want keep-alive.
- @driver.start if @driver.respond_to? :start and Puppet::Network::HttpPool.keep_alive?
-
@local = false
elsif hash.include?(driverparam)
@driver = hash[driverparam]
diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb
index 7d227b4d4..8baf48c77 100644
--- a/lib/puppet/network/http_pool.rb
+++ b/lib/puppet/network/http_pool.rb
@@ -1,53 +1,14 @@
require 'puppet/ssl/host'
require 'net/https'
-require 'puppet/util/cacher'
module Puppet::Network; end
-# Manage Net::HTTP instances for keep-alive.
module Puppet::Network::HttpPool
- class << self
- include Puppet::Util::Cacher
-
- private
-
- cached_attr(:http_cache) { Hash.new }
- end
-
# Use the global localhost instance.
def self.ssl_host
Puppet::SSL::Host.localhost
end
- # 2008/03/23
- # LAK:WARNING: Enabling this has a high propability of
- # causing corrupt files and who knows what else. See #1010.
- HTTP_KEEP_ALIVE = false
-
- def self.keep_alive?
- HTTP_KEEP_ALIVE
- end
-
- # Clear our http cache, closing all connections.
- def self.clear_http_instances
- http_cache.each do |name, connection|
- connection.finish if connection.started?
- end
- Puppet::Util::Cacher.expire
- end
-
- # Make sure we set the driver up when we read the cert in.
- def self.read_cert
- if val = super # This calls read_cert from the Puppet::SSLCertificates::Support module.
- # Clear out all of our connections, since they previously had no cert and now they
- # should have them.
- clear_http_instances
- return val
- else
- return false
- end
- end
-
# Use cert information from a Puppet client to set up the http object.
def self.cert_setup(http)
# Just no-op if we don't have certs.
@@ -63,21 +24,6 @@ module Puppet::Network::HttpPool
# Retrieve a cached http instance if caching is enabled, else return
# a new one.
def self.http_instance(host, port, reset = false)
- # We overwrite the uninitialized @http here with a cached one.
- key = "#{host}:#{port}"
-
- # Return our cached instance if we've got a cache, as long as we're not
- # resetting the instance.
- if keep_alive?
- return http_cache[key] if ! reset and http_cache[key]
-
- # Clean up old connections if we have them.
- if http = http_cache[key]
- http_cache.delete(key)
- http.finish if http.started?
- end
- end
-
args = [host, port]
if Puppet[:http_proxy_host] == "none"
args << nil << nil
@@ -97,8 +43,6 @@ module Puppet::Network::HttpPool
cert_setup(http)
- http_cache[key] = http if keep_alive?
-
http
end
end
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index dc631979e..4fc314a6a 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -95,7 +95,7 @@ class Puppet::Node::Environment
# Cache the modulepath, so that we aren't searching through
# all known directories all the time.
- cached_attr(:modulepath, :ttl => Puppet[:filetimeout]) do
+ cached_attr(:modulepath, Puppet[:filetimeout]) do
dirs = self[:modulepath].split(File::PATH_SEPARATOR)
dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs if ENV["PUPPETLIB"]
validate_dirs(dirs)
@@ -103,7 +103,7 @@ class Puppet::Node::Environment
# Return all modules from this environment.
# Cache the list, because it can be expensive to create.
- cached_attr(:modules, :ttl => Puppet[:filetimeout]) do
+ cached_attr(:modules, Puppet[:filetimeout]) do
module_names = modulepath.collect { |path| Dir.entries(path) }.flatten.uniq
module_names.collect do |path|
begin
@@ -114,12 +114,6 @@ class Puppet::Node::Environment
end.compact
end
- # Cache the manifestdir, so that we aren't searching through
- # all known directories all the time.
- cached_attr(:manifestdir, :ttl => Puppet[:filetimeout]) do
- validate_dirs(self[:manifestdir].split(File::PATH_SEPARATOR))
- end
-
def to_s
name.to_s
end
@@ -136,14 +130,18 @@ class Puppet::Node::Environment
end
def validate_dirs(dirs)
+ dir_regex = Puppet.features.microsoft_windows? ? /^[A-Za-z]:#{File::SEPARATOR}/ : /^#{File::SEPARATOR}/
+ # REMIND: Dir.getwd on windows returns a path containing backslashes, which when joined with
+ # dir containing forward slashes, breaks our regex matching. In general, path validation needs
+ # to be refactored which will be handled in a future commit.
dirs.collect do |dir|
- if dir !~ /^#{File::SEPARATOR}/
- File.join(Dir.getwd, dir)
+ if dir !~ dir_regex
+ File.expand_path(File.join(Dir.getwd, dir))
else
dir
end
end.find_all do |p|
- p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p)
+ p =~ dir_regex && FileTest.directory?(p)
end
end
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb
index 29d60fc66..c97f93b23 100644
--- a/lib/puppet/parameter.rb
+++ b/lib/puppet/parameter.rb
@@ -2,7 +2,6 @@ require 'puppet/util/methodhelper'
require 'puppet/util/log_paths'
require 'puppet/util/logging'
require 'puppet/util/docs'
-require 'puppet/util/cacher'
class Puppet::Parameter
include Puppet::Util
@@ -10,7 +9,6 @@ class Puppet::Parameter
include Puppet::Util::LogPaths
include Puppet::Util::Logging
include Puppet::Util::MethodHelper
- include Puppet::Util::Cacher
require 'puppet/parameter/value_collection'
@@ -150,10 +148,6 @@ class Puppet::Parameter
self.fail(Puppet::DevError, msg)
end
- def expirer
- resource.catalog
- end
-
def fail(*args)
type = nil
if args[0].is_a?(Class)
diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb
index 1fba73d0b..68def068d 100644
--- a/lib/puppet/parser/type_loader.rb
+++ b/lib/puppet/parser/type_loader.rb
@@ -80,7 +80,8 @@ class Puppet::Parser::TypeLoader
loaded_asts = []
files.each do |file|
- unless file =~ /^#{File::SEPARATOR}/
+ regex = Puppet.features.microsoft_windows? ? /^[A-Za-z]:#{File::SEPARATOR}/ : /^#{File::SEPARATOR}/
+ unless file =~ regex
file = File.join(dir, file)
end
@loading_helper.do_once(file) do
diff --git a/lib/puppet/provider/group/windows_adsi.rb b/lib/puppet/provider/group/windows_adsi.rb
new file mode 100644
index 000000000..4468d0071
--- /dev/null
+++ b/lib/puppet/provider/group/windows_adsi.rb
@@ -0,0 +1,48 @@
+require 'puppet/util/adsi'
+
+Puppet::Type.type(:group).provide :windows_adsi do
+ desc "Group management for Windows"
+
+ defaultfor :operatingsystem => :windows
+ confine :operatingsystem => :windows
+ confine :feature => :microsoft_windows
+
+ has_features :manages_members
+
+ def group
+ @group ||= Puppet::Util::ADSI::Group.new(@resource[:name])
+ end
+
+ def members
+ group.members
+ end
+
+ def members=(members)
+ group.set_members(members)
+ end
+
+ def create
+ @group = Puppet::Util::ADSI::Group.create(@resource[:name])
+ self.members = @resource[:members]
+ end
+
+ def exists?
+ Puppet::Util::ADSI::Group.exists?(@resource[:name])
+ end
+
+ def delete
+ Puppet::Util::ADSI::Group.delete(@resource[:name])
+ end
+
+ def gid
+ nil
+ end
+
+ def gid=(value)
+ warning "No support for managing property gid of group #{@resource[:name]} on Windows"
+ end
+
+ def self.instances
+ Puppet::Util::ADSI::Group.map { |g| new(:ensure => :present, :name => g.name) }
+ end
+end
diff --git a/lib/puppet/provider/host/parsed.rb b/lib/puppet/provider/host/parsed.rb
index 2ba01a41c..1a2bdb460 100644
--- a/lib/puppet/provider/host/parsed.rb
+++ b/lib/puppet/provider/host/parsed.rb
@@ -3,6 +3,9 @@ require 'puppet/provider/parsedfile'
hosts = nil
case Facter.value(:operatingsystem)
when "Solaris"; hosts = "/etc/inet/hosts"
+when "windows"
+ require 'win32/resolv'
+ hosts = Win32::Resolv.get_hosts_path
else
hosts = "/etc/hosts"
end
diff --git a/lib/puppet/provider/service/windows.rb b/lib/puppet/provider/service/windows.rb
new file mode 100644
index 000000000..289be697a
--- /dev/null
+++ b/lib/puppet/provider/service/windows.rb
@@ -0,0 +1,110 @@
+# Windows Service Control Manager (SCM) provider
+
+require 'win32/service' if Puppet.features.microsoft_windows?
+
+Puppet::Type.type(:service).provide :windows do
+
+ desc "Support for Windows Service Control Manager (SCM).
+
+ Services are controlled according to win32-service gem.
+
+ * All SCM operations (start/stop/enable/disable/query) are supported.
+
+ * Control of service groups (dependencies) is not yet supported."
+
+ defaultfor :operatingsystem => :windows
+ confine :operatingsystem => :windows
+
+ has_feature :refreshable
+
+ def enable
+ w32ss = Win32::Service.configure( 'service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_AUTO_START )
+ raise Puppet::Error.new("Win32 service enable of #{@resource[:name]} failed" ) if( w32ss.nil? )
+ rescue Win32::Service::Error => detail
+ raise Puppet::Error.new("Cannot enable #{@resource[:name]}, error was: #{detail}" )
+ end
+
+ def disable
+ w32ss = Win32::Service.configure( 'service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DISABLED )
+ raise Puppet::Error.new("Win32 service disable of #{@resource[:name]} failed" ) if( w32ss.nil? )
+ rescue Win32::Service::Error => detail
+ raise Puppet::Error.new("Cannot disable #{@resource[:name]}, error was: #{detail}" )
+ end
+
+ def manual_start
+ w32ss = Win32::Service.configure( 'service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DEMAND_START )
+ raise Puppet::Error.new("Win32 service manual enable of #{@resource[:name]} failed" ) if( w32ss.nil? )
+ rescue Win32::Service::Error => detail
+ raise Puppet::Error.new("Cannot enable #{@resource[:name]} for manual start, error was: #{detail}" )
+ end
+
+ def enabled?
+ w32ss = Win32::Service.config_info( @resource[:name] )
+ raise Puppet::Error.new("Win32 service query of #{@resource[:name]} failed" ) unless( !w32ss.nil? && w32ss.instance_of?( Struct::ServiceConfigInfo ) )
+ debug("Service #{@resource[:name]} start type is #{w32ss.start_type}")
+ case w32ss.start_type
+ when Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START),
+ Win32::Service.get_start_type(Win32::Service::SERVICE_BOOT_START),
+ Win32::Service.get_start_type(Win32::Service::SERVICE_SYSTEM_START)
+ :true
+ when Win32::Service.get_start_type(Win32::Service::SERVICE_DEMAND_START)
+ :manual
+ when Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED)
+ :false
+ else
+ raise Puppet::Error.new("Unknown start type: #{w32ss.start_type}")
+ end
+ rescue Win32::Service::Error => detail
+ raise Puppet::Error.new("Cannot get start type for #{@resource[:name]}, error was: #{detail}" )
+ end
+
+ def start
+ if enabled? == :false
+ # If disabled and not managing enable, respect disabled and fail.
+ if @resource[:enable].nil?
+ raise Puppet::Error, "Will not start disabled service #{@resource[:name]} without managing enable. Specify 'enable => false' to override."
+ # Otherwise start. If enable => false, we will later sync enable and
+ # disable the service again.
+ elsif @resource[:enable] == :true
+ enable
+ else
+ manual_start
+ end
+ end
+
+ Win32::Service.start( @resource[:name] )
+ rescue Win32::Service::Error => detail
+ raise Puppet::Error.new("Cannot start #{@resource[:name]}, error was: #{detail}" )
+ end
+
+ def stop
+ Win32::Service.stop( @resource[:name] )
+ rescue Win32::Service::Error => detail
+ raise Puppet::Error.new("Cannot stop #{@resource[:name]}, error was: #{detail}" )
+ end
+
+ def restart
+ self.stop
+ self.start
+ end
+
+ def status
+ w32ss = Win32::Service.status( @resource[:name] )
+ raise Puppet::Error.new("Win32 service query of #{@resource[:name]} failed" ) unless( !w32ss.nil? && w32ss.instance_of?( Struct::ServiceStatus ) )
+ state = case w32ss.current_state
+ when "stopped", "pause pending", "stop pending", "paused" then :stopped
+ when "running", "continue pending", "start pending" then :running
+ else
+ raise Puppet::Error.new("Unknown service state '#{w32ss.current_state}' for service '#{@resource[:name]}'")
+ end
+ debug("Service #{@resource[:name]} is #{w32ss.current_state}")
+ return state
+ rescue Win32::Service::Error => detail
+ raise Puppet::Error.new("Cannot get status of #{@resource[:name]}, error was: #{detail}" )
+ end
+
+ # returns all providers for all existing services and startup state
+ def self.instances
+ Win32::Service.services.collect { |s| new(:name => s.service_name) }
+ end
+end
diff --git a/lib/puppet/provider/user/windows_adsi.rb b/lib/puppet/provider/user/windows_adsi.rb
new file mode 100644
index 000000000..9250def59
--- /dev/null
+++ b/lib/puppet/provider/user/windows_adsi.rb
@@ -0,0 +1,71 @@
+require 'puppet/util/adsi'
+
+Puppet::Type.type(:user).provide :windows_adsi do
+ desc "User management for Windows"
+
+ defaultfor :operatingsystem => :windows
+ confine :operatingsystem => :windows
+ confine :feature => :microsoft_windows
+
+ has_features :manages_homedir
+
+ def user
+ @user ||= Puppet::Util::ADSI::User.new(@resource[:name])
+ end
+
+ def groups
+ user.groups.join(',')
+ end
+
+ def groups=(groups)
+ user.set_groups(groups, @resource[:membership] == :minimum)
+ end
+
+ def create
+ @user = Puppet::Util::ADSI::User.create(@resource[:name])
+ [:comment, :home, :groups].each do |prop|
+ send("#{prop}=", @resource[prop]) if @resource[prop]
+ end
+ end
+
+ def exists?
+ Puppet::Util::ADSI::User.exists?(@resource[:name])
+ end
+
+ def delete
+ Puppet::Util::ADSI::User.delete(@resource[:name])
+ end
+
+ # Only flush if we created or modified a user, not deleted
+ def flush
+ @user.commit if @user
+ end
+
+ def comment
+ user['Description']
+ end
+
+ def comment=(value)
+ user['Description'] = value
+ end
+
+ def home
+ user['HomeDirectory']
+ end
+
+ def home=(value)
+ user['HomeDirectory'] = value
+ end
+
+ [:uid, :gid, :shell].each do |prop|
+ define_method(prop) { nil }
+
+ define_method("#{prop}=") do |v|
+ warning "No support for managing property #{prop} of user #{@resource[:name]} on Windows"
+ end
+ end
+
+ def self.instances
+ Puppet::Util::ADSI::User.map { |u| new(:ensure => :present, :name => u.name) }
+ end
+end
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index be6302595..ca9f25a5a 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -3,7 +3,6 @@ require 'puppet/indirector'
require 'puppet/simple_graph'
require 'puppet/transaction'
-require 'puppet/util/cacher'
require 'puppet/util/pson'
require 'puppet/util/tagging'
@@ -20,7 +19,6 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
include Puppet::Util::Tagging
extend Puppet::Util::Pson
- include Puppet::Util::Cacher::Expirer
# The host name this is a catalog for.
attr_accessor :name
@@ -126,10 +124,6 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
def apply(options = {})
@applying = true
- # Expire all of the resource data -- this ensures that all
- # data we're operating against is entirely current.
- expire
-
Puppet::Util::Storage.load if host_config?
transaction = Puppet::Transaction.new(self, options[:report])
@@ -165,7 +159,6 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
return transaction
ensure
@applying = false
- cleanup
end
# Are we in the middle of applying the catalog?
@@ -200,14 +193,6 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
resource
end
- def dependent_data_expired?(ts)
- if applying?
- return super
- else
- return true
- end
- end
-
# Turn our catalog graph into an old-style tree of TransObjects and TransBuckets.
# LAK:NOTE(20081211): This is a pre-0.25 backward compatibility method.
# It can be removed as soon as xmlrpc is killed.
@@ -567,11 +552,6 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
private
- def cleanup
- # Expire any cached data the resources are keeping.
- expire
- end
-
# Verify that the given resource isn't defined elsewhere.
def fail_on_duplicate_type_and_title(resource)
# Short-curcuit the common case,
diff --git a/lib/puppet/ssl/certificate_authority.rb b/lib/puppet/ssl/certificate_authority.rb
index d65067c70..a4cbaf78a 100644
--- a/lib/puppet/ssl/certificate_authority.rb
+++ b/lib/puppet/ssl/certificate_authority.rb
@@ -1,6 +1,6 @@
+require 'monitor'
require 'puppet/ssl/host'
require 'puppet/ssl/certificate_request'
-require 'puppet/util/cacher'
# The class that knows how to sign certificates. It creates
# a 'special' SSL::Host whose name is 'ca', thus indicating
@@ -17,6 +17,8 @@ class Puppet::SSL::CertificateAuthority
require 'puppet/ssl/certificate_authority/interface'
require 'puppet/network/authstore'
+ extend MonitorMixin
+
class CertificateVerificationError < RuntimeError
attr_accessor :error_code
@@ -25,10 +27,10 @@ class Puppet::SSL::CertificateAuthority
end
end
- class << self
- include Puppet::Util::Cacher
-
- cached_attr(:singleton_instance) { new }
+ def self.singleton_instance
+ synchronize do
+ @singleton_instance ||= new
+ end
end
def self.ca?
diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb
index b9215effd..08a8ace1f 100644
--- a/lib/puppet/ssl/host.rb
+++ b/lib/puppet/ssl/host.rb
@@ -4,7 +4,6 @@ require 'puppet/ssl/key'
require 'puppet/ssl/certificate'
require 'puppet/ssl/certificate_request'
require 'puppet/ssl/certificate_revocation_list'
-require 'puppet/util/cacher'
# The class that manages all aspects of our SSL certificates --
# private keys, public keys, requests, etc.
@@ -27,14 +26,10 @@ class Puppet::SSL::Host
# This accessor is used in instances for indirector requests to hold desired state
attr_accessor :desired_state
- class << self
- include Puppet::Util::Cacher
-
- cached_attr(:localhost) do
- result = new
- result.generate unless result.certificate
- result.key # Make sure it's read in
- result
+ def self.localhost
+ @localhost ||= new.tap do |l|
+ l.generate unless l.certificate
+ l.key # Make sure it's read in
end
end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 4472387d1..803b5c6a0 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -9,7 +9,6 @@ require 'puppet/metatype/manager'
require 'puppet/util/errors'
require 'puppet/util/log_paths'
require 'puppet/util/logging'
-require 'puppet/util/cacher'
require 'puppet/file_collection/lookup'
require 'puppet/util/tagging'
@@ -21,7 +20,6 @@ class Type
include Puppet::Util::Errors
include Puppet::Util::LogPaths
include Puppet::Util::Logging
- include Puppet::Util::Cacher
include Puppet::FileCollection::Lookup
include Puppet::Util::Tagging
@@ -469,12 +467,6 @@ class Type
Puppet::Transaction::Event.new({:resource => self, :file => file, :line => line, :tags => tags}.merge(options))
end
- # Let the catalog determine whether a given cached value is
- # still valid or has expired.
- def expirer
- catalog
- end
-
# retrieve the 'should' value for a specified property
def should(name)
name = attr_alias(name)
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 9cac37f27..d3c66bc02 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -23,7 +23,7 @@ Puppet::Type.newtype(:file) do
location, rather than using native resources, please contact
Puppet Labs and we can hopefully work with you to develop a
native resource to support what you are doing.
-
+
**Autorequires:** If Puppet is managing the user or group that owns a file, the file resource will autorequire them. If Puppet is managing any parent directories of a file, the file resource will autorequire them."
def self.title_patterns
@@ -36,7 +36,7 @@ Puppet::Type.newtype(:file) do
validate do |value|
# accept various path syntaxes: lone slash, posix, win32, unc
- unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
+ unless (Puppet.features.posix? and value =~ /^\//) or (value =~ /^[A-Za-z]:\// or value =~ /^\/\/[^\/]+\/[^\/]+/)
fail Puppet::Error, "File paths must be fully qualified, not '#{value}'"
end
end
@@ -44,7 +44,21 @@ Puppet::Type.newtype(:file) do
# convert the current path in an index into the collection and the last
# path name. The aim is to use less storage for all common paths in a hierarchy
munge do |value|
- path, name = ::File.split(value.gsub(/\/+/,'/'))
+ # We need to save off, and remove the volume designator in the
+ # path if it is there, since File.split does not handle paths
+ # with volume designators properly, except when run on Windows.
+ # Since we are potentially compiling a catalog for a Windows
+ # machine on a non-Windows master, we need to handle this
+ # ourselves.
+ optional_volume_designator = value.match(/^([a-z]:)[\/\\].*/i)
+ value_without_designator = value.sub(/^(?:[a-z]:)?(.*)/i, '\1')
+
+ path, name = ::File.split(value_without_designator.gsub(/\/+/,'/'))
+
+ if optional_volume_designator
+ path = optional_volume_designator[1] + path
+ end
+
{ :index => Puppet::FileCollection.collection.index(path), :name => name }
end
@@ -396,7 +410,7 @@ Puppet::Type.newtype(:file) do
@parameters.each do |name, param|
param.flush if param.respond_to?(:flush)
end
- @stat = nil
+ @stat = :needs_stat
end
def initialize(hash)
@@ -415,7 +429,7 @@ Puppet::Type.newtype(:file) do
end
end
- @stat = nil
+ @stat = :needs_stat
end
# Configure discovered resources to be purged.
@@ -625,7 +639,7 @@ Puppet::Type.newtype(:file) do
else
self.fail "Could not back up files of type #{s.ftype}"
end
- expire
+ @stat = :needs_stat
end
def retrieve
@@ -676,22 +690,27 @@ Puppet::Type.newtype(:file) do
# use either 'stat' or 'lstat', and we expect the properties to use the
# resulting stat object accordingly (mostly by testing the 'ftype'
# value).
- cached_attr(:stat) do
+ #
+ # We use the initial value :needs_stat to ensure we only stat the file once,
+ # but can also keep track of a failed stat (@stat == nil). This also allows
+ # us to re-stat on demand by setting @stat = :needs_stat.
+ def stat
+ return @stat unless @stat == :needs_stat
+
method = :stat
# Files are the only types that support links
if (self.class.name == :file and self[:links] != :follow) or self.class.name == :tidy
method = :lstat
end
- path = self[:path]
- begin
+ @stat = begin
::File.send(method, self[:path])
rescue Errno::ENOENT => error
- return nil
+ nil
rescue Errno::EACCES => error
warning "Could not stat; permission denied"
- return nil
+ nil
end
end
@@ -778,7 +797,7 @@ Puppet::Type.newtype(:file) do
next unless [:mode, :owner, :group, :seluser, :selrole, :seltype, :selrange].include?(thing.name)
# Make sure we get a new stat objct
- expire
+ @stat = :needs_stat
currentvalue = thing.retrieve
thing.sync unless thing.safe_insync?(currentvalue)
end
diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb
index 67401505d..8653a8f7a 100755
--- a/lib/puppet/type/file/source.rb
+++ b/lib/puppet/type/file/source.rb
@@ -72,7 +72,7 @@ module Puppet
self.fail "Could not understand source #{source}: #{detail}"
end
- self.fail "Cannot use URLs of type '#{uri.scheme}' as source for fileserving" unless uri.scheme.nil? or %w{file puppet}.include?(uri.scheme)
+ self.fail "Cannot use URLs of type '#{uri.scheme}' as source for fileserving" unless uri.scheme.nil? or %w{file puppet}.include?(uri.scheme) or (Puppet.features.microsoft_windows? and uri.scheme =~ /^[a-z]$/i)
end
end
@@ -95,13 +95,14 @@ module Puppet
end
# Look up (if necessary) and return remote content.
- cached_attr(:content) do
+ def content
+ return @content if @content
raise Puppet::DevError, "No source for content was stored with the metadata" unless metadata.source
unless tmp = Puppet::FileServing::Content.indirection.find(metadata.source)
fail "Could not find any content at %s" % metadata.source
end
- tmp.content
+ @content = tmp.content
end
# Copy the values from the source to the resource. Yay.
@@ -137,25 +138,27 @@ module Puppet
! (metadata.nil? or metadata.ftype.nil?)
end
+ attr_writer :metadata
+
# Provide, and retrieve if necessary, the metadata for this file. Fail
# if we can't find data about this host, and fail if there are any
# problems in our query.
- cached_attr(:metadata) do
+ def metadata
+ return @metadata if @metadata
return nil unless value
- result = nil
value.each do |source|
begin
if data = Puppet::FileServing::Metadata.indirection.find(source)
- result = data
- result.source = source
+ @metadata = data
+ @metadata.source = source
break
end
rescue => detail
fail detail, "Could not retrieve file metadata for #{source}: #{detail}"
end
end
- fail "Could not retrieve information from environment #{Puppet[:environment]} source(s) #{value.join(", ")}" unless result
- result
+ fail "Could not retrieve information from environment #{Puppet[:environment]} source(s) #{value.join(", ")}" unless @metadata
+ @metadata
end
def local?
@@ -177,6 +180,8 @@ module Puppet
private
def uri
+ return nil if metadata.source =~ /^[a-z]:[\/\\]/i # Abspath for Windows
+
@uri ||= URI.parse(URI.escape(metadata.source))
end
end
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb
index 3116f5f8e..eaf2b8ee1 100644
--- a/lib/puppet/type/service.rb
+++ b/lib/puppet/type/service.rb
@@ -47,9 +47,19 @@ module Puppet
provider.disable
end
+ newvalue(:manual, :event => :service_manual_start) do
+ provider.manual_start
+ end
+
def retrieve
provider.enabled?
end
+
+ validate do |value|
+ if value == :manual and !Puppet.features.microsoft_windows?
+ raise Puppet::Error.new("Setting enable to manual is only supported on Microsoft Windows.")
+ end
+ end
end
# Handle whether the service should actually be running right now.
diff --git a/lib/puppet/util/adsi.rb b/lib/puppet/util/adsi.rb
new file mode 100644
index 000000000..f865743e2
--- /dev/null
+++ b/lib/puppet/util/adsi.rb
@@ -0,0 +1,278 @@
+module Puppet::Util::ADSI
+ class << self
+ def connectable?(uri)
+ begin
+ !! connect(uri)
+ rescue
+ false
+ end
+ end
+
+ def connect(uri)
+ begin
+ WIN32OLE.connect(uri)
+ rescue Exception => e
+ raise Puppet::Error.new( "ADSI connection error: #{e}" )
+ end
+ end
+
+ def create(name, resource_type)
+ Puppet::Util::ADSI.connect(computer_uri).Create(resource_type, name)
+ end
+
+ def delete(name, resource_type)
+ Puppet::Util::ADSI.connect(computer_uri).Delete(resource_type, name)
+ end
+
+ def computer_name
+ unless @computer_name
+ buf = " " * 128
+ Win32API.new('kernel32', 'GetComputerName', ['P','P'], 'I').call(buf, buf.length.to_s)
+ @computer_name = buf.unpack("A*")
+ end
+ @computer_name
+ end
+
+ def computer_uri
+ "WinNT://#{computer_name}"
+ end
+
+ def wmi_resource_uri( host = '.' )
+ "winmgmts:{impersonationLevel=impersonate}!//#{host}/root/cimv2"
+ end
+
+ def uri(resource_name, resource_type)
+ "#{computer_uri}/#{resource_name},#{resource_type}"
+ end
+
+ def execquery(query)
+ connect(wmi_resource_uri).execquery(query)
+ end
+ end
+
+ class User
+ extend Enumerable
+
+ attr_accessor :native_user
+ attr_reader :name
+ def initialize(name, native_user = nil)
+ @name = name
+ @native_user = native_user
+ end
+
+ def native_user
+ @native_user ||= Puppet::Util::ADSI.connect(uri)
+ end
+
+ def self.uri(name)
+ Puppet::Util::ADSI.uri(name, 'user')
+ end
+
+ def uri
+ self.class.uri(name)
+ end
+
+ def self.logon(name, password)
+ fLOGON32_LOGON_NETWORK = 3
+ fLOGON32_PROVIDER_DEFAULT = 0
+
+ logon_user = Win32API.new("advapi32", "LogonUser", ['P', 'P', 'P', 'L', 'L', 'P'], 'L')
+ close_handle = Win32API.new("kernel32", "CloseHandle", ['P'], 'V')
+
+ token = ' ' * 4
+ if logon_user.call(name, "", password, fLOGON32_LOGON_NETWORK, fLOGON32_PROVIDER_DEFAULT, token) != 0
+ close_handle.call(token.unpack('L')[0])
+ true
+ else
+ false
+ end
+ end
+
+ def [](attribute)
+ native_user.Get(attribute)
+ end
+
+ def []=(attribute, value)
+ native_user.Put(attribute, value)
+ end
+
+ def commit
+ begin
+ native_user.SetInfo unless native_user.nil?
+ rescue Exception => e
+ raise Puppet::Error.new( "User update failed: #{e}" )
+ end
+ self
+ end
+
+ def password_is?(password)
+ self.class.logon(name, password)
+ end
+
+ def add_flag(flag_name, value)
+ flag = native_user.Get(flag_name) rescue 0
+
+ native_user.Put(flag_name, flag | value)
+
+ commit
+ end
+
+ def password=(password)
+ native_user.SetPassword(password)
+ commit
+ fADS_UF_DONT_EXPIRE_PASSWD = 0x10000
+ add_flag("UserFlags", fADS_UF_DONT_EXPIRE_PASSWD)
+ end
+
+ def groups
+ # WIN32OLE objects aren't enumerable, so no map
+ groups = []
+ native_user.Groups.each {|g| groups << g.Name}
+ groups
+ end
+
+ def add_to_groups(*group_names)
+ group_names.each do |group_name|
+ Puppet::Util::ADSI::Group.new(group_name).add_member(@name)
+ end
+ end
+ alias add_to_group add_to_groups
+
+ def remove_from_groups(*group_names)
+ group_names.each do |group_name|
+ Puppet::Util::ADSI::Group.new(group_name).remove_member(@name)
+ end
+ end
+ alias remove_from_group remove_from_groups
+
+ def set_groups(desired_groups, minimum = true)
+ return if desired_groups.nil? or desired_groups.empty?
+
+ desired_groups = desired_groups.split(',').map(&:strip)
+
+ current_groups = self.groups
+
+ # First we add the user to all the groups it should be in but isn't
+ groups_to_add = desired_groups - current_groups
+ add_to_groups(*groups_to_add)
+
+ # Then we remove the user from all groups it is in but shouldn't be, if
+ # that's been requested
+ groups_to_remove = current_groups - desired_groups
+ remove_from_groups(*groups_to_remove) unless minimum
+ end
+
+ def self.create(name)
+ new(name, Puppet::Util::ADSI.create(name, 'user'))
+ end
+
+ def self.exists?(name)
+ Puppet::Util::ADSI::connectable?(User.uri(name))
+ end
+
+ def self.delete(name)
+ Puppet::Util::ADSI.delete(name, 'user')
+ end
+
+ def self.each(&block)
+ wql = Puppet::Util::ADSI.execquery("select * from win32_useraccount")
+
+ users = []
+ wql.each do |u|
+ users << new(u.name, u)
+ end
+
+ users.each(&block)
+ end
+ end
+
+ class Group
+ extend Enumerable
+
+ attr_accessor :native_group
+ attr_reader :name
+ def initialize(name, native_group = nil)
+ @name = name
+ @native_group = native_group
+ end
+
+ def uri
+ self.class.uri(name)
+ end
+
+ def self.uri(name)
+ Puppet::Util::ADSI.uri(name, 'group')
+ end
+
+ def native_group
+ @native_group ||= Puppet::Util::ADSI.connect(uri)
+ end
+
+ def commit
+ begin
+ native_group.SetInfo unless native_group.nil?
+ rescue Exception => e
+ raise Puppet::Error.new( "Group update failed: #{e}" )
+ end
+ self
+ end
+
+ def add_members(*names)
+ names.each do |name|
+ native_group.Add(Puppet::Util::ADSI::User.uri(name))
+ end
+ end
+ alias add_member add_members
+
+ def remove_members(*names)
+ names.each do |name|
+ native_group.Remove(Puppet::Util::ADSI::User.uri(name))
+ end
+ end
+ alias remove_member remove_members
+
+ def members
+ # WIN32OLE objects aren't enumerable, so no map
+ members = []
+ native_group.Members.each {|m| members << m.Name}
+ members
+ end
+
+ def set_members(desired_members)
+ return if desired_members.nil? or desired_members.empty?
+
+ current_members = self.members
+
+ # First we add all missing members
+ members_to_add = desired_members - current_members
+ add_members(*members_to_add)
+
+ # Then we remove all extra members
+ members_to_remove = current_members - desired_members
+ remove_members(*members_to_remove)
+ end
+
+ def self.create(name)
+ new(name, Puppet::Util::ADSI.create(name, 'group'))
+ end
+
+ def self.exists?(name)
+ Puppet::Util::ADSI.connectable?(Group.uri(name))
+ end
+
+ def self.delete(name)
+ Puppet::Util::ADSI.delete(name, 'group')
+ end
+
+ def self.each(&block)
+ wql = Puppet::Util::ADSI.execquery( "select * from win32_group" )
+
+ groups = []
+ wql.each do |g|
+ groups << new(g.name, g)
+ end
+
+ groups.each(&block)
+ end
+ end
+end
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb
index 6537a4a4e..2e8710ab1 100644
--- a/lib/puppet/util/autoload.rb
+++ b/lib/puppet/util/autoload.rb
@@ -1,5 +1,4 @@
require 'puppet/util/warnings'
-require 'puppet/util/cacher'
# Autoload paths, either based on names or all at once.
class Puppet::Util::Autoload
@@ -7,7 +6,6 @@ class Puppet::Util::Autoload
include Puppet::Util
include Puppet::Util::Warnings
- include Puppet::Util::Cacher
include Puppet::Util::Autoload::FileCache
@autoloaders = {}
diff --git a/lib/puppet/util/cacher.rb b/lib/puppet/util/cacher.rb
index 3dddec0d4..136c9973e 100644
--- a/lib/puppet/util/cacher.rb
+++ b/lib/puppet/util/cacher.rb
@@ -1,25 +1,6 @@
require 'monitor'
module Puppet::Util::Cacher
- module Expirer
- attr_reader :timestamp
-
- # Cause all cached values to be considered expired.
- def expire
- @timestamp = Time.now
- end
-
- # Is the provided timestamp earlier than our expiration timestamp?
- # If it is, then the associated value is expired.
- def dependent_data_expired?(ts)
- return false unless timestamp
-
- timestamp > ts
- end
- end
-
- extend Expirer
-
# Our module has been extended in a class; we can only add the Instance methods,
# which become *class* methods in the class.
def self.extended(other)
@@ -40,27 +21,26 @@ module Puppet::Util::Cacher
module ClassMethods
# Provide a means of defining an attribute whose value will be cached.
# Must provide a block capable of defining the value if it's flushed..
- def cached_attr(name, options = {}, &block)
+ def cached_attr(name, ttl, &block)
init_method = "init_#{name}"
define_method(init_method, &block)
+ set_attr_ttl(name, ttl)
+
define_method(name) do
cached_value(name)
end
define_method(name.to_s + "=") do |value|
# Make sure the cache timestamp is set
- cache_timestamp
- value_cache.synchronize { value_cache[name] = value }
- end
-
- if ttl = options[:ttl]
- set_attr_ttl(name, ttl)
+ value_cache.synchronize do
+ value_cache[name] = value
+ set_expiration(name)
+ end
end
end
def attr_ttl(name)
- return nil unless @attr_ttls
@attr_ttls[name]
end
@@ -72,57 +52,25 @@ module Puppet::Util::Cacher
# Methods that get added to instances.
module InstanceMethods
-
- def expire
- # Only expire if we have an expirer. This is
- # mostly so that we can comfortably handle cases
- # like Puppet::Type instances, which use their
- # catalog as their expirer, and they often don't
- # have a catalog.
- if e = expirer
- e.expire
- end
- end
-
- def expirer
- Puppet::Util::Cacher
- end
-
private
- def cache_timestamp
- @cache_timestamp ||= Time.now
- end
-
def cached_value(name)
value_cache.synchronize do
- # Allow a nil expirer, in which case we regenerate the value every time.
- if expired_by_expirer?(name)
- value_cache.clear
- @cache_timestamp = Time.now
- elsif expired_by_ttl?(name)
- value_cache.delete(name)
+ if value_cache[name].nil? or expired_by_ttl?(name)
+ value_cache[name] = send("init_#{name}")
+ set_expiration(name)
end
- value_cache[name] = send("init_#{name}") unless value_cache.include?(name)
value_cache[name]
end
end
- def expired_by_expirer?(name)
- if expirer.nil?
- return true unless self.class.attr_ttl(name)
- end
- expirer.dependent_data_expired?(cache_timestamp)
- end
-
def expired_by_ttl?(name)
- return false unless self.class.respond_to?(:attr_ttl)
- return false unless ttl = self.class.attr_ttl(name)
-
- @ttl_timestamps ||= {}
- @ttl_timestamps[name] ||= Time.now
+ @attr_expirations[name] < Time.now
+ end
- (Time.now - @ttl_timestamps[name]) > ttl
+ def set_expiration(name)
+ @attr_expirations ||= {}
+ @attr_expirations[name] = Time.now + self.class.attr_ttl(name)
end
def value_cache
diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
index 762ce25f0..a8996ee9a 100644
--- a/lib/puppet/util/rdoc/parser.rb
+++ b/lib/puppet/util/rdoc/parser.rb
@@ -113,7 +113,9 @@ class Parser
Puppet::Module.modulepath.each do |mp|
# check that fullpath is a descendant of mp
dirname = fullpath
- while (dirname = File.dirname(dirname)) != '/'
+ previous = dirname
+ while (dirname = File.dirname(previous)) != previous
+ previous = dirname
return nil if File.identical?(dirname,mp)
end
end
diff --git a/lib/puppet/util/run_mode.rb b/lib/puppet/util/run_mode.rb
index 450cbf1a6..6028aef29 100644
--- a/lib/puppet/util/run_mode.rb
+++ b/lib/puppet/util/run_mode.rb
@@ -27,14 +27,14 @@ module Puppet
def conf_dir
which_dir(
- (Puppet.features.microsoft_windows? ? File.join(Dir::WINDOWS, "puppet", "etc") : "/etc/puppet"),
+ (Puppet.features.microsoft_windows? ? File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "etc") : "/etc/puppet"),
"~/.puppet"
)
end
def var_dir
which_dir(
- (Puppet.features.microsoft_windows? ? File.join(Dir::WINDOWS, "puppet", "var") : "/var/lib/puppet"),
+ (Puppet.features.microsoft_windows? ? File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "var") : "/var/lib/puppet"),
"~/.puppet/var"
)
end
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 4559e9af3..caaf61b7b 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -2,13 +2,11 @@ require 'puppet'
require 'sync'
require 'getoptlong'
require 'puppet/external/event-loop'
-require 'puppet/util/cacher'
require 'puppet/util/loadedfile'
# The class for handling configuration files.
class Puppet::Util::Settings
include Enumerable
- include Puppet::Util::Cacher
require 'puppet/util/settings/setting'
require 'puppet/util/settings/file_setting'
@@ -401,11 +399,10 @@ class Puppet::Util::Settings
}
end
- # Cache this in an easily clearable way, since we were
- # having trouble cleaning it up after tests.
- cached_attr(:file) do
+ def file
+ return @file if @file
if path = self[:config] and FileTest.exist?(path)
- Puppet::Util::LoadedFile.new(path)
+ @file = Puppet::Util::LoadedFile.new(path)
end
end
diff --git a/lib/puppet/util/settings/file_setting.rb b/lib/puppet/util/settings/file_setting.rb
index 776398ef4..0fa65d846 100644
--- a/lib/puppet/util/settings/file_setting.rb
+++ b/lib/puppet/util/settings/file_setting.rb
@@ -86,7 +86,7 @@ class Puppet::Util::Settings::FileSetting < Puppet::Util::Settings::Setting
path = File.expand_path(path)
return nil unless type == :directory or create_files? or File.exist?(path)
- return nil if path =~ /^\/dev/
+ return nil if path =~ /^\/dev/ or path =~ /^[A-Z]:\/dev/i
resource = Puppet::Resource.new(:file, path)
diff --git a/spec/integration/application/doc_spec.rb b/spec/integration/application/doc_spec.rb
index 9412976f0..2cf5fd1e9 100755
--- a/spec/integration/application/doc_spec.rb
+++ b/spec/integration/application/doc_spec.rb
@@ -5,7 +5,7 @@ require 'puppet_spec/files'
describe Puppet::Application::Doc do
include PuppetSpec::Files
- it "should not generate an error when module dir overlaps parent of site.pp (#4798)", :'fails_on_ruby_1.9.2' => true do
+ it "should not generate an error when module dir overlaps parent of site.pp (#4798)", :'fails_on_ruby_1.9.2' => true, :unless => Puppet.features.microsoft_windows? do
begin
# Note: the directory structure below is more complex than it
# needs to be, but it's representative of the directory structure
diff --git a/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb
index 8cf0e3e7b..84297e8f9 100755
--- a/spec/integration/defaults_spec.rb
+++ b/spec/integration/defaults_spec.rb
@@ -277,4 +277,14 @@ describe "Puppet defaults" do
subject { Puppet.settings[:reporturl] }
it { should == "http://localhost:3000/reports/upload" }
end
+
+ describe "when configuring color" do
+ it "should default to ansi", :unless => Puppet.features.microsoft_windows? do
+ Puppet.settings[:color].should == 'ansi'
+ end
+
+ it "should default to false", :if => Puppet.features.microsoft_windows? do
+ Puppet.settings[:color].should == 'false'
+ end
+ end
end
diff --git a/spec/integration/file_serving/content_spec.rb b/spec/integration/file_serving/content_spec.rb
index 5b08a6137..e2efecfa4 100755
--- a/spec/integration/file_serving/content_spec.rb
+++ b/spec/integration/file_serving/content_spec.rb
@@ -11,6 +11,4 @@ describe Puppet::FileServing::Content, " when finding files" do
@test_class = Puppet::FileServing::Content
@indirection = Puppet::FileServing::Content.indirection
end
-
- after { Puppet::Util::Cacher.expire }
end
diff --git a/spec/integration/file_serving/metadata_spec.rb b/spec/integration/file_serving/metadata_spec.rb
index 821b6baca..d9aaa37f5 100755
--- a/spec/integration/file_serving/metadata_spec.rb
+++ b/spec/integration/file_serving/metadata_spec.rb
@@ -12,6 +12,4 @@ describe Puppet::FileServing::Metadata, " when finding files" do
@test_class = Puppet::FileServing::Metadata
@indirection = Puppet::FileServing::Metadata.indirection
end
-
- after { Puppet::Util::Cacher.expire }
end
diff --git a/spec/integration/file_serving/terminus_helper_spec.rb b/spec/integration/file_serving/terminus_helper_spec.rb
index 7500b1fc0..99fee9ce5 100755
--- a/spec/integration/file_serving/terminus_helper_spec.rb
+++ b/spec/integration/file_serving/terminus_helper_spec.rb
@@ -10,7 +10,7 @@ class TerminusHelperIntegrationTester
end
end
-describe Puppet::FileServing::TerminusHelper do
+describe Puppet::FileServing::TerminusHelper, :fails_on_windows => true do
it "should be able to recurse on a single file" do
@path = Tempfile.new("fileset_integration")
request = Puppet::Indirector::Request.new(:metadata, :find, @path.path, :recurse => true)
diff --git a/spec/integration/indirector/direct_file_server_spec.rb b/spec/integration/indirector/direct_file_server_spec.rb
index 98f0ebe17..79afe7569 100755
--- a/spec/integration/indirector/direct_file_server_spec.rb
+++ b/spec/integration/indirector/direct_file_server_spec.rb
@@ -3,12 +3,14 @@ require 'spec_helper'
require 'puppet/indirector/file_content/file'
-describe Puppet::Indirector::DirectFileServer, " when interacting with the filesystem and the model" do
+describe Puppet::Indirector::DirectFileServer, " when interacting with the filesystem and the model", :fails_on_windows => true do
+ include PuppetSpec::Files
+
before do
# We just test a subclass, since it's close enough.
@terminus = Puppet::Indirector::FileContent::File.new
- @filepath = "/path/to/my/file"
+ @filepath = make_absolute("/path/to/my/file")
end
it "should return an instance of the model" do
@@ -28,7 +30,7 @@ describe Puppet::Indirector::DirectFileServer, " when interacting with the files
end
end
-describe Puppet::Indirector::DirectFileServer, " when interacting with FileServing::Fileset and the model" do
+describe Puppet::Indirector::DirectFileServer, " when interacting with FileServing::Fileset and the model", :fails_on_windows => true do
before do
@terminus = Puppet::Indirector::FileContent::File.new
diff --git a/spec/integration/indirector/file_content/file_server_spec.rb b/spec/integration/indirector/file_content/file_server_spec.rb
index 787f1562d..3be32754f 100755
--- a/spec/integration/indirector/file_content/file_server_spec.rb
+++ b/spec/integration/indirector/file_content/file_server_spec.rb
@@ -6,13 +6,14 @@ require 'shared_behaviours/file_server_terminus'
require 'puppet_spec/files'
-describe Puppet::Indirector::FileContent::FileServer, " when finding files" do
+describe Puppet::Indirector::FileContent::FileServer, " when finding files", :fails_on_windows => true do
it_should_behave_like "Puppet::Indirector::FileServerTerminus"
include PuppetSpec::Files
before do
@terminus = Puppet::Indirector::FileContent::FileServer.new
@test_class = Puppet::FileServing::Content
+ Puppet::FileServing::Configuration.instance_variable_set(:@configuration, nil)
end
it "should find plugin file content in the environment specified in the request" do
@@ -58,7 +59,6 @@ describe Puppet::Indirector::FileContent::FileServer, " when finding files" do
end
it "should find file content in files when node name expansions are used" do
- Puppet::Util::Cacher.expire
FileTest.stubs(:exists?).returns true
FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true)
diff --git a/spec/integration/indirector/file_metadata/file_server_spec.rb b/spec/integration/indirector/file_metadata/file_server_spec.rb
index c2cbcfa5c..2e7c54b70 100755
--- a/spec/integration/indirector/file_metadata/file_server_spec.rb
+++ b/spec/integration/indirector/file_metadata/file_server_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
require 'puppet/indirector/file_metadata/file_server'
require 'shared_behaviours/file_server_terminus'
-describe Puppet::Indirector::FileMetadata::FileServer, " when finding files" do
+describe Puppet::Indirector::FileMetadata::FileServer, " when finding files", :fails_on_windows => true do
it_should_behave_like "Puppet::Indirector::FileServerTerminus"
before do
diff --git a/spec/integration/network/server/webrick_spec.rb b/spec/integration/network/server/webrick_spec.rb
index 81c35af4f..7365462d3 100755
--- a/spec/integration/network/server/webrick_spec.rb
+++ b/spec/integration/network/server/webrick_spec.rb
@@ -4,7 +4,9 @@ require 'puppet/network/server'
require 'puppet/ssl/certificate_authority'
require 'socket'
-describe Puppet::Network::Server do
+describe Puppet::Network::Server, :unless => Puppet.features.microsoft_windows? do
+ include PuppetSpec::Files
+
describe "when using webrick" do
before :each do
Puppet[:servertype] = 'webrick'
@@ -12,11 +14,10 @@ describe Puppet::Network::Server do
@params = { :port => 34343, :handlers => [ :node ], :xmlrpc_handlers => [ :status ] }
# Get a safe temporary file
- @tmpfile = Tempfile.new("webrick_integration_testing")
- @dir = @tmpfile.path + "_dir"
+ dir = tmpdir("webrick_integration_testing")
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = dir
+ Puppet.settings[:vardir] = dir
Puppet.settings[:group] = Process.gid
Puppet::SSL::Host.ca_location = :local
@@ -26,13 +27,9 @@ describe Puppet::Network::Server do
end
after do
- @tmpfile.delete
Puppet.settings.clear
- system("rm -rf #{@dir}")
-
Puppet::SSL::Host.ca_location = :none
- Puppet::Util::Cacher.expire
end
describe "before listening" do
diff --git a/spec/integration/node/facts_spec.rb b/spec/integration/node/facts_spec.rb
index b2c71e42a..78bdabce1 100755
--- a/spec/integration/node/facts_spec.rb
+++ b/spec/integration/node/facts_spec.rb
@@ -3,8 +3,6 @@ require 'spec_helper'
describe Puppet::Node::Facts do
describe "when using the indirector" do
- after(:each) { Puppet::Util::Cacher.expire }
-
it "should expire any cached node instances when it is saved" do
Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml
diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb
index 9f6aae907..582882d83 100755
--- a/spec/integration/parser/compiler_spec.rb
+++ b/spec/integration/parser/compiler_spec.rb
@@ -13,11 +13,12 @@ describe Puppet::Parser::Compiler do
Puppet.settings.clear
end
- it "should be able to determine the configuration version from a local version control repository" do
+ it "should be able to determine the configuration version from a local version control repository", :fails_on_windows => true do
# This should always work, because we should always be
# in the puppet repo when we run this.
version = %x{git rev-parse HEAD}.chomp
+ # REMIND: this fails on Windows due to #8410, re-enable the test when it is fixed
Puppet.settings[:config_version] = 'git rev-parse HEAD'
@parser = Puppet::Parser::Parser.new "development"
diff --git a/spec/integration/provider/mount_spec.rb b/spec/integration/provider/mount_spec.rb
index 4af0dca4a..b2e9c4497 100755
--- a/spec/integration/provider/mount_spec.rb
+++ b/spec/integration/provider/mount_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
require 'puppet/file_bucket/dipper'
-describe "mount provider (integration)" do
+describe "mount provider (integration)", :unless => Puppet.features.microsoft_windows? do
include PuppetSpec::Files
def create_fake_fstab(initially_contains_entry)
diff --git a/spec/integration/provider/package_spec.rb b/spec/integration/provider/package_spec.rb
index 5fecdf13c..701752371 100755
--- a/spec/integration/provider/package_spec.rb
+++ b/spec/integration/provider/package_spec.rb
@@ -12,7 +12,7 @@ describe "Package Provider", :'fails_on_ruby_1.9.2' => true do
lambda { pkg.provider.install }.should raise_error
end
- it "should be able to get a list of existing packages" do
+ it "should be able to get a list of existing packages", :fails_on_windows => true do
provider.instances.each do |package|
package.should be_instance_of(provider)
package.properties[:provider].should == provider.name
diff --git a/spec/integration/provider/ssh_authorized_key_spec.rb b/spec/integration/provider/ssh_authorized_key_spec.rb
index 902f9ad22..252f7bf78 100644..100755
--- a/spec/integration/provider/ssh_authorized_key_spec.rb
+++ b/spec/integration/provider/ssh_authorized_key_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'puppet/file_bucket/dipper'
-describe "ssh_authorized_key provider (integration)" do
+describe "ssh_authorized_key provider (integration)", :unless => Puppet.features.microsoft_windows? do
include PuppetSpec::Files
before :each do
diff --git a/spec/integration/resource/catalog_spec.rb b/spec/integration/resource/catalog_spec.rb
index 528e29545..df310b184 100755
--- a/spec/integration/resource/catalog_spec.rb
+++ b/spec/integration/resource/catalog_spec.rb
@@ -9,7 +9,6 @@ describe Puppet::Resource::Catalog do
end
describe "when using the indirector" do
- after { Puppet::Util::Cacher.expire }
before do
# This is so the tests work w/out networking.
Facter.stubs(:to_hash).returns({"hostname" => "foo.domain.com"})
diff --git a/spec/integration/ssl/certificate_authority_spec.rb b/spec/integration/ssl/certificate_authority_spec.rb
index 2517f121e..a4792449e 100755
--- a/spec/integration/ssl/certificate_authority_spec.rb
+++ b/spec/integration/ssl/certificate_authority_spec.rb
@@ -2,17 +2,16 @@
require 'spec_helper'
require 'puppet/ssl/certificate_authority'
-require 'tempfile'
-describe Puppet::SSL::CertificateAuthority do
+describe Puppet::SSL::CertificateAuthority, :unless => Puppet.features.microsoft_windows? do
+ include PuppetSpec::Files
+
before do
# Get a safe temporary file
- file = Tempfile.new("ca_integration_testing")
- @dir = file.path
- file.delete
+ dir = tmpdir("ca_integration_testing")
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = dir
+ Puppet.settings[:vardir] = dir
Puppet.settings[:group] = Process.gid
Puppet::SSL::Host.ca_location = :local
@@ -22,11 +21,8 @@ describe Puppet::SSL::CertificateAuthority do
after {
Puppet::SSL::Host.ca_location = :none
- system("rm -rf #{@dir}")
Puppet.settings.clear
- Puppet::Util::Cacher.expire
-
Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil)
}
diff --git a/spec/integration/ssl/certificate_request_spec.rb b/spec/integration/ssl/certificate_request_spec.rb
index 4f3e98dc8..bcfcd2b43 100755
--- a/spec/integration/ssl/certificate_request_spec.rb
+++ b/spec/integration/ssl/certificate_request_spec.rb
@@ -2,21 +2,19 @@
require 'spec_helper'
require 'puppet/ssl/certificate_request'
-require 'tempfile'
-describe Puppet::SSL::CertificateRequest do
+# REMIND: Fails on windows because there is no user provider yet
+describe Puppet::SSL::CertificateRequest, :fails_on_windows => true do
+ include PuppetSpec::Files
+
before do
# Get a safe temporary file
- file = Tempfile.new("csr_integration_testing")
- @dir = file.path
- file.delete
-
- Dir.mkdir(@dir)
+ dir = tmpdir("csr_integration_testing")
Puppet.settings.clear
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = dir
+ Puppet.settings[:vardir] = dir
Puppet.settings[:group] = Process.gid
Puppet::SSL::Host.ca_location = :none
@@ -24,14 +22,13 @@ describe Puppet::SSL::CertificateRequest do
@csr = Puppet::SSL::CertificateRequest.new("luke.madstop.com")
@key = OpenSSL::PKey::RSA.new(512)
+
+ # This is necessary so the terminus instances don't lie around.
+ Puppet::SSL::CertificateRequest.indirection.termini.clear
end
after do
- system("rm -rf #{@dir}")
Puppet.settings.clear
-
- # This is necessary so the terminus instances don't lie around.
- Puppet::Util::Cacher.expire
end
it "should be able to generate CSRs" do
diff --git a/spec/integration/ssl/certificate_revocation_list_spec.rb b/spec/integration/ssl/certificate_revocation_list_spec.rb
index 55e8f4ac7..5912e4b98 100755
--- a/spec/integration/ssl/certificate_revocation_list_spec.rb
+++ b/spec/integration/ssl/certificate_revocation_list_spec.rb
@@ -2,17 +2,17 @@
require 'spec_helper'
require 'puppet/ssl/certificate_revocation_list'
-require 'tempfile'
-describe Puppet::SSL::CertificateRevocationList do
+# REMIND: Fails on windows because there is no user provider yet
+describe Puppet::SSL::CertificateRevocationList, :fails_on_windows => true do
+ include PuppetSpec::Files
+
before do
# Get a safe temporary file
- file = Tempfile.new("ca_integration_testing")
- @dir = file.path
- file.delete
+ dir = tmpdir("ca_integration_testing")
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = dir
+ Puppet.settings[:vardir] = dir
Puppet.settings[:group] = Process.gid
Puppet::SSL::Host.ca_location = :local
@@ -21,11 +21,10 @@ describe Puppet::SSL::CertificateRevocationList do
after {
Puppet::SSL::Host.ca_location = :none
- system("rm -rf #{@dir}")
Puppet.settings.clear
# This is necessary so the terminus instances don't lie around.
- Puppet::Util::Cacher.expire
+ Puppet::SSL::Host.indirection.termini.clear
}
it "should be able to read in written out CRLs with no revoked certificates" do
diff --git a/spec/integration/ssl/host_spec.rb b/spec/integration/ssl/host_spec.rb
index 5aa3eebad..55484ad1d 100755
--- a/spec/integration/ssl/host_spec.rb
+++ b/spec/integration/ssl/host_spec.rb
@@ -2,17 +2,17 @@
require 'spec_helper'
require 'puppet/ssl/host'
-require 'tempfile'
-describe Puppet::SSL::Host do
+# REMIND: Fails on windows because there is no user provider yet
+describe Puppet::SSL::Host, :fails_on_windows => true do
+ include PuppetSpec::Files
+
before do
# Get a safe temporary file
- file = Tempfile.new("host_integration_testing")
- @dir = file.path
- file.delete
+ dir = tmpdir("host_integration_testing")
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = dir
+ Puppet.settings[:vardir] = dir
Puppet.settings[:group] = Process.gid
Puppet::SSL::Host.ca_location = :local
@@ -24,9 +24,7 @@ describe Puppet::SSL::Host do
after {
Puppet::SSL::Host.ca_location = :none
- system("rm -rf #{@dir}")
Puppet.settings.clear
- Puppet::Util::Cacher.expire
}
it "should be considered a CA host if its name is equal to 'ca'" do
@@ -77,7 +75,7 @@ describe Puppet::SSL::Host do
end
end
- it "should pass the verification of its own SSL store" do
+ it "should pass the verification of its own SSL store", :unless => Puppet.features.microsoft_windows? do
@host.generate
@ca = Puppet::SSL::CertificateAuthority.new
@ca.sign(@host.name)
diff --git a/spec/integration/transaction/report_spec.rb b/spec/integration/transaction/report_spec.rb
index 031562ea1..8c581cc04 100755
--- a/spec/integration/transaction/report_spec.rb
+++ b/spec/integration/transaction/report_spec.rb
@@ -4,7 +4,6 @@ require 'spec_helper'
describe Puppet::Transaction::Report do
describe "when using the indirector" do
after do
- Puppet::Util::Cacher.expire
Puppet.settings.stubs(:use)
end
diff --git a/spec/integration/transaction_spec.rb b/spec/integration/transaction_spec.rb
index 00e9dbb8e..b4214214e 100755
--- a/spec/integration/transaction_spec.rb
+++ b/spec/integration/transaction_spec.rb
@@ -1,9 +1,7 @@
#!/usr/bin/env rspec
require 'spec_helper'
-require 'puppet_spec/files'
require 'puppet/transaction'
-require 'puppet_spec/files'
describe Puppet::Transaction do
include PuppetSpec::Files
@@ -20,10 +18,10 @@ describe Puppet::Transaction do
it "should not apply generated resources if the parent resource fails" do
catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
+ resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false
catalog.add_resource resource
- child_resource = Puppet::Type.type(:file).new :path => "/foo/bar/baz", :backup => false
+ child_resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar/baz"), :backup => false
resource.expects(:eval_generate).returns([child_resource])
@@ -39,7 +37,7 @@ describe Puppet::Transaction do
it "should not apply virtual resources" do
catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
+ resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false
resource.virtual = true
catalog.add_resource resource
@@ -63,7 +61,7 @@ describe Puppet::Transaction do
it "should not apply virtual exported resources" do
catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
+ resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false
resource.exported = true
resource.virtual = true
catalog.add_resource resource
@@ -91,7 +89,7 @@ describe Puppet::Transaction do
it "should not apply host resources on device" do
catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
+ resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false
catalog.add_resource resource
transaction = Puppet::Transaction.new(catalog)
@@ -133,7 +131,7 @@ describe Puppet::Transaction do
# Verify that one component requiring another causes the contained
# resources in the requiring component to get refreshed.
- it "should propagate events from a contained resource through its container to its dependent container's contained resources" do
+ it "should propagate events from a contained resource through its container to its dependent container's contained resources", :fails_on_windows => true do
transaction = nil
file = Puppet::Type.type(:file).new :path => tmpfile("event_propagation"), :ensure => :present
execfile = File.join(tmpdir("exec_event"), "exectestingness2")
@@ -157,7 +155,7 @@ describe Puppet::Transaction do
end
# Make sure that multiple subscriptions get triggered.
- it "should propagate events to all dependent resources" do
+ it "should propagate events to all dependent resources", :fails_on_windows => true do
path = tmpfile("path")
file1 = tmpfile("file1")
file2 = tmpfile("file2")
@@ -187,7 +185,7 @@ describe Puppet::Transaction do
FileTest.should be_exist(file2)
end
- it "should not let one failed refresh result in other refreshes failing" do
+ it "should not let one failed refresh result in other refreshes failing", :fails_on_windows => true do
path = tmpfile("path")
newfile = tmpfile("file")
file = Puppet::Type.type(:file).new(
@@ -220,7 +218,7 @@ describe Puppet::Transaction do
FileTest.should be_exists(newfile)
end
- it "should still trigger skipped resources", :'fails_on_ruby_1.9.2' => true do
+ it "should still trigger skipped resources", :'fails_on_ruby_1.9.2' => true, :fails_on_windows => true do
catalog = mk_catalog
catalog.add_resource(*Puppet::Type.type(:schedule).mkdefaultschedules)
@@ -272,7 +270,7 @@ describe Puppet::Transaction do
FileTest.should be_exists(fname)
end
- it "should not attempt to evaluate resources with failed dependencies" do
+ it "should not attempt to evaluate resources with failed dependencies", :fails_on_windows => true do
exec = Puppet::Type.type(:exec).new(
:command => "/bin/mkdir /this/path/cannot/possibly/exist",
@@ -300,7 +298,7 @@ describe Puppet::Transaction do
FileTest.should_not be_exists(file2[:path])
end
- it "should not trigger subscribing resources on failure" do
+ it "should not trigger subscribing resources on failure", :fails_on_windows => true do
file1 = tmpfile("file1")
file2 = tmpfile("file2")
diff --git a/spec/integration/type/file_spec.rb b/spec/integration/type/file_spec.rb
index 4bed8c6c1..9814c4539 100755
--- a/spec/integration/type/file_spec.rb
+++ b/spec/integration/type/file_spec.rb
@@ -12,7 +12,7 @@ describe Puppet::Type.type(:file) do
end
it "should not attempt to manage files that do not exist if no means of creating the file is specified" do
- file = Puppet::Type.type(:file).new :path => "/my/file", :mode => "755"
+ file = Puppet::Type.type(:file).new :path => make_absolute("/my/file"), :mode => "755"
catalog = Puppet::Resource::Catalog.new
catalog.add_resource file
@@ -23,7 +23,7 @@ describe Puppet::Type.type(:file) do
end
describe "when writing files" do
- it "should backup files to a filebucket when one is configured" do
+ it "should backup files to a filebucket when one is configured", :fails_on_windows => true do
bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo"
catalog = Puppet::Resource::Catalog.new
@@ -73,7 +73,7 @@ describe Puppet::Type.type(:file) do
File.read(file[:path]).should == "bar\n"
end
- it "should not backup symlinks" do
+ it "should not backup symlinks", :unless => Puppet.features.microsoft_windows? do
link = tmpfile("link")
dest1 = tmpfile("dest1")
dest2 = tmpfile("dest2")
@@ -110,7 +110,7 @@ describe Puppet::Type.type(:file) do
File.read(File.join(backup, "foo")).should == "yay"
end
- it "should backup directories to filebuckets by backing up each file separately" do
+ it "should backup directories to filebuckets by backing up each file separately", :fails_on_windows => true do
bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo", :force => true
catalog = Puppet::Resource::Catalog.new
@@ -172,7 +172,7 @@ describe Puppet::Type.type(:file) do
end
end
- it "should be able to recurse over a nonexistent file" do
+ it "should be able to recurse over a nonexistent file", :fails_on_windows => true do
@path = tmpfile("file_integration_tests")
@file = Puppet::Type::File.new(
@@ -214,7 +214,7 @@ describe Puppet::Type.type(:file) do
end
end
- it "should be able to recursively make links to other files" do
+ it "should be able to recursively make links to other files", :unless => Puppet.features.microsoft_windows? do
source = tmpfile("file_link_integration_source")
build_path(source)
@@ -241,7 +241,7 @@ describe Puppet::Type.type(:file) do
end
end
- it "should be able to recursively copy files" do
+ it "should be able to recursively copy files", :fails_on_windows => true do
source = tmpfile("file_source_integration_source")
build_path(source)
@@ -292,24 +292,25 @@ describe Puppet::Type.type(:file) do
it "should recursively manage files even if there is an explicit file whose name is a prefix of the managed file" do
dir = tmpfile("recursion_vs_explicit_2")
- managed = File.join(dir, "file")
- generated = File.join(dir, "file_with_a_name_starting_with_the_word_file")
+ managed = File.join(dir, "file")
+ generated = File.join(dir, "file_with_a_name_starting_with_the_word_file")
+ managed_mode = Puppet.features.microsoft_windows? ? 0444 : 0700
FileUtils.mkdir_p(dir)
File.open(managed, "w") { |f| f.puts "" }
File.open(generated, "w") { |f| f.puts "" }
@catalog = Puppet::Resource::Catalog.new
- @catalog.add_resource Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => "755")
+ @catalog.add_resource Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => managed_mode)
@catalog.add_resource Puppet::Type::File.new(:name => managed, :recurse => true, :backup => false, :mode => "644")
@catalog.apply
- (File.stat(generated).mode & 007777).should == 0755
+ (File.stat(generated).mode & 007777).should == managed_mode
end
end
- describe "when generating resources" do
+ describe "when generating resources", :fails_on_windows => true do
before do
@source = tmpfile("generating_in_catalog_source")
@@ -381,8 +382,9 @@ describe Puppet::Type.type(:file) do
catalog.apply
+ expected_mode = Puppet.features.microsoft_windows? ? 0644 : 0755
File.read(dest).should == "foo"
- (File.stat(dest).mode & 007777).should == 0755
+ (File.stat(dest).mode & 007777).should == expected_mode
end
it "should be able to copy individual files even if recurse has been specified" do
@@ -442,7 +444,7 @@ describe Puppet::Type.type(:file) do
file = Puppet::Type.type(:file).new(
- :name => dest,
+ :name => make_absolute(dest),
:ensure => :absent,
:source => source,
:backup => false
@@ -470,7 +472,6 @@ describe Puppet::Type.type(:file) do
# this file should get removed
File.open(@purgee, "w") { |f| f.puts "footest" }
-
@lfobj = Puppet::Type.newfile(
:title => "localfile",
:path => @localfile,
@@ -479,7 +480,6 @@ describe Puppet::Type.type(:file) do
:backup => false
)
-
@destobj = Puppet::Type.newfile(
:title => "destdir",
:path => @destdir,
diff --git a/spec/integration/type/tidy_spec.rb b/spec/integration/type/tidy_spec.rb
index 675aaf4cd..d1bb62d6e 100755
--- a/spec/integration/type/tidy_spec.rb
+++ b/spec/integration/type/tidy_spec.rb
@@ -12,7 +12,7 @@ describe Puppet::Type.type(:tidy) do
end
# Testing #355.
- it "should be able to remove dead links" do
+ it "should be able to remove dead links", :unless => Puppet.features.microsoft_windows? do
dir = tmpfile("tidy_link_testing")
link = File.join(dir, "link")
target = tmpfile("no_such_file_tidy_link_testing")
diff --git a/spec/integration/util/settings_spec.rb b/spec/integration/util/settings_spec.rb
index b05c63107..46d783c4e 100755
--- a/spec/integration/util/settings_spec.rb
+++ b/spec/integration/util/settings_spec.rb
@@ -18,12 +18,12 @@ describe Puppet::Util::Settings do
File.should be_directory(settings[:maindir])
end
- it "should make its directories with the corret modes" do
+ it "should make its directories with the correct modes" do
settings = Puppet::Util::Settings.new
settings.setdefaults :main, minimal_default_settings.update( :maindir => {:default => tmpfile("main"), :desc => "a", :mode => 0750} )
settings.use(:main)
- (File.stat(settings[:maindir]).mode & 007777).should == 0750
+ (File.stat(settings[:maindir]).mode & 007777).should == (Puppet.features.microsoft_windows? ? 0755 : 0750)
end
end
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index 30fb4fc42..725bf2af9 100755
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -1,21 +1,19 @@
require 'fileutils'
require 'tempfile'
+require 'pathname'
# A support module for testing files.
module PuppetSpec::Files
# This code exists only to support tests that run as root, pretty much.
# Once they have finally been eliminated this can all go... --daniel 2011-04-08
- if Puppet.features.posix? then
- def self.in_tmp(path)
- path =~ /^\/tmp/ or path =~ /^\/var\/folders/
- end
- elsif Puppet.features.microsoft_windows?
- def self.in_tmp(path)
- tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp"))
- path =~ /^#{tempdir}/
+ def self.in_tmp(path)
+ tempdir = Dir.tmpdir
+
+ Pathname.new(path).ascend do |dir|
+ return true if File.identical?(tempdir, dir)
end
- else
- fail "Help! Can't find in_tmp for this platform"
+
+ false
end
def self.cleanup
@@ -31,6 +29,16 @@ module PuppetSpec::Files
end
end
+ def make_absolute(path)
+ return path unless Puppet.features.microsoft_windows?
+ # REMIND UNC
+ return path if path =~ /^[A-Za-z]:/
+
+ pwd = Dir.getwd
+ return "#{pwd[0,2]}#{path}" if pwd.length > 2 and pwd =~ /^[A-Za-z]:/
+ return "C:#{path}"
+ end
+
def tmpfile(name)
# Generate a temporary file, just for the name...
source = Tempfile.new(name)
diff --git a/spec/shared_behaviours/file_server_terminus.rb b/spec/shared_behaviours/file_server_terminus.rb
index e300d9b4d..33037e551 100755
--- a/spec/shared_behaviours/file_server_terminus.rb
+++ b/spec/shared_behaviours/file_server_terminus.rb
@@ -3,7 +3,7 @@ shared_examples_for "Puppet::Indirector::FileServerTerminus" do
# This only works if the shared behaviour is included before
# the 'before' block in the including context.
before do
- Puppet::Util::Cacher.expire
+ Puppet::FileServing::Configuration.instance_variable_set(:@configuration, nil)
FileTest.stubs(:exists?).returns true
FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true)
diff --git a/spec/unit/application/device_spec.rb b/spec/unit/application/device_spec.rb
index 42a62da22..f88c0c3d9 100755
--- a/spec/unit/application/device_spec.rb
+++ b/spec/unit/application/device_spec.rb
@@ -7,6 +7,8 @@ require 'ostruct'
require 'puppet/configurer'
describe Puppet::Application::Device do
+ include PuppetSpec::Files
+
before :each do
@device = Puppet::Application[:device]
@device.preinit
@@ -264,8 +266,8 @@ describe Puppet::Application::Device do
describe "for each device" do
before(:each) do
- Puppet[:vardir] = "/dummy"
- Puppet[:confdir] = "/dummy"
+ Puppet[:vardir] = make_absolute("/dummy")
+ Puppet[:confdir] = make_absolute("/dummy")
Puppet[:certname] = "certname"
@device_hash = {
"device1" => OpenStruct.new(:name => "device1", :url => "url", :provider => "cisco"),
@@ -281,12 +283,12 @@ describe Puppet::Application::Device do
end
it "should set vardir to the device vardir" do
- Puppet.settings.expects(:set_value).with(:vardir, "/dummy/devices/device1", :cli)
+ Puppet.settings.expects(:set_value).with(:vardir, make_absolute("/dummy/devices/device1"), :cli)
@device.main
end
it "should set confdir to the device confdir" do
- Puppet.settings.expects(:set_value).with(:confdir, "/dummy/devices/device1", :cli)
+ Puppet.settings.expects(:set_value).with(:confdir, make_absolute("/dummy/devices/device1"), :cli)
@device.main
end
@@ -319,9 +321,9 @@ describe Puppet::Application::Device do
[:vardir, :confdir].each do |setting|
it "should cleanup the #{setting} setting after the run" do
configurer = states('configurer').starts_as('notrun')
- Puppet.settings.expects(:set_value).with(setting, "/dummy/devices/device1", :cli).when(configurer.is('notrun'))
+ Puppet.settings.expects(:set_value).with(setting, make_absolute("/dummy/devices/device1"), :cli).when(configurer.is('notrun'))
@configurer.expects(:run).twice.then(configurer.is('run'))
- Puppet.settings.expects(:set_value).with(setting, "/dummy", :cli).when(configurer.is('run'))
+ Puppet.settings.expects(:set_value).with(setting, make_absolute("/dummy"), :cli).when(configurer.is('run'))
@device.main
end
diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb
index 77f36f438..750f25ab8 100755
--- a/spec/unit/application/inspect_spec.rb
+++ b/spec/unit/application/inspect_spec.rb
@@ -103,6 +103,7 @@ describe Puppet::Application::Inspect do
catalog = Puppet::Resource::Catalog.new
file = Tempfile.new("foo")
resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
+ file.close
file.delete
catalog.add_resource(resource)
Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
@@ -147,7 +148,7 @@ describe Puppet::Application::Inspect do
@inspect.run_command
end
- it "should not send unreadable files" do
+ it "should not send unreadable files", :unless => Puppet.features.microsoft_windows? do
File.open(@file, 'w') { |f| f.write('stuff') }
File.chmod(0, @file)
Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
diff --git a/spec/unit/application/master_spec.rb b/spec/unit/application/master_spec.rb
index 2f6a328e2..c6df48f4d 100755
--- a/spec/unit/application/master_spec.rb
+++ b/spec/unit/application/master_spec.rb
@@ -5,7 +5,7 @@ require 'puppet/application/master'
require 'puppet/daemon'
require 'puppet/network/server'
-describe Puppet::Application::Master do
+describe Puppet::Application::Master, :unless => Puppet.features.microsoft_windows? do
before :each do
@master = Puppet::Application[:master]
@daemon = stub_everything 'daemon'
@@ -106,7 +106,6 @@ describe Puppet::Application::Master do
end
describe "during setup" do
-
before :each do
Puppet::Log.stubs(:newdestination)
Puppet.stubs(:settraps)
@@ -117,6 +116,12 @@ describe Puppet::Application::Master do
@master.options.stubs(:[]).with(any_parameters)
end
+ it "should abort stating that the master is not supported on Windows" do
+ Puppet.features.stubs(:microsoft_windows?).returns(true)
+
+ expect { @master.setup }.to raise_error(Puppet::Error, /Puppet master is not supported on Microsoft Windows/)
+ end
+
it "should set log level to debug if --debug was passed" do
@master.options.stubs(:[]).with(:debug).returns(true)
@master.setup
diff --git a/spec/unit/application/queue_spec.rb b/spec/unit/application/queue_spec.rb
index 15e3927a1..d861383a6 100755
--- a/spec/unit/application/queue_spec.rb
+++ b/spec/unit/application/queue_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
require 'puppet/application/queue'
require 'puppet/indirector/catalog/queue'
-describe Puppet::Application::Queue do
+describe Puppet::Application::Queue, :unless => Puppet.features.microsoft_windows? do
before :each do
@queue = Puppet::Application[:queue]
@queue.stubs(:puts)
diff --git a/spec/unit/application/resource_spec.rb b/spec/unit/application/resource_spec.rb
index 01cd17e00..b6ed8598d 100755
--- a/spec/unit/application/resource_spec.rb
+++ b/spec/unit/application/resource_spec.rb
@@ -235,12 +235,13 @@ describe Puppet::Application::Resource do
end
it "should output a file resource when given a file path" do
- res = Puppet::Type.type(:file).new(:path => "/etc").to_resource
+ path = File.expand_path('/etc')
+ res = Puppet::Type.type(:file).new(:path => path).to_resource
Puppet::Resource.indirection.expects(:find).returns(res)
- @resource.command_line.stubs(:args).returns(['file', '/etc'])
+ @resource.command_line.stubs(:args).returns(['file', path])
@resource.expects(:puts).with do |args|
- args.should =~ /file \{ '\/etc'/m
+ args.should =~ /file \{ '#{Regexp.escape(path)}'/m
end
@resource.main
diff --git a/spec/unit/configurer/downloader_spec.rb b/spec/unit/configurer/downloader_spec.rb
index 17b285d53..8bb6a3dc6 100755
--- a/spec/unit/configurer/downloader_spec.rb
+++ b/spec/unit/configurer/downloader_spec.rb
@@ -97,14 +97,15 @@ describe Puppet::Configurer::Downloader do
describe "when creating the catalog to do the downloading" do
before do
- @dler = Puppet::Configurer::Downloader.new("foo", "/download/path", "source")
+ @path = make_absolute("/download/path")
+ @dler = Puppet::Configurer::Downloader.new("foo", @path, "source")
end
it "should create a catalog and add the file to it" do
catalog = @dler.catalog
catalog.resources.size.should == 1
catalog.resources.first.class.should == Puppet::Type::File
- catalog.resources.first.name.should == "/download/path"
+ catalog.resources.first.name.should == @path
end
it "should specify that it is not managing a host catalog" do
@@ -121,7 +122,7 @@ describe Puppet::Configurer::Downloader do
@dler = Puppet::Configurer::Downloader.new("foo", @dl_name, source_name)
end
- it "should not skip downloaded resources when filtering on tags" do
+ it "should not skip downloaded resources when filtering on tags", :fails_on_windows => true do
Puppet[:tags] = 'maytag'
@dler.evaluate
diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb
index e2679a966..fc43d93ad 100755
--- a/spec/unit/daemon_spec.rb
+++ b/spec/unit/daemon_spec.rb
@@ -28,7 +28,9 @@ describe Puppet::Daemon do
end
describe "when setting signal traps" do
- {:INT => :stop, :TERM => :stop, :HUP => :restart, :USR1 => :reload, :USR2 => :reopen_logs}.each do |signal, method|
+ signals = {:INT => :stop, :TERM => :stop }
+ signals.update({:HUP => :restart, :USR1 => :reload, :USR2 => :reopen_logs}) unless Puppet.features.microsoft_windows?
+ signals.each do |signal, method|
it "should log and call #{method} when it receives #{signal}" do
Signal.expects(:trap).with(signal).yields
diff --git a/spec/unit/face/ca_spec.rb b/spec/unit/face/ca_spec.rb
index b8c82ce99..1df4d7c53 100755
--- a/spec/unit/face/ca_spec.rb
+++ b/spec/unit/face/ca_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
require 'puppet/face'
-describe Puppet::Face[:ca, '0.1.0'] do
+describe Puppet::Face[:ca, '0.1.0'], :unless => Puppet.features.microsoft_windows? do
include PuppetSpec::Files
before :each do
diff --git a/spec/unit/file_bucket/dipper_spec.rb b/spec/unit/file_bucket/dipper_spec.rb
index 910b2808d..605719324 100755
--- a/spec/unit/file_bucket/dipper_spec.rb
+++ b/spec/unit/file_bucket/dipper_spec.rb
@@ -16,7 +16,7 @@ describe Puppet::FileBucket::Dipper do
end
it "should fail in an informative way when there are failures checking for the file on the server" do
- @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => make_absolute("/my/bucket"))
file = make_tmp_file('contents')
Puppet::FileBucket::File.indirection.expects(:head).raises ArgumentError
@@ -25,7 +25,7 @@ describe Puppet::FileBucket::Dipper do
end
it "should fail in an informative way when there are failures backing up to the server" do
- @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket")
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => make_absolute("/my/bucket"))
file = make_tmp_file('contents')
Puppet::FileBucket::File.indirection.expects(:head).returns false
@@ -34,7 +34,7 @@ describe Puppet::FileBucket::Dipper do
lambda { @dipper.backup(file) }.should raise_error(Puppet::Error)
end
- it "should backup files to a local bucket" do
+ it "should backup files to a local bucket", :fails_on_windows => true do
Puppet[:bucketdir] = "/non/existent/directory"
file_bucket = tmpdir("bucket")
@@ -91,7 +91,7 @@ describe Puppet::FileBucket::Dipper do
[request1, request2].each do |r|
r.server.should == 'puppetmaster'
r.port.should == 31337
- r.key.should == "md5/#{checksum}#{real_path}"
+ r.key.should == "md5/#{checksum}/#{real_path}"
end
end
diff --git a/spec/unit/file_bucket/file_spec.rb b/spec/unit/file_bucket/file_spec.rb
index c4444ae77..ebf02438c 100755
--- a/spec/unit/file_bucket/file_spec.rb
+++ b/spec/unit/file_bucket/file_spec.rb
@@ -26,11 +26,17 @@ describe Puppet::FileBucket::File do
it "should raise an error if changing content" do
x = Puppet::FileBucket::File.new("first")
- proc { x.contents = "new" }.should raise_error
+ expect { x.contents = "new" }.to raise_error(NoMethodError, /undefined method .contents=/)
end
it "should require contents to be a string" do
- proc { Puppet::FileBucket::File.new(5) }.should raise_error(ArgumentError)
+ expect { Puppet::FileBucket::File.new(5) }.to raise_error(ArgumentError, /contents must be a String, got a Fixnum$/)
+ end
+
+ it "should complain about options other than :bucket_path" do
+ expect {
+ Puppet::FileBucket::File.new('5', :crazy_option => 'should not be passed')
+ }.to raise_error(ArgumentError, /Unknown option\(s\): crazy_option/)
end
it "should set the contents appropriately" do
@@ -61,7 +67,7 @@ describe Puppet::FileBucket::File do
it "should reject a url-ish name with an invalid checksum" do
bucket = Puppet::FileBucket::File.new(@contents)
- lambda { bucket.name = "sha1/4a8ec4fa5f01b4ab1a0ab8cbccb709f0/new/path" }.should raise_error
+ expect { bucket.name = "sha1/4a8ec4fa5f01b4ab1a0ab8cbccb709f0/new/path" }.to raise_error(NoMethodError, /undefined method .name=/)
end
it "should convert the contents to PSON" do
diff --git a/spec/unit/file_serving/configuration_spec.rb b/spec/unit/file_serving/configuration_spec.rb
index 6ee1a4f38..a1546c987 100755
--- a/spec/unit/file_serving/configuration_spec.rb
+++ b/spec/unit/file_serving/configuration_spec.rb
@@ -4,42 +4,31 @@ require 'spec_helper'
require 'puppet/file_serving/configuration'
describe Puppet::FileServing::Configuration do
- it "should make :new a private method" do
- proc { Puppet::FileServing::Configuration.new }.should raise_error
- end
-
- it "should return the same configuration each time :create is called" do
- Puppet::FileServing::Configuration.create.should equal(Puppet::FileServing::Configuration.create)
- end
-
- it "should have a method for removing the current configuration instance" do
- old = Puppet::FileServing::Configuration.create
- Puppet::Util::Cacher.expire
- Puppet::FileServing::Configuration.create.should_not equal(old)
- end
-
- after do
- Puppet::Util::Cacher.expire
- end
-end
-
-describe Puppet::FileServing::Configuration do
+ include PuppetSpec::Files
before :each do
- @path = "/path/to/configuration/file.conf"
+ @path = make_absolute("/path/to/configuration/file.conf")
Puppet.settings.stubs(:value).with(:trace).returns(false)
Puppet.settings.stubs(:value).with(:fileserverconfig).returns(@path)
end
after :each do
- Puppet::Util::Cacher.expire
+ Puppet::FileServing::Configuration.instance_variable_set(:@configuration, nil)
+ end
+
+ it "should make :new a private method" do
+ proc { Puppet::FileServing::Configuration.new }.should raise_error
+ end
+
+ it "should return the same configuration each time 'configuration' is called" do
+ Puppet::FileServing::Configuration.configuration.should equal(Puppet::FileServing::Configuration.configuration)
end
describe "when initializing" do
it "should work without a configuration file" do
FileTest.stubs(:exists?).with(@path).returns(false)
- proc { Puppet::FileServing::Configuration.create }.should_not raise_error
+ proc { Puppet::FileServing::Configuration.configuration }.should_not raise_error
end
it "should parse the configuration file if present" do
@@ -47,11 +36,11 @@ describe Puppet::FileServing::Configuration do
@parser = mock 'parser'
@parser.expects(:parse).returns({})
Puppet::FileServing::Configuration::Parser.stubs(:new).returns(@parser)
- Puppet::FileServing::Configuration.create
+ Puppet::FileServing::Configuration.configuration
end
it "should determine the path to the configuration file from the Puppet settings" do
- Puppet::FileServing::Configuration.create
+ Puppet::FileServing::Configuration.configuration
end
end
@@ -65,18 +54,18 @@ describe Puppet::FileServing::Configuration do
it "should set the mount list to the results of parsing" do
@parser.expects(:parse).returns("one" => mock("mount"))
- config = Puppet::FileServing::Configuration.create
+ config = Puppet::FileServing::Configuration.configuration
config.mounted?("one").should be_true
end
it "should not raise exceptions" do
@parser.expects(:parse).raises(ArgumentError)
- proc { Puppet::FileServing::Configuration.create }.should_not raise_error
+ proc { Puppet::FileServing::Configuration.configuration }.should_not raise_error
end
it "should replace the existing mount list with the results of reparsing" do
@parser.expects(:parse).returns("one" => mock("mount"))
- config = Puppet::FileServing::Configuration.create
+ config = Puppet::FileServing::Configuration.configuration
config.mounted?("one").should be_true
# Now parse again
@parser.expects(:parse).returns("two" => mock('other'))
@@ -88,7 +77,7 @@ describe Puppet::FileServing::Configuration do
it "should not replace the mount list until the file is entirely parsed successfully" do
@parser.expects(:parse).returns("one" => mock("mount"))
@parser.expects(:parse).raises(ArgumentError)
- config = Puppet::FileServing::Configuration.create
+ config = Puppet::FileServing::Configuration.configuration
# Now parse again, so the exception gets thrown
config.send(:readconfig, false)
config.mounted?("one").should be_true
@@ -96,7 +85,7 @@ describe Puppet::FileServing::Configuration do
it "should add modules and plugins mounts even if the file does not exist" do
FileTest.expects(:exists?).returns false # the file doesn't exist
- config = Puppet::FileServing::Configuration.create
+ config = Puppet::FileServing::Configuration.configuration
config.mounted?("modules").should be_true
config.mounted?("plugins").should be_true
end
@@ -111,7 +100,7 @@ describe Puppet::FileServing::Configuration do
Puppet::FileServing::Mount::Plugins.stubs(:new).returns(plugins)
plugins.expects(:allow).with('*')
- Puppet::FileServing::Configuration.create
+ Puppet::FileServing::Configuration.configuration
end
it "should not allow access from all to modules and plugins if the fileserver.conf provided some rules" do
@@ -125,13 +114,13 @@ describe Puppet::FileServing::Configuration do
Puppet::FileServing::Mount::Plugins.stubs(:new).returns(plugins)
plugins.expects(:allow).with('*').never
- Puppet::FileServing::Configuration.create
+ Puppet::FileServing::Configuration.configuration
end
it "should add modules and plugins mounts even if they are not returned by the parser" do
@parser.expects(:parse).returns("one" => mock("mount"))
FileTest.expects(:exists?).returns true # the file doesn't exist
- config = Puppet::FileServing::Configuration.create
+ config = Puppet::FileServing::Configuration.configuration
config.mounted?("modules").should be_true
config.mounted?("plugins").should be_true
end
@@ -139,13 +128,13 @@ describe Puppet::FileServing::Configuration do
describe "when finding the specified mount" do
it "should choose the named mount if one exists" do
- config = Puppet::FileServing::Configuration.create
+ config = Puppet::FileServing::Configuration.configuration
config.expects(:mounts).returns("one" => "foo")
config.find_mount("one", mock('env')).should == "foo"
end
it "should use the provided environment to find a matching module if the named module cannot be found" do
- config = Puppet::FileServing::Configuration.create
+ config = Puppet::FileServing::Configuration.configuration
mod = mock 'module'
env = mock 'environment'
@@ -158,7 +147,7 @@ describe Puppet::FileServing::Configuration do
end
it "should return nil if there is no such named mount and no module with the same name exists" do
- config = Puppet::FileServing::Configuration.create
+ config = Puppet::FileServing::Configuration.configuration
env = mock 'environment'
env.expects(:module).with("foo").returns nil
@@ -171,7 +160,7 @@ describe Puppet::FileServing::Configuration do
describe "when finding the mount name and relative path in a request key" do
before do
- @config = Puppet::FileServing::Configuration.create
+ @config = Puppet::FileServing::Configuration.configuration
@config.stubs(:find_mount)
@request = stub 'request', :key => "foo/bar/baz", :options => {}, :node => nil, :environment => mock("env")
diff --git a/spec/unit/file_serving/fileset_spec.rb b/spec/unit/file_serving/fileset_spec.rb
index 41810650a..aff4c91fa 100755
--- a/spec/unit/file_serving/fileset_spec.rb
+++ b/spec/unit/file_serving/fileset_spec.rb
@@ -4,6 +4,12 @@ require 'spec_helper'
require 'puppet/file_serving/fileset'
describe Puppet::FileServing::Fileset, " when initializing" do
+ include PuppetSpec::Files
+
+ before :each do
+ @somefile = make_absolute("/some/file")
+ end
+
it "should require a path" do
proc { Puppet::FileServing::Fileset.new }.should raise_error(ArgumentError)
end
@@ -13,83 +19,82 @@ describe Puppet::FileServing::Fileset, " when initializing" do
end
it "should not fail if the path is fully qualified, with a trailing separator" do
- path = "/some/path/with/trailing/separator"
- path_with_separator = "#{path}#{File::SEPARATOR}"
- File.stubs(:lstat).with(path).returns stub('stat')
+ path_with_separator = "#{@somefile}#{File::SEPARATOR}"
+ File.stubs(:lstat).with(@somefile).returns stub('stat')
fileset = Puppet::FileServing::Fileset.new(path_with_separator)
- fileset.path.should == path
+ fileset.path.should == @somefile
end
it "should not fail if the path is just the file separator" do
- path = File::SEPARATOR
+ path = make_absolute(File::SEPARATOR)
File.stubs(:lstat).with(path).returns stub('stat')
fileset = Puppet::FileServing::Fileset.new(path)
fileset.path.should == path
end
it "should fail if its path does not exist" do
- File.expects(:lstat).with("/some/file").returns nil
- proc { Puppet::FileServing::Fileset.new("/some/file") }.should raise_error(ArgumentError)
+ File.expects(:lstat).with(@somefile).returns nil
+ proc { Puppet::FileServing::Fileset.new(@somefile) }.should raise_error(ArgumentError)
end
it "should accept a 'recurse' option" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- set = Puppet::FileServing::Fileset.new("/some/file", :recurse => true)
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ set = Puppet::FileServing::Fileset.new(@somefile, :recurse => true)
set.recurse.should be_true
end
it "should accept a 'recurselimit' option" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- set = Puppet::FileServing::Fileset.new("/some/file", :recurselimit => 3)
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ set = Puppet::FileServing::Fileset.new(@somefile, :recurselimit => 3)
set.recurselimit.should == 3
end
it "should accept an 'ignore' option" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- set = Puppet::FileServing::Fileset.new("/some/file", :ignore => ".svn")
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ set = Puppet::FileServing::Fileset.new(@somefile, :ignore => ".svn")
set.ignore.should == [".svn"]
end
it "should accept a 'links' option" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- set = Puppet::FileServing::Fileset.new("/some/file", :links => :manage)
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ set = Puppet::FileServing::Fileset.new(@somefile, :links => :manage)
set.links.should == :manage
end
it "should accept a 'checksum_type' option" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- set = Puppet::FileServing::Fileset.new("/some/file", :checksum_type => :test)
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ set = Puppet::FileServing::Fileset.new(@somefile, :checksum_type => :test)
set.checksum_type.should == :test
end
it "should fail if 'links' is set to anything other than :manage or :follow" do
- proc { Puppet::FileServing::Fileset.new("/some/file", :links => :whatever) }.should raise_error(ArgumentError)
+ proc { Puppet::FileServing::Fileset.new(@somefile, :links => :whatever) }.should raise_error(ArgumentError)
end
it "should default to 'false' for recurse" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- Puppet::FileServing::Fileset.new("/some/file").recurse.should == false
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ Puppet::FileServing::Fileset.new(@somefile).recurse.should == false
end
it "should default to :infinite for recurselimit" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- Puppet::FileServing::Fileset.new("/some/file").recurselimit.should == :infinite
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ Puppet::FileServing::Fileset.new(@somefile).recurselimit.should == :infinite
end
it "should default to an empty ignore list" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- Puppet::FileServing::Fileset.new("/some/file").ignore.should == []
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ Puppet::FileServing::Fileset.new(@somefile).ignore.should == []
end
it "should default to :manage for links" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
- Puppet::FileServing::Fileset.new("/some/file").links.should == :manage
+ File.expects(:lstat).with(@somefile).returns stub("stat")
+ Puppet::FileServing::Fileset.new(@somefile).links.should == :manage
end
it "should support using an Indirector Request for its options" do
- File.expects(:lstat).with("/some/file").returns stub("stat")
+ File.expects(:lstat).with(@somefile).returns stub("stat")
request = Puppet::Indirector::Request.new(:file_serving, :find, "foo")
- lambda { Puppet::FileServing::Fileset.new("/some/file", request) }.should_not raise_error
+ lambda { Puppet::FileServing::Fileset.new(@somefile, request) }.should_not raise_error
end
describe "using an indirector request" do
@@ -97,40 +102,43 @@ describe Puppet::FileServing::Fileset, " when initializing" do
File.stubs(:lstat).returns stub("stat")
@values = {:links => :manage, :ignore => %w{a b}, :recurse => true, :recurselimit => 1234}
@request = Puppet::Indirector::Request.new(:file_serving, :find, "foo")
+ @myfile = make_absolute("/my/file")
end
[:recurse, :recurselimit, :ignore, :links].each do |option|
it "should pass :recurse, :recurselimit, :ignore, and :links settings on to the fileset if present" do
@request.stubs(:options).returns(option => @values[option])
- Puppet::FileServing::Fileset.new("/my/file", @request).send(option).should == @values[option]
+ Puppet::FileServing::Fileset.new(@myfile, @request).send(option).should == @values[option]
end
it "should pass :recurse, :recurselimit, :ignore, and :links settings on to the fileset if present with the keys stored as strings" do
@request.stubs(:options).returns(option.to_s => @values[option])
- Puppet::FileServing::Fileset.new("/my/file", @request).send(option).should == @values[option]
+ Puppet::FileServing::Fileset.new(@myfile, @request).send(option).should == @values[option]
end
end
it "should convert the integer as a string to their integer counterpart when setting options" do
@request.stubs(:options).returns(:recurselimit => "1234")
- Puppet::FileServing::Fileset.new("/my/file", @request).recurselimit.should == 1234
+ Puppet::FileServing::Fileset.new(@myfile, @request).recurselimit.should == 1234
end
it "should convert the string 'true' to the boolean true when setting options" do
@request.stubs(:options).returns(:recurse => "true")
- Puppet::FileServing::Fileset.new("/my/file", @request).recurse.should == true
+ Puppet::FileServing::Fileset.new(@myfile, @request).recurse.should == true
end
it "should convert the string 'false' to the boolean false when setting options" do
@request.stubs(:options).returns(:recurse => "false")
- Puppet::FileServing::Fileset.new("/my/file", @request).recurse.should == false
+ Puppet::FileServing::Fileset.new(@myfile, @request).recurse.should == false
end
end
end
describe Puppet::FileServing::Fileset, " when determining whether to recurse" do
+ include PuppetSpec::Files
+
before do
- @path = "/my/path"
+ @path = make_absolute("/my/path")
File.expects(:lstat).with(@path).returns stub("stat")
@fileset = Puppet::FileServing::Fileset.new(@path)
end
@@ -166,8 +174,10 @@ describe Puppet::FileServing::Fileset, " when determining whether to recurse" do
end
describe Puppet::FileServing::Fileset, " when recursing" do
+ include PuppetSpec::Files
+
before do
- @path = "/my/path"
+ @path = make_absolute("/my/path")
File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
@fileset = Puppet::FileServing::Fileset.new(@path)
@@ -257,7 +267,7 @@ describe Puppet::FileServing::Fileset, " when recursing" do
end
it "should succeed when paths have regexp significant characters" do
- @path = "/my/path/rV1x2DafFr0R6tGG+1bbk++++TM"
+ @path = make_absolute("/my/path/rV1x2DafFr0R6tGG+1bbk++++TM")
File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
@fileset = Puppet::FileServing::Fileset.new(@path)
mock_dir_structure(@path)
@@ -267,8 +277,10 @@ describe Puppet::FileServing::Fileset, " when recursing" do
end
describe Puppet::FileServing::Fileset, " when following links that point to missing files" do
+ include PuppetSpec::Files
+
before do
- @path = "/my/path"
+ @path = make_absolute("/my/path")
File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
@fileset = Puppet::FileServing::Fileset.new(@path)
@fileset.links = :follow
@@ -291,8 +303,10 @@ describe Puppet::FileServing::Fileset, " when following links that point to miss
end
describe Puppet::FileServing::Fileset, " when ignoring" do
+ include PuppetSpec::Files
+
before do
- @path = "/my/path"
+ @path = make_absolute("/my/path")
File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
@fileset = Puppet::FileServing::Fileset.new(@path)
end
@@ -318,8 +332,10 @@ describe Puppet::FileServing::Fileset, " when ignoring" do
end
describe Puppet::FileServing::Fileset, "when merging other filesets" do
+ include PuppetSpec::Files
+
before do
- @paths = %w{/first/path /second/path /third/path}
+ @paths = [make_absolute("/first/path"), make_absolute("/second/path"), make_absolute("/third/path")]
File.stubs(:lstat).returns stub("stat", :directory? => false)
@filesets = @paths.collect do |path|
@@ -331,32 +347,32 @@ describe Puppet::FileServing::Fileset, "when merging other filesets" do
end
it "should return a hash of all files in each fileset with the value being the base path" do
- Dir.expects(:entries).with("/first/path").returns(%w{one uno})
- Dir.expects(:entries).with("/second/path").returns(%w{two dos})
- Dir.expects(:entries).with("/third/path").returns(%w{three tres})
+ Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one uno})
+ Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two dos})
+ Dir.expects(:entries).with(make_absolute("/third/path")).returns(%w{three tres})
Puppet::FileServing::Fileset.merge(*@filesets).should == {
- "." => "/first/path",
- "one" => "/first/path",
- "uno" => "/first/path",
- "two" => "/second/path",
- "dos" => "/second/path",
- "three" => "/third/path",
- "tres" => "/third/path",
+ "." => make_absolute("/first/path"),
+ "one" => make_absolute("/first/path"),
+ "uno" => make_absolute("/first/path"),
+ "two" => make_absolute("/second/path"),
+ "dos" => make_absolute("/second/path"),
+ "three" => make_absolute("/third/path"),
+ "tres" => make_absolute("/third/path"),
}
end
it "should include the base directory from the first fileset" do
- Dir.expects(:entries).with("/first/path").returns(%w{one})
- Dir.expects(:entries).with("/second/path").returns(%w{two})
+ Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one})
+ Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two})
- Puppet::FileServing::Fileset.merge(*@filesets)["."].should == "/first/path"
+ Puppet::FileServing::Fileset.merge(*@filesets)["."].should == make_absolute("/first/path")
end
it "should use the base path of the first found file when relative file paths conflict" do
- Dir.expects(:entries).with("/first/path").returns(%w{one})
- Dir.expects(:entries).with("/second/path").returns(%w{one})
+ Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one})
+ Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{one})
- Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == "/first/path"
+ Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == make_absolute("/first/path")
end
end
diff --git a/spec/unit/file_serving/mount/file_spec.rb b/spec/unit/file_serving/mount/file_spec.rb
index 70c804abd..1ee004c10 100755
--- a/spec/unit/file_serving/mount/file_spec.rb
+++ b/spec/unit/file_serving/mount/file_spec.rb
@@ -10,12 +10,6 @@ module FileServingMountTesting
end
describe Puppet::FileServing::Mount::File do
- it "should provide a method for clearing its cached host information" do
- old = Puppet::FileServing::Mount::File.localmap
- Puppet::Util::Cacher.expire
- Puppet::FileServing::Mount::File.localmap.should_not equal(old)
- end
-
it "should be invalid if it does not have a path" do
lambda { Puppet::FileServing::Mount::File.new("foo").validate }.should raise_error(ArgumentError)
end
@@ -27,169 +21,169 @@ describe Puppet::FileServing::Mount::File do
mount.path = "/foo"
lambda { mount.validate }.should_not raise_error(ArgumentError)
end
-end
-
-describe Puppet::FileServing::Mount::File, " when setting the path" do
- before do
- @mount = Puppet::FileServing::Mount::File.new("test")
- @dir = "/this/path/does/not/exist"
- end
-
- it "should fail if the path is not a directory" do
- FileTest.expects(:directory?).returns(false)
- proc { @mount.path = @dir }.should raise_error(ArgumentError)
- end
-
- it "should fail if the path is not readable" do
- FileTest.expects(:directory?).returns(true)
- FileTest.expects(:readable?).returns(false)
- proc { @mount.path = @dir }.should raise_error(ArgumentError)
- end
-end
-
-describe Puppet::FileServing::Mount::File, " when substituting hostnames and ip addresses into file paths" do
- include FileServingMountTesting
-
- before do
- FileTest.stubs(:directory?).returns(true)
- FileTest.stubs(:readable?).returns(true)
- @mount = Puppet::FileServing::Mount::File.new("test")
- @host = "host.domain.com"
- end
-
- it "should replace incidences of %h in the path with the client's short name" do
- @mount.path = "/dir/%h/yay"
- @mount.path(@host).should == "/dir/host/yay"
- end
-
- it "should replace incidences of %H in the path with the client's fully qualified name" do
- @mount.path = "/dir/%H/yay"
- @mount.path(@host).should == "/dir/host.domain.com/yay"
- end
-
- it "should replace incidences of %d in the path with the client's domain name" do
- @mount.path = "/dir/%d/yay"
- @mount.path(@host).should == "/dir/domain.com/yay"
- end
-
- it "should perform all necessary replacements" do
- @mount.path = "/%h/%d/%H"
- @mount.path(@host).should == "/host/domain.com/host.domain.com"
- end
-
- it "should use local host information if no client data is provided" do
- stub_facter("myhost.mydomain.com")
- @mount.path = "/%h/%d/%H"
- @mount.path.should == "/myhost/mydomain.com/myhost.mydomain.com"
- end
-
- after do
- Puppet::Util::Cacher.expire
- end
-end
-
-describe Puppet::FileServing::Mount::File, "when determining the complete file path" do
- include FileServingMountTesting
-
- before do
- FileTest.stubs(:exist?).returns(true)
- FileTest.stubs(:directory?).returns(true)
- FileTest.stubs(:readable?).returns(true)
- @mount = Puppet::FileServing::Mount::File.new("test")
- @mount.path = "/mount"
- stub_facter("myhost.mydomain.com")
- @host = "host.domain.com"
- end
-
- it "should return nil if the file is absent" do
- FileTest.stubs(:exist?).returns(false)
- @mount.complete_path("/my/path", nil).should be_nil
- end
-
- it "should write a log message if the file is absent" do
- FileTest.stubs(:exist?).returns(false)
-
- Puppet.expects(:info).with("File does not exist or is not accessible: /mount/my/path")
-
- @mount.complete_path("/my/path", nil)
- end
-
- it "should return the file path if the file is present" do
- FileTest.stubs(:exist?).with("/my/path").returns(true)
- @mount.complete_path("/my/path", nil).should == "/mount/my/path"
- end
-
- it "should treat a nil file name as the path to the mount itself" do
- FileTest.stubs(:exist?).returns(true)
- @mount.complete_path(nil, nil).should == "/mount"
- end
-
- it "should use the client host name if provided in the options" do
- @mount.path = "/mount/%h"
- @mount.complete_path("/my/path", @host).should == "/mount/host/my/path"
- end
-
- it "should perform replacements on the base path" do
- @mount.path = "/blah/%h"
- @mount.complete_path("/my/stuff", @host).should == "/blah/host/my/stuff"
- end
-
- it "should not perform replacements on the per-file path" do
- @mount.path = "/blah"
- @mount.complete_path("/%h/stuff", @host).should == "/blah/%h/stuff"
- end
-
- it "should look for files relative to its base directory" do
- @mount.complete_path("/my/stuff", @host).should == "/mount/my/stuff"
- end
-end
-
-describe Puppet::FileServing::Mount::File, "when finding files" do
- include FileServingMountTesting
-
- before do
- FileTest.stubs(:exist?).returns(true)
- FileTest.stubs(:directory?).returns(true)
- FileTest.stubs(:readable?).returns(true)
- @mount = Puppet::FileServing::Mount::File.new("test")
- @mount.path = "/mount"
- stub_facter("myhost.mydomain.com")
- @host = "host.domain.com"
-
- @request = stub 'request', :node => "foo"
- end
-
- it "should return the results of the complete file path" do
- FileTest.stubs(:exist?).returns(false)
- @mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
- @mount.find("/my/path", @request).should == "eh"
- end
-end
-
-describe Puppet::FileServing::Mount::File, "when searching for files" do
- include FileServingMountTesting
-
- before do
- FileTest.stubs(:exist?).returns(true)
- FileTest.stubs(:directory?).returns(true)
- FileTest.stubs(:readable?).returns(true)
- @mount = Puppet::FileServing::Mount::File.new("test")
- @mount.path = "/mount"
- stub_facter("myhost.mydomain.com")
- @host = "host.domain.com"
-
- @request = stub 'request', :node => "foo"
- end
-
- it "should return the results of the complete file path as an array" do
- FileTest.stubs(:exist?).returns(false)
- @mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
- @mount.search("/my/path", @request).should == ["eh"]
- end
- it "should return nil if the complete path is nil" do
- FileTest.stubs(:exist?).returns(false)
- @mount.expects(:complete_path).with("/my/path", "foo").returns nil
- @mount.search("/my/path", @request).should be_nil
+ describe "when setting the path" do
+ before do
+ @mount = Puppet::FileServing::Mount::File.new("test")
+ @dir = "/this/path/does/not/exist"
+ end
+
+ it "should fail if the path is not a directory" do
+ FileTest.expects(:directory?).returns(false)
+ proc { @mount.path = @dir }.should raise_error(ArgumentError)
+ end
+
+ it "should fail if the path is not readable" do
+ FileTest.expects(:directory?).returns(true)
+ FileTest.expects(:readable?).returns(false)
+ proc { @mount.path = @dir }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "when substituting hostnames and ip addresses into file paths" do
+ include FileServingMountTesting
+
+ before do
+ FileTest.stubs(:directory?).returns(true)
+ FileTest.stubs(:readable?).returns(true)
+ @mount = Puppet::FileServing::Mount::File.new("test")
+ @host = "host.domain.com"
+ end
+
+ after :each do
+ Puppet::FileServing::Mount::File.instance_variable_set(:@localmap, nil)
+ end
+
+ it "should replace incidences of %h in the path with the client's short name" do
+ @mount.path = "/dir/%h/yay"
+ @mount.path(@host).should == "/dir/host/yay"
+ end
+
+ it "should replace incidences of %H in the path with the client's fully qualified name" do
+ @mount.path = "/dir/%H/yay"
+ @mount.path(@host).should == "/dir/host.domain.com/yay"
+ end
+
+ it "should replace incidences of %d in the path with the client's domain name" do
+ @mount.path = "/dir/%d/yay"
+ @mount.path(@host).should == "/dir/domain.com/yay"
+ end
+
+ it "should perform all necessary replacements" do
+ @mount.path = "/%h/%d/%H"
+ @mount.path(@host).should == "/host/domain.com/host.domain.com"
+ end
+
+ it "should use local host information if no client data is provided" do
+ stub_facter("myhost.mydomain.com")
+ @mount.path = "/%h/%d/%H"
+ @mount.path.should == "/myhost/mydomain.com/myhost.mydomain.com"
+ end
+ end
+
+ describe "when determining the complete file path" do
+ include FileServingMountTesting
+
+ before do
+ FileTest.stubs(:exist?).returns(true)
+ FileTest.stubs(:directory?).returns(true)
+ FileTest.stubs(:readable?).returns(true)
+ @mount = Puppet::FileServing::Mount::File.new("test")
+ @mount.path = "/mount"
+ stub_facter("myhost.mydomain.com")
+ @host = "host.domain.com"
+ end
+
+ it "should return nil if the file is absent" do
+ FileTest.stubs(:exist?).returns(false)
+ @mount.complete_path("/my/path", nil).should be_nil
+ end
+
+ it "should write a log message if the file is absent" do
+ FileTest.stubs(:exist?).returns(false)
+
+ Puppet.expects(:info).with("File does not exist or is not accessible: /mount/my/path")
+
+ @mount.complete_path("/my/path", nil)
+ end
+
+ it "should return the file path if the file is present" do
+ FileTest.stubs(:exist?).with("/my/path").returns(true)
+ @mount.complete_path("/my/path", nil).should == "/mount/my/path"
+ end
+
+ it "should treat a nil file name as the path to the mount itself" do
+ FileTest.stubs(:exist?).returns(true)
+ @mount.complete_path(nil, nil).should == "/mount"
+ end
+
+ it "should use the client host name if provided in the options" do
+ @mount.path = "/mount/%h"
+ @mount.complete_path("/my/path", @host).should == "/mount/host/my/path"
+ end
+
+ it "should perform replacements on the base path" do
+ @mount.path = "/blah/%h"
+ @mount.complete_path("/my/stuff", @host).should == "/blah/host/my/stuff"
+ end
+
+ it "should not perform replacements on the per-file path" do
+ @mount.path = "/blah"
+ @mount.complete_path("/%h/stuff", @host).should == "/blah/%h/stuff"
+ end
+
+ it "should look for files relative to its base directory" do
+ @mount.complete_path("/my/stuff", @host).should == "/mount/my/stuff"
+ end
+ end
+
+ describe "when finding files" do
+ include FileServingMountTesting
+
+ before do
+ FileTest.stubs(:exist?).returns(true)
+ FileTest.stubs(:directory?).returns(true)
+ FileTest.stubs(:readable?).returns(true)
+ @mount = Puppet::FileServing::Mount::File.new("test")
+ @mount.path = "/mount"
+ stub_facter("myhost.mydomain.com")
+ @host = "host.domain.com"
+
+ @request = stub 'request', :node => "foo"
+ end
+
+ it "should return the results of the complete file path" do
+ FileTest.stubs(:exist?).returns(false)
+ @mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
+ @mount.find("/my/path", @request).should == "eh"
+ end
+ end
+
+ describe "when searching for files" do
+ include FileServingMountTesting
+
+ before do
+ FileTest.stubs(:exist?).returns(true)
+ FileTest.stubs(:directory?).returns(true)
+ FileTest.stubs(:readable?).returns(true)
+ @mount = Puppet::FileServing::Mount::File.new("test")
+ @mount.path = "/mount"
+ stub_facter("myhost.mydomain.com")
+ @host = "host.domain.com"
+
+ @request = stub 'request', :node => "foo"
+ end
+
+ it "should return the results of the complete file path as an array" do
+ FileTest.stubs(:exist?).returns(false)
+ @mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
+ @mount.search("/my/path", @request).should == ["eh"]
+ end
+
+ it "should return nil if the complete path is nil" do
+ FileTest.stubs(:exist?).returns(false)
+ @mount.expects(:complete_path).with("/my/path", "foo").returns nil
+ @mount.search("/my/path", @request).should be_nil
+ end
end
end
diff --git a/spec/unit/indirector/certificate_request/ca_spec.rb b/spec/unit/indirector/certificate_request/ca_spec.rb
index 028bc94c6..9c74f09d1 100755
--- a/spec/unit/indirector/certificate_request/ca_spec.rb
+++ b/spec/unit/indirector/certificate_request/ca_spec.rb
@@ -6,7 +6,7 @@ require 'puppet/sslcertificates'
require 'puppet/sslcertificates/ca'
require 'puppet/indirector/certificate_request/ca'
-describe Puppet::SSL::CertificateRequest::Ca do
+describe Puppet::SSL::CertificateRequest::Ca, :unless => Puppet.features.microsoft_windows? do
include PuppetSpec::Files
before :each do
diff --git a/spec/unit/indirector/certificate_status/file_spec.rb b/spec/unit/indirector/certificate_status/file_spec.rb
index 5451913a1..c5d4e283f 100755
--- a/spec/unit/indirector/certificate_status/file_spec.rb
+++ b/spec/unit/indirector/certificate_status/file_spec.rb
@@ -4,7 +4,7 @@ require 'puppet/ssl/host'
require 'puppet/indirector/certificate_status'
require 'tempfile'
-describe "Puppet::Indirector::CertificateStatus::File" do
+describe "Puppet::Indirector::CertificateStatus::File", :fails_on_windows => true do
include PuppetSpec::Files
before :all do
diff --git a/spec/unit/indirector/file_bucket_file/file_spec.rb b/spec/unit/indirector/file_bucket_file/file_spec.rb
index e0612cb21..808da17d8 100755
--- a/spec/unit/indirector/file_bucket_file/file_spec.rb
+++ b/spec/unit/indirector/file_bucket_file/file_spec.rb
@@ -111,7 +111,7 @@ describe Puppet::FileBucketFile::File do
end
end
- describe "when diffing files" do
+ describe "when diffing files", :unless => Puppet.features.microsoft_windows? do
it "should generate an empty string if there is no diff" do
checksum = save_bucket_file("I'm the contents of a file")
Puppet::FileBucket::File.indirection.find("md5/#{checksum}", :diff_with => checksum).should == ''
@@ -243,11 +243,11 @@ HERE
describe "when verifying identical files" do
before do
# this is the default from spec_helper, but it keeps getting reset at odd times
- Puppet[:bucketdir] = "/dev/null/bucket"
+ Puppet[:bucketdir] = make_absolute("/dev/null/bucket")
@digest = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
@checksum = "{md5}4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
- @dir = '/dev/null/bucket/4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0'
+ @dir = make_absolute('/dev/null/bucket/4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0')
@contents = "file contents"
diff --git a/spec/unit/indirector/file_server_spec.rb b/spec/unit/indirector/file_server_spec.rb
index b0227772b..8f7a5d1b3 100755
--- a/spec/unit/indirector/file_server_spec.rb
+++ b/spec/unit/indirector/file_server_spec.rb
@@ -23,7 +23,7 @@ describe Puppet::Indirector::FileServer do
@uri = "puppet://host/my/local/file"
@configuration = mock 'configuration'
- Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
+ Puppet::FileServing::Configuration.stubs(:configuration).returns(@configuration)
@request = Puppet::Indirector::Request.new(:myind, :mymethod, @uri, :environment => "myenv")
end
diff --git a/spec/unit/indirector/indirection_spec.rb b/spec/unit/indirector/indirection_spec.rb
index 4bbc855b1..c33fdf165 100755
--- a/spec/unit/indirector/indirection_spec.rb
+++ b/spec/unit/indirector/indirection_spec.rb
@@ -102,9 +102,6 @@ shared_examples_for "Delegation Authorizer" do
end
describe Puppet::Indirector::Indirection do
- after do
- Puppet::Util::Cacher.expire
- end
describe "when initializing" do
# (LAK) I've no idea how to test this, really.
it "should store a reference to itself before it consumes its options" do
@@ -643,7 +640,6 @@ describe Puppet::Indirector::Indirection do
after :each do
@indirection.delete
- Puppet::Util::Cacher.expire
end
end
diff --git a/spec/unit/indirector/resource/ral_spec.rb b/spec/unit/indirector/resource/ral_spec.rb
index cf746cb0c..e38745f05 100755
--- a/spec/unit/indirector/resource/ral_spec.rb
+++ b/spec/unit/indirector/resource/ral_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
describe "Puppet::Resource::Ral" do
- describe "find" do
+ describe "find", :fails_on_windows => true do
before do
@request = stub 'request', :key => "user/root"
end
diff --git a/spec/unit/indirector/resource_type/parser_spec.rb b/spec/unit/indirector/resource_type/parser_spec.rb
index c4fc455a0..67ea73fd6 100755
--- a/spec/unit/indirector/resource_type/parser_spec.rb
+++ b/spec/unit/indirector/resource_type/parser_spec.rb
@@ -25,7 +25,7 @@ describe Puppet::Indirector::ResourceType::Parser do
@terminus.find(@request).should == type
end
- it "should attempt to load the type if none is found in memory" do
+ it "should attempt to load the type if none is found in memory", :fails_on_windows => true do
dir = tmpdir("find_a_type")
FileUtils.mkdir_p(dir)
Puppet[:modulepath] = dir
@@ -122,13 +122,13 @@ describe Puppet::Indirector::ResourceType::Parser do
@terminus.search(@request).should be_nil
end
- it "should load all resource types from all search paths" do
+ it "should load all resource types from all search paths", :fails_on_windows => true do
dir = tmpdir("searching_in_all")
first = File.join(dir, "first")
second = File.join(dir, "second")
FileUtils.mkdir_p(first)
FileUtils.mkdir_p(second)
- Puppet[:modulepath] = "#{first}:#{second}"
+ Puppet[:modulepath] = "#{first}#{File::PATH_SEPARATOR}#{second}"
# Make a new request, since we've reset the env
@request = Puppet::Indirector::Request.new(:resource_type, :search, "*")
diff --git a/spec/unit/indirector/ssl_file_spec.rb b/spec/unit/indirector/ssl_file_spec.rb
index ae188317f..e0e30bd9d 100755
--- a/spec/unit/indirector/ssl_file_spec.rb
+++ b/spec/unit/indirector/ssl_file_spec.rb
@@ -4,6 +4,8 @@ require 'spec_helper'
require 'puppet/indirector/ssl_file'
describe Puppet::Indirector::SslFile do
+ include PuppetSpec::Files
+
before :all do
@indirection = stub 'indirection', :name => :testing, :model => @model
Puppet::Indirector::Indirection.expects(:instance).with(:testing).returns(@indirection)
@@ -17,7 +19,7 @@ describe Puppet::Indirector::SslFile do
@setting = :certdir
@file_class.store_in @setting
- @path = "/tmp/my_directory"
+ @path = make_absolute("/tmp/my_directory")
Puppet[:noop] = false
Puppet[@setting] = @path
Puppet[:trace] = false
diff --git a/spec/unit/module_spec.rb b/spec/unit/module_spec.rb
index 822c76296..a0f64c6d3 100755
--- a/spec/unit/module_spec.rb
+++ b/spec/unit/module_spec.rb
@@ -275,7 +275,7 @@ describe Puppet::Module do
FileUtils.mkdir_p(first)
FileUtils.mkdir_p(second)
- Puppet[:modulepath] = "#{first}:#{second}"
+ Puppet[:modulepath] = "#{first}#{File::PATH_SEPARATOR}#{second}"
modpath = File.join(first, "foo")
FileUtils.mkdir_p(modpath)
@@ -294,7 +294,7 @@ describe Puppet::Module do
FileUtils.mkdir_p(first)
FileUtils.mkdir_p(second)
- Puppet[:modulepath] = "#{first}:#{second}"
+ Puppet[:modulepath] = "#{first}#{File::PATH_SEPARATOR}#{second}"
modpath = File.join(second, "foo")
FileUtils.mkdir_p(modpath)
diff --git a/spec/unit/network/client_spec.rb b/spec/unit/network/client_spec.rb
deleted file mode 100755
index 861f33033..000000000
--- a/spec/unit/network/client_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env rspec
-require 'spec_helper'
-
-require 'puppet/network/client'
-
-describe Puppet::Network::Client do
- before do
- Puppet.settings.stubs(:use).returns(true)
- Puppet::Network::HttpPool.stubs(:cert_setup)
- end
-
- describe "when keep-alive is enabled" do
- before do
- Puppet::Network::HttpPool.stubs(:keep_alive?).returns true
- end
- it "should start the http client up on creation" do
- http = mock 'http'
- http.stub_everything
- http.expects(:start)
- Net::HTTP.stubs(:new).returns http
-
- # Pick a random subclass...
- Puppet::Network::Client.runner.new :Server => Puppet[:server]
- end
- end
-
- describe "when keep-alive is disabled" do
- before do
- Puppet::Network::HttpPool.stubs(:keep_alive?).returns false
- end
- it "should not start the http client up on creation" do
- http = mock 'http'
- http.stub_everything
- http.expects(:start).never
- Net::HTTP.stubs(:new).returns http
-
- # Pick a random subclass...
- Puppet::Network::Client.runner.new :Server => Puppet[:server]
- end
- end
-end
diff --git a/spec/unit/network/handler/fileserver_spec.rb b/spec/unit/network/handler/fileserver_spec.rb
index 851736e76..2b8094b8b 100755
--- a/spec/unit/network/handler/fileserver_spec.rb
+++ b/spec/unit/network/handler/fileserver_spec.rb
@@ -73,12 +73,12 @@ describe Puppet::Network::Handler::FileServer do
@mount.list("/no_such_file", false, false).should be(nil)
end
- it "should list a symbolic link as a file when given the link path" do
+ it "should list a symbolic link as a file when given the link path", :unless => Puppet.features.microsoft_windows? do
File.symlink(@file, @link)
@mount.list("/aLink", false, false).should == [["/", "file"]]
end
- it "should return nil for a dangling symbolic link when given the link path" do
+ it "should return nil for a dangling symbolic link when given the link path", :unless => Puppet.features.microsoft_windows? do
File.symlink("/some/where", @link)
@mount.list("/aLink", false, false).should be(nil)
end
@@ -138,18 +138,18 @@ describe Puppet::Network::Handler::FileServer do
list.sort.should == [ ["/aFile", "file"], ["/", "directory"] , ["/nested_dir", "directory"], ["/nested_dir/nested_dir_file", "file"]].sort
end
- it "should list a valid symbolic link as a file when recursing base dir" do
+ it "should list a valid symbolic link as a file when recursing base dir", :unless => Puppet.features.microsoft_windows? do
File.symlink(@file, @link)
list = @mount.list("/", true, false)
list.sort.should == [ ["/", "directory"], ["/aFile", "file"], ["/aLink", "file"] ].sort
end
- it "should not error when a dangling symlink is present" do
+ it "should not error when a dangling symlink is present", :unless => Puppet.features.microsoft_windows? do
File.symlink("/some/where", @link)
lambda { @mount.list("/", true, false) }.should_not raise_error
end
- it "should return the directory contents of valid entries when a dangling symlink is present" do
+ it "should return the directory contents of valid entries when a dangling symlink is present", :unless => Puppet.features.microsoft_windows? do
File.symlink("/some/where", @link)
list = @mount.list("/", true, false)
list.sort.should == [ ["/aFile", "file"], ["/", "directory"] ].sort
diff --git a/spec/unit/network/http/webrick_spec.rb b/spec/unit/network/http/webrick_spec.rb
index 72660efda..f84e78e24 100755
--- a/spec/unit/network/http/webrick_spec.rb
+++ b/spec/unit/network/http/webrick_spec.rb
@@ -4,13 +4,13 @@ require 'puppet/network/handler'
require 'puppet/network/http'
require 'puppet/network/http/webrick'
-describe Puppet::Network::HTTP::WEBrick, "after initializing" do
+describe Puppet::Network::HTTP::WEBrick, "after initializing", :unless => Puppet.features.microsoft_windows? do
it "should not be listening" do
Puppet::Network::HTTP::WEBrick.new.should_not be_listening
end
end
-describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
+describe Puppet::Network::HTTP::WEBrick, "when turning on listening", :unless => Puppet.features.microsoft_windows? do
before do
@mock_webrick = stub('webrick', :[] => {}, :listeners => [], :status => :Running)
[:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)}
@@ -139,7 +139,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
end
-describe Puppet::Network::HTTP::WEBrick, "when looking up the class to handle a protocol" do
+describe Puppet::Network::HTTP::WEBrick, "when looking up the class to handle a protocol", :unless => Puppet.features.microsoft_windows? do
it "should require a protocol" do
lambda { Puppet::Network::HTTP::WEBrick.class_for_protocol }.should raise_error(ArgumentError)
end
@@ -157,7 +157,7 @@ describe Puppet::Network::HTTP::WEBrick, "when looking up the class to handle a
end
end
-describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
+describe Puppet::Network::HTTP::WEBrick, "when turning off listening", :unless => Puppet.features.microsoft_windows? do
before do
@mock_webrick = stub('webrick', :[] => {}, :listeners => [], :status => :Running)
[:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)}
@@ -184,7 +184,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
end
end
-describe Puppet::Network::HTTP::WEBrick do
+describe Puppet::Network::HTTP::WEBrick, :unless => Puppet.features.microsoft_windows? do
before do
@mock_webrick = stub('webrick', :[] => {})
[:mount, :start, :shutdown].each {|meth| @mock_webrick.stubs(meth)}
diff --git a/spec/unit/network/http_pool_spec.rb b/spec/unit/network/http_pool_spec.rb
index 41105ece9..c86f7a660 100755
--- a/spec/unit/network/http_pool_spec.rb
+++ b/spec/unit/network/http_pool_spec.rb
@@ -4,15 +4,9 @@ require 'puppet/network/http_pool'
describe Puppet::Network::HttpPool do
after do
- Puppet::Util::Cacher.expire
- Puppet::Network::HttpPool.clear_http_instances
Puppet::Network::HttpPool.instance_variable_set("@ssl_host", nil)
end
- it "should have keep-alive disabled" do
- Puppet::Network::HttpPool::HTTP_KEEP_ALIVE.should be_false
- end
-
it "should use the global SSL::Host instance to get its certificate information" do
host = mock 'host'
Puppet::SSL::Host.expects(:localhost).with.returns host
@@ -54,71 +48,10 @@ describe Puppet::Network::HttpPool do
Puppet::Network::HttpPool.http_instance("me", 54321).open_timeout.should == 120
end
- describe "and http keep-alive is enabled" do
- before do
- Puppet::Network::HttpPool.stubs(:keep_alive?).returns true
- end
-
- it "should cache http instances" do
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
- old = Puppet::Network::HttpPool.http_instance("me", 54321)
- Puppet::Network::HttpPool.http_instance("me", 54321).should equal(old)
- end
-
- it "should have a mechanism for getting a new http instance instead of the cached instance" do
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
- old = Puppet::Network::HttpPool.http_instance("me", 54321)
- Puppet::Network::HttpPool.http_instance("me", 54321, true).should_not equal(old)
- end
-
- it "should close existing, open connections when requesting a new connection" do
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
- old = Puppet::Network::HttpPool.http_instance("me", 54321)
- old.expects(:started?).returns(true)
- old.expects(:finish)
- Puppet::Network::HttpPool.http_instance("me", 54321, true)
- end
-
- it "should have a mechanism for clearing the http cache" do
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
- old = Puppet::Network::HttpPool.http_instance("me", 54321)
- Puppet::Network::HttpPool.http_instance("me", 54321).should equal(old)
- old = Puppet::Network::HttpPool.http_instance("me", 54321)
- Puppet::Network::HttpPool.clear_http_instances
- Puppet::Network::HttpPool.http_instance("me", 54321).should_not equal(old)
- end
-
- it "should close open http connections when clearing the cache" do
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
- one = Puppet::Network::HttpPool.http_instance("me", 54321)
- one.expects(:started?).returns(true)
- one.expects(:finish).returns(true)
- Puppet::Network::HttpPool.clear_http_instances
- end
-
- it "should not close unopened http connections when clearing the cache" do
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
- one = Puppet::Network::HttpPool.http_instance("me", 54321)
- one.expects(:started?).returns(false)
- one.expects(:finish).never
- Puppet::Network::HttpPool.clear_http_instances
- end
- end
-
- describe "and http keep-alive is disabled" do
- before do
- Puppet::Network::HttpPool.stubs(:keep_alive?).returns false
- end
-
- it "should not cache http instances" do
- stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
- old = Puppet::Network::HttpPool.http_instance("me", 54321)
- Puppet::Network::HttpPool.http_instance("me", 54321).should_not equal(old)
- end
- end
-
- after do
- Puppet::Network::HttpPool.clear_http_instances
+ it "should not cache http instances" do
+ stub_settings :http_proxy_host => "myhost", :http_proxy_port => 432, :configtimeout => 120
+ old = Puppet::Network::HttpPool.http_instance("me", 54321)
+ Puppet::Network::HttpPool.http_instance("me", 54321).should_not equal(old)
end
end
diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb
index d1badfa3a..79c21248d 100755
--- a/spec/unit/node/environment_spec.rb
+++ b/spec/unit/node/environment_spec.rb
@@ -1,6 +1,8 @@
#!/usr/bin/env rspec
require 'spec_helper'
+require 'tmpdir'
+
require 'puppet/node/environment'
require 'puppet/util/execution'
@@ -10,10 +12,6 @@ describe Puppet::Node::Environment do
Puppet::Node::Environment.clear
end
- it "should include the Cacher module" do
- Puppet::Node::Environment.ancestors.should be_include(Puppet::Util::Cacher)
- end
-
it "should use the filetimeout for the ttl for the modulepath" do
Puppet::Node::Environment.attr_ttl(:modulepath).should == Integer(Puppet[:filetimeout])
end
@@ -22,10 +20,6 @@ describe Puppet::Node::Environment do
Puppet::Node::Environment.attr_ttl(:modules).should == Integer(Puppet[:filetimeout])
end
- it "should use the filetimeout for the ttl for the manifestdir" do
- Puppet::Node::Environment.attr_ttl(:manifestdir).should == Integer(Puppet[:filetimeout])
- end
-
it "should use the default environment if no name is provided while initializing an environment" do
Puppet.settings.expects(:value).with(:environment).returns("one")
Puppet::Node::Environment.new.name.should == :one
@@ -109,27 +103,15 @@ describe Puppet::Node::Environment do
end
end
- [:modulepath, :manifestdir].each do |setting|
- it "should validate the #{setting} directories" do
- path = %w{/one /two}.join(File::PATH_SEPARATOR)
-
- env = Puppet::Node::Environment.new("testing")
- env.stubs(:[]).with(setting).returns path
-
- env.expects(:validate_dirs).with(%w{/one /two})
-
- env.send(setting)
- end
+ it "should validate the modulepath directories" do
+ real_file = Dir.mktmpdir
+ path = %W[/one /two #{real_file}].join(File::PATH_SEPARATOR)
- it "should return the validated dirs for #{setting}" do
- path = %w{/one /two}.join(File::PATH_SEPARATOR)
+ Puppet[:modulepath] = path
- env = Puppet::Node::Environment.new("testing")
- env.stubs(:[]).with(setting).returns path
- env.stubs(:validate_dirs).returns %w{/one /two}
+ env = Puppet::Node::Environment.new("testing")
- env.send(setting).should == %w{/one /two}
- end
+ env.modulepath.should == [real_file]
end
it "should prefix the value of the 'PUPPETLIB' environment variable to the module path if present" do
@@ -144,21 +126,26 @@ describe Puppet::Node::Environment do
end
describe "when validating modulepath or manifestdir directories" do
+ before :each do
+ @path_one = make_absolute('/one')
+ @path_two = make_absolute('/two')
+ end
+
it "should not return non-directories" do
env = Puppet::Node::Environment.new("testing")
- FileTest.expects(:directory?).with("/one").returns true
- FileTest.expects(:directory?).with("/two").returns false
+ FileTest.expects(:directory?).with(@path_one).returns true
+ FileTest.expects(:directory?).with(@path_two).returns false
- env.validate_dirs(%w{/one /two}).should == %w{/one}
+ env.validate_dirs([@path_one, @path_two]).should == [@path_one]
end
it "should use the current working directory to fully-qualify unqualified paths" do
FileTest.stubs(:directory?).returns true
env = Puppet::Node::Environment.new("testing")
- two = File.join(Dir.getwd, "two")
- env.validate_dirs(%w{/one two}).should == ["/one", two]
+ two = File.expand_path(File.join(Dir.getwd, "two"))
+ env.validate_dirs([@path_one, 'two']).should == [@path_one, two]
end
end
diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb
index efaa76e12..4514607be 100755
--- a/spec/unit/node/facts_spec.rb
+++ b/spec/unit/node/facts_spec.rb
@@ -68,10 +68,6 @@ describe Puppet::Node::Facts, "when indirecting" do
before do
@indirection = stub 'indirection', :request => mock('request'), :name => :facts
- # We have to clear the cache so that the facts ask for our indirection stub,
- # instead of anything that might be cached.
- Puppet::Util::Cacher.expire
-
@facts = Puppet::Node::Facts.new("me", "one" => "two")
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 339054d55..33bb4d1b2 100755
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -132,8 +132,6 @@ describe Puppet::Node, "when indirecting" do
Puppet::Node.indirection.reset_terminus_class
Puppet::Node.indirection.terminus_class.should == :plain
-
- Puppet::Util::Cacher.expire
end
end
diff --git a/spec/unit/other/selinux_spec.rb b/spec/unit/other/selinux_spec.rb
index 216feaf1f..f20951868 100755
--- a/spec/unit/other/selinux_spec.rb
+++ b/spec/unit/other/selinux_spec.rb
@@ -5,11 +5,13 @@ require 'puppet/type/selboolean'
require 'puppet/type/selmodule'
describe Puppet::Type.type(:file), " when manipulating file contexts" do
+ include PuppetSpec::Files
+
before :each do
@file = Puppet::Type::File.new(
- :name => "/tmp/foo",
+ :name => make_absolute("/tmp/foo"),
:ensure => "file",
:seluser => "user_u",
:selrole => "role_r",
diff --git a/spec/unit/parameter_spec.rb b/spec/unit/parameter_spec.rb
index 04556c013..1ed211957 100755
--- a/spec/unit/parameter_spec.rb
+++ b/spec/unit/parameter_spec.rb
@@ -25,16 +25,6 @@ describe Puppet::Parameter do
@parameter.to_s.should == @parameter.name.to_s
end
- it "should be able to use cached attributes" do
- Puppet::Parameter.ancestors.should be_include(Puppet::Util::Cacher)
- end
-
- it "should use the resource catalog for expiration" do
- catalog = mock 'catalog'
- @resource.stubs(:catalog).returns catalog
- @parameter.expirer.should equal(catalog)
- end
-
[:line, :file, :version].each do |data|
it "should return its resource's #{data} as its #{data}" do
@resource.expects(data).returns "foo"
diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb
index fcce9f6f4..2478d2792 100755
--- a/spec/unit/parser/compiler_spec.rb
+++ b/spec/unit/parser/compiler_spec.rb
@@ -43,6 +43,8 @@ class CompilerTestResource
end
describe Puppet::Parser::Compiler do
+ include PuppetSpec::Files
+
def resource(type, title)
Puppet::Parser::Resource.new(type, title, :scope => @scope)
end
@@ -413,7 +415,7 @@ describe Puppet::Parser::Compiler do
end
it "should fail to add resources that conflict with existing resources" do
- path = Puppet.features.posix? ? "/foo" : "C:/foo"
+ path = make_absolute("/foo")
file1 = Puppet::Type.type(:file).new :path => path
file2 = Puppet::Type.type(:file).new :path => path
diff --git a/spec/unit/parser/files_spec.rb b/spec/unit/parser/files_spec.rb
index 04777f0ec..1bf75e623 100755
--- a/spec/unit/parser/files_spec.rb
+++ b/spec/unit/parser/files_spec.rb
@@ -4,9 +4,10 @@ require 'spec_helper'
require 'puppet/parser/files'
describe Puppet::Parser::Files do
+ include PuppetSpec::Files
before do
- @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath"
+ @basepath = make_absolute("/somepath")
end
it "should have a method for finding a template" do
@@ -77,8 +78,9 @@ describe Puppet::Parser::Files do
it "should accept relative templatedirs" do
FileTest.stubs(:exist?).returns true
Puppet[:templatedir] = "my/templates"
- File.expects(:directory?).with(File.join(Dir.getwd,"my/templates")).returns(true)
- Puppet::Parser::Files.find_template("mytemplate").should == File.join(Dir.getwd,"my/templates/mytemplate")
+ # We expand_path to normalize backslashes and slashes on Windows
+ File.expects(:directory?).with(File.expand_path(File.join(Dir.getwd,"my/templates"))).returns(true)
+ Puppet::Parser::Files.find_template("mytemplate").should == File.expand_path(File.join(Dir.getwd,"my/templates/mytemplate"))
end
it "should use the environment templatedir if no module is found and an environment is specified" do
@@ -158,7 +160,8 @@ describe Puppet::Parser::Files do
end
it "should look for files relative to the current directory" do
- cwd = Dir.getwd
+ # We expand_path to normalize backslashes and slashes on Windows
+ cwd = File.expand_path(Dir.getwd)
Dir.expects(:glob).with("#{cwd}/foobar/init.pp").returns(["#{cwd}/foobar/init.pp"])
Puppet::Parser::Files.find_manifests("foobar/init.pp")[1].should == ["#{cwd}/foobar/init.pp"]
end
diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb
index f68daaf3f..486e7cb98 100755
--- a/spec/unit/parser/functions/extlookup_spec.rb
+++ b/spec/unit/parser/functions/extlookup_spec.rb
@@ -3,6 +3,8 @@ require 'spec_helper'
require 'tempfile'
describe "the extlookup function" do
+ include PuppetSpec::Files
+
before :all do
Puppet::Parser::Functions.autoloader.loadall
end
@@ -64,9 +66,10 @@ describe "the extlookup function" do
describe "should look in $extlookup_datadir for data files listed by $extlookup_precedence" do
before do
- @scope.stubs(:lookupvar).with('::extlookup_datadir').returns("/tmp")
- File.open("/tmp/one.csv","w"){|one| one.puts "key,value1" }
- File.open("/tmp/two.csv","w") do |two|
+ dir = tmpdir('extlookup_datadir')
+ @scope.stubs(:lookupvar).with('::extlookup_datadir').returns(dir)
+ File.open(File.join(dir, "one.csv"),"w"){|one| one.puts "key,value1" }
+ File.open(File.join(dir, "two.csv"),"w") do |two|
two.puts "key,value2"
two.puts "key2,value_two"
end
diff --git a/spec/unit/parser/functions/sprintf_spec.rb b/spec/unit/parser/functions/sprintf_spec.rb
index bd4863f23..3351c7fb3 100755
--- a/spec/unit/parser/functions/sprintf_spec.rb
+++ b/spec/unit/parser/functions/sprintf_spec.rb
@@ -30,7 +30,8 @@ describe "the sprintf function" do
it "should format large floats" do
result = @scope.function_sprintf(["%+.2e", "27182818284590451"])
- result.should(eql("+2.72e+16"))
+ str = Puppet.features.microsoft_windows? ? "+2.72e+016" : "+2.72e+16"
+ result.should(eql(str))
end
it "should perform more complex formatting" do
diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb
index 9367b61c8..8b139613a 100755
--- a/spec/unit/parser/type_loader_spec.rb
+++ b/spec/unit/parser/type_loader_spec.rb
@@ -56,8 +56,8 @@ describe Puppet::Parser::TypeLoader do
end
it "should use the directory of the current file if one is set" do
- Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:cwd] == "/current" }.returns ["modname", %w{one}]
- @loader.import("myfile", "/current/file")
+ Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:cwd] == make_absolute("/current") }.returns ["modname", %w{one}]
+ @loader.import("myfile", make_absolute("/current/file"))
end
it "should pass the environment when looking for files" do
@@ -71,15 +71,15 @@ describe Puppet::Parser::TypeLoader do
end
it "should parse each found file" do
- Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
- @loader.expects(:parse_file).with("/one").returns(Puppet::Parser::AST::Hostclass.new(''))
+ Puppet::Parser::Files.expects(:find_manifests).returns ["modname", [make_absolute("/one")]]
+ @loader.expects(:parse_file).with(make_absolute("/one")).returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.import("myfile")
end
it "should make each file qualified before attempting to parse it" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}]
- @loader.expects(:parse_file).with("/current/one").returns(Puppet::Parser::AST::Hostclass.new(''))
- @loader.import("myfile", "/current/file")
+ @loader.expects(:parse_file).with(make_absolute("/current/one")).returns(Puppet::Parser::AST::Hostclass.new(''))
+ @loader.import("myfile", make_absolute("/current/file"))
end
it "should not attempt to import files that have already been imported" do
@@ -102,7 +102,7 @@ describe Puppet::Parser::TypeLoader do
@modulebase2 = File.join(@base, "second")
FileUtils.mkdir_p(@modulebase2)
- Puppet[:modulepath] = "#{@modulebase1}:#{@modulebase2}"
+ Puppet[:modulepath] = "#{@modulebase1}#{File::PATH_SEPARATOR}#{@modulebase2}"
end
def mk_module(basedir, name)
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 7728b5d40..99d4bc7c5 100755
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -109,7 +109,7 @@ describe Puppet::Property do
end
end
- describe "when creating an event" do
+ describe "when creating an event", :fails_on_windows => true do
before do
@event = Puppet::Transaction::Event.new
diff --git a/spec/unit/provider/exec/shell_spec.rb b/spec/unit/provider/exec/shell_spec.rb
index 90047b9d6..62036a79c 100755
--- a/spec/unit/provider/exec/shell_spec.rb
+++ b/spec/unit/provider/exec/shell_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
provider_class = Puppet::Type.type(:exec).provider(:shell)
-describe provider_class do
+describe provider_class, :unless => Puppet.features.microsoft_windows? do
before :each do
@resource = Puppet::Resource.new(:exec, 'foo')
@provider = provider_class.new(@resource)
diff --git a/spec/unit/provider/group/windows_adsi_spec.rb b/spec/unit/provider/group/windows_adsi_spec.rb
new file mode 100644
index 000000000..7faaa1a8c
--- /dev/null
+++ b/spec/unit/provider/group/windows_adsi_spec.rb
@@ -0,0 +1,79 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+describe Puppet::Type.type(:group).provider(:windows_adsi) do
+ let(:resource) do
+ Puppet::Type.type(:group).new(
+ :title => 'testers',
+ :provider => :windows_adsi
+ )
+ end
+
+ let(:provider) { resource.provider }
+
+ let(:connection) { stub 'connection' }
+
+ before :each do
+ Puppet::Util::ADSI.stubs(:computer_name).returns('testcomputername')
+ Puppet::Util::ADSI.stubs(:connect).returns connection
+ end
+
+ describe ".instances" do
+ it "should enumerate all groups" do
+ names = ['group1', 'group2', 'group3']
+ stub_groups = names.map{|n| stub(:name => n)}
+
+ connection.stubs(:execquery).with("select * from win32_group").returns stub_groups
+
+ described_class.instances.map(&:name).should =~ names
+ end
+ end
+
+ describe "when managing members" do
+ it "should be able to provide a list of members" do
+ provider.group.stubs(:members).returns ['user1', 'user2', 'user3']
+
+ provider.members.should =~ ['user1', 'user2', 'user3']
+ end
+
+ it "should be able to set group members" do
+ provider.group.stubs(:members).returns ['user1', 'user2']
+
+ provider.group.expects(:remove_members).with('user1')
+ provider.group.expects(:add_members).with('user3')
+
+ provider.members = ['user2', 'user3']
+ end
+ end
+
+ it "should be able to create a group" do
+ resource[:members] = ['user1', 'user2']
+
+ group = stub 'group'
+ Puppet::Util::ADSI::Group.expects(:create).with('testers').returns group
+
+ group.expects(:set_members).with(['user1', 'user2'])
+
+ provider.create
+ end
+
+ it "should be able to test whether a group exists" do
+ Puppet::Util::ADSI.stubs(:connect).returns stub('connection')
+ provider.should be_exists
+
+ Puppet::Util::ADSI.stubs(:connect).returns nil
+ provider.should_not be_exists
+ end
+
+ it "should be able to delete a group" do
+ connection.expects(:Delete).with('group', 'testers')
+
+ provider.delete
+ end
+
+ it "should warn when trying to manage the gid property" do
+ provider.expects(:warning).with { |msg| msg =~ /No support for managing property gid/ }
+ provider.send(:gid=, 500)
+ end
+end
diff --git a/spec/unit/provider/macauthorization_spec.rb b/spec/unit/provider/macauthorization_spec.rb
index a76f917f7..dbe36a04b 100755
--- a/spec/unit/provider/macauthorization_spec.rb
+++ b/spec/unit/provider/macauthorization_spec.rb
@@ -106,6 +106,11 @@ describe provider_class do
end
it "should call the internal method set_right" do
+ @provider.expects(:execute).with { |cmds, args|
+ cmds.include?("read") and
+ cmds.include?(@authname) and
+ args[:combine] == false
+ }.once
@provider.expects(:set_right)
@provider.flush
end
diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb
index e812e3359..c86525707 100755
--- a/spec/unit/provider/mount/parsed_spec.rb
+++ b/spec/unit/provider/mount/parsed_spec.rb
@@ -4,7 +4,7 @@ require 'shared_behaviours/all_parsedfile_providers'
provider_class = Puppet::Type.type(:mount).provider(:parsed)
-describe provider_class do
+describe provider_class, :fails_on_windows => true do
before :each do
@mount_class = Puppet::Type.type(:mount)
diff --git a/spec/unit/provider/service/smf_spec.rb b/spec/unit/provider/service/smf_spec.rb
index 5212d540a..fd7d50e3a 100755
--- a/spec/unit/provider/service/smf_spec.rb
+++ b/spec/unit/provider/service/smf_spec.rb
@@ -111,6 +111,7 @@ describe provider_class do
it "should import the manifest if service is missing" do
@provider.expects(:svccfg).with(:import, "/tmp/myservice.xml")
@provider.expects(:texecute).with(:start, ["/usr/sbin/svcadm", :enable, "/system/myservice"], true)
+ @provider.expects(:svcs).with('-H', '-o', 'state,nstate', "/system/myservice").returns("online\t-")
@provider.start
end
diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb
new file mode 100755
index 000000000..07e4f4d1a
--- /dev/null
+++ b/spec/unit/provider/service/windows_spec.rb
@@ -0,0 +1,166 @@
+#!/usr/bin/env rspec
+#
+# Unit testing for the Windows service Provider
+#
+
+require 'spec_helper'
+
+require 'win32/service' if Puppet.features.microsoft_windows?
+
+describe Puppet::Type.type(:service).provider(:windows), :if => Puppet.features.microsoft_windows? do
+
+ before :each do
+ @resource = Puppet::Type.type(:service).new(:name => 'snmptrap', :provider => :windows)
+
+ @config = Struct::ServiceConfigInfo.new
+
+ @status = Struct::ServiceStatus.new
+
+ Win32::Service.stubs(:config_info).with(@resource[:name]).returns(@config)
+ Win32::Service.stubs(:status).with(@resource[:name]).returns(@status)
+ end
+
+ describe ".instances" do
+ it "should enumerate all services" do
+ list_of_services = ['snmptrap', 'svchost', 'sshd'].map { |s| stub('service', :service_name => s) }
+ Win32::Service.expects(:services).returns(list_of_services)
+
+ described_class.instances.map(&:name).should =~ ['snmptrap', 'svchost', 'sshd']
+ end
+ end
+
+ describe "#start" do
+ it "should call out to the Win32::Service API to start the service" do
+ @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START)
+
+ Win32::Service.expects(:start).with( @resource[:name] )
+
+ @resource.provider.start
+ end
+
+ it "should handle when Win32::Service.start raises a Win32::Service::Error" do
+ @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START)
+
+ Win32::Service.expects(:start).with( @resource[:name] ).raises(
+ Win32::Service::Error.new("The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.")
+ )
+
+ expect { @resource.provider.start }.to raise_error(
+ Puppet::Error,
+ /Cannot start .*, error was: The service cannot be started, either/
+ )
+ end
+
+ describe "when the service is disabled" do
+ before :each do
+ @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED)
+ Win32::Service.stubs(:start).with(@resource[:name])
+ end
+
+ it "should refuse to start if not managing enable" do
+ expect { @resource.provider.start }.to raise_error(Puppet::Error, /Will not start disabled service/)
+ end
+
+ it "should enable if managing enable and enable is true" do
+ @resource[:enable] = :true
+
+ Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_AUTO_START).returns(Win32::Service)
+
+ @resource.provider.start
+ end
+
+ it "should manual start if managing enable and enable is false" do
+ @resource[:enable] = :false
+
+ Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DEMAND_START).returns(Win32::Service)
+
+ @resource.provider.start
+ end
+ end
+ end
+
+ describe "#stop" do
+ it "should call out to the Win32::Service API to stop the service" do
+ Win32::Service.expects(:stop).with( @resource[:name] )
+ @resource.provider.stop
+ end
+
+ it "should handle when Win32::Service.stop raises a Win32::Service::Error" do
+ Win32::Service.expects(:stop).with( @resource[:name] ).raises(
+ Win32::Service::Error.new("should not try to stop an already stopped service.")
+ )
+
+ expect { @resource.provider.stop }.to raise_error(
+ Puppet::Error,
+ /Cannot stop .*, error was: should not try to stop an already stopped service/
+ )
+ end
+ end
+
+ describe "#status" do
+ ['stopped', 'paused', 'stop pending', 'pause pending'].each do |state|
+ it "should report a #{state} service as stopped" do
+ @status.current_state = state
+
+ @resource.provider.status.should == :stopped
+ end
+ end
+
+ ["running", "continue pending", "start pending" ].each do |state|
+ it "should report a #{state} service as running" do
+ @status.current_state = state
+
+ @resource.provider.status.should == :running
+ end
+ end
+ end
+
+ describe "#enabled?" do
+ it "should report a service with a startup type of manual as manual" do
+ @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DEMAND_START)
+
+ @resource.provider.enabled?.should == :manual
+ end
+
+ it "should report a service with a startup type of disabled as false" do
+ @config.start_type = Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED)
+
+ @resource.provider.enabled?.should == :false
+ end
+
+ # We need to guard this section explicitly since rspec will always
+ # construct all examples, even if it isn't going to run them.
+ if Puppet.features.microsoft_windows?
+ [Win32::Service::SERVICE_AUTO_START, Win32::Service::SERVICE_BOOT_START, Win32::Service::SERVICE_SYSTEM_START].each do |start_type_const|
+ start_type = Win32::Service.get_start_type(start_type_const)
+ it "should report a service with a startup type of '#{start_type}' as true" do
+ @config.start_type = start_type
+
+ @resource.provider.enabled?.should == :true
+ end
+ end
+ end
+ end
+
+ describe "#enable" do
+ it "should set service start type to Service_Auto_Start when enabled" do
+ Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_AUTO_START).returns(Win32::Service)
+ @resource.provider.enable
+ end
+ end
+
+ describe "#disable" do
+ it "should set service start type to Service_Disabled when disabled" do
+ Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DISABLED).returns(Win32::Service)
+ @resource.provider.disable
+ end
+ end
+
+ describe "#manual_start" do
+ it "should set service start type to Service_Demand_Start (manual) when manual" do
+ Win32::Service.expects(:configure).with('service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DEMAND_START).returns(Win32::Service)
+ @resource.provider.manual_start
+ end
+ end
+
+end
diff --git a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb
index bd5e55a9e..a7798be54 100755
--- a/spec/unit/provider/ssh_authorized_key/parsed_spec.rb
+++ b/spec/unit/provider/ssh_authorized_key/parsed_spec.rb
@@ -5,7 +5,7 @@ require 'puppet_spec/files'
provider_class = Puppet::Type.type(:ssh_authorized_key).provider(:parsed)
-describe provider_class do
+describe provider_class, :unless => Puppet.features.microsoft_windows? do
include PuppetSpec::Files
before :each do
@@ -77,7 +77,7 @@ describe provider_class do
end
end
-describe provider_class do
+describe provider_class, :unless => Puppet.features.microsoft_windows? do
before :each do
@resource = Puppet::Type.type(:ssh_authorized_key).new(:name => "foo", :user => "random_bob")
diff --git a/spec/unit/provider/user/user_role_add_spec.rb b/spec/unit/provider/user/user_role_add_spec.rb
index 5f2fc306e..c44fc5a65 100755
--- a/spec/unit/provider/user/user_role_add_spec.rb
+++ b/spec/unit/provider/user/user_role_add_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
provider_class = Puppet::Type.type(:user).provider(:user_role_add)
-describe provider_class do
+describe provider_class, :fails_on_windows => true do
before do
@resource = stub("resource", :name => "myuser", :managehome? => nil)
@resource.stubs(:should).returns "fakeval"
diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/useradd_spec.rb
index 724fc12c0..4265ee3a0 100755
--- a/spec/unit/provider/user/useradd_spec.rb
+++ b/spec/unit/provider/user/useradd_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
provider_class = Puppet::Type.type(:user).provider(:useradd)
-describe provider_class do
+describe provider_class, :fails_on_windows => true do
before do
@resource = stub("resource", :name => "myuser", :managehome? => nil)
@resource.stubs(:should).returns "fakeval"
diff --git a/spec/unit/provider/user/windows_adsi_spec.rb b/spec/unit/provider/user/windows_adsi_spec.rb
new file mode 100644
index 000000000..073a3d328
--- /dev/null
+++ b/spec/unit/provider/user/windows_adsi_spec.rb
@@ -0,0 +1,110 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+describe Puppet::Type.type(:user).provider(:windows_adsi) do
+ let(:resource) do
+ Puppet::Type.type(:user).new(
+ :title => 'testuser',
+ :comment => 'Test J. User',
+ :provider => :windows_adsi
+ )
+ end
+
+ let(:provider) { resource.provider }
+
+ let(:connection) { stub 'connection' }
+
+ before :each do
+ Puppet::Util::ADSI.stubs(:computer_name).returns('testcomputername')
+ Puppet::Util::ADSI.stubs(:connect).returns connection
+ end
+
+ describe ".instances" do
+ it "should enumerate all users" do
+ names = ['user1', 'user2', 'user3']
+ stub_users = names.map{|n| stub(:name => n)}
+
+ connection.stubs(:execquery).with("select * from win32_useraccount").returns(stub_users)
+
+ described_class.instances.map(&:name).should =~ names
+ end
+ end
+
+ it "should provide access to a Puppet::Util::ADSI::User object" do
+ provider.user.should be_a(Puppet::Util::ADSI::User)
+ end
+
+ describe "when managing groups" do
+ it 'should return the list of groups as a comma-separated list' do
+ provider.user.stubs(:groups).returns ['group1', 'group2', 'group3']
+
+ provider.groups.should == 'group1,group2,group3'
+ end
+
+ it "should return absent if there are no groups" do
+ provider.user.stubs(:groups).returns []
+
+ provider.groups.should == ''
+ end
+
+ it 'should be able to add a user to a set of groups' do
+ resource[:membership] = :minimum
+ provider.user.expects(:set_groups).with('group1,group2', true)
+
+ provider.groups = 'group1,group2'
+
+ resource[:membership] = :inclusive
+ provider.user.expects(:set_groups).with('group1,group2', false)
+
+ provider.groups = 'group1,group2'
+ end
+ end
+
+ describe "when creating a user" do
+ it "should create the user on the system and set its other properties" do
+ resource[:groups] = ['group1', 'group2']
+ resource[:membership] = :inclusive
+ resource[:comment] = 'a test user'
+ resource[:home] = 'C:\Users\testuser'
+
+ user = stub 'user'
+ Puppet::Util::ADSI::User.expects(:create).with('testuser').returns user
+
+ user.stubs(:groups).returns(['group2', 'group3'])
+
+ user.expects(:set_groups).with('group1,group2', false)
+ user.expects(:[]=).with('Description', 'a test user')
+ user.expects(:[]=).with('HomeDirectory', 'C:\Users\testuser')
+
+ provider.create
+ end
+ end
+
+ it 'should be able to test whether a user exists' do
+ Puppet::Util::ADSI.stubs(:connect).returns stub('connection')
+ provider.should be_exists
+
+ Puppet::Util::ADSI.stubs(:connect).returns nil
+ provider.should_not be_exists
+ end
+
+ it 'should be able to delete a user' do
+ connection.expects(:Delete).with('user', 'testuser')
+
+ provider.delete
+ end
+
+ it "should commit the user when flushed" do
+ provider.user.expects(:commit)
+
+ provider.flush
+ end
+
+ [:uid, :gid, :shell].each do |prop|
+ it "should warn when trying to manage the #{prop} property" do
+ provider.expects(:warning).with { |msg| msg =~ /No support for managing property #{prop}/ }
+ provider.send("#{prop}=", 'foo')
+ end
+ end
+end
diff --git a/spec/unit/resource/catalog_spec.rb b/spec/unit/resource/catalog_spec.rb
index 896167a2b..6a9b1196f 100755
--- a/spec/unit/resource/catalog_spec.rb
+++ b/spec/unit/resource/catalog_spec.rb
@@ -2,30 +2,14 @@
require 'spec_helper'
describe Puppet::Resource::Catalog, "when compiling" do
+ include PuppetSpec::Files
before do
- @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath"
+ @basepath = make_absolute("/somepath")
# stub this to not try to create state.yaml
Puppet::Util::Storage.stubs(:store)
end
- it "should be an Expirer" do
- Puppet::Resource::Catalog.ancestors.should be_include(Puppet::Util::Cacher::Expirer)
- end
-
- it "should always be expired if it's not applying" do
- @catalog = Puppet::Resource::Catalog.new("host")
- @catalog.expects(:applying?).returns false
- @catalog.should be_dependent_data_expired(Time.now)
- end
-
- it "should not be expired if it's applying and the timestamp is late enough" do
- @catalog = Puppet::Resource::Catalog.new("host")
- @catalog.expire
- @catalog.expects(:applying?).returns true
- @catalog.should_not be_dependent_data_expired(Time.now)
- end
-
it "should be able to write its list of classes to the class file" do
@catalog = Puppet::Resource::Catalog.new("host")
@@ -508,7 +492,7 @@ describe Puppet::Resource::Catalog, "when compiling" do
@catalog.resource(:file, @basepath+"/something").should equal(resource)
end
- it "should not create aliases for non-isomorphic resources whose names do not match their titles" do
+ it "should not create aliases for non-isomorphic resources whose names do not match their titles", :fails_on_windows => true do
resource = Puppet::Type.type(:exec).new(:title => "testing", :command => "echo", :path => %w{/bin /usr/bin /usr/local/bin})
@catalog.add_resource(resource)
@@ -614,11 +598,12 @@ describe Puppet::Resource::Catalog, "when compiling" do
end
it "should conflict when its uniqueness key matches another resource's title" do
- @resource = Puppet::Type.type(:file).new(:title => "/tmp/foo")
- @other = Puppet::Type.type(:file).new(:title => "another file", :path => "/tmp/foo")
+ path = make_absolute("/tmp/foo")
+ @resource = Puppet::Type.type(:file).new(:title => path)
+ @other = Puppet::Type.type(:file).new(:title => "another file", :path => path)
@catalog.add_resource(@resource)
- expect { @catalog.add_resource(@other) }.to raise_error(ArgumentError, /Cannot alias File\[another file\] to \["\/tmp\/foo"\].*resource \["File", "\/tmp\/foo"\] already defined/)
+ expect { @catalog.add_resource(@other) }.to raise_error(ArgumentError, /Cannot alias File\[another file\] to \["#{Regexp.escape(path)}"\].*resource \["File", "#{Regexp.escape(path)}"\] already defined/)
end
it "should conflict when its uniqueness key matches the uniqueness key derived from another resource's title" do
@@ -690,11 +675,6 @@ describe Puppet::Resource::Catalog, "when compiling" do
@catalog.apply(:ignoreschedules => true)
end
- it "should expire cached data in the resources both before and after the transaction" do
- @catalog.expects(:expire).times(2)
- @catalog.apply
- end
-
describe "host catalogs" do
# super() doesn't work in the setup method for some reason
@@ -855,8 +835,6 @@ describe Puppet::Resource::Catalog, "when compiling" do
@real_indirection = Puppet::Resource::Catalog.indirection
@indirection = stub 'indirection', :name => :catalog
-
- Puppet::Util::Cacher.expire
end
it "should use the value of the 'catalog_terminus' setting to determine its terminus class" do
@@ -875,7 +853,6 @@ describe Puppet::Resource::Catalog, "when compiling" do
end
after do
- Puppet::Util::Cacher.expire
@real_indirection.reset_terminus_class
end
end
diff --git a/spec/unit/resource/status_spec.rb b/spec/unit/resource/status_spec.rb
index e5a9291db..18e3359df 100755
--- a/spec/unit/resource/status_spec.rb
+++ b/spec/unit/resource/status_spec.rb
@@ -4,14 +4,16 @@ require 'spec_helper'
require 'puppet/resource/status'
describe Puppet::Resource::Status do
+ include PuppetSpec::Files
+
before do
- @resource = Puppet::Type.type(:file).new :path => "/my/file"
+ @resource = Puppet::Type.type(:file).new :path => make_absolute("/my/file")
@status = Puppet::Resource::Status.new(@resource)
end
it "should compute type and title correctly" do
@status.resource_type.should == "File"
- @status.title.should == "/my/file"
+ @status.title.should == make_absolute("/my/file")
end
[:node, :file, :line, :current_values, :status, :evaluation_time].each do |attr|
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 5c8e8dcf9..b4ef8bc34 100755
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -3,9 +3,10 @@ require 'spec_helper'
require 'puppet/resource'
describe Puppet::Resource do
+ include PuppetSpec::Files
before do
- @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath"
+ @basepath = make_absolute("/somepath")
end
[:catalog, :file, :line].each do |attr|
diff --git a/spec/unit/ssl/certificate_authority_spec.rb b/spec/unit/ssl/certificate_authority_spec.rb
index 3aedfdc25..3c5780a43 100755
--- a/spec/unit/ssl/certificate_authority_spec.rb
+++ b/spec/unit/ssl/certificate_authority_spec.rb
@@ -5,7 +5,7 @@ require 'puppet/ssl/certificate_authority'
describe Puppet::SSL::CertificateAuthority do
after do
- Puppet::Util::Cacher.expire
+ Puppet::SSL::CertificateAuthority.instance_variable_set(:@singleton_instance, nil)
Puppet.settings.clearused
end
@@ -25,7 +25,7 @@ describe Puppet::SSL::CertificateAuthority do
describe "when finding an existing instance" do
describe "and the host is a CA host and the run_mode is master" do
before do
- Puppet.settings.stubs(:value).with(:ca).returns true
+ Puppet[:ca] = true
Puppet.run_mode.stubs(:master?).returns true
@ca = mock('ca')
diff --git a/spec/unit/ssl/host_spec.rb b/spec/unit/ssl/host_spec.rb
index c2d9690e6..226acdecd 100755
--- a/spec/unit/ssl/host_spec.rb
+++ b/spec/unit/ssl/host_spec.rb
@@ -5,15 +5,24 @@ require 'puppet/ssl/host'
require 'puppet/sslcertificates'
require 'puppet/sslcertificates/ca'
-describe Puppet::SSL::Host do
+# REMIND: Fails on windows because there is no user provider yet
+describe Puppet::SSL::Host, :fails_on_windows => true do
+ include PuppetSpec::Files
+
before do
Puppet::SSL::Host.indirection.terminus_class = :file
+
+ # Get a safe temporary file
+ dir = tmpdir("ssl_host_testing")
+ Puppet.settings[:confdir] = dir
+ Puppet.settings[:vardir] = dir
+
@host = Puppet::SSL::Host.new("myname")
end
after do
# Cleaned out any cached localhost instance.
- Puppet::Util::Cacher.expire
+ Puppet::SSL::Host.instance_variable_set(:@localhost, nil)
Puppet::SSL::Host.ca_location = :none
end
@@ -82,16 +91,6 @@ describe Puppet::SSL::Host do
Puppet::SSL::Host.localhost.should == Puppet::SSL::Host.localhost
end
- it "should be able to expire the cached instance" do
- one = stub 'host1', :certificate => "eh", :key => 'foo'
- two = stub 'host2', :certificate => "eh", :key => 'foo'
- Puppet::SSL::Host.expects(:new).times(2).returns(one).then.returns(two)
-
- Puppet::SSL::Host.localhost.should equal(one)
- Puppet::Util::Cacher.expire
- Puppet::SSL::Host.localhost.should equal(two)
- end
-
it "should be able to verify its certificate matches its key" do
Puppet::SSL::Host.new("foo").should respond_to(:certificate_matches_key?)
end
@@ -711,7 +710,7 @@ describe Puppet::SSL::Host do
end
end
- describe "when handling PSON" do
+ describe "when handling PSON", :unless => Puppet.features.microsoft_windows? do
include PuppetSpec::Files
before do
diff --git a/spec/unit/ssl/inventory_spec.rb b/spec/unit/ssl/inventory_spec.rb
index d8606b1b4..000f0a253 100755
--- a/spec/unit/ssl/inventory_spec.rb
+++ b/spec/unit/ssl/inventory_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
require 'puppet/ssl/inventory'
-describe Puppet::SSL::Inventory do
+describe Puppet::SSL::Inventory, :unless => Puppet.features.microsoft_windows? do
before do
@class = Puppet::SSL::Inventory
end
@@ -118,7 +118,7 @@ describe Puppet::SSL::Inventory do
end
end
- describe "and formatting a certificate" do
+ describe "and formatting a certificate", :fails_on_windows => true do
before do
@cert = stub 'cert', :not_before => Time.now, :not_after => Time.now, :subject => "mycert", :serial => 15
end
diff --git a/spec/unit/sslcertificates/ca_spec.rb b/spec/unit/sslcertificates/ca_spec.rb
index eea246ba1..7a687b825 100755
--- a/spec/unit/sslcertificates/ca_spec.rb
+++ b/spec/unit/sslcertificates/ca_spec.rb
@@ -5,27 +5,23 @@ require 'puppet'
require 'puppet/sslcertificates'
require 'puppet/sslcertificates/ca'
-describe Puppet::SSLCertificates::CA do
+describe Puppet::SSLCertificates::CA, :unless => Puppet.features.microsoft_windows? do
+ include PuppetSpec::Files
+
before :all do
@hosts = %w{host.domain.com Other.Testing.Com}
end
before :each do
Puppet::Util::SUIDManager.stubs(:asuser).yields
- file = Tempfile.new("ca_testing")
- @dir = file.path
- file.delete
+ dir = tmpdir("ca_testing")
- Puppet.settings[:confdir] = @dir
- Puppet.settings[:vardir] = @dir
+ Puppet.settings[:confdir] = dir
+ Puppet.settings[:vardir] = dir
@ca = Puppet::SSLCertificates::CA.new
end
- after :each do
- system("rm -rf #{@dir}")
- end
-
describe 'when cleaning' do
it 'should remove associated files' do
dirs = [:csrdir, :signeddir, :publickeydir, :privatekeydir, :certdir]
diff --git a/spec/unit/transaction/event_manager_spec.rb b/spec/unit/transaction/event_manager_spec.rb
index d127d0391..37775997d 100755
--- a/spec/unit/transaction/event_manager_spec.rb
+++ b/spec/unit/transaction/event_manager_spec.rb
@@ -4,6 +4,8 @@ require 'spec_helper'
require 'puppet/transaction/event_manager'
describe Puppet::Transaction::EventManager do
+ include PuppetSpec::Files
+
describe "at initialization" do
it "should require a transaction" do
Puppet::Transaction::EventManager.new("trans").transaction.should == "trans"
@@ -23,7 +25,7 @@ describe Puppet::Transaction::EventManager do
before do
@manager = Puppet::Transaction::EventManager.new(@transaction)
- @resource = Puppet::Type.type(:file).new :path => "/my/file"
+ @resource = Puppet::Type.type(:file).new :path => make_absolute("/my/file")
@graph = stub 'graph', :matching_edges => [], :resource => @resource
@manager.stubs(:relationship_graph).returns @graph
@@ -139,7 +141,7 @@ describe Puppet::Transaction::EventManager do
@manager = Puppet::Transaction::EventManager.new(@transaction)
@manager.stubs(:queue_events)
- @resource = Puppet::Type.type(:file).new :path => "/my/file"
+ @resource = Puppet::Type.type(:file).new :path => make_absolute("/my/file")
@event = Puppet::Transaction::Event.new(:name => :event, :resource => @resource)
end
diff --git a/spec/unit/transaction/event_spec.rb b/spec/unit/transaction/event_spec.rb
index 0093baeb9..5f7f367b4 100755
--- a/spec/unit/transaction/event_spec.rb
+++ b/spec/unit/transaction/event_spec.rb
@@ -4,6 +4,8 @@ require 'spec_helper'
require 'puppet/transaction/event'
describe Puppet::Transaction::Event do
+ include PuppetSpec::Files
+
[:previous_value, :desired_value, :property, :resource, :name, :message, :file, :line, :tags, :audited].each do |attr|
it "should support #{attr}", :'fails_on_ruby_1.9.2' => true do
event = Puppet::Transaction::Event.new
@@ -113,7 +115,7 @@ describe Puppet::Transaction::Event do
describe "When converting to YAML" do
it "should include only documented attributes" do
- resource = Puppet::Type.type(:file).new(:title => "/tmp/foo")
+ resource = Puppet::Type.type(:file).new(:title => make_absolute("/tmp/foo"))
event = Puppet::Transaction::Event.new(:source_description => "/my/param", :resource => resource,
:file => "/foo.rb", :line => 27, :tags => %w{one two},
:desired_value => 7, :historical_value => 'Brazil',
diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb
index 4b04cc157..0a6ab8b5f 100755
--- a/spec/unit/transaction/report_spec.rb
+++ b/spec/unit/transaction/report_spec.rb
@@ -103,10 +103,6 @@ describe Puppet::Transaction::Report do
report.expects(:host).returns "me"
report.name.should == "me"
end
-
- after do
- Puppet::Util::Cacher.expire
- end
end
describe "when computing exit status" do
@@ -154,7 +150,7 @@ describe Puppet::Transaction::Report do
def add_statuses(count, type = :file)
count.times do |i|
- status = Puppet::Resource::Status.new(Puppet::Type.type(type).new(:title => "/my/path#{i}"))
+ status = Puppet::Resource::Status.new(Puppet::Type.type(type).new(:title => make_absolute("/my/path#{i}")))
yield status if block_given?
@report.add_resource_status status
end
@@ -208,7 +204,7 @@ describe Puppet::Transaction::Report do
end
describe "for times" do
- it "should provide the total amount of time for each resource type" do
+ it "should provide the total amount of time for each resource type", :fails_on_windows => true do
add_statuses(3, :file) do |status|
status.evaluation_time = 1
end
diff --git a/spec/unit/transaction/resource_harness_spec.rb b/spec/unit/transaction/resource_harness_spec.rb
index 20a42d27b..cadc31a0f 100755
--- a/spec/unit/transaction/resource_harness_spec.rb
+++ b/spec/unit/transaction/resource_harness_spec.rb
@@ -7,10 +7,14 @@ describe Puppet::Transaction::ResourceHarness do
include PuppetSpec::Files
before do
+ @mode_750 = Puppet.features.microsoft_windows? ? '644' : '750'
+ @mode_755 = Puppet.features.microsoft_windows? ? '644' : '755'
+ path = make_absolute("/my/file")
+
@transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
- @resource = Puppet::Type.type(:file).new :path => "/my/file"
+ @resource = Puppet::Type.type(:file).new :path => path
@harness = Puppet::Transaction::ResourceHarness.new(@transaction)
- @current_state = Puppet::Resource.new(:file, "/my/file")
+ @current_state = Puppet::Resource.new(:file, path)
@resource.stubs(:retrieve).returns @current_state
@status = Puppet::Resource::Status.new(@resource)
Puppet::Resource::Status.stubs(:new).returns @status
@@ -148,8 +152,8 @@ describe Puppet::Transaction::ResourceHarness do
describe "when applying changes" do
[false, true].each do |noop_mode|; describe (noop_mode ? "in noop mode" : "in normal mode") do
- [nil, '750'].each do |machine_state|; describe (machine_state ? "with a file initially present" : "with no file initially present") do
- [nil, '750', '755'].each do |yaml_mode|
+ [nil, @mode_750].each do |machine_state|; describe (machine_state ? "with a file initially present" : "with no file initially present") do
+ [nil, @mode_750, @mode_755].each do |yaml_mode|
[nil, :file, :absent].each do |yaml_ensure|; describe "with mode=#{yaml_mode.inspect} and ensure=#{yaml_ensure.inspect} stored in state.yml" do
[false, true].each do |auditing_ensure|
[false, true].each do |auditing_mode|
@@ -157,7 +161,7 @@ describe Puppet::Transaction::ResourceHarness do
auditing.push(:mode) if auditing_mode
auditing.push(:ensure) if auditing_ensure
[nil, :file, :absent].each do |ensure_property| # what we set "ensure" to in the manifest
- [nil, '750', '755'].each do |mode_property| # what we set "mode" to in the manifest
+ [nil, @mode_750, @mode_755].each do |mode_property| # what we set "mode" to in the manifest
manifest_settings = {}
manifest_settings[:audit] = auditing if !auditing.empty?
manifest_settings[:ensure] = ensure_property if ensure_property
diff --git a/spec/unit/transaction_spec.rb b/spec/unit/transaction_spec.rb
index 3829cfaf5..3f34f65bd 100755
--- a/spec/unit/transaction_spec.rb
+++ b/spec/unit/transaction_spec.rb
@@ -11,8 +11,10 @@ def without_warnings
end
describe Puppet::Transaction do
+ include PuppetSpec::Files
+
before do
- @basepath = Puppet.features.posix? ? "/what/ever" : "C:/tmp"
+ @basepath = make_absolute("/what/ever")
@transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
end
diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb
index 7bf92eb02..f2c18896b 100755
--- a/spec/unit/type/cron_spec.rb
+++ b/spec/unit/type/cron_spec.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env rspec
require 'spec_helper'
-describe Puppet::Type.type(:cron) do
+describe Puppet::Type.type(:cron), :unless => Puppet.features.microsoft_windows? do
before do
@class = Puppet::Type.type(:cron)
diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb
index 47d1b8523..8146dce92 100755
--- a/spec/unit/type/exec_spec.rb
+++ b/spec/unit/type/exec_spec.rb
@@ -2,6 +2,8 @@
require 'spec_helper'
describe Puppet::Type.type(:exec) do
+ include PuppetSpec::Files
+
def exec_tester(command, exitstatus = 0, rest = {})
@user_name = 'some_user_name'
@group_name = 'some_group_name'
@@ -30,12 +32,13 @@ describe Puppet::Type.type(:exec) do
end
before do
- @command = Puppet.features.posix? ? '/bin/true whatever' : '"C:/Program Files/something.exe" whatever'
+ @command = make_absolute('/bin/true whatever')
+ @executable = make_absolute('/bin/true')
+ @bogus_cmd = make_absolute('/bogus/cmd')
end
- describe "when not stubbing the provider" do
+ describe "when not stubbing the provider", :fails_on_windows => true do
before do
- @executable = Puppet.features.posix? ? '/bin/true' : 'C:/Program Files/something.exe'
File.stubs(:exists?).returns false
File.stubs(:exists?).with(@executable).returns true
File.stubs(:exists?).with('/bin/false').returns true
@@ -139,17 +142,18 @@ describe Puppet::Type.type(:exec) do
end
end
- it "should be able to autorequire files mentioned in the command" do
+ it "should be able to autorequire files mentioned in the command", :fails_on_windows => true do
+ foo = make_absolute('/bin/foo')
catalog = Puppet::Resource::Catalog.new
- tmp = Puppet::Type.type(:file).new(:name => "/bin/foo")
+ tmp = Puppet::Type.type(:file).new(:name => foo)
catalog.add_resource tmp
- execer = Puppet::Type.type(:exec).new(:name => "/bin/foo")
+ execer = Puppet::Type.type(:exec).new(:name => foo)
catalog.add_resource execer
catalog.relationship_graph.dependencies(execer).should == [tmp]
end
- describe "when handling the path parameter" do
+ describe "when handling the path parameter", :fails_on_windows => true do
expect = %w{one two three four}
{ "an array" => expect,
"a colon separated list" => "one:two:three:four",
@@ -165,7 +169,7 @@ describe Puppet::Type.type(:exec) do
end
end
- describe "when setting user" do
+ describe "when setting user", :fails_on_windows => true do
it "should fail if we are not root" do
Puppet.features.stubs(:root?).returns(false)
expect { Puppet::Type.type(:exec).new(:name => @command, :user => 'input') }.
@@ -184,7 +188,7 @@ describe Puppet::Type.type(:exec) do
describe "when setting group" do
shared_examples_for "exec[:group]" do
['one', 2, 'wheel', 4294967295, 4294967296].each do |value|
- it "should accept '#{value}' without error or judgement" do
+ it "should accept '#{value}' without error or judgement", :fails_on_windows => true do
type = Puppet::Type.type(:exec).new(:name => @command, :group => value)
type[:group].should == value
end
@@ -205,7 +209,7 @@ describe Puppet::Type.type(:exec) do
describe "when setting cwd" do
it_should_behave_like "all path parameters", :cwd, :array => false do
def instance(path)
- Puppet::Type.type(:exec).new(:name => '/bin/true', :cwd => path)
+ Puppet::Type.type(:exec).new(:name => @executable, :cwd => path)
end
end
end
@@ -221,7 +225,7 @@ describe Puppet::Type.type(:exec) do
if @param == :name then
instance = Puppet::Type.type(:exec).new()
else
- instance = Puppet::Type.type(:exec).new(:name => "/bin/true")
+ instance = Puppet::Type.type(:exec).new(:name => @executable)
end
if valid then
instance.provider.expects(:validatecmd).returns(true)
@@ -246,7 +250,7 @@ describe Puppet::Type.type(:exec) do
shared_examples_for "all exec command parameters that take arrays" do |param|
describe "when given an array of inputs" do
before :each do
- @test = Puppet::Type.type(:exec).new(:name => "/bin/true")
+ @test = Puppet::Type.type(:exec).new(:name => @executable)
end
it "should accept the array when all commands return valid" do
@@ -281,7 +285,7 @@ describe Puppet::Type.type(:exec) do
describe "for simple parameters" do
before :each do
- @exec = Puppet::Type.type(:exec).new(:name => '/bin/true')
+ @exec = Puppet::Type.type(:exec).new(:name => @executable)
end
describe "when setting environment" do
@@ -330,7 +334,8 @@ describe Puppet::Type.type(:exec) do
end
end
- it "should fail if timeout is exceeded" do
+ # REMIND: the exec provider is not supported on windows yet
+ it "should fail if timeout is exceeded", :fails_on_windows => true do
File.stubs(:exists?).with('/bin/sleep').returns(true)
File.stubs(:exists?).with('sleep').returns(false)
sleep_exec = Puppet::Type.type(:exec).new(:name => 'sleep 1', :path => ['/bin'], :timeout => '0.2')
@@ -338,13 +343,15 @@ describe Puppet::Type.type(:exec) do
end
it "should convert timeout to a float" do
- resource = Puppet::Type.type(:exec).new :command => "/bin/false", :timeout => "12"
+ command = make_absolute('/bin/false')
+ resource = Puppet::Type.type(:exec).new :command => command, :timeout => "12"
resource[:timeout].should be_a(Float)
resource[:timeout].should == 12.0
end
it "should munge negative timeouts to 0.0" do
- resource = Puppet::Type.type(:exec).new :command => "/bin/false", :timeout => "-12.0"
+ command = make_absolute('/bin/false')
+ resource = Puppet::Type.type(:exec).new :command => command, :timeout => "-12.0"
resource.parameter(:timeout).value.should be_a(Float)
resource.parameter(:timeout).value.should == 0.0
end
@@ -442,7 +449,7 @@ describe Puppet::Type.type(:exec) do
describe "when setting creates" do
it_should_behave_like "all path parameters", :creates, :array => true do
def instance(path)
- Puppet::Type.type(:exec).new(:name => '/bin/true', :creates => path)
+ Puppet::Type.type(:exec).new(:name => @executable, :creates => path)
end
end
end
@@ -460,7 +467,7 @@ describe Puppet::Type.type(:exec) do
describe "#check" do
before :each do
- @test = Puppet::Type.type(:exec).new(:name => "/bin/true")
+ @test = Puppet::Type.type(:exec).new(:name => @executable)
end
describe ":refreshonly" do
@@ -525,8 +532,8 @@ describe Puppet::Type.type(:exec) do
}.each do |param, sense|
describe ":#{param}" do
before :each do
- @pass = "/magic/pass"
- @fail = "/magic/fail"
+ @pass = make_absolute("/magic/pass")
+ @fail = make_absolute("/magic/fail")
@pass_status = stub('status', :exitstatus => sense[:pass] ? 0 : 1)
@fail_status = stub('status', :exitstatus => sense[:fail] ? 0 : 1)
@@ -584,9 +591,9 @@ describe Puppet::Type.type(:exec) do
end
end
- describe "#retrieve" do
+ describe "#retrieve", :fails_on_windows => true do
before :each do
- @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd")
+ @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd)
end
it "should return :notrun when check_all_attributes returns true" do
@@ -608,7 +615,7 @@ describe Puppet::Type.type(:exec) do
describe "#output" do
before :each do
- @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd")
+ @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd)
end
it "should return the provider's run output" do
@@ -625,14 +632,15 @@ describe Puppet::Type.type(:exec) do
describe "#refresh" do
before :each do
- @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd")
+ @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd)
end
it "should call provider run with the refresh parameter if it is set" do
+ myother_bogus_cmd = make_absolute('/myother/bogus/cmd')
provider = stub 'provider'
@exec_resource.stubs(:provider).returns(provider)
- @exec_resource.stubs(:[]).with(:refresh).returns('/myother/bogus/cmd')
- provider.expects(:run).with('/myother/bogus/cmd')
+ @exec_resource.stubs(:[]).with(:refresh).returns(myother_bogus_cmd)
+ provider.expects(:run).with(myother_bogus_cmd)
@exec_resource.refresh
end
@@ -641,7 +649,7 @@ describe Puppet::Type.type(:exec) do
provider = stub 'provider'
status = stubs "process_status"
status.stubs(:exitstatus).returns("0")
- provider.expects(:run).with('/bogus/cmd').returns(["silly output", status])
+ provider.expects(:run).with(@bogus_cmd).returns(["silly output", status])
@exec_resource.stubs(:provider).returns(provider)
@exec_resource.refresh
diff --git a/spec/unit/type/file/checksum_spec.rb b/spec/unit/type/file/checksum_spec.rb
index b47f617cc..30c4aba6d 100755
--- a/spec/unit/type/file/checksum_spec.rb
+++ b/spec/unit/type/file/checksum_spec.rb
@@ -4,7 +4,8 @@ require 'spec_helper'
checksum = Puppet::Type.type(:file).attrclass(:checksum)
describe checksum do
before do
- @resource = Puppet::Type.type(:file).new :path => "/foo/bar"
+ @path = Puppet.features.microsoft_windows? ? "c:/foo/bar" : "/foo/bar"
+ @resource = Puppet::Type.type(:file).new :path => @path
@checksum = @resource.parameter(:checksum)
end
@@ -35,25 +36,25 @@ describe checksum do
it "should use its current value when asked to sum a file's content" do
@checksum.value = :md5lite
- @checksum.expects(:md5lite_file).with("/foo/bar").returns "yay"
- @checksum.sum_file("/foo/bar")
+ @checksum.expects(:md5lite_file).with(@path).returns "yay"
+ @checksum.sum_file(@path)
end
it "should use :md5 to sum a file when no value is set" do
- @checksum.expects(:md5_file).with("/foo/bar").returns "yay"
- @checksum.sum_file("/foo/bar")
+ @checksum.expects(:md5_file).with(@path).returns "yay"
+ @checksum.sum_file(@path)
end
it "should convert all sums to strings when summing files" do
@checksum.value = :mtime
- @checksum.expects(:mtime_file).with("/foo/bar").returns Time.now
- lambda { @checksum.sum_file("/foo/bar") }.should_not raise_error
+ @checksum.expects(:mtime_file).with(@path).returns Time.now
+ lambda { @checksum.sum_file(@path) }.should_not raise_error
end
it "should return the summed contents of a file with a checksum label" do
@resource[:checksum] = :md5
@checksum.expects(:md5_file).returns "mysum"
- @checksum.sum_file("/foo/bar").should == "{md5}mysum"
+ @checksum.sum_file(@path).should == "{md5}mysum"
end
it "should return the summed contents of a stream with a checksum label" do
diff --git a/spec/unit/type/file/content_spec.rb b/spec/unit/type/file/content_spec.rb
index 7af5f9d83..04ec48555 100755
--- a/spec/unit/type/file/content_spec.rb
+++ b/spec/unit/type/file/content_spec.rb
@@ -254,6 +254,7 @@ describe content do
@content.should = "{md5}foo"
@content.resource.bucket.class.any_instance.stubs(:getfile).returns "foo"
@content.write(@fh)
+ @fh.close
end
describe "from actual content" do
@@ -298,7 +299,7 @@ describe content do
end
end
- describe "from local source" do
+ describe "from local source", :fails_on_windows => true do
before(:each) do
@resource = Puppet::Type.type(:file).new :path => @filename, :backup => false
@sourcename = tmpfile('source')
diff --git a/spec/unit/type/file/selinux_spec.rb b/spec/unit/type/file/selinux_spec.rb
index 2622948d0..f6e7451c7 100755
--- a/spec/unit/type/file/selinux_spec.rb
+++ b/spec/unit/type/file/selinux_spec.rb
@@ -1,12 +1,14 @@
#!/usr/bin/env rspec
require 'spec_helper'
-
[:seluser, :selrole, :seltype, :selrange].each do |param|
property = Puppet::Type.type(:file).attrclass(param)
describe property do
+ include PuppetSpec::Files
+
before do
- @resource = Puppet::Type.type(:file).new :path => "/my/file"
+ @path = make_absolute("/my/file")
+ @resource = Puppet::Type.type(:file).new :path => @path
@sel = property.new :resource => @resource
end
@@ -18,14 +20,14 @@ require 'spec_helper'
it "should retrieve nil for #{param} if there is no SELinux support" do
stat = stub 'stat', :ftype => "foo"
@resource.expects(:stat).returns stat
- @sel.expects(:get_selinux_current_context).with("/my/file").returns nil
+ @sel.expects(:get_selinux_current_context).with(@path).returns nil
@sel.retrieve.should be_nil
end
it "should retrieve #{param} if a SELinux context is found with a range" do
stat = stub 'stat', :ftype => "foo"
@resource.expects(:stat).returns stat
- @sel.expects(:get_selinux_current_context).with("/my/file").returns "user_u:role_r:type_t:s0"
+ @sel.expects(:get_selinux_current_context).with(@path).returns "user_u:role_r:type_t:s0"
expectedresult = case param
when :seluser; "user_u"
when :selrole; "role_r"
@@ -38,7 +40,7 @@ require 'spec_helper'
it "should retrieve #{param} if a SELinux context is found without a range" do
stat = stub 'stat', :ftype => "foo"
@resource.expects(:stat).returns stat
- @sel.expects(:get_selinux_current_context).with("/my/file").returns "user_u:role_r:type_t"
+ @sel.expects(:get_selinux_current_context).with(@path).returns "user_u:role_r:type_t"
expectedresult = case param
when :seluser; "user_u"
when :selrole; "role_r"
@@ -49,13 +51,13 @@ require 'spec_helper'
end
it "should handle no default gracefully" do
- @sel.expects(:get_selinux_default_context).with("/my/file").returns nil
+ @sel.expects(:get_selinux_default_context).with(@path).returns nil
@sel.default.must be_nil
end
it "should be able to detect matchpathcon defaults" do
@sel.stubs(:debug)
- @sel.expects(:get_selinux_default_context).with("/my/file").returns "user_u:role_r:type_t:s0"
+ @sel.expects(:get_selinux_default_context).with(@path).returns "user_u:role_r:type_t:s0"
expectedresult = case param
when :seluser; "user_u"
when :selrole; "role_r"
@@ -73,7 +75,7 @@ require 'spec_helper'
it "should be able to set a new context" do
stat = stub 'stat', :ftype => "foo"
@sel.should = %w{newone}
- @sel.expects(:set_selinux_context).with("/my/file", ["newone"], param)
+ @sel.expects(:set_selinux_context).with(@path, ["newone"], param)
@sel.sync
end
diff --git a/spec/unit/type/file/source_spec.rb b/spec/unit/type/file/source_spec.rb
index 5665d323d..c696feaf8 100755
--- a/spec/unit/type/file/source_spec.rb
+++ b/spec/unit/type/file/source_spec.rb
@@ -3,9 +3,13 @@ require 'spec_helper'
source = Puppet::Type.type(:file).attrclass(:source)
describe Puppet::Type.type(:file).attrclass(:source) do
+ include PuppetSpec::Files
+
before do
# Wow that's a messy interface to the resource.
@resource = stub 'resource', :[]= => nil, :property => nil, :catalog => stub("catalog", :dependent_data_expired? => false), :line => 0, :file => ''
+ @foobar = make_absolute("/foo/bar")
+ @feebooz = make_absolute("/fee/booz")
end
it "should be a subclass of Parameter" do
@@ -27,15 +31,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do
end
end
- it "should have a method for retrieving its metadata" do
- source.new(:resource => @resource).must respond_to(:metadata)
- end
-
- it "should have a method for setting its metadata" do
- source.new(:resource => @resource).must respond_to(:metadata=)
- end
-
- describe "when returning the metadata" do
+ describe "when returning the metadata", :fails_on_windows => true do
before do
@metadata = stub 'metadata', :source= => nil
end
@@ -52,58 +48,44 @@ describe Puppet::Type.type(:file).attrclass(:source) do
end
it "should collect its metadata using the Metadata class if it is not already set" do
- @source = source.new(:resource => @resource, :value => "/foo/bar")
- Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns @metadata
+ @source = source.new(:resource => @resource, :value => @foobar)
+ Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns @metadata
@source.metadata
end
it "should use the metadata from the first found source" do
metadata = stub 'metadata', :source= => nil
- @source = source.new(:resource => @resource, :value => ["/foo/bar", "/fee/booz"])
- Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns nil
- Puppet::FileServing::Metadata.indirection.expects(:find).with("/fee/booz").returns metadata
+ @source = source.new(:resource => @resource, :value => [@foobar, @feebooz])
+ Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns nil
+ Puppet::FileServing::Metadata.indirection.expects(:find).with(@feebooz).returns metadata
@source.metadata.should equal(metadata)
end
it "should store the found source as the metadata's source" do
metadata = mock 'metadata'
- @source = source.new(:resource => @resource, :value => "/foo/bar")
- Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns metadata
+ @source = source.new(:resource => @resource, :value => @foobar)
+ Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns metadata
- metadata.expects(:source=).with("/foo/bar")
+ metadata.expects(:source=).with(@foobar)
@source.metadata
end
it "should fail intelligently if an exception is encountered while querying for metadata" do
- @source = source.new(:resource => @resource, :value => "/foo/bar")
- Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").raises RuntimeError
+ @source = source.new(:resource => @resource, :value => @foobar)
+ Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).raises RuntimeError
@source.expects(:fail).raises ArgumentError
lambda { @source.metadata }.should raise_error(ArgumentError)
end
it "should fail if no specified sources can be found" do
- @source = source.new(:resource => @resource, :value => "/foo/bar")
- Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns nil
+ @source = source.new(:resource => @resource, :value => @foobar)
+ Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns nil
@source.expects(:fail).raises RuntimeError
lambda { @source.metadata }.should raise_error(RuntimeError)
end
-
- it "should expire the metadata appropriately" do
- expirer = stub 'expired', :dependent_data_expired? => true
-
- metadata = stub 'metadata', :source= => nil
- Puppet::FileServing::Metadata.indirection.expects(:find).with("/fee/booz").returns metadata
-
- @source = source.new(:resource => @resource, :value => ["/fee/booz"])
- @source.metadata = "foo"
-
- @source.stubs(:expirer).returns expirer
-
- @source.metadata.should_not == "foo"
- end
end
it "should have a method for setting the desired values on the resource" do
@@ -113,7 +95,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do
describe "when copying the source values" do
before do
- @resource = Puppet::Type.type(:file).new :path => "/foo/bar"
+ @resource = Puppet::Type.type(:file).new :path => @foobar
@source = source.new(:resource => @resource)
@metadata = stub 'metadata', :owner => 100, :group => 200, :mode => 123, :checksum => "{md5}asdfasdf", :ftype => "file"
diff --git a/spec/unit/type/file_spec.rb b/spec/unit/type/file_spec.rb
index c71bdd62a..0041ce9f2 100755
--- a/spec/unit/type/file_spec.rb
+++ b/spec/unit/type/file_spec.rb
@@ -37,7 +37,6 @@ describe Puppet::Type.type(:file) do
end
describe "#write" do
-
it "should propagate failures encountered when renaming the temporary file" do
File.stubs(:open)
@@ -92,7 +91,6 @@ describe Puppet::Type.type(:file) do
lambda { @file.write :NOTUSED }.should_not raise_error(Puppet::Error)
end
-
end
end
@@ -152,255 +150,204 @@ describe Puppet::Type.type(:file) do
end
describe "when using POSIX filenames" do
- describe "on POSIX systems" do
- before do
- Puppet.features.stubs(:posix?).returns(true)
- Puppet.features.stubs(:microsoft_windows?).returns(false)
- end
-
- it "should autorequire its parent directory" do
- file = Puppet::Type::File.new(:path => "/foo/bar")
- dir = Puppet::Type::File.new(:path => "/foo")
- @catalog.add_resource file
- @catalog.add_resource dir
- reqs = file.autorequire
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
-
- it "should autorequire its nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "/foo/bar/baz")
- dir = Puppet::Type::File.new(:path => "/foo")
- root = Puppet::Type::File.new(:path => "/")
- @catalog.add_resource file
- @catalog.add_resource dir
- @catalog.add_resource root
- reqs = file.autorequire
- reqs.length.must == 1
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
-
- it "should not autorequire anything when there is no nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "/foo/bar/baz")
- @catalog.add_resource file
- file.autorequire.should be_empty
- end
-
- it "should not autorequire its parent dir if its parent dir is itself" do
- file = Puppet::Type::File.new(:path => "/")
- @catalog.add_resource file
- file.autorequire.should be_empty
- end
-
- it "should remove trailing slashes" do
- file = Puppet::Type::File.new(:path => "/foo/bar/baz/")
- file[:path].should == "/foo/bar/baz"
- end
-
- it "should remove double slashes" do
- file = Puppet::Type::File.new(:path => "/foo/bar//baz")
- file[:path].should == "/foo/bar/baz"
- end
+ it "should autorequire its parent directory" do
+ file = Puppet::Type::File.new(:path => "/foo/bar")
+ dir = Puppet::Type::File.new(:path => "/foo")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ reqs = file.autorequire
+ reqs[0].source.must == dir
+ reqs[0].target.must == file
+ end
- it "should remove trailing double slashes" do
- file = Puppet::Type::File.new(:path => "/foo/bar/baz//")
- file[:path].should == "/foo/bar/baz"
- end
+ it "should autorequire its nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz")
+ dir = Puppet::Type::File.new(:path => "/foo")
+ root = Puppet::Type::File.new(:path => "/")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ @catalog.add_resource root
+ reqs = file.autorequire
+ reqs.length.must == 1
+ reqs[0].source.must == dir
+ reqs[0].target.must == file
+ end
- it "should leave a single slash alone" do
- file = Puppet::Type::File.new(:path => "/")
- file[:path].should == "/"
- end
+ it "should not autorequire anything when there is no nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz")
+ @catalog.add_resource file
+ file.autorequire.should be_empty
+ end
- it "should accept a double-slash at the start of the path" do
- expect {
- file = Puppet::Type::File.new(:path => "//tmp/xxx")
- # REVISIT: This should be wrong, later. See the next test.
- # --daniel 2011-01-31
- file[:path].should == '/tmp/xxx'
- }.should_not raise_error
- end
+ it "should not autorequire its parent dir if its parent dir is itself" do
+ file = Puppet::Type::File.new(:path => "/")
+ @catalog.add_resource file
+ file.autorequire.should be_empty
+ end
- # REVISIT: This is pending, because I don't want to try and audit the
- # entire codebase to make sure we get this right. POSIX treats two (and
- # exactly two) '/' characters at the start of the path specially.
- #
- # See sections 3.2 and 4.11, which allow DomainOS to be all special like
- # and still have the POSIX branding and all. --daniel 2011-01-31
- it "should preserve the double-slash at the start of the path"
+ it "should remove trailing slashes" do
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz/")
+ file[:path].should == "/foo/bar/baz"
end
- describe "on Microsoft Windows systems" do
- before do
- Puppet.features.stubs(:posix?).returns(false)
- Puppet.features.stubs(:microsoft_windows?).returns(true)
- end
+ it "should remove double slashes" do
+ file = Puppet::Type::File.new(:path => "/foo/bar//baz")
+ file[:path].should == "/foo/bar/baz"
+ end
- it "should refuse to work" do
- lambda { Puppet::Type::File.new(:path => "/foo/bar") }.should raise_error(Puppet::Error)
- end
+ it "should remove trailing double slashes" do
+ file = Puppet::Type::File.new(:path => "/foo/bar/baz//")
+ file[:path].should == "/foo/bar/baz"
end
- end
- describe "when using Microsoft Windows filenames", :if => Puppet.features.microsoft_windows? do
- describe "on Microsoft Windows systems" do
- before do
- Puppet.features.stubs(:posix?).returns(false)
- Puppet.features.stubs(:microsoft_windows?).returns(true)
- end
+ it "should leave a single slash alone" do
+ file = Puppet::Type::File.new(:path => "/")
+ file[:path].should == "/"
+ end
- it "should autorequire its parent directory" do
- file = Puppet::Type::File.new(:path => "X:/foo/bar")
- dir = Puppet::Type::File.new(:path => "X:/foo")
- @catalog.add_resource file
- @catalog.add_resource dir
- reqs = file.autorequire
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
+ it "should accept a double-slash at the start of the path" do
+ expect {
+ file = Puppet::Type::File.new(:path => "//tmp/xxx")
+ # REVISIT: This should be wrong, later. See the next test.
+ # --daniel 2011-01-31
+ file[:path].should == '/tmp/xxx'
+ }.should_not raise_error
+ end
- it "should autorequire its nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
- dir = Puppet::Type::File.new(:path => "X:/foo")
- root = Puppet::Type::File.new(:path => "X:/")
- @catalog.add_resource file
- @catalog.add_resource dir
- @catalog.add_resource root
- reqs = file.autorequire
- reqs.length.must == 1
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
+ # REVISIT: This is pending, because I don't want to try and audit the
+ # entire codebase to make sure we get this right. POSIX treats two (and
+ # exactly two) '/' characters at the start of the path specially.
+ #
+ # See sections 3.2 and 4.11, which allow DomainOS to be all special like
+ # and still have the POSIX branding and all. --daniel 2011-01-31
+ it "should preserve the double-slash at the start of the path"
+ end
- it "should not autorequire anything when there is no nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
- @catalog.add_resource file
- file.autorequire.should be_empty
- end
+ describe "when using Microsoft Windows filenames" do
+ it "should autorequire its parent directory" do
+ file = Puppet::Type::File.new(:path => "X:/foo/bar")
+ dir = Puppet::Type::File.new(:path => "X:/foo")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ reqs = file.autorequire
+ reqs[0].source.must == dir
+ reqs[0].target.must == file
+ end
- it "should not autorequire its parent dir if its parent dir is itself" do
- file = Puppet::Type::File.new(:path => "X:/")
- @catalog.add_resource file
- file.autorequire.should be_empty
- end
+ it "should autorequire its nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
+ dir = Puppet::Type::File.new(:path => "X:/foo")
+ root = Puppet::Type::File.new(:path => "X:/")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ @catalog.add_resource root
+ reqs = file.autorequire
+ reqs.length.must == 1
+ reqs[0].source.must == dir
+ reqs[0].target.must == file
+ end
- it "should remove trailing slashes" do
- file = Puppet::Type::File.new(:path => "X:/foo/bar/baz/")
- file[:path].should == "X:/foo/bar/baz"
- end
+ it "should not autorequire anything when there is no nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "X:/foo/bar/baz")
+ @catalog.add_resource file
+ file.autorequire.should be_empty
+ end
- it "should remove double slashes" do
- file = Puppet::Type::File.new(:path => "X:/foo/bar//baz")
- file[:path].should == "X:/foo/bar/baz"
- end
+ it "should not autorequire its parent dir if its parent dir is itself" do
+ file = Puppet::Type::File.new(:path => "X:/")
+ @catalog.add_resource file
+ file.autorequire.should be_empty
+ end
- it "should remove trailing double slashes" do
- file = Puppet::Type::File.new(:path => "X:/foo/bar/baz//")
- file[:path].should == "X:/foo/bar/baz"
- end
+ it "should remove trailing slashes" do
+ file = Puppet::Type::File.new(:path => "X:/foo/bar/baz/")
+ file[:path].should == "X:/foo/bar/baz"
+ end
- it "should leave a drive letter with a slash alone", :'fails_on_ruby_1.9.2' => true do
- file = Puppet::Type::File.new(:path => "X:/")
- file[:path].should == "X:/"
- end
+ it "should remove double slashes" do
+ file = Puppet::Type::File.new(:path => "X:/foo/bar//baz")
+ file[:path].should == "X:/foo/bar/baz"
+ end
- it "should add a slash to a drive letter", :'fails_on_ruby_1.9.2' => true do
- file = Puppet::Type::File.new(:path => "X:")
- file[:path].should == "X:/"
- end
+ it "should remove trailing double slashes" do
+ file = Puppet::Type::File.new(:path => "X:/foo/bar/baz//")
+ file[:path].should == "X:/foo/bar/baz"
end
- describe "on POSIX systems" do
- before do
- Puppet.features.stubs(:posix?).returns(true)
- Puppet.features.stubs(:microsoft_windows?).returns(false)
- end
+ it "should leave a drive letter with a slash alone", :'fails_on_ruby_1.9.2' => true do
+ file = Puppet::Type::File.new(:path => "X:/")
+ file[:path].should == "X:/"
+ end
- it "should refuse to work" do
- lambda { Puppet::Type::File.new(:path => "X:/foo/bar") }.should raise_error(Puppet::Error)
- end
+ it "should not accept a drive letter without a slash", :'fails_on_ruby_1.9.2' => true do
+ lambda { Puppet::Type::File.new(:path => "X:") }.should raise_error(/File paths must be fully qualified/)
end
end
- describe "when using UNC filenames" do
- describe "on Microsoft Windows systems", :if => Puppet.features.microsoft_windows?, :'fails_on_ruby_1.9.2' => true do
- before do
- Puppet.features.stubs(:posix?).returns(false)
- Puppet.features.stubs(:microsoft_windows?).returns(true)
- end
-
- it "should autorequire its parent directory" do
- file = Puppet::Type::File.new(:path => "//server/foo/bar")
- dir = Puppet::Type::File.new(:path => "//server/foo")
- @catalog.add_resource file
- @catalog.add_resource dir
- reqs = file.autorequire
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
-
- it "should autorequire its nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
- dir = Puppet::Type::File.new(:path => "//server/foo/bar")
- root = Puppet::Type::File.new(:path => "//server/foo")
- @catalog.add_resource file
- @catalog.add_resource dir
- @catalog.add_resource root
- reqs = file.autorequire
- reqs.length.must == 1
- reqs[0].source.must == dir
- reqs[0].target.must == file
- end
+ describe "when using UNC filenames", :'fails_on_ruby_1.9.2' => true do
+ before :each do
+ pending("UNC file paths not yet supported")
+ end
- it "should not autorequire anything when there is no nearest ancestor directory" do
- file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
- @catalog.add_resource file
- file.autorequire.should be_empty
- end
+ it "should autorequire its parent directory" do
+ file = Puppet::Type::File.new(:path => "//server/foo/bar")
+ dir = Puppet::Type::File.new(:path => "//server/foo")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ reqs = file.autorequire
+ reqs[0].source.must == dir
+ reqs[0].target.must == file
+ end
- it "should not autorequire its parent dir if its parent dir is itself" do
- file = Puppet::Type::File.new(:path => "//server/foo")
- @catalog.add_resource file
- puts file.autorequire
- file.autorequire.should be_empty
- end
+ it "should autorequire its nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
+ dir = Puppet::Type::File.new(:path => "//server/foo/bar")
+ root = Puppet::Type::File.new(:path => "//server/foo")
+ @catalog.add_resource file
+ @catalog.add_resource dir
+ @catalog.add_resource root
+ reqs = file.autorequire
+ reqs.length.must == 1
+ reqs[0].source.must == dir
+ reqs[0].target.must == file
+ end
- it "should remove trailing slashes" do
- file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/")
- file[:path].should == "//server/foo/bar/baz"
- end
+ it "should not autorequire anything when there is no nearest ancestor directory" do
+ file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux")
+ @catalog.add_resource file
+ file.autorequire.should be_empty
+ end
- it "should remove double slashes" do
- file = Puppet::Type::File.new(:path => "//server/foo/bar//baz")
- file[:path].should == "//server/foo/bar/baz"
- end
+ it "should not autorequire its parent dir if its parent dir is itself" do
+ file = Puppet::Type::File.new(:path => "//server/foo")
+ @catalog.add_resource file
+ puts file.autorequire
+ file.autorequire.should be_empty
+ end
- it "should remove trailing double slashes" do
- file = Puppet::Type::File.new(:path => "//server/foo/bar/baz//")
- file[:path].should == "//server/foo/bar/baz"
- end
+ it "should remove trailing slashes" do
+ file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/")
+ file[:path].should == "//server/foo/bar/baz"
+ end
- it "should remove a trailing slash from a sharename" do
- file = Puppet::Type::File.new(:path => "//server/foo/")
- file[:path].should == "//server/foo"
- end
+ it "should remove double slashes" do
+ file = Puppet::Type::File.new(:path => "//server/foo/bar//baz")
+ file[:path].should == "//server/foo/bar/baz"
+ end
- it "should not modify a sharename" do
- file = Puppet::Type::File.new(:path => "//server/foo")
- file[:path].should == "//server/foo"
- end
+ it "should remove trailing double slashes" do
+ file = Puppet::Type::File.new(:path => "//server/foo/bar/baz//")
+ file[:path].should == "//server/foo/bar/baz"
end
- describe "on POSIX systems" do
- before do
- Puppet.features.stubs(:posix?).returns(true)
- Puppet.features.stubs(:microsoft_windows?).returns(false)
- end
+ it "should remove a trailing slash from a sharename" do
+ file = Puppet::Type::File.new(:path => "//server/foo/")
+ file[:path].should == "//server/foo"
+ end
- it "should refuse to work" do
- lambda { Puppet::Type::File.new(:path => "X:/foo/bar") }.should raise_error(Puppet::Error)
- end
+ it "should not modify a sharename" do
+ file = Puppet::Type::File.new(:path => "//server/foo")
+ file[:path].should == "//server/foo"
end
end
diff --git a/spec/unit/type/group_spec.rb b/spec/unit/type/group_spec.rb
index afe28247a..3b6cac8bc 100755
--- a/spec/unit/type/group_spec.rb
+++ b/spec/unit/type/group_spec.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env rspec
require 'spec_helper'
-describe Puppet::Type.type(:group) do
+describe Puppet::Type.type(:group), :fails_on_windows => true do
before do
ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
@class = Puppet::Type.type(:group)
diff --git a/spec/unit/type/mount_spec.rb b/spec/unit/type/mount_spec.rb
index 9ef76992a..3309cd267 100755
--- a/spec/unit/type/mount_spec.rb
+++ b/spec/unit/type/mount_spec.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env rspec
require 'spec_helper'
-describe Puppet::Type.type(:mount) do
+describe Puppet::Type.type(:mount), :fails_on_windows => true do
it "should have a :refreshable feature that requires the :remount method" do
Puppet::Type.type(:mount).provider_feature(:refreshable).methods.should == [:remount]
end
@@ -16,7 +16,7 @@ describe Puppet::Type.type(:mount) do
end
end
-describe Puppet::Type.type(:mount), "when validating attributes" do
+describe Puppet::Type.type(:mount), "when validating attributes", :fails_on_windows => true do
[:name, :remounts, :provider].each do |param|
it "should have a #{param} parameter" do
Puppet::Type.type(:mount).attrtype(param).should == :param
@@ -30,7 +30,7 @@ describe Puppet::Type.type(:mount), "when validating attributes" do
end
end
-describe Puppet::Type.type(:mount)::Ensure, "when validating values" do
+describe Puppet::Type.type(:mount)::Ensure, "when validating values", :fails_on_windows => true do
before do
@provider = stub 'provider', :class => Puppet::Type.type(:mount).defaultprovider, :clear => nil
Puppet::Type.type(:mount).defaultprovider.expects(:new).returns(@provider)
@@ -62,7 +62,7 @@ describe Puppet::Type.type(:mount)::Ensure, "when validating values" do
end
end
-describe Puppet::Type.type(:mount)::Ensure do
+describe Puppet::Type.type(:mount)::Ensure, :fails_on_windows => true do
before :each do
provider_properties = {}
@provider = stub 'provider', :class => Puppet::Type.type(:mount).defaultprovider, :clear => nil, :satisfies? => true, :name => :mock, :property_hash => provider_properties
@@ -279,7 +279,7 @@ describe Puppet::Type.type(:mount)::Ensure do
end
end
-describe Puppet::Type.type(:mount), "when modifying an existing mount entry" do
+describe Puppet::Type.type(:mount), "when modifying an existing mount entry", :fails_on_windows => true do
before do
@provider = stub 'provider', :class => Puppet::Type.type(:mount).defaultprovider, :clear => nil, :satisfies? => true, :name => :mock, :remount => nil
Puppet::Type.type(:mount).defaultprovider.stubs(:new).returns(@provider)
diff --git a/spec/unit/type/noop_metaparam_spec.rb b/spec/unit/type/noop_metaparam_spec.rb
index f4241d417..7083dd037 100755
--- a/spec/unit/type/noop_metaparam_spec.rb
+++ b/spec/unit/type/noop_metaparam_spec.rb
@@ -4,9 +4,11 @@ require 'spec_helper'
require 'puppet/type'
describe Puppet::Type.type(:file).attrclass(:noop) do
+ include PuppetSpec::Files
+
before do
Puppet.settings.stubs(:use)
- @file = Puppet::Type.newfile :path => "/what/ever"
+ @file = Puppet::Type.newfile :path => make_absolute("/what/ever")
end
it "should accept true as a value" do
diff --git a/spec/unit/type/resources_spec.rb b/spec/unit/type/resources_spec.rb
index 48c068cfa..f596968d3 100755
--- a/spec/unit/type/resources_spec.rb
+++ b/spec/unit/type/resources_spec.rb
@@ -51,7 +51,7 @@ describe resources do
@resources.generate.collect { |r| r.ref }.should_not include(@host1.ref)
end
- it "should not include the skipped users", :'fails_on_ruby_1.9.2' => true do
+ it "should not include the skipped users", :'fails_on_ruby_1.9.2' => true, :fails_on_windows => true do
res = Puppet::Type.type(:resources).new :name => :user, :purge => true
res.catalog = Puppet::Resource::Catalog.new
@@ -72,7 +72,7 @@ describe resources do
end
end
- describe "when the instance's do not have an ensure property" do
+ describe "when the instance's do not have an ensure property", :fails_on_windows => true do
it "should not be included in the generated resources" do
@no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo')
Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
diff --git a/spec/unit/type/service_spec.rb b/spec/unit/type/service_spec.rb
index 40270e7c8..ab006a4be 100755
--- a/spec/unit/type/service_spec.rb
+++ b/spec/unit/type/service_spec.rb
@@ -57,6 +57,21 @@ describe Puppet::Type.type(:service), "when validating attribute values" do
Puppet::Type.type(:service).new(:name => "yay", :enable => :false)
end
+ it "should support :manual as a value to :enable on Windows" do
+ Puppet.features.stubs(:microsoft_windows?).returns true
+
+ Puppet::Type.type(:service).new(:name => "yay", :enable => :manual)
+ end
+
+ it "should not support :manual as a value to :enable when not on Windows" do
+ Puppet.features.stubs(:microsoft_windows?).returns false
+
+ expect { Puppet::Type.type(:service).new(:name => "yay", :enable => :manual) }.to raise_error(
+ Puppet::Error,
+ /Setting enable to manual is only supported on Microsoft Windows\./
+ )
+ end
+
it "should support :true as a value to :hasstatus" do
Puppet::Type.type(:service).new(:name => "yay", :hasstatus => :true)
end
diff --git a/spec/unit/type/ssh_authorized_key_spec.rb b/spec/unit/type/ssh_authorized_key_spec.rb
index 71b8a9ab0..db58dc9f3 100755
--- a/spec/unit/type/ssh_authorized_key_spec.rb
+++ b/spec/unit/type/ssh_authorized_key_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
ssh_authorized_key = Puppet::Type.type(:ssh_authorized_key)
-describe ssh_authorized_key do
+describe ssh_authorized_key, :unless => Puppet.features.microsoft_windows? do
+ include PuppetSpec::Files
+
before do
@class = Puppet::Type.type(:ssh_authorized_key)
@@ -11,7 +13,7 @@ describe ssh_authorized_key do
@class.stubs(:defaultprovider).returns(@provider_class)
@class.stubs(:provider).returns(@provider_class)
- @provider = stub 'provider', :class => @provider_class, :file_path => "/tmp/whatever", :clear => nil
+ @provider = stub 'provider', :class => @provider_class, :file_path => make_absolute("/tmp/whatever"), :clear => nil
@provider_class.stubs(:new).returns(@provider)
@catalog = Puppet::Resource::Catalog.new
end
diff --git a/spec/unit/type/tidy_spec.rb b/spec/unit/type/tidy_spec.rb
index cb030634b..bf892e836 100755
--- a/spec/unit/type/tidy_spec.rb
+++ b/spec/unit/type/tidy_spec.rb
@@ -5,8 +5,10 @@ require 'puppet/file_bucket/dipper'
tidy = Puppet::Type.type(:tidy)
describe tidy do
+ include PuppetSpec::Files
+
before do
- @basepath = Puppet.features.posix? ? "/what/ever" : "C:/tmp"
+ @basepath = make_absolute("/what/ever")
Puppet.settings.stubs(:use)
# for an unknown reason some of these specs fails when run individually
diff --git a/spec/unit/type/user_spec.rb b/spec/unit/type/user_spec.rb
index 823b12f27..f24fc8eef 100755
--- a/spec/unit/type/user_spec.rb
+++ b/spec/unit/type/user_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
user = Puppet::Type.type(:user)
-describe user do
+describe user, :fails_on_windows => true do
before do
ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
@provider = stub 'provider'
diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb
index bbdaec3bc..218c626d2 100755
--- a/spec/unit/type_spec.rb
+++ b/spec/unit/type_spec.rb
@@ -1,10 +1,8 @@
#!/usr/bin/env rspec
require 'spec_helper'
-describe Puppet::Type do
- it "should include the Cacher module" do
- Puppet::Type.ancestors.should be_include(Puppet::Util::Cacher)
- end
+describe Puppet::Type, :'fails_on_windows' => true do
+ include PuppetSpec::Files
it "should consider a parameter to be valid if it is a valid parameter" do
Puppet::Type.type(:mount).should be_valid_parameter(:path)
@@ -18,18 +16,6 @@ describe Puppet::Type do
Puppet::Type.type(:mount).should be_valid_parameter(:noop)
end
- it "should use its catalog as its expirer" do
- catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:mount).new(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
- resource.catalog = catalog
- resource.expirer.should equal(catalog)
- end
-
- it "should do nothing when asked to expire when it has no catalog" do
- resource = Puppet::Type.type(:mount).new(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
- lambda { resource.expire }.should_not raise_error
- end
-
it "should be able to retrieve a property by name" do
resource = Puppet::Type.type(:mount).new(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
resource.property(:fstype).must be_instance_of(Puppet::Type.type(:mount).attrclass(:fstype))
@@ -309,7 +295,8 @@ describe Puppet::Type do
end
it "should use the Resource Type's namevar to determine how to find the name in the hash" do
- Puppet::Type.type(:file).new(:path => "/yay").title.should == "/yay"
+ yay = make_absolute('/yay')
+ Puppet::Type.type(:file).new(:path => yay).title.should == yay
end
[:catalog].each do |param|
@@ -387,7 +374,7 @@ describe Puppet::Type do
end
it "should delete the name via the namevar from the originally provided parameters" do
- Puppet::Type.type(:file).new(:name => "/foo").original_parameters[:path].should be_nil
+ Puppet::Type.type(:file).new(:name => make_absolute('/foo')).original_parameters[:path].should be_nil
end
end
@@ -471,7 +458,7 @@ describe Puppet::Type do
end
it "should provide a value for 'ensure' even if no desired value is provided" do
- @resource = Puppet::Type.type(:file).new(:path => "/my/file/that/can't/exist")
+ @resource = Puppet::Type.type(:file).new(:path => make_absolute("/my/file/that/can't/exist"))
end
it "should not call retrieve on non-ensure properties if the resource is absent and should consider the property absent" do
@@ -513,8 +500,8 @@ describe Puppet::Type do
before do
@catalog = Puppet::Resource::Catalog.new
@container = Puppet::Type.type(:component).new(:name => "container")
- @one = Puppet::Type.type(:file).new(:path => "/file/one")
- @two = Puppet::Type.type(:file).new(:path => "/file/two")
+ @one = Puppet::Type.type(:file).new(:path => make_absolute("/file/one"))
+ @two = Puppet::Type.type(:file).new(:path => make_absolute("/file/two"))
@catalog.add_resource @container
@catalog.add_resource @one
@@ -541,7 +528,9 @@ describe Puppet::Type do
end
end
-describe Puppet::Type::RelationshipMetaparam do
+describe Puppet::Type::RelationshipMetaparam, :fails_on_windows => true do
+ include PuppetSpec::Files
+
it "should be a subclass of Puppet::Parameter" do
Puppet::Type::RelationshipMetaparam.superclass.should equal(Puppet::Parameter)
end
@@ -550,14 +539,15 @@ describe Puppet::Type::RelationshipMetaparam do
Puppet::Type::RelationshipMetaparam.should respond_to(:subclasses)
end
- describe "when munging relationships" do
+ describe "when munging relationships", :'fails_on_windows' => true do
before do
- @resource = Puppet::Type.type(:mount).new :name => "/foo"
+ @path = make_absolute('/foo')
+ @resource = Puppet::Type.type(:mount).new :name => @path
@metaparam = Puppet::Type.metaparamclass(:require).new :resource => @resource
end
it "should accept Puppet::Resource instances" do
- ref = Puppet::Resource.new(:file, "/foo")
+ ref = Puppet::Resource.new(:file, @path)
@metaparam.munge(ref)[0].should equal(ref)
end
@@ -585,18 +575,22 @@ describe Puppet::Type::RelationshipMetaparam do
end
end
-describe Puppet::Type.metaparamclass(:check) do
+describe Puppet::Type.metaparamclass(:check), :fails_on_windows => true do
+ include PuppetSpec::Files
+
it "should warn and create an instance of ':audit'" do
- file = Puppet::Type.type(:file).new :path => "/foo"
+ file = Puppet::Type.type(:file).new :path => make_absolute('/foo')
file.expects(:warning)
file[:check] = :mode
file[:audit].should == [:mode]
end
end
-describe Puppet::Type.metaparamclass(:audit) do
+describe Puppet::Type.metaparamclass(:audit), :fails_on_windows => true do
+ include PuppetSpec::Files
+
before do
- @resource = Puppet::Type.type(:file).new :path => "/foo"
+ @resource = Puppet::Type.type(:file).new :path => make_absolute('/foo')
end
it "should default to being nil" do
@@ -642,8 +636,9 @@ describe Puppet::Type.metaparamclass(:audit) do
Puppet::Type.type(:file).stubs(:title_patterns).returns(
[ [ /(.*)/, [ [:path, lambda{|x| x} ] ] ] ]
)
- res = Puppet::Type.type(:file).new( :title => '/my/file', :path => '/my/file', :owner => 'root', :content => 'hello' )
- res.uniqueness_key.should == [ nil, 'root', '/my/file']
+ myfile = make_absolute('/my/file')
+ res = Puppet::Type.type(:file).new( :title => myfile, :path => myfile, :owner => 'root', :content => 'hello' )
+ res.uniqueness_key.should == [ nil, 'root', myfile]
end
end
end
diff --git a/spec/unit/util/adsi_spec.rb b/spec/unit/util/adsi_spec.rb
new file mode 100644
index 000000000..b61724405
--- /dev/null
+++ b/spec/unit/util/adsi_spec.rb
@@ -0,0 +1,202 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+require 'puppet/util/adsi'
+
+describe Puppet::Util::ADSI do
+ let(:connection) { stub 'connection' }
+
+ before(:each) do
+ Puppet::Util::ADSI.instance_variable_set(:@computer_name, 'testcomputername')
+ Puppet::Util::ADSI.stubs(:connect).returns connection
+ end
+
+ it "should generate the correct URI for a resource" do
+ Puppet::Util::ADSI.uri('test', 'user').should == "WinNT://testcomputername/test,user"
+ end
+
+ it "should be able to get the name of the computer" do
+ Puppet::Util::ADSI.computer_name.should == 'testcomputername'
+ end
+
+ it "should be able to provide the correct WinNT base URI for the computer" do
+ Puppet::Util::ADSI.computer_uri.should == "WinNT://testcomputername"
+ end
+
+ describe Puppet::Util::ADSI::User do
+ let(:username) { 'testuser' }
+
+ it "should generate the correct URI" do
+ Puppet::Util::ADSI::User.uri(username).should == "WinNT://testcomputername/#{username},user"
+ end
+
+ it "should be able to create a user" do
+ adsi_user = stub('adsi')
+
+ connection.expects(:Create).with('user', username).returns(adsi_user)
+
+ user = Puppet::Util::ADSI::User.create(username)
+
+ user.should be_a(Puppet::Util::ADSI::User)
+ user.native_user.should == adsi_user
+ end
+
+ it "should be able to check the existence of a user" do
+ Puppet::Util::ADSI.expects(:connect).with("WinNT://testcomputername/#{username},user").returns connection
+ Puppet::Util::ADSI::User.exists?(username).should be_true
+ end
+
+ it "should be able to delete a user" do
+ connection.expects(:Delete).with('user', username)
+
+ Puppet::Util::ADSI::User.delete(username)
+ end
+
+ describe "an instance" do
+ let(:adsi_user) { stub 'user' }
+ let(:user) { Puppet::Util::ADSI::User.new(username, adsi_user) }
+
+ it "should provide its groups as a list of names" do
+ names = ["group1", "group2"]
+
+ groups = names.map { |name| mock('group', :Name => name) }
+
+ adsi_user.expects(:Groups).returns(groups)
+
+ user.groups.should =~ names
+ end
+
+ it "should be able to test whether a given password is correct" do
+ Puppet::Util::ADSI::User.expects(:logon).with(username, 'pwdwrong').returns(false)
+ Puppet::Util::ADSI::User.expects(:logon).with(username, 'pwdright').returns(true)
+
+ user.password_is?('pwdwrong').should be_false
+ user.password_is?('pwdright').should be_true
+ end
+
+ it "should be able to set a password" do
+ adsi_user.expects(:SetPassword).with('pwd')
+ adsi_user.expects(:SetInfo).at_least_once
+
+ flagname = "UserFlags"
+ fADS_UF_DONT_EXPIRE_PASSWD = 0x10000
+
+ adsi_user.expects(:Get).with(flagname).returns(0)
+ adsi_user.expects(:Put).with(flagname, fADS_UF_DONT_EXPIRE_PASSWD)
+
+ user.password = 'pwd'
+ end
+
+ it "should generate the correct URI" do
+ user.uri.should == "WinNT://testcomputername/#{username},user"
+ end
+
+ describe "when given a set of groups to which to add the user" do
+ let(:groups_to_set) { 'group1,group2' }
+
+ before(:each) do
+ user.expects(:groups).returns ['group2', 'group3']
+ end
+
+ describe "if membership is specified as inclusive" do
+ it "should add the user to those groups, and remove it from groups not in the list" do
+ group1 = stub 'group1'
+ group1.expects(:Add).with("WinNT://testcomputername/#{username},user")
+
+ group3 = stub 'group1'
+ group3.expects(:Remove).with("WinNT://testcomputername/#{username},user")
+
+ Puppet::Util::ADSI.expects(:connect).with('WinNT://testcomputername/group1,group').returns group1
+ Puppet::Util::ADSI.expects(:connect).with('WinNT://testcomputername/group3,group').returns group3
+
+ user.set_groups(groups_to_set, false)
+ end
+ end
+
+ describe "if membership is specified as minimum" do
+ it "should add the user to the specified groups without affecting its other memberships" do
+ group1 = stub 'group1'
+ group1.expects(:Add).with("WinNT://testcomputername/#{username},user")
+
+ Puppet::Util::ADSI.expects(:connect).with('WinNT://testcomputername/group1,group').returns group1
+
+ user.set_groups(groups_to_set, true)
+ end
+ end
+ end
+ end
+ end
+
+ describe Puppet::Util::ADSI::Group do
+ let(:groupname) { 'testgroup' }
+
+ describe "an instance" do
+ let(:adsi_group) { stub 'group' }
+ let(:group) { Puppet::Util::ADSI::Group.new(groupname, adsi_group) }
+
+ it "should be able to add a member" do
+ adsi_group.expects(:Add).with("WinNT://testcomputername/someone,user")
+
+ group.add_member('someone')
+ end
+
+ it "should be able to remove a member" do
+ adsi_group.expects(:Remove).with("WinNT://testcomputername/someone,user")
+
+ group.remove_member('someone')
+ end
+
+ it "should provide its groups as a list of names" do
+ names = ['user1', 'user2']
+
+ users = names.map { |name| mock('user', :Name => name) }
+
+ adsi_group.expects(:Members).returns(users)
+
+ group.members.should =~ names
+ end
+
+ it "should be able to add a list of users to a group" do
+ names = ['user1', 'user2']
+ adsi_group.expects(:Members).returns names.map{|n| stub(:Name => n)}
+
+ adsi_group.expects(:Remove).with('WinNT://testcomputername/user1,user')
+ adsi_group.expects(:Add).with('WinNT://testcomputername/user3,user')
+
+ group.set_members(['user2', 'user3'])
+ end
+
+ it "should generate the correct URI" do
+ group.uri.should == "WinNT://testcomputername/#{groupname},group"
+ end
+ end
+
+ it "should generate the correct URI" do
+ Puppet::Util::ADSI::Group.uri("people").should == "WinNT://testcomputername/people,group"
+ end
+
+ it "should be able to create a group" do
+ adsi_group = stub("adsi")
+
+ connection.expects(:Create).with('group', groupname).returns(adsi_group)
+
+ group = Puppet::Util::ADSI::Group.create(groupname)
+
+ group.should be_a(Puppet::Util::ADSI::Group)
+ group.native_group.should == adsi_group
+ end
+
+ it "should be able to confirm the existence of a group" do
+ Puppet::Util::ADSI.expects(:connect).with("WinNT://testcomputername/#{groupname},group").returns connection
+
+ Puppet::Util::ADSI::Group.exists?(groupname).should be_true
+ end
+
+ it "should be able to delete a group" do
+ connection.expects(:Delete).with('group', groupname)
+
+ Puppet::Util::ADSI::Group.delete(groupname)
+ end
+ end
+end
diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb
index d61b7689e..47ee54e1f 100755
--- a/spec/unit/util/autoload_spec.rb
+++ b/spec/unit/util/autoload_spec.rb
@@ -4,43 +4,47 @@ require 'spec_helper'
require 'puppet/util/autoload'
describe Puppet::Util::Autoload do
+ include PuppetSpec::Files
+
before do
@autoload = Puppet::Util::Autoload.new("foo", "tmp")
@autoload.stubs(:eachdir).yields "/my/dir"
end
- it "should use the Cacher module" do
- Puppet::Util::Autoload.ancestors.should be_include(Puppet::Util::Cacher)
- end
-
describe "when building the search path" do
+ before :each do
+ @dira = make_absolute('/a')
+ @dirb = make_absolute('/b')
+ @dirc = make_absolute('/c')
+ end
+
it "should collect all of the plugins and lib directories that exist in the current environment's module path" do
Puppet.settings.expects(:value).with(:environment).returns "foo"
- Puppet.settings.expects(:value).with(:modulepath, :foo).returns "/a:/b:/c"
- Dir.expects(:entries).with("/a").returns %w{one two}
- Dir.expects(:entries).with("/b").returns %w{one two}
+ Puppet.settings.expects(:value).with(:modulepath, :foo).returns "#{@dira}#{File::PATH_SEPARATOR}#{@dirb}#{File::PATH_SEPARATOR}#{@dirc}"
+ Dir.expects(:entries).with(@dira).returns %w{one two}
+ Dir.expects(:entries).with(@dirb).returns %w{one two}
FileTest.stubs(:directory?).returns false
- FileTest.expects(:directory?).with("/a").returns true
- FileTest.expects(:directory?).with("/b").returns true
- %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib}.each do |d|
+ FileTest.expects(:directory?).with(@dira).returns true
+ FileTest.expects(:directory?).with(@dirb).returns true
+ ["#{@dira}/one/plugins", "#{@dira}/two/lib", "#{@dirb}/one/plugins", "#{@dirb}/two/lib"].each do |d|
FileTest.expects(:directory?).with(d).returns true
end
- @autoload.module_directories.should == %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib}
+ @autoload.module_directories.should == ["#{@dira}/one/plugins", "#{@dira}/two/lib", "#{@dirb}/one/plugins", "#{@dirb}/two/lib"]
end
it "should not look for lib directories in directories starting with '.'" do
Puppet.settings.expects(:value).with(:environment).returns "foo"
- Puppet.settings.expects(:value).with(:modulepath, :foo).returns "/a"
- Dir.expects(:entries).with("/a").returns %w{. ..}
-
- FileTest.expects(:directory?).with("/a").returns true
- FileTest.expects(:directory?).with("/a/./lib").never
- FileTest.expects(:directory?).with("/a/./plugins").never
- FileTest.expects(:directory?).with("/a/../lib").never
- FileTest.expects(:directory?).with("/a/../plugins").never
+ Puppet.settings.expects(:value).with(:modulepath, :foo).returns @dira
+ Dir.expects(:entries).with(@dira).returns %w{. ..}
+
+ FileTest.expects(:directory?).with(@dira).returns true
+ FileTest.expects(:directory?).with("#{@dira}/./lib").never
+ FileTest.expects(:directory?).with("#{@dira}/./plugins").never
+ FileTest.expects(:directory?).with("#{@dira}/../lib").never
+ FileTest.expects(:directory?).with("#{@dira}/../plugins").never
@autoload.module_directories
end
diff --git a/spec/unit/util/backups_spec.rb b/spec/unit/util/backups_spec.rb
index 611c19304..d2f36a6e6 100755
--- a/spec/unit/util/backups_spec.rb
+++ b/spec/unit/util/backups_spec.rb
@@ -4,28 +4,31 @@ require 'spec_helper'
require 'puppet/util/backups'
describe Puppet::Util::Backups do
+ include PuppetSpec::Files
+
before do
FileTest.stubs(:exists?).returns true
+ @nosuchfile = make_absolute('/no/such/file')
end
describe "when backing up a file" do
it "should noop if the file does not exist" do
FileTest.expects(:exists?).returns false
- file = Puppet::Type.type(:file).new(:name => '/no/such/file')
+ file = Puppet::Type.type(:file).new(:name => @nosuchfile)
file.expects(:bucket).never
file.perform_backup
end
it "should succeed silently if self[:backup] is false" do
- file = Puppet::Type.type(:file).new(:name => '/no/such/file', :backup => false)
+ file = Puppet::Type.type(:file).new(:name => @nosuchfile, :backup => false)
file.expects(:bucket).never
FileTest.expects(:exists?).never
file.perform_backup
end
it "a bucket should be used when provided" do
- path = '/my/file'
+ path = make_absolute('/my/file')
File.stubs(:stat).with(path).returns(mock('stat', :ftype => 'file'))
@@ -39,7 +42,7 @@ describe Puppet::Util::Backups do
end
it "should propagate any exceptions encountered when backing up to a filebucket" do
- path = '/my/file'
+ path = make_absolute('/my/file')
File.stubs(:stat).with(path).returns(mock('stat', :ftype => 'file'))
@@ -54,7 +57,7 @@ describe Puppet::Util::Backups do
describe "and no filebucket is configured" do
it "should remove any local backup if one exists" do
- path = '/my/file'
+ path = make_absolute('/my/file')
FileTest.stubs(:exists?).returns true
backup = path + ".foo"
@@ -69,7 +72,7 @@ describe Puppet::Util::Backups do
end
it "should fail when the old backup can't be removed" do
- path = '/my/file'
+ path = make_absolute('/my/file')
FileTest.stubs(:exists?).returns true
backup = path + ".foo"
@@ -84,7 +87,7 @@ describe Puppet::Util::Backups do
end
it "should not try to remove backups that don't exist" do
- path = '/my/file'
+ path = make_absolute('/my/file')
FileTest.stubs(:exists?).returns true
backup = path + ".foo"
@@ -99,7 +102,7 @@ describe Puppet::Util::Backups do
end
it "a copy should be created in the local directory" do
- path = '/my/file'
+ path = make_absolute('/my/file')
FileTest.stubs(:exists?).with(path).returns true
FileUtils.expects(:cp_r).with(path, path + ".foo", :preserve => true)
@@ -109,7 +112,7 @@ describe Puppet::Util::Backups do
end
it "should propagate exceptions if no backup can be created" do
- path = '/my/file'
+ path = make_absolute('/my/file')
FileTest.stubs(:exists?).with(path).returns true
FileUtils.expects(:cp_r).raises ArgumentError
@@ -122,13 +125,13 @@ describe Puppet::Util::Backups do
describe "when backing up a directory" do
it "a bucket should work when provided" do
- path = '/my/dir'
+ path = make_absolute('/my/dir')
File.stubs(:file?).returns true
- Find.expects(:find).with(path).yields("/my/dir/file")
+ Find.expects(:find).with(path).yields(make_absolute("/my/dir/file"))
bucket = stub('bucket', :name => "eh")
- bucket.expects(:backup).with("/my/dir/file").returns true
+ bucket.expects(:backup).with(make_absolute("/my/dir/file")).returns true
file = Puppet::Type.type(:file).new(:name => path, :backup => 'foo')
file.stubs(:bucket).returns bucket
@@ -139,7 +142,7 @@ describe Puppet::Util::Backups do
end
it "should do nothing when recursing" do
- path = '/my/dir'
+ path = make_absolute('/my/dir')
bucket = stub('bucket', :name => "eh")
bucket.expects(:backup).never
diff --git a/spec/unit/util/cacher_spec.rb b/spec/unit/util/cacher_spec.rb
index fe93afd2b..16414c858 100755
--- a/spec/unit/util/cacher_spec.rb
+++ b/spec/unit/util/cacher_spec.rb
@@ -3,182 +3,105 @@ require 'spec_helper'
require 'puppet/util/cacher'
-class ExpirerTest
- include Puppet::Util::Cacher::Expirer
-end
-
class CacheTest
- @@init_count = 0
-
- include Puppet::Util::Cacher
- cached_attr(:instance_cache) { Time.now }
-end
+ @@count = 0
-describe Puppet::Util::Cacher::Expirer do
- before do
- @expirer = ExpirerTest.new
+ def self.count
+ @@count
end
- it "should be able to test whether a timestamp is expired" do
- @expirer.should respond_to(:dependent_data_expired?)
- end
-
- it "should be able to expire all values" do
- @expirer.should respond_to(:expire)
- end
-
- it "should consider any value to be valid if it has never been expired" do
- @expirer.should_not be_dependent_data_expired(Time.now)
- end
+ include Puppet::Util::Cacher
- it "should consider any value created after expiration to be expired" do
- @expirer.expire
- @expirer.should be_dependent_data_expired(Time.now - 1)
+ cached_attr(:instance_cache, 10) do
+ @@count += 1
+ {:number => @@count}
end
end
describe Puppet::Util::Cacher do
- it "should be extended with the Expirer module" do
- Puppet::Util::Cacher.singleton_class.ancestors.should be_include(Puppet::Util::Cacher::Expirer)
+ before :each do
+ CacheTest.set_attr_ttl(:instance_cache, 10)
+ @object = CacheTest.new
end
- it "should support defining cached attributes", :'fails_on_ruby_1.9.2' => true do
- CacheTest.methods.should be_include("cached_attr")
+ it "should return a value calculated from the provided block" do
+ @object.instance_cache.should == {:number => CacheTest.count}
end
- it "should default to the Cacher module as its expirer" do
- CacheTest.new.expirer.should equal(Puppet::Util::Cacher)
+ it "should return the cached value from the getter every time if the value is not expired" do
+ @object.instance_cache.should equal(@object.instance_cache)
end
- describe "when using cached attributes" do
- before do
- @expirer = ExpirerTest.new
- @object = CacheTest.new
+ it "should regenerate and return a new value using the provided block if the value has expired" do
+ initial = @object.instance_cache
- @object.stubs(:expirer).returns @expirer
- end
-
- it "should create a getter for the cached attribute" do
- @object.should respond_to(:instance_cache)
- end
-
- it "should return a value calculated from the provided block" do
- time = Time.now
- Time.stubs(:now).returns time
- @object.instance_cache.should equal(time)
- end
+ # Ensure the value is expired immediately
+ CacheTest.set_attr_ttl(:instance_cache, -10)
+ @object.send(:set_expiration, :instance_cache)
- it "should return the cached value from the getter every time if the value is not expired" do
- @object.instance_cache.should equal(@object.instance_cache)
- end
-
- it "should regenerate and return a new value using the provided block if the value has been expired" do
- value = @object.instance_cache
- @expirer.expire
- @object.instance_cache.should_not equal(value)
- end
+ @object.instance_cache.should_not equal(initial)
+ end
- it "should be able to trigger expiration on its expirer" do
- @expirer.expects(:expire)
- @object.expire
- end
+ it "should be able to cache false values" do
+ @object.expects(:init_instance_cache).once.returns false
+ @object.instance_cache.should be_false
+ @object.instance_cache.should be_false
+ end
- it "should do nothing when asked to expire when no expirer is available" do
- cacher = CacheTest.new
- class << cacher
- def expirer
- nil
- end
- end
- lambda { cacher.expire }.should_not raise_error
- end
+ it "should cache values again after expiration" do
+ initial = @object.instance_cache
- it "should be able to cache false values" do
- @object.expects(:init_instance_cache).returns false
- @object.instance_cache.should be_false
- @object.instance_cache.should be_false
- end
+ # Ensure the value is expired immediately
+ CacheTest.set_attr_ttl(:instance_cache, -10)
+ @object.send(:set_expiration, :instance_cache)
- it "should cache values again after expiration" do
- @object.instance_cache
- @expirer.expire
- @object.instance_cache.should equal(@object.instance_cache)
- end
+ # Reset ttl so this new value doesn't get expired
+ CacheTest.set_attr_ttl(:instance_cache, 10)
+ after_expiration = @object.instance_cache
- it "should always consider a value expired if it has no expirer" do
- @object.stubs(:expirer).returns nil
- @object.instance_cache.should_not equal(@object.instance_cache)
- end
+ after_expiration.should_not == initial
+ @object.instance_cache.should == after_expiration
+ end
- it "should allow writing of the attribute" do
- @object.should respond_to(:instance_cache=)
- end
+ it "should allow writing of the attribute" do
+ initial = @object.instance_cache
- it "should correctly configure timestamps for expiration when the cached attribute is written to" do
- @object.instance_cache = "foo"
- @expirer.expire
- @object.instance_cache.should_not == "foo"
- end
+ @object.instance_cache = "another value"
+ @object.instance_cache.should == "another value"
+ end
- it "should allow specification of a ttl for cached attributes" do
- klass = Class.new do
- include Puppet::Util::Cacher
- end
+ it "should update the expiration when the cached attribute is set manually" do
+ # Freeze time
+ now = Time.now
+ Time.stubs(:now).returns now
- klass.cached_attr(:myattr, :ttl => 5) { Time.now }
+ @object.instance_cache
- klass.attr_ttl(:myattr).should == 5
- end
+ # Set expiration to something far in the future
+ CacheTest.set_attr_ttl(:instance_cache, 60)
+ @object.send(:set_expiration, :instance_cache)
- it "should allow specification of a ttl as a string" do
- klass = Class.new do
- include Puppet::Util::Cacher
- end
+ CacheTest.set_attr_ttl(:instance_cache, 10)
- klass.cached_attr(:myattr, :ttl => "5") { Time.now }
+ @object.instance_cache = "foo"
+ @object.instance_variable_get(:@attr_expirations)[:instance_cache].should == now + 10
+ end
- klass.attr_ttl(:myattr).should == 5
+ it "should allow specification of a ttl as a string" do
+ klass = Class.new do
+ include Puppet::Util::Cacher
end
- it "should fail helpfully if the ttl cannot be converted to an integer" do
- klass = Class.new do
- include Puppet::Util::Cacher
- end
-
- lambda { klass.cached_attr(:myattr, :ttl => "yep") { Time.now } }.should raise_error(ArgumentError)
- end
+ klass.cached_attr(:myattr, "5") { 10 }
- it "should not check for a ttl expiration if the class does not support that method" do
- klass = Class.new do
- extend Puppet::Util::Cacher
- end
+ klass.attr_ttl(:myattr).should == 5
+ end
- klass.singleton_class.cached_attr(:myattr) { "eh" }
- klass.myattr
+ it "should fail helpfully if the ttl cannot be converted to an integer" do
+ klass = Class.new do
+ include Puppet::Util::Cacher
end
- it "should automatically expire cached attributes whose ttl has expired, even if no expirer is present" do
- klass = Class.new do
- def self.to_s
- "CacheTestClass"
- end
- include Puppet::Util::Cacher
- attr_accessor :value
- end
-
- klass.cached_attr(:myattr, :ttl => 5) { self.value += 1; self.value }
-
- now = Time.now
- later = Time.now + 15
-
- instance = klass.new
- instance.value = 0
- instance.myattr.should == 1
-
- Time.expects(:now).returns later
-
- # This call should get the new Time value, which should expire the old value
- instance.myattr.should == 2
- end
+ lambda { klass.cached_attr(:myattr, "yep") { 10 } }.should raise_error(ArgumentError)
end
end
diff --git a/spec/unit/util/execution_stub_spec.rb b/spec/unit/util/execution_stub_spec.rb
index 34987689c..9cd15ca6a 100755
--- a/spec/unit/util/execution_stub_spec.rb
+++ b/spec/unit/util/execution_stub_spec.rb
@@ -16,7 +16,7 @@ describe Puppet::Util::ExecutionStub do
Puppet::Util::ExecutionStub.current_value.should == nil
end
- it "should restore normal execution after 'reset' is called" do
+ it "should restore normal execution after 'reset' is called", :fails_on_windows => true do
true_command = Puppet::Util.which('true') # Note: "true" exists at different paths in different OSes
stub_call_count = 0
Puppet::Util::ExecutionStub.set do |command, options|
diff --git a/spec/unit/util/log_spec.rb b/spec/unit/util/log_spec.rb
index 1baa0d5af..39da4b010 100755
--- a/spec/unit/util/log_spec.rb
+++ b/spec/unit/util/log_spec.rb
@@ -4,6 +4,8 @@ require 'spec_helper'
require 'puppet/util/log'
describe Puppet::Util::Log do
+ include PuppetSpec::Files
+
it "should write a given message to the specified destination" do
arraydest = []
Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(arraydest))
@@ -167,7 +169,7 @@ describe Puppet::Util::Log do
describe "when setting the source as a RAL object" do
it "should tag itself with any tags the source has" do
- source = Puppet::Type.type(:file).new :path => "/foo/bar"
+ source = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar")
log = Puppet::Util::Log.new(:level => "notice", :message => :foo, :source => source)
source.tags.each do |tag|
log.tags.should be_include(tag)
@@ -188,7 +190,7 @@ describe Puppet::Util::Log do
end
it "should copy over any file and line information" do
- source = Puppet::Type.type(:file).new :path => "/foo/bar"
+ source = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar")
source.file = "/my/file"
source.line = 50
log = Puppet::Util::Log.new(:level => "notice", :message => :foo, :source => source)
diff --git a/spec/unit/util/logging_spec.rb b/spec/unit/util/logging_spec.rb
index 6a77e70ef..2953f54a4 100755
--- a/spec/unit/util/logging_spec.rb
+++ b/spec/unit/util/logging_spec.rb
@@ -46,7 +46,7 @@ describe Puppet::Util::Logging do
@logger.notice "foo"
end
- it "should use the path of any provided resource type" do
+ it "should use the path of any provided resource type", :fails_on_windows => true do
resource = Puppet::Type.type(:mount).new :name => "foo"
resource.expects(:path).returns "/path/to/mount".to_sym
@@ -56,7 +56,7 @@ describe Puppet::Util::Logging do
resource.notice "foo"
end
- it "should use the path of any provided resource parameter" do
+ it "should use the path of any provided resource parameter", :fails_on_windows => true do
resource = Puppet::Type.type(:mount).new :name => "foo"
param = resource.parameter(:name)
diff --git a/spec/unit/util/network_device/config_spec.rb b/spec/unit/util/network_device/config_spec.rb
index d69358a92..d9bd3d979 100755
--- a/spec/unit/util/network_device/config_spec.rb
+++ b/spec/unit/util/network_device/config_spec.rb
@@ -4,9 +4,11 @@ require 'spec_helper'
require 'puppet/util/network_device/config'
describe Puppet::Util::NetworkDevice::Config do
+ include PuppetSpec::Files
+
before(:each) do
- Puppet[:deviceconfig] = "/dummy"
- FileTest.stubs(:exists?).with("/dummy").returns(true)
+ Puppet[:deviceconfig] = make_absolute("/dummy")
+ FileTest.stubs(:exists?).with(make_absolute("/dummy")).returns(true)
end
describe "when initializing" do
@@ -15,7 +17,7 @@ describe Puppet::Util::NetworkDevice::Config do
end
it "should use the deviceconfig setting as pathname" do
- Puppet.expects(:[]).with(:deviceconfig).returns("/dummy")
+ Puppet.expects(:[]).with(:deviceconfig).returns(make_absolute("/dummy"))
Puppet::Util::NetworkDevice::Config.new
end
diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb
index 92b50e09b..29e3298f0 100755
--- a/spec/unit/util/rdoc/parser_spec.rb
+++ b/spec/unit/util/rdoc/parser_spec.rb
@@ -8,6 +8,8 @@ require 'rdoc/options'
require 'rdoc/rdoc'
describe RDoc::Parser, :'fails_on_ruby_1.9.2' => true do
+ include PuppetSpec::Files
+
before :each do
File.stubs(:stat).with("init.pp")
@top_level = stub_everything 'toplevel', :file_relative_name => "init.pp"
@@ -21,7 +23,7 @@ describe RDoc::Parser, :'fails_on_ruby_1.9.2' => true do
Puppet::Parser::Parser.stubs(:new).returns(parser)
parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')).at_least_once
parser.expects(:file=).with("module/manifests/init.pp")
- parser.expects(:file=).with("/dev/null/manifests/site.pp")
+ parser.expects(:file=).with(make_absolute("/dev/null/manifests/site.pp"))
@parser.scan
end
@@ -147,6 +149,10 @@ describe RDoc::Parser, :'fails_on_ruby_1.9.2' => true do
File.stubs(:identical?).returns(false)
@parser.split_module("/path/to/manifests/init.pp").should == RDoc::Parser::SITE
end
+
+ it "should handle windows paths with drive letters", :if => Puppet.features.microsoft_windows? do
+ @parser.split_module("C:/temp/init.pp").should == RDoc::Parser::SITE
+ end
end
describe "when parsing AST elements" do
diff --git a/spec/unit/util/run_mode_spec.rb b/spec/unit/util/run_mode_spec.rb
index c8d2b31f6..f2303ccc2 100755
--- a/spec/unit/util/run_mode_spec.rb
+++ b/spec/unit/util/run_mode_spec.rb
@@ -8,7 +8,9 @@ describe Puppet::Util::RunMode do
it "should have confdir /etc/puppet when run as root" do
Puppet.features.stubs(:root?).returns(true)
- @run_mode.conf_dir.should == '/etc/puppet'
+ etcdir = Puppet.features.microsoft_windows? ? File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "etc") : '/etc/puppet'
+ # REMIND: issue with windows backslashes
+ @run_mode.conf_dir.should == File.expand_path(etcdir)
end
it "should have confdir ~/.puppet when run as non-root" do
@@ -19,7 +21,9 @@ describe Puppet::Util::RunMode do
it "should have vardir /var/lib/puppet when run as root" do
Puppet.features.stubs(:root?).returns(true)
- @run_mode.var_dir.should == '/var/lib/puppet'
+ vardir = Puppet.features.microsoft_windows? ? File.join(Dir::COMMON_APPDATA, "PuppetLabs", "puppet", "var") : '/var/lib/puppet'
+ # REMIND: issue with windows backslashes
+ @run_mode.var_dir.should == File.expand_path(vardir)
end
it "should have vardir ~/.puppet/var when run as non-root" do
diff --git a/spec/unit/util/settings/file_setting_spec.rb b/spec/unit/util/settings/file_setting_spec.rb
index 489628a78..01d891f08 100755
--- a/spec/unit/util/settings/file_setting_spec.rb
+++ b/spec/unit/util/settings/file_setting_spec.rb
@@ -7,8 +7,10 @@ require 'puppet/util/settings/file_setting'
describe Puppet::Util::Settings::FileSetting do
FileSetting = Puppet::Util::Settings::FileSetting
+ include PuppetSpec::Files
+
before do
- @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath"
+ @basepath = make_absolute("/somepath")
end
describe "when determining whether the service user should be used" do
@@ -165,7 +167,10 @@ describe Puppet::Util::Settings::FileSetting do
it "should fully qualified returned files if necessary (#795)" do
@settings.stubs(:value).with(:mydir).returns "myfile"
- @file.to_resource.title.should == File.join(Dir.getwd, "myfile")
+ path = File.join(Dir.getwd, "myfile")
+ # Dir.getwd can return windows paths with backslashes, so we normalize them using expand_path
+ path = File.expand_path(path) if Puppet.features.microsoft_windows?
+ @file.to_resource.title.should == path
end
it "should set the mode on the file if a mode is provided" do
diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb
index a2cd57a0c..76f229c0f 100755
--- a/spec/unit/util/settings_spec.rb
+++ b/spec/unit/util/settings_spec.rb
@@ -3,6 +3,8 @@ require 'spec_helper'
require 'ostruct'
describe Puppet::Util::Settings do
+ include PuppetSpec::Files
+
describe "when specifying defaults" do
before do
@settings = Puppet::Util::Settings.new
@@ -378,7 +380,7 @@ describe Puppet::Util::Settings do
end
it "should use its current ':config' value for the file to parse" do
- myfile = Puppet.features.posix? ? "/my/file" : "C:/myfile" # do not stub expand_path here, as this leads to a stack overflow, when mocha tries to use it
+ myfile = make_absolute("/my/file") # do not stub expand_path here, as this leads to a stack overflow, when mocha tries to use it
@settings[:config] = myfile
File.expects(:read).with(myfile).returns "[main]"
@@ -445,25 +447,27 @@ describe Puppet::Util::Settings do
it "should support specifying all metadata (owner, group, mode) in the configuration file" do
@settings.setdefaults :section, :myfile => ["/myfile", "a"]
+ otherfile = make_absolute("/other/file")
text = "[main]
- myfile = /other/file {owner = service, group = service, mode = 644}
+ myfile = #{otherfile} {owner = service, group = service, mode = 644}
"
@settings.expects(:read_file).returns(text)
@settings.parse
- @settings[:myfile].should == "/other/file"
+ @settings[:myfile].should == otherfile
@settings.metadata(:myfile).should == {:owner => "suser", :group => "sgroup", :mode => "644"}
end
it "should support specifying a single piece of metadata (owner, group, or mode) in the configuration file" do
@settings.setdefaults :section, :myfile => ["/myfile", "a"]
+ otherfile = make_absolute("/other/file")
text = "[main]
- myfile = /other/file {owner = service}
+ myfile = #{otherfile} {owner = service}
"
file = "/some/file"
@settings.expects(:read_file).returns(text)
@settings.parse
- @settings[:myfile].should == "/other/file"
+ @settings[:myfile].should == otherfile
@settings.metadata(:myfile).should == {:owner => "suser"}
end
@@ -602,16 +606,6 @@ describe Puppet::Util::Settings do
@settings.reparse
end
- it "should use a cached LoadedFile instance" do
- first = mock 'first'
- second = mock 'second'
- Puppet::Util::LoadedFile.expects(:new).times(2).with("/test/file").returns(first).then.returns(second)
-
- @settings.file.should equal(first)
- Puppet::Util::Cacher.expire
- @settings.file.should equal(second)
- end
-
it "should replace in-memory values with on-file values" do
# Init the value
text = "[main]\none = disk-init\n"
diff --git a/spec/unit/util/storage_spec.rb b/spec/unit/util/storage_spec.rb
index 90c11aa69..575ad1ef3 100755
--- a/spec/unit/util/storage_spec.rb
+++ b/spec/unit/util/storage_spec.rb
@@ -8,7 +8,7 @@ describe Puppet::Util::Storage do
include PuppetSpec::Files
before(:all) do
- @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath"
+ @basepath = make_absolute("/somepath")
Puppet[:statedir] = tmpdir("statedir")
end
diff --git a/spec/unit/util/suidmanager_spec.rb b/spec/unit/util/suidmanager_spec.rb
index fc70e1718..abfe3f723 100755
--- a/spec/unit/util/suidmanager_spec.rb
+++ b/spec/unit/util/suidmanager_spec.rb
@@ -33,6 +33,7 @@ describe Puppet::Util::SUIDManager do
describe "#asuser" do
it "should set euid/egid when root" do
Process.stubs(:uid).returns(0)
+ Puppet.features.stubs(:microsoft_windows?).returns(false)
Process.stubs(:egid).returns(51)
Process.stubs(:euid).returns(50)
@@ -168,6 +169,8 @@ describe Puppet::Util::SUIDManager do
describe "with #system" do
it "should set euid/egid when root" do
Process.stubs(:uid).returns(0)
+ Puppet.features.stubs(:microsoft_windows?).returns(false)
+
Process.stubs(:egid).returns(51)
Process.stubs(:euid).returns(50)
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index a60092cf7..6bae80a01 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -280,7 +280,6 @@ module PuppetTest
Puppet::Util::Storage.clear
Puppet.clear
Puppet.settings.clear
- Puppet::Util::Cacher.expire
@memoryatend = Puppet::Util.memory
diff = @memoryatend - @memoryatstart
diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb
index 4c0374a76..9326e4b38 100755
--- a/test/network/handler/master.rb
+++ b/test/network/handler/master.rb
@@ -16,11 +16,6 @@ class TestMaster < Test::Unit::TestCase
Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog)
end
- def teardown
- super
- Puppet::Util::Cacher.expire
- end
-
def test_freshness_is_always_now
now1 = mock 'now1'
Time.stubs(:now).returns(now1)
diff --git a/test/network/server/webrick.rb b/test/network/server/webrick.rb
index 624147b6c..e1fd68921 100755
--- a/test/network/server/webrick.rb
+++ b/test/network/server/webrick.rb
@@ -11,24 +11,17 @@ class TestWebrickServer < Test::Unit::TestCase
def setup
Puppet::Util::SUIDManager.stubs(:asuser).yields
+ Puppet::SSL::Host.instance_variable_set(:@localhost, nil)
super
end
- def teardown
- super
- Puppet::Network::HttpPool.clear_http_instances
- end
-
# Make sure we can create a server, and that it knows how to create its
# certs by default.
def test_basics
server = nil
assert_raise(Puppet::Error, "server succeeded with no cert") do
-
- server = Puppet::Network::HTTPServer::WEBrick.new(
-
+ server = Puppet::Network::HTTPServer::WEBrick.new(
:Port => @@port,
-
:Handlers => {
:Status => nil
}
@@ -36,11 +29,8 @@ class TestWebrickServer < Test::Unit::TestCase
end
assert_nothing_raised("Could not create simple server") do
-
- server = Puppet::Network::HTTPServer::WEBrick.new(
-
+ server = Puppet::Network::HTTPServer::WEBrick.new(
:Port => @@port,
-
:Handlers => {
:CA => {}, # so that certs autogenerate
:Status => nil
@@ -76,11 +66,8 @@ class TestWebrickServer < Test::Unit::TestCase
client = nil
assert_nothing_raised {
-
- client = Puppet::Network::Client.status.new(
-
+ client = Puppet::Network::Client.status.new(
:Server => "localhost",
-
:Port => @@port
)
}
@@ -91,17 +78,13 @@ class TestWebrickServer < Test::Unit::TestCase
server = nil
Puppet[:certdnsnames] = "localhost"
assert_nothing_raised {
-
- server = Puppet::Network::HTTPServer::WEBrick.new(
-
+ server = Puppet::Network::HTTPServer::WEBrick.new(
:Port => @@port,
-
:Handlers => {
:CA => {}, # so that certs autogenerate
:Status => nil
}
)
-
}
pid = fork {
diff --git a/test/ral/type/filesources.rb b/test/ral/type/filesources.rb
index 3363aafb3..f39d53907 100755
--- a/test/ral/type/filesources.rb
+++ b/test/ral/type/filesources.rb
@@ -26,7 +26,6 @@ class TestFileSources < Test::Unit::TestCase
def teardown
super
- Puppet::Network::HttpPool.clear_http_instances
end
def use_storage