diff options
author | James Turnbull <james@lovedthanlost.net> | 2009-01-27 10:23:26 +1100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-01-27 10:23:26 +1100 |
commit | da52e30971ebb6935c64777e4a91cb2cbb066db9 (patch) | |
tree | 4fdc856618534fa2e83c329907e91a70f940cea2 | |
parent | c2de35f1329dbaf6c843ff0a4967955ce989f2f0 (diff) | |
download | facter-da52e30971ebb6935c64777e4a91cb2cbb066db9.tar.gz facter-da52e30971ebb6935c64777e4a91cb2cbb066db9.tar.xz facter-da52e30971ebb6935c64777e4a91cb2cbb066db9.zip |
Fixed #1870 - Format all subnet masks as human-readable
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | lib/facter/util/ip.rb | 9 | ||||
-rw-r--r-- | spec/unit/util/ip.rb | 17 |
3 files changed, 26 insertions, 2 deletions
@@ -1,4 +1,6 @@ 1.5.3: + Fixed #1870 - Format all subnet masks as human-readable + Added uptime facts Fixed autotest on win32 diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb index 35dadb6..a7f0a85 100644 --- a/lib/facter/util/ip.rb +++ b/lib/facter/util/ip.rb @@ -13,7 +13,7 @@ module Facter::Util::IP :aliases => [:openbsd, :netbsd, :freebsd, :darwin], :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, :macaddress => /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/, - :netmask => /netmask\s+(\w{10})/ + :netmask => /netmask\s+0x(\w{8})/ }, :sunos => { :addr => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, @@ -27,6 +27,11 @@ module Facter::Util::IP interface.gsub(/[:.]/, '_') end + def self.convert_from_hex?(kernel) + kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin] + kernels_to_convert.include?(kernel) + end + def self.supported_platforms REGEX_MAP.inject([]) do |result, tmp| key, map = tmp @@ -122,7 +127,7 @@ module Facter::Util::IP output_int.each do |s| if s =~ regex value = $1 - if label == 'netmask' && Facter.value(:kernel) == "SunOS" + if label == 'netmask' && convert_from_hex?(kernel) value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.') end tmp1.push(value) diff --git a/spec/unit/util/ip.rb b/spec/unit/util/ip.rb index af7e109..4f6e2c0 100644 --- a/spec/unit/util/ip.rb +++ b/spec/unit/util/ip.rb @@ -76,4 +76,21 @@ describe Facter::Util::IP do Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0" end + + it "should return a human readable netmask on Darwin" do + sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface" + + darwin_ifconfig_interface = File.new(sample_output_file).read() + + Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(darwin_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("Darwin") + + Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0" + end + + [:freebsd, :netbsd, :openbsd, :sunos, :darwin].each do |platform| + it "should require conversion from hex on #{platform}" do + Facter::Util::IP.convert_from_hex?(platform).should == true + end + end end |