diff options
-rwxr-xr-x | lib/puppet/provider/port/parsed.rb | 340 | ||||
-rwxr-xr-x | lib/puppet/type/port.rb | 232 | ||||
-rwxr-xr-x | lib/puppet/type/user.rb | 2 | ||||
-rw-r--r-- | lib/puppet/type/yumrepo.rb | 2 | ||||
-rwxr-xr-x | test/types/host.rb | 15 | ||||
-rwxr-xr-x | test/types/mount.rb | 22 | ||||
-rwxr-xr-x | test/types/port.rb | 283 | ||||
-rwxr-xr-x | test/types/sshkey.rb | 49 |
8 files changed, 488 insertions, 457 deletions
diff --git a/lib/puppet/provider/port/parsed.rb b/lib/puppet/provider/port/parsed.rb index 17633e23a..f5f12d3a1 100755 --- a/lib/puppet/provider/port/parsed.rb +++ b/lib/puppet/provider/port/parsed.rb @@ -1,174 +1,174 @@ require 'puppet/provider/parsedfile' -services = nil -case Facter.value(:operatingsystem) -when "Solaris": services = "/etc/inet/services" -else - services = "/etc/services" -end - -Puppet::Type.type(:port).provide(:parsed, - :parent => Puppet::Provider::ParsedFile, - :default_target => services, - :filetype => :flat -) do - text_line :comment, :match => /^\s*#/ - text_line :blank, :match => /^\s*$/ - - # We're cheating horribly here -- we don't support ddp, because it assigns - # the same number to already-used names, and the same name to different - # numbers. - text_line :ddp, :match => /^\S+\s+\d+\/ddp/ - - # Also, just ignore the lines on OS X that don't have service names. - text_line :funky_darwin, :match => /^\s+\d+\// - - # We have to manually parse the line, since it's so darn complicated. - record_line :parsed, :fields => %w{name port protocols alias description}, - :optional => %w{alias description} do |line| - if line =~ /\/ddp/ - raise "missed ddp in %s" % line - end - # The record might contain multiple port lines separated by \n. - hashes = line.split("\n").collect { |l| parse_port(l) } - - # It's easy if there's just one hash. - if hashes.length == 1 - return hashes.shift - end - - # Else, merge the two records into one. - return port_merge(*hashes) - end - - # Override how we split into lines, so that we always treat both protocol - # lines as a single line. This drastically simplifies merging the two lines - # into one record. - def self.lines(text) - names = {} - lines = [] - - # We organize by number, because that's apparently how the ports work. - # You'll never be able to use Puppet to manage multiple entries - # with the same name but different numbers, though. - text.split("\n").each do |line| - if line =~ /^([-\w]+)\s+(\d+)\/[^d]/ # We want to skip ddp proto stuff - names[$1] ||= [] - names[$1] << line - lines << [:special, $1] - else - lines << line - end - end - - # Now, return each line in order, but join the ones with the same name - lines.collect do |line| - if line.is_a?(Array) - name = line[1] - if names[name] - t = names[name].join("\n") - names.delete(name) - t - end - else - line - end - end.reject { |l| l.nil? } - end - - # Parse a single port line, returning a hash. - def self.parse_port(line) - hash = {} - if line.sub!(/^(\S+)\s+(\d+)\/(\w+)\s*/, '') - hash[:name] = $1 - hash[:number] = $2 - hash[:protocols] = [$3] - - unless line == "" - line.sub!(/^([^#]+)\s*/) do |value| - aliases = $1 - - # Remove any trailing whitespace - aliases.strip! - unless aliases =~ /^\s*$/ - hash[:alias] = aliases.split(/\s+/) - end - - "" - end - - line.sub!(/^\s*#\s*(.+)$/) do |value| - desc = $1 - unless desc =~ /^\s*$/ - hash[:description] = desc.sub(/\s*$/, '') - end - - "" - end - end - else - if line =~ /^\s+\d+/ and - Facter["operatingsystem"].value == "Darwin" - #Puppet.notice "Skipping wonky OS X port entry %s" % - # line.inspect - next - end - Puppet.notice "Ignoring unparseable line '%s' in %s" % [line, self.target] - end - - if hash.empty? - return nil - else - return hash - end - end - - # Merge two records into one. - def self.port_merge(one, two) - keys = [one.keys, two.keys].flatten.uniq - - # We'll be returning the 'one' hash. so make any necessary modifications - # to it. - keys.each do |key| - # The easy case - if one[key] == two[key] - next - elsif one[key] and ! two[key] - next - elsif ! one[key] and two[key] - one[key] = two[key] - elsif one[key].is_a?(Array) and two[key].is_a?(Array) - one[key] = [one[key], two[key]].flatten.uniq - else - # Keep the info from the first hash, so don't do anything - #Puppet.notice "Cannot merge %s in %s with %s" % - # [key, one.inspect, two.inspect] - end - end - - return one - end - - # Convert the current object into one or more services entry. - def self.to_line(hash) - unless hash[:record_type] == :parsed - return super - end - - # Strangely, most sites seem to use tabs as separators. - hash[:protocols].collect { |proto| - str = "%s\t\t%s/%s" % [hash[:name], hash[:number], proto] - - if value = hash[:alias] and value != :absent - str += "\t\t%s" % value.join(" ") - end - - if value = hash[:description] and value != :absent - str += "\t# %s" % value - end - str - }.join("\n") - end -end +#services = nil +#case Facter.value(:operatingsystem) +#when "Solaris": services = "/etc/inet/services" +#else +# services = "/etc/services" +#end +# +#Puppet::Type.type(:port).provide(:parsed, +# :parent => Puppet::Provider::ParsedFile, +# :default_target => services, +# :filetype => :flat +#) do +# text_line :comment, :match => /^\s*#/ +# text_line :blank, :match => /^\s*$/ +# +# # We're cheating horribly here -- we don't support ddp, because it assigns +# # the same number to already-used names, and the same name to different +# # numbers. +# text_line :ddp, :match => /^\S+\s+\d+\/ddp/ +# +# # Also, just ignore the lines on OS X that don't have service names. +# text_line :funky_darwin, :match => /^\s+\d+\// +# +# # We have to manually parse the line, since it's so darn complicated. +# record_line :parsed, :fields => %w{name port protocols alias description}, +# :optional => %w{alias description} do |line| +# if line =~ /\/ddp/ +# raise "missed ddp in %s" % line +# end +# # The record might contain multiple port lines separated by \n. +# hashes = line.split("\n").collect { |l| parse_port(l) } +# +# # It's easy if there's just one hash. +# if hashes.length == 1 +# return hashes.shift +# end +# +# # Else, merge the two records into one. +# return port_merge(*hashes) +# end +# +# # Override how we split into lines, so that we always treat both protocol +# # lines as a single line. This drastically simplifies merging the two lines +# # into one record. +# def self.lines(text) +# names = {} +# lines = [] +# +# # We organize by number, because that's apparently how the ports work. +# # You'll never be able to use Puppet to manage multiple entries +# # with the same name but different numbers, though. +# text.split("\n").each do |line| +# if line =~ /^([-\w]+)\s+(\d+)\/[^d]/ # We want to skip ddp proto stuff +# names[$1] ||= [] +# names[$1] << line +# lines << [:special, $1] +# else +# lines << line +# end +# end +# +# # Now, return each line in order, but join the ones with the same name +# lines.collect do |line| +# if line.is_a?(Array) +# name = line[1] +# if names[name] +# t = names[name].join("\n") +# names.delete(name) +# t +# end +# else +# line +# end +# end.reject { |l| l.nil? } +# end +# +# # Parse a single port line, returning a hash. +# def self.parse_port(line) +# hash = {} +# if line.sub!(/^(\S+)\s+(\d+)\/(\w+)\s*/, '') +# hash[:name] = $1 +# hash[:number] = $2 +# hash[:protocols] = [$3] +# +# unless line == "" +# line.sub!(/^([^#]+)\s*/) do |value| +# aliases = $1 +# +# # Remove any trailing whitespace +# aliases.strip! +# unless aliases =~ /^\s*$/ +# hash[:alias] = aliases.split(/\s+/) +# end +# +# "" +# end +# +# line.sub!(/^\s*#\s*(.+)$/) do |value| +# desc = $1 +# unless desc =~ /^\s*$/ +# hash[:description] = desc.sub(/\s*$/, '') +# end +# +# "" +# end +# end +# else +# if line =~ /^\s+\d+/ and +# Facter["operatingsystem"].value == "Darwin" +# #Puppet.notice "Skipping wonky OS X port entry %s" % +# # line.inspect +# next +# end +# Puppet.notice "Ignoring unparseable line '%s' in %s" % [line, self.target] +# end +# +# if hash.empty? +# return nil +# else +# return hash +# end +# end +# +# # Merge two records into one. +# def self.port_merge(one, two) +# keys = [one.keys, two.keys].flatten.uniq +# +# # We'll be returning the 'one' hash. so make any necessary modifications +# # to it. +# keys.each do |key| +# # The easy case +# if one[key] == two[key] +# next +# elsif one[key] and ! two[key] +# next +# elsif ! one[key] and two[key] +# one[key] = two[key] +# elsif one[key].is_a?(Array) and two[key].is_a?(Array) +# one[key] = [one[key], two[key]].flatten.uniq +# else +# # Keep the info from the first hash, so don't do anything +# #Puppet.notice "Cannot merge %s in %s with %s" % +# # [key, one.inspect, two.inspect] +# end +# end +# +# return one +# end +# +# # Convert the current object into one or more services entry. +# def self.to_line(hash) +# unless hash[:record_type] == :parsed +# return super +# end +# +# # Strangely, most sites seem to use tabs as separators. +# hash[:protocols].collect { |proto| +# str = "%s\t\t%s/%s" % [hash[:name], hash[:number], proto] +# +# if value = hash[:alias] and value != :absent +# str += "\t\t%s" % value.join(" ") +# end +# +# if value = hash[:description] and value != :absent +# str += "\t# %s" % value +# end +# str +# }.join("\n") +# end +#end # $Id$ diff --git a/lib/puppet/type/port.rb b/lib/puppet/type/port.rb index c1eed299b..0460c0972 100755 --- a/lib/puppet/type/port.rb +++ b/lib/puppet/type/port.rb @@ -1,119 +1,121 @@ require 'puppet/type/parsedtype' -module Puppet - newtype(:port) do - @doc = "Installs and manages port entries. For most systems, these - entries will just be in /etc/services, but some systems (notably OS X) - will have different solutions." - - newstate(:protocols) do - desc "The protocols the port uses. Valid values are *udp* and *tcp*. - Most services have both protocols, but not all. If you want - both protocols, you must specify that; Puppet replaces the - current values, it does not merge with them. If you specify - multiple protocols they must be as an array." - - def is=(value) - case value - when String - @is = value.split(/\s+/) - else - @is = value - end - end - - def is - @is - end - - # We actually want to return the whole array here, not just the first - # value. - def should - if defined? @should - if @should[0] == :absent - return :absent - else - return @should - end - else - return nil - end - end - - validate do |value| - valids = ["udp", "tcp", "ddp", :absent] - unless valids.include? value - raise Puppet::Error, - "Protocols can be either 'udp' or 'tcp', not %s" % value - end - end - end - - newstate(:number) do - desc "The port number." - end - - newstate(:description) do - desc "The port description." - end - - newstate(:alias) do - desc "Any aliases the port might have. Multiple values must be - specified as an array. Note that this state has the same name as - one of the metaparams; using this state to set aliases will make - those aliases available in your Puppet scripts and also on disk." - - # We actually want to return the whole array here, not just the first - # value. - def should - if defined? @should - if @should[0] == :absent - return :absent - else - return @should - end - else - return nil - end - end - - validate do |value| - if value.is_a? String and value =~ /\s/ - raise Puppet::Error, - "Aliases cannot have whitespace in them: %s" % - value.inspect - end - end - - munge do |value| - unless value == "absent" or value == :absent - # Add the :alias metaparam in addition to the state - @parent.newmetaparam( - @parent.class.metaparamclass(:alias), value - ) - end - value - end - end - - newstate(:target) do - desc "The file in which to store service information. Only used by - those providers that write to disk (i.e., not NetInfo)." - - defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) - @parent.class.defaultprovider.default_target - else - nil - end - } - end - - newparam(:name) do - desc "The port name." - - isnamevar - end - end -end +#module Puppet +# newtype(:port) do +# @doc = "Installs and manages port entries. For most systems, these +# entries will just be in /etc/services, but some systems (notably OS X) +# will have different solutions." +# +# ensurable +# +# newstate(:protocols) do +# desc "The protocols the port uses. Valid values are *udp* and *tcp*. +# Most services have both protocols, but not all. If you want +# both protocols, you must specify that; Puppet replaces the +# current values, it does not merge with them. If you specify +# multiple protocols they must be as an array." +# +# def is=(value) +# case value +# when String +# @is = value.split(/\s+/) +# else +# @is = value +# end +# end +# +# def is +# @is +# end +# +# # We actually want to return the whole array here, not just the first +# # value. +# def should +# if defined? @should +# if @should[0] == :absent +# return :absent +# else +# return @should +# end +# else +# return nil +# end +# end +# +# validate do |value| +# valids = ["udp", "tcp", "ddp", :absent] +# unless valids.include? value +# raise Puppet::Error, +# "Protocols can be either 'udp' or 'tcp', not %s" % value +# end +# end +# end +# +# newstate(:number) do +# desc "The port number." +# end +# +# newstate(:description) do +# desc "The port description." +# end +# +# newstate(:alias) do +# desc "Any aliases the port might have. Multiple values must be +# specified as an array. Note that this state has the same name as +# one of the metaparams; using this state to set aliases will make +# those aliases available in your Puppet scripts and also on disk." +# +# # We actually want to return the whole array here, not just the first +# # value. +# def should +# if defined? @should +# if @should[0] == :absent +# return :absent +# else +# return @should +# end +# else +# return nil +# end +# end +# +# validate do |value| +# if value.is_a? String and value =~ /\s/ +# raise Puppet::Error, +# "Aliases cannot have whitespace in them: %s" % +# value.inspect +# end +# end +# +# munge do |value| +# unless value == "absent" or value == :absent +# # Add the :alias metaparam in addition to the state +# @parent.newmetaparam( +# @parent.class.metaparamclass(:alias), value +# ) +# end +# value +# end +# end +# +# newstate(:target) do +# desc "The file in which to store service information. Only used by +# those providers that write to disk (i.e., not NetInfo)." +# +# defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) +# @parent.class.defaultprovider.default_target +# else +# nil +# end +# } +# end +# +# newparam(:name) do +# desc "The port name." +# +# isnamevar +# end +# end +#end # $Id$ diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index 2fffc6f48..661d10e4a 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -89,7 +89,7 @@ module Puppet end # Set ourselves to whatever our should value is. - self.set + self.set(self.should) end end diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb index 92f83b384..5c06edc57 100644 --- a/lib/puppet/type/yumrepo.rb +++ b/lib/puppet/type/yumrepo.rb @@ -21,7 +21,7 @@ module Puppet if insync? result = nil else - result = set + result = set(self.should) if should == :absent parent.section[inikey] = nil else diff --git a/test/types/host.rb b/test/types/host.rb index 3c9d28434..a68e46020 100755 --- a/test/types/host.rb +++ b/test/types/host.rb @@ -23,12 +23,14 @@ class TestHost < Test::Unit::TestCase cleanup do @hosttype.defaultprovider = nil end - @default_file = @provider.default_target - cleanup do - @provider.default_target = @default_file + if @provider.respond_to?(:default_target=) + @default_file = @provider.default_target + cleanup do + @provider.default_target = @default_file + end + @target = tempfile() + @provider.default_target = @target end - @target = tempfile() - @provider.default_target = @target end def mkhost @@ -62,6 +64,8 @@ class TestHost < Test::Unit::TestCase assert_equal(0, count, "Found hosts in empty file somehow") end + # Darwin will actually write to netinfo here. + if Facter.value(:operatingsystem) != "Darwin" or Process.uid == 0 def test_simplehost host = nil @@ -105,6 +109,7 @@ class TestHost < Test::Unit::TestCase assert_equal(%w{madstop kirby yayness}, host.is(:alias)) end + end def test_aliasisstate assert_equal(:state, @hosttype.attrtype(:alias)) diff --git a/test/types/mount.rb b/test/types/mount.rb index 5a5a5da85..999599457 100755 --- a/test/types/mount.rb +++ b/test/types/mount.rb @@ -66,7 +66,7 @@ class TestMounts < Test::Unit::TestCase def teardown Puppet.type(:mount).clear - @realprovider.clear + #@realprovider.clear Puppet::Type.type(:mount).defaultprovider = nil super end @@ -156,6 +156,8 @@ class TestMounts < Test::Unit::TestCase assert(obj.provider.mounted?, "Object is not mounted") end + # Darwin doesn't put its mount table into netinfo + unless Facter.value(:operatingsystem) == "Darwin" def test_list list = nil assert(@mount.respond_to?(:list), @@ -180,8 +182,11 @@ class TestMounts < Test::Unit::TestCase assert(root.is(:device), "Device was not set") assert(root.state(:device).value, "Device was not returned by value method") end + end # Make sure we actually remove the object from the file and such. + # Darwin will actually write to netinfo here. + if Facter.value(:operatingsystem) != "Darwin" or Process.uid == 0 def test_removal # Reset the provider so that we're using the real thing @mount.defaultprovider = nil @@ -189,13 +194,15 @@ class TestMounts < Test::Unit::TestCase provider = @mount.defaultprovider assert(provider, "Could not retrieve default provider") - file = provider.default_target - assert(FileTest.exists?(file), - "FSTab %s does not exist" % file) + if provider.respond_to?(:default_target) + file = provider.default_target + assert(FileTest.exists?(file), + "FSTab %s does not exist" % file) - # Now switch to ram, so we're just doing this there, not really on disk. - provider.filetype = :ram - #provider.target_object(file).write text + # Now switch to ram, so we're just doing this there, not really on disk. + provider.filetype = :ram + #provider.target_object(file).write text + end mount = mkmount @@ -213,6 +220,7 @@ class TestMounts < Test::Unit::TestCase assert(! list.find { |r| r[:name] == mount[:name] }, "Mount was not actually removed") end + end end # $Id$ diff --git a/test/types/port.rb b/test/types/port.rb index 7a809bddd..a6bc449ca 100755 --- a/test/types/port.rb +++ b/test/types/port.rb @@ -2,145 +2,148 @@ $:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ -require 'puppettest' -require 'puppet' -require 'test/unit' -require 'facter' - -class TestPort < Test::Unit::TestCase - include PuppetTest - - def setup - super - @porttype = Puppet.type(:port) - - @provider = @porttype.defaultprovider - - # Make sure they aren't using something funky like netinfo - unless @provider.name == :parsed - @porttype.defaultprovider = @porttype.provider(:parsed) - end - - cleanup do @porttype.defaultprovider = nil end - - oldpath = @provider.path - cleanup do - @provider.path = oldpath - end - @provider.path = tempfile() - end - - def mkport - port = nil - - if defined? @pcount - @pcount += 1 - else - @pcount = 1 - end - assert_nothing_raised { - port = Puppet.type(:port).create( - :name => "puppet%s" % @pcount, - :number => "813%s" % @pcount, - :protocols => "tcp", - :description => "The port that Puppet runs on", - :alias => "coolness%s" % @pcount - ) - } - - return port - end - - def test_list - assert_nothing_raised { - Puppet.type(:port).list - } - - count = 0 - @porttype.each do |h| - count += 1 - end - - assert_equal(0, count, "Found hosts in empty file somehow") - - dns = @porttype["domain"] - assert(dns, "Did not retrieve dns service") - end - def test_simpleport - host = nil - - port = mkport - - assert_apply(port) - assert_nothing_raised { - port.retrieve - } - - assert(port.exists?, "Port did not get created") - end - - def test_moddingport - port = nil - port = mkport - - assert_events([:port_created], port) - - port.retrieve - - port[:protocols] = %w{tcp udp} - - assert_events([:port_changed], port) - end - - def test_multivalues - port = mkport - assert_raise(Puppet::Error) { - port[:protocols] = "udp tcp" - } - assert_raise(Puppet::Error) { - port[:alias] = "puppetmasterd yayness" - } - end - - def test_removal - port = mkport() - assert_nothing_raised { - port[:ensure] = :present - } - assert_events([:port_created], port) - assert_events([], port) - - assert(port.exists?, "port was not created") - assert_nothing_raised { - port[:ensure] = :absent - } - - assert_events([:port_removed], port) - assert(! port.exists?, "port was not removed") - assert_events([], port) - end - - def test_addingstates - port = mkport() - assert_events([:port_created], port) - - port.delete(:alias) - assert(! port.state(:alias)) - assert_events([:port_changed], port) - - assert_nothing_raised { - port.retrieve - } - - assert_equal(:present, port.is(:ensure)) - - assert_equal(:absent, port.is(:alias)) - - port[:alias] = "yaytest" - assert_events([:port_changed], port) - port.retrieve - assert(port.state(:alias).is == ["yaytest"]) - end -end +#require 'puppettest' +#require 'puppet' +#require 'test/unit' +#require 'facter' +# +#class TestPort < Test::Unit::TestCase +# include PuppetTest +# +# def setup +# super +# @porttype = Puppet.type(:port) +# +# @provider = @porttype.defaultprovider +# +# # Make sure they aren't using something funky like netinfo +# unless @provider.name == :parsed +# @porttype.defaultprovider = @porttype.provider(:parsed) +# end +# +# cleanup do @porttype.defaultprovider = nil end +# +# if @provider.respond_to?(:default_target) +# oldpath = @provider.default_target +# cleanup do +# @provider.default_target = oldpath +# end +# @provider.default_target = tempfile() +# end +# end +# +# def mkport +# port = nil +# +# if defined? @pcount +# @pcount += 1 +# else +# @pcount = 1 +# end +# assert_nothing_raised { +# port = Puppet.type(:port).create( +# :name => "puppet%s" % @pcount, +# :number => "813%s" % @pcount, +# :protocols => "tcp", +# :description => "The port that Puppet runs on", +# :alias => "coolness%s" % @pcount +# ) +# } +# +# return port +# end +# +# def test_list +# assert_nothing_raised { +# Puppet.type(:port).list +# } +# +# count = 0 +# @porttype.each do |h| +# count += 1 +# end +# +# assert_equal(0, count, "Found hosts in empty file somehow") +# +# dns = @porttype["domain"] +# assert(dns, "Did not retrieve dns service") +# end +# +# def test_simpleport +# host = nil +# +# port = mkport +# +# assert_apply(port) +# assert_nothing_raised { +# port.retrieve +# } +# +# assert(port.provider.exists?, "Port did not get created") +# end +# +# def test_moddingport +# port = nil +# port = mkport +# +# assert_events([:port_created], port) +# +# port.retrieve +# +# port[:protocols] = %w{tcp udp} +# +# assert_events([:port_changed], port) +# end +# +# def test_multivalues +# port = mkport +# assert_raise(Puppet::Error) { +# port[:protocols] = "udp tcp" +# } +# assert_raise(Puppet::Error) { +# port[:alias] = "puppetmasterd yayness" +# } +# end +# +# def test_removal +# port = mkport() +# assert_nothing_raised { +# port[:ensure] = :present +# } +# assert_events([:port_created], port) +# assert_events([], port) +# +# assert(port.provider.exists?, "port was not created") +# assert_nothing_raised { +# port[:ensure] = :absent +# } +# +# assert_events([:port_removed], port) +# assert(! port.provider.exists?, "port was not removed") +# assert_events([], port) +# end +# +# def test_addingstates +# port = mkport() +# assert_events([:port_created], port) +# +# port.delete(:alias) +# assert(! port.state(:alias)) +# assert_events([:port_changed], port) +# +# assert_nothing_raised { +# port.retrieve +# } +# +# assert_equal(:present, port.is(:ensure)) +# +# assert_equal(:absent, port.is(:alias)) +# +# port[:alias] = "yaytest" +# assert_events([:port_changed], port) +# port.retrieve +# assert(port.state(:alias).is == ["yaytest"]) +# end +#end # $Id$ diff --git a/test/types/sshkey.rb b/test/types/sshkey.rb index 1a25c4cd0..d4e8c59a5 100755 --- a/test/types/sshkey.rb +++ b/test/types/sshkey.rb @@ -23,11 +23,20 @@ class TestSSHKey < Test::Unit::TestCase cleanup do @sshkeytype.defaultprovider = nil end - oldpath = @provider.path - cleanup do - @provider.path = oldpath + if @provider.respond_to?(:default_target) + oldpath = @provider.default_target + cleanup do + @provider.default_target = oldpath + end + @provider.default_target = tempfile() + end + end + + def teardown + super + if @provider.respond_to?(:clear) + @provider.clear end - @provider.path = tempfile() end def mkkey @@ -51,23 +60,25 @@ class TestSSHKey < Test::Unit::TestCase return key end - def test_simplekey + def test_list assert_nothing_raised { - Puppet.type(:sshkey).defaultprovider.retrieve + Puppet.type(:sshkey).defaultprovider.list + } - count = 0 - @sshkeytype.each do |h| - count += 1 - end + count = 0 + @sshkeytype.each do |h| + count += 1 + end - assert_equal(0, count, "Found sshkeys in empty file somehow") - } + assert_equal(0, count, "Found sshkeys in empty file somehow") + end + def test_simplekey key = mkkey assert_apply(key) - assert(key.exists?, "Key did not get created") + assert(key.provider.exists?, "Key did not get created") end def test_moddingkey @@ -111,13 +122,13 @@ class TestSSHKey < Test::Unit::TestCase } assert_events([:sshkey_created], sshkey) - assert(sshkey.exists?, "key was not created") + assert(sshkey.provider.exists?, "key was not created") assert_nothing_raised { sshkey[:ensure] = :absent } - assert_events([:sshkey_removed], sshkey) - assert(! sshkey.exists?, "Key was not deleted") + assert_events([:sshkey_deleted], sshkey) + assert(! sshkey.provider.exists?, "Key was not deleted") assert_events([], sshkey) end @@ -142,14 +153,16 @@ class TestSSHKey < Test::Unit::TestCase # Verify we can retrieve that info assert_nothing_raised("Could not retrieve after second write") { + newkey.provider.class.prefetch newkey.retrieve } # And verify that we have data for everything names.each { |name| - key = Puppet.type(:sshkey)[name] || Puppet.type(:sshkey).create(:name => name) + key = Puppet.type(:sshkey)[name] || + Puppet.type(:sshkey).create(:name => name) assert(key, "Could not retrieve key for %s" % name) - assert(key.exists?, "key %s is missing" % name) + assert(key.provider.exists?, "key %s is missing" % name) } end end |