The cert name should be searched first in default
circumstances, even if it disagrees with the hostname.

Brice's change to the way catalogs are searched for didn't
quite work when the hostname and certname didn't agree *and*
the certname was fully qualified.

Signed-off-by: Luke Kanies <[email protected]>
---
 lib/puppet/node.rb |   20 ++++++++++++++------
 spec/unit/node.rb  |   21 ++++++++++++---------
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb
index 263aaf6..ad5a40b 100644
--- a/lib/puppet/node.rb
+++ b/lib/puppet/node.rb
@@ -85,6 +85,10 @@ class Puppet::Node
 
         names = []
 
+        if name.include?(".")
+            names += split_name(name)
+        end
+
         # First, get the fqdn
         unless fqdn = parameters["fqdn"]
             if parameters["hostname"] and parameters["domain"]
@@ -97,12 +101,7 @@ class Puppet::Node
         # Now that we (might) have the fqdn, add each piece to the name
         # list to search, in order of longest to shortest.
         if fqdn
-            list = fqdn.split(".")
-            tmp = []
-            list.each_with_index do |short, i|
-                tmp << list[0..i].join(".")
-            end
-            names += tmp.reverse
+            names += split_name(fqdn)
         end
 
         # And make sure the node name is first, since that's the most
@@ -116,4 +115,13 @@ class Puppet::Node
         end
         names.uniq
     end
+
+    def split_name(name)
+        list = name.split(".")
+        tmp = []
+        list.each_with_index do |short, i|
+            tmp << list[0..i].join(".")
+        end
+        tmp.reverse
+    end
 end
diff --git a/spec/unit/node.rb b/spec/unit/node.rb
index fb7d363..025bdc8 100755
--- a/spec/unit/node.rb
+++ b/spec/unit/node.rb
@@ -147,23 +147,26 @@ describe Puppet::Node, "when generating the list of names 
to search through" do
         @node.names.should be_instance_of(Array)
     end
 
-    it "should have the node's fqdn as the second name" do
-        @node.names[1].should == "yay.domain.com"
+    describe "and the node name is fully qualified" do
+        it "should contain an entry for each part of the node name" do
+            @node.names.should be_include("foo.domain.com")
+            @node.names.should be_include("foo.domain")
+            @node.names.should be_include("foo")
+        end
     end
 
-    it "should set the fqdn to the node's 'fqdn' fact if it is available" do
-        @node.parameters["fqdn"] = "boo.domain.com"
-        @node.names[1].should == "boo.domain.com"
+    it "should include the node's fqdn" do
+        @node.names.should be_include("yay.domain.com")
     end
 
-    it "should set the fqdn to the node's hostname and domain if no fqdn is 
available" do
-        @node.names[1].should == "yay.domain.com"
+    it "should combine and include the node's hostname and domain if no fqdn 
is available" do
+        @node.names.should be_include("yay.domain.com")
     end
 
     it "should contain an entry for each name available by stripping a segment 
of the fqdn" do
         @node.parameters["fqdn"] = "foo.deep.sub.domain.com"
-        @node.names[2].should == "foo.deep.sub.domain"
-        @node.names[3].should == "foo.deep.sub"
+        @node.names.should be_include("foo.deep.sub.domain")
+        @node.names.should be_include("foo.deep.sub")
     end
 
     describe "and :node_name is set to 'cert'" do
-- 
1.6.1


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to