[Pkg-puppet-devel] [facter] 40/61: (#16668) Only consider NICs that have a binding entry
Stig Sandbeck Mathisen
ssm at debian.org
Mon Nov 4 15:02:01 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 47bfb4a06a33263344d203232da1daabe2b10e95
Author: Rob Reynolds <ferventcoder at gmail.com>
Date: Sat Jul 27 06:34:53 2013 -0500
(#16668) Only consider NICs that have a binding entry
This ensures that only nics that are in the bindings for ipv4/ipv6 are checked
against the registry bindings.
---
lib/facter/util/ip/windows.rb | 4 +-
spec/unit/ipaddress6_spec.rb | 102 ++++++++++++-------------------------
spec/unit/ipaddress_spec.rb | 69 +++++++++----------------
spec/unit/netmask_spec.rb | 53 +++++++------------
spec/unit/util/macaddress_spec.rb | 52 +++++++------------
5 files changed, 97 insertions(+), 183 deletions(-)
diff --git a/lib/facter/util/ip/windows.rb b/lib/facter/util/ip/windows.rb
index 0881ecb..42b4db7 100644
--- a/lib/facter/util/ip/windows.rb
+++ b/lib/facter/util/ip/windows.rb
@@ -136,7 +136,9 @@ class Facter::Util::IP::Windows
#
# @api private
def self.get_preferred_network_adapters(bindings)
- network_adapter_configurations.sort do |nic_left,nic_right|
+ network_adapter_configurations.select do |nic|
+ bindings.bindings.include?(nic.SettingID)
+ end.sort do |nic_left,nic_right|
cmp = nic_left.IPConnectionMetric <=> nic_right.IPConnectionMetric
if cmp == 0
bindings.bindings[nic_left.SettingID] <=> bindings.bindings[nic_right.SettingID]
diff --git a/spec/unit/ipaddress6_spec.rb b/spec/unit/ipaddress6_spec.rb
index 2735f3d..9173f90 100755
--- a/spec/unit/ipaddress6_spec.rb
+++ b/spec/unit/ipaddress6_spec.rb
@@ -54,10 +54,9 @@ describe "The IPv6 address fact" do
require 'facter/util/wmi'
require 'facter/util/registry'
require 'facter/util/ip/windows'
+ require 'facter_spec/windows_network'
- let(:settingId0) { '{4AE6B55C-6DD6-427D-A5BB-13535D4BE926}' }
- let(:settingId1) { '{38762816-7957-42AC-8DAA-3B08D0C857C7}' }
- let(:nic_bindings) { ["\\Device\\#{settingId0}", "\\Device\\#{settingId1}" ] }
+ include FacterSpec::WindowsNetwork
before :each do
Facter.fact(:kernel).stubs(:value).returns(:windows)
@@ -77,29 +76,31 @@ describe "The IPv6 address fact" do
context "when you have one network adapter" do
it "should return empty if ipv6 is not on" do
- network1 = mock('network1', :IPAddress => ["12.123.12.12"])
- Facter::Util::WMI.expects(:execquery).returns([network1])
+ nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
+ nic.expects(:IPAddress).returns([ipAddress1])
+ Facter::Util::WMI.expects(:execquery).returns([nic])
Facter.value(:ipaddress6).should == nil
end
it "should return the ipv6 address properly" do
- network1 = mock('network1', :IPAddress => ["12.123.12.12", "2011:0:4137:9e76:2087:77a:53ef:7527"])
- Facter::Util::WMI.expects(:execquery).returns([network1])
+ Facter::Util::WMI.expects(:execquery).returns([given_a_valid_windows_nic_with_ipv4_and_ipv6])
- Facter.value(:ipaddress6).should == "2011:0:4137:9e76:2087:77a:53ef:7527"
+ Facter.value(:ipaddress6).should == ipv6Address0
end
it "should return the first ipv6 address if there is more than one (multi-homing)" do
- network1 = mock('network1', :IPAddress => ["12.123.12.12", "2013:0:4137:9e76:2087:77a:53ef:7527", "2011:0:4137:9e76:2087:77a:53ef:7527"])
- Facter::Util::WMI.expects(:execquery).returns([network1])
+ nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
+ nic.expects(:IPAddress).returns([ipAddress0, ipv6Address0,ipv6Address1])
+ Facter::Util::WMI.expects(:execquery).returns([nic])
- Facter.value(:ipaddress6).should == "2013:0:4137:9e76:2087:77a:53ef:7527"
+ Facter.value(:ipaddress6).should == ipv6Address0
end
it "should return return nil if the ipv6 address is link local" do
- network1 = mock('network1', :IPAddress => ["12.123.12.12", "fe80::2db2:5b42:4e30:b508"])
- Facter::Util::WMI.expects(:execquery).returns([network1])
+ nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
+ nic.expects(:IPAddress).returns([ipAddress0, ipv6LinkLocal])
+ Facter::Util::WMI.expects(:execquery).returns([nic])
Facter.value(:ipaddress6).should == nil
end
@@ -107,84 +108,45 @@ describe "The IPv6 address fact" do
context "when you have more than one network adapter" do
it "should return empty if ipv6 is not on" do
- network1 = mock('network1')
- network1.expects(:SettingID).returns(settingId0)
- network1.expects(:IPConnectionMetric).returns(10)
- network1.expects(:IPAddress).returns(["12.123.12.12"])
- network2 = mock('network2')
- network2.expects(:SettingID).returns(settingId1)
- network2.expects(:IPConnectionMetric).returns(10)
- network2.expects(:IPAddress).returns(["12.123.12.13"])
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ nics[:nic0].expects(:IPAddress).returns([ipAddress0])
+ nics[:nic1].expects(:IPAddress).returns([ipAddress1])
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
Facter.value(:ipaddress6).should == nil
end
it "should return the ipv6 of the adapter with the lowest IP connection metric (best connection)" do
- network1 = mock('network1')
- network1.expects(:IPConnectionMetric).returns(10)
- network2 = mock('network2')
- network2.expects(:IPConnectionMetric).returns(5)
- network2.expects(:IPAddress).returns(["12.123.12.13", "2013:0:4137:9e76:2087:77a:53ef:7527"])
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:ipaddress6).should == "2013:0:4137:9e76:2087:77a:53ef:7527"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ nics[:nic1].expects(:IPConnectionMetric).returns(5)
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+
+ Facter.value(:ipaddress6).should == ipv6Address1
end
it "should return the ipv6 of the adapter with the lowest IP connection metric (best connection) that has ipv6 enabled" do
- network1 = mock('network1')
- network1.expects(:IPConnectionMetric).returns(10)
- network1.expects(:IPAddress).returns(["12.123.12.12", "2011:0:4137:9e76:2087:77a:53ef:7527"])
- network2 = mock('network2')
- network2.expects(:IPConnectionMetric).returns(5)
- network2.expects(:IPAddress).returns(["12.123.12.13"])
-
- Facter::Util::WMI.expects(:execquery).returns([network2, network1])
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ nics[:nic1].expects(:IPConnectionMetric).returns(5)
+ nics[:nic1].expects(:IPAddress).returns([ipAddress1])
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
- Facter.value(:ipaddress6).should == "2011:0:4137:9e76:2087:77a:53ef:7527"
+ Facter.value(:ipaddress6).should == ipv6Address0
end
context "when the IP connection metric is the same" do
it "should return the ipv6 of the adapter with the lowest binding order" do
- network1 = mock('network1')
- network1.expects(:SettingID).returns(settingId0)
- network1.expects(:IPConnectionMetric).returns(5)
- network1.expects(:IPAddress).returns(["12.123.12.12", "2011:0:4137:9e76:2087:77a:53ef:7527"])
- network2 = mock('network2')
- network2.expects(:SettingID).returns(settingId1)
- network2.expects(:IPConnectionMetric).returns(5)
- #network2.expects(:IPAddress).returns(["12.123.12.13", "2013:0:4137:9e76:2087:77a:53ef:7527"])
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:ipaddress6).should == "2011:0:4137:9e76:2087:77a:53ef:7527"
- end
-
- it "should return the ipv6 of the adapter with the lowest binding order even if the adapter is not first" do
-<<<<<<< HEAD
- network1 = mock('network1')
- network1.expects(:SettingID).returns(settingId1)
- network1.expects(:IPConnectionMetric).returns(5)
- network2 = mock('network2')
- network2.expects(:SettingID).returns(settingId0)
- network2.expects(:IPConnectionMetric).returns(5)
- network2.expects(:IPAddress).returns(["12.123.12.13", "2013:0:4137:9e76:2087:77a:53ef:7527"])
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:ipaddress6).should == "2013:0:4137:9e76:2087:77a:53ef:7527"
-||||||| parent of 6541f09... maint: remove whitespace from netmask.rb, windows_network.rb, and ipaddress6_spec.rb
nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
- Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ])
-
Facter::Util::WMI.expects(:execquery).returns(nics.values)
- Facter.value(:ipaddress6).should == ipv6Address1
-=======
+ Facter.value(:ipaddress6).should == ipv6Address0
+ end
+
+ it "should return the ipv6 of the adapter with the lowest binding order even if the adapter is not first" do
nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ])
Facter::Util::WMI.expects(:execquery).returns(nics.values)
Facter.value(:ipaddress6).should == ipv6Address1
->>>>>>> 6541f09... maint: remove whitespace from netmask.rb, windows_network.rb, and ipaddress6_spec.rb
end
end
end
diff --git a/spec/unit/ipaddress_spec.rb b/spec/unit/ipaddress_spec.rb
index 62cbbc2..674b743 100755
--- a/spec/unit/ipaddress_spec.rb
+++ b/spec/unit/ipaddress_spec.rb
@@ -45,10 +45,9 @@ describe "ipaddress fact" do
require 'facter/util/wmi'
require 'facter/util/registry'
require 'facter/util/ip/windows'
+ require 'facter_spec/windows_network'
- let(:settingId0) { '{4AE6B55C-6DD6-427D-A5BB-13535D4BE926}' }
- let(:settingId1) { '{38762816-7957-42AC-8DAA-3B08D0C857C7}' }
- let(:nic_bindings) { ["\\Device\\#{settingId0}", "\\Device\\#{settingId1}" ] }
+ include FacterSpec::WindowsNetwork
before :each do
Facter.fact(:kernel).stubs(:value).returns(:windows)
@@ -69,63 +68,45 @@ describe "ipaddress fact" do
context "when you have one network adapter" do
it "should return the ip address properly" do
- network1 = mock('network1')
- network1.expects(:IPAddress).returns(["12.123.12.12", "2011:0:4137:9e76:2087:77a:53ef:7527"])
- Facter::Util::WMI.expects(:execquery).returns([network1])
+ nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns([nic])
- Facter.value(:ipaddress).should == "12.123.12.12"
+ Facter.value(:ipaddress).should == ipAddress0
end
end
context "when you have more than one network adapter" do
it "should return the ip of the adapter with the lowest IP connection metric (best connection)" do
- network1 = mock('network1')
- network1.expects(:IPConnectionMetric).returns(10)
- network2 = mock('network2')
- network2.expects(:IPConnectionMetric).returns(5)
- network2.expects(:IPAddress).returns(["12.123.12.13", "2013:0:4137:9e76:2087:77a:53ef:7527"])
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:ipaddress).should == "12.123.12.13"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ nics[:nic1].expects(:IPConnectionMetric).returns(5)
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+
+ Facter.value(:ipaddress).should == ipAddress1
end
it "should return the ip of the adapter with the lowest IP connection metric (best connection) that has ipv4 enabled" do
- network1 = mock('network1')
- network1.expects(:IPConnectionMetric).returns(10)
- network1.expects(:IPAddress).returns(["12.123.12.12", "2011:0:4137:9e76:2087:77a:53ef:7527"])
- network2 = mock('network2')
- network2.expects(:IPConnectionMetric).returns(5)
- network2.expects(:IPAddress).returns(["2013:0:4137:9e76:2087:77a:53ef:7527"])
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:ipaddress).should == "12.123.12.12"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ nics[:nic1].expects(:IPConnectionMetric).returns(5)
+ nics[:nic1].expects(:IPAddress).returns([ipv6Address1])
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+
+ Facter.value(:ipaddress).should == ipAddress0
end
context "when the IP connection metric is the same" do
it "should return the ip of the adapter with the lowest binding order" do
- network1 = mock('network1')
- network1.expects(:SettingID).returns(settingId0)
- network1.expects(:IPConnectionMetric).returns(5)
- network1.expects(:IPAddress).returns(["12.123.12.12", "2011:0:4137:9e76:2087:77a:53ef:7527"])
- network2 = mock('network2')
- network2.expects(:SettingID).returns(settingId1)
- network2.expects(:IPConnectionMetric).returns(5)
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:ipaddress).should == "12.123.12.12"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+
+ Facter.value(:ipaddress).should == ipAddress0
end
it "should return the ip of the adapter with the lowest binding order even if the adapter is not first" do
- network1 = mock('network1')
- network1.expects(:IPConnectionMetric).returns(5)
- network1.expects(:SettingID).returns(settingId1)
- network2 = mock('network2')
- network2.expects(:IPConnectionMetric).returns(5)
- network2.expects(:IPAddress).returns(["12.123.12.13", "2013:0:4137:9e76:2087:77a:53ef:7527"])
- network2.expects(:SettingID).returns(settingId0)
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:ipaddress).should == "12.123.12.13"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+ Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ])
+
+ Facter.value(:ipaddress).should == ipAddress1
end
end
end
diff --git a/spec/unit/netmask_spec.rb b/spec/unit/netmask_spec.rb
old mode 100644
new mode 100755
index 25896b3..8e81cc8
--- a/spec/unit/netmask_spec.rb
+++ b/spec/unit/netmask_spec.rb
@@ -30,10 +30,9 @@ describe "The netmask fact" do
context "on Windows" do
require 'facter/util/wmi'
require 'facter/util/registry'
+ require 'facter_spec/windows_network'
- let(:settingId0) { '{4AE6B55C-6DD6-427D-A5BB-13535D4BE926}' }
- let(:settingId1) { '{38762816-7957-42AC-8DAA-3B08D0C857C7}' }
- let(:nic_bindings) { ["\\Device\\#{settingId0}", "\\Device\\#{settingId1}" ] }
+ include FacterSpec::WindowsNetwork
before :each do
Facter.fact(:kernel).stubs(:value).returns(:windows)
@@ -50,52 +49,36 @@ describe "The netmask fact" do
describe "when you have one network adapter" do
it "should return properly" do
- network1 = mock('network1')
- network1.expects(:IPSubnet).returns(["255.255.255.0", "48","2"])
- Facter::Util::WMI.expects(:execquery).returns([network1])
+ nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns([nic])
- Facter.value(:netmask).should == "255.255.255.0"
+ Facter.value(:netmask).should == subnet0
end
end
describe "when you have more than one network adapter" do
it "should return the netmask of the adapter with the lowest IP connection metric (best connection)" do
- network1 = mock('network1')
- network1.expects(:IPConnectionMetric).returns(10)
- network2 = mock('network2')
- network2.expects(:IPConnectionMetric).returns(5)
- network2.expects(:IPSubnet).returns(["255.255.0.0", "48","2"])
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:netmask).should == "255.255.0.0"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ nics[:nic1].expects(:IPConnectionMetric).returns(5)
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+
+ Facter.value(:netmask).should == subnet1
end
context "when the IP connection metric is the same" do
it "should return the netmask of the adapter with the lowest binding order" do
- network1 = mock('network1')
- network1.expects(:SettingID).returns(settingId0)
- network1.expects(:IPConnectionMetric).returns(5)
- network1.expects(:IPSubnet).returns(["255.255.255.0", "48","64"])
- network2 = mock('network2')
- network2.expects(:SettingID).returns(settingId1)
- network2.expects(:IPConnectionMetric).returns(5)
-
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
- Facter.value(:netmask).should =="255.255.255.0"
+ Facter.value(:netmask).should == subnet0
end
it "should return the netmask of the adapter with the lowest binding even if the adapter is not first" do
- network1 = mock('network1')
- network1.expects(:SettingID).returns(settingId1)
- network1.expects(:IPConnectionMetric).returns(5)
- network2 = mock('network2')
- network2.expects(:SettingID).returns(settingId0)
- network2.expects(:IPConnectionMetric).returns(5)
- network2.expects(:IPSubnet).returns(["255.255.0.0", "48","2"])
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:netmask).should =="255.255.0.0"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+ Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ])
+
+ Facter.value(:netmask).should == subnet1
end
end
end
diff --git a/spec/unit/util/macaddress_spec.rb b/spec/unit/util/macaddress_spec.rb
index 863ed11..17e5500 100755
--- a/spec/unit/util/macaddress_spec.rb
+++ b/spec/unit/util/macaddress_spec.rb
@@ -85,10 +85,9 @@ describe "The macaddress fact" do
context "on Windows" do
require 'facter/util/wmi'
require 'facter/util/registry'
+ require 'facter_spec/windows_network'
- let(:settingId0) { '{4AE6B55C-6DD6-427D-A5BB-13535D4BE926}' }
- let(:settingId1) { '{38762816-7957-42AC-8DAA-3B08D0C857C7}' }
- let(:nic_bindings) { ["\\Device\\#{settingId0}", "\\Device\\#{settingId1}" ] }
+ include FacterSpec::WindowsNetwork
before :each do
Facter.fact(:kernel).stubs(:value).returns(:windows)
@@ -105,49 +104,36 @@ describe "The macaddress fact" do
describe "when you have one network adapter" do
it "should return properly" do
- network1 = mock('network1')
- network1.expects(:MACAddress).returns("00:0C:29:0C:9E:9F")
- Facter::Util::WMI.expects(:execquery).returns([network1])
+ nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns([nic])
- Facter.value(:macaddress).should == "00:0C:29:0C:9E:9F"
+ Facter.value(:macaddress).should == macAddress0
end
end
describe "when you have more than one network adapter" do
it "should return the macaddress of the adapter with the lowest IP connection metric (best connection)" do
- network1 = mock('network1')
- network1.expects(:IPConnectionMetric).returns(10)
- network2 = mock('network2')
- network2.expects(:MACAddress).returns("00:0C:29:0C:9E:AF")
- network2.expects(:IPConnectionMetric).returns(5)
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:macaddress).should == "00:0C:29:0C:9E:AF"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ nics[:nic1].expects(:IPConnectionMetric).returns(5)
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+
+ Facter.value(:macaddress).should == macAddress1
end
context "when the IP connection metric is the same" do
it "should return the macaddress of the adapter with the lowest binding order" do
- network1 = mock('network1', :MACAddress => "23:24:df:12:12:00")
- network1.expects(:SettingID).returns(settingId0)
- network1.expects(:IPConnectionMetric).returns(5)
- network2 = mock('network2')
- network2.expects(:SettingID).returns(settingId1)
- network2.expects(:IPConnectionMetric).returns(5)
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:macaddress).should == "23:24:df:12:12:00"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+
+ Facter.value(:macaddress).should == macAddress0
end
it "should return the macaddress of the adapter with the lowest MACAddress when multiple adapters have the same IP connection metric when the lowest MACAddress is not first" do
- network1 = stub('network1', :MACAddress => "23:24:df:12:12:00")
- network1.expects(:SettingID).returns(settingId1)
- network1.expects(:IPConnectionMetric).returns(5)
- network2 = stub('network2', :MACAddress => "23:24:df:12:12:11")
- network2.expects(:SettingID).returns(settingId0)
- network2.expects(:IPConnectionMetric).returns(5)
- Facter::Util::WMI.expects(:execquery).returns([network1, network2])
-
- Facter.value(:macaddress).should == "23:24:df:12:12:11"
+ nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
+ Facter::Util::WMI.expects(:execquery).returns(nics.values)
+ Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ])
+
+ Facter.value(:macaddress).should == macAddress1
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