From 553b2ad8add20cd629fcd90b512d97d4edd7e481 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 19 Dec 2007 11:42:22 -0600 Subject: Entirely refactoring http keep-alive. There's now a central module responsible for managing the http pool (Puppet::Network::HttpPool), and it also handles setting certificate information. This gets rid of what were otherwise long chains of method calls, and it makes the code paths much clearer. --- test/network/client/client.rb | 30 ------------------------------ test/network/server/webrick.rb | 8 +++++++- test/network/xmlrpc/client.rb | 39 --------------------------------------- 3 files changed, 7 insertions(+), 70 deletions(-) (limited to 'test/network') diff --git a/test/network/client/client.rb b/test/network/client/client.rb index 2588b9be5..b6b915d31 100755 --- a/test/network/client/client.rb +++ b/test/network/client/client.rb @@ -221,34 +221,4 @@ class TestClient < Test::Unit::TestCase end end end - - # Make sure that reading the cert in also sets up the cert stuff for the driver - def test_read_cert - Puppet::Util::SUIDManager.stubs(:asuser).yields - - ca = Puppet::Network::Handler.ca.new - caclient = Puppet::Network::Client.ca.new :CA => ca - - caclient.request_cert - - # First make sure it doesn't get called when the driver doesn't support :cert_setup - client = FakeClient.new :Test => FakeDriver.new - driver = client.driver - - assert_nothing_raised("Could not read cert") do - client.read_cert - end - - # And then that it does when the driver supports it - client = FakeClient.new :Test => FakeDriver.new - - driver = client.driver - driver.meta_def(:recycle_connection) { |c| } - driver.expects(:recycle_connection).with(client) - - assert_nothing_raised("Could not read cert") do - client.read_cert - end - end end - diff --git a/test/network/server/webrick.rb b/test/network/server/webrick.rb index 3561cd41a..d3408c166 100755 --- a/test/network/server/webrick.rb +++ b/test/network/server/webrick.rb @@ -14,6 +14,11 @@ class TestWebrickServer < Test::Unit::TestCase super end + def teardown + super + Puppet::Network::HttpPool.clear_http_instances + end + # Make sure we can create a server, and that it knows how to create its # certs by default. def test_basics @@ -102,7 +107,7 @@ class TestWebrickServer < Test::Unit::TestCase assert_nothing_raised() { client = Puppet::Network::Client.status.new( - :Server => Facter.value(:fqdn), + :Server => "localhost", :Port => @@port ) } @@ -111,6 +116,7 @@ class TestWebrickServer < Test::Unit::TestCase def mk_status_server server = nil + Puppet[:certdnsnames] = "localhost" assert_nothing_raised() { server = Puppet::Network::HTTPServer::WEBrick.new( :Port => @@port, diff --git a/test/network/xmlrpc/client.rb b/test/network/xmlrpc/client.rb index f6d234324..53be5ca07 100755 --- a/test/network/xmlrpc/client.rb +++ b/test/network/xmlrpc/client.rb @@ -42,43 +42,4 @@ class TestXMLRPCClient < Test::Unit::TestCase assert(net, "did not get net client") end - - # Make sure the xmlrpc client is correctly reading all of the cert stuff - # and setting it into the @http var - def test_cert_setup - client = nil - assert_nothing_raised do - client = Puppet::Network::XMLRPCClient.new() - end - - caclient = mock 'client', :cert => :ccert, :key => :ckey - - FileTest.expects(:exist?).with(Puppet[:localcacert]).returns(true) - - store = mock 'sslstore' - OpenSSL::X509::Store.expects(:new).returns(store) - store.expects(:add_file).with(Puppet[:localcacert]) - store.expects(:purpose=).with(OpenSSL::X509::PURPOSE_SSL_CLIENT) - - class << client - attr_accessor :http - end - - http = mock 'http' - client.http = http - - http.expects(:ca_file).returns(false) - http.expects(:ca_file=).with(Puppet[:localcacert]) - http.expects(:cert=).with(:ccert) - http.expects(:key=).with(:ckey) - http.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER) - http.expects(:cert_store=) - - assert_nothing_raised do - client.cert_setup(caclient) - end - end - - def test_http_cache - end end -- cgit From 927cb24c0a6783b87bc511227f1640143c4a4649 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 19 Dec 2007 13:43:22 -0600 Subject: Fixing #967 -- default resources no longer conflict with managed resources. --- test/network/client/master.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'test/network') diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 60058aed9..3ec1d4d36 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -333,14 +333,16 @@ end assert(FileTest.exists?(file), "file was not created on second run") end - def test_default_objects + def test_default_resources + client = mkclient() + # Make sure they start out missing assert_nil(Puppet::Type.type(:filebucket)["puppet"], "default filebucket already exists") assert_nil(Puppet::Type.type(:schedule)["daily"], "default schedules already exists") - master = mkclient() + client.make_default_resources # Now make sure they got created assert(Puppet::Type.type(:filebucket)["puppet"], @@ -354,7 +356,7 @@ end "default filebucket not removed") assert_nil(Puppet::Type.type(:schedule)["daily"], "default schedules not removed") - assert_nothing_raised { master.mkdefault_objects } + assert_nothing_raised { client.make_default_resources } assert(Puppet::Type.type(:filebucket)["puppet"], "default filebucket not found") assert(Puppet::Type.type(:schedule)["daily"], @@ -366,6 +368,19 @@ end assert(Puppet::Type.type(:filebucket)["puppet"], "Could not retrieve default bucket") end + # #965 - make sure default objects don't conflict with existing + # objects. + def test_default_resources_do_not_conflict_with_managed_resources + # Create some that conflict with our defaults + bucket = Puppet::Type.type(:filebucket).create :name => "puppet" + schedule = Puppet::Type.type(:schedule).create :name => "daily" + + client = mkclient() + + # Then make sure creating new defaults doesn't throw an exception. + assert_nothing_raised("Default resources conflicted with resources in the catalog") { client.make_default_resources } + end + # #540 - make sure downloads aren't affected by noop def test_download_in_noop source = tempfile -- cgit From c59ff622a33b82f413207a146edd4ff6e011e729 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 21 Dec 2007 17:52:06 -0600 Subject: Further fixes toward #965. Turned out that the previous fix caused other problems. This whole thing will hopefully get *drastically* easier once we get rid of global resources. --- test/network/client/master.rb | 48 ------------------------------------------- 1 file changed, 48 deletions(-) (limited to 'test/network') diff --git a/test/network/client/master.rb b/test/network/client/master.rb index 3ec1d4d36..696d08bfd 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -333,54 +333,6 @@ end assert(FileTest.exists?(file), "file was not created on second run") end - def test_default_resources - client = mkclient() - - # Make sure they start out missing - assert_nil(Puppet::Type.type(:filebucket)["puppet"], - "default filebucket already exists") - assert_nil(Puppet::Type.type(:schedule)["daily"], - "default schedules already exists") - - client.make_default_resources - - # Now make sure they got created - assert(Puppet::Type.type(:filebucket)["puppet"], - "default filebucket not found") - assert(Puppet::Type.type(:schedule)["daily"], - "default schedules not found") - - # clear everything, and make sure we can recreate them - Puppet::Type.allclear - assert_nil(Puppet::Type.type(:filebucket)["puppet"], - "default filebucket not removed") - assert_nil(Puppet::Type.type(:schedule)["daily"], - "default schedules not removed") - assert_nothing_raised { client.make_default_resources } - assert(Puppet::Type.type(:filebucket)["puppet"], - "default filebucket not found") - assert(Puppet::Type.type(:schedule)["daily"], - "default schedules not found") - - - # Make sure we've got schedules - assert(Puppet::Type.type(:schedule)["hourly"], "Could not retrieve hourly schedule") - assert(Puppet::Type.type(:filebucket)["puppet"], "Could not retrieve default bucket") - end - - # #965 - make sure default objects don't conflict with existing - # objects. - def test_default_resources_do_not_conflict_with_managed_resources - # Create some that conflict with our defaults - bucket = Puppet::Type.type(:filebucket).create :name => "puppet" - schedule = Puppet::Type.type(:schedule).create :name => "daily" - - client = mkclient() - - # Then make sure creating new defaults doesn't throw an exception. - assert_nothing_raised("Default resources conflicted with resources in the catalog") { client.make_default_resources } - end - # #540 - make sure downloads aren't affected by noop def test_download_in_noop source = tempfile -- cgit