[Pkg-puppet-devel] [facter] 54/61: (#12116) Don't break on the first interface

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 5a730af67e30812ff1cbb1cf4bd39611173ae3c8
Author: Josh Cooper <josh at puppetlabs.com>
Date:   Mon Aug 19 15:01:04 2013 -0700

    (#12116) Don't break on the first interface
    
    Previously, if there were multiple interfaces with IPEnabled on Windows,
    we would always use the DNSDomain value from the first interface, even
    if it was nil or empty.
    
    This commit changes the domain fact to look for the first non-nil and
    non-empty DNSDomain value.
---
 lib/facter/domain.rb     |    6 ++++--
 spec/unit/domain_spec.rb |   37 ++++++++++++++++++++++++++-----------
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb
index 6741b6e..9709d92 100644
--- a/lib/facter/domain.rb
+++ b/lib/facter/domain.rb
@@ -79,8 +79,10 @@ Facter.add(:domain) do
     if domain == ""
       require 'facter/util/wmi'
       Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
-        domain = nic.DNSDomain
-        break
+        if nic.DNSDomain && nic.DNSDomain.length > 0
+          domain = nic.DNSDomain
+          break
+        end
       }
     end
 
diff --git a/spec/unit/domain_spec.rb b/spec/unit/domain_spec.rb
index 93e259d..a2c1385 100755
--- a/spec/unit/domain_spec.rb
+++ b/spec/unit/domain_spec.rb
@@ -160,31 +160,46 @@ describe "Domain name facts" do
         Facter::Util::Registry.stubs(:hklm_read).returns('')
       end
 
-      it "should use the DNSDomain for the first nic where ip is enabled" do
-        nic = stubs 'nic'
-        nic.stubs(:DNSDomain).returns("foo.com")
+      def expects_dnsdomains(domains)
+        nics = []
 
-        nic2 = stubs 'nic'
-        nic2.stubs(:DNSDomain).returns("bar.com")
+        domains.each do |domain|
+          nic = stubs 'nic'
+          nic.stubs(:DNSDomain).returns(domain)
+          nics << nic
+        end
 
         require 'facter/util/wmi'
-        Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic, nic2])
+        Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns(nics)
+      end
+
+      it "uses the first DNSDomain" do
+        expects_dnsdomains(['foo.com', 'bar.com'])
 
         Facter.fact(:domain).value.should == 'foo.com'
       end
 
+      it "uses the first non-nil DNSDomain" do
+        expects_dnsdomains([nil, 'bar.com'])
+
+        Facter.fact(:domain).value.should == 'bar.com'
+      end
+
+      it "uses the first non-empty DNSDomain" do
+        expects_dnsdomains(['', 'bar.com'])
+
+        Facter.fact(:domain).value.should == 'bar.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)
+          expects_dnsdomains([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

-- 
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