facter 1.6.18 → 1.7.0.rc1

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 (126) hide show
  1. data/Gemfile +23 -8
  2. data/bin/facter +4 -1
  3. data/ext/build_defaults.yaml +1 -1
  4. data/ext/debian/changelog.erb +4 -22
  5. data/ext/debian/control +2 -2
  6. data/ext/project_data.yaml +1 -1
  7. data/ext/redhat/facter.spec.erb +10 -9
  8. data/install.rb +27 -53
  9. data/lib/facter.rb +23 -5
  10. data/lib/facter/application.rb +21 -0
  11. data/lib/facter/blockdevices.rb +105 -0
  12. data/lib/facter/domain.rb +19 -7
  13. data/lib/facter/filesystems.rb +38 -0
  14. data/lib/facter/hardwaremodel.rb +3 -2
  15. data/lib/facter/ipaddress6.rb +1 -2
  16. data/lib/facter/kernelrelease.rb +10 -2
  17. data/lib/facter/ldom.rb +47 -0
  18. data/lib/facter/macaddress.rb +1 -1
  19. data/lib/facter/manufacturer.rb +7 -1
  20. data/lib/facter/memory.rb +58 -160
  21. data/lib/facter/operatingsystem.rb +17 -2
  22. data/lib/facter/operatingsystemmajrelease.rb +33 -0
  23. data/lib/facter/operatingsystemrelease.rb +88 -37
  24. data/lib/facter/osfamily.rb +6 -2
  25. data/lib/facter/processor.rb +2 -2
  26. data/lib/facter/ps.rb +5 -0
  27. data/lib/facter/ssh.rb +50 -12
  28. data/lib/facter/util/cfpropertylist.rb +6 -0
  29. data/lib/facter/util/cfpropertylist/LICENSE +19 -0
  30. data/lib/facter/util/cfpropertylist/README +44 -0
  31. data/lib/facter/util/cfpropertylist/Rakefile +44 -0
  32. data/lib/facter/util/cfpropertylist/THANKS +7 -0
  33. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +6 -0
  34. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +562 -0
  35. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +26 -0
  36. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +402 -0
  37. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +244 -0
  38. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +135 -0
  39. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +140 -0
  40. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +136 -0
  41. data/lib/facter/util/collection.rb +36 -14
  42. data/lib/facter/util/composite_loader.rb +12 -0
  43. data/lib/facter/util/config.rb +36 -0
  44. data/lib/facter/util/confine.rb +1 -6
  45. data/lib/facter/util/directory_loader.rb +83 -0
  46. data/lib/facter/util/fact.rb +49 -42
  47. data/lib/facter/util/file_read.rb +32 -0
  48. data/lib/facter/util/ip.rb +2 -9
  49. data/lib/facter/util/loader.rb +16 -2
  50. data/lib/facter/util/macosx.rb +15 -2
  51. data/lib/facter/util/memory.rb +154 -27
  52. data/lib/facter/util/nothing_loader.rb +15 -0
  53. data/lib/facter/util/parser.rb +141 -0
  54. data/lib/facter/util/processor.rb +27 -35
  55. data/lib/facter/util/resolution.rb +97 -26
  56. data/lib/facter/util/solaris_zones.rb +153 -0
  57. data/lib/facter/util/virtual.rb +32 -3
  58. data/lib/facter/version.rb +72 -2
  59. data/lib/facter/virtual.rb +56 -3
  60. data/lib/facter/zfs_version.rb +10 -0
  61. data/lib/facter/zonename.rb +6 -0
  62. data/lib/facter/zones.rb +17 -0
  63. data/lib/facter/zpool_version.rb +10 -0
  64. data/spec/fixtures/ifconfig/ifconfig_net_tools_1.60.txt +19 -0
  65. data/spec/fixtures/ifconfig/ifconfig_ubuntu_1204.txt +16 -0
  66. data/spec/fixtures/ldom/ldom_v1 +6 -0
  67. data/spec/fixtures/unit/filesystems/linux +28 -0
  68. data/spec/fixtures/unit/util/manufacturer/intel_linux_dmidecode +549 -0
  69. data/spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt +0 -0
  70. data/spec/fixtures/unit/zfs_version/freebsd_8.2 +14 -0
  71. data/spec/fixtures/unit/zfs_version/freebsd_9.0 +13 -0
  72. data/spec/fixtures/unit/zfs_version/linux-fuse_0.6.9 +14 -0
  73. data/spec/fixtures/unit/zfs_version/solaris_10 +10 -0
  74. data/spec/fixtures/unit/zfs_version/solaris_11 +12 -0
  75. data/spec/fixtures/unit/zpool_version/freebsd_8.2 +26 -0
  76. data/spec/fixtures/unit/zpool_version/freebsd_9.0 +38 -0
  77. data/spec/fixtures/unit/zpool_version/linux-fuse_0.6.9 +35 -0
  78. data/spec/fixtures/unit/zpool_version/solaris_10 +31 -0
  79. data/spec/fixtures/unit/zpool_version/solaris_11 +43 -0
  80. data/spec/integration/facter_spec.rb +12 -0
  81. data/spec/spec_helper.rb +9 -0
  82. data/spec/unit/architecture_spec.rb +1 -1
  83. data/spec/unit/blockdevices_spec.rb +109 -0
  84. data/spec/unit/domain_spec.rb +189 -81
  85. data/spec/unit/ec2_spec.rb +15 -8
  86. data/spec/unit/filesystems_spec.rb +50 -0
  87. data/spec/unit/hardwaremodel_spec.rb +8 -1
  88. data/spec/unit/id_spec.rb +6 -5
  89. data/spec/unit/ipaddress6_spec.rb +14 -2
  90. data/spec/unit/ipaddress_spec.rb +1 -1
  91. data/spec/unit/kernel_spec.rb +24 -0
  92. data/spec/unit/kernelmajversion_spec.rb +17 -0
  93. data/spec/unit/kernelrelease_spec.rb +53 -0
  94. data/spec/unit/kernelversion_spec.rb +32 -0
  95. data/spec/unit/ldom_spec.rb +74 -0
  96. data/spec/unit/macaddress_spec.rb +3 -1
  97. data/spec/unit/manufacturer_spec.rb +115 -0
  98. data/spec/unit/memory_spec.rb +442 -75
  99. data/spec/unit/operatingsystem_spec.rb +16 -2
  100. data/spec/unit/operatingsystemmajrelease_spec.rb +16 -0
  101. data/spec/unit/operatingsystemrelease_spec.rb +110 -1
  102. data/spec/unit/processor_spec.rb +22 -7
  103. data/spec/unit/ps_spec.rb +42 -0
  104. data/spec/unit/ssh_spec.rb +76 -0
  105. data/spec/unit/util/collection_spec.rb +94 -118
  106. data/spec/unit/util/config_spec.rb +36 -5
  107. data/spec/unit/util/confine_spec.rb +31 -43
  108. data/spec/unit/util/directory_loader_spec.rb +87 -0
  109. data/spec/unit/util/fact_spec.rb +37 -25
  110. data/spec/unit/util/file_read_spec.rb +29 -0
  111. data/spec/unit/util/ip_spec.rb +4 -2
  112. data/spec/unit/util/loader_spec.rb +102 -45
  113. data/spec/unit/util/macosx_spec.rb +40 -9
  114. data/spec/unit/util/manufacturer_spec.rb +12 -1
  115. data/spec/unit/util/parser_spec.rb +135 -0
  116. data/spec/unit/util/resolution_spec.rb +136 -4
  117. data/spec/unit/util/solaris_zones_spec.rb +127 -0
  118. data/spec/unit/util/virtual_spec.rb +54 -0
  119. data/spec/unit/version_spec.rb +42 -0
  120. data/spec/unit/virtual_spec.rb +102 -27
  121. data/spec/unit/zfs_version_spec.rb +76 -0
  122. data/spec/unit/zonename_spec.rb +14 -0
  123. data/spec/unit/zones_spec.rb +55 -0
  124. data/spec/unit/zpool_version_spec.rb +76 -0
  125. metadata +113 -11
  126. data/lib/facter/arp.rb +0 -28
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spec_helper'
4
+ require 'facter'
5
+ require 'facter/util/manufacturer'
6
+
7
+ describe "Hardware manufacturer facts" do
8
+
9
+ describe "on OS'es without DMI support" do
10
+
11
+ it "no DMI facts should be reported" do
12
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
13
+ Facter.fact(:boardmanufacturer).should == nil
14
+ Facter.fact(:boardproductname).should == nil
15
+ Facter.fact(:boardserialnumber).should == nil
16
+ Facter.fact(:bios_vendor).should == nil
17
+ Facter.fact(:bios_version).should == nil
18
+ Facter.fact(:bios_release_date).should == nil
19
+ Facter.fact(:type).should == nil
20
+ end
21
+
22
+ end
23
+
24
+ describe "on OS'es with DMI support" do
25
+ before :each do
26
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
27
+ dmidecode_output = <<-eos
28
+ Handle 0x0000, DMI type 0, 24 bytes
29
+ BIOS Information
30
+ Vendor: Dell Inc.
31
+ Version: 1.2.5
32
+ Release Date: 03/16/2011
33
+ Address: 0xF0000
34
+ Runtime Size: 64 kB
35
+ ROM Size: 4096 kB
36
+ Characteristics:
37
+ ISA is supported
38
+ PCI is supported
39
+ PNP is supported
40
+ BIOS is upgradeable
41
+ BIOS shadowing is allowed
42
+ Boot from CD is supported
43
+ Selectable boot is supported
44
+ EDD is supported
45
+ 8042 keyboard services are supported (int 9h)
46
+ Serial services are supported (int 14h)
47
+ CGA/mono video services are supported (int 10h)
48
+ ACPI is supported
49
+ USB legacy is supported
50
+ BIOS boot specification is supported
51
+ Function key-initiated network boot is supported
52
+ Targeted content distribution is supported
53
+ BIOS Revision: 1.2
54
+
55
+ Handle 0x0100, DMI type 1, 27 bytes
56
+ System Information
57
+ Manufacturer: Dell Inc.
58
+ Product Name: PowerEdge R515
59
+ Version: Not Specified
60
+ Serial Number: ABCD124
61
+ UUID: 1A2B3456-7890-1A23-4567-B8C91D123456
62
+ Wake-up Type: Power Switch
63
+ SKU Number: Not Specified
64
+ Family: Not Specified
65
+
66
+ Handle 0x0200, DMI type 2, 9 bytes
67
+ Base Board Information
68
+ Manufacturer: Dell Inc.
69
+ Product Name: 03X0MN
70
+ Version: A03
71
+ Serial Number: ..AB1234567B1234.
72
+ Asset Tag: Not Specified
73
+
74
+ Handle 0x0300, DMI type 3, 21 bytes
75
+ Chassis Information
76
+ Manufacturer: Dell Inc.
77
+ Type: Rack Mount Chassis
78
+ Lock: Present
79
+ Version: Not Specified
80
+ Serial Number: ABCD124
81
+ Asset Tag: Not Specified
82
+ Boot-up State: Safe
83
+ Power Supply State: Safe
84
+ Thermal State: Safe
85
+ Security Status: Unknown
86
+ OEM Information: 0x00000000
87
+ Height: 2 U
88
+ Number Of Power Cords: Unspecified
89
+ Contained Elements: 0
90
+
91
+ Handle 0x7F00, DMI type 127, 4 bytes
92
+ End Of Table
93
+ eos
94
+ Facter::Manufacturer.stubs(:get_dmi_table).returns(dmidecode_output)
95
+ end
96
+
97
+ it "should report the correct details from the DMI query" do
98
+ Facter.fact(:manufacturer).value.should == "Dell Inc."
99
+ Facter.fact(:boardmanufacturer).value.should == "Dell Inc."
100
+ Facter.fact(:boardproductname).value.should == "03X0MN"
101
+ Facter.fact(:boardserialnumber).value.should == "..AB1234567B1234."
102
+ Facter.fact(:bios_vendor).value.should == "Dell Inc."
103
+ Facter.fact(:bios_version).value.should == "1.2.5"
104
+ Facter.fact(:bios_release_date).value.should == "03/16/2011"
105
+ Facter.fact(:manufacturer).value.should == "Dell Inc."
106
+ Facter.fact(:productname).value.should == "PowerEdge R515"
107
+ Facter.fact(:serialnumber).value.should == "ABCD124"
108
+ Facter.fact(:type).value.should == "Rack Mount Chassis"
109
+ Facter.fact(:productname).value.should_not == Facter.fact(:boardproductname).value
110
+ Facter.fact(:serialnumber).value.should_not == Facter.fact(:boardserialnumber).value
111
+ end
112
+
113
+ end
114
+
115
+ end
@@ -3,46 +3,195 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe "Memory facts" do
6
- before do
7
- # We need these facts loaded, but they belong to a file with a
8
- # different name, so load the file explicitly.
9
- Facter.collection.loader.load(:memory)
10
- end
11
-
12
6
  after do
13
7
  Facter.clear
14
8
  end
15
9
 
16
- it "should return the current swap size" do
10
+ describe "when returning scaled sizes" do
11
+ before(:each) do
12
+ Facter.collection.internal_loader.load(:memory)
13
+ end
17
14
 
18
- Facter.fact(:kernel).stubs(:value).returns("Darwin")
19
- Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
20
- swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
15
+ [ "memorysize",
16
+ "memoryfree",
17
+ "swapsize",
18
+ "swapfree"
19
+ ].each do |fact|
20
+
21
+ describe "when #{fact}_mb does not exist" do
22
+ before(:each) do
23
+ Facter.fact(fact + "_mb").stubs(:value).returns(nil)
24
+ end
25
+
26
+ it "#{fact} should not exist either" do
27
+ Facter.fact(fact).value.should be_nil
28
+ end
29
+ end
30
+
31
+ { "200.00" => "200.00 MB",
32
+ "1536.00" => "1.50 GB",
33
+ "1572864.00" => "1.50 TB",
34
+ }.each do |mbval, scval|
35
+ it "should scale #{fact} when given #{mbval} MB" do
36
+ Facter.fact(fact + "_mb").stubs(:value).returns(mbval)
37
+ Facter.fact(fact).value.should == scval
38
+ end
39
+ end
40
+ end
21
41
 
22
- if swapusage =~ /total = (\S+).*/
23
- Facter.fact(:swapfree).value.should == $1
42
+ after(:each) do
43
+ Facter.clear
24
44
  end
25
45
  end
26
46
 
27
- it "should return the current swap free" do
28
- Facter.fact(:kernel).stubs(:value).returns("Darwin")
29
- Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
30
- swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
47
+ describe "on Darwin" do
48
+ before(:each) do
49
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
50
+ Facter::Util::Resolution.stubs(:exec).with('sysctl -n hw.memsize').returns('8589934592')
51
+ sample_vm_stat = <<VMSTAT
52
+ Mach Virtual Memory Statistics: (page size of 4096 bytes)
53
+ Pages free: 28430.
54
+ Pages active: 1152576.
55
+ Pages inactive: 489054.
56
+ Pages speculative: 7076.
57
+ Pages wired down: 418217.
58
+ "Translation faults": 1340091228.
59
+ Pages copy-on-write: 16851357.
60
+ Pages zero filled: 665168768.
61
+ Pages reactivated: 3082708.
62
+ Pageins: 13862917.
63
+ Pageouts: 1384383.
64
+ Object cache: 14 hits of 2619925 lookups (0% hit rate)
65
+ VMSTAT
66
+ Facter::Util::Resolution.stubs(:exec).with('vm_stat').returns(sample_vm_stat)
67
+ Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 1.00M free = 63.00M (encrypted)")
68
+
69
+ Facter.collection.internal_loader.load(:memory)
70
+ end
71
+
72
+ it "should return the current swap size in MB" do
73
+ Facter.fact(:swapsize_mb).value.should == "64.00"
74
+ end
75
+
76
+ it "should return the current swap free in MB" do
77
+ Facter.fact(:swapfree_mb).value.should == "63.00"
78
+ end
31
79
 
32
- if swapusage =~ /free = (\S+).*/
33
- Facter.fact(:swapfree).value.should == $1
80
+ it "should return whether swap is encrypted" do
81
+ Facter.fact(:swapencrypted).value.should == true
82
+ end
83
+
84
+ it "should return the memory size in MB" do
85
+ Facter.fact(:memorysize_mb).value.should == "8192.00"
86
+ end
87
+
88
+ it "should return the memory free in MB" do
89
+ Facter.fact(:memoryfree_mb).value.should == "138.70"
90
+ end
91
+
92
+ after(:each) do
93
+ Facter.clear
34
94
  end
35
95
  end
36
96
 
37
- it "should return whether swap is encrypted" do
38
- Facter.fact(:kernel).stubs(:value).returns("Darwin")
39
- Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
40
- swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
97
+ [ "linux",
98
+ "gnu/kfreebsd",
99
+ ].each do |kernel|
100
+
101
+
102
+ describe "on #{kernel}" do
103
+ before(:each) do
104
+ Facter.clear
105
+ Facter.fact(:kernel).stubs(:value).returns(kernel)
106
+ meminfo = <<INFO
107
+ MemTotal: 255908 kB
108
+ MemFree: 69936 kB
109
+ Buffers: 15812 kB
110
+ Cached: 115124 kB
111
+ SwapCached: 0 kB
112
+ Active: 92700 kB
113
+ Inactive: 63792 kB
114
+ SwapTotal: 524280 kB
115
+ SwapFree: 524280 kB
116
+ Dirty: 4 kB
117
+ INFO
118
+
119
+ File.stubs(:readlines).with("/proc/meminfo").returns(meminfo.split("\n"))
120
+
121
+ Facter.collection.internal_loader.load(:memory)
122
+ end
123
+
124
+ after(:each) do
125
+ Facter.clear
126
+ end
127
+
128
+ it "should return the current memory size in MB" do
129
+ Facter.fact(:memorysize_mb).value.should == "249.91"
130
+ end
131
+
132
+ it "should return the current memory free in MB" do
133
+ Facter.fact(:memoryfree_mb).value.should == "196.16"
134
+ end
135
+
136
+ it "should return the current swap size in MB" do
137
+ Facter.fact(:swapsize_mb).value.should == "511.99"
138
+ end
139
+
140
+ it "should return the current swap free in MB" do
141
+ Facter.fact(:swapfree_mb).value.should == "511.99"
142
+ end
143
+ end
144
+ end
41
145
 
42
- swapusage =~ /\(encrypted\)/
43
- Facter.fact(:swapencrypted).value.should == true
146
+ describe "on AIX" do
147
+ before (:each) do
148
+ Facter.clear
149
+ Facter.fact(:kernel).stubs(:value).returns("AIX")
150
+
151
+ swapusage = <<SWAP
152
+ device maj,min total free
153
+ /dev/hd6 10, 2 512MB 508MB
154
+ SWAP
155
+
156
+ Facter::Util::Resolution.stubs(:exec).with('swap -l').returns(swapusage)
157
+
158
+ Facter.collection.internal_loader.load(:memory)
159
+ end
160
+
161
+ after(:each) do
162
+ Facter.clear
163
+ end
164
+
165
+ describe "when not root" do
166
+ before(:each) do
167
+ Facter.fact(:id).stubs(:value).returns("notroot")
168
+ end
169
+
170
+ it "should return nil for swap size" do
171
+ Facter.fact(:swapsize_mb).value.should be_nil
172
+ end
173
+
174
+ it "should return nil for swap free" do
175
+ Facter.fact(:swapfree_mb).value.should be_nil
176
+ end
177
+ end
178
+
179
+ describe "when root" do
180
+ before(:each) do
181
+ Facter.fact(:id).stubs(:value).returns("root")
182
+ end
183
+
184
+ it "should return the current swap size in MB" do
185
+ Facter.fact(:swapsize_mb).value.should == "512.00"
186
+ end
187
+
188
+ it "should return the current swap free in MB" do
189
+ Facter.fact(:swapfree_mb).value.should == "508.00"
190
+ end
191
+ end
44
192
  end
45
193
 
194
+
46
195
  describe "on OpenBSD" do
47
196
  before :each do
48
197
  Facter.clear
@@ -60,96 +209,314 @@ EOS
60
209
 
61
210
  Facter::Util::Resolution.stubs(:exec).with("sysctl hw.physmem | cut -d'=' -f2").returns('267321344')
62
211
 
63
- Facter.collection.loader.load(:memory)
212
+ Facter.collection.internal_loader.load(:memory)
64
213
  end
65
214
 
66
215
  after :each do
67
216
  Facter.clear
68
217
  end
69
218
 
70
- it "should return the current swap free" do
71
- Facter.fact(:swapfree).value.should == "144.87 MB"
219
+ it "should return the current swap free in MB" do
220
+ Facter.fact(:swapfree_mb).value.should == "144.87"
72
221
  end
73
222
 
74
- it "should return the current swap size" do
75
- Facter.fact(:swapsize).value.should == "144.87 MB"
223
+ it "should return the current swap size in MB" do
224
+ Facter.fact(:swapsize_mb).value.should == "144.87"
76
225
  end
77
226
 
78
- it "should return the current memorysize" do
79
- Facter.fact(:memorysize).value.should == "254.94 MB"
227
+ it "should return the current memory free in MB" do
228
+ Facter.fact(:memoryfree_mb).value.should == "176.79"
229
+ end
230
+
231
+ it "should return the current memory size in MB" do
232
+ Facter.fact(:memorysize_mb).value.should == "254.94"
80
233
  end
81
234
  end
82
235
 
83
- describe "on DragonFly BSD" do
84
- before :each do
236
+ describe "on Solaris" do
237
+ before(:each) do
85
238
  Facter.clear
86
- Facter.fact(:kernel).stubs(:value).returns("dragonfly")
239
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
240
+ sample_prtconf = <<PRTCONF
241
+ System Configuration: Sun Microsystems sun4u
242
+ Memory size: 2048 Megabytes
243
+ System Peripherals (Software Nodes):
244
+
245
+ PRTCONF
246
+ Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/prtconf 2>/dev/null').returns sample_prtconf
247
+
248
+ vmstat_lines = <<VMSTAT
249
+ kthr memory page disk faults cpu
250
+ r b w swap free re mf pi po fr de sr s0 s3 -- -- in sy cs us sy id
251
+ 0 0 0 1154552 476224 8 19 0 0 0 0 0 0 0 0 0 460 294 236 1 2 97
252
+ VMSTAT
253
+ Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat_lines)
254
+ end
87
255
 
88
- swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
89
- Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n hw.pagesize').returns("4096")
90
- Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_size').returns("128461")
91
- Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_anon_use').returns("2635")
92
- Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_cache_use').returns("0")
256
+ after(:each) do
257
+ Facter.clear
258
+ end
93
259
 
94
- vmstat = <<EOS
95
- procs memory page disks faults cpu
96
- r b w avm fre flt re pi po fr sr da0 sg1 in sy cs us sy id
97
- 0 0 0 33152 13940 1902120 2198 53119 11642 6544597 5460994 0 0 6148243 7087927 3484264 0 1 9
98
- EOS
99
- Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
260
+ describe "when single swap exists" do
261
+ before(:each) do
262
+ sample_swap_line = <<SWAP
263
+ swapfile dev swaplo blocks free
264
+ /dev/swap 4294967295,4294967295 16 2097136 2097136
265
+ SWAP
266
+ Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/swap -l').returns sample_swap_line
100
267
 
101
- Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.physmem").returns('248512512')
268
+ Facter.collection.internal_loader.load(:memory)
269
+ end
102
270
 
103
- Facter.collection.loader.load(:memory)
104
- end
271
+ it "should return the current memory size in MB" do
272
+ Facter.fact(:memorysize_mb).value.should == "2048.00"
273
+ end
105
274
 
106
- after :each do
107
- Facter.clear
108
- end
275
+ it "should return the current memory free in MB" do
276
+ Facter.fact(:memoryfree_mb).value.should == "465.06"
277
+ end
109
278
 
110
- it "should return the current swap free" do
111
- Facter.fact(:swapfree).value.should == "491.51 MB"
279
+ it "should return the current swap free in MB" do
280
+ Facter.fact(:swapfree_mb).value.should == "1023.99"
281
+ end
282
+
283
+ it "should return the current swap size in MB" do
284
+ Facter.fact(:swapsize_mb).value.should == "1023.99"
285
+ end
112
286
  end
113
287
 
114
- it "should return the current swap size" do
115
- Facter.fact(:swapsize).value.should == "501.80 MB"
288
+ describe "when multiple swaps exist" do
289
+ before(:each) do
290
+ sample_swap_line = <<SWAP
291
+ swapfile dev swaplo blocks free
292
+ /dev/swap 4294967295,4294967295 16 2097136 2097136
293
+ /dev/swap2 4294967295,4294967295 16 2097136 2097136
294
+ SWAP
295
+ Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/swap -l').returns sample_swap_line
296
+ Facter.collection.internal_loader.load(:memory)
297
+ end
298
+
299
+ it "should return the current memory size in MB" do
300
+ Facter.fact(:memorysize_mb).value.should == "2048.00"
301
+ end
302
+
303
+ it "should return the current memory free in MB" do
304
+ Facter.fact(:memoryfree_mb).value.should == "465.06"
305
+ end
306
+
307
+ it "should return the current swap free in MB" do
308
+ Facter.fact(:swapfree_mb).value.should == "2047.98"
309
+ end
310
+
311
+ it "should return the current swap size in MB" do
312
+ Facter.fact(:swapsize_mb).value.should == "2047.98"
313
+ end
116
314
  end
117
315
 
118
- it "should return the current memorysize" do
119
- Facter.fact(:memorysize).value.should == "237.00 MB"
316
+ describe "when no swap exists" do
317
+ before(:each) do
318
+ Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/swap -l').returns ""
319
+
320
+ Facter.collection.internal_loader.load(:memory)
321
+ end
322
+
323
+ it "should return the current memory size in MB" do
324
+ Facter.fact(:memorysize_mb).value.should == "2048.00"
325
+ end
326
+
327
+ it "should return the current memory free in MB" do
328
+ Facter.fact(:memoryfree_mb).value.should == "465.06"
329
+ end
330
+
331
+ it "should return 0 for the swap free in MB" do
332
+ Facter.fact(:swapfree_mb).value.should == "0.00"
333
+ end
334
+
335
+ it "should return 0 for the swap size in MB" do
336
+ Facter.fact(:swapsize_mb).value.should == "0.00"
337
+ end
120
338
  end
121
339
  end
122
340
 
123
- describe "on Windows" do
124
- before :each do
125
- Facter.clear
126
- Facter.fact(:kernel).stubs(:value).returns("windows")
127
- Facter.collection.loader.load(:memory)
341
+ describe "on DragonFly BSD" do
342
+ before :each do
343
+ Facter.clear
344
+ Facter.fact(:kernel).stubs(:value).returns("dragonfly")
128
345
 
129
- require 'facter/util/wmi'
130
- end
346
+ swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
347
+ Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n hw.pagesize').returns("4096")
348
+ Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_size').returns("128461")
349
+ Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_anon_use').returns("2635")
350
+ Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_cache_use').returns("0")
351
+
352
+ vmstat = <<EOS
353
+ procs memory page disks faults cpu
354
+ r b w avm fre flt re pi po fr sr da0 sg1 in sy cs us sy id
355
+ 0 0 0 33152 13940 1902120 2198 53119 11642 6544597 5460994 0 0 6148243 7087927 3484264 0 1 9
356
+ EOS
357
+ Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
358
+
359
+ Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.physmem").returns('248512512')
360
+
361
+ Facter.collection.internal_loader.load(:memory)
362
+ end
131
363
 
132
- it "should return free memory" do
133
- os = stubs 'os'
134
- os.stubs(:FreePhysicalMemory).returns("3415624")
135
- Facter::Util::WMI.stubs(:execquery).returns([os])
364
+ after :each do
365
+ Facter.clear
366
+ end
136
367
 
137
- Facter.fact(:MemoryFree).value.should == '3.26 GB'
368
+ it "should return the current swap free in MB" do
369
+ Facter.fact(:swapfree_mb).value.should == "491.51"
370
+ end
371
+
372
+ it "should return the current swap size in MB" do
373
+ Facter.fact(:swapsize_mb).value.should == "501.80"
374
+ end
375
+
376
+ it "should return the current memory size in MB" do
377
+ Facter.fact(:memorysize_mb).value.should == "237.00"
378
+ end
379
+
380
+ it "should return the current memory free in MB" do
381
+ Facter.fact(:memoryfree_mb).value.should == "13.61"
382
+ end
138
383
  end
139
384
 
140
- it "should return total memory" do
141
- computer = stubs 'computer'
142
- computer.stubs(:TotalPhysicalMemory).returns("4193837056")
143
- Facter::Util::WMI.stubs(:execquery).returns([computer])
385
+ describe "on FreeBSD" do
386
+ before(:each) do
387
+ Facter.clear
388
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
389
+
390
+ sample_vmstat = <<VM_STAT
391
+ procs memory page disks faults cpu
392
+ r b w avm fre flt re pi po fr sr da0 cd0 in sy cs us sy id
393
+ 1 0 0 207600 656640 10 0 0 0 13 0 0 0 51 164 257 0 1 99
394
+ VM_STAT
395
+ Facter::Util::Resolution.stubs(:exec).with('vmstat -H').returns sample_vmstat
396
+ sample_physmem = <<PHYSMEM
397
+ 1056276480
398
+ PHYSMEM
399
+ Facter::Util::Resolution.stubs(:exec).with('sysctl -n hw.physmem').returns sample_physmem
400
+ end
401
+
402
+ after(:each) do
403
+ Facter.clear
404
+ end
405
+
406
+ describe "with no swap" do
407
+ before(:each) do
408
+ sample_swapinfo = <<SWAP
409
+ Device 1K-blocks Used Avail Capacity
410
+ SWAP
411
+ Facter::Util::Resolution.stubs(:exec).with('swapinfo -k').returns sample_swapinfo
412
+
413
+ Facter.collection.internal_loader.load(:memory)
414
+ end
415
+
416
+ it "should return the current swap free in MB" do
417
+ Facter.fact(:swapfree_mb).value.should == "0.00"
418
+ end
419
+
420
+ it "should return the current swap size in MB" do
421
+ Facter.fact(:swapsize_mb).value.should == "0.00"
422
+ end
423
+
424
+ it "should return the current memory size in MB" do
425
+ Facter.fact(:memorysize_mb).value.should == "1007.34"
426
+ end
427
+
428
+ it "should return the current memory free in MB" do
429
+ Facter.fact(:memoryfree_mb).value.should == "641.25"
430
+ end
431
+ end
432
+
433
+ describe "with one swap" do
434
+ before(:each) do
435
+ sample_swapinfo = <<SWAP
436
+ Device 1K-blocks Used Avail Capacity
437
+ /dev/da0p3 2048540 0 1048540 0%
438
+ SWAP
439
+ Facter::Util::Resolution.stubs(:exec).with('swapinfo -k').returns sample_swapinfo
440
+
441
+ Facter.collection.internal_loader.load(:memory)
442
+ end
443
+
444
+ it "should return the current swap free in MB" do
445
+ Facter.fact(:swapfree_mb).value.should == "1023.96"
446
+ end
447
+
448
+ it "should return the current swap size in MB" do
449
+ Facter.fact(:swapsize_mb).value.should == "2000.53"
450
+ end
451
+
452
+ it "should return the current memory size in MB" do
453
+ Facter.fact(:memorysize_mb).value.should == "1007.34"
454
+ end
455
+
456
+ it "should return the current memory free in MB" do
457
+ Facter.fact(:memoryfree_mb).value.should == "641.25"
458
+ end
459
+ end
460
+
461
+ describe "with multiple swaps" do
462
+ before(:each) do
463
+ sample_swapinfo = <<SWAP
464
+ Device 1K-blocks Used Avail Capacity
465
+ /dev/da0p3 2048540 0 1048540 0%
466
+ /dev/da0p4 3048540 0 1048540 0%
467
+ SWAP
468
+ Facter::Util::Resolution.stubs(:exec).with('swapinfo -k').returns sample_swapinfo
469
+
470
+ Facter.collection.internal_loader.load(:memory)
471
+ end
472
+
473
+ it "should return the current swap free in MB" do
474
+ Facter.fact(:swapfree_mb).value.should == "2047.93"
475
+ end
476
+
477
+ it "should return the current swap size in MB" do
478
+ Facter.fact(:swapsize_mb).value.should == "4977.62"
479
+ end
480
+
481
+ it "should return the current memory size in MB" do
482
+ Facter.fact(:memorysize_mb).value.should == "1007.34"
483
+ end
484
+
485
+ it "should return the current memory free in MB" do
486
+ Facter.fact(:memoryfree_mb).value.should == "641.25"
487
+ end
488
+ end
489
+ end
144
490
 
145
- Facter.fact(:MemoryTotal).value.should == '3.91 GB'
491
+ describe "on Windows" do
492
+ before :each do
493
+ Facter.clear
494
+ Facter.fact(:kernel).stubs(:value).returns("windows")
495
+ Facter.collection.internal_loader.load(:memory)
496
+ require 'facter/util/wmi'
497
+ end
498
+
499
+ it "should return free memory in MB" do
500
+ os = stubs 'os'
501
+ os.stubs(:FreePhysicalMemory).returns("3415624")
502
+ Facter::Util::WMI.stubs(:execquery).returns([os])
503
+
504
+ Facter.fact(:memoryfree_mb).value.should == '3335.57'
505
+ end
506
+
507
+ it "should return total memory in MB" do
508
+ computer = stubs 'computer'
509
+ computer.stubs(:TotalPhysicalMemory).returns("4193837056")
510
+ Facter::Util::WMI.stubs(:execquery).returns([computer])
511
+
512
+ Facter.fact(:memorysize_mb).value.should == '3999.55'
513
+ Facter.fact(:MemoryTotal).value.should == '3.91 GB'
146
514
  end
147
515
  end
148
516
 
149
517
  it "should use the memorysize fact for the memorytotal fact" do
150
518
  Facter.fact("memorysize").expects(:value).once.returns "yay"
151
519
  Facter::Util::Resolution.expects(:exec).never
152
- Facter::Memory.expects(:meminfo_number).never
153
520
  Facter.fact("memorytotal").value.should == "yay"
154
521
  end
155
522
  end