diff options
author | Marc Fournier <marc.fournier@camptocamp.com> | 2010-09-10 19:02:44 +0200 |
---|---|---|
committer | Daniel Pittman <daniel@rimspace.net> | 2011-01-31 12:55:25 -0800 |
commit | 0d7a2e683125028758ae91d3754c0466fd068cf3 (patch) | |
tree | 476f9a0af5446613d1ebb7519bcb2ba3ecc77d6d | |
parent | ecd7cda64bdf3c8cd97b7c05f9cf7eb890d3682b (diff) | |
download | facter-0d7a2e683125028758ae91d3754c0466fd068cf3.tar.gz facter-0d7a2e683125028758ae91d3754c0466fd068cf3.tar.xz facter-0d7a2e683125028758ae91d3754c0466fd068cf3.zip |
Fix #4755: add support for GNU/kFreeBSD platform where missing.
Merged manually to the current state of the art. Minimal conflicts resolved
by adding both Darwin and GNU/KFreeBSD to the confine lines.
Author: Marc Fournier <marc.fournier@camptocamp.com>
Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
Signed-off-by: Rick Bradley <rick@rickbradley.com>
-rw-r--r-- | lib/facter/hardwareisa.rb | 2 | ||||
-rw-r--r-- | lib/facter/id.rb | 2 | ||||
-rw-r--r-- | lib/facter/lsb.rb | 2 | ||||
-rw-r--r-- | lib/facter/lsbmajdistrelease.rb | 2 | ||||
-rw-r--r-- | lib/facter/macaddress.rb | 2 | ||||
-rw-r--r-- | lib/facter/memory.rb | 2 | ||||
-rw-r--r-- | lib/facter/netmask.rb | 2 | ||||
-rw-r--r-- | lib/facter/processor.rb | 6 | ||||
-rw-r--r-- | lib/facter/uniqueid.rb | 2 | ||||
-rw-r--r-- | lib/facter/util/ip.rb | 10 | ||||
-rw-r--r-- | lib/facter/util/manufacturer.rb | 4 | ||||
-rw-r--r-- | lib/facter/util/netmask.rb | 2 | ||||
-rw-r--r-- | lib/facter/util/virtual.rb | 6 | ||||
-rw-r--r-- | lib/facter/virtual.rb | 6 | ||||
-rw-r--r-- | spec/unit/data/debian_kfreebsd_ifconfig | 40 | ||||
-rwxr-xr-x | spec/unit/util/ip_spec.rb | 30 | ||||
-rw-r--r-- | spec/unit/util/virtual_spec.rb | 6 |
17 files changed, 100 insertions, 26 deletions
diff --git a/lib/facter/hardwareisa.rb b/lib/facter/hardwareisa.rb index 45a16bc..23f7d08 100644 --- a/lib/facter/hardwareisa.rb +++ b/lib/facter/hardwareisa.rb @@ -1,4 +1,4 @@ Facter.add(:hardwareisa) do setcode 'uname -p', '/bin/sh' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS} + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS GNU/kFreeBSD} end diff --git a/lib/facter/id.rb b/lib/facter/id.rb index 0a4067d..c2ab3b7 100644 --- a/lib/facter/id.rb +++ b/lib/facter/id.rb @@ -1,5 +1,5 @@ Facter.add(:id) do - confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS} + confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS GNU/kFreeBSD} setcode "whoami" end diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index f54d75f..4b98466 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb @@ -20,7 +20,7 @@ "LSBDistCodeName" => %r{^Codename:\t(.*)$} }.each do |fact, pattern| Facter.add(fact) do - confine :kernel => :linux + confine :kernel => [ :linux, :"gnu/kfreebsd" ] setcode do unless defined?(@@lsbdata) and defined?(@@lsbtime) and (Time.now.to_i - @@lsbtime.to_i < 5) type = nil diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb index e091593..997e7ef 100644 --- a/lib/facter/lsbmajdistrelease.rb +++ b/lib/facter/lsbmajdistrelease.rb @@ -3,7 +3,7 @@ require 'facter' Facter.add("lsbmajdistrelease") do - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS} + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS GNU/kFreeBSD} setcode do if /(\d*)\./i =~ Facter.value(:lsbdistrelease) result=$1 diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb index adc2c64..4a12384 100644 --- a/lib/facter/macaddress.rb +++ b/lib/facter/macaddress.rb @@ -1,7 +1,7 @@ require 'facter/util/macaddress' Facter.add(:macaddress) do - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS} + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS GNU/kFreeBSD} setcode do ether = [] output = %x{/sbin/ifconfig -a} diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb index f744c3f..86adc7f 100644 --- a/lib/facter/memory.rb +++ b/lib/facter/memory.rb @@ -13,7 +13,7 @@ require 'facter/util/memory' :SwapFree => "SwapFree" }.each do |fact, name| Facter.add(fact) do - confine :kernel => :linux + confine :kernel => [ :linux, :"gnu/kfreebsd" ] setcode do Facter::Memory.meminfo_number(name) end diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb index bad3648..d6d125e 100644 --- a/lib/facter/netmask.rb +++ b/lib/facter/netmask.rb @@ -9,7 +9,7 @@ require 'facter/util/netmask' Facter.add("netmask") do - confine :kernel => [ :sunos, :linux, :freebsd, :openbsd, :netbsd, :darwin ] + confine :kernel => [ :sunos, :linux, :freebsd, :openbsd, :netbsd, :darwin, :"gnu/kfreebsd" ] setcode do Facter::NetMask.get_netmask end diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb index 53998ff..ac75867 100644 --- a/lib/facter/processor.rb +++ b/lib/facter/processor.rb @@ -7,7 +7,7 @@ require 'thread' -if Facter.value(:kernel) == "Linux" +if ["Linux", "GNU/kFreeBSD"].include? Facter.value(:kernel) processor_num = -1 processor_list = [] Thread::exclusive do @@ -22,7 +22,7 @@ if Facter.value(:kernel) == "Linux" end Facter.add("ProcessorCount") do - confine :kernel => :linux + confine :kernel => [ :linux, :"gnu/kfreebsd" ] setcode do processor_list.length.to_s end @@ -30,7 +30,7 @@ if Facter.value(:kernel) == "Linux" processor_list.each_with_index do |desc, i| Facter.add("Processor#{i}") do - confine :kernel => :linux + confine :kernel => [ :linux, :"gnu/kfreebsd" ] setcode do desc end diff --git a/lib/facter/uniqueid.rb b/lib/facter/uniqueid.rb index 93f8a61..aaeaa12 100644 --- a/lib/facter/uniqueid.rb +++ b/lib/facter/uniqueid.rb @@ -1,4 +1,4 @@ Facter.add(:uniqueid) do setcode 'hostid', '/bin/sh' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS} + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS GNU/kFreeBSD} end diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb index 366303c..62d50a4 100644 --- a/lib/facter/util/ip.rb +++ b/lib/facter/util/ip.rb @@ -10,9 +10,9 @@ module Facter::Util::IP :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ }, :bsd => { - :aliases => [:openbsd, :netbsd, :freebsd, :darwin], + :aliases => [:openbsd, :netbsd, :freebsd, :darwin, :"gnu/kfreebsd"], :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)/, + :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, :netmask => /netmask\s+0x(\w{8})/ }, :sunos => { @@ -33,7 +33,7 @@ module Facter::Util::IP end def self.convert_from_hex?(kernel) - kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux"] + kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux", :"gnu/kfreebsd"] kernels_to_convert.include?(kernel) end @@ -61,7 +61,7 @@ module Facter::Util::IP def self.get_all_interface_output case Facter.value(:kernel) - when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin' + when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD' output = %x{/sbin/ifconfig -a} when 'SunOS' output = %x{/usr/sbin/ifconfig -a} @@ -74,7 +74,7 @@ module Facter::Util::IP def self.get_single_interface_output(interface) output = "" case Facter.value(:kernel) - when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin' + when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD' output = %x{/sbin/ifconfig #{interface}} when 'SunOS' output = %x{/usr/sbin/ifconfig #{interface}} diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb index 22359ea..8e9bde2 100644 --- a/lib/facter/util/manufacturer.rb +++ b/lib/facter/util/manufacturer.rb @@ -5,7 +5,7 @@ module Facter::Manufacturer def self.get_dmi_table() case Facter.value(:kernel) - when 'Linux' + when 'Linux', 'GNU/kFreeBSD' return nil unless FileTest.exists?("/usr/sbin/dmidecode") output=%x{/usr/sbin/dmidecode 2>/dev/null} @@ -38,7 +38,7 @@ module Facter::Manufacturer if line =~ /#{key}/ and line =~ /\n\s+#{value} (.+)\n/ result = $1.strip Facter.add(facterkey) do - confine :kernel => [ :linux, :freebsd, :netbsd, :sunos ] + confine :kernel => [ :linux, :freebsd, :netbsd, :sunos, :"gnu/kfreebsd" ] setcode do result end diff --git a/lib/facter/util/netmask.rb b/lib/facter/util/netmask.rb index 160cdbd..5dcc576 100644 --- a/lib/facter/util/netmask.rb +++ b/lib/facter/util/netmask.rb @@ -17,7 +17,7 @@ module Facter::NetMask :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s (\w{8})}x, :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } } - when 'FreeBSD','NetBSD','OpenBSD', 'Darwin' + when 'FreeBSD','NetBSD','OpenBSD', 'Darwin', 'GNU/kFreeBSD' ops = { :ifconfig => '/sbin/ifconfig -a', :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s 0x(\w{8})}x, diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index e94070d..129448e 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb @@ -59,7 +59,11 @@ module Facter::Util::Virtual end def self.jail? - Facter::Util::Resolution.exec("/sbin/sysctl -n security.jail.jailed") == "1" + path = case Facter.value(:kernel) + when "FreeBSD": "/sbin" + when "GNU/kFreeBSD": "/bin" + end + Facter::Util::Resolution.exec("#{path}/sysctl -n security.jail.jailed") == "1" end def self.hpvm? diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 8412a0a..47c9504 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -19,7 +19,7 @@ end Facter.add("virtual") do - confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX} + confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX GNU/kFreeBSD} result = "physical" @@ -60,7 +60,7 @@ Facter.add("virtual") do result = Facter::Util::Virtual.kvm_type() end - if Facter.value(:kernel)=="FreeBSD" + if ["FreeBSD", "GNU/kFreeBSD"].include? Facter.value(:kernel) result = "jail" if Facter::Util::Virtual.jail? end @@ -103,7 +103,7 @@ Facter.add("virtual") do end Facter.add("is_virtual") do - confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin} + confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD} setcode do if Facter.value(:virtual) != "physical" && Facter.value(:virtual) != "xen0" diff --git a/spec/unit/data/debian_kfreebsd_ifconfig b/spec/unit/data/debian_kfreebsd_ifconfig new file mode 100644 index 0000000..44a3b62 --- /dev/null +++ b/spec/unit/data/debian_kfreebsd_ifconfig @@ -0,0 +1,40 @@ +em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 + options=209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC> + ether 0:11:a:59:67:90 + inet6 fe80::211:aff:fe59:6790%em0 prefixlen 64 scopeid 0x1 + nd6 options=3<PERFORMNUD,ACCEPT_RTADV> + media: Ethernet autoselect (1000baseT <full-duplex>) + status: active +em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 + options=209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC> + ether 0:11:a:59:67:91 + inet6 fe80::211:aff:fe59:6791%em1 prefixlen 64 scopeid 0x2 + inet 192.168.10.10 netmask 0xffffff00 broadcast 192.168.10.255 + nd6 options=3<PERFORMNUD,ACCEPT_RTADV> + media: Ethernet autoselect (100baseTX <full-duplex>) + status: active +bge0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500 + options=8009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,LINKSTATE> + ether 0:14:c2:3f:ea:e4 + media: Ethernet autoselect (none) + status: no carrier +bge1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500 + options=8009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,LINKSTATE> + ether 0:14:c2:3f:ea:e3 + media: Ethernet autoselect (none) + status: no carrier +lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384 + options=3<RXCSUM,TXCSUM> + inet6 ::1 prefixlen 128 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5 + inet 127.0.0.1 netmask 0xff000000 + nd6 options=3<PERFORMNUD,ACCEPT_RTADV> +vlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 + options=3<RXCSUM,TXCSUM> + ether 0:11:a:59:67:90 + inet6 fe80::211:aff:fe59:6790%vlan0 prefixlen 64 scopeid 0x6 + inet 192.168.192.2 netmask 0xffffff00 broadcast 192.168.192.255 + nd6 options=3<PERFORMNUD,ACCEPT_RTADV> + media: Ethernet autoselect (1000baseT <full-duplex>) + status: active + vlan: 192 parent interface: em0 diff --git a/spec/unit/util/ip_spec.rb b/spec/unit/util/ip_spec.rb index d87b4b9..ceceb3f 100755 --- a/spec/unit/util/ip_spec.rb +++ b/spec/unit/util/ip_spec.rb @@ -5,7 +5,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'facter/util/ip' describe Facter::Util::IP do - [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do |platform| + [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux", :"gnu/kfreebsd"].each do |platform| it "should be supported on #{platform}" do Facter::Util::IP.supported_platforms.should be_include(platform) end @@ -48,6 +48,13 @@ describe Facter::Util::IP do Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"] end + it "should return a list of six interfaces on a GNU/kFreeBSD with six interfaces" do + sample_output_file = File.dirname(__FILE__) + '/../data/debian_kfreebsd_ifconfig' + kfreebsd_ifconfig = File.new(sample_output_file).read() + Facter::Util::IP.stubs(:get_all_interface_output).returns(kfreebsd_ifconfig) + Facter::Util::IP.get_interfaces().should == ["em0", "em1", "bge0", "bge1", "lo0", "vlan0"] + end + it "should return a value for a specific interface" do Facter::Util::IP.should respond_to(:get_interface_value) end @@ -107,6 +114,16 @@ describe Facter::Util::IP do Facter::Util::IP.get_interface_value("lan0", "macaddress").should == "00:13:21:BD:9C:B7" end + it "should return macaddress with leading zeros stripped off for GNU/kFreeBSD" do + sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig" + kfreebsd_ifconfig = File.new(sample_output_file).read() + + Facter::Util::IP.expects(:get_single_interface_output).with("em0").returns(kfreebsd_ifconfig) + Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD") + + Facter::Util::IP.get_interface_value("em0", "macaddress").should == "0:11:a:59:67:90" + end + it "should return netmask information for HP-UX" do sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" hpux_ifconfig_interface = File.new(sample_output_file).read() @@ -188,6 +205,17 @@ describe Facter::Util::IP do Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0" end + it "should return a human readable netmask on GNU/kFreeBSD" do + sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig" + + kfreebsd_ifconfig = File.new(sample_output_file).read() + + Facter::Util::IP.expects(:get_single_interface_output).with("em1").returns(kfreebsd_ifconfig) + Facter.stubs(:value).with(:kernel).returns("GNU/kFreeBSD") + + Facter::Util::IP.get_interface_value("em1", "netmask").should == "255.255.255.0" + end + it "should not get bonding master on interface aliases" do Facter.stubs(:value).with(:kernel).returns("Linux") diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb index 12ba0ac..aa2de5a 100644 --- a/spec/unit/util/virtual_spec.rb +++ b/spec/unit/util/virtual_spec.rb @@ -128,12 +128,14 @@ describe Facter::Util::Virtual do end it "should identify FreeBSD jail when in jail" do + Facter.fact(:kernel).stubs(:value).returns("FreeBSD") Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n security.jail.jailed").returns("1") Facter::Util::Virtual.should be_jail end - it "should not identify FreeBSD jail when not in jail" do - Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n security.jail.jailed").returns("0") + it "should not identify GNU/kFreeBSD jail when not in jail" do + Facter.fact(:kernel).stubs(:value).returns("GNU/kFreeBSD") + Facter::Util::Resolution.stubs(:exec).with("/bin/sysctl -n security.jail.jailed").returns("0") Facter::Util::Virtual.should_not be_jail end |