[Pkg-puppet-devel] [facter] 20/352: (#22619) Error when NetConnectionId is missing

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:27 UTC 2014


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

ssm pushed a commit to branch master
in repository facter.

commit 874a5a96ac5fa778c50f1e93424850022b1756cf
Author: Rob Reynolds <ferventcoder at gmail.com>
Date:   Mon Sep 23 10:24:19 2013 -0500

    (#22619) Error when NetConnectionId is missing
    
    When someone is using something like failover clustering, an adapter
    configuration is created and set to IPEnabled but the underlying network
    adapter is set to NetEnabled=False. Further, the NetConnectionId is empty and
    causes facter to error. This adds a check to remove items where the adapter
    itself is NetEnabled=False as well. This also adds a check to not add empty or
    nil items to the list of interfaces.
---
 lib/facter/util/ip/windows.rb     |  4 ++--
 spec/unit/util/ip/windows_spec.rb | 36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/lib/facter/util/ip/windows.rb b/lib/facter/util/ip/windows.rb
index 30c4c05..0bbdfa7 100644
--- a/lib/facter/util/ip/windows.rb
+++ b/lib/facter/util/ip/windows.rb
@@ -43,8 +43,8 @@ class Facter::Util::IP::Windows
     interface_names = []
 
     network_adapter_configurations.map do |nic|
-      Facter::Util::WMI.execquery("SELECT * FROM Win32_NetworkAdapter WHERE Index = #{nic.Index}").each do |nic|
-        interface_names << nic.NetConnectionId
+      Facter::Util::WMI.execquery("SELECT * FROM Win32_NetworkAdapter WHERE Index = #{nic.Index} AND NetEnabled = TRUE").each do |nic|
+        interface_names << nic.NetConnectionId unless nic.NetConnectionId.nil? or nic.NetConnectionId.empty?
       end
     end
 
diff --git a/spec/unit/util/ip/windows_spec.rb b/spec/unit/util/ip/windows_spec.rb
index da7cbc5..208ad60 100644
--- a/spec/unit/util/ip/windows_spec.rb
+++ b/spec/unit/util/ip/windows_spec.rb
@@ -34,15 +34,47 @@ describe Facter::Util::IP::Windows do
     let(:name)       { 'Local Area Connection' }
     let(:index)      { 7 }
     let(:nic_config) { mock('nic_config', :Index => index) }
-    let(:nic)        { mock('nic', :NetConnectionId => name ) }
+    let(:nic)        { stub('nic', :NetConnectionId => name ) }
+    let(:nic_empty_NetConnectionId)        { stub('nic', :NetConnectionId => '' ) }
+    let(:nic_nil_NetConnectionId)        { stub('nic', :NetConnectionId => nil ) }
+    let(:wmi_query) {"SELECT * FROM Win32_NetworkAdapter WHERE Index = #{index} AND NetEnabled = TRUE"}
 
     it "should return an array of only connected interfaces" do
       Facter::Util::WMI.expects(:execquery).with(Facter::Util::IP::Windows::WMI_IP_INFO_QUERY).
         returns([nic_config])
-      Facter::Util::WMI.expects(:execquery).with("SELECT * FROM Win32_NetworkAdapter WHERE Index = #{index}").
+      Facter::Util::WMI.expects(:execquery).with(wmi_query).
         returns([nic])
 
       described_class.interfaces.should == [name]
     end
+
+    it "should not return an interface with an empty NetConnectionId" do
+      Facter::Util::WMI.expects(:execquery).with(Facter::Util::IP::Windows::WMI_IP_INFO_QUERY).
+        returns([nic_config])
+      Facter::Util::WMI.expects(:execquery).with(wmi_query).
+        returns([nic_empty_NetConnectionId])
+
+      described_class.interfaces.should == []
+    end
+
+    it "should not return an interface with a nil NetConnectionId" do
+      Facter::Util::WMI.expects(:execquery).with(Facter::Util::IP::Windows::WMI_IP_INFO_QUERY).
+        returns([nic_config])
+      Facter::Util::WMI.expects(:execquery).with(wmi_query).
+        returns([nic_nil_NetConnectionId])
+
+      described_class.interfaces.should == []
+    end
+
+    context "when the adapter configuration is enabled but the underlying adapter is not enabled" do
+      it "should not return an interface" do
+        Facter::Util::WMI.expects(:execquery).with(Facter::Util::IP::Windows::WMI_IP_INFO_QUERY).
+          returns([nic_config])
+        Facter::Util::WMI.expects(:execquery).with(wmi_query).
+          returns([])
+
+        described_class.interfaces.should == []
+      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