diff options
| author | Luke Kanies <luke@madstop.com> | 2007-11-12 22:11:40 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-11-12 22:11:40 -0600 |
| commit | fa1924eb04a2d6600349eddf13e1f3e62b45d6ce (patch) | |
| tree | 978aa0e92812f5854978048162c6e2ab752dad72 /test/network | |
| parent | a535cbbe148802c0afe62cd2d5b29d0768b3a0f0 (diff) | |
| parent | 72510bfaa65e97f4eaaf246ef8f1c155716967b6 (diff) | |
Merge branch 'master' of ssh://reductivelabs.com/opt/rl/git/puppet-luke
Diffstat (limited to 'test/network')
| -rwxr-xr-x | test/network/client/master.rb | 144 | ||||
| -rwxr-xr-x | test/network/client/resource.rb | 8 | ||||
| -rwxr-xr-x | test/network/handler/master.rb | 68 | ||||
| -rwxr-xr-x | test/network/handler/runner.rb | 72 |
4 files changed, 55 insertions, 237 deletions
diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 4f6956470..7216af936 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -7,38 +7,6 @@ require 'mocha' class TestMasterClient < Test::Unit::TestCase include PuppetTest::ServerTest - - class FakeTrans - def initialize - @counters = Hash.new { |h,k| h[k] = 0 } - end - [:evaluate, :report, :cleanup, :addtimes, :tags, :ignoreschedules].each do |m| - define_method(m.to_s + "=") do |*args| - @counters[m] += 1 - end - define_method(m) do |*args| - @counters[m] += 1 - end - define_method(m.to_s + "?") do - @counters[m] - end - end - end - class FakeComponent - attr_accessor :trans - def evaluate - @trans = FakeTrans.new - @trans - end - - def finalize - @finalized = true - end - - def finalized? - @finalized - end - end def setup super @@ -67,66 +35,6 @@ class TestMasterClient < Test::Unit::TestCase return client end - - def mk_fake_client - server = Puppet::Network::Handler.master.new :Code => "" - master = Puppet::Network::Client.master.new :Master => server, :Local => true - - # Now create some objects - objects = FakeComponent.new - - master.send(:instance_variable_set, "@objects", objects) - - class << master - def report(r) - @reported ||= 0 - @reported += 1 - end - def reported - @reported ||= 0 - @reported - end - end - return master, objects - end - - def test_getconfig - client = mkclient - - $methodsrun = [] - cleanup { $methodsrun = nil } - client.meta_def(:getplugins) do - $methodsrun << :getplugins - end - client.meta_def(:get_actual_config) do - $methodsrun << :get_actual_config - result = Puppet::TransBucket.new() - result.type = "testing" - result.name = "yayness" - result - end - - assert_nothing_raised do - client.getconfig - end - [:get_actual_config].each do |method| - assert($methodsrun.include?(method), "method %s was not run" % method) - end - assert(! $methodsrun.include?(:getplugins), "plugins were synced even tho disabled") - - # Now set pluginsync - Puppet[:pluginsync] = true - $methodsrun.clear - - assert_nothing_raised do - client.getconfig - end - [:getplugins, :get_actual_config].each do |method| - assert($methodsrun.include?(method), "method %s was not run" % method) - end - - assert_instance_of(Puppet::Node::Configuration, client.configuration, "Configuration was not created") - end def test_disable FileUtils.mkdir_p(Puppet[:statedir]) @@ -136,27 +44,22 @@ class TestMasterClient < Test::Unit::TestCase client = mkclient(master) - assert(! FileTest.exists?(@createdfile)) - - assert_nothing_raised { + assert_nothing_raised("Could not disable client") { client.disable } - assert_nothing_raised { - client.run - } + client.expects(:getconfig).never - assert(! FileTest.exists?(@createdfile), "Disabled client ran") + client.run - assert_nothing_raised { - client.enable - } + client = mkclient(master) - assert_nothing_raised { - client.run - } + client.expects(:getconfig) - assert(FileTest.exists?(@createdfile), "Enabled client did not run") + assert_nothing_raised("Could not enable client") { + client.enable + } + client.run end # Make sure we're getting the client version in our list of facts @@ -652,15 +555,16 @@ end client = mkclient ftype = Puppet::Type.type(:file) + file = ftype.create :title => "/what/ever", :ensure => :present + config = Puppet::Node::Configuration.new + config.add_resource(file) - assert_nil(ftype[@createdfile], "file object already exists") - assert(! FileTest.exists?(@createdfile), "File already exists on disk") + config.expects :apply - assert_nothing_raised("Could not apply config") do - client.run - end + client.configuration = config + client.expects(:getconfig) + client.run - assert(FileTest.exists?(@createdfile), "File does not exist on disk") assert_nil(ftype[@createdfile], "file object was not removed from memory") end @@ -675,20 +579,20 @@ end end end - # #800 -- we cannot fix this using the current design. - def disabled_test_invalid_relationships_do_not_get_cached - # Make a master with an invalid relationship + def test_invalid_configurations_do_not_get_cached master = mkmaster :Code => "notify { one: require => File[yaytest] }" master.local = false # so it gets cached client = mkclient(master) + client.stubs(:facts).returns({}) client.local = false - client.getconfig - # Doesn't throw an exception, but definitely fails. - client.apply + Puppet::Node::Facts.indirection.stubs(:terminus_class).returns(:memory) # Make sure the config is not cached. - config = Puppet.settings[:localconfig] + ".yaml" - assert(! File.exists?(config), "Cached an invalid configuration") + client.expects(:cache).never + + client.getconfig + # Doesn't throw an exception, but definitely fails. + client.run end end diff --git a/test/network/client/resource.rb b/test/network/client/resource.rb index 83c195035..eb8e829eb 100755 --- a/test/network/client/resource.rb +++ b/test/network/client/resource.rb @@ -3,10 +3,13 @@ require File.dirname(__FILE__) + '/../../lib/puppettest' require 'puppettest' +require 'puppettest/support/utils' +require 'puppettest/support/assertions' require 'puppet/network/client/resource' class TestResourceClient < Test::Unit::TestCase include PuppetTest::ServerTest + include PuppetTest::Support::Utils def mkresourceserver Puppet::Network::Handler.resource.new @@ -35,6 +38,7 @@ class TestResourceClient < Test::Unit::TestCase assert_instance_of(Puppet::TransObject, tobj) + Puppet::Type.allclear obj = nil assert_nothing_raised { obj = tobj.to_type @@ -45,6 +49,7 @@ class TestResourceClient < Test::Unit::TestCase File.unlink(file) # Now test applying + Puppet::Type.allclear result = nil assert_nothing_raised { result = client.apply(tobj) @@ -52,6 +57,7 @@ class TestResourceClient < Test::Unit::TestCase assert(FileTest.exists?(file), "File was not created on apply") # Lastly, test "list" + Puppet::Type.allclear list = nil assert_nothing_raised { list = client.list("user") @@ -64,12 +70,14 @@ class TestResourceClient < Test::Unit::TestCase break if count > 3 assert_instance_of(Puppet::TransObject, tobj) + Puppet::Type.allclear tobj2 = nil assert_nothing_raised { tobj2 = client.describe(tobj.type, tobj.name) } obj = nil + Puppet::Type.allclear assert_nothing_raised { obj = tobj2.to_type } diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb index 694888f4d..25117030e 100755 --- a/test/network/handler/master.rb +++ b/test/network/handler/master.rb @@ -13,39 +13,11 @@ class TestMaster < Test::Unit::TestCase Puppet::Indirector::Indirection.clear_cache end - def test_defaultmanifest - textfiles { |file| - Puppet[:manifest] = file - client = nil - master = nil - assert_nothing_raised() { - # this is the default server setup - master = Puppet::Network::Handler.master.new( - :Manifest => file, - :UseNodes => false, - :Local => true - ) - } - assert_nothing_raised() { - client = Puppet::Network::Client.master.new( - :Master => master - ) - } - - # pull our configuration - assert_nothing_raised() { - client.getconfig - stopservices - Puppet::Type.allclear - } - - break - } - end - + # Make sure that files are reread when they change. def test_filereread # Start with a normal setting Puppet[:filetimeout] = 15 + manifest = mktestmanifest() facts = Puppet::Network::Client.master.facts @@ -63,35 +35,12 @@ class TestMaster < Test::Unit::TestCase :Local => true ) } - assert_nothing_raised() { - client = Puppet::Network::Client.master.new( - :Master => master - ) - } - assert(client, "did not create master client") - # The client doesn't have a config, so it can't be up to date - assert(! client.fresh?(facts), - "Client is incorrectly up to date") - - Puppet.settings.use(:main) - config = nil - assert_nothing_raised { - config = client.getconfig - config.apply - } - - # Now it should be up to date - assert(client.fresh?(facts), "Client is not up to date") + config = master.getconfig({"hostname" => "blah"}) # Cache this value for later parse1 = master.freshness("mynode") - # Verify the config got applied - assert(FileTest.exists?(@createdfile), - "Created file %s does not exist" % @createdfile) - Puppet::Type.allclear - sleep 1.5 # Create a new manifest File.open(manifest, "w") { |f| @@ -101,7 +50,6 @@ class TestMaster < Test::Unit::TestCase # Verify that the master doesn't immediately reparse the file; we # want to wait through the timeout assert_equal(parse1, master.freshness("mynode"), "Master did not wait through timeout") - assert(client.fresh?(facts), "Client is not up to date") # Then eliminate it Puppet[:filetimeout] = 0 @@ -109,16 +57,8 @@ class TestMaster < Test::Unit::TestCase # Now make sure the master does reparse #Puppet.notice "%s vs %s" % [parse1, master.freshness] assert(parse1 != master.freshness("mynode"), "Master did not reparse file") - assert(! client.fresh?(facts), "Client is incorrectly up to date") - - # Retrieve and apply the new config - assert_nothing_raised { - config = client.getconfig - config.apply - } - assert(client.fresh?(facts), "Client is not up to date") - assert(FileTest.exists?(file2), "Second file %s does not exist" % file2) + assert(master.getconfig({"hostname" => "blah"}) != config, "Did not use reloaded config") end # Make sure we're correctly doing clientname manipulations. diff --git a/test/network/handler/runner.rb b/test/network/handler/runner.rb index 402b27ffc..171458ffa 100755 --- a/test/network/handler/runner.rb +++ b/test/network/handler/runner.rb @@ -29,7 +29,8 @@ class TestHandlerRunner < Test::Unit::TestCase client end - def test_runner + def setup + super FileUtils.mkdir_p(Puppet[:statedir]) Puppet[:ignoreschedules] = false # Okay, make our manifest @@ -37,7 +38,7 @@ class TestHandlerRunner < Test::Unit::TestCase created = tempfile() # We specify the schedule here, because I was having problems with # using default schedules. - code = %{ + @code = %{ class yayness { schedule { "yayness": period => weekly } file { "#{created}": ensure => file, schedule => yayness } @@ -46,59 +47,24 @@ class TestHandlerRunner < Test::Unit::TestCase include yayness } - client = mkclient(code) + @client = mkclient(@code) - runner = nil - assert_nothing_raised { - runner = Puppet::Network::Handler.runner.new - } - # First: tags - # Second: ignore schedules true/false - # Third: background true/false - # Fourth: whether file should exist true/false - [ - ["with no backgrounding", - nil, true, true, true], - ["in the background", - nil, true, false, true], - ["with a bad tag", - ["coolness"], true, false, false], - ["with another bad tag", - "coolness", true, false, false], - ["with a good tag", - ["coolness", "yayness"], true, false, true], - ["with another good tag", - ["yayness"], true, false, true], - ["with a third good tag", - "yayness", true, false, true], - ["with no tags", - "", true, false, true], - ["not ignoring schedules", - nil, false, false, false], - ["ignoring schedules", - nil, true, false, true], - ].each do |msg, tags, ignore, fg, shouldexist| - if FileTest.exists?(created) - File.unlink(created) - end - assert_nothing_raised { - # Try it without backgrounding - runner.run(tags, ignore, fg) - } + @runner = Puppet::Network::Handler.runner.new + end + + def test_runner_when_in_foreground + @client.expects(:run).with(:tags => "mytags", :ignoreschedules => true) + + Process.expects(:newthread).never - unless fg - Puppet.join - end - - if shouldexist - assert(FileTest.exists?(created), "File did not get created " + - msg) - else - assert(!FileTest.exists?(created), "File got created incorrectly " + - msg) - end - end + @runner.run("mytags", true, true) end -end + def test_runner_when_in_background + @client.expects(:run).with(:tags => "mytags", :ignoreschedules => true) + + Puppet.expects(:newthread).yields + @runner.run("mytags", true, false) + end +end |
