facter 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (52) hide show
  1. data/CHANGELOG +105 -28
  2. data/Rakefile +23 -20
  3. data/bin/facter +3 -3
  4. data/conf/osx/createpackage.sh +12 -1
  5. data/conf/osx/preflight +4 -0
  6. data/install.rb +7 -14
  7. data/lib/facter.rb +14 -2
  8. data/lib/facter/architecture.rb +10 -2
  9. data/lib/facter/domain.rb +0 -3
  10. data/lib/facter/ipaddress.rb +18 -21
  11. data/lib/facter/kernel.rb +4 -2
  12. data/lib/facter/macaddress.rb +21 -8
  13. data/lib/facter/memory.rb +47 -6
  14. data/lib/facter/operatingsystem.rb +4 -0
  15. data/lib/facter/operatingsystemrelease.rb +15 -3
  16. data/lib/facter/processor.rb +16 -0
  17. data/lib/facter/uptime.rb +17 -14
  18. data/lib/facter/uptime_days.rb +7 -0
  19. data/lib/facter/uptime_hours.rb +7 -0
  20. data/lib/facter/uptime_seconds.rb +10 -0
  21. data/lib/facter/util/ip.rb +17 -5
  22. data/lib/facter/util/manufacturer.rb +13 -7
  23. data/lib/facter/util/resolution.rb +34 -11
  24. data/lib/facter/util/uptime.rb +45 -23
  25. data/lib/facter/util/virtual.rb +23 -1
  26. data/lib/facter/util/vlans.rb +24 -0
  27. data/lib/facter/virtual.rb +11 -3
  28. data/lib/facter/vlans.rb +8 -0
  29. data/spec/fixtures/uptime/sysctl_kern_boottime +0 -0
  30. data/spec/fixtures/uptime/ubuntu_proc_uptime +1 -0
  31. data/spec/fixtures/uptime/who_b_boottime +1 -0
  32. data/spec/spec_helper.rb +2 -0
  33. data/spec/unit/data/freebsd_dmidecode +42 -0
  34. data/spec/unit/data/hpux_ifconfig +3 -0
  35. data/spec/unit/data/hpux_ifconfig_single_interface +3 -0
  36. data/spec/unit/data/hpux_netscan +4 -0
  37. data/spec/unit/data/hpux_netstat_all_interfaces +6 -0
  38. data/spec/unit/data/linux_dmidecode_with_spaces +60 -0
  39. data/spec/unit/data/linux_vlan_config +6 -0
  40. data/spec/unit/data/opensolaris_smbios +33 -0
  41. data/spec/unit/facter.rb +73 -0
  42. data/spec/unit/operatingsystemrelease.rb +39 -0
  43. data/spec/unit/uptime.rb +112 -0
  44. data/spec/unit/util/ip.rb +59 -2
  45. data/spec/unit/util/manufacturer.rb +121 -0
  46. data/spec/unit/util/resolution.rb +44 -11
  47. data/spec/unit/util/uptime.rb +53 -0
  48. data/spec/unit/util/virtual.rb +24 -1
  49. data/spec/unit/util/vlans.rb +14 -0
  50. data/spec/unit/virtual.rb +20 -0
  51. metadata +115 -91
  52. data/ChangeLog +0 -1727
@@ -0,0 +1,6 @@
1
+ VLAN Dev name | VLAN ID
2
+ Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
3
+ eth0.400 | 400 | eth0
4
+ eth0.300 | 300 | eth0
5
+ eth0.200 | 200 | eth0
6
+ eth0.100 | 100 | eth0
@@ -0,0 +1,33 @@
1
+ ID SIZE TYPE
2
+ 0 54 SMB_TYPE_BIOS (BIOS information)
3
+
4
+ Vendor: innotek GmbH
5
+ Version String: VirtualBox
6
+ Release Date: 12/01/2006
7
+ Address Segment: 0xe000
8
+ ROM Size: 131072 bytes
9
+ Image Size: 131072 bytes
10
+ Characteristics: 0x48018090
11
+ SMB_BIOSFL_ISA (ISA is supported)
12
+ SMB_BIOSFL_PCI (PCI is supported)
13
+ SMB_BIOSFL_CDBOOT (Boot from CD is supported)
14
+ SMB_BIOSFL_SELBOOT (Selectable Boot supported)
15
+ SMB_BIOSFL_I9_KBD (int 0x9 8042 keyboard svcs)
16
+ SMB_BIOSFL_I10_CGA (int 0x10 CGA svcs)
17
+ Characteristics Extension Byte 1: 0x1
18
+ SMB_BIOSXB1_ACPI (ACPI is supported)
19
+ Characteristics Extension Byte 2: 0x0
20
+
21
+ ID SIZE TYPE
22
+ 1 72 SMB_TYPE_SYSTEM (system information)
23
+
24
+ Manufacturer: innotek GmbH
25
+ Product: VirtualBox
26
+ Version: 1.2
27
+ Serial Number: 0
28
+
29
+ UUID: cf4bff06-0b33-4891-bda0-5ec17bea5511
30
+ Wake-Up Event: 0x6 (power switch)
31
+ SKU Number:
32
+ Family: Virtual Machine
33
+
data/spec/unit/facter.rb CHANGED
@@ -131,6 +131,79 @@ describe Facter do
131
131
  Facter.should respond_to(:search_path)
132
132
  end
133
133
 
134
+ it "should have a method to query debugging mode" do
135
+ Facter.should respond_to(:debugging?)
136
+ end
137
+
138
+ it "should have a method to warn" do
139
+ Facter.should respond_to(:warn)
140
+ end
141
+
142
+ describe "when warning" do
143
+ it "should warn if debugging is enabled" do
144
+ Facter.debugging(true)
145
+ Kernel.stubs(:warn)
146
+ Kernel.expects(:warn).with('foo')
147
+ Facter.warn('foo')
148
+ end
149
+
150
+ it "should not warn if debugging is enabled but nil is passed" do
151
+ Facter.debugging(true)
152
+ Kernel.stubs(:warn)
153
+ Kernel.expects(:warn).never
154
+ Facter.warn(nil)
155
+ end
156
+
157
+ it "should not warn if debugging is enabled but an empyt string is passed" do
158
+ Facter.debugging(true)
159
+ Kernel.stubs(:warn)
160
+ Kernel.expects(:warn).never
161
+ Facter.warn('')
162
+ end
163
+
164
+ it "should not warn if debugging is disabled" do
165
+ Facter.debugging(false)
166
+ Kernel.stubs(:warn)
167
+ Kernel.expects(:warn).never
168
+ Facter.warn('foo')
169
+ end
170
+
171
+ it "should warn for any given element for an array if debugging is enabled" do
172
+ Facter.debugging(true)
173
+ Kernel.stubs(:warn)
174
+ Kernel.expects(:warn).with('foo')
175
+ Kernel.expects(:warn).with('bar')
176
+ Facter.warn( ['foo','bar'])
177
+ end
178
+ end
179
+
180
+ describe "when setting debugging mode" do
181
+ it "should have debugging enabled using 1" do
182
+ Facter.debugging(1)
183
+ Facter.should be_debugging
184
+ end
185
+ it "should have debugging enabled using true" do
186
+ Facter.debugging(true)
187
+ Facter.should be_debugging
188
+ end
189
+ it "should have debugging enabled using any string except off" do
190
+ Facter.debugging('aaaaa')
191
+ Facter.should be_debugging
192
+ end
193
+ it "should have debugging disabled using 0" do
194
+ Facter.debugging(0)
195
+ Facter.should_not be_debugging
196
+ end
197
+ it "should have debugging disabled using false" do
198
+ Facter.debugging(false)
199
+ Facter.should_not be_debugging
200
+ end
201
+ it "should have debugging disabled using the string 'off'" do
202
+ Facter.debugging('off')
203
+ Facter.should_not be_debugging
204
+ end
205
+ end
206
+
134
207
  describe "when registering directories to search" do
135
208
  after { Facter.instance_variable_set("@search_path", []) }
136
209
 
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ require 'facter'
6
+
7
+ describe "Operating System Release fact" do
8
+
9
+ before do
10
+ Facter.clear
11
+ end
12
+
13
+ after do
14
+ Facter.clear
15
+ end
16
+
17
+ test_cases = {
18
+ "CentOS" => "/etc/redhat-release",
19
+ "RedHat" => "/etc/redhat-release",
20
+ "Fedora" => "/etc/fedora-release",
21
+ "MeeGo" => "/etc/meego-release",
22
+ "OEL" => "/etc/enterprise-release",
23
+ "oel" => "/etc/enterprise-release",
24
+ "OVS" => "/etc/ovs-release",
25
+ "ovs" => "/etc/ovs-release"
26
+ }
27
+
28
+ test_cases.each do |system, file|
29
+ context "with operatingsystem reported as #{system.inspect}" do
30
+ it "should read the #{file.inspect} file" do
31
+ Facter.fact(:operatingsystem).stubs(:value).returns(system)
32
+
33
+ File.expects(:open).with(file, "r").at_least(1)
34
+
35
+ Facter.fact(:operatingsystemrelease).value
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ require 'facter'
6
+ require 'facter/util/uptime'
7
+
8
+ describe "uptime facts:" do
9
+ before { Facter.clear }
10
+ after { Facter.clear }
11
+
12
+ context "when uptime information is available" do
13
+ describe "uptime" do
14
+ test_cases = [
15
+ [60 * 60 * 24 * 3, '3 days'],
16
+ [60 * 60 * 24 * 3 + 25, '3 days'],
17
+ [60 * 60 * 24 * 1, '1 day'],
18
+ [60 * 60 * 24 * 1 + 25, '1 day'],
19
+ [60 * (60 * 3 + 45), '3:45 hours'],
20
+ [60 * (60 * 3 + 4), '3:04 hours'],
21
+ [60 * 60, '1:00 hours'],
22
+ [60 * 35, '0:35 hours']
23
+ ]
24
+
25
+ test_cases.each do |seconds, expected|
26
+ it "should return #{expected.inspect} for #{seconds} seconds" do
27
+ Facter::Util::Uptime.stubs(:get_uptime_seconds_unix).returns(seconds)
28
+ Facter::Util::Uptime.stubs(:get_uptime_seconds_win).returns(seconds)
29
+
30
+ Facter.fact(:uptime).value.should == expected
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ context "when uptime information is available" do
38
+ before do
39
+ Facter::Util::Uptime.stubs(:get_uptime_seconds_unix).returns(60 * 60 * 24 + 23)
40
+ Facter::Util::Uptime.stubs(:get_uptime_seconds_win).returns(60 * 60 * 24 + 23)
41
+ end
42
+
43
+ describe "uptime_seconds" do
44
+ it "should return the uptime in seconds" do
45
+ Facter.fact(:uptime_seconds).value.should == 60 * 60 * 24 + 23
46
+ end
47
+ end
48
+
49
+ describe "uptime_hours" do
50
+ it "should return the uptime in hours" do
51
+ Facter.fact(:uptime_hours).value.should == 24
52
+ end
53
+ end
54
+
55
+ describe "uptime_days" do
56
+ it "should return the uptime in days" do
57
+ Facter.fact(:uptime_days).value.should == 1
58
+ end
59
+ end
60
+ end
61
+
62
+ context "when uptime information is not available" do
63
+ before do
64
+ Facter::Util::Uptime.stubs(:get_uptime_seconds_unix).returns(nil)
65
+ Facter::Util::Uptime.stubs(:get_uptime_seconds_win).returns(nil)
66
+ $stderr, @old = StringIO.new, $stderr
67
+ end
68
+
69
+ after do
70
+ $stderr = @old
71
+ end
72
+
73
+ describe "uptime" do
74
+ it "should return 'unknown'" do
75
+ Facter.fact(:uptime).value.should == "unknown"
76
+ end
77
+ end
78
+
79
+ describe "uptime_seconds" do
80
+ it "should return nil" do
81
+ Facter.fact(:uptime_seconds).value.should == nil
82
+ end
83
+
84
+ it "should not print a warn message to stderr" do
85
+ Facter.fact(:uptime_seconds).value
86
+ $stderr.string.should == ""
87
+ end
88
+ end
89
+
90
+ describe "uptime_hours" do
91
+ it "should return nil" do
92
+ Facter.fact(:uptime_hours).value.should == nil
93
+ end
94
+
95
+ it "should not print a warn message to stderr" do
96
+ Facter.fact(:uptime_hours).value
97
+ $stderr.string.should == ""
98
+ end
99
+ end
100
+
101
+ describe "uptime_days" do
102
+ it "should return nil" do
103
+ Facter.fact(:uptime_days).value.should == nil
104
+ end
105
+
106
+ it "should not print a warn message to stderr" do
107
+ Facter.fact(:uptime_days).value
108
+ $stderr.string.should == ""
109
+ end
110
+ end
111
+ end
112
+ end
data/spec/unit/util/ip.rb CHANGED
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
5
5
  require 'facter/util/ip'
6
6
 
7
7
  describe Facter::Util::IP do
8
- [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin].each do |platform|
8
+ [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do |platform|
9
9
  it "should be supported on #{platform}" do
10
10
  Facter::Util::IP.supported_platforms.should be_include(platform)
11
11
  end
@@ -41,6 +41,13 @@ describe Facter::Util::IP do
41
41
  Facter::Util::IP.get_interfaces().should == ["lo0", "e1000g0"]
42
42
  end
43
43
 
44
+ it "should return a list three interfaces on HP-UX with three interfaces multiply reporting" do
45
+ sample_output_file = File.dirname(__FILE__) + '/../data/hpux_netstat_all_interfaces'
46
+ hpux_netstat = File.new(sample_output_file).read()
47
+ Facter::Util::IP.stubs(:get_all_interface_output).returns(hpux_netstat)
48
+ Facter::Util::IP.get_interfaces().should == ["lan1", "lan0", "lo0"]
49
+ end
50
+
44
51
  it "should return a value for a specific interface" do
45
52
  Facter::Util::IP.should respond_to(:get_interface_value)
46
53
  end
@@ -80,6 +87,46 @@ describe Facter::Util::IP do
80
87
  Facter::Util::IP.get_network_value("e1000g0").should == "172.16.15.0"
81
88
  end
82
89
 
90
+ it "should return ipaddress information for HP-UX" do
91
+ sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
92
+ hpux_ifconfig_interface = File.new(sample_output_file).read()
93
+
94
+ Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
95
+ Facter.stubs(:value).with(:kernel).returns("HP-UX")
96
+
97
+ Facter::Util::IP.get_interface_value("lan0", "ipaddress").should == "168.24.80.71"
98
+ end
99
+
100
+ it "should return macaddress information for HP-UX" do
101
+ sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
102
+ hpux_ifconfig_interface = File.new(sample_output_file).read()
103
+
104
+ Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
105
+ Facter.stubs(:value).with(:kernel).returns("HP-UX")
106
+
107
+ Facter::Util::IP.get_interface_value("lan0", "macaddress").should == "00:13:21:BD:9C:B7"
108
+ end
109
+
110
+ it "should return netmask information for HP-UX" do
111
+ sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
112
+ hpux_ifconfig_interface = File.new(sample_output_file).read()
113
+
114
+ Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
115
+ Facter.stubs(:value).with(:kernel).returns("HP-UX")
116
+
117
+ Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0"
118
+ end
119
+
120
+ it "should return calculated network information for HP-UX" do
121
+ sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
122
+ hpux_ifconfig_interface = File.new(sample_output_file).read()
123
+
124
+ Facter::Util::IP.stubs(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
125
+ Facter.stubs(:value).with(:kernel).returns("HP-UX")
126
+
127
+ Facter::Util::IP.get_network_value("lan0").should == "168.24.80.0"
128
+ end
129
+
83
130
  it "should return interface information for FreeBSD supported via an alias" do
84
131
  sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig"
85
132
  ifconfig_interface = File.new(sample_output_file).read()
@@ -120,6 +167,16 @@ describe Facter::Util::IP do
120
167
  Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
121
168
  end
122
169
 
170
+ it "should return a human readable netmask on HP-UX" do
171
+ sample_output_file = File.dirname(__FILE__) + "/../data/hpux_ifconfig_single_interface"
172
+ hpux_ifconfig_interface = File.new(sample_output_file).read()
173
+
174
+ Facter::Util::IP.expects(:get_single_interface_output).with("lan0").returns(hpux_ifconfig_interface)
175
+ Facter.stubs(:value).with(:kernel).returns("HP-UX")
176
+
177
+ Facter::Util::IP.get_interface_value("lan0", "netmask").should == "255.255.255.0"
178
+ end
179
+
123
180
  it "should return a human readable netmask on Darwin" do
124
181
  sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface"
125
182
 
@@ -137,7 +194,7 @@ describe Facter::Util::IP do
137
194
  Facter::Util::IP.get_bonding_master("eth0:1").should be_nil
138
195
  end
139
196
 
140
- [:freebsd, :netbsd, :openbsd, :sunos, :darwin].each do |platform|
197
+ [:freebsd, :netbsd, :openbsd, :sunos, :darwin, :"hp-ux"].each do |platform|
141
198
  it "should require conversion from hex on #{platform}" do
142
199
  Facter::Util::IP.convert_from_hex?(platform).should == true
143
200
  end
@@ -0,0 +1,121 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'facter/util/manufacturer'
4
+
5
+ describe Facter::Manufacturer do
6
+ it "should return the system DMI table" do
7
+ Facter::Manufacturer.should respond_to(:get_dmi_table)
8
+ end
9
+
10
+ it "should return nil on non-supported operating systems" do
11
+ Facter.stubs(:value).with(:kernel).returns("SomeThing")
12
+ Facter::Manufacturer.get_dmi_table().should be_nil
13
+ end
14
+
15
+ it "should strip white space on dmi output with spaces" do
16
+ sample_output_file = File.dirname(__FILE__) + "/../data/linux_dmidecode_with_spaces"
17
+ dmidecode_output = File.new(sample_output_file).read()
18
+ Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
19
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
20
+
21
+ query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => 'productname' } ] }
22
+
23
+ Facter::Manufacturer.dmi_find_system_info(query)
24
+ Facter.value(:productname).should == "MS-6754"
25
+ end
26
+
27
+ it "should handle output from smbios when run under sunos" do
28
+ sample_output_file = File.dirname(__FILE__) + "/../data/opensolaris_smbios"
29
+ smbios_output = File.new(sample_output_file).read()
30
+ Facter::Manufacturer.expects(:get_dmi_table).returns(smbios_output)
31
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
32
+
33
+ query = { 'BIOS information' => [ { 'Release Date:' => 'reldate' } ] }
34
+
35
+ Facter::Manufacturer.dmi_find_system_info(query)
36
+ Facter.value(:reldate).should == "12/01/2006"
37
+ end
38
+
39
+ it "should not split on dmi keys containing the string Handle" do
40
+ dmidecode_output = <<-eos
41
+ Handle 0x1000, DMI type 16, 15 bytes
42
+ Physical Memory Array
43
+ Location: System Board Or Motherboard
44
+ Use: System Memory
45
+ Error Correction Type: None
46
+ Maximum Capacity: 4 GB
47
+ Error Information Handle: Not Provided
48
+ Number Of Devices: 123
49
+
50
+ Handle 0x001F
51
+ DMI type 127, 4 bytes.
52
+ End Of Table
53
+ eos
54
+ Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
55
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
56
+ query = { 'Physical Memory Array' => [ { 'Number Of Devices:' => 'ramslots'}]}
57
+ Facter::Manufacturer.dmi_find_system_info(query)
58
+ Facter.value(:ramslots).should == "123"
59
+ end
60
+
61
+ it "should match the key in the defined section and not the first one found" do
62
+ dmidecode_output = <<-eos
63
+ Handle 0x000C, DMI type 7, 19 bytes
64
+ Cache Information
65
+ Socket Designation: Internal L2 Cache
66
+ Configuration: Enabled, Socketed, Level 2
67
+ Operational Mode: Write Back
68
+ Location: Internal
69
+ Installed Size: 4096 KB
70
+ Maximum Size: 4096 KB
71
+ Supported SRAM Types:
72
+ Burst
73
+ Installed SRAM Type: Burst
74
+ Speed: Unknown
75
+ Error Correction Type: Single-bit ECC
76
+ System Type: Unified
77
+ Associativity: 8-way Set-associative
78
+
79
+ Handle 0x1000, DMI type 16, 15 bytes
80
+ Physical Memory Array
81
+ Location: System Board Or Motherboard
82
+ Use: System Memory
83
+ Error Correction Type: None
84
+ Maximum Capacity: 4 GB
85
+ Error Information Handle: Not Provided
86
+ Number Of Devices: 2
87
+
88
+ Handle 0x001F
89
+ DMI type 127, 4 bytes.
90
+ End Of Table
91
+ eos
92
+ Facter::Manufacturer.expects(:get_dmi_table).returns(dmidecode_output)
93
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
94
+ query = { 'Physical Memory Array' => [ { 'Location:' => 'ramlocation'}]}
95
+ Facter::Manufacturer.dmi_find_system_info(query)
96
+ Facter.value(:ramlocation).should == "System Board Or Motherboard"
97
+ end
98
+
99
+ def find_product_name(os)
100
+ output_file = case os
101
+ when "FreeBSD": File.dirname(__FILE__) + "/../data/freebsd_dmidecode"
102
+ when "SunOS" : File.dirname(__FILE__) + "/../data/opensolaris_smbios"
103
+ end
104
+
105
+ output = File.new(output_file).read()
106
+ query = { '[Ss]ystem [Ii]nformation' => [ { 'Product(?: Name)?:' => "product_name_#{os}" } ] }
107
+
108
+ Facter.fact(:kernel).stubs(:value).returns(os)
109
+ Facter::Manufacturer.expects(:get_dmi_table).returns(output)
110
+
111
+ Facter::Manufacturer.dmi_find_system_info(query)
112
+
113
+ return Facter.value("product_name_#{os}")
114
+ end
115
+
116
+ it "should return the same result with smbios than with dmidecode" do
117
+ find_product_name("FreeBSD").should_not == nil
118
+ find_product_name("FreeBSD").should == find_product_name("SunOS")
119
+ end
120
+
121
+ end