diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-22 22:24:12 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-22 22:24:12 +0000 |
commit | 55f2873d454dfb32593171e3f2b16f3b4221d897 (patch) | |
tree | db92bec4529d3f595ce3bc47a72e8b5785265b70 | |
parent | 3aac2e1eb48efa8f97d9c2e00b224c448cb77e8f (diff) | |
download | puppet-55f2873d454dfb32593171e3f2b16f3b4221d897.tar.gz puppet-55f2873d454dfb32593171e3f2b16f3b4221d897.tar.xz puppet-55f2873d454dfb32593171e3f2b16f3b4221d897.zip |
Merging the fix to server/master.rb
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1673 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/server/master.rb | 25 | ||||
-rw-r--r-- | test/server/master.rb | 55 |
2 files changed, 72 insertions, 8 deletions
diff --git a/lib/puppet/server/master.rb b/lib/puppet/server/master.rb index 198a6f682..1822e779e 100644 --- a/lib/puppet/server/master.rb +++ b/lib/puppet/server/master.rb @@ -36,6 +36,23 @@ class Server end end + # Manipulate the client name as appropriate. + def clientname(name, ip, facts) + # Always use the hostname from Facter. + client = facts["hostname"] + clientip = facts["ipaddress"] + if Puppet[:node_name] == 'cert' + if name + client = name + end + if ip + clientip = ip + end + end + + return client, clientip + end + # Tell a client whether there's a fresh config for it def freshness(client = nil, clientip = nil) if defined? @interpreter @@ -120,13 +137,7 @@ class Server end end - # Always use the hostname from Facter. - if Puppet[:node_name] == 'facter' - client = facts["hostname"] - clientip = facts["ipaddress"] - else - facts['hostname'] = client - end + client, clientip = clientname(client, clientip, facts) # Add any server-side facts to our server. addfacts(facts) diff --git a/test/server/master.rb b/test/server/master.rb index 2d1b9ec2c..b04fc92fd 100644 --- a/test/server/master.rb +++ b/test/server/master.rb @@ -116,6 +116,7 @@ class TestMaster < Test::Unit::TestCase # 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 @@ -195,7 +196,7 @@ class TestMaster < Test::Unit::TestCase file_fact = tempfile() certname = "y4yn3ss" - factname = Facter["hostname"].value + factname = Facter.value("hostname") File.open(file, "w") { |f| f.puts %{ @@ -242,6 +243,58 @@ class TestMaster < Test::Unit::TestCase "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::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 end # $Id$ |