summaryrefslogtreecommitdiffstats
path: root/test/network/server/master.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-08 02:22:57 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-08 02:22:57 +0000
commita216df2bcb304ad379e152f2f59ef7d942f54f3b (patch)
treeeef3289c588cf44373fe959619d732c5a05ab7b5 /test/network/server/master.rb
parent7e07e3dc843798bdbc7a03428ca054adaff2fb72 (diff)
Okay, last file moves for the night. The test code has been moved to match the lib directory, and I have moved a couple of things into network/ instead of network/server, since they did not belong as much.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2180 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/network/server/master.rb')
-rwxr-xr-xtest/network/server/master.rb346
1 files changed, 346 insertions, 0 deletions
diff --git a/test/network/server/master.rb b/test/network/server/master.rb
new file mode 100755
index 000000000..797e75e3d
--- /dev/null
+++ b/test/network/server/master.rb
@@ -0,0 +1,346 @@
+#!/usr/bin/env ruby
+
+$:.unshift("../../lib") if __FILE__ =~ /\.rb$/
+
+require 'puppettest'
+require 'puppet/network/server'
+
+class TestMaster < Test::Unit::TestCase
+ include PuppetTest::ServerTest
+ def teardown
+ super
+ #print "\n\n\n\n" if Puppet[:debug]
+ end
+
+ # run through all of the existing test files and make sure everything
+ # works
+ def test_files
+ count = 0
+ textfiles { |file|
+ Puppet.debug("parsing %s" % file)
+ client = nil
+ master = nil
+
+ # create our master
+ assert_nothing_raised() {
+ # this is the default server setup
+ master = Puppet::Network::Server::Master.new(
+ :Manifest => file,
+ :UseNodes => false,
+ :Local => true
+ )
+ }
+
+ # and our client
+ assert_nothing_raised() {
+ client = Puppet::Network::Client::MasterClient.new(
+ :Master => master
+ )
+ }
+
+ # pull our configuration a few times
+ assert_nothing_raised() {
+ client.getconfig
+ stopservices
+ Puppet::Type.allclear
+ }
+ assert_nothing_raised() {
+ client.getconfig
+ stopservices
+ Puppet::Type.allclear
+ }
+ assert_nothing_raised() {
+ client.getconfig
+ stopservices
+ Puppet::Type.allclear
+ }
+ # only test three files; that's plenty
+ if count > 3
+ break
+ end
+ count += 1
+ }
+ 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::Server::Master.new(
+ :Manifest => file,
+ :UseNodes => false,
+ :Local => true
+ )
+ }
+ assert_nothing_raised() {
+ client = Puppet::Network::Client::MasterClient.new(
+ :Master => master
+ )
+ }
+
+ # pull our configuration
+ assert_nothing_raised() {
+ client.getconfig
+ stopservices
+ Puppet::Type.allclear
+ }
+
+ break
+ }
+ end
+
+ def test_filereread
+ # Start with a normal setting
+ Puppet[:filetimeout] = 15
+ manifest = mktestmanifest()
+
+ file2 = @createdfile + "2"
+ @@tmpfiles << file2
+
+ client = master = nil
+ assert_nothing_raised() {
+ # this is the default server setup
+ master = Puppet::Network::Server::Master.new(
+ :Manifest => manifest,
+ :UseNodes => false,
+ :Local => true
+ )
+ }
+ assert_nothing_raised() {
+ client = Puppet::Network::Client::MasterClient.new(
+ :Master => master
+ )
+ }
+
+ # The client doesn't have a config, so it can't be up to date
+ assert(! client.fresh?, "Client is incorrectly up to date")
+
+ Puppet.config.use(:puppet)
+ assert_nothing_raised {
+ client.getconfig
+ client.apply
+ }
+
+ # Now it should be up to date
+ assert(client.fresh?, "Client is not up to date")
+
+ # Cache this value for later
+ parse1 = master.freshness
+
+ # 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|
+ 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, "Master did not wait through timeout")
+ assert(client.fresh?, "Client is not up to date")
+
+ # Then eliminate it
+ Puppet[:filetimeout] = 0
+
+ # Now make sure the master does reparse
+ #Puppet.notice "%s vs %s" % [parse1, master.freshness]
+ assert(parse1 != master.freshness, "Master did not reparse file")
+ assert(! client.fresh?, "Client is incorrectly up to date")
+
+ # Retrieve and apply the new config
+ assert_nothing_raised {
+ client.getconfig
+ client.apply
+ }
+ assert(client.fresh?, "Client is not up to date")
+
+ assert(FileTest.exists?(file2), "Second file %s does not exist" % file2)
+ end
+
+ def test_addfacts
+ master = nil
+ file = mktestmanifest()
+ # create our master
+ assert_nothing_raised() {
+ # this is the default server setup
+ master = Puppet::Network::Server::Master.new(
+ :Manifest => file,
+ :UseNodes => false,
+ :Local => true
+ )
+ }
+
+ facts = {}
+
+ assert_nothing_raised {
+ master.addfacts(facts)
+ }
+
+ %w{serverversion servername serverip}.each do |fact|
+ assert(facts.include?(fact), "Fact %s was not set" % fact)
+ end
+ end
+
+ # Make sure we're using the hostname as configured with :node_name
+ def test_hostname_in_getconfig
+ master = nil
+ file = tempfile()
+ #@createdfile = File.join(tmpdir(), self.class.to_s + "manifesttesting" +
+ # "_" + @method_name)
+ file_cert = tempfile()
+ file_fact = tempfile()
+
+ certname = "y4yn3ss"
+ factname = Facter.value("hostname")
+
+ File.open(file, "w") { |f|
+ f.puts %{
+ node #{certname} { file { "#{file_cert}": ensure => file, mode => 755 } }
+ node #{factname} { file { "#{file_fact}": ensure => file, mode => 755 } }
+}
+ }
+ # create our master
+ assert_nothing_raised() {
+ # this is the default server setup
+ master = Puppet::Network::Server::Master.new(
+ :Manifest => file,
+ :UseNodes => true,
+ :Local => true
+ )
+ }
+
+ result = nil
+
+ # Use the hostname from facter
+ Puppet[:node_name] = 'facter'
+ assert_nothing_raised {
+ result = master.getconfig({"hostname" => factname}, "yaml", certname, "127.0.0.1")
+ }
+
+ result = result.flatten
+
+ assert(result.find { |obj| obj.name == file_fact },
+ "Could not find correct file")
+ assert(!result.find { |obj| obj.name == file_cert },
+ "Found incorrect file")
+
+ # Use the hostname from the cert
+ Puppet[:node_name] = 'cert'
+ assert_nothing_raised {
+ result = master.getconfig({"hostname" => factname}, "yaml", certname, "127.0.0.1")
+ }
+
+ result = result.flatten
+
+ assert(!result.find { |obj| obj.name == file_fact },
+ "Could not find correct file")
+ assert(result.find { |obj| obj.name == file_cert },
+ "Found incorrect file")
+ end
+
+ # Make sure we're correctly doing clientname manipulations.
+ # Testing to make sure we always get a hostname and IP address.
+ def test_clientname
+ master = nil
+ file = tempfile()
+
+ File.open(file, "w") { |f|
+ f.puts %{
+ node yay { file { "/something": ensure => file, mode => 755 } }
+}
+ }
+ # create our master
+ assert_nothing_raised() {
+ # this is the default server setup
+ master = Puppet::Network::Server::Master.new(
+ :Manifest => file,
+ :UseNodes => true,
+ :Local => true
+ )
+ }
+
+ Puppet[:node_name] = "cert"
+ # First act like we're local
+ fakename = nil
+ fakeip = nil
+
+ name = ip = nil
+ facts = Facter.to_hash
+ assert_nothing_raised do
+ name, ip = master.clientname(fakename, fakeip, facts)
+ end
+
+ assert(facts["hostname"], "Removed hostname fact")
+ assert(facts["ipaddress"], "Removed ipaddress fact")
+
+ assert_equal(facts["hostname"], name)
+ assert_equal(facts["ipaddress"], ip)
+
+ # Now set them to something real, and make sure we get them back
+ fakename = "yayness"
+ fakeip = "192.168.0.1"
+ facts = Facter.to_hash
+ assert_nothing_raised do
+ name, ip = master.clientname(fakename, fakeip, facts)
+ end
+
+ assert(facts["hostname"], "Removed hostname fact")
+ assert(facts["ipaddress"], "Removed ipaddress fact")
+
+ assert_equal(fakename, name)
+ assert_equal(fakeip, ip)
+ end
+
+ if Puppet.features.rails?
+ def test_freshness_connect_update
+ Puppet::Rails.init
+ Puppet[:storeconfigs] = true
+
+ # this is the default server setup
+ master = Puppet::Network::Server::Master.new(
+ :Code => "",
+ :UseNodes => true,
+ :Local => true
+ )
+
+ # Create a host
+ Puppet::Rails::Host.new(:name => "test", :ip => "192.168.0.3").save
+
+ assert_nothing_raised("Failed to update last_connect for unknown host") do
+ master.freshness("created",'192.168.0.1')
+ end
+
+ # Make sure it created the host
+ created = Puppet::Rails::Host.find_by_name("created")
+ assert(created, "Freshness did not create host")
+ assert(created.last_freshcheck,
+ "Did not set last_freshcheck on created host")
+ assert_equal("192.168.0.1", created.ip,
+ "Did not set IP address on created host")
+
+ # Now check on the existing host
+ assert_nothing_raised("Failed to update last_connect for unknown host") do
+ master.freshness("test",'192.168.0.2')
+ end
+
+ # Recreate it, so we're not using the cached object.
+ host = Puppet::Rails::Host.find_by_name("test")
+
+ # Make sure it created the host
+ assert(host.last_freshcheck,
+ "Did not set last_freshcheck on existing host")
+ assert_equal("192.168.0.3", host.ip,
+ "Overrode IP on found host")
+ end
+ end
+end
+
+# $Id$
+