diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-18 18:15:43 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-18 18:15:43 +0000 |
| commit | 7b34e25d1cb4c70568ed05e01556a12994b19dbf (patch) | |
| tree | a7bdbcc9c2883f805a9c84a518a1b1513a0fc09a | |
| parent | ead49c673e352166d87f47cbbea2086d4c1fc2f7 (diff) | |
| download | puppet-7b34e25d1cb4c70568ed05e01556a12994b19dbf.tar.gz puppet-7b34e25d1cb4c70568ed05e01556a12994b19dbf.tar.xz puppet-7b34e25d1cb4c70568ed05e01556a12994b19dbf.zip | |
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
| -rw-r--r-- | lib/puppet/provider.rb | 8 | ||||
| -rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/reports/store.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/suidmanager.rb | 62 | ||||
| -rw-r--r-- | test/data/types/mount/linux.fstab | 2 | ||||
| -rwxr-xr-x | test/lib/puppettest.rb | 5 | ||||
| -rw-r--r-- | test/lib/puppettest/fakes.rb | 10 | ||||
| -rwxr-xr-x | test/providers/parsedmount.rb | 2 | ||||
| -rwxr-xr-x | test/puppet/tc_suidmanager.rb | 31 | ||||
| -rwxr-xr-x | test/util/classgen.rb | 2 |
10 files changed, 81 insertions, 48 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index e0f465159..5185b172b 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -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 diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index f690c03a4..35267c673 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -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 diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb index 82eebff39..a2ab797e1 100644 --- a/lib/puppet/reports/store.rb +++ b/lib/puppet/reports/store.rb @@ -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] } ) diff --git a/lib/puppet/suidmanager.rb b/lib/puppet/suidmanager.rb index 4f94ddde2..6e9f58867 100644 --- a/lib/puppet/suidmanager.rb +++ b/lib/puppet/suidmanager.rb @@ -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 diff --git a/test/data/types/mount/linux.fstab b/test/data/types/mount/linux.fstab index 06afe1242..978103b69 100644 --- a/test/data/types/mount/linux.fstab +++ b/test/data/types/mount/linux.fstab @@ -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 diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index de2747336..07e3e084e 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -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. diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb index 40fe96a10..338afe575 100644 --- a/test/lib/puppettest/fakes.rb +++ b/test/lib/puppettest/fakes.rb @@ -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) diff --git a/test/providers/parsedmount.rb b/test/providers/parsedmount.rb index a4bcb7534..0d146df34 100755 --- a/test/providers/parsedmount.rb +++ b/test/providers/parsedmount.rb @@ -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 diff --git a/test/puppet/tc_suidmanager.rb b/test/puppet/tc_suidmanager.rb index c8a77222a..1f4bd4ad2 100755 --- a/test/puppet/tc_suidmanager.rb +++ b/test/puppet/tc_suidmanager.rb @@ -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 diff --git a/test/util/classgen.rb b/test/util/classgen.rb index 2e8374437..6f935c010 100755 --- a/test/util/classgen.rb +++ b/test/util/classgen.rb @@ -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 |
