diff options
author | Paul Nasrat <pnasrat@googlemail.com> | 2009-08-11 17:45:40 +0100 |
---|---|---|
committer | Paul Nasrat <pnasrat@googlemail.com> | 2009-08-12 08:30:41 +0100 |
commit | fe41fb80dda8c96814b7a57875331b731dd04395 (patch) | |
tree | f48f21abd8bda6105bad36a187b721f617e55236 | |
parent | be9e484c0daaf4befb0dfbcf85bda08ce6c1effd (diff) | |
download | facter-fe41fb80dda8c96814b7a57875331b731dd04395.tar.gz facter-fe41fb80dda8c96814b7a57875331b731dd04395.tar.xz facter-fe41fb80dda8c96814b7a57875331b731dd04395.zip |
Fix #2470 - duplicate entries in interfaces fact
Solaris orders inet and inet6 seperately. This tests for and fixes this by
uniqueing the list. Will probably need work when we get to ipv6 support.
-rw-r--r-- | lib/facter/util/ip.rb | 2 | ||||
-rw-r--r-- | spec/unit/data/solaris_ifconfig_all_with_multiple_interfaces | 8 | ||||
-rw-r--r-- | spec/unit/util/ip.rb | 7 |
3 files changed, 16 insertions, 1 deletions
diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb index fb32d70..9fb7034 100644 --- a/lib/facter/util/ip.rb +++ b/lib/facter/util/ip.rb @@ -51,7 +51,7 @@ module Facter::Util::IP # at the end of interfaces. So, we have to trim those trailing # characters. I tried making the regex better but supporting all # platforms with a single regex is probably a bit too much. - output.scan(/^\w+[.:]?\d+[.:]?\d*[.:]?\w*/).collect { |i| i.sub(/:$/, '') } + output.scan(/^\w+[.:]?\d+[.:]?\d*[.:]?\w*/).collect { |i| i.sub(/:$/, '') }.uniq end def self.get_all_interface_output diff --git a/spec/unit/data/solaris_ifconfig_all_with_multiple_interfaces b/spec/unit/data/solaris_ifconfig_all_with_multiple_interfaces new file mode 100644 index 0000000..f04ad5d --- /dev/null +++ b/spec/unit/data/solaris_ifconfig_all_with_multiple_interfaces @@ -0,0 +1,8 @@ +lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 + inet 127.0.0.1 netmask ff000000 +e1000g0: flags=201004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4,CoS> mtu 1500 index 2 + inet 192.168.162.130 netmask ffffff00 broadcast 192.168.162.255 +lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1 + inet6 ::1/128 +e1000g0: flags=202004841<UP,RUNNING,MULTICAST,DHCP,IPv6,CoS> mtu 1500 index 2 + inet6 fe80::20c:29ff:fe09:627e/10 diff --git a/spec/unit/util/ip.rb b/spec/unit/util/ip.rb index 512c07b..60ec09e 100644 --- a/spec/unit/util/ip.rb +++ b/spec/unit/util/ip.rb @@ -34,6 +34,13 @@ describe Facter::Util::IP do Facter::Util::IP.get_interfaces().should == ["lo0", "en0"] end + it "should return a list two interfaces on Solaris with two interfaces multiply reporting" do + sample_output_file = File.dirname(__FILE__) + '/../data/solaris_ifconfig_all_with_multiple_interfaces' + solaris_ifconfig = File.new(sample_output_file).read() + Facter::Util::IP.stubs(:get_all_interface_output).returns(solaris_ifconfig) + Facter::Util::IP.get_interfaces().should == ["lo0", "e1000g0"] + end + it "should return a value for a specific interface" do Facter::Util::IP.should respond_to(:get_interface_value) end |