diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-03-02 07:30:14 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-03-02 07:30:14 +0000 |
commit | 95856eaaf02361ff597ca2c85e51cf141fe81280 (patch) | |
tree | db31ba74ce65523fa9dcd4d1cae0cd75c55a4395 /test | |
parent | ff1df8e1aef99dbdc222c5d5d808494fd08e7f83 (diff) | |
download | puppet-95856eaaf02361ff597ca2c85e51cf141fe81280.tar.gz puppet-95856eaaf02361ff597ca2c85e51cf141fe81280.tar.xz puppet-95856eaaf02361ff597ca2c85e51cf141fe81280.zip |
Okay, Puppet is now almost entirely capable of configuring itself. I have not yet added the extra tests to puppetmasterd to make sure it can start as a normal user, and the executables still fail some simple tests because they are producing output when they start (I will get rid of the output), but overall things look pretty good.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@965 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rw-r--r-- | test/client/client.rb | 24 | ||||
-rwxr-xr-x | test/other/config.rb | 93 | ||||
-rwxr-xr-x | test/other/events.rb | 45 | ||||
-rw-r--r-- | test/other/metrics.rb | 1 | ||||
-rwxr-xr-x | test/other/relationships.rb | 32 | ||||
-rw-r--r-- | test/other/transactions.rb | 2 | ||||
-rwxr-xr-x | test/puppet/conffiles.rb | 2 | ||||
-rwxr-xr-x | test/puppet/defaults.rb | 2 | ||||
-rwxr-xr-x | test/types/component.rb | 38 | ||||
-rwxr-xr-x | test/types/exec.rb | 6 | ||||
-rw-r--r-- | test/types/file.rb | 19 | ||||
-rwxr-xr-x | test/types/tidy.rb | 3 | ||||
-rw-r--r-- | test/types/type.rb | 4 | ||||
-rwxr-xr-x | test/types/user.rb | 2 |
14 files changed, 218 insertions, 55 deletions
diff --git a/test/client/client.rb b/test/client/client.rb index 3a462c097..659378abd 100644 --- a/test/client/client.rb +++ b/test/client/client.rb @@ -83,9 +83,12 @@ class TestClient < Test::Unit::TestCase } # create a ca so we can create a set of certs + # make a new ssldir for it ca = nil assert_nothing_raised { - ca = Puppet::Client::CAClient.new(:CA => true, :Local => true) + ca = Puppet::Client::CAClient.new( + :CA => true, :Local => true + ) ca.requestcert } @@ -107,9 +110,24 @@ class TestClient < Test::Unit::TestCase } # clean up the existing certs, so the server creates a new CA - system("rm -rf %s" % Puppet[:ssldir]) + #system("rm -rf %s" % Puppet[:ssldir]) + confdir = tempfile() + Puppet[:confdir] = confdir + + # Now we need to recreate the directory structure + [:certificates, :ca].each { |section| + Puppet.config.params(section).each { |param| + val = Puppet[param] + if val =~ /^#{File::SEPARATOR}/ + if param.to_s =~ /dir/ + Puppet::Util.recmkdir(val) + else + Puppet::Util.recmkdir(File.dirname(val)) + end + end + } + } - # start our server mkserver # now verify that our client cannot do non-cert operations diff --git a/test/other/config.rb b/test/other/config.rb index e3338ba10..f01aeeaaf 100755 --- a/test/other/config.rb +++ b/test/other/config.rb @@ -145,6 +145,13 @@ class TestConfig < Test::Unit::TestCase } assert_equal(val, c[:strtest]) + + # Verify that variables are interpolated + assert_nothing_raised { + c.setdefaults(:testing, :another => ["another $strtest", "testing"]) + } + + assert_equal("another #{val}", c[:another]) end def test_files @@ -219,7 +226,8 @@ yay = /a/path c.setdefaults("puppet", :one => ["a", "one"], :two => ["a", "two"], - :yay => ["/default/path", "boo"] + :yay => ["/default/path", "boo"], + :mkusers => [true, "uh, yeah"] ) } @@ -344,10 +352,16 @@ yay = /a/path dir = tempfile() file = "$mydir/myfile" realfile = File.join(dir, "myfile") + otherfile = File.join(dir, "otherfile") section = "testing" assert_nothing_raised { c.setdefaults(section, :mydir => [dir, "A dir arg"], + :otherfile => { + :default => "$mydir/otherfile", + :create => true, + :desc => "A file arg" + }, :myfile => [file, "A file arg"] ) } @@ -356,7 +370,12 @@ yay = /a/path c.use(section) } + assert_nothing_raised("Could not reuse a section") { + c.use(section) + } + assert(FileTest.directory?(dir), "Did not create directory") + assert(FileTest.exists?(otherfile), "Did not create file") assert(!FileTest.exists?(realfile), "Created file") end @@ -387,6 +406,78 @@ yay = /a/path assert_equal(false, c[:a], "Values are not equal") assert_equal("/my/file", c[:b], "Values are not equal") end + + def test_reuse + c = mkconfig + + file = tempfile() + section = "testing" + assert_nothing_raised { + c.setdefaults(section, + :myfile => {:default => file, :create => true} + ) + } + + assert_nothing_raised("Could not use a section") { + c.use(section) + } + + assert(FileTest.exists?(file), "Did not create file") + + assert(! Puppet::Type.type(:file)[file], "File obj still exists") + + File.unlink(file) + + c.reuse + assert(FileTest.exists?(file), "Did not create file") + end + + def test_mkusers + c = mkconfig + + file = tempfile() + section = "testing" + assert_nothing_raised { + c.setdefaults(section, + :mkusers => [false, "yay"], + :myfile => { + :default => file, + :owner => "pptest", + :group => "pptest", + :create => true + } + ) + } + + comp = nil + assert_nothing_raised { + comp = c.to_component + } + + [:user, :group].each do |type| + # The objects might get created internally by Puppet::Util; just + # make sure they're not being managed + if obj = Puppet.type(type)["pptest"] + assert(! obj.managed?, "%s objectis managed" % type) + end + end + comp.each { |o| o.remove } + + c[:mkusers] = true + + assert_nothing_raised { + c.to_component + } + + assert(Puppet.type(:user)["pptest"], "User object did not get created") + assert(Puppet.type(:user)["pptest"].managed?, + "User object is not managed." + ) + assert(Puppet.type(:group)["pptest"], "Group object did not get created") + assert(Puppet.type(:group)["pptest"].managed?, + "Group object is not managed." + ) + end end # $Id$ diff --git a/test/other/events.rb b/test/other/events.rb index be319724c..3138a5a59 100755 --- a/test/other/events.rb +++ b/test/other/events.rb @@ -70,37 +70,26 @@ class TestEvents < Test::Unit::TestCase comps = {} objects = {} fname = tempfile() - [:a, :b].each { |l| - case l - when :a - name = tempfile() + l.to_s - objects[l] = Puppet.type(:file).create( - :name => name, - :ensure => "file" - ) - @@tmpfiles << name - when :b - objects[l] = Puppet.type(:exec).create( - :name => "touch %s" % fname, - :path => "/usr/bin:/bin", - :refreshonly => true - ) - @@tmpfiles << fname - end - - - comps[l] = Puppet.type(:component).create( - :name => "eventtesting%s" % l - ) - - comps[l].push objects[l] - } + file = Puppet.type(:file).create( + :name => tempfile(), + :ensure => "file" + ) - comps[:b][:subscribe] = [[comps[:a].class.name, comps[:a].name]] + exec = Puppet.type(:exec).create( + :name => "touch %s" % fname, + :path => "/usr/bin:/bin", + :refreshonly => true + ) - Puppet::Type.finalize + comps[:f] = newcomp(file) + comps[:e] = newcomp(exec) + + comps[:e][:subscribe] = [[comps[:f].class.name, comps[:f].name]] + comps.each { |l, c| + c.finalize + } - trans = comps[:a].evaluate + trans = comps[:f].evaluate events = nil assert_nothing_raised { events = trans.evaluate diff --git a/test/other/metrics.rb b/test/other/metrics.rb index 32d73cf06..4cbc1ff1e 100644 --- a/test/other/metrics.rb +++ b/test/other/metrics.rb @@ -6,6 +6,7 @@ end require 'puppet/metric' require 'puppet' +require 'puppettest' require 'puppet/type' require 'test/unit' diff --git a/test/other/relationships.rb b/test/other/relationships.rb index 3decfd5af..83949d1ed 100755 --- a/test/other/relationships.rb +++ b/test/other/relationships.rb @@ -26,8 +26,8 @@ class TestRelationships < Test::Unit::TestCase file1[:require] = [file2.class.name, file2.name] } - Puppet::Type.finalize - + comp = newcomp(file1, file2) + comp.finalize deps = [] assert_nothing_raised { file1.eachdependency { |obj| @@ -110,6 +110,34 @@ class TestRelationships < Test::Unit::TestCase assert(! sub.match?(:ALL_EVENTS), "ALL_EVENTS matched") assert(! sub.match?(:NONE), "matched :NONE") end + + def test_deletingsubs + file1 = newfile() + file2 = newfile() + + file1[:subscribe] = [:file, file2.name] + + comp = newcomp(file1, file2) + comp.finalize + + assert(file1.requires?(file2)) + + assert_nothing_raised { + file1.unsubscribe(file2) + } + assert(!file1.requires?(file2)) + + # Now readd it, so we can use 'remove' + file1[:subscribe] = [:file, file2.name] + comp.finalize + + assert_nothing_raised { + file1.remove + } + + assert(!comp.include?(file1)) + assert(!file2.subscribesto?(file1)) + end end # $Id$ diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 862a28b85..a5f881e12 100644 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -201,7 +201,7 @@ class TestTransactions < Test::Unit::TestCase assert(FileTest.exists?(execfile), "Execfile does not exist") end - def test_zrefreshAcrossTwoComponents + def test_refreshAcrossTwoComponents transaction = nil file = newfile() execfile = File.join(tmpdir(), "exectestingness2") diff --git a/test/puppet/conffiles.rb b/test/puppet/conffiles.rb index b63886488..095ac9c99 100755 --- a/test/puppet/conffiles.rb +++ b/test/puppet/conffiles.rb @@ -79,7 +79,7 @@ class TestConfFiles < Test::Unit::TestCase config = Puppet::Config.new data.each { |section, hash| hash.each { |param, value| - config.setdefaults(section, [param, value, value]) + config.setdefaults(section, param => [value, value]) } } # Write it out as a config file diff --git a/test/puppet/defaults.rb b/test/puppet/defaults.rb index 73759ca6b..2557140e6 100755 --- a/test/puppet/defaults.rb +++ b/test/puppet/defaults.rb @@ -95,7 +95,7 @@ class TestPuppetDefaults < Test::Unit::TestCase testvals.each { |param, default| assert_nothing_raised { - Puppet.setdefaults("testing", [param, default, "a value"]) + Puppet.setdefaults("testing", param => [default, "a value"]) } } end diff --git a/test/types/component.rb b/test/types/component.rb index 83da95a56..0754e7cdc 100755 --- a/test/types/component.rb +++ b/test/types/component.rb @@ -89,7 +89,7 @@ class TestComponent < Test::Unit::TestCase comp.push obj } - Puppet::Type.finalize + comp.finalize comp end @@ -159,11 +159,8 @@ class TestComponent < Test::Unit::TestCase ) } - Puppet::Type.finalize - comp = Puppet.type(:component).create(:name => "RefreshTest") - [cmd, file].each { |obj| - comp.push obj - } + comp = newcomp(cmd, file) + comp.finalize objects = nil assert_nothing_raised { objects = comp.flatten @@ -204,7 +201,7 @@ class TestComponent < Test::Unit::TestCase ecomp[:subscribe] = [[fcomp.class.name,fcomp.name]] comp = newcomp("bflatten", ecomp, fcomp) - Puppet::Type.finalize + comp.finalize objects = nil assert_nothing_raised { objects = comp.flatten @@ -257,7 +254,7 @@ class TestComponent < Test::Unit::TestCase ocmd[:subscribe] = [[cmd.class.name,cmd.name]] comp = newcomp("bflatten", ocomp, ecomp, fcomp) - Puppet::Type.finalize + comp.finalize objects = nil assert_nothing_raised { objects = comp.flatten @@ -273,4 +270,29 @@ class TestComponent < Test::Unit::TestCase assert(objects[1] == cmd, "Exec was not second object") assert(objects[2] == ocmd, "Other exec was not second object") end + + def test_moreordering + dir = tempfile() + + comp = Puppet.type(:component).create( + :name => "ordertesting" + ) + + 10.times { |i| + fileobj = Puppet.type(:file).create( + :path => File.join(dir, "file%s" % i), + :ensure => "file" + ) + comp.push(fileobj) + } + + dirobj = Puppet.type(:file).create( + :path => dir, + :ensure => "directory" + ) + + comp.push(dirobj) + + assert_apply(comp) + end end diff --git a/test/types/exec.rb b/test/types/exec.rb index cb40d4f5c..3006ef0ec 100755 --- a/test/types/exec.rb +++ b/test/types/exec.rb @@ -251,7 +251,8 @@ class TestExec < Test::Unit::TestCase :path => ENV["PATH"] ) - Puppet::Type.finalize + comp = newcomp(ofile, exec, cat, file, baseobj) + comp.finalize # Verify we get the script itself assert(exec.requires?(file), "Exec did not autorequire %s" % file) @@ -424,9 +425,8 @@ class TestExec < Test::Unit::TestCase ) } - Puppet::Type.finalize - comp = newcomp(file, exec) + comp.finalize assert_events([:executed_command, :file_changed], comp) assert(FileTest.exists?(path), "Exec ran first") diff --git a/test/types/file.rb b/test/types/file.rb index e6d81a7a3..25fc82781 100644 --- a/test/types/file.rb +++ b/test/types/file.rb @@ -606,11 +606,11 @@ class TestFile < Test::Unit::TestCase :name => subfile, :ensure => "file" ) + comp = newcomp(baseobj, subobj) + comp.finalize - Puppet::Type.finalize assert(subobj.requires?(baseobj), "File did not require basedir") assert(!subobj.requires?(subobj), "File required itself") - comp = newcomp(subobj, baseobj) assert_events([:directory_created, :file_created], comp) end @@ -668,7 +668,7 @@ class TestFile < Test::Unit::TestCase } comp = newcomp("yay", file) - Puppet::Type.finalize + comp.finalize assert_apply(comp) #assert_events([:directory_created], comp) @@ -753,6 +753,19 @@ class TestFile < Test::Unit::TestCase assert(FileTest.exists?(path)) end + + # Make sure that a missing group isn't fatal at object instantiation time. + def test_missinggroup + file = nil + assert_nothing_raised { + file = Puppet.type(:file).create( + :path => tempfile(), + :group => "fakegroup" + ) + } + + assert(file.state(:group), "Group state failed") + end end # $Id$ diff --git a/test/types/tidy.rb b/test/types/tidy.rb index 551b4ce0b..6c9c4e88b 100755 --- a/test/types/tidy.rb +++ b/test/types/tidy.rb @@ -42,9 +42,8 @@ class TestTidy < Test::Unit::TestCase :size => "1b", :recurse => true ) - Puppet::Type.finalize - comp = newcomp("tidytesting", tidy) + comp.finalize trans = nil assert_events([:file_tidied], comp) diff --git a/test/types/type.rb b/test/types/type.rb index bb3a7f629..b0da6da29 100644 --- a/test/types/type.rb +++ b/test/types/type.rb @@ -179,8 +179,10 @@ class TestType < Test::Unit::TestCase ) } + comp = newcomp(twoobj, oneobj) + assert_nothing_raised { - Puppet::Type.finalize + comp.finalize } diff --git a/test/types/user.rb b/test/types/user.rb index 81be56788..acd7aba1d 100755 --- a/test/types/user.rb +++ b/test/types/user.rb @@ -384,8 +384,8 @@ class TestUser < Test::Unit::TestCase group = Puppet.type(:group).create( :name => "pptestg" ) - Puppet::Type.finalize comp = newcomp(user, group) + comp.finalize comp.retrieve assert(user.requires?(group), "User did not require group") |