summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/provider.rb19
-rw-r--r--lib/puppet/provider/nameservice.rb3
-rw-r--r--lib/puppet/provider/nameservice/netinfo.rb17
-rwxr-xr-xlib/puppet/provider/package/apple.rb2
-rwxr-xr-xlib/puppet/provider/package/darwinport.rb1
-rwxr-xr-xlib/puppet/provider/package/gem.rb20
-rw-r--r--lib/puppet/provider/user/netinfo.rb21
-rw-r--r--lib/puppet/suidmanager.rb43
-rw-r--r--lib/puppet/transaction.rb1
-rwxr-xr-xlib/puppet/type/exec.rb4
-rwxr-xr-xlib/puppet/type/host.rb15
-rwxr-xr-xlib/puppet/type/user.rb6
-rw-r--r--lib/puppet/util.rb54
-rw-r--r--test/data/providers/package/testpackages.yaml1
-rwxr-xr-xtest/other/transactions.rb4
-rwxr-xr-xtest/providers/package.rb24
-rwxr-xr-xtest/providers/provider.rb10
-rwxr-xr-xtest/providers/user.rb38
-rwxr-xr-xtest/puppet/tc_suidmanager.rb2
-rwxr-xr-xtest/rails/rails.rb10
-rwxr-xr-xtest/types/host.rb15
-rwxr-xr-xtest/util/utiltest.rb46
22 files changed, 229 insertions, 127 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb
index a5890f131..3a31a89a3 100644
--- a/lib/puppet/provider.rb
+++ b/lib/puppet/provider.rb
@@ -1,6 +1,7 @@
# The container class for implementations.
class Puppet::Provider
include Puppet::Util
+ include Puppet::Util::Errors
Puppet::Util.logmethods(self, true)
@@ -47,22 +48,24 @@ class Puppet::Provider
@commands[name] = path
confine :exists => path
- # Now define a method for that package
- #unless method_defined? name
+ # Now define a method for that command
unless metaclass.method_defined? name
- meta_def(name) do |args|
- if args
- cmd = command(name) + " " + args
+ meta_def(name) do |*args|
+ if args.empty?
+ cmd = [command(name)]
else
- cmd = command(name)
+ cmd = [command(name)] + args
end
# This might throw an ExecutionFailure, but the system above
# will catch it, if so.
return execute(cmd)
end
+
+ # And then define an instance method that just calls the class method.
+ # We need both, so both instances and classes can easily run the commands.
unless method_defined? name
- define_method(name) do |args|
- self.class.send(name, args)
+ define_method(name) do |*args|
+ self.class.send(name, *args)
end
end
end
diff --git a/lib/puppet/provider/nameservice.rb b/lib/puppet/provider/nameservice.rb
index d33ab1936..b10ac34ad 100644
--- a/lib/puppet/provider/nameservice.rb
+++ b/lib/puppet/provider/nameservice.rb
@@ -307,6 +307,9 @@ class Puppet::Provider::NameService < Puppet::Provider
def set(param, value)
#self.class.validate(param, value)
cmd = modifycmd(param, value)
+ unless cmd.is_a?(Array)
+ raise Puppet::DevError, "Nameservice command must be an array"
+ end
begin
execute(cmd)
rescue Puppet::ExecutionFailure => detail
diff --git a/lib/puppet/provider/nameservice/netinfo.rb b/lib/puppet/provider/nameservice/netinfo.rb
index 313b41753..54f2e8c00 100644
--- a/lib/puppet/provider/nameservice/netinfo.rb
+++ b/lib/puppet/provider/nameservice/netinfo.rb
@@ -12,7 +12,7 @@ class NetInfo < Puppet::Provider::NameService
# Attempt to flush the database, but this doesn't seem to work at all.
def self.flush
begin
- output = execute("/usr/sbin/lookupd -flushcache 2>&1")
+ output = execute(["/usr/sbin/lookupd", "-flushcache"])
rescue Puppet::ExecutionFailure
# Don't throw an error; it's just a failed cache flush
Puppet.err "Could not flush lookupd cache: %s" % output
@@ -89,7 +89,7 @@ class NetInfo < Puppet::Provider::NameService
end
begin
- output = execute(cmd.join(" "))
+ output = execute(cmd)
rescue Puppet::ExecutionFailure => detail
Puppet.err "Failed to call nireport: %s" % detail
return nil
@@ -111,7 +111,7 @@ class NetInfo < Puppet::Provider::NameService
cmd << "/" << "/%s/%s" %
[self.class.netinfodir(), @model[:name]]
- return cmd.join(" ")
+ return cmd
end
def deletecmd
@@ -175,14 +175,16 @@ class NetInfo < Puppet::Provider::NameService
cmd << "-createprop" << "/" << "/%s/%s" %
[self.class.netinfodir, @model[:name]]
+ value = [value] unless value.is_a?(Array)
if key = netinfokey(param)
- cmd << key << "'%s'" % value
+ cmd << key
+ cmd += value
else
raise Puppet::DevError,
"Could not find netinfokey for state %s" %
self.class.name
end
- cmd.join(" ")
+ cmd
end
# Determine the flag to pass to our command.
@@ -196,11 +198,10 @@ class NetInfo < Puppet::Provider::NameService
end
def setuserlist(group, list)
- cmd = "#{command(:niutil)} -createprop / /groups/%s users %s" %
- [group, list.join(",")]
+ cmd = [command(:niutil), "-createprop", "/", "/groups/%s" % group, "users", list.join(",")]
begin
output = execute(cmd)
- rescue Puppet::Execution::Failure => detail
+ rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Failed to set user list on %s: %s" %
[group, detail]
end
diff --git a/lib/puppet/provider/package/apple.rb b/lib/puppet/provider/package/apple.rb
index 4238447a3..7f1c93e5b 100755
--- a/lib/puppet/provider/package/apple.rb
+++ b/lib/puppet/provider/package/apple.rb
@@ -44,7 +44,7 @@ Puppet::Type.type(:package).provide :apple do
self.fail "Mac OS X packages must specify a package source"
end
- installer "-pkg #{source} -target /"
+ installer "-pkg", source, "-target", "/"
end
end
diff --git a/lib/puppet/provider/package/darwinport.rb b/lib/puppet/provider/package/darwinport.rb
index 43e9bce5b..729371db5 100755
--- a/lib/puppet/provider/package/darwinport.rb
+++ b/lib/puppet/provider/package/darwinport.rb
@@ -21,6 +21,7 @@ Puppet::Type.type(:package).provide :darwinport do
}
hash.delete :location
+ hash[:provider] = self.name
yield hash.dup
else
raise Puppet::DevError,
diff --git a/lib/puppet/provider/package/gem.rb b/lib/puppet/provider/package/gem.rb
index 0fb55c67c..24f997613 100755
--- a/lib/puppet/provider/package/gem.rb
+++ b/lib/puppet/provider/package/gem.rb
@@ -6,16 +6,16 @@ Puppet::Type.type(:package).provide :gem do
commands :gem => "gem"
def self.gemlist(hash)
- command = "#{command(:gem)} list "
+ command = [command(:gem), "list"]
if hash[:local]
- command += "--local "
+ command << "--local"
else
- command += "--remote "
+ command << "--remote"
end
if name = hash[:justme]
- command += name
+ command << name
end
begin
@@ -61,17 +61,17 @@ Puppet::Type.type(:package).provide :gem do
end
def install(useversion = true)
- command = "install "
+ command = ["install"]
if (! @model.should(:ensure).is_a? Symbol) and useversion
- command += "-v %s " % @model.should(:ensure)
+ command << "-v" << @model.should(:ensure)
end
if source = @model[:source]
- command += source
+ command << source
else
- command += @model[:name]
+ command << @model[:name]
end
- gem command
+ gem(*command)
end
def latest
@@ -86,7 +86,7 @@ Puppet::Type.type(:package).provide :gem do
end
def uninstall
- gem "uninstall -x -a #{@model[:name]}"
+ gem "uninstall", "-x", "-a", @model[:name]
end
def update
diff --git a/lib/puppet/provider/user/netinfo.rb b/lib/puppet/provider/user/netinfo.rb
index 79469fa24..6f82d1d34 100644
--- a/lib/puppet/provider/user/netinfo.rb
+++ b/lib/puppet/provider/user/netinfo.rb
@@ -9,6 +9,13 @@ Puppet::Type.type(:user).provide :netinfo, :parent => Puppet::Provider::NameServ
options :comment, :key => "realname"
defaultfor :operatingsystem => :darwin
+
+ def gid=(value)
+ unless value.is_a?(Integer)
+ raise ArgumentError, "gid= only accepts integers, not %s(%s)" % [value.class, value.inspect]
+ end
+ super
+ end
# The list of all groups the user is a member of. Different
# user mgmt systems will need to override this method.
@@ -71,16 +78,12 @@ Puppet::Type.type(:user).provide :netinfo, :parent => Puppet::Provider::NameServ
end
end
end
-
- def setuserlist(group, list)
- cmd = "#{command(:niutil)} -createprop / /groups/%s users %s" %
- [group, list.join(",")]
- begin
- output = execute(cmd)
- rescue Puppet::ExecutionFailure
- raise Puppet::Error,
- "Failed to set groups: %s" % output
+
+ def uid=(value)
+ unless value.is_a?(Integer)
+ raise ArgumentError, "uid= only accepts integers"
end
+ super
end
end
diff --git a/lib/puppet/suidmanager.rb b/lib/puppet/suidmanager.rb
index b65b5eb60..659ffaab8 100644
--- a/lib/puppet/suidmanager.rb
+++ b/lib/puppet/suidmanager.rb
@@ -35,22 +35,12 @@ module Puppet
end
old_egid = old_euid = nil
if new_egid
- saved_state_egid = new_egid
- new_egid = Puppet::Util.gid(new_egid)
- if new_egid == nil
- raise Puppet::Error, "Invalid group: %s" % saved_state_egid
- end
old_egid = self.egid
- self.egid = new_egid
+ self.egid = convert_xid(:gid, new_egid)
end
if new_euid
- saved_state_euid = new_euid
- new_euid = Puppet::Util.uid(new_euid)
- if new_euid == nil
- raise Puppet::Error, "Invalid user: %s" % saved_state_euid
- end
old_euid = self.euid
- self.euid = new_euid
+ self.euid = convert_xid(:uid, new_euid)
end
return yield
@@ -58,23 +48,24 @@ module Puppet
self.euid = old_euid if old_euid
self.egid = old_egid if old_egid
end
+
+ # Make sure the passed argument is a number.
+ def convert_xid(type, id)
+ map = {:gid => :group, :uid => :user}
+ raise ArgumentError, "Invalid id type %s" % type unless map.include?(type)
+ ret = Puppet::Util.send(type, id)
+ if ret == nil
+ raise Puppet::Error, "Invalid %s: %s" % [map[type], id]
+ end
+ return ret
+ end
- module_function :asuser
+ module_function :asuser, :convert_xid
def run_and_capture(command, new_uid=nil, new_gid=nil)
output = nil
-
- asuser(new_uid, new_gid) do
- # capture both stdout and stderr unless we are on ruby < 1.8.4
- # NOTE: this would be much better facilitated with a specialized popen()
- # (see the test suite for more details.)
- if new_uid and (Facter['rubyversion'].value <=> "1.8.4") < 0
- Puppet::Util::Warnings.warnonce "Cannot capture STDERR when running as another user on Ruby < 1.8.4"
- output = %x{#{command}}
- else
- output = %x{#{command} 2>&1}
- end
- end
+
+ output = Puppet::Util.execute(command, false, new_uid, new_gid)
[output, $?.dup]
end
@@ -89,7 +80,7 @@ module Puppet
end
status
end
-
+
module_function :system
end
end
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 59b42f82c..7c7aaa38b 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -506,6 +506,7 @@ class Transaction
def skip?(resource)
skip = false
if ! tagged?(resource)
+ p resource.tags
resource.debug "Not tagged with %s" % tags.join(", ")
elsif ! scheduled?(resource)
resource.debug "Not scheduled"
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index c9fa0aa36..44903f40c 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -536,13 +536,13 @@ module Puppet
end
env[name] = value
else
- warning "Cannot understand env setting '%s'" % setting
+ warning "Cannot understand env setting %s" % setting.inspect
end
end
end
withenv env do
- output, status = Puppet::SUIDManager.run_and_capture(command, self[:user], self[:group])
+ output, status = Puppet::SUIDManager.run_and_capture([command], self[:user], self[:group])
# The shell returns 127 if the command is missing.
if status.exitstatus == 127
raise ArgumentError, output
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb
index abc0ad30c..d11d1894c 100755
--- a/lib/puppet/type/host.rb
+++ b/lib/puppet/type/host.rb
@@ -22,9 +22,7 @@ module Puppet
# Make sure our "is" value is always an array.
def is
current = super
- unless current.is_a? Array
- current = [current]
- end
+ current = [current] unless current.is_a? Array
current
end
@@ -48,7 +46,16 @@ module Puppet
def retrieve
super
- @is = [@is] unless @is.is_a?(Array)
+ case @is
+ when String
+ @is = @is.split(/\s*,\s*/)
+ when Symbol:
+ @is = [@is]
+ when Array
+ # nothing
+ else
+ raise Puppet::DevError, "Invalid @is type %s" % @is.class
+ end
end
# We actually want to return the whole array here, not just the first
diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb
index 661d10e4a..e9cd2372e 100755
--- a/lib/puppet/type/user.rb
+++ b/lib/puppet/type/user.rb
@@ -124,6 +124,10 @@ module Puppet
newstate(:gid) do
desc "The user's primary group. Can be specified numerically or
by name."
+
+ def found?
+ defined? @found and @found
+ end
munge do |gid|
method = :getgrgid
@@ -157,7 +161,7 @@ module Puppet
unless defined? @should
return super
end
- unless defined? @found and @found
+ unless found?
@should = @should.each { |val|
next unless val
Puppet::Util.gid(val)
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 246be2bd0..906184c18 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -267,18 +267,60 @@ module Util
end
# Execute the desired command, and return the status and output.
- def execute(command, failonfail = true)
+ def execute(command, failonfail = true, uid = nil, gid = nil)
+ if command.is_a?(Array)
+ command = command.collect { |i| i.to_s }
+ str = command.join(" ")
+ else
+ raise "Must pass an array"
+ str = command
+ end
if respond_to? :debug
- debug "Executing '%s'" % command
+ debug "Executing '%s'" % str
else
- Puppet.debug "Executing '%s'" % command
+ Puppet.debug "Executing '%s'" % str
+ end
+
+ if uid
+ uid = Puppet::SUIDManager.convert_xid(:uid, uid)
+ end
+ if gid
+ gid = Puppet::SUIDManager.convert_xid(:gid, gid)
+ end
+
+ @@os ||= Facter.value(:operatingsystem)
+ output = nil
+ IO.popen("-") do |f|
+ if f
+ output = f.read
+ else
+ begin
+ $stderr.close
+ $stderr = $stdout.dup
+ if gid
+ Process.egid = gid
+ Process.gid = gid unless @@os == "Darwin"
+ end
+ if uid
+ Process.euid = uid
+ Process.uid = uid unless @@os == "Darwin"
+ end
+ if command.is_a?(Array)
+ system(*command)
+ else
+ system(command)
+ end
+ exit!($?.exitstatus)
+ rescue => detail
+ puts detail.to_s
+ exit!(1)
+ end
+ end
end
- command += " 2>&1" unless command =~ />/
- output = %x{#{command}}
if failonfail
unless $? == 0
- raise ExecutionFailure, "Could not execute '%s': %s" % [command, output]
+ raise ExecutionFailure, "Execution of '%s' returned %s: %s" % [str, $?, output]
end
end
diff --git a/test/data/providers/package/testpackages.yaml b/test/data/providers/package/testpackages.yaml
index 47998ed33..8d8935eb9 100644
--- a/test/data/providers/package/testpackages.yaml
+++ b/test/data/providers/package/testpackages.yaml
@@ -57,6 +57,7 @@
:files:
- /Users/luke/Documents/Puppet/pkgtesting.pkg
:name: pkgtesting
+ :cleanup: rm -rf /Library/Receipts/pkgtesting.pkg/ /tmp/file
- :provider: :gem
:name: wxrubylayouts
:versions:
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 2ae4b1b13..8c67b5b56 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -521,7 +521,9 @@ class TestTransactions < Test::Unit::TestCase
# Make sure all of the components are gone
comps = graph.vertices.find_all { |v| v.is_a?(Puppet::Type::Component)}
- assert(comps.empty?, "Deps graph still contains components")
+ assert(comps.empty?, "Deps graph still contains components %s" % comps.inspect)
+
+ assert_equal([], comps, "Deps graph still contains components")
# It must be reversed because of how topsort works
sorted = graph.topsort.reverse
diff --git a/test/providers/package.rb b/test/providers/package.rb
index 6b175c44a..6de88eace 100755
--- a/test/providers/package.rb
+++ b/test/providers/package.rb
@@ -118,6 +118,10 @@ class TestPackageProvider < Test::Unit::TestCase
return
end
end
+
+ if cleancmd = hash[:cleanup]
+ hash.delete(:cleanup)
+ end
pkg = nil
assert_nothing_raised(
@@ -141,8 +145,14 @@ class TestPackageProvider < Test::Unit::TestCase
end
cleanup do
- pkg[:ensure] = :absent
- assert_apply(pkg)
+ if pkg.provider.respond_to?(:uninstall)
+ pkg[:ensure] = :absent
+ assert_apply(pkg)
+ else
+ if cleancmd
+ system(cleancmd)
+ end
+ end
end
assert_nothing_raised("Could not install package") do
@@ -175,11 +185,13 @@ class TestPackageProvider < Test::Unit::TestCase
end
# Now remove the package
- assert_nothing_raised do
- provider.uninstall
- end
+ if provider.respond_to?(:uninstall)
+ assert_nothing_raised do
+ provider.uninstall
+ end
- assert_absent(provider)
+ assert_absent(provider)
+ end
end
# Now create a separate test method for each package
diff --git a/test/providers/provider.rb b/test/providers/provider.rb
index bde265fff..61090d5db 100755
--- a/test/providers/provider.rb
+++ b/test/providers/provider.rb
@@ -90,7 +90,7 @@ class TestProvider < Test::Unit::TestCase
inst = provider.new(nil)
assert_nothing_raised do
[provider, inst].each do |thing|
- out = thing.echo "some text"
+ out = thing.echo "some", "text"
assert_equal("some text\n", out)
end
end
@@ -167,12 +167,12 @@ class TestProvider < Test::Unit::TestCase
inst = provider.new(nil)
assert_raise(Puppet::ExecutionFailure) do
- inst.cmd "some arguments"
+ inst.cmd "some", "arguments"
end
out = nil
begin
- inst.cmd "some arguments"
+ inst.cmd "some", "arguments"
rescue Puppet::ExecutionFailure => detail
out = detail.to_s
end
@@ -180,10 +180,8 @@ class TestProvider < Test::Unit::TestCase
assert(out =~ /A Failure/,
"Did not receive command output on failure")
- assert(out =~ /Could not execute/,
+ assert(out =~ /Execution of/,
"Did not receive info wrapper on failure")
-
-
end
end
diff --git a/test/providers/user.rb b/test/providers/user.rb
index 25579ece0..40d3828cc 100755
--- a/test/providers/user.rb
+++ b/test/providers/user.rb
@@ -29,7 +29,6 @@ class TestUserProvider < Test::Unit::TestCase
end
}
super
- #Puppet.type(:user).clear
end
case Facter["operatingsystem"].value
@@ -51,20 +50,17 @@ class TestUserProvider < Test::Unit::TestCase
st.name == param
}
- output = %x{nireport / /users name #{state.netinfokey}}
- output.split("\n").each { |line|
- if line =~ /^(\w+)\s+(.+)$/
- username = $1
- id = $2.sub(/\s+$/, '')
- if username == user.name
- if id =~ /^[-0-9]+$/
- return Integer(id)
- else
- return id
- end
+ prov = Puppet::Type.type(:user).defaultprovider
+ output = prov.report(param)
+ # output = %x{nireport / /users name #{prov.netinfokey(param)}}
+ output.each { |hash|
+ if hash[:name] == user.name
+ val = hash[param]
+ if val =~ /^[-0-9]+$/
+ return Integer(val)
+ else
+ return val
end
- else
- raise "Could not match %s" % line
end
}
@@ -125,8 +121,8 @@ class TestUserProvider < Test::Unit::TestCase
case param
when :name: name
when :ensure: :present
- when :comment: "Puppet Testing User %s" % name
- when :gid: nonrootgroup.name
+ when :comment: "Puppet's Testing User %s" % name # use a single quote a la #375
+ when :gid: nonrootgroup.gid
when :shell: findshell()
when :home: "/home/%s" % name
else
@@ -222,11 +218,12 @@ class TestUserProvider < Test::Unit::TestCase
def attrtest_comment(user)
old = user.comment
+ newname = "Billy O'Neal" # use a single quote, a la #372
assert_nothing_raised {
- user.comment = "A different comment"
+ user.comment = newname
}
- assert_equal("A different comment", current?(:comment, user),
+ assert_equal(newname, current?(:comment, user),
"Comment was not changed")
assert_nothing_raised {
@@ -423,7 +420,7 @@ class TestUserProvider < Test::Unit::TestCase
user.create
}
- assert_equal("Puppet Testing User pptest",
+ assert_equal("Puppet's Testing User pptest",
user.comment,
"Comment was not set")
@@ -453,14 +450,13 @@ class TestUserProvider < Test::Unit::TestCase
assert_nothing_raised {
user.create
}
- assert_equal("Puppet Testing User pptest", user.comment,
+ assert_equal("Puppet's Testing User pptest", user.comment,
"Comment was not set")
tests = Puppet::Type.type(:user).validstates
just = nil
tests.each { |test|
- next unless test == :groups
if self.respond_to?("attrtest_%s" % test)
self.send("attrtest_%s" % test, user)
else
diff --git a/test/puppet/tc_suidmanager.rb b/test/puppet/tc_suidmanager.rb
index 674dfff8e..5561992e3 100755
--- a/test/puppet/tc_suidmanager.rb
+++ b/test/puppet/tc_suidmanager.rb
@@ -97,7 +97,7 @@ class TestSUIDManager < Test::Unit::TestCase
else
uid = Process.uid
end
- cmd = "/bin/echo $EUID"
+ cmd = [%{/bin/echo $EUID}]
output = Puppet::SUIDManager.run_and_capture(cmd, uid)[0].chomp
assert_equal(uid.to_s, output)
end
diff --git a/test/rails/rails.rb b/test/rails/rails.rb
index c0f902d65..1342437bd 100755
--- a/test/rails/rails.rb
+++ b/test/rails/rails.rb
@@ -17,16 +17,6 @@ class TestRails < Test::Unit::TestCase
include PuppetTest::ResourceTesting
include PuppetTest::RailsTesting
- def setup
- super
- railsinit
- end
-
- def teardown
- railsteardown
- super
- end
-
def test_includerails
assert_nothing_raised {
require 'puppet/rails'
diff --git a/test/types/host.rb b/test/types/host.rb
index 580ecbf3b..18d87db77 100755
--- a/test/types/host.rb
+++ b/test/types/host.rb
@@ -12,7 +12,7 @@ class TestHost < Test::Unit::TestCase
def setup
super
- @hosttype = Puppet.type(:host)
+ @hosttype = Puppet::Type.type(:host)
@provider = @hosttype.defaultprovider
@@ -68,6 +68,10 @@ class TestHost < Test::Unit::TestCase
if Facter.value(:operatingsystem) != "Darwin" or Process.uid == 0
def test_simplehost
host = nil
+ # We want to actually use the netinfo provider on darwin
+ if Facter.value(:operatingsystem) == "Darwin"
+ Puppet::Type.type(:host).defaultprovider = nil
+ end
assert_nothing_raised {
host = Puppet.type(:host).create(
@@ -76,6 +80,7 @@ class TestHost < Test::Unit::TestCase
)
}
+ host.retrieve
assert_events([:host_created], host)
assert_nothing_raised { host.retrieve }
@@ -118,12 +123,8 @@ class TestHost < Test::Unit::TestCase
host.retrieve
- if Facter.value(:operatingsystem) == "Darwin"
- # Netinfo can't handle arrays right now
- assert_equal(%w{madstop}, host.is(:alias))
- else
- assert_equal(%w{madstop kirby yayness}, host.is(:alias))
- end
+ assert_equal(%w{madstop kirby yayness}, host.is(:alias))
+
host[:ensure] = :absent
assert_events([:host_removed], host)
end
diff --git a/test/util/utiltest.rb b/test/util/utiltest.rb
index ffb2ef347..74a29d56f 100755
--- a/test/util/utiltest.rb
+++ b/test/util/utiltest.rb
@@ -261,6 +261,52 @@ class TestPuppetUtil < Test::Unit::TestCase
assert_equal(nil, ret)
end
+
+ def test_execute
+ command = tempfile()
+ File.open(command, "w") { |f|
+ f.puts %{#!/bin/sh\n/bin/echo "$1">&1; echo "$2">&2}
+ }
+ File.chmod(0755, command)
+ output = nil
+ assert_nothing_raised do
+ output = Puppet::Util.execute([command, "yaytest", "funtest"])
+ end
+ assert_equal("yaytest\nfuntest\n", output)
+
+ # Now try it with a single quote
+ assert_nothing_raised do
+ output = Puppet::Util.execute([command, "yay'test", "funtest"])
+ # output = Puppet::Util.execute(command)
+
+ end
+ assert_equal("yay'test\nfuntest\n", output)
+
+ # Now test that we correctly fail if the command returns non-zero
+ assert_raise(Puppet::ExecutionFailure) do
+ out = Puppet::Util.execute(["touch", "/no/such/file/could/exist"])
+ end
+
+ # And that we can tell it not to fail
+ assert_nothing_raised() do
+ out = Puppet::Util.execute(["touch", "/no/such/file/could/exist"], false)
+ end
+
+ if Process.uid == 0
+ # Make sure we correctly set our uid and gid
+ user = nonrootuser
+ group = nonrootgroup
+ file = tempfile()
+ assert_nothing_raised do
+ Puppet::Util.execute(["touch", file], true, user.name, group.name)
+ end
+ assert(FileTest.exists?(file), "file was not created")
+ assert_equal(user.uid, File.stat(file).uid, "uid was not set correctly")
+
+ # We can't really check the gid, because it just behaves too inconsistently everywhere.
+ # assert_equal(group.gid, File.stat(file).gid, "gid was not set correctly")
+ end
+ end
end
# $Id$