From ff9705914570158d1bad3073728a2e94ca4a0060 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 23 Feb 2008 19:06:29 -0500 Subject: Somewhat refactored fileserving so that it no longer caches any objects, nor does it use Puppet's RAL resources. In the process, I fixed #894 (you can now copy links) and refactored other classes as necessary. Mostly it was fixing tests. This is a squashed commit of a temporary branch, fwiw, and it also includes any fixes to the tests that were necessary to get all tests passing again. --- test/lib/puppettest.rb | 30 ++++++----- test/network/handler/fileserver.rb | 100 +++++++++++++++++++------------------ test/network/server/webrick.rb | 2 +- test/other/dsl.rb | 7 ++- test/other/transactions.rb | 2 + test/rails/ast.rb | 4 +- test/rails/configuration.rb | 2 +- test/ral/manager/type.rb | 4 +- test/ral/providers/cron/crontab.rb | 4 +- test/ral/types/file.rb | 65 +----------------------- test/ral/types/filesources.rb | 35 +++---------- 11 files changed, 92 insertions(+), 163 deletions(-) (limited to 'test') diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 902831e68..e276bdf0f 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -36,9 +36,9 @@ class Class def publicize_methods(*methods) saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods - self.class_eval { public *saved_private_instance_methods } + self.class_eval { public(*saved_private_instance_methods) } yield - self.class_eval { private *saved_private_instance_methods } + self.class_eval { private(*saved_private_instance_methods) } end end @@ -198,7 +198,7 @@ module PuppetTest # If we're running under rake, then disable debugging and such. #if rake? or ! Puppet[:debug] - if defined?($puppet_debug) or ! rake? + #if defined?($puppet_debug) or ! rake? if textmate? Puppet[:color] = false end @@ -210,11 +210,11 @@ module PuppetTest end Puppet::Util::Log.level = :debug #$VERBOSE = 1 - else - Puppet::Util::Log.close - Puppet::Util::Log.newdestination(@logs) - Puppet[:httplog] = tempfile() - end + #else + # Puppet::Util::Log.close + # Puppet::Util::Log.newdestination(@logs) + # Puppet[:httplog] = tempfile() + #end Puppet[:ignoreschedules] = true @@ -267,11 +267,7 @@ module PuppetTest @tmpdir end - def teardown - #@stop = Time.now - #File.open("/tmp/test_times.log", ::File::WRONLY|::File::CREAT|::File::APPEND) { |f| f.puts "%0.4f %s %s" % [@stop - @start, @method_name, self.class] } - @@cleaners.each { |cleaner| cleaner.call() } - + def remove_tmp_files @@tmpfiles.each { |file| unless file =~ /tmp/ puts "Not deleting tmpfile %s" % file @@ -283,6 +279,14 @@ module PuppetTest end } @@tmpfiles.clear + end + + def teardown + #@stop = Time.now + #File.open("/tmp/test_times.log", ::File::WRONLY|::File::CREAT|::File::APPEND) { |f| f.puts "%0.4f %s %s" % [@stop - @start, @method_name, self.class] } + @@cleaners.each { |cleaner| cleaner.call() } + + remove_tmp_files @@tmppids.each { |pid| %x{kill -INT #{pid} 2>/dev/null} diff --git a/test/network/handler/fileserver.rb b/test/network/handler/fileserver.rb index 233e705c6..a705dbf4b 100755 --- a/test/network/handler/fileserver.rb +++ b/test/network/handler/fileserver.rb @@ -109,13 +109,13 @@ class TestFileServer < Test::Unit::TestCase # and verify different iterations of 'root' return the same value list = nil assert_nothing_raised { - list = server.list("/test/", :ignore, true, false) + list = server.list("/test/", :manage, true, false) } assert(list =~ pattern) assert_nothing_raised { - list = server.list("/test", :ignore, true, false) + list = server.list("/test", :manage, true, false) } assert(list =~ pattern) @@ -143,7 +143,7 @@ class TestFileServer < Test::Unit::TestCase list = nil sfile = "/test/tmpfile" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false) + list = server.list(sfile, :manage, true, false) } assert_nothing_raised { @@ -200,7 +200,7 @@ class TestFileServer < Test::Unit::TestCase list = nil sfile = "/test/" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false) + list = server.list(sfile, :manage, true, false) } # create the new file @@ -210,7 +210,7 @@ class TestFileServer < Test::Unit::TestCase newlist = nil assert_nothing_raised { - newlist = server.list(sfile, :ignore, true, false) + newlist = server.list(sfile, :manage, true, false) } # verify the list has changed @@ -239,12 +239,12 @@ class TestFileServer < Test::Unit::TestCase list = nil assert_nothing_raised { - list = server.list("/root/" + testdir, :ignore, true, false) + list = server.list("/root/" + testdir, :manage, true, false) } assert(list =~ pattern) assert_nothing_raised { - list = server.list("/root" + testdir, :ignore, true, false) + list = server.list("/root" + testdir, :manage, true, false) } assert(list =~ pattern) @@ -279,7 +279,7 @@ class TestFileServer < Test::Unit::TestCase # get our list list = nil assert_nothing_raised { - list = server.list("/test/with", :ignore, false, false) + list = server.list("/test/with", :manage, false, false) } # make sure we only got one line, since we're not recursing @@ -288,7 +288,7 @@ class TestFileServer < Test::Unit::TestCase # for each level of recursion, make sure we get the right list [0, 1, 2].each { |num| assert_nothing_raised { - list = server.list("/test/with", :ignore, num, false) + list = server.list("/test/with", :manage, num, false) } count = 0 @@ -332,13 +332,13 @@ class TestFileServer < Test::Unit::TestCase list = nil # and then check a few dirs assert_nothing_raised { - list = server.list("/localhost/with", :ignore, false, false) + list = server.list("/localhost/with", :manage, false, false) } assert(list !~ /with/) assert_nothing_raised { - list = server.list("/localhost/with/some/sub", :ignore, true, false) + list = server.list("/localhost/with/some/sub", :manage, true, false) } assert(list !~ /sub/) @@ -370,7 +370,7 @@ class TestFileServer < Test::Unit::TestCase list = nil assert_nothing_raised { - list = server.list("/localhost/", :ignore, 1, false) + list = server.list("/localhost/", :manage, 1, false) } assert_instance_of(String, list, "Server returned %s instead of string") list = list.split("\n") @@ -402,7 +402,7 @@ class TestFileServer < Test::Unit::TestCase list = nil sfile = "/test/" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false) + list = server.list(sfile, :manage, true, false) } # and describe each file in the list @@ -492,7 +492,7 @@ class TestFileServer < Test::Unit::TestCase mounts.each { |mount, files| mount = "/#{mount}/" assert_nothing_raised { - list = server.list(mount, :ignore, true, false) + list = server.list(mount, :manage, true, false) } assert_nothing_raised { @@ -544,12 +544,12 @@ class TestFileServer < Test::Unit::TestCase assert_raise(Puppet::AuthorizationError, "Host %s, ip %s, allowed %s" % [host, ip, mount]) { - list = server.list(mount, :ignore, true, false, host, ip) + list = server.list(mount, :manage, true, false, host, ip) } when :allow: assert_nothing_raised("Host %s, ip %s, denied %s" % [host, ip, mount]) { - list = server.list(mount, :ignore, true, false, host, ip) + list = server.list(mount, :manage, true, false, host, ip) } end } @@ -602,7 +602,7 @@ class TestFileServer < Test::Unit::TestCase assert_raise(Puppet::Network::Handler::FileServerError, "Invalid mount was mounted") { - server.list(mount, :ignore) + server.list(mount, :manage) } } @@ -654,13 +654,13 @@ class TestFileServer < Test::Unit::TestCase list = nil assert_nothing_raised { - list = server.list("/thing/", :ignore, false, false, + list = server.list("/thing/", :manage, false, false, "test1.domain.com", "127.0.0.1") } assert(list != "", "List returned nothing in rereard test") assert_raise(Puppet::AuthorizationError, "List allowed invalid host") { - list = server.list("/thing/", :ignore, false, false, + list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1") } @@ -675,12 +675,12 @@ class TestFileServer < Test::Unit::TestCase } assert_raise(Puppet::AuthorizationError, "List allowed invalid host") { - list = server.list("/thing/", :ignore, false, false, + list = server.list("/thing/", :manage, false, false, "test1.domain.com", "127.0.0.1") } assert_nothing_raised { - list = server.list("/thing/", :ignore, false, false, + list = server.list("/thing/", :manage, false, false, "test2.domain.com", "127.0.0.1") } @@ -735,7 +735,7 @@ class TestFileServer < Test::Unit::TestCase # Then not results = {} assert_nothing_raised { - server.describe("/mount/link", :ignore).split("\t").zip( + server.describe("/mount/link", :manage).split("\t").zip( Puppet::Network::Handler.fileserver::CHECKPARAMS ).each { |v,p| results[p] = v } } @@ -801,28 +801,28 @@ allow * list = nil sfile = "/host/file.txt" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false, client1, ip) + list = server.list(sfile, :manage, true, false, client1, ip) } assert_equal("/\tfile", list) assert_nothing_raised { - list = server.list(sfile, :ignore, true, false, client2, ip) + list = server.list(sfile, :manage, true, false, client2, ip) } assert_equal("", list) sfile = "/fqdn/file.txt" assert_nothing_raised { - list = server.list(sfile, :ignore, true, false, client1, ip) + list = server.list(sfile, :manage, true, false, client1, ip) } assert_equal("", list) assert_nothing_raised { - list = server.list(sfile, :ignore, true, false, client2, ip) + list = server.list(sfile, :manage, true, false, client2, ip) } assert_equal("/\tfile", list) # check describe sfile = "/host/file.txt" assert_nothing_raised { - list = server.describe(sfile, :ignore, client1, ip).split("\t") + list = server.describe(sfile, :manage, client1, ip).split("\t") } assert_equal(5, list.size) assert_equal("file", list[1]) @@ -830,18 +830,18 @@ allow * assert_equal("{md5}#{md5}", list[4]) assert_nothing_raised { - list = server.describe(sfile, :ignore, client2, ip).split("\t") + list = server.describe(sfile, :manage, client2, ip).split("\t") } assert_equal([], list) sfile = "/fqdn/file.txt" assert_nothing_raised { - list = server.describe(sfile, :ignore, client1, ip).split("\t") + list = server.describe(sfile, :manage, client1, ip).split("\t") } assert_equal([], list) assert_nothing_raised { - list = server.describe(sfile, :ignore, client2, ip).split("\t") + list = server.describe(sfile, :manage, client2, ip).split("\t") } assert_equal(5, list.size) assert_equal("file", list[1]) @@ -851,23 +851,23 @@ allow * # Check retrieve sfile = "/host/file.txt" assert_nothing_raised { - list = server.retrieve(sfile, :ignore, client1, ip).chomp + list = server.retrieve(sfile, :manage, client1, ip).chomp } assert_equal(contents[client1_hostdir].chomp, list) assert_nothing_raised { - list = server.retrieve(sfile, :ignore, client2, ip).chomp + list = server.retrieve(sfile, :manage, client2, ip).chomp } assert_equal("", list) sfile = "/fqdn/file.txt" assert_nothing_raised { - list = server.retrieve(sfile, :ignore, client1, ip).chomp + list = server.retrieve(sfile, :manage, client1, ip).chomp } assert_equal("", list) assert_nothing_raised { - list = server.retrieve(sfile, :ignore, client2, ip).chomp + list = server.retrieve(sfile, :manage, client2, ip).chomp } assert_equal(contents[client2_fqdndir].chomp, list) end @@ -945,12 +945,14 @@ allow * # Now, check that they use Facter info Puppet.notice "The following messages are normal" client = nil - local = Facter["hostname"].value - domain = Facter["domain"].value - fqdn = [local, domain].join(".") - {"%h" => local, # Short name - "%H" => fqdn, # Full name - "%d" => domain, # domain + Facter.stubs(:value).with(:ipaddress).returns("127.0.0.1") + Facter.stubs(:value).with { |v| v.to_s == "hostname" }.returns("myhost") + Facter.stubs(:value).with { |v| v.to_s == "domain" }.returns("mydomain.com") + Facter.stubs(:value).with(:domain).returns("mydomain.com") + + {"%h" => "myhost", # Short name + "%H" => "myhost.mydomain.com", # Full name + "%d" => "mydomain.com", # domain "%%" => "%", # escape "%o" => "%o" # other }.each do |pat, repl| @@ -993,18 +995,18 @@ allow * ret = nil assert_nothing_raised do - ret = server.list("/name", :ignore, false, false, host, ip) + ret = server.list("/name", :manage, false, false, host, ip) end assert_equal("/\tfile", ret) assert_nothing_raised do - ret = server.describe("/name", :ignore, host, ip) + ret = server.describe("/name", :manage, host, ip) end - assert(ret =~ /\tfile\t/, "Did not get valid a description") + assert(ret =~ /\tfile\t/, "Did not get valid a description (#{ret.inspect})") assert_nothing_raised do - ret = server.retrieve("/name", :ignore, host, ip) + ret = server.retrieve("/name", :manage, host, ip) end assert_equal(ret, File.read(file)) @@ -1050,7 +1052,7 @@ allow * mount = "/#{mod.name}/" list = nil assert_nothing_raised { - list = server.list(mount, :ignore, true, false) + list = server.list(mount, :manage, true, false) } list = list.split("\n") if mod.name == "green" @@ -1063,7 +1065,7 @@ allow * end assert_nothing_raised("Host 'allow' denied #{mount}") { - server.list(mount, :ignore, true, false, + server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1") } end @@ -1106,7 +1108,7 @@ allow * list = nil mount = "/#{mod.name}/" assert_nothing_raised { - list = server.list(mount, :ignore, true, false) + list = server.list(mount, :manage, true, false) } assert_nothing_raised { @@ -1121,11 +1123,11 @@ allow * # now let's check that things are being correctly forbidden assert_raise(Puppet::AuthorizationError, "Host 'deny' allowed #{mount}") { - server.list(mount, :ignore, true, false, + server.list(mount, :manage, true, false, 'deny.example.com', "192.168.1.1") } assert_nothing_raised("Host 'allow' denied #{mount}") { - server.list(mount, :ignore, true, false, + server.list(mount, :manage, true, false, 'allow.example.com', "192.168.0.1") } end diff --git a/test/network/server/webrick.rb b/test/network/server/webrick.rb index d3408c166..fe6d69ade 100755 --- a/test/network/server/webrick.rb +++ b/test/network/server/webrick.rb @@ -95,7 +95,7 @@ class TestWebrickServer < Test::Unit::TestCase # the client starts its connection immediately, thus throwing # the error. assert_raise(OpenSSL::SSL::SSLError) { - client = Puppet::Network::Client.status.new(:Server => "localhost", :Port => @@port) + Puppet::Network::HttpPool.http_instance("localhost", @@port).start } end diff --git a/test/other/dsl.rb b/test/other/dsl.rb index b4dd0659b..45b51982d 100755 --- a/test/other/dsl.rb +++ b/test/other/dsl.rb @@ -12,7 +12,7 @@ class TestDSL < Test::Unit::TestCase def teardown super - Puppet::Aspect.clear + Puppet::DSL::Aspect.clear end def test_aspect @@ -22,7 +22,7 @@ class TestDSL < Test::Unit::TestCase end end - assert_equal(a, Puppet::Aspect[:yaytest]) + assert_equal(a, Puppet::DSL::Aspect[:yaytest]) # Now make a child aspect b = nil @@ -154,8 +154,7 @@ class TestDSL < Test::Unit::TestCase resource = nil assert_nothing_raised do - resource = a.newresource filetype, path, - :content => "yay", :mode => "640" + resource = a.newresource filetype, path, :content => "yay", :mode => "640" end assert_instance_of(Puppet::Parser::Resource, resource) diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 105698da1..ce2d0d52b 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -6,10 +6,12 @@ require 'puppet' require 'puppettest' require 'mocha' require 'puppettest/support/resources' +require 'puppettest/support/utils' class TestTransactions < Test::Unit::TestCase include PuppetTest::FileTesting include PuppetTest::Support::Resources + include PuppetTest::Support::Utils class Fakeprop @scope + str, code = query.evaluate @scope end next else assert_nothing_raised("Could not evaluate '#{string}'") do - str, code = query.evaluate :scope => @scope + str, code = query.evaluate @scope end end assert_nothing_raised("Could not find resource") do diff --git a/test/rails/configuration.rb b/test/rails/configuration.rb index 9e2ddfedd..a878d1381 100755 --- a/test/rails/configuration.rb +++ b/test/rails/configuration.rb @@ -24,7 +24,7 @@ class ConfigurationRailsTests < PuppetTest::TestCase # We need to make sure finished objects are stored in the db. def test_finish_before_store railsinit - compile = mkcompile + compile = mkcompiler parser = compile.parser node = parser.newnode [compile.node.name], :code => AST::ASTArray.new(:children => [ diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb index 6c5587ddd..324550acb 100755 --- a/test/ral/manager/type.rb +++ b/test/ral/manager/type.rb @@ -574,8 +574,8 @@ class TestType < Test::Unit::TestCase assert_equal(greater, type.defaultprovider) end - # Make sure that we can have multiple isomorphic objects with the same name, - # but not with non-isomorphic objects. + # Make sure that we can have multiple non-isomorphic objects with the same name, + # but not with isomorphic objects. def test_isomorphic_names # First do execs, since they're not isomorphic. echo = Puppet::Util.binary "echo" diff --git a/test/ral/providers/cron/crontab.rb b/test/ral/providers/cron/crontab.rb index 2da4b1b57..1ff1e34ef 100755 --- a/test/ral/providers/cron/crontab.rb +++ b/test/ral/providers/cron/crontab.rb @@ -344,7 +344,9 @@ class TestCronParsedProvider < Test::Unit::TestCase end end - # Make sure we can create a cron in an empty tab + # Make sure we can create a cron in an empty tab. + # LAK:FIXME This actually modifies the user's crontab, + # which is pretty heinous. def test_mkcron_if_empty setme @provider.filetype = @oldfiletype diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb index c7872ccea..cbbe818ae 100755 --- a/test/ral/types/file.rb +++ b/test/ral/types/file.rb @@ -177,7 +177,7 @@ class TestFile < Test::Unit::TestCase assert_equal(inituser, File.stat(file).uid) obj.delete(:owner) - obj[:links] = :ignore + obj[:links] = :follow # And then test 'group' group = nonrootgroup @@ -1041,66 +1041,6 @@ class TestFile < Test::Unit::TestCase "directory mode is incorrect") end - def test_followlinks - File.umask(0022) - - basedir = tempfile() - Dir.mkdir(basedir) - file = File.join(basedir, "file") - link = File.join(basedir, "link") - - File.open(file, "w", 0644) { |f| f.puts "yayness"; f.flush } - File.symlink(file, link) - - obj = nil - assert_nothing_raised { - obj = Puppet.type(:file).create( - :path => link, - :mode => "755" - ) - } - obj.retrieve - - assert_events([], obj) - - # Assert that we default to not following links - assert_equal("%o" % 0644, "%o" % (File.stat(file).mode & 007777)) - - # Assert that we can manage the link directly, but modes still don't change - obj[:links] = :manage - assert_events([], obj) - - assert_equal("%o" % 0644, "%o" % (File.stat(file).mode & 007777)) - - obj[:links] = :follow - assert_events([:file_changed], obj) - - assert_equal("%o" % 0755, "%o" % (File.stat(file).mode & 007777)) - - # Now verify that content and checksum don't update, either - obj.delete(:mode) - obj[:checksum] = "md5" - obj[:links] = :ignore - - assert_events([], obj) - File.open(file, "w") { |f| f.puts "more text" } - assert_events([], obj) - obj[:links] = :follow - assert_events([], obj) - File.open(file, "w") { |f| f.puts "even more text" } - assert_events([:file_changed], obj) - - obj.delete(:checksum) - obj[:content] = "this is some content" - obj[:links] = :ignore - - assert_events([], obj) - File.open(file, "w") { |f| f.puts "more text" } - assert_events([], obj) - obj[:links] = :follow - assert_events([:file_changed, :file_changed], obj) - end - # If both 'ensure' and 'content' are used, make sure that all of the other # properties are handled correctly. def test_contentwithmode @@ -1383,8 +1323,7 @@ class TestFile < Test::Unit::TestCase File.symlink(dir, link) File.open(file, "w") { |f| f.puts "" } assert_equal(dir, File.readlink(link)) - obj = Puppet::Type.newfile :path => link, :ensure => :link, - :target => file, :recurse => false, :backup => "main" + obj = Puppet::Type.newfile :path => link, :ensure => :link, :target => file, :recurse => false, :backup => "main" assert_apply(obj) diff --git a/test/ral/types/filesources.rb b/test/ral/types/filesources.rb index 02bf8a5b3..a7bb6fefa 100755 --- a/test/ral/types/filesources.rb +++ b/test/ral/types/filesources.rb @@ -84,8 +84,7 @@ class TestFileSources < Test::Unit::TestCase source = tempfile() dest = tempfile() - file = Puppet::Type.newfile :path => dest, :source => source, - :title => "copier" + file = Puppet::Type.newfile :path => dest, :source => source, :title => "copier" property = file.property(:source) @@ -124,17 +123,10 @@ class TestFileSources < Test::Unit::TestCase File.open(target, "w") { |f| f.puts "yay" } File.symlink(target, source) - file[:links] = :ignore - assert_nil(property.describe(source), - "Links were not ignored") - file[:links] = :manage - # We can't manage links at this point - assert_raise(Puppet::Network::Handler::FileServerError) do - property.describe(source) - end + assert_equal("link", property.describe(source)[:type]) - # And then make sure links get followed, otherwise + # And then make sure links get followed file[:links] = :follow assert_equal("file", property.describe(source)[:type]) end @@ -753,29 +745,18 @@ class TestFileSources < Test::Unit::TestCase assert_nothing_raised { file = Puppet.type(:file).create( :name => dest, - :source => link + :source => link, + :links => :follow ) } - # Default to skipping links - assert_events([], file) - assert(! FileTest.exists?(dest), "Created link") - - # Now follow the links - file[:links] = :follow assert_events([:file_created], file) assert(FileTest.file?(dest), "Destination is not a file") # Now copy the links - #assert_raise(Puppet::Network::Handler::FileServerError) { - trans = nil - assert_nothing_raised { - file[:links] = :manage - comp = mk_catalog(file) - trans = comp.apply - } - - assert(trans.failed?(file), "Object did not fail to copy links") + file[:links] = :manage + assert_events([:link_created], file) + assert(FileTest.symlink?(dest), "Destination is not a link") end def test_changes -- cgit