Another round of bug-fixes in preparation for 0.20.0
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1813 980ebf18-57e1-0310-9a29-db15c13687c0
This commit is contained in:
Родитель
ead49c673e
Коммит
7b34e25d1c
|
@ -149,7 +149,7 @@ class Puppet::Provider
|
|||
found = values.find do |v|
|
||||
result == v.to_s.downcase.intern
|
||||
end
|
||||
debug "Not suitable: %s not in %s" [check, values]
|
||||
debug "Not suitable: %s not in %s" % [check, values]
|
||||
return false unless found
|
||||
else
|
||||
return false
|
||||
|
@ -162,7 +162,11 @@ class Puppet::Provider
|
|||
|
||||
def self.to_s
|
||||
unless defined? @str
|
||||
@str = "%s provider %s" % [@model.name, self.name]
|
||||
if self.model
|
||||
@str = "%s provider %s" % [@model.name, self.name]
|
||||
else
|
||||
@str = "unattached provider %s" % [self.name]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -122,8 +122,9 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
|
|||
def hash
|
||||
@instances = allinstances()
|
||||
|
||||
namevar = @model.class.namevar
|
||||
if @instances and h = @instances.find do |o|
|
||||
o.is_a? Hash and o[:name] == @model[:name]
|
||||
o.is_a? Hash and o[namevar] == @model[namevar]
|
||||
end
|
||||
@me = h
|
||||
else
|
||||
|
|
|
@ -19,8 +19,8 @@ Puppet::Server::Report.newreport(:store, :useyaml => true) do
|
|||
config.setdefaults("reportclient-#{client}",
|
||||
"clientdir-#{client}" => { :default => dir,
|
||||
:mode => 0750,
|
||||
:owner => "$user",
|
||||
:group => "$group"
|
||||
:owner => Puppet[:user],
|
||||
:group => Puppet[:group]
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -28,37 +28,6 @@ module Puppet
|
|||
module_function method
|
||||
end
|
||||
|
||||
def run_and_capture(command, new_uid=self.euid, new_gid=self.egid)
|
||||
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 (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, $?.dup]
|
||||
end
|
||||
|
||||
module_function :run_and_capture
|
||||
|
||||
def system(command, new_uid=self.euid, new_gid=self.egid)
|
||||
status = nil
|
||||
asuser(new_uid, new_gid) do
|
||||
Kernel.system(command)
|
||||
status = $?.dup
|
||||
end
|
||||
status
|
||||
end
|
||||
|
||||
module_function :system
|
||||
|
||||
def asuser(new_euid=nil, new_egid=nil)
|
||||
# Unless we're root, don't do a damn thing.
|
||||
unless Process.uid == 0
|
||||
|
@ -91,6 +60,37 @@ module Puppet
|
|||
end
|
||||
|
||||
module_function :asuser
|
||||
|
||||
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 (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, $?.dup]
|
||||
end
|
||||
|
||||
module_function :run_and_capture
|
||||
|
||||
def system(command, new_uid=nil, new_gid=nil)
|
||||
status = nil
|
||||
asuser(new_uid, new_gid) do
|
||||
Kernel.system(command)
|
||||
status = $?.dup
|
||||
end
|
||||
status
|
||||
end
|
||||
|
||||
module_function :system
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ LABEL=/boot /boot ext3 defaults 1 2
|
|||
devpts /dev/pts devpts gid=5,mode=620 0 0
|
||||
tmpfs /dev/shm tmpfs defaults 0 0
|
||||
LABEL=/home /home ext3 defaults 1 2
|
||||
/home /homes auto bind
|
||||
/home /homes auto bind 0 2
|
||||
proc /proc proc defaults 0 0
|
||||
/dev/vg00/lv01 /spare ext3 defaults 1 2
|
||||
sysfs /sys sysfs defaults 0 0
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
require 'puppet'
|
||||
require 'test/unit'
|
||||
|
||||
# Yay; hackish but it works
|
||||
if ARGV.include?("-d")
|
||||
Puppet.debug = true
|
||||
end
|
||||
|
||||
module PuppetTest
|
||||
# Find the root of the Puppet tree; this is not the test directory, but
|
||||
# the parent of that dir.
|
||||
|
|
|
@ -5,10 +5,14 @@ module PuppetTest
|
|||
class FakeModel
|
||||
include Puppet::Util
|
||||
class << self
|
||||
attr_accessor :name
|
||||
attr_accessor :name, :realmodel
|
||||
@name = :fakemodel
|
||||
end
|
||||
|
||||
def self.namevar
|
||||
@realmodel.namevar
|
||||
end
|
||||
|
||||
def self.validstates
|
||||
Puppet::Type.type(@name).validstates
|
||||
end
|
||||
|
@ -154,6 +158,10 @@ module PuppetTest
|
|||
unless @@fakemodels.include? type
|
||||
@@fakemodels[type] = Class.new(FakeModel)
|
||||
@@fakemodels[type].name = type
|
||||
|
||||
model = Puppet::Type.type(type)
|
||||
raise("Could not find type %s" % type) unless model
|
||||
@@fakemodels[type].realmodel = model
|
||||
end
|
||||
|
||||
obj = @@fakemodels[type].new(name)
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
|
||||
|
||||
require 'puppettest'
|
||||
require 'puppettest/fileparsing'
|
||||
require 'puppet'
|
||||
require 'facter'
|
||||
|
||||
class TestParsedMounts < Test::Unit::TestCase
|
||||
include PuppetTest
|
||||
include PuppetTest::FileParsing
|
||||
|
||||
def setup
|
||||
super
|
||||
|
|
|
@ -20,10 +20,10 @@ class TestSUIDManager < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_metaprogramming_function_additions
|
||||
# NOTE: the way that we are dynamically generating the methods in SUIDManager for
|
||||
# the UID/GID calls was causing problems due to the modification
|
||||
# of a closure. Should the bug rear itself again, this test
|
||||
# will fail.
|
||||
# NOTE: the way that we are dynamically generating the methods in
|
||||
# SUIDManager for the UID/GID calls was causing problems due to the
|
||||
# modification of a closure. Should the bug rear itself again, this
|
||||
# test will fail.
|
||||
assert_nothing_raised do
|
||||
Puppet::SUIDManager.uid
|
||||
Puppet::SUIDManager.uid
|
||||
|
@ -49,12 +49,14 @@ class TestSUIDManager < Test::Unit::TestCase
|
|||
assert_uid_gid(user.uid, user.gid, tempfile)
|
||||
end
|
||||
end
|
||||
|
||||
def test_utiluid
|
||||
user = nonrootuser.name
|
||||
if @run
|
||||
assert_not_equal(nil, Puppet::Util.uid(user))
|
||||
end
|
||||
end
|
||||
|
||||
def test_asuser
|
||||
if @run
|
||||
user = nonrootuser
|
||||
|
@ -62,20 +64,21 @@ class TestSUIDManager < Test::Unit::TestCase
|
|||
|
||||
assert_nothing_raised do
|
||||
Puppet::SUIDManager.asuser(user.uid, user.gid) do
|
||||
uid = Puppet::SUIDManager.euid
|
||||
gid = Puppet::SUIDManager.egid
|
||||
uid = Process.euid
|
||||
gid = Process.egid
|
||||
end
|
||||
end
|
||||
assert_equal(user.uid, uid)
|
||||
assert_equal(user.gid, gid)
|
||||
end
|
||||
end
|
||||
|
||||
def test_system
|
||||
# NOTE: not sure what shells this will work on..
|
||||
if @run
|
||||
user = nonrootuser
|
||||
status = Puppet::SUIDManager.system("exit $EUID", user.uid, user.gid)
|
||||
assert_equal(status.exitstatus, user.uid)
|
||||
assert_equal(user.uid, status.exitstatus)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -87,8 +90,18 @@ class TestSUIDManager < Test::Unit::TestCase
|
|||
# works, we cannot just blindly echo to stderr. This little
|
||||
# hack gets around our problem, but the real problem is the
|
||||
# way that run_and_capture works.
|
||||
output = Puppet::SUIDManager.run_and_capture("ruby -e '$stderr.puts \"foo\"'")[0].chomp
|
||||
assert_equal(output, 'foo')
|
||||
user = nil
|
||||
uid = nil
|
||||
if Puppet::SUIDManager.uid == 0
|
||||
userobj = nonrootuser()
|
||||
user = userobj.name
|
||||
uid = userobj.uid
|
||||
else
|
||||
uid = Process.uid
|
||||
end
|
||||
cmd = "/bin/echo $EUID"
|
||||
output = Puppet::SUIDManager.run_and_capture(cmd, uid)[0].chomp
|
||||
assert_equal(uid.to_s, output)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -120,7 +120,7 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_initclass_include_and_extend
|
||||
sub, klass = testclasses("attributes")
|
||||
sub, klass = testclasses("include_and_extend")
|
||||
|
||||
incl = Module.new do
|
||||
attr_accessor :included
|
||||
|
|
Загрузка…
Ссылка в новой задаче