summaryrefslogtreecommitdiffstats
path: root/test/network/handler/master.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/network/handler/master.rb')
-rwxr-xr-xtest/network/handler/master.rb129
1 files changed, 27 insertions, 102 deletions
diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb
index 9cf52b1cd..5ac8cbbbc 100755
--- a/test/network/handler/master.rb
+++ b/test/network/handler/master.rb
@@ -116,114 +116,39 @@ class TestMaster < Test::Unit::TestCase
assert(FileTest.exists?(file2), "Second file %s does not exist" % file2)
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::Handler.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::Handler.master.new(
- :Manifest => file,
- :UseNodes => true,
- :Local => true
- )
- }
+ master = Puppet::Network::Handler.master.new(
+ :Manifest => tempfile,
+ :UseNodes => true,
+ :Local => true
+ )
+
+ # First check that 'cert' works
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)
+
+ # Make sure we get the fact data back when nothing is set
+ facts = {"hostname" => "fact_hostname", "ipaddress" => "fact_ip"}
+ certname = "cert_hostname"
+ certip = "cert_ip"
+
+ resname, resip = master.send(:clientname, nil, nil, facts)
+ assert_equal(facts["hostname"], resname, "Did not use fact hostname when no certname was present")
+ assert_equal(facts["ipaddress"], resip, "Did not use fact ip when no certname was present")
+
+ # Now try it with the cert stuff present
+ resname, resip = master.send(:clientname, certname, certip, facts)
+ assert_equal(certname, resname, "Did not use cert hostname when certname was present")
+ assert_equal(certip, resip, "Did not use cert ip when certname was present")
+
+ # And reset the node_name stuff and make sure we use it.
+ Puppet[:node_name] = :facter
+ resname, resip = master.send(:clientname, certname, certip, facts)
+ assert_equal(facts["hostname"], resname, "Did not use fact hostname when nodename was set to facter")
+ assert_equal(facts["ipaddress"], resip, "Did not use fact ip when nodename was set to facter")
end
end