|
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
|
|
3
|
require 'facter'
|
|
4
|
require 'facter/util/virtual'
|
|
5
|
require 'facter/util/macosx'
|
|
6
|
|
|
7
|
describe "Virtual fact" do
|
|
8
|
before do
|
|
9
|
Facter::Util::Virtual.stubs(:zone?).returns(false)
|
|
10
|
Facter::Util::Virtual.stubs(:openvz?).returns(false)
|
|
11
|
Facter::Util::Virtual.stubs(:vserver?).returns(false)
|
|
12
|
Facter::Util::Virtual.stubs(:xen?).returns(false)
|
|
13
|
Facter::Util::Virtual.stubs(:kvm?).returns(false)
|
|
14
|
Facter::Util::Virtual.stubs(:hpvm?).returns(false)
|
|
15
|
Facter::Util::Virtual.stubs(:zlinux?).returns(false)
|
|
16
|
end
|
|
17
|
|
|
18
|
it "should be zone on Solaris when a zone" do
|
|
19
|
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
|
20
|
Facter::Util::Virtual.stubs(:zone?).returns(true)
|
|
21
|
Facter::Util::Virtual.stubs(:vserver?).returns(false)
|
|
22
|
Facter::Util::Virtual.stubs(:xen?).returns(false)
|
|
23
|
Facter.fact(:virtual).value.should == "zone"
|
|
24
|
end
|
|
25
|
|
|
26
|
it "should be jail on FreeBSD when a jail in kvm" do
|
|
27
|
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
|
|
28
|
Facter::Util::Virtual.stubs(:jail?).returns(true)
|
|
29
|
Facter::Util::Virtual.stubs(:kvm?).returns(true)
|
|
30
|
Facter.fact(:virtual).value.should == "jail"
|
|
31
|
end
|
|
32
|
|
|
33
|
it "should be hpvm on HP-UX when in HP-VM" do
|
|
34
|
Facter.fact(:kernel).stubs(:value).returns("HP-UX")
|
|
35
|
Facter::Util::Virtual.stubs(:hpvm?).returns(true)
|
|
36
|
Facter.fact(:virtual).value.should == "hpvm"
|
|
37
|
end
|
|
38
|
|
|
39
|
it "should be zlinux on s390x" do
|
|
40
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
41
|
Facter.fact(:architecture).stubs(:value).returns("s390x")
|
|
42
|
Facter::Util::Virtual.stubs(:zlinux?).returns(true)
|
|
43
|
Facter.fact(:virtual).value.should == "zlinux"
|
|
44
|
end
|
|
45
|
|
|
46
|
describe "on Darwin" do
|
|
47
|
it "should be parallels with Parallels vendor id" do
|
|
48
|
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
|
49
|
Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x1ab8" })
|
|
50
|
Facter.fact(:virtual).value.should == "parallels"
|
|
51
|
end
|
|
52
|
|
|
53
|
it "should be parallels with Parallels vendor name" do
|
|
54
|
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
|
55
|
Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "Parallels" })
|
|
56
|
Facter.fact(:virtual).value.should == "parallels"
|
|
57
|
end
|
|
58
|
|
|
59
|
it "should be vmware with VMWare vendor id" do
|
|
60
|
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
|
61
|
Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x15ad" })
|
|
62
|
Facter.fact(:virtual).value.should == "vmware"
|
|
63
|
end
|
|
64
|
|
|
65
|
it "should be vmware with VMWare vendor name" do
|
|
66
|
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
|
67
|
Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "VMWare" })
|
|
68
|
Facter.fact(:virtual).value.should == "vmware"
|
|
69
|
end
|
|
70
|
end
|
|
71
|
|
|
72
|
describe "on Linux" do
|
|
73
|
|
|
74
|
before do
|
|
75
|
Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
|
|
76
|
Facter.fact(:operatingsystem).stubs(:value).returns(true)
|
|
77
|
|
|
78
|
FileTest.stubs(:exists?).with("/proc/sys/xen").returns false
|
|
79
|
FileTest.stubs(:exists?).with("/sys/bus/xen").returns false
|
|
80
|
FileTest.stubs(:exists?).with("/proc/xen").returns false
|
|
81
|
Facter.fact(:architecture).stubs(:value).returns(true)
|
|
82
|
end
|
|
83
|
|
|
84
|
it "should be parallels with Parallels vendor id from lspci" do
|
|
85
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
86
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005")
|
|
87
|
Facter.fact(:virtual).value.should == "parallels"
|
|
88
|
end
|
|
89
|
|
|
90
|
it "should be parallels with Parallels vendor name from lspci" do
|
|
91
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
92
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Parallels Display Adapter")
|
|
93
|
Facter.fact(:virtual).value.should == "parallels"
|
|
94
|
end
|
|
95
|
|
|
96
|
it "should be vmware with VMware vendor name from lspci" do
|
|
97
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
98
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter")
|
|
99
|
Facter.fact(:virtual).value.should == "vmware"
|
|
100
|
end
|
|
101
|
|
|
102
|
it "should be virtualbox with VirtualBox vendor name from lspci" do
|
|
103
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
104
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter")
|
|
105
|
Facter.fact(:virtual).value.should == "virtualbox"
|
|
106
|
end
|
|
107
|
|
|
108
|
it "should be vmware with VMWare vendor name from dmidecode" do
|
|
109
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
110
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
|
111
|
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device 1 Information\nType: Video\nStatus: Disabled\nDescription: VMware SVGA II")
|
|
112
|
Facter.fact(:virtual).value.should == "vmware"
|
|
113
|
end
|
|
114
|
|
|
115
|
it "should be xenhvm with Xen HVM vendor name from lspci" do
|
|
116
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
117
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:03.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01)")
|
|
118
|
Facter.fact(:virtual).value.should == "xenhvm"
|
|
119
|
end
|
|
120
|
|
|
121
|
it "should be xenhvm with Xen HVM vendor name from dmidecode" do
|
|
122
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
123
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
|
124
|
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Xen\nProduct Name: HVM domU")
|
|
125
|
Facter.fact(:virtual).value.should == "xenhvm"
|
|
126
|
end
|
|
127
|
|
|
128
|
it "should be parallels with Parallels vendor name from dmidecode" do
|
|
129
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
130
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
|
131
|
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device Information\nType: Video\nStatus: Disabled\nDescription: Parallels Video Adapter")
|
|
132
|
Facter.fact(:virtual).value.should == "parallels"
|
|
133
|
end
|
|
134
|
|
|
135
|
it "should be virtualbox with VirtualBox vendor name from dmidecode" do
|
|
136
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
137
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
|
138
|
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("BIOS Information\nVendor: innotek GmbH\nVersion: VirtualBox\n\nSystem Information\nManufacturer: innotek GmbH\nProduct Name: VirtualBox\nFamily: Virtual Machine")
|
|
139
|
Facter.fact(:virtual).value.should == "virtualbox"
|
|
140
|
end
|
|
141
|
|
|
142
|
it "should be hyperv with Microsoft vendor name from lspci" do
|
|
143
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
144
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA")
|
|
145
|
Facter.fact(:virtual).value.should == "hyperv"
|
|
146
|
end
|
|
147
|
|
|
148
|
it "should be hyperv with Microsoft vendor name from dmidecode" do
|
|
149
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
150
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
|
151
|
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Microsoft Corporation\nProduct Name: Virtual Machine")
|
|
152
|
Facter.fact(:virtual).value.should == "hyperv"
|
|
153
|
end
|
|
154
|
|
|
155
|
end
|
|
156
|
describe "on Solaris" do
|
|
157
|
before(:each) do
|
|
158
|
Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
|
|
159
|
end
|
|
160
|
|
|
161
|
it "should be vmware with VMWare vendor name from prtdiag" do
|
|
162
|
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
|
163
|
Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
|
|
164
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
|
165
|
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
|
|
166
|
Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform")
|
|
167
|
Facter.fact(:virtual).value.should == "vmware"
|
|
168
|
end
|
|
169
|
|
|
170
|
it "should be parallels with Parallels vendor name from prtdiag" do
|
|
171
|
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
|
172
|
Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
|
|
173
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
|
174
|
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
|
|
175
|
Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform")
|
|
176
|
Facter.fact(:virtual).value.should == "parallels"
|
|
177
|
end
|
|
178
|
|
|
179
|
it "should be virtualbox with VirtualBox vendor name from prtdiag" do
|
|
180
|
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
|
181
|
Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
|
|
182
|
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
|
183
|
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
|
|
184
|
Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox")
|
|
185
|
Facter.fact(:virtual).value.should == "virtualbox"
|
|
186
|
end
|
|
187
|
|
|
188
|
it "should be xen0 with xen dom0 files in /proc" do
|
|
189
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
190
|
Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
|
|
191
|
Facter.fact(:hardwaremodel).stubs(:value).returns("i386")
|
|
192
|
Facter::Util::Virtual.expects(:xen?).returns(true)
|
|
193
|
FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(true)
|
|
194
|
Facter.fact(:virtual).value.should == "xen0"
|
|
195
|
end
|
|
196
|
|
|
197
|
it "should be xenu with xen domU files in /proc" do
|
|
198
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
199
|
Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
|
|
200
|
Facter.fact(:hardwaremodel).stubs(:value).returns("i386")
|
|
201
|
Facter::Util::Virtual.expects(:xen?).returns(true)
|
|
202
|
FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(false)
|
|
203
|
FileTest.expects(:exists?).with("/proc/xen/capabilities").returns(true)
|
|
204
|
Facter.fact(:virtual).value.should == "xenu"
|
|
205
|
end
|
|
206
|
end
|
|
207
|
end
|
|
208
|
|
|
209
|
describe "is_virtual fact" do
|
|
210
|
|
|
211
|
it "should be virtual when running on xen" do
|
|
212
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
213
|
Facter.fact(:virtual).stubs(:value).returns("xenu")
|
|
214
|
Facter.fact(:is_virtual).value.should == "true"
|
|
215
|
end
|
|
216
|
|
|
217
|
it "should be false when running on xen0" do
|
|
218
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
219
|
Facter.fact(:virtual).stubs(:value).returns("xen0")
|
|
220
|
Facter.fact(:is_virtual).value.should == "false"
|
|
221
|
end
|
|
222
|
|
|
223
|
it "should be true when running on xenhvm" do
|
|
224
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
225
|
Facter.fact(:virtual).stubs(:value).returns("xenhvm")
|
|
226
|
Facter.fact(:is_virtual).value.should == "true"
|
|
227
|
end
|
|
228
|
|
|
229
|
it "should be false when running on physical" do
|
|
230
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
231
|
Facter.fact(:virtual).stubs(:value).returns("physical")
|
|
232
|
Facter.fact(:is_virtual).value.should == "false"
|
|
233
|
end
|
|
234
|
|
|
235
|
it "should be true when running on vmware" do
|
|
236
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
237
|
Facter.fact(:virtual).stubs(:value).returns("vmware")
|
|
238
|
Facter.fact(:is_virtual).value.should == "true"
|
|
239
|
end
|
|
240
|
|
|
241
|
it "should be true when running on virtualbox" do
|
|
242
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
243
|
Facter.fact(:virtual).stubs(:value).returns("virtualbox")
|
|
244
|
Facter.fact(:is_virtual).value.should == "true"
|
|
245
|
end
|
|
246
|
|
|
247
|
it "should be true when running on openvzve" do
|
|
248
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
249
|
Facter.fact(:virtual).stubs(:value).returns("openvzve")
|
|
250
|
Facter.fact(:is_virtual).value.should == "true"
|
|
251
|
end
|
|
252
|
|
|
253
|
it "should be true when running on kvm" do
|
|
254
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
255
|
Facter.fact(:virtual).stubs(:value).returns("kvm")
|
|
256
|
Facter.fact(:is_virtual).value.should == "true"
|
|
257
|
end
|
|
258
|
|
|
259
|
it "should be true when running in jail" do
|
|
260
|
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
|
|
261
|
Facter.fact(:virtual).stubs(:value).returns("jail")
|
|
262
|
Facter.fact(:is_virtual).value.should == "true"
|
|
263
|
end
|
|
264
|
|
|
265
|
it "should be true when running in zone" do
|
|
266
|
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
|
267
|
Facter.fact(:virtual).stubs(:value).returns("zone")
|
|
268
|
Facter.fact(:is_virtual).value.should == "true"
|
|
269
|
end
|
|
270
|
|
|
271
|
it "should be true when running on hp-vm" do
|
|
272
|
Facter.fact(:kernel).stubs(:value).returns("HP-UX")
|
|
273
|
Facter.fact(:virtual).stubs(:value).returns("hpvm")
|
|
274
|
Facter.fact(:is_virtual).value.should == "true"
|
|
275
|
end
|
|
276
|
|
|
277
|
it "should be true when running on S390" do
|
|
278
|
Facter.fact(:architecture).stubs(:value).returns("s390x")
|
|
279
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
280
|
Facter.fact(:virtual).stubs(:value).returns("zlinux")
|
|
281
|
Facter.fact(:is_virtual).value.should == "true"
|
|
282
|
end
|
|
283
|
|
|
284
|
it "should be true when running on parallels" do
|
|
285
|
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
|
286
|
Facter.fact(:virtual).stubs(:value).returns("parallels")
|
|
287
|
Facter.fact(:is_virtual).value.should == "true"
|
|
288
|
end
|
|
289
|
|
|
290
|
it "should be false on vmware_server" do
|
|
291
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
292
|
Facter.fact(:virtual).stubs(:value).returns("vmware_server")
|
|
293
|
Facter.fact(:is_virtual).value.should == "false"
|
|
294
|
end
|
|
295
|
|
|
296
|
it "should be false on openvz host nodes" do
|
|
297
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
298
|
Facter.fact(:virtual).stubs(:value).returns("openvzhn")
|
|
299
|
Facter.fact(:is_virtual).value.should == "false"
|
|
300
|
end
|
|
301
|
|
|
302
|
it "should be true when running on hyperv" do
|
|
303
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
304
|
Facter.fact(:virtual).stubs(:value).returns("hyperv")
|
|
305
|
Facter.fact(:is_virtual).value.should == "true"
|
|
306
|
end
|
|
307
|
end
|