[Pkg-puppet-devel] [facter] 52/61: (#12116) Windows domain/fqdn error when no domain

Stig Sandbeck Mathisen ssm at debian.org
Mon Nov 4 15:02:04 UTC 2013


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit b9abdd1635ce6b18a42088ab1102ba171a205544
Author: Rob Reynolds <ferventcoder at gmail.com>
Date:   Mon Aug 19 14:13:39 2013 -0500

    (#12116) Windows domain/fqdn error when no domain
    
    This fixes an annoying issue that causes facter to throw errors when domain is
    not properly configured or doesn't exist. With this fix, it will properly
    return an empty domain and empty fqdn without errorring.
    
    When moving up the chain to the less specific domain fact, added a
    windows_hostname command and a check so that it also does not fail with path
    not found errors.
    
    Paired-with: Josh Cooper<josh at puppetlabs.com>
---
 lib/facter/domain.rb     |    8 +++++++-
 spec/unit/domain_spec.rb |   16 ++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb
index 5d176e6..6741b6e 100644
--- a/lib/facter/domain.rb
+++ b/lib/facter/domain.rb
@@ -29,11 +29,14 @@ Facter.add(:domain) do
     # Due to dangerous behavior of 'hostname -f' on old OS, we will explicitly opt-in
     # 'hostname -f' --hkenney May 9, 2012
     basic_hostname = 'hostname 2> /dev/null'
+    windows_hostname = 'hostname > NUL'
     full_hostname = 'hostname -f 2> /dev/null'
     can_do_hostname_f = Regexp.union /Linux/i, /FreeBSD/i, /Darwin/i
 
     hostname_command = if Facter.value(:kernel) =~ can_do_hostname_f
                          full_hostname
+                       elsif Facter.value(:kernel) == "windows"
+                         windows_hostname
                        else
                          basic_hostname
                        end
@@ -42,7 +45,7 @@ Facter.add(:domain) do
       and name =~ /.*?\.(.+$)/
 
       return_value = $1
-    elsif domain = Facter::Util::Resolution.exec('dnsdomainname 2> /dev/null') \
+    elsif Facter.value(:kernel) != "windows" and domain = Facter::Util::Resolution.exec('dnsdomainname 2> /dev/null') \
       and domain =~ /.+/
 
       return_value = domain
@@ -80,6 +83,9 @@ Facter.add(:domain) do
         break
       }
     end
+
+    domain ||= ''
+
     domain.gsub(/\.$/, '')
   end
 end
diff --git a/spec/unit/domain_spec.rb b/spec/unit/domain_spec.rb
index 96176f9..93e259d 100755
--- a/spec/unit/domain_spec.rb
+++ b/spec/unit/domain_spec.rb
@@ -172,6 +172,22 @@ describe "Domain name facts" do
 
         Facter.fact(:domain).value.should == 'foo.com'
       end
+
+      context "without any network adapters with a specified DNSDomain" do
+        let(:hostname_command) { 'hostname > NUL' }
+
+        it "should return nil" do
+          nic = stubs 'nic'
+          nic.stubs(:DNSDomain).returns(nil)
+          Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns('sometest')
+          FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(false)
+
+          require 'facter/util/wmi'
+          Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic])
+
+          Facter.fact(:domain).value.should be_nil
+        end
+      end
     end
   end
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list