diff options
author | Luke Kanies <luke@madstop.com> | 2008-07-29 00:46:11 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-07-29 00:46:11 -0500 |
commit | 40375a8fc34dbd85d87f507ba72c7394b25b7271 (patch) | |
tree | efd5a93980b042b73322bd31e6fdb41203d07576 /test | |
parent | 93eeff59d807261ed154cc104e318ae604602430 (diff) | |
parent | 8f5800f0608dff46407cb5f23ee73f314fe051e8 (diff) | |
download | puppet-40375a8fc34dbd85d87f507ba72c7394b25b7271.tar.gz puppet-40375a8fc34dbd85d87f507ba72c7394b25b7271.tar.xz puppet-40375a8fc34dbd85d87f507ba72c7394b25b7271.zip |
Merge branch '0.24.x' into merging
Conflicts:
test/ral/type/filesources.rb
Diffstat (limited to 'test')
-rwxr-xr-x | test/certmgr/support.rb | 43 | ||||
-rw-r--r-- | test/lib/puppettest/runnable_test.rb | 3 | ||||
-rwxr-xr-x | test/network/handler/master.rb | 34 | ||||
-rwxr-xr-x | test/other/provider.rb | 45 | ||||
-rwxr-xr-x | test/ral/type/filesources.rb | 117 |
5 files changed, 164 insertions, 78 deletions
diff --git a/test/certmgr/support.rb b/test/certmgr/support.rb index c055cbca1..10d431939 100755 --- a/test/certmgr/support.rb +++ b/test/certmgr/support.rb @@ -79,22 +79,31 @@ class TestCertSupport < Test::Unit::TestCase end end - # Fixing #1382. - def test_uppercase_files_are_renamed_and_read - # Write a key out to disk in a file containing upper-case. - key = OpenSSL::PKey::RSA.new(32) - should_path = Puppet[:hostprivkey] - - dir, file = File.split(should_path) - newfile = file.sub(/^([a-z.]+)\./) { $1.upcase + "."} - upper_path = File.join(dir, newfile) - File.open(upper_path, "w") { |f| f.print key.to_s } - - user = CertUser.new - - assert_equal(key.to_s, user.read_key.to_s, "Did not read key in from disk") - assert(! FileTest.exist?(upper_path), "Upper case file was not removed") - assert(FileTest.exist?(should_path), "File was not renamed to lower-case file") - assert_equal(key.to_s, user.read_key.to_s, "Did not read key in from disk") + # Fixing #1382. This test will always fail on Darwin, because its + # FS is case-insensitive. + unless Facter.value(:operatingsystem) == "Darwin" + def test_uppercase_files_are_renamed_and_read + # Write a key out to disk in a file containing upper-case. + key = OpenSSL::PKey::RSA.new(32) + should_path = Puppet[:hostprivkey] + puts "%s: %s" % [should_path, FileTest.exist?(should_path).inspect] + + dir, file = File.split(should_path) + newfile = file.sub(/^([a-z.]+)\./) { $1.upcase + "."} + puts "%s: %s" % [should_path, FileTest.exist?(should_path).inspect] + upper_path = File.join(dir, newfile) + puts "%s: %s" % [should_path, FileTest.exist?(should_path).inspect] + puts "%s: %s" % [upper_path, FileTest.exist?(upper_path).inspect] + File.open(upper_path, "w") { |f| f.print key.to_s } + puts "%s: %s" % [should_path, FileTest.exist?(should_path).inspect] + puts "%s: %s" % [upper_path, FileTest.exist?(upper_path).inspect] + + user = CertUser.new + + assert_equal(key.to_s, user.read_key.to_s, "Did not read key in from disk") + assert(! FileTest.exist?(upper_path), "Upper case file was not removed") + assert(FileTest.exist?(should_path), "File was not renamed to lower-case file") + assert_equal(key.to_s, user.read_key.to_s, "Did not read key in from disk") + end end end diff --git a/test/lib/puppettest/runnable_test.rb b/test/lib/puppettest/runnable_test.rb index e4b0f9033..e3cde5052 100644 --- a/test/lib/puppettest/runnable_test.rb +++ b/test/lib/puppettest/runnable_test.rb @@ -15,6 +15,9 @@ module PuppetTest # Evaluate all of our tests to see if any of them are false # and thus whether this test is considered not runnable. def runnable? + if superclass.respond_to?(:runnable?) and ! superclass.runnable? + return false + end @messages ||= [] return false unless @messages.empty? return true unless defined? @confines diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb index 17bf1b3cc..bbdc021b9 100755 --- a/test/network/handler/master.rb +++ b/test/network/handler/master.rb @@ -56,3 +56,37 @@ class TestMaster < Test::Unit::TestCase @master.getconfig("facts", "yaml", "foo.com") end end + +class TestMasterFormats < Test::Unit::TestCase + def setup + @facts = stub('facts', :save => nil) + Puppet::Node::Facts.stubs(:new).returns(@facts) + + @master = Puppet::Network::Handler.master.new(:Code => "") + @master.stubs(:decode_facts) + + @catalog = stub 'catalog', :extract => "" + Puppet::Node::Catalog.stubs(:find).returns(@catalog) + end + + def test_marshal_can_be_used + @catalog.expects(:extract).returns "myextract" + + Marshal.expects(:dump).with("myextract").returns "eh" + + @master.getconfig("facts", "marshal", "foo.com") + end + + def test_yaml_can_be_used + extract = mock 'extract' + @catalog.expects(:extract).returns extract + + extract.expects(:to_yaml).returns "myaml" + + @master.getconfig("facts", "yaml", "foo.com") + end + + def test_failure_when_non_yaml_or_marshal_is_used + assert_raise(RuntimeError) { @master.getconfig("facts", "blah", "foo.com") } + end +end diff --git a/test/other/provider.rb b/test/other/provider.rb index 3e4ad83d6..b0860f634 100755 --- a/test/other/provider.rb +++ b/test/other/provider.rb @@ -48,51 +48,6 @@ class TestImpl < Test::Unit::TestCase end - def test_provider_false_confine - assert_nothing_raised do - @provider.confine :false => false - end - - assert(@provider.suitable?, "False did not check correctly") - end - - def test_provider_true_confine - assert_nothing_raised do - @provider.confine :true => true - end - - assert(@provider.suitable?, "True did not check correctly") - - # Now check whether we multiple true things work - assert_nothing_raised do - @provider.confine :true => false - @provider.confine :true => true - end - assert(! @provider.suitable?, "One truth overrode another") - end - - def test_provider_exists_confine - file = tempfile() - - assert_nothing_raised do - @provider.confine :exists => file - end - - assert(! @provider.suitable?, "Exists did not check correctly") - File.open(file, "w") { |f| f.puts "" } - assert(@provider.suitable?, "Exists did not find file correctly") - end - - def test_provider_facts_confine - # Now check for multiple platforms - assert_nothing_raised do - @provider.confine :operatingsystem => [Facter["operatingsystem"].value, :yayos] - @provider.confine :operatingsystem => [:fakeos, :otheros] - end - - assert(@provider.suitable?, "Implementation not considered suitable") - end - def test_provider_default nondef = nil assert_nothing_raised { diff --git a/test/ral/type/filesources.rb b/test/ral/type/filesources.rb index 653db5c7d..e35b66fbd 100755 --- a/test/ral/type/filesources.rb +++ b/test/ral/type/filesources.rb @@ -144,16 +144,7 @@ class TestFileSources < Test::Unit::TestCase # Make sure the munge didn't actually change the source assert_equal([source], property.should, "munging changed the source") - # First try it with a missing source currentvalue = nil - assert_nothing_raised do - currentvalue = property.retrieve - end - - # And make sure the property considers itself in sync, since there's nothing - # to do - assert(property.insync?(currentvalue), "source thinks there's work to do with no file or dest") - # Now make the dest a directory, and make sure the object sets :ensure # up to create a directory Dir.mkdir(source) @@ -169,9 +160,6 @@ class TestFileSources < Test::Unit::TestCase # Now remove the source, and make sure :ensure was not modified Dir.rmdir(source) - assert_nothing_raised do - property.retrieve - end assert_equal(:directory, file.should(:ensure), "Did not keep :ensure setting") @@ -207,10 +195,6 @@ class TestFileSources < Test::Unit::TestCase property = file.property(:source) assert(property, "did not get source property") - # Try it with no source at all - currentvalues = file.retrieve - assert(property.insync?(currentvalues[property]), "source property not in sync with missing source") - # with a directory Dir.mkdir(source) currentvalues = file.retrieve @@ -525,6 +509,107 @@ class TestFileSources < Test::Unit::TestCase return file end + def test_NetworkSources + server = nil + mounts = { + "/" => "root" + } + + fileserverconf = mkfileserverconf(mounts) + + Puppet[:autosign] = true + + Puppet[:masterport] = 8762 + Puppet[:name] = "puppetmasterd" + Puppet[:certdnsnames] = "localhost" + + serverpid = nil + assert_nothing_raised() { + server = Puppet::Network::HTTPServer::WEBrick.new( + :Handlers => { + :CA => {}, # so that certs autogenerate + :FileServer => { + :Config => fileserverconf + } + } + ) + + } + serverpid = fork { + assert_nothing_raised() { + #trap(:INT) { server.shutdown; Kernel.exit! } + trap(:INT) { server.shutdown } + server.start + } + } + @@tmppids << serverpid + + sleep(1) + + fromdir, todir = run_complex_sources("root") + assert_trees_equal(fromdir,todir) + recursive_source_test(fromdir, todir) + assert_trees_equal(fromdir,todir) + + assert_nothing_raised { + system("kill -INT %s" % serverpid) + } + end + + def test_unmountedNetworkSources + server = nil + mounts = { + "/" => "root", + "/noexistokay" => "noexist" + } + + fileserverconf = mkfileserverconf(mounts) + + Puppet[:autosign] = true + Puppet[:masterport] = @port + Puppet[:certdnsnames] = "localhost" + + serverpid = nil + assert_nothing_raised("Could not start on port %s" % @port) { + server = Puppet::Network::HTTPServer::WEBrick.new( + :Port => @port, + :Handlers => { + :CA => {}, # so that certs autogenerate + :FileServer => { + :Config => fileserverconf + } + } + ) + + } + + serverpid = fork { + assert_nothing_raised() { + #trap(:INT) { server.shutdown; Kernel.exit! } + trap(:INT) { server.shutdown } + server.start + } + } + @@tmppids << serverpid + + sleep(1) + + name = File.join(tmpdir(), "nosourcefile") + file = Puppet.type(:file).create( + :source => "puppet://localhost/noexist/file", + :name => name + ) + + assert_raise Puppet::Error do + file.retrieve + end + + comp = mk_catalog(file) + comp.apply + + assert(!FileTest.exists?(name), "File with no source exists anyway") + end + def test_alwayschecksum from = tempfile() to = tempfile() |