diff options
-rw-r--r-- | CHANGELOG | 4 | ||||
-rw-r--r-- | Rakefile | 2 | ||||
-rw-r--r-- | lib/puppet/networkclient.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parameter.rb | 52 | ||||
-rw-r--r-- | lib/puppet/type.rb | 3 | ||||
-rwxr-xr-x | lib/puppet/type/nameservice.rb | 15 | ||||
-rw-r--r-- | lib/puppet/type/pfile.rb | 4 | ||||
-rw-r--r-- | lib/puppet/util.rb | 45 | ||||
-rw-r--r-- | test/other/log.rb | 7 | ||||
-rwxr-xr-x | test/puppet/utiltest.rb | 100 | ||||
-rwxr-xr-x | test/types/group.rb | 16 |
11 files changed, 191 insertions, 60 deletions
@@ -1,3 +1,7 @@ +0.13.2 + Changed package[answerfile] to package[adminfile], and added package[responsefile] + Fixed a bunch of internal functions to behave more consistently and usefully + 0.13.1 Fixed RPM spec files to create puppet user and group (lutter) Fixed crontab reading and writing (luke) @@ -386,8 +386,8 @@ task :hosttest do if $? != 0 file = File.join("/tmp", "%stest.out" % host) File.open(file, "w") { |of| of.print out } - puts "%s failed; output is in %s" % [host, file] puts out + puts "%s failed; output is in %s" % [host, file] end #sh %{ssh #{host} 'cd #{cwd}/test; sudo ./test' 2>&1} } diff --git a/lib/puppet/networkclient.rb b/lib/puppet/networkclient.rb index fc204ce10..766acef1b 100644 --- a/lib/puppet/networkclient.rb +++ b/lib/puppet/networkclient.rb @@ -68,6 +68,9 @@ module Puppet Puppet.err "Could not call %s.%s: %s" % [namespace, method, detail.inspect] #raise NetworkClientError.new(detail.to_s) + if Puppet[:debug] + puts detail.backtrace + end raise end } diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index 25789e9af..18ed07d35 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -11,6 +11,10 @@ module Puppet if block define_method(:default, &block) else + if value.nil? + raise Puppet::DevError, + "Either a default value or block must be provided" + end define_method(:default) do value end end end @@ -104,6 +108,9 @@ module Puppet rescue ArgumentError, Puppet::Error, TypeError raise rescue => detail + if Puppet[:debug] + puts detail.backtrace + end raise Puppet::DevError, "Validate method failed for class %s: %s" % [self.name, detail] @@ -145,7 +152,13 @@ module Puppet @aliasvalues ||= {} #[@aliasvalues.keys, @parametervalues.keys].flatten - @parametervalues.dup + if @parametervalues.is_a? Array + return @parametervalues.dup + elsif @parametervalues.is_a? Hash + return @parametervalues.keys + else + return [] + end end end @@ -162,36 +175,6 @@ module Puppet attr_accessor :parent - # This doesn't work, because the instance_eval doesn't bind the inner block - # only the outer one. -# def munge(value) -# if munger = self.class.munger -# return @parent.instance_eval { -# munger.call(value) -# } -# else -# return value -# end -# end -# -# def validate(value) -# if validater = self.class.validater -# return @parent.instance_eval { -# validater.call(value) -# } -# end -# end - - #def default - # default = self.class.default - # if default.is_a?(Proc) - # val = self.instance_eval(&default) - # return val - # else - # return default - # end - #end - def devfail(msg) self.fail(Puppet::DevError, msg) end @@ -276,16 +259,17 @@ module Puppet # Verify that the passed value is valid. validate do |value| - if self.class.values.empty? + values = self.class.values + if values.empty? # This parameter isn't using defined values to do its work. return end unless value.is_a?(Symbol) value = value.to_s.intern end - unless self.class.values.include?(value) or self.class.alias(value) + unless values.include?(value) or self.class.alias(value) self.fail "Invalid '%s' value '%s'. Valid values are '%s'" % - [self.class.name, value, self.class.values.join(", ")] + [self.class.name, value, values.join(", ")] end end diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index c90185fc1..9469d8b0a 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1497,7 +1497,8 @@ class Type < Puppet::Element next if self.attrset?(type, klass.name) obj = self.newattr(type, klass) - if value = obj.default + value = obj.default + unless value.nil? #self.debug "defaulting %s to %s" % [obj.name, obj.default] obj.value = value else diff --git a/lib/puppet/type/nameservice.rb b/lib/puppet/type/nameservice.rb index 2f812ac61..1f132ee68 100755 --- a/lib/puppet/type/nameservice.rb +++ b/lib/puppet/type/nameservice.rb @@ -139,21 +139,6 @@ class State return nil end end -# # if the object needs to be created or deleted, -# # depend on another method to do it all at once -# if @is == :absent or self.should == :absent -# Puppet.info "creating" -# event = syncname() -# -# Puppet.info "created with event %s" % event -# -# return event -# # if the whole object is created at once, just return -# # an event saying so -# #if self.class.allatonce? -# # return event -# #end -# end unless @parent.exists? self.devfail "%s %s does not exist; cannot set %s" % diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 082b2f5dc..6f064ee2a 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -440,9 +440,11 @@ module Puppet end end + #ignore = self[:ignore] || false ignore = self[:ignore] - #self.warning "Listing path %s" % path.inspect + #self.warning "Listing path %s with ignore %s" % + # [path.inspect, ignore.inspect] desc = server.list(path, r, ignore) desc.split("\n").each { |line| diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 0d2d73900..1d5aff4d1 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -21,7 +21,11 @@ module Util # The gid has to be changed first, because, well, otherwise we won't # be able to if group - gid = self.gid(group) + if group.is_a? Integer + gid = group + else + gid = self.gid(group) + end if Process.gid != gid oldgid = Process.gid @@ -34,6 +38,11 @@ module Util end if user + if user.is_a? Integer + uid = user + else + uid = self.uid(user) + end uid = self.uid(user) # Now change the uid if Process.uid != uid @@ -133,11 +142,21 @@ module Util obj = nil # We want to look the group up either way - if group.is_a?(Integer) + if group.is_a?(Integer) + # If this doesn't find anything obj = Puppet.type(:group).find { |gobj| gobj.should(:gid) == group || gobj.is(:gid) == group } + + unless obj + begin + gobj = Etc.getgrgid(group) + gid = gobj.gid + rescue ArgumentError => detail + # ignore it; we couldn't find the group + end + end else unless obj = Puppet.type(:group)[group] obj = Puppet.type(:group).create( @@ -160,8 +179,22 @@ module Util if user =~ /^\d+$/ user = Integer(user) end + if user.is_a?(Integer) - uid = user + # If this doesn't find anything + obj = Puppet.type(:user).find { |uobj| + uobj.should(:uid) == user || + uobj.is(:uid) == user + } + + unless obj + begin + uobj = Etc.getpwuid(user) + uid = uobj.uid + rescue ArgumentError => detail + # ignore it; we couldn't find the user + end + end else unless obj = Puppet.type(:user)[user] obj = Puppet.type(:user).create( @@ -169,11 +202,11 @@ module Util :check => [:uid, :gid] ) end + end + + if obj obj.retrieve uid = obj.is(:uid) - unless uid.is_a?(Integer) - raise Puppet::Error, "Could not find user %s" % user - end end return uid diff --git a/test/other/log.rb b/test/other/log.rb index ad13b15bf..a138b198b 100644 --- a/test/other/log.rb +++ b/test/other/log.rb @@ -14,9 +14,15 @@ require 'test/unit' class TestLog < Test::Unit::TestCase include TestPuppet + def setup + super + @oldloglevel = Puppet::Log.level + end + def teardown super Puppet::Log.close + Puppet::Log.level = @oldloglevel end def getlevels @@ -44,6 +50,7 @@ class TestLog < Test::Unit::TestCase def test_logfile fact = nil levels = nil + oldlevel = Puppet::Log.level Puppet::Log.level = :debug levels = getlevels logfile = tempfile() diff --git a/test/puppet/utiltest.rb b/test/puppet/utiltest.rb index 5ca2e4343..ec398d8b9 100755 --- a/test/puppet/utiltest.rb +++ b/test/puppet/utiltest.rb @@ -43,6 +43,106 @@ class TestPuppetUtil < Test::Unit::TestCase threads.each { |th| th.join } end + # First verify we can convert a known user + def test_gidbyname + %x{groups}.split(" ").each { |group| + gid = nil + assert_nothing_raised { + gid = Puppet::Util.gid(group) + } + + assert(gid, "Could not retrieve gid for %s" % group) + + assert(Puppet.type(:group)[group], "Util did not create %s" % group) + } + end + + # Then verify we can retrieve a known group by gid + def test_gidbyid + %x{groups}.split(" ").each { |group| + obj = Puppet.type(:group).create( + :name => group, + :check => [:gid] + ) + obj.retrieve + id = obj.is(:gid) + gid = nil + assert_nothing_raised { + gid = Puppet::Util.gid(id) + } + + assert(gid, "Could not retrieve gid for %s" % group) + assert_equal(id, gid, "Got mismatched ids") + } + end + + # Finally, verify that we can find groups by id even if we don't + # know them + def test_gidbyunknownid + gid = nil + group = Process.gid + assert_nothing_raised { + gid = Puppet::Util.gid(group) + } + + assert(gid, "Could not retrieve gid for %s" % group) + assert_equal(group, gid, "Got mismatched ids") + end + + def user + require 'etc' + unless defined? @user + obj = Etc.getpwuid(Process.uid) + @user = obj.name + end + return @user + end + + # And do it all over again for users + # First verify we can convert a known user + def test_uidbyname + user = user() + uid = nil + assert_nothing_raised { + uid = Puppet::Util.uid(user) + } + + assert(uid, "Could not retrieve uid for %s" % user) + assert_equal(Process.uid, uid, "UIDs did not match") + assert(Puppet.type(:user)[user], "Util did not create %s" % user) + end + + # Then verify we can retrieve a known user by uid + def test_uidbyid + user = user() + obj = Puppet.type(:user).create( + :name => user, + :check => [:uid] + ) + obj.retrieve + id = obj.is(:uid) + uid = nil + assert_nothing_raised { + uid = Puppet::Util.uid(id) + } + + assert(uid, "Could not retrieve uid for %s" % user) + assert_equal(id, uid, "Got mismatched ids") + end + + # Finally, verify that we can find users by id even if we don't + # know them + def test_uidbyunknownid + uid = nil + user = Process.uid + assert_nothing_raised { + uid = Puppet::Util.uid(user) + } + + assert(uid, "Could not retrieve uid for %s" % user) + assert_equal(user, uid, "Got mismatched ids") + end + unless Process.uid == 0 $stderr.puts "Run as root to perform Utility tests" def test_nothing diff --git a/test/types/group.rb b/test/types/group.rb index 6f60de3e3..e1b4e4fed 100755 --- a/test/types/group.rb +++ b/test/types/group.rb @@ -214,6 +214,18 @@ class TestGroup < Test::Unit::TestCase assert_equal(Process.gid, user.is(:gid), "Retrieved UID does not match") end + def test_ensurevals + gobj = nil + assert_nothing_raised { + gobj = Puppet.type(:group).create( + :name => name, + :ensure => :exists + ) + } + + assert_equal(false, gobj.state(:ensure)) + end + if Process.uid == 0 def test_mkgroup gobj = nil @@ -234,10 +246,10 @@ class TestGroup < Test::Unit::TestCase #} #end assert(missing?(name), "Group %s is still present" % name) - assert_nothing_raised { gobj = Puppet.type(:group).create( - :name => name + :name => name, + :ensure => :present ) comp = newcomp("groupmaker %s" % name, gobj) |