diff options
author | Adrien Thebo <adrien@puppetlabs.com> | 2011-03-15 15:40:17 -0700 |
---|---|---|
committer | Adrien Thebo <adrien@puppetlabs.com> | 2011-03-15 15:40:17 -0700 |
commit | edb97601a2f452af231d95a1e4675c8ed7da8577 (patch) | |
tree | 300296ba9e33927ec597111745ff9e68f5a03ff3 | |
parent | 6d6d8daf2b75844d035012695db73e4c67df17a0 (diff) | |
parent | 4a718a7561e6a87c00d333fedecf6097a8060696 (diff) | |
download | facter-edb97601a2f452af231d95a1e4675c8ed7da8577.tar.gz facter-edb97601a2f452af231d95a1e4675c8ed7da8577.tar.xz facter-edb97601a2f452af231d95a1e4675c8ed7da8577.zip |
Merge branch 'next' into tickets/next/2721
-rwxr-xr-x | install.rb | 28 | ||||
-rw-r--r-- | lib/facter/application.rb | 2 | ||||
-rw-r--r-- | lib/facter/id.rb | 2 | ||||
-rw-r--r-- | lib/facter/ipaddress.rb | 2 | ||||
-rw-r--r-- | lib/facter/lsb.rb | 8 | ||||
-rw-r--r-- | lib/facter/lsbmajdistrelease.rb | 2 | ||||
-rw-r--r-- | lib/facter/operatingsystem.rb | 2 | ||||
-rw-r--r-- | lib/facter/processor.rb | 7 | ||||
-rw-r--r-- | lib/facter/selinux.rb | 41 | ||||
-rw-r--r-- | lib/facter/util/ip.rb | 18 | ||||
-rw-r--r-- | lib/facter/util/virtual.rb | 7 | ||||
-rw-r--r-- | lib/facter/util/vlans.rb | 4 | ||||
-rw-r--r-- | lib/facter/virtual.rb | 4 | ||||
-rw-r--r-- | spec/unit/data/hpux_netstat_all_interfaces | 9 | ||||
-rw-r--r-- | spec/unit/data/selinux_sestatus | 6 | ||||
-rwxr-xr-x | spec/unit/operatingsystem_spec.rb | 12 | ||||
-rwxr-xr-x | spec/unit/selinux_spec.rb | 45 | ||||
-rwxr-xr-x | spec/unit/util/ip_spec.rb | 20 | ||||
-rwxr-xr-x | spec/unit/util/loader_spec.rb | 11 | ||||
-rw-r--r-- | spec/unit/util/manufacturer_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/virtual_spec.rb | 39 |
21 files changed, 192 insertions, 81 deletions
@@ -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 diff --git a/lib/facter/application.rb b/lib/facter/application.rb index 9d6bc34..6b351b1 100644 --- a/lib/facter/application.rb +++ b/lib/facter/application.rb @@ -85,7 +85,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) 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 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 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/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 diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb index 061e18e..1675909 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/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 diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb index 0e9637d..9fab427 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,15 +31,48 @@ end Facter.add("selinux_policyversion") do confine :selinux => :true - setcode do + setcode do File.read("/selinux/policyvers") end end -Facter.add("selinux_mode") do +Facter.add("selinux_current_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 =~ /^Current mode\:\s+(\w+)$/i } + result.chomp + end +end + +Facter.add("selinux_config_mode") do confine :selinux => :true setcode do - %x{/usr/sbin/sestatus | /bin/grep "Policy from config file:" | awk '{print $5}'} + 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/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/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb index 129448e..4355451 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 @@ -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/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 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/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/data/selinux_sestatus b/spec/unit/data/selinux_sestatus new file mode 100644 index 0000000..50cea13 --- /dev/null +++ b/spec/unit/data/selinux_sestatus @@ -0,0 +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/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 diff --git a/spec/unit/selinux_spec.rb b/spec/unit/selinux_spec.rb index 43fd5bf..d820958 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,45 @@ describe "SELinux facts" do Facter.fact(:selinux_policyversion).value.should == "1" end + + it "should return the SELinux current 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_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 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 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 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() diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb index a152b40..f5a5c3c 100644 --- a/spec/unit/virtual_spec.rb +++ b/spec/unit/virtual_spec.rb @@ -5,10 +5,15 @@ require 'facter/util/virtual' 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) + Facter::Util::Virtual.stubs(:zlinux?).returns(false) + end it "should be zone on Solaris when a zone" do Facter.fact(:kernel).stubs(:value).returns("SunOS") @@ -31,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") @@ -59,13 +71,9 @@ describe "Virtual fact" do 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) + 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") @@ -114,15 +122,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") @@ -177,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") |