diff options
author | Luke Kanies <luke@madstop.com> | 2008-04-11 13:01:42 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-04-11 13:01:42 -0500 |
commit | fb05ef3c96038d67a46eb142202af186ad6cb0b3 (patch) | |
tree | 148e8b882e5c8104c4f3fa8ecc4288e8608f812d /test/network | |
parent | b49fb68f768e8b98c555ef0ae08a7bd22f5d36bd (diff) | |
parent | b49fd495622b15f96faf944db1e70cbe9e7fe7c4 (diff) | |
download | puppet-fb05ef3c96038d67a46eb142202af186ad6cb0b3.tar.gz puppet-fb05ef3c96038d67a46eb142202af186ad6cb0b3.tar.xz puppet-fb05ef3c96038d67a46eb142202af186ad6cb0b3.zip |
Merge branch '0.24.x'
Diffstat (limited to 'test/network')
-rwxr-xr-x | test/network/client/master.rb | 110 | ||||
-rwxr-xr-x | test/network/handler/configuration.rb | 160 | ||||
-rwxr-xr-x | test/network/handler/master.rb | 53 |
3 files changed, 9 insertions, 314 deletions
diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 682d48eb5..c0d14ccee 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -305,44 +305,6 @@ end assert_equal(RUBY_VERSION, facts["rubyversion"], "ruby version did not get added") end - # #424 - def test_caching_of_compile_time - file = tempfile() - manifest = tempfile() - File.open(manifest, "w") { |f| f.puts "file { '#{file}': content => yay }" } - - Puppet::Node::Facts.indirection.stubs(:save) - - driver = mkmaster(:Manifest => manifest) - driver.local = false - master = mkclient(driver) - - # We have to make everything thinks it's remote, because there's no local caching info - master.local = false - - assert(! master.fresh?(master.class.facts), - "Considered fresh with no compile at all") - - assert_nothing_raised { master.run } - assert(master.fresh?(master.class.facts), - "not considered fresh after compile") - - # Now make sure the config time is cached - assert(master.compile_time, "No stored config time") - assert_equal(master.compile_time, Puppet::Util::Storage.cache(:configuration)[:compile_time], "times did not match") - time = master.compile_time - master.clear - File.unlink(file) - Puppet::Util::Storage.store - - # Now make a new master - Puppet::Util::Storage.clear - master = mkclient(driver) - master.run - assert_equal(time, master.compile_time, "time was not retrieved from cache") - assert(FileTest.exists?(file), "file was not created on second run") - end - # #540 - make sure downloads aren't affected by noop def test_download_in_noop source = tempfile @@ -384,44 +346,6 @@ end "Tried to load cache when it is non-existent") end - # #519 - cache the facts so that we notice if they change. - def test_factchanges_cause_recompile - $value = "one" - Facter.add(:testfact) do - setcode { $value } - end - assert_equal("one", Facter.value(:testfact), "fact was not set correctly") - master = mkclient - master.local = false - driver = master.send(:instance_variable_get, "@driver") - driver.local = false - - Puppet::Node::Facts.indirection.stubs(:save) - - assert_nothing_raised("Could not compile config") do - master.getconfig - end - - $value = "two" - Facter.clear - Facter.loadfacts - Facter.add(:testfact) do - setcode { $value } - end - facts = master.class.facts - assert_equal("two", Facter.value(:testfact), "fact did not change") - - assert(master.send(:facts_changed?, facts), - "master does not think facts changed") - assert(! master.fresh?(facts), - "master is considered fresh after facts changed") - - assert_nothing_raised("Could not recompile when facts changed") do - master.getconfig - end - - end - def test_locking master = mkclient @@ -455,40 +379,6 @@ end assert_equal(100, master.timeout, "Did not get changed integer default value for timeout on second run") end - # #569 -- Make sure we can ignore dynamic facts. - def test_dynamic_facts - client = mkclient - - assert_equal(%w{memorysize memoryfree swapsize swapfree}, client.class.dynamic_facts, - "Did not get correct defaults for dynamic facts") - - # Cache some values for comparison - cached = {"one" => "yep", "two" => "nope"} - Puppet::Util::Storage.cache(:configuration)[:facts] = cached - - assert(! client.send(:facts_changed?, cached), "Facts incorrectly considered to be changed") - - # Now add some values to the passed result and make sure we get a positive - newfacts = cached.dup - newfacts["changed"] = "something" - - assert(client.send(:facts_changed?, newfacts), "Did not catch changed fact") - - # Now add a dynamic fact and make sure it's ignored - newfacts = cached.dup - newfacts["memorysize"] = "something" - - assert(! client.send(:facts_changed?, newfacts), "Dynamic facts resulted in a false positive") - - # And try it with both - cached["memorysize"] = "something else" - assert(! client.send(:facts_changed?, newfacts), "Dynamic facts resulted in a false positive") - - # And finally, with only in the cache - newfacts.delete("memorysize") - assert(! client.send(:facts_changed?, newfacts), "Dynamic facts resulted in a false positive") - end - def test_splay client = mkclient diff --git a/test/network/handler/configuration.rb b/test/network/handler/configuration.rb deleted file mode 100755 index 36c5d9e54..000000000 --- a/test/network/handler/configuration.rb +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../lib/puppettest' - -require 'puppettest' -require 'puppet/network/handler/configuration' - -class TestHandlerConfiguration < Test::Unit::TestCase - include PuppetTest - - Config = Puppet::Network::Handler.handler(:configuration) - - # Check all of the setup stuff. - def test_initialize - config = nil - assert_nothing_raised("Could not create local config") do - config = Config.new(:Local => true) - end - - assert(config.local?, "Config is not considered local after being started that way") - end - - # Test creation/returning of the interpreter - def test_interpreter - config = Config.new - - # First test the defaults - config.expects(:create_interpreter).returns(:interp) - assert_equal(:interp, config.send(:interpreter), "Did not return the interpreter") - - # Now run it again and make sure we get the same thing - assert_equal(:interp, config.send(:interpreter), "Did not cache the interpreter") - end - - def test_create_interpreter - config = Config.new(:Local => false) - args = {} - - # Try it first with defaults. - Puppet::Parser::Interpreter.expects(:new).returns(:interp) - assert_equal(:interp, config.send(:create_interpreter), "Did not return the interpreter") - end - - # Make sure node objects get appropriate data added to them. - def test_add_node_data - # First with no classes - config = Config.new - - fakenode = Object.new - # Set the server facts to something - config.instance_variable_set("@server_facts", :facts) - fakenode.expects(:merge).with(:facts) - config.send(:add_node_data, fakenode) - - # Now try it with classes. - config.classes = %w{a b} - list = [] - fakenode = Object.new - fakenode.expects(:merge).with(:facts) - fakenode.expects(:classes).returns(list).times(2) - config.send(:add_node_data, fakenode) - assert_equal(%w{a b}, list, "Did not add classes to node") - end - - def test_compile - config = Config.new - - # First do a local - node = mock 'node' - node.stubs(:name).returns(:mynode) - node.stubs(:environment).returns(:myenv) - - interp = mock 'interpreter' - interp.stubs(:environment) - interp.expects(:compile).with(node).returns(:config) - config.expects(:interpreter).returns(interp) - - Puppet.expects(:notice) # The log message from benchmarking - - assert_equal(:config, config.send(:compile, node), "Did not return config") - - # Now try it non-local - node = mock 'node' - node.stubs(:name).returns(:mynode) - node.stubs(:environment).returns(:myenv) - - interp = mock 'interpreter' - interp.stubs(:environment) - interp.expects(:compile).with(node).returns(:config) - - config = Config.new(:Local => true) - config.expects(:interpreter).returns(interp) - - assert_equal(:config, config.send(:compile, node), "Did not return config") - end - - def test_set_server_facts - config = Config.new - assert_nothing_raised("Could not call :set_server_facts") do - config.send(:set_server_facts) - end - facts = config.instance_variable_get("@server_facts") - %w{servername serverversion serverip}.each do |fact| - assert(facts.include?(fact), "Config did not set %s fact" % fact) - end - end - - def test_translate - # First do a local config - config = Config.new(:Local => true) - assert_equal(:plain, config.send(:translate, :plain), "Attempted to translate local config") - - # Now a non-local - config = Config.new(:Local => false) - assert(! config.local?, "Config wrongly thinks it's local") - obj = mock 'dumpee' - yamld = mock 'yaml' - obj.expects(:to_yaml).with(:UseBlock => true).returns(yamld) - CGI.expects(:escape).with(yamld).returns(:translated) - assert_equal(:translated, config.send(:translate, obj), "Did not return translated config") - end - - # Check that we're storing the node freshness into the rails db. Hackilicious. - def test_update_node_check - # This is stupid. - config = Config.new - node = Object.new - node.expects(:name).returns(:hostname) - now = Object.new - Time.expects(:now).returns(now) - host = Object.new - host.expects(:last_freshcheck=).with(now) - host.expects(:save) - - # Only test the case where rails is there - Puppet[:storeconfigs] = true - Puppet.features.expects(:rails?).returns(true) - Puppet::Rails.expects(:connect) - Puppet::Rails::Host.expects(:find_or_create_by_name).with(:hostname).returns(host) - - config.send(:update_node_check, node) - end - - def test_version - # First try the case where we can't look up the node - config = Config.new - node = Object.new - Puppet::Node.stubs(:find_by_any_name).with(:client).returns(false, node) - interp = Object.new - assert_instance_of(Bignum, config.version(:client), "Did not return configuration version") - - # And then when we find the node. - config = Config.new - config.expects(:update_node_check).with(node) - interp = Object.new - interp.expects(:configuration_version).returns(:version) - config.expects(:interpreter).returns(interp) - assert_equal(:version, config.version(:client), "Did not return configuration version") - end -end diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb index 55522237b..e91ec2f47 100755 --- a/test/network/handler/master.rb +++ b/test/network/handler/master.rb @@ -13,52 +13,17 @@ class TestMaster < Test::Unit::TestCase Puppet::Indirector::Indirection.clear_cache 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 - # Store them, so we don't determine frshness based on facts. - Puppet::Util::Storage.cache(:configuration)[:facts] = facts - - file2 = @createdfile + "2" - @@tmpfiles << file2 - - client = master = nil - Puppet[:manifest] = manifest - assert_nothing_raised() { - # this is the default server setup - master = Puppet::Network::Handler.master.new( - :Local => true - ) - } - - config = master.getconfig({"hostname" => "blah"}) - - # Cache this value for later - parse1 = master.freshness("mynode") - - sleep 1.5 - # Create a new manifest - File.open(manifest, "w") { |f| - f.puts "file { \"%s\": ensure => file }\n" % file2 - } - - # 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") - - # Then eliminate it - Puppet[:filetimeout] = 0 + def test_freshness_is_always_now + master = Puppet::Network::Handler.master.new( + :Manifest => tempfile, + :UseNodes => true, + :Local => true + ) - # 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") + now1 = mock 'now1' + Time.expects(:now).returns(now1) - assert(master.getconfig({"hostname" => "blah"}) != config, "Did not use reloaded config") + assert_equal(master.freshness, now1, "Did not return current time as freshness") end # Make sure we're correctly doing clientname manipulations. |