summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/manufacturer.rb
blob: 07473db9ffcbc20e563f17d83d39817a73f15a1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
require File.expand_path(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

    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 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()
        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

    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()
        Facter::Manufacturer.expects(:get_dmi_table).returns(smbios_output)
        Facter.fact(:kernel).stubs(:value).returns("SunOS")

        query = { 'BIOS information' => [ { 'Release Date:' => 'reldate' } ] }

        Facter::Manufacturer.dmi_find_system_info(query)
        Facter.value(:reldate).should == "12/01/2006"
    end

    it "should not split on dmi keys containing the string Handle" do
        dmidecode_output = <<-eos
Handle 0x1000, DMI type 16, 15 bytes
Physical Memory Array
        Location: System Board Or Motherboard
        Use: System Memory
        Error Correction Type: None
        Maximum Capacity: 4 GB
        Error Information Handle: Not Provided
        Number Of Devices: 123

Handle 0x001F
        DMI type 127, 4 bytes.
        End Of Table
        eos
        Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
        Facter.fact(:kernel).stubs(:value).returns("Linux")
        query = { 'Physical Memory Array' => [ { 'Number Of Devices:' => 'ramslots'}]}
        Facter::Manufacturer.dmi_find_system_info(query)
        Facter.value(:ramslots).should == "123"
    end

    it "should match the key in the defined section and not the first one found" do
        dmidecode_output = <<-eos
Handle 0x000C, DMI type 7, 19 bytes
Cache Information
        Socket Designation: Internal L2 Cache
        Configuration: Enabled, Socketed, Level 2
        Operational Mode: Write Back
        Location: Internal
        Installed Size: 4096 KB
        Maximum Size: 4096 KB
        Supported SRAM Types:
                Burst
        Installed SRAM Type: Burst
        Speed: Unknown
        Error Correction Type: Single-bit ECC
        System Type: Unified
        Associativity: 8-way Set-associative

Handle 0x1000, DMI type 16, 15 bytes
Physical Memory Array
        Location: System Board Or Motherboard
        Use: System Memory
        Error Correction Type: None
        Maximum Capacity: 4 GB
        Error Information Handle: Not Provided
        Number Of Devices: 2

Handle 0x001F
        DMI type 127, 4 bytes.
        End Of Table
        eos
        Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
        Facter.fact(:kernel).stubs(:value).returns("Linux")
        query = { 'Physical Memory Array' => [ { 'Location:' => 'ramlocation'}]}
        Facter::Manufacturer.dmi_find_system_info(query)
        Facter.value(:ramlocation).should == "System Board Or Motherboard"
    end

    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"
            end

        output = File.new(output_file).read()
        query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => "product_name_#{os}" } ] }

        Facter.fact(:kernel).stubs(:value).returns(os)
        Facter::Manufacturer.expects(:get_dmi_table).returns(output)

        Facter::Manufacturer.dmi_find_system_info(query)

        return Facter.value("product_name_#{os}")
    end

    it "should return the same result with smbios than with dmidecode" do
        find_product_name("FreeBSD").should_not == nil
        find_product_name("FreeBSD").should == find_product_name("SunOS")
    end

end