[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, upstream, updated. 51bcebe38cab6088c901f1006339bbe40a36d161
Paul Nasrat
pnasrat at googlemail.com
Wed Aug 18 05:55:40 UTC 2010
The following commit has been merged in the upstream branch:
commit 356cf15a72027773d38db5ef74e6861345e32b56
Author: Paul Nasrat <pnasrat at googlemail.com>
Date: Sun Jan 10 17:22:30 2010 +0000
Remove whitespace in DMI facts (#3008, #3011)
In addition to the stripping of the output of these facts this patchset:
Refactor - Extracted function to enable easier testing.
Tests - data driven tests for the dmidecode/smbios fact.
Paul
diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb
index c609a12..dd503f9 100644
--- a/lib/facter/util/manufacturer.rb
+++ b/lib/facter/util/manufacturer.rb
@@ -2,8 +2,8 @@
# Support methods for manufacturer specific facts
module Facter::Manufacturer
- def self.dmi_find_system_info(name)
- splitstr="Handle"
+
+ def self.get_dmi_table()
case Facter.value(:kernel)
when 'Linux'
return nil unless FileTest.exists?("/usr/sbin/dmidecode")
@@ -19,18 +19,23 @@ module Facter::Manufacturer
output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
when 'SunOS'
return nil unless FileTest.exists?("/usr/sbin/smbios")
- splitstr="ID SIZE TYPE"
- output=%x{/usr/sbin/smbios 2>/dev/null}
+ output=%x{/usr/sbin/smbios 2>/dev/null}
else
- return
+ output=nil
end
+ return output
+ end
+
+ def self.dmi_find_system_info(name)
+ splitstr= Facter.value(:kernel) == 'SunOS' ? "ID SIZE TYPE" : "Handle"
+ output = self.get_dmi_table()
name.each_pair do |key,v|
v.each do |v2|
v2.each_pair do |value,facterkey|
output.split(splitstr).each do |line|
if line =~ /#{key}/ and ( line =~ /#{value} 0x\d+ \(([-\w].*)\)\n*./ or line =~ /#{value} ([-\w].*)\n*./ )
- result = $1
+ result = $1.strip
Facter.add(facterkey) do
confine :kernel => [ :linux, :freebsd, :netbsd, :sunos ]
setcode do
diff --git a/spec/unit/data/linux_dmidecode_with_spaces b/spec/unit/data/linux_dmidecode_with_spaces
new file mode 100644
index 0000000..0d77386
--- /dev/null
+++ b/spec/unit/data/linux_dmidecode_with_spaces
@@ -0,0 +1,60 @@
+# dmidecode 2.2
+SMBIOS 2.3 present.
+32 structures occupying 994 bytes.
+Table at 0x000F0800.
+Handle 0x0000
+ DMI type 0, 20 bytes.
+ BIOS Information
+ Vendor: Award Software International, Inc.
+ Version: 6.00 PG
+ Release Date: 01/03/2003
+ Address: 0xE0000
+ Runtime Size: 128 kB
+ ROM Size: 256 kB
+ Characteristics:
+ ISA is supported
+ PCI is supported
+ PNP is supported
+ APM is supported
+ BIOS is upgradeable
+ BIOS shadowing is allowed
+ ESCD support is available
+ Boot from CD is supported
+ Selectable boot is supported
+ BIOS ROM is socketed
+ EDD is supported
+ 5.25"/360 KB floppy services are supported (int 13h)
+ 5.25"/1.2 MB floppy services are supported (int 13h)
+ 3.5"/720 KB floppy services are supported (int 13h)
+ 3.5"/2.88 MB floppy services are supported (int 13h)
+ Print screen service is supported (int 5h)
+ 8042 keyboard services are supported (int 9h)
+ Serial services are supported (int 14h)
+ Printer services are supported (int 17h)
+ CGA/mono video services are supported (int 10h)
+ ACPI is supported
+ USB legacy is supported
+ AGP is supported
+ LS-120 boot is supported
+ ATAPI Zip drive boot is supported
+Handle 0x0001
+ DMI type 1, 25 bytes.
+ System Information
+ Manufacturer: MICRO-STAR INTERNATIONAL CO., LTD
+ Product Name: MS-6754
+ Version:
+ Serial Number:
+ UUID: Not Present
+ Wake-up Type: Power Switch
+Handle 0x0002
+ DMI type 2, 8 bytes.
+ Base Board Information
+ Manufacturer: MICRO-STAR INTERNATIONAL CO., LTD
+ Product Name: MS-6754
+ Version:
+ Serial Number:
+
+Handle 0x001F
+ DMI type 127, 4 bytes.
+ End Of Table
+
diff --git a/spec/unit/util/manufacturer.rb b/spec/unit/util/manufacturer.rb
new file mode 100644
index 0000000..47a0c98
--- /dev/null
+++ b/spec/unit/util/manufacturer.rb
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'facter/util/manufacturer'
+
+describe Facter::Manufacturer do
+ it "should return the system DMI table" do
+ Facter::Manufacturer.should respond_to(:get_dmi_table)
+ end
+
+ it "should return nil on non-supported operating systems" do
+ Facter.stubs(:value).with(:kernel).returns("SomeThing")
+ Facter::Manufacturer.get_dmi_table().should be_nil
+ 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()
+ Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+
+ query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => 'productname' } ] }
+
+ Facter::Manufacturer.dmi_find_system_info(query)
+ Facter.value(:productname).should == "MS-6754"
+ end
+end
\ No newline at end of file
--
Packaging of Facter for debian
More information about the Pkg-puppet-devel
mailing list