Skip to content

Commit

Permalink
Merge branch 'tickets/next/6716-osx-ipv6-macaddress' into next
Browse files Browse the repository at this point in the history
* tickets/next/6716-osx-ipv6-macaddress:
  Clean up indentation, and alignment in macaddress_spec.rb
  (#6716) fix facter issues on OSX with ipv6 in macaddress.rb.
  • Loading branch information
jhelwig committed Mar 17, 2011
2 parents 8bb503e + 2fb8316 commit 330d399
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lib/facter/util/macaddress.rb
Expand Up @@ -12,7 +12,7 @@ def self.macaddress
end

def self.default_interface
`#{netstat_command} | /usr/bin/awk '/^default/{print $6}'`.chomp
`#{netstat_command} | /usr/bin/awk '/^default/{print $6;exit}'`.chomp
end

private
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/ifconfig/darwin_10_6_6_dualstack
@@ -0,0 +1,8 @@
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 00:25:4b:ca:56:72
media: autoselect
status: inactive
7 changes: 7 additions & 0 deletions spec/fixtures/ifconfig/darwin_10_6_6_dualstack_en1
@@ -0,0 +1,7 @@
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 00:25:00:48:19:ef
inet6 fe80::225:ff:fe48:19ef%en1 prefixlen 64 scopeid 0x5
inet 192.168.1.207 netmask 0xffffff00 broadcast 192.168.1.255
inet6 2000:44b4:32:400::1 prefixlen 64
media: autoselect
status: active
34 changes: 34 additions & 0 deletions spec/fixtures/netstat/darwin_10_6_6_dualstack
@@ -0,0 +1,34 @@
Routing tables

Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.1.254 UGSc 38 0 en1
127 127.0.0.1 UCS 0 0 lo0
127.0.0.1 127.0.0.1 UH 14 1044474 lo0
169.254 link#5 UCS 0 0 en1
192.168.1 link#5 UCS 2 0 en1
192.168.1.207 127.0.0.1 UHS 0 1 lo0
192.168.1.220 e0:f8:47:98:85:71 UHLWI 0 0 en1 135
192.168.1.254 0:4:ed:66:13:cc UHLWI 42 134 en1 1158

Internet6:
Destination Gateway Flags Netif Expire
default 2000:44b4:61::16e UGSc tun0
::1 ::1 UH lo0
2000:44b4:61::16e 2000:44b4:61::16f UH tun0
2000:44b4:61::16f link#9 UHL lo0
2000:44b4:62:480::/64 link#5 UC en1
2000:44b4:62:480::/60 ::1 UGSc lo0
2000:44b4:62:480::1 0:25:0:48:19:ef UHL lo0
fe80::%lo0/64 fe80::1%lo0 Uc lo0
fe80::1%lo0 link#1 UHL lo0
fe80::%en1/64 link#5 UC en1
fe80::225:ff:fe48:19ef%en1 0:25:0:48:19:ef UHL lo0
fe80::a00:27ff:fe02:bcb5%en1 8:0:27:2:bc:b5 UHLW en1
fe80::a932:c76f:9c2e:ead8%en1 0:1e:2a:b3:9b:66 UHLW en1
fe80::e2f8:47ff:fe98:8571%en1 e0:f8:47:98:85:71 UHLW en1
fe80::225:4bff:feca:5672%tun0 link#9 UHL lo0
ff01::/32 ::1 Um lo0
ff02::/32 ::1 UmC lo0
ff02::/32 link#5 UmC en1
ff02::/32 fe80::225:4bff:feca:5672%tun0 UmC tun0
109 changes: 51 additions & 58 deletions spec/unit/util/macaddress_spec.rb
Expand Up @@ -5,71 +5,64 @@
require 'facter/util/macaddress'

describe "Darwin" do
test_cases = [
# version, iface, real macaddress, fallback macaddress
["9.8.0", 'en0', "00:17:f2:06:e4:2e", "00:17:f2:06:e4:2e"],
["10.3.0", 'en0', "00:17:f2:06:e3:c2", "00:17:f2:06:e3:c2"],
["10.6.4", 'en1', "58:b0:35:7f:25:b3", "58:b0:35:fa:08:b1"]
]

test_cases.each do |version, default_iface, macaddress, fallback_macaddress|
netstat_file = File.join(SPECDIR, "fixtures", "netstat", "darwin_#{version.tr('.', '_')}")
ifconfig_file_no_iface = File.join(SPECDIR, "fixtures", "ifconfig", "darwin_#{version.tr('.', '_')}")
ifconfig_file = "#{ifconfig_file_no_iface}_#{default_iface}"

describe "version #{version}" do

describe Facter::Util::Macaddress::Darwin do

describe ".default_interface" do
describe "when netstat has a default interface" do

before do
Facter::Util::Macaddress::Darwin.stubs(:netstat_command).returns("cat \"#{netstat_file}\"")
end

it "should return the default interface name" do
Facter::Util::Macaddress::Darwin.default_interface.should == default_iface
end
end

end

describe ".macaddress" do
describe "when netstat has a default interface" do
before do
Facter.stubs(:warn)
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('')
Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file}\"")
end

it "should return the macaddress of the default interface" do
Facter::Util::Macaddress::Darwin.macaddress.should == macaddress
end

end
test_cases = [
# version, iface, real macaddress, fallback macaddress
["9.8.0", 'en0', "00:17:f2:06:e4:2e", "00:17:f2:06:e4:2e"],
["10.3.0", 'en0', "00:17:f2:06:e3:c2", "00:17:f2:06:e3:c2"],
["10.6.4", 'en1', "58:b0:35:7f:25:b3", "58:b0:35:fa:08:b1"],
["10.6.6_dualstack", "en1", "00:25:00:48:19:ef", "00:25:4b:ca:56:72"]
]

test_cases.each do |version, default_iface, macaddress, fallback_macaddress|
netstat_file = File.join(SPECDIR, "fixtures", "netstat", "darwin_#{version.tr('.', '_')}")
ifconfig_file_no_iface = File.join(SPECDIR, "fixtures", "ifconfig", "darwin_#{version.tr('.', '_')}")
ifconfig_file = "#{ifconfig_file_no_iface}_#{default_iface}"

describe "version #{version}" do
describe Facter::Util::Macaddress::Darwin do
describe ".default_interface" do
describe "when netstat has a default interface" do
before do
Facter::Util::Macaddress::Darwin.stubs(:netstat_command).returns("cat \"#{netstat_file}\"")
end

describe "when netstat does not have a default interface" do
before do
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns("")
Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file_no_iface}\"")
end
it "should return the default interface name" do
Facter::Util::Macaddress::Darwin.default_interface.should == default_iface
end
end
end

it "should warn about the lack of default" do
Facter.expects(:warn).with("Could not find a default route. Using first non-loopback interface")
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('')
Facter::Util::Macaddress::Darwin.macaddress
end
describe ".macaddress" do
describe "when netstat has a default interface" do
before do
Facter.stubs(:warn)
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('')
Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file}\"")
end

it "should return the macaddress of the first non-loopback interface" do
Facter::Util::Macaddress::Darwin.macaddress.should == fallback_macaddress
end
it "should return the macaddress of the default interface" do
Facter::Util::Macaddress::Darwin.macaddress.should == macaddress
end
end

end
end
describe "when netstat does not have a default interface" do
before do
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns("")
Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file_no_iface}\"")
end

it "should warn about the lack of default" do
Facter.expects(:warn).with("Could not find a default route. Using first non-loopback interface")
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('')
Facter::Util::Macaddress::Darwin.macaddress
end

it "should return the macaddress of the first non-loopback interface" do
Facter::Util::Macaddress::Darwin.macaddress.should == fallback_macaddress
end
end
end
end
end
end
end

0 comments on commit 330d399

Please sign in to comment.