diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-23 22:38:39 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-23 22:38:39 +0000 |
| commit | 18e8e74a2e3b4c5d092fc0aae38bbc5455d4db48 (patch) | |
| tree | a655a05e449fb0f3218d87555b33c7fb57968fdc /test | |
| parent | 258114d48b4853cbaa79b53776d5279f727451ab (diff) | |
| download | puppet-18e8e74a2e3b4c5d092fc0aae38bbc5455d4db48.tar.gz puppet-18e8e74a2e3b4c5d092fc0aae38bbc5455d4db48.tar.xz puppet-18e8e74a2e3b4c5d092fc0aae38bbc5455d4db48.zip | |
Committing most of the scheduling stuff. There is still a bit of work to do in terms of how puppetd interacts with scheduling, but the bulk of the work is done.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@847 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rw-r--r-- | test/client/client.rb | 4 | ||||
| -rw-r--r-- | test/other/state.rb | 85 | ||||
| -rwxr-xr-x | test/other/storage.rb | 31 | ||||
| -rwxr-xr-x | test/puppet/defaults.rb | 2 | ||||
| -rw-r--r-- | test/puppettest.rb | 6 | ||||
| -rw-r--r-- | test/types/file.rb | 39 | ||||
| -rwxr-xr-x | test/types/filebucket.rb | 2 | ||||
| -rw-r--r-- | test/types/fileignoresource.rb | 2 | ||||
| -rwxr-xr-x | test/types/filesources.rb | 2 | ||||
| -rwxr-xr-x | test/types/schedule.rb | 336 |
10 files changed, 392 insertions, 117 deletions
diff --git a/test/client/client.rb b/test/client/client.rb index 608fa1dc6..3a462c097 100644 --- a/test/client/client.rb +++ b/test/client/client.rb @@ -114,11 +114,11 @@ class TestClient < Test::Unit::TestCase # now verify that our client cannot do non-cert operations # because its certs are signed by a different CA - assert_raise(Puppet::NetworkClientError, + assert_raise(Puppet::Error, "Client was allowed to call getconfig with no certs") { nonemaster.getconfig } - assert_raise(Puppet::NetworkClientError, + assert_raise(Puppet::Error, "Client was allowed to call getconfig with untrusted certs") { certmaster.getconfig } diff --git a/test/other/state.rb b/test/other/state.rb deleted file mode 100644 index 15512f6fe..000000000 --- a/test/other/state.rb +++ /dev/null @@ -1,85 +0,0 @@ -if __FILE__ == $0 - $:.unshift '..' - $:.unshift '../../lib' - $puppetbase = "../../../../language/trunk" -end - -require 'puppet' -require 'puppettest' -require 'puppet/storage' -require 'test/unit' - -# $Id$ - -class StorageTestingClass -end - -class TestStorage < Test::Unit::TestCase - include TestPuppet - def test_simple - state = nil - assert_nothing_raised { - Puppet::Storage.load - } - assert_nothing_raised { - state = Puppet::Storage.state(Puppet::Type) - } - assert(state) - state["/etc/passwd"] = ["md5","9ebebe0c02445c40b9dc6871b64ee416"] - assert_nothing_raised { - Puppet::Storage.store - } - - # clear the memory, so we're sure we're hitting the state file - assert_nothing_raised { - Puppet::Storage.clear - Puppet::Storage.init - } - assert_nothing_raised { - Puppet::Storage.load - } - assert_equal( - ["md5","9ebebe0c02445c40b9dc6871b64ee416"], - Puppet::Storage.state(Puppet::Type)["/etc/passwd"] - ) - end - - def test_instance - file = nil - state = nil - assert_nothing_raised { - file = Puppet.type(:file).create( - :path => "/etc/passwd" - ) - } - assert_nothing_raised { - Puppet::Storage.load - } - assert_nothing_raised { - state = Puppet::Storage.state(file) - } - assert(state) - end - - def test_update - state = Puppet::Storage.state(StorageTestingClass) - state["testing"] = "yayness" - Puppet::Storage.store - assert(FileTest.exists?(Puppet[:checksumfile])) - end - - def test_hashstorage - state = Puppet::Storage.state(StorageTestingClass) - hash = { - :yay => "boo", - :rah => "foo" - } - state["testing"] = hash - Puppet::Storage.store - Puppet::Storage.clear - Puppet::Storage.init - Puppet::Storage.load - state = Puppet::Storage.state(StorageTestingClass) - assert_equal(hash, state["testing"]) - end -end diff --git a/test/other/storage.rb b/test/other/storage.rb index 64f08cdc7..fc9b52cd6 100755 --- a/test/other/storage.rb +++ b/test/other/storage.rb @@ -11,12 +11,28 @@ require 'test/unit' class TestParsedFile < Test::Unit::TestCase include TestPuppet + def mkfile + path = tempfile() + File.open(path, "w") { |f| f.puts :yayness } + + f = Puppet.type(:file).create( + :name => path, + :check => %w{checksum type} + ) + + return f + end + def test_storeandretrieve + path = tempfile() + + f = mkfile() + hash = {:a => :b, :c => :d} state = nil assert_nothing_raised { - state = Puppet::Storage.state(hash) + state = Puppet::Storage.cache(f) } assert(!state.include?("name")) @@ -34,8 +50,11 @@ class TestParsedFile < Test::Unit::TestCase assert_nothing_raised { Puppet::Storage.load } + + # Reset it + state = nil assert_nothing_raised { - state = Puppet::Storage.state(hash) + state = Puppet::Storage.cache(f) } assert_equal(state["name"], hash) @@ -45,6 +64,8 @@ class TestParsedFile < Test::Unit::TestCase # are reading or writing the file at once # so we need to test that def test_multiwrite + f = mkfile() + value = {:a => :b} threads = [] 9.times { |a| @@ -52,7 +73,7 @@ class TestParsedFile < Test::Unit::TestCase 9.times { |b| assert_nothing_raised { Puppet::Storage.load - state = Puppet::Storage.state(value) + state = Puppet::Storage.cache(f) value.each { |k,v| state[k] = v } state[:e] = rand(100) Puppet::Storage.store @@ -68,7 +89,9 @@ class TestParsedFile < Test::Unit::TestCase Puppet::Storage.store Puppet::Storage.clear Puppet::Storage.load - state = Puppet::Storage.state('newstate') + + f = mkfile() + state = Puppet::Storage.cache(f) assert_same Hash, state.class assert_equal 0, state.size end diff --git a/test/puppet/defaults.rb b/test/puppet/defaults.rb index 9c16578e7..2fbd4fe46 100755 --- a/test/puppet/defaults.rb +++ b/test/puppet/defaults.rb @@ -13,7 +13,7 @@ require 'test/unit' class TestPuppetDefaults < Test::Unit::TestCase include TestPuppet @@dirs = %w{rrddir puppetconf puppetvar logdir statedir} - @@files = %w{logfile checksumfile manifest masterlog} + @@files = %w{logfile statefile manifest masterlog} @@normals = %w{puppetport masterport server} @@booleans = %w{rrdgraph noop} diff --git a/test/puppettest.rb b/test/puppettest.rb index 34d48ff52..ec7b1b104 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -53,6 +53,8 @@ module TestPuppet Puppet[:logdest] = "/dev/null" Puppet[:httplog] = "/dev/null" end + + Puppet[:ignoreschedules] = true end @@ -209,10 +211,12 @@ module TestPuppet trans = comp.evaluate } + events = nil assert_nothing_raised("Failed to evaluate transaction") { - trans.evaluate + events = trans.evaluate.collect { |e| e.event } } Puppet.type(:component).delete(comp) + events end def run_events(type, trans, events, msg) diff --git a/test/types/file.rb b/test/types/file.rb index b9e85839e..a54b78e12 100644 --- a/test/types/file.rb +++ b/test/types/file.rb @@ -36,14 +36,14 @@ class TestFile < Test::Unit::TestCase begin initstorage rescue - system("rm -rf %s" % Puppet[:checksumfile]) + system("rm -rf %s" % Puppet[:statefile]) end end def teardown clearstorage Puppet::Storage.clear - system("rm -rf %s" % Puppet[:checksumfile]) + system("rm -rf %s" % Puppet[:statefile]) super end @@ -306,9 +306,8 @@ class TestFile < Test::Unit::TestCase ) comp.push file trans = nil - assert_nothing_raised() { - trans = comp.evaluate - } + + file.retrieve if file.name !~ /nonexists/ sum = file.state(:checksum) @@ -316,14 +315,16 @@ class TestFile < Test::Unit::TestCase assert(sum.insync?) end - assert_nothing_raised() { - events = trans.evaluate.collect { |e| e.event } - } - # we don't want to kick off an event the first time we - # come across a file - assert( - ! events.include?(:file_changed) - ) + events = assert_apply(comp) + + assert(! events.include?(:file_changed), + "File incorrectly changed") + assert_events([], comp) + + # We have to sleep because the time resolution of the time-based + # mechanisms is greater than one second + sleep 1 + assert_nothing_raised() { File.open(path,File::CREAT|File::TRUNC|File::WRONLY) { |of| of.puts "some more text, yo" @@ -332,10 +333,6 @@ class TestFile < Test::Unit::TestCase Puppet.type(:file).clear Puppet.type(:component).clear - # We have to sleep because the time resolution of the time-based - # mechanisms is greater than one second - sleep 1.1 - # now recreate the file assert_nothing_raised() { file = Puppet.type(:file).create( @@ -351,11 +348,11 @@ class TestFile < Test::Unit::TestCase # If the file was missing, it should not generate an event # when it gets created. - if path =~ /nonexists/e - assert_events([], comp) - else + #if path =~ /nonexists/ + # assert_events([], comp) + #else assert_events([:file_changed], comp) - end + #end assert_nothing_raised() { File.unlink(path) File.open(path,File::CREAT|File::TRUNC|File::WRONLY) { |of| diff --git a/test/types/filebucket.rb b/test/types/filebucket.rb index 5220eea98..a788bd929 100755 --- a/test/types/filebucket.rb +++ b/test/types/filebucket.rb @@ -52,7 +52,7 @@ class TestFileBucket < Test::Unit::TestCase begin initstorage rescue - system("rm -rf %s" % Puppet[:checksumfile]) + system("rm -rf %s" % Puppet[:statefile]) end end diff --git a/test/types/fileignoresource.rb b/test/types/fileignoresource.rb index ce8352384..4189c50e3 100644 --- a/test/types/fileignoresource.rb +++ b/test/types/fileignoresource.rb @@ -20,7 +20,7 @@ class TestFileIgnoreSources < Test::Unit::TestCase begin initstorage rescue - system("rm -rf %s" % Puppet[:checksumfile]) + system("rm -rf %s" % Puppet[:statefile]) end end diff --git a/test/types/filesources.rb b/test/types/filesources.rb index ba401b446..e08fa268c 100755 --- a/test/types/filesources.rb +++ b/test/types/filesources.rb @@ -18,7 +18,7 @@ class TestFileSources < Test::Unit::TestCase begin initstorage rescue - system("rm -rf %s" % Puppet[:checksumfile]) + system("rm -rf %s" % Puppet[:statefile]) end if defined? @port @port += 1 diff --git a/test/types/schedule.rb b/test/types/schedule.rb new file mode 100755 index 000000000..04519b3ca --- /dev/null +++ b/test/types/schedule.rb @@ -0,0 +1,336 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $puppetbase = "../.." +end + +require 'puppet' +require 'test/unit' +require 'puppet/type/schedule' +require 'puppettest' + +class TestSchedule < Test::Unit::TestCase + include TestPuppet + + def setup + super + @stype = Puppet::Type::Schedule + + # This will probably get overridden by different tests + @now = Time.now + Puppet[:ignoreschedules] = false + end + + def mksched + s = nil + assert_nothing_raised { + s = @stype.create( + :name => "testsched" + ) + } + + s + end + + def diff(unit, incr, method, count) + diff = @now.to_i.send(method, incr * count) + t = Time.at(diff) + + #Puppet.notice "%s: %s %s %s = %s" % + # [unit, @now.send(unit), method, count, t] + #t.strftime("%H:%M:%S") + t + end + + def month(method, count) + diff(:hour, 3600 * 24 * 30, method, count) + end + + def week(method, count) + diff(:hour, 3600 * 24 * 7, method, count) + end + + def day(method, count) + diff(:hour, 3600 * 24, method, count) + end + + def hour(method, count) + diff(:hour, 3600, method, count) + end + + def min(method, count) + diff(:min, 60, method, count) + end + + def sec(method, count) + diff(:sec, 1, method, count) + end + + def settimes + unless defined? @@times + @@times = [Time.now] + + # Make one with an edge year on each side + ary = Time.now.to_a + [1999, 2000, 2001].each { |y| + ary[5] = y; @@times << Time.local(*ary) + } + + # And with edge hours + ary = Time.now.to_a + #[23, 0].each { |h| ary[2] = h; @@times << Time.local(*ary) } + # 23 hour + ary[2] = 23 + @@times << Time.local(*ary) + # 0 hour, next day + ary[2] = 0 + @@times << addday(Time.local(*ary)) + + # And with edge minutes + #[59, 0].each { |m| ary[1] = m; @@times << Time.local(*ary) } + ary = Time.now.to_a + ary[1] = 59; @@times << Time.local(*ary) + ary[1] = 0 + #if ary[2] == 23 + @@times << Time.local(*ary) + #else + # @@times << addday(Time.local(*ary)) + #end + end + + Puppet.err @@times.inspect + + @@times.each { |time| + @now = time + yield time + } + + @now = Time.now + end + + def test_range + s = mksched + + ary = @now.to_a + ary[2] = 12 + @now = Time.local(*ary) + data = { + true => [ + # An hour previous, an hour after + [hour("-", 1), hour("+", 1)], + + # an hour previous but a couple minutes later, and an hour plus + [min("-", 57), hour("+", 1)] + ], + false => [ + # five minutes from now, an hour from now + [min("+", 5), hour("+", 1)], + + # an hour ago, 20 minutes ago + [hour("-", 1), min("-", 20)] + ] + } + + data.each { |result, values| + values = values.collect { |value| + "%s - %s" % [value[0].strftime("%H:%M:%S"), + value[1].strftime("%H:%M:%S")] + } + values.each { |value| + assert_nothing_raised("Could not parse %s" % value) { + s[:range] = value + } + + assert_equal(result, s.match?(nil, @now), + "%s matched %s incorrectly" % [value.inspect, @now]) + } + + assert_nothing_raised("Could not parse %s" % values) { + s[:range] = values + } + + assert_equal(result, s.match?(nil, @now), + "%s matched %s incorrectly" % [values.inspect, @now]) + } + end + + def test_period_by_distance + previous = @now + + s = mksched + + assert_nothing_raised { + s[:period] = :daily + } + + assert(s.match?(day("-", 1)), "did not match minus a day") + assert(s.match?(day("-", 2)), "did not match two days") + assert(! s.match?(@now), "matched today") + assert(! s.match?(hour("-", 11)), "matched minus 11 hours") + + # Now test hourly + assert_nothing_raised { + s[:period] = :hourly + } + + assert(s.match?(hour("-", 1)), "did not match minus an hour") + assert(s.match?(hour("-", 2)), "did not match two hours") + assert(! s.match?(@now), "matched now") + assert(! s.match?(min("-", 59)), "matched minus 11 hours") + + # and weekly + assert_nothing_raised { + s[:period] = :weekly + } + + assert(s.match?(week("-", 1)), "did not match minus a week") + assert(s.match?(day("-", 7)), "did not match minus 7 days") + assert(s.match?(day("-", 8)), "did not match minus 8 days") + assert(s.match?(week("-", 2)), "did not match two weeks") + assert(! s.match?(@now), "matched now") + assert(! s.match?(day("-", 6)), "matched minus 6 days") + + # and monthly + assert_nothing_raised { + s[:period] = :monthly + } + + assert(s.match?(month("-", 1)), "did not match minus a month") + assert(s.match?(week("-", 5)), "did not match minus 5 weeks") + assert(s.match?(week("-", 7)), "did not match minus 7 weeks") + assert(s.match?(day("-", 50)), "did not match minus 50 days") + assert(s.match?(month("-", 2)), "did not match two months") + assert(! s.match?(@now), "matched now") + assert(! s.match?(week("-", 3)), "matched minus 3 weeks") + assert(! s.match?(day("-", 20)), "matched minus 20 days") + end + + # A shortened test... + def test_period_by_number + s = mksched + assert_nothing_raised { + s[:periodmatch] = :number + } + + assert_nothing_raised { + s[:period] = :daily + } + + assert(s.match?(day("+", 1)), "didn't match plus a day") + assert(s.match?(week("+", 1)), "didn't match plus a week") + assert(! s.match?(@now), "matched today") + assert(! s.match?(hour("-", 11)), "matched minus 11 hours") + assert(! s.match?(hour("-", 1)), "matched minus an hour") + assert(! s.match?(hour("-", 2)), "matched plus two hours") + + # Now test hourly + assert_nothing_raised { + s[:period] = :hourly + } + + assert(s.match?(hour("+", 1)), "did not match plus an hour") + assert(s.match?(hour("+", 2)), "did not match plus two hours") + assert(! s.match?(@now), "matched now") + assert(! s.match?(sec("+", 20)), "matched plus 20 seconds") + end + + def test_periodmatch_default + s = mksched + + match = s[:periodmatch] + assert(match, "Could not find periodmatch") + + assert_equal(:distance, match, "Periodmatch was %s" % match) + end + + def test_scheduled_objects + s = mksched + s[:period] = :hourly + + f = nil + path = tempfile() + assert_nothing_raised { + f = Puppet.type(:file).create( + :name => path, + :schedule => s.name, + :ensure => "file" + ) + } + + assert(f.scheduled?, "File is not scheduled to run") + + assert_apply(f) + + assert(! f.scheduled?, "File is scheduled to run already") + File.unlink(path) + + assert_apply(f) + + assert(! FileTest.exists?(path), "File was created when not scheduled") + end + + def test_latebinding_schedules + f = nil + path = tempfile() + assert_nothing_raised { + f = Puppet.type(:file).create( + :name => path, + :schedule => "testsched", + :ensure => "file" + ) + } + + s = mksched + s[:period] = :hourly + + assert_nothing_raised { + f.schedule + } + + assert(f.scheduled?, "File is not scheduled to run") + end + + # Verify that each of our default schedules exist + def test_defaultschedules + Puppet.type(:schedule).mkdefaultschedules + %w{puppet hourly daily weekly monthly}.each { |period| + assert(Puppet.type(:schedule)[period], "Could not find %s schedule" % + period) + } + end + + def test_period_with_repeat + previous = @now + + s = mksched + s[:period] = :hourly + + assert_nothing_raised("Was not able to set periodmatch") { + s[:periodmatch] = :number + } + assert_raise(Puppet::Error) { + s[:repeat] = 2 + } + assert_nothing_raised("Was not able to reset periodmatch") { + s[:periodmatch] = :distance + } + + assert(! s.match?(min("-", 40)), "matched minus 40 minutes") + + assert_nothing_raised("Was not able to set period") { + s[:repeat] = 2 + } + + assert(! s.match?(min("-", 20)), "matched minus 20 minutes with half-hourly") + assert(s.match?(min("-", 40)), "Did not match minus 40 with half-hourly") + + assert_nothing_raised("Was not able to set period") { + s[:repeat] = 3 + } + + assert(! s.match?(min("-", 15)), "matched minus 15 minutes with half-hourly") + assert(s.match?(min("-", 25)), "Did not match minus 25 with half-hourly") + end +end + +# $Id$ |
