From f2e66b6f6828af18811294777408c88045ff93fd Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 18 Oct 2010 14:36:34 -0700 Subject: (#5031) Remove redundant puts from RDoc.usage RDoc.usage prints the usage string. As a result, `puts RDoc.usage` is redundant and unnecessary. See http://ruby-doc.org/core/classes/RDoc.html#M004706. --- lib/facter/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/application.rb b/lib/facter/application.rb index 9de9249..56827ec 100644 --- a/lib/facter/application.rb +++ b/lib/facter/application.rb @@ -72,7 +72,7 @@ module Facter begin require 'rdoc/ri/ri_paths' require 'rdoc/usage' - puts RDoc.usage + RDoc.usage # print usage and exit rescue LoadError $stderr.puts "No help available unless your RDoc has RDoc.usage" exit(1) -- cgit From eb5d6fca87990a7c1cd0442b70da3792059fe6dd Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 2 Mar 2011 00:24:11 +1100 Subject: Fixed #6525 - Test failures on Ruby 1.9.x --- spec/unit/util/manufacturer_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/util/manufacturer_spec.rb b/spec/unit/util/manufacturer_spec.rb index 07473db..c3b372e 100644 --- a/spec/unit/util/manufacturer_spec.rb +++ b/spec/unit/util/manufacturer_spec.rb @@ -109,8 +109,8 @@ Handle 0x001F def find_product_name(os) output_file = case os - when "FreeBSD": File.dirname(__FILE__) + "/../data/freebsd_dmidecode" - when "SunOS" : File.dirname(__FILE__) + "/../data/opensolaris_smbios" + when "FreeBSD" then File.dirname(__FILE__) + "/../data/freebsd_dmidecode" + when "SunOS" then File.dirname(__FILE__) + "/../data/opensolaris_smbios" end output = File.new(output_file).read() -- cgit From 3e6217d63c73c720a7d697d810f556adf13f134b Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 2 Mar 2011 00:16:02 +1100 Subject: Fixes #6521 and other Ruby 1.9 issues Tested on Ruby 1.9.2p180 --- lib/facter/lsb.rb | 8 ++++---- lib/facter/util/virtual.rb | 4 ++-- lib/facter/util/vlans.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb index 4b98466..bf4b9db 100644 --- a/lib/facter/lsb.rb +++ b/lib/facter/lsb.rb @@ -22,13 +22,13 @@ Facter.add(fact) do confine :kernel => [ :linux, :"gnu/kfreebsd" ] setcode do - unless defined?(@@lsbdata) and defined?(@@lsbtime) and (Time.now.to_i - @@lsbtime.to_i < 5) + unless defined?(lsbdata) and defined?(lsbtime) and (Time.now.to_i - lsbtime.to_i < 5) type = nil - @@lsbtime = Time.now - @@lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null') + lsbtime = Time.now + lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null') end - if pattern.match(@@lsbdata) + if pattern.match(lsbdata) $1 else nil diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index 129448e..06b1b6d 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb @@ -60,8 +60,8 @@ module Facter::Util::Virtual def self.jail? path = case Facter.value(:kernel) - when "FreeBSD": "/sbin" - when "GNU/kFreeBSD": "/bin" + when "FreeBSD" then "/sbin" + when "GNU/kFreeBSD" then "/bin" end Facter::Util::Resolution.exec("#{path}/sysctl -n security.jail.jailed") == "1" end diff --git a/lib/facter/util/vlans.rb b/lib/facter/util/vlans.rb index 6d226ff..2b2a72f 100644 --- a/lib/facter/util/vlans.rb +++ b/lib/facter/util/vlans.rb @@ -12,7 +12,7 @@ module Facter::Util::Vlans def self.get_vlans vlans = Array.new if self.get_vlan_config - self.get_vlan_config.each do |line| + self.get_vlan_config.each_line do |line| if line =~ /^([0-9A-Za-z]+)\.([0-9]+) / vlans.insert(-1, $~[2]) if $~[2] end @@ -21,4 +21,4 @@ module Facter::Util::Vlans vlans.join(',') end -end +end -- cgit From 84fa3c440edefd117ce8a7fa5fb13d76b66ec7db Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 5 Mar 2011 15:34:04 -0600 Subject: (#6525) change semicolons to 'then' in case statement for ruby 1.9.2 compatibility --- lib/facter/util/virtual.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index 129448e..06b1b6d 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb @@ -60,8 +60,8 @@ module Facter::Util::Virtual def self.jail? path = case Facter.value(:kernel) - when "FreeBSD": "/sbin" - when "GNU/kFreeBSD": "/bin" + when "FreeBSD" then "/sbin" + when "GNU/kFreeBSD" then "/bin" end Facter::Util::Resolution.exec("#{path}/sysctl -n security.jail.jailed") == "1" end -- cgit From d6ce08a4d7c7e0a7396cc2eacd32d18d9c95542d Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 7 Mar 2011 06:47:45 +1100 Subject: Fixed #6611 - Fixed broken HPVM test and rationalised test structure --- spec/unit/virtual_spec.rb | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index a152b40..5f63dab 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -6,9 +6,14 @@ require 'facter/util/macosx' describe "Virtual fact" do - after do - Facter.clear - end + before do + Facter::Util::Virtual.stubs(:zone?).returns(false) + Facter::Util::Virtual.stubs(:openvz?).returns(false) + Facter::Util::Virtual.stubs(:vserver?).returns(false) + Facter::Util::Virtual.stubs(:xen?).returns(false) + Facter::Util::Virtual.stubs(:kvm?).returns(false) + Facter::Util::Virtual.stubs(:hpvm?).returns(false) + end it "should be zone on Solaris when a zone" do Facter.fact(:kernel).stubs(:value).returns("SunOS") @@ -58,13 +63,6 @@ describe "Virtual fact" do end describe "on Linux" do - before do - Facter::Util::Virtual.stubs(:zone?).returns(false) - Facter::Util::Virtual.stubs(:openvz?).returns(false) - Facter::Util::Virtual.stubs(:vserver?).returns(false) - Facter::Util::Virtual.stubs(:xen?).returns(false) - Facter::Util::Virtual.stubs(:kvm?).returns(false) - end it "should be parallels with Parallels vendor id from lspci" do Facter.fact(:kernel).stubs(:value).returns("Linux") @@ -114,15 +112,10 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "parallels" end end - end describe "is_virtual fact" do - after do - Facter.clear - end - it "should be virtual when running on xen" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter.fact(:virtual).stubs(:value).returns("xenu") -- cgit From 7dd730d4cd7aebf0552647632e709570f15831ec Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 7 Mar 2011 11:16:44 +1100 Subject: Fixed #5699 - Added virtual support for s390x/Zlinux Patch modified from Hector Rivas --- lib/facter/util/virtual.rb | 3 +++ lib/facter/virtual.rb | 4 ++++ spec/unit/virtual_spec.rb | 20 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index 06b1b6d..4355451 100644 --- a/lib/facter/util/virtual.rb +++ b/lib/facter/util/virtual.rb @@ -70,4 +70,7 @@ module Facter::Util::Virtual Facter::Util::Resolution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/ end + def self.zlinux? + "zlinux" + end end diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb index 47c9504..a5954cd 100644 --- a/lib/facter/virtual.rb +++ b/lib/facter/virtual.rb @@ -31,6 +31,10 @@ Facter.add("virtual") do result = "hpvm" if Facter::Util::Virtual.hpvm? end + if Facter.value(:architecture)=="s390x" + result = "zlinux" if Facter::Util::Virtual.zlinux? + end + if Facter::Util::Virtual.openvz? result = Facter::Util::Virtual.openvz_type() end diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index 5f63dab..f5a5c3c 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -5,7 +5,6 @@ require 'facter/util/virtual' require 'facter/util/macosx' describe "Virtual fact" do - before do Facter::Util::Virtual.stubs(:zone?).returns(false) Facter::Util::Virtual.stubs(:openvz?).returns(false) @@ -13,6 +12,7 @@ describe "Virtual fact" do Facter::Util::Virtual.stubs(:xen?).returns(false) Facter::Util::Virtual.stubs(:kvm?).returns(false) Facter::Util::Virtual.stubs(:hpvm?).returns(false) + Facter::Util::Virtual.stubs(:zlinux?).returns(false) end it "should be zone on Solaris when a zone" do @@ -36,6 +36,13 @@ describe "Virtual fact" do Facter.fact(:virtual).value.should == "hpvm" end + it "should be zlinux on s390x" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:architecture).stubs(:value).returns("s390x") + Facter::Util::Virtual.stubs(:zlinux?).returns(true) + Facter.fact(:virtual).value.should == "zlinux" + end + describe "on Darwin" do it "should be parallels with Parallels vendor id" do Facter.fact(:kernel).stubs(:value).returns("Darwin") @@ -63,7 +70,10 @@ describe "Virtual fact" do end describe "on Linux" do - + before do + Facter.fact(:architecture).stubs(:value).returns(true) + end + it "should be parallels with Parallels vendor id from lspci" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005") @@ -170,6 +180,12 @@ describe "is_virtual fact" do Facter.fact(:is_virtual).value.should == "true" end + it "should be true when running on S390" do + Facter.fact(:architecture).stubs(:value).returns("s390x") + Facter.fact(:virtual).stubs(:value).returns("zlinux") + Facter.fact(:is_virtual).value.should == "true" + end + it "should be true when running on parallels" do Facter.fact(:kernel).stubs(:value).returns("Darwin") Facter.fact(:virtual).stubs(:value).returns("parallels") -- cgit From 52026ee4dbf5544419e118422161c7cc8ec1ead8 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 7 Mar 2011 11:59:58 +1100 Subject: Fixed #5699 - Added processorcount support for S390x Patch from Hector Rivas --- lib/facter/processor.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb index ac75867..c71bad4 100644 --- a/lib/facter/processor.rb +++ b/lib/facter/processor.rb @@ -17,6 +17,9 @@ if ["Linux", "GNU/kFreeBSD"].include? Facter.value(:kernel) elsif l =~ /model name\s+:\s+(.*)\s*$/ processor_list[processor_num] = $1 unless processor_num == -1 processor_num = -1 + elsif l =~ /processor\s+(\d+):\s+(.*)/ + processor_num = $1.to_i + processor_list[processor_num] = $2 unless processor_num == -1 end end end @@ -80,9 +83,9 @@ if Facter.value(:kernel) == "OpenBSD" Facter::Util::Resolution.exec("uname -p") end end - + Facter.add("ProcessorCount") do - confine :kernel => :openbsd + confine :kernel => :openbsd setcode do Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d'=' -f2") end -- cgit From dd5d5bfc2b549e49b065de740572cb901079bf12 Mon Sep 17 00:00:00 2001 From: William Van Hevelingen Date: Sun, 27 Feb 2011 22:36:15 -0800 Subject: (#4925) - MS Windows doesn't do man pages Added logic to prevent installation of man pages on windows Signed-off-by: William Van Hevelingen --- install.rb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/install.rb b/install.rb index bbf4007..eb91e7c 100755 --- a/install.rb +++ b/install.rb @@ -97,16 +97,20 @@ def do_libs(libs, strip = 'lib/') end def do_man(man, strip = 'man/') + if (InstallOptions.man == true) man.each do |mf| - omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, '')) - om = File.dirname(omf) - FileUtils.makedirs(om, {:mode => 0755, :verbose => true}) - FileUtils.chmod(0755, om) - FileUtils.install(mf, omf, {:mode => 0644, :verbose => true}) - gzip = %x{which gzip} - gzip.chomp! - %x{#{gzip} -f #{omf}} + omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, '')) + om = File.dirname(omf) + FileUtils.makedirs(om, {:mode => 0755, :verbose => true}) + FileUtils.chmod(0755, om) + FileUtils.install(mf, omf, {:mode => 0644, :verbose => true}) + gzip = %x{which gzip} + gzip.chomp! + %x{#{gzip} -f #{omf}} end + else + puts "Skipping Man Page Generation" + end end # Verify that all of the prereqs are installed @@ -121,6 +125,10 @@ def check_prereqs } end +def is_windows? + RUBY_PLATFORM.to_s.match(/mswin|win32|dos|cygwin|mingw/) +end + ## # Prepare the file installation. # @@ -128,7 +136,7 @@ def prepare_installation # Only try to do docs if we're sure they have rdoc if $haverdoc InstallOptions.rdoc = true - if RUBY_PLATFORM == "i386-mswin32" + if is_windows? InstallOptions.ri = false else InstallOptions.ri = true @@ -141,7 +149,7 @@ def prepare_installation if $haveman InstallOptions.man = true - if RUBY_PLATFORM == "i386-mswin32" + if is_windows? InstallOptions.man = false end else -- cgit From 3c7841e8d10ee8cd409e15cc85683ef15fbca6d9 Mon Sep 17 00:00:00 2001 From: William Van Hevelingen Date: Thu, 23 Dec 2010 18:05:08 -0800 Subject: (#5666) windows support for facter/id.rb Signed-off-by: William Van Hevelingen --- lib/facter/id.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/id.rb b/lib/facter/id.rb index c2ab3b7..c2c3594 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 GNU/kFreeBSD} + confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS GNU/kFreeBSD windows} setcode "whoami" end -- cgit From 2e06cdcc820ad045f345579901d3d9f04530e0c6 Mon Sep 17 00:00:00 2001 From: Rick Bradley Date: Sun, 6 Mar 2011 21:38:49 -0600 Subject: (#6615) fix missing stub calls in loader specs It's not clear to me how these are now needed and apparently weren't when we first checked this in. These stubs will let the specs continue on so we can check the load order, which was the original intent of (#5510) which caused the introduction of these specs. Signed-off-by: Rick Bradley --- spec/unit/util/loader_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/unit/util/loader_spec.rb b/spec/unit/util/loader_spec.rb index eed533a..90530e8 100755 --- a/spec/unit/util/loader_spec.rb +++ b/spec/unit/util/loader_spec.rb @@ -119,7 +119,10 @@ describe Facter::Util::Loader do @loader.stubs(:search_path).returns %w{/one/dir} Dir.stubs(:entries).with("/one/dir/testing").returns %w{foo.rb bar.rb} - %w{/one/dir/testing/foo.rb /one/dir/testing/bar.rb}.each { |f| File.stubs(:directory?).with(f).returns false } + %w{/one/dir/testing/foo.rb /one/dir/testing/bar.rb}.each do |f| + File.stubs(:directory?).with(f).returns false + Kernel.stubs(:load).with(f) + end @loader.load(:testing) @loader.loaded_files.should == %w{/one/dir/testing/bar.rb /one/dir/testing/foo.rb} @@ -202,7 +205,11 @@ describe Facter::Util::Loader do Dir.stubs(:entries).with("/one/dir").returns %w{foo.rb bar.rb} %w{/one/dir}.each { |f| File.stubs(:directory?).with(f).returns true } - %w{/one/dir/foo.rb /one/dir/bar.rb}.each { |f| File.stubs(:directory?).with(f).returns false } + + %w{/one/dir/foo.rb /one/dir/bar.rb}.each do |f| + File.stubs(:directory?).with(f).returns false + Kernel.expects(:load).with(f) + end @loader.load_all -- cgit From 93461d9ba2f798beedf67ca28d4dee3da1a7c4cf Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Thu, 20 Jan 2011 16:40:33 +0000 Subject: Fixed #5950 - Solaris ipaddress incorrect after bonding failure --- lib/facter/ipaddress.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb index 08a5dc8..d563408 100644 --- a/lib/facter/ipaddress.rb +++ b/lib/facter/ipaddress.rb @@ -47,7 +47,7 @@ Facter.add(:ipaddress) do output.split(/^\S/).each { |str| if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ tmp = $1 - unless tmp =~ /^127\./ + unless tmp =~ /^127\./ or tmp == "0.0.0.0" ip = tmp break end -- cgit From ba2601f6eeb0428bf46dbb312241077c6aa37754 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 8 Mar 2011 09:30:03 +1100 Subject: Fix for #6495 - Updated interface detection 1. Fixed IP return to not filter lo/localhost and return it as a proper interface 2. Fixed HP-UX netstat return to remove extraneous first line of naming. 3. Updated tests to reflect changes --- lib/facter/util/ip.rb | 18 ++++++++---------- spec/unit/data/hpux_netstat_all_interfaces | 9 +++------ spec/unit/util/ip_spec.rb | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb index 23eeb9c..e4370dc 100644 --- a/lib/facter/util/ip.rb +++ b/lib/facter/util/ip.rb @@ -59,7 +59,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(/:$/, '') }.uniq + output.scan(/^\S+/).collect { |i| i.sub(/:$/, '') }.uniq end def self.get_all_interface_output @@ -69,7 +69,7 @@ module Facter::Util::IP when 'SunOS' output = %x{/usr/sbin/ifconfig -a} when 'HP-UX' - output = %x{/bin/netstat -i} + output = %x{/bin/netstat -in | sed -e 1d} end output end @@ -141,15 +141,13 @@ module Facter::Util::IP else output_int = get_single_interface_output(interface) - if interface != /^lo[0:]?\d?/ - output_int.each_line do |s| - if s =~ regex - value = $1 + output_int.each_line do |s| + if s =~ regex + value = $1 if label == 'netmask' && convert_from_hex?(kernel) value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.') end - tmp1.push(value) - end + tmp1.push(value) end end @@ -158,13 +156,13 @@ module Facter::Util::IP end end end - + def self.get_network_value(interface) require 'ipaddr' ipaddress = get_interface_value(interface, "ipaddress") netmask = get_interface_value(interface, "netmask") - + if ipaddress && netmask ip = IPAddr.new(ipaddress, Socket::AF_INET) subnet = IPAddr.new(netmask, Socket::AF_INET) diff --git a/spec/unit/data/hpux_netstat_all_interfaces b/spec/unit/data/hpux_netstat_all_interfaces index 7745fa8..0e8f9dc 100644 --- a/spec/unit/data/hpux_netstat_all_interfaces +++ b/spec/unit/data/hpux_netstat_all_interfaces @@ -1,6 +1,3 @@ -Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll -lan1 1500 15.12.0.0 host1.default.com - 572527659 0 1129421249 0 0 -lan0 1500 172.54.85.0 host2.default.com - 519222647 0 329127145 0 0 -lo0 4136 loopback localhost 14281117 0 14281125 0 0 +lan1 1500 192.168.100.0 192.168.100.182 12964 0 900 0 0 +lan0 1500 192.168.100.0 192.168.100.181 12964 0 715 0 0 +lo0 4136 127.0.0.0 127.0.0.1 98 0 98 0 0 diff --git a/spec/unit/util/ip_spec.rb b/spec/unit/util/ip_spec.rb index ceceb3f..1a545b8 100755 --- a/spec/unit/util/ip_spec.rb +++ b/spec/unit/util/ip_spec.rb @@ -20,11 +20,11 @@ describe Facter::Util::IP do Facter::Util::IP.get_interfaces().should == [] end - it "should return a list with a single interface on Linux with a single interface" do + it "should return a list with a single interface and the loopback interface on Linux with a single interface" do sample_output_file = File.dirname(__FILE__) + '/../data/linux_ifconfig_all_with_single_interface' linux_ifconfig = File.new(sample_output_file).read() Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig) - Facter::Util::IP.get_interfaces().should == ["eth0"] + Facter::Util::IP.get_interfaces().should == ["eth0", "lo"] end it "should return a list two interfaces on Darwin with two interfaces" do @@ -46,7 +46,7 @@ describe Facter::Util::IP do hpux_netstat = File.new(sample_output_file).read() Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat) Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"] - end + 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' @@ -102,7 +102,7 @@ describe Facter::Util::IP do Facter.stubs(:value).with(:kernel).returns("HP-UX") Facter::Util::IP.get_interface_value("lan0", "ipaddress").should == "168.24.80.71" - end + end it "should return macaddress information for HP-UX" do sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" @@ -112,7 +112,7 @@ describe Facter::Util::IP do Facter.stubs(:value).with(:kernel).returns("HP-UX") Facter::Util::IP.get_interface_value("lan0", "macaddress").should == "00:13:21:BD:9C:B7" - end + end it "should return macaddress with leading zeros stripped off for GNU/kFreeBSD" do sample_output_file = File.dirname(__FILE__) + "/../data/debian_kfreebsd_ifconfig" @@ -132,7 +132,7 @@ describe Facter::Util::IP do Facter.stubs(:value).with(:kernel).returns("HP-UX") Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0" - end + end it "should return calculated network information for HP-UX" do sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface" @@ -142,7 +142,7 @@ describe Facter::Util::IP do Facter.stubs(:value).with(:kernel).returns("HP-UX") Facter::Util::IP.get_network_value("lan0").should == "168.24.80.0" - end + end it "should return interface information for FreeBSD supported via an alias" do sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig" @@ -192,7 +192,7 @@ describe Facter::Util::IP do Facter.stubs(:value).with(:kernel).returns("HP-UX") Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0" - end + end it "should return a human readable netmask on Darwin" do sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface" @@ -204,7 +204,7 @@ 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" @@ -218,7 +218,7 @@ describe Facter::Util::IP do it "should not get bonding master on interface aliases" do Facter.stubs(:value).with(:kernel).returns("Linux") - + Facter::Util::IP.get_bonding_master("eth0:1").should be_nil end -- cgit From 214da73ac765dbff83831b2674d304046bbd3749 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 7 Mar 2011 20:25:14 +1100 Subject: Fixed #5485 - Updated selinux_mode fact 1. Added tested 2. Refactored to use F:U:R.exec 3. Chomp trailing newline --- lib/facter/selinux.rb | 11 +++++++---- spec/unit/data/selinux_sestatus | 4 ++++ spec/unit/selinux_spec.rb | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 spec/unit/data/selinux_sestatus diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb index 0e9637d..ee663a0 100644 --- a/lib/facter/selinux.rb +++ b/lib/facter/selinux.rb @@ -4,7 +4,7 @@ Facter.add("selinux") do confine :kernel => :linux - setcode do + setcode do result = "false" if FileTest.exists?("/selinux/enforce") if FileTest.exists?("/proc/self/attr/current") @@ -31,7 +31,7 @@ end Facter.add("selinux_policyversion") do confine :selinux => :true - setcode do + setcode do File.read("/selinux/policyvers") end end @@ -39,7 +39,10 @@ end Facter.add("selinux_mode") do confine :selinux => :true setcode do - %x{/usr/sbin/sestatus | /bin/grep "Policy from config file:" | awk '{print $5}'} + mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus') + mode.each_line do |l| + mode = $1 if l =~ /^Current Mode:\s+(\w+)$/ + end + mode.chomp end end - diff --git a/spec/unit/data/selinux_sestatus b/spec/unit/data/selinux_sestatus new file mode 100644 index 0000000..b16777f --- /dev/null +++ b/spec/unit/data/selinux_sestatus @@ -0,0 +1,4 @@ +SELinux status: enabled +SELinuxfs mount: /selinux +Current Mode: permissive +Policy version: 16 diff --git a/spec/unit/selinux_spec.rb b/spec/unit/selinux_spec.rb index 43fd5bf..2af9583 100755 --- a/spec/unit/selinux_spec.rb +++ b/spec/unit/selinux_spec.rb @@ -31,11 +31,11 @@ describe "SELinux facts" do File.stubs(:read).with("/selinux/enforce").returns("0") FileTest.expects(:exists?).with("/selinux/enforce").returns true - File.expects(:read).with("/selinux/enforce").returns("1") + File.expects(:read).with("/selinux/enforce").returns("1") Facter.fact(:selinux_enforced).value.should == "true" end - + it "should return an SELinux policy version" do Facter.fact(:selinux).stubs(:value).returns("true") @@ -45,4 +45,15 @@ describe "SELinux facts" do Facter.fact(:selinux_policyversion).value.should == "1" end + + it "should return the SELinux policy mode" do + Facter.fact(:selinux).stubs(:value).returns("true") + + sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' + selinux_sestatus = File.read(sample_output_file) + + Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) + + Facter.fact(:selinux_mode).value.should == "permissive" + end end -- cgit From 868e7ba51dd9511e3f23af65a51c0fc7392a76d2 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 8 Mar 2011 16:11:46 -0800 Subject: (#5485) Made selinux_mode fact work Changed regular expression to be case insensitive for cross platform compatibility. --- lib/facter/selinux.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb index ee663a0..73e3239 100644 --- a/lib/facter/selinux.rb +++ b/lib/facter/selinux.rb @@ -39,10 +39,9 @@ end Facter.add("selinux_mode") do confine :selinux => :true setcode do + result = 'unknown' mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus') - mode.each_line do |l| - mode = $1 if l =~ /^Current Mode:\s+(\w+)$/ - end - mode.chomp + mode.each_line { |l| result = $1 if l =~ /^Current mode\:\s+(\w+)$/i } + result.chomp end end -- cgit From dea6f78ace56df3459dd182300cc9618df712317 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 11 Mar 2011 10:42:41 +1100 Subject: Further fix to #5485 - SELinux facts 1. Added new facts for all values returned by the sestatus command 2. Updated legacy selinux_mode fact with former value 3. Added note and ticket #6677 to remove legacy fact at Facter 2.0.0 4. Added tests for new facts and legacy fact --- lib/facter/selinux.rb | 33 ++++++++++++++++++++++++++++++++- spec/unit/data/selinux_sestatus | 2 ++ spec/unit/selinux_spec.rb | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb index 73e3239..9fab427 100644 --- a/lib/facter/selinux.rb +++ b/lib/facter/selinux.rb @@ -36,7 +36,7 @@ Facter.add("selinux_policyversion") do end end -Facter.add("selinux_mode") do +Facter.add("selinux_current_mode") do confine :selinux => :true setcode do result = 'unknown' @@ -45,3 +45,34 @@ Facter.add("selinux_mode") do result.chomp end end + +Facter.add("selinux_config_mode") do + confine :selinux => :true + setcode do + result = 'unknown' + mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus') + mode.each_line { |l| result = $1 if l =~ /^Mode from config file\:\s+(\w+)$/i } + result.chomp + end +end + +Facter.add("selinux_config_policy") do + confine :selinux => :true + setcode do + result = 'unknown' + mode = Facter::Util::Resolution.exec('/usr/sbin/sestatus') + mode.each_line { |l| result = $1 if l =~ /^Policy from config file\:\s+(\w+)$/i } + result.chomp + end +end + +# This is a legacy fact which returns the old selinux_mode fact value to prevent +# breakages of existing manifests. It should be removed at the next major release. +# See ticket #6677. + +Facter.add("selinux_mode") do + confine :selinux => :true + setcode do + Facter.value(:selinux_config_policy) + end +end diff --git a/spec/unit/data/selinux_sestatus b/spec/unit/data/selinux_sestatus index b16777f..50cea13 100644 --- a/spec/unit/data/selinux_sestatus +++ b/spec/unit/data/selinux_sestatus @@ -1,4 +1,6 @@ SELinux status: enabled SELinuxfs mount: /selinux Current Mode: permissive +Mode from config file: permissive Policy version: 16 +Policy from config file: targeted diff --git a/spec/unit/selinux_spec.rb b/spec/unit/selinux_spec.rb index 2af9583..d820958 100755 --- a/spec/unit/selinux_spec.rb +++ b/spec/unit/selinux_spec.rb @@ -46,7 +46,7 @@ describe "SELinux facts" do Facter.fact(:selinux_policyversion).value.should == "1" end - it "should return the SELinux policy mode" do + it "should return the SELinux current mode" do Facter.fact(:selinux).stubs(:value).returns("true") sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' @@ -54,6 +54,36 @@ describe "SELinux facts" do Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) - Facter.fact(:selinux_mode).value.should == "permissive" + Facter.fact(:selinux_current_mode).value.should == "permissive" + end + + it "should return the SELinux mode from the configuration file" do + Facter.fact(:selinux).stubs(:value).returns("true") + + sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' + selinux_sestatus = File.read(sample_output_file) + + Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) + + Facter.fact(:selinux_config_mode).value.should == "permissive" + end + + it "should return the SELinux configuration file policy" do + Facter.fact(:selinux).stubs(:value).returns("true") + + sample_output_file = File.dirname(__FILE__) + '/data/selinux_sestatus' + selinux_sestatus = File.read(sample_output_file) + + Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus) + + Facter.fact(:selinux_config_policy).value.should == "targeted" + end + + it "should ensure legacy selinux_mode facts returns same value as selinux_config_policy fact" do + Facter.fact(:selinux).stubs(:value).returns("true") + + Facter.fact(:selinux_config_policy).stubs(:value).returns("targeted") + + Facter.fact(:selinux_mode).value.should == "targeted" end end -- cgit From d718af449fc30585fcc672861077ec9045a4ef03 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 11 Mar 2011 11:51:43 +1100 Subject: Fix #6679 - Added Scientific Linux to operatingsystem fact Thanks to James Goddard for the patch --- lib/facter/operatingsystem.rb | 2 ++ spec/unit/operatingsystem_spec.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index c5a3dc1..bda8ba3 100644 --- a/lib/facter/operatingsystem.rb +++ b/lib/facter/operatingsystem.rb @@ -36,6 +36,8 @@ Facter.add(:operatingsystem) do txt = File.read("/etc/redhat-release") if txt =~ /centos/i "CentOS" + elsif txt =~ /scientific/i + "Scientific" else "RedHat" end diff --git a/spec/unit/operatingsystem_spec.rb b/spec/unit/operatingsystem_spec.rb index be83916..73b3649 100755 --- a/spec/unit/operatingsystem_spec.rb +++ b/spec/unit/operatingsystem_spec.rb @@ -9,23 +9,23 @@ describe "Operating System fact" do before do Facter.clear end - + after do Facter.clear end - + it "should default to the kernel name" do Facter.fact(:kernel).stubs(:value).returns("Nutmeg") Facter.fact(:operatingsystem).value.should == "Nutmeg" end - + it "should be Solaris for SunOS" do Facter.fact(:kernel).stubs(:value).returns("SunOS") - + Facter.fact(:operatingsystem).value.should == "Solaris" end - + it "should identify Oracle VM as OVS" do Facter.fact(:kernel).stubs(:value).returns("Linux") @@ -33,7 +33,7 @@ describe "Operating System fact" do FileTest.expects(:exists?).with("/etc/ovs-release").returns true FileTest.expects(:exists?).with("/etc/enterprise-release").returns true - + Facter.fact(:operatingsystem).value.should == "OVS" end end -- cgit From aa959df77ac353c25672f3a234298f5ae63a3a79 Mon Sep 17 00:00:00 2001 From: Ben Hughes Date: Mon, 14 Mar 2011 15:53:45 +1100 Subject: Remove Solaris from the list of confined systems. It won't get the original lsb facts, and it's nonsensical too. --- lib/facter/lsbmajdistrelease.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb index 997e7ef..34a2f1e 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 GNU/kFreeBSD} + confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS GNU/kFreeBSD} setcode do if /(\d*)\./i =~ Facter.value(:lsbdistrelease) result=$1 -- cgit