From 9d990797e9f787aca5bbcc3f1698d9cd00336bf6 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Mon, 22 Nov 2010 11:25:14 -0800 Subject: maint: Fix spec failures caused by having a space in the path to facter's source --- spec/unit/util/macaddress.rb | 6 +++--- spec/unit/util/uptime.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/unit/util/macaddress.rb b/spec/unit/util/macaddress.rb index 8349b36..1ccca18 100644 --- a/spec/unit/util/macaddress.rb +++ b/spec/unit/util/macaddress.rb @@ -25,7 +25,7 @@ context "Darwin" do context "when netstat has a default interface" do before do - Facter::Util::Macaddress::Darwin.stubs(:netstat_command).returns("cat #{netstat_file}") + Facter::Util::Macaddress::Darwin.stubs(:netstat_command).returns("cat \"#{netstat_file}\"") end it "should return the default interface name" do @@ -40,7 +40,7 @@ context "Darwin" 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}") + Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file}\"") end it "should return the macaddress of the default interface" do @@ -52,7 +52,7 @@ context "Darwin" do context "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}") + Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file_no_iface}\"") end it "should warn about the lack of default" do diff --git a/spec/unit/util/uptime.rb b/spec/unit/util/uptime.rb index 9ba6665..72c97ed 100644 --- a/spec/unit/util/uptime.rb +++ b/spec/unit/util/uptime.rb @@ -10,7 +10,7 @@ describe Facter::Util::Uptime do context "when /proc/uptime is available" do before do uptime_file = File.join(SPECDIR, "fixtures", "uptime", "ubuntu_proc_uptime") - Facter::Util::Uptime.stubs(:uptime_file).returns(uptime_file) + Facter::Util::Uptime.stubs(:uptime_file).returns("\"#{uptime_file}\"") end it "should return the uptime in seconds as an integer" do @@ -24,7 +24,7 @@ describe Facter::Util::Uptime do File.exists?(nonexistent_file).should == false Facter::Util::Uptime.stubs(:uptime_file).returns(nonexistent_file) sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'sysctl_kern_boottime') # Aug 01 14:13:47 -0700 2010 - Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat #{sysctl_output_file}") + Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"") Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 end @@ -35,7 +35,7 @@ describe Facter::Util::Uptime do Facter::Util::Uptime.stubs(:uptime_file).returns(nonexistent_file) Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat #{nonexistent_file}") who_b_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'who_b_boottime') # Aug 1 14:13 - Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat #{who_b_output_file}") + Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"") Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60 end -- cgit From 5b561e3b02b1dbbfb705566f62c34b404b63d7b4 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Fri, 19 Nov 2010 09:35:18 +0000 Subject: (#5325) Manufacturer and product name on SPARC Use prtdiag output on Solaris/SPARC to determine manufacturer and productname as smbios is unavailable. --- lib/facter/manufacturer.rb | 2 ++ lib/facter/util/manufacturer.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb index 9d66465..cbbb88b 100644 --- a/lib/facter/manufacturer.rb +++ b/lib/facter/manufacturer.rb @@ -13,6 +13,8 @@ if Facter.value(:kernel) == "OpenBSD" } Facter::Manufacturer.sysctl_find_system_info(mfg_keys) +elsif Facter.value(:kernel) == "SunOS" and Facter.value(:hardwareisa) == "sparc" + Facter::Manufacturer.prtdiag_sparc_find_system_info() else query = { '[Ss]ystem [Ii]nformation' => [ diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb index 112380b..5ac0585 100644 --- a/lib/facter/util/manufacturer.rb +++ b/lib/facter/util/manufacturer.rb @@ -60,4 +60,24 @@ module Facter::Manufacturer end end end + + def self.prtdiag_sparc_find_system_info() + # Parses prtdiag for a SPARC architecture string, won't work with Solaris x86 + output = Facter::Util::Resolution.exec('/usr/sbin/prtdiag') + + # System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server + sysconfig = output.split("\n")[0] + if sysconfig =~ /^System Configuration:\s+(.+?)\s+(sun\d+\S+)\s+(.+)/ then + Facter.add('manufacturer') do + setcode do + $1 + end + end + Facter.add('productname') do + setcode do + $3 + end + end + end + end end -- cgit From 9332f8a69fcf1f623f57f808085af3e1aafabc38 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Mon, 22 Nov 2010 15:41:35 -0800 Subject: (#5325) Add tests for SPARC manufacturer and product name Just tests the regex, won't actually catch problems if prtdiag doesn't return output like our test. Paired-with: Nick Lewis --- spec/unit/util/manufacturer.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spec/unit/util/manufacturer.rb b/spec/unit/util/manufacturer.rb index c0d4b13..291a6ff 100644 --- a/spec/unit/util/manufacturer.rb +++ b/spec/unit/util/manufacturer.rb @@ -3,6 +3,10 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'facter/util/manufacturer' describe Facter::Manufacturer do + before :each do + Facter.clear + end + it "should return the system DMI table" do Facter::Manufacturer.should respond_to(:get_dmi_table) end @@ -12,6 +16,13 @@ describe Facter::Manufacturer do Facter::Manufacturer.get_dmi_table().should be_nil end + it "should parse prtdiag output" do + Facter::Util::Resolution.stubs(:exec).returns("System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server") + Facter::Manufacturer.prtdiag_sparc_find_system_info() + Facter.value(:manufacturer).should == "Sun Microsystems" + Facter.value(:productname).should == "Sun SPARC Enterprise M3000 Server" + end + it "should strip white space on dmi output with spaces" do sample_output_file = File.dirname(__FILE__) + "/../data/linux_dmidecode_with_spaces" dmidecode_output = File.new(sample_output_file).read() @@ -23,7 +34,7 @@ describe Facter::Manufacturer do Facter::Manufacturer.dmi_find_system_info(query) Facter.value(:productname).should == "MS-6754" end - + it "should handle output from smbios when run under sunos" do sample_output_file = File.dirname(__FILE__) + "/../data/opensolaris_smbios" smbios_output = File.new(sample_output_file).read() -- cgit