ohai 15.0.35 → 15.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ohai.rb +4 -4
  3. data/lib/ohai/application.rb +3 -3
  4. data/lib/ohai/config.rb +2 -2
  5. data/lib/ohai/dsl.rb +2 -2
  6. data/lib/ohai/dsl/plugin.rb +5 -5
  7. data/lib/ohai/hints.rb +1 -1
  8. data/lib/ohai/loader.rb +4 -4
  9. data/lib/ohai/mixin/azure_metadata.rb +3 -3
  10. data/lib/ohai/mixin/command.rb +3 -3
  11. data/lib/ohai/mixin/do_metadata.rb +3 -3
  12. data/lib/ohai/mixin/ec2_metadata.rb +6 -6
  13. data/lib/ohai/mixin/gce_metadata.rb +3 -3
  14. data/lib/ohai/mixin/http_helper.rb +1 -1
  15. data/lib/ohai/mixin/scaleway_metadata.rb +3 -3
  16. data/lib/ohai/mixin/softlayer_metadata.rb +2 -2
  17. data/lib/ohai/plugin_config.rb +1 -1
  18. data/lib/ohai/plugins/aix/network.rb +6 -6
  19. data/lib/ohai/plugins/azure.rb +2 -2
  20. data/lib/ohai/plugins/bsd/virtualization.rb +2 -2
  21. data/lib/ohai/plugins/darwin/network.rb +14 -13
  22. data/lib/ohai/plugins/darwin/virtualization.rb +1 -1
  23. data/lib/ohai/plugins/digital_ocean.rb +2 -2
  24. data/lib/ohai/plugins/dmi.rb +3 -3
  25. data/lib/ohai/plugins/dragonflybsd/network.rb +9 -9
  26. data/lib/ohai/plugins/ec2.rb +2 -2
  27. data/lib/ohai/plugins/eucalyptus.rb +2 -2
  28. data/lib/ohai/plugins/filesystem.rb +5 -5
  29. data/lib/ohai/plugins/freebsd/network.rb +9 -9
  30. data/lib/ohai/plugins/gce.rb +2 -2
  31. data/lib/ohai/plugins/hostname.rb +2 -2
  32. data/lib/ohai/plugins/kernel.rb +1 -1
  33. data/lib/ohai/plugins/linux/fips.rb +1 -1
  34. data/lib/ohai/plugins/linux/network.rb +18 -18
  35. data/lib/ohai/plugins/linux/platform.rb +1 -3
  36. data/lib/ohai/plugins/linux/sessions.rb +2 -2
  37. data/lib/ohai/plugins/linux/virtualization.rb +2 -2
  38. data/lib/ohai/plugins/netbsd/network.rb +9 -9
  39. data/lib/ohai/plugins/network.rb +3 -3
  40. data/lib/ohai/plugins/openbsd/network.rb +9 -9
  41. data/lib/ohai/plugins/openstack.rb +2 -2
  42. data/lib/ohai/plugins/os.rb +1 -1
  43. data/lib/ohai/plugins/packages.rb +6 -8
  44. data/lib/ohai/plugins/passwd.rb +1 -1
  45. data/lib/ohai/plugins/scaleway.rb +2 -2
  46. data/lib/ohai/plugins/scsi.rb +1 -1
  47. data/lib/ohai/plugins/softlayer.rb +1 -1
  48. data/lib/ohai/plugins/solaris2/dmi.rb +2 -2
  49. data/lib/ohai/plugins/solaris2/network.rb +9 -9
  50. data/lib/ohai/plugins/solaris2/virtualization.rb +1 -1
  51. data/lib/ohai/plugins/uptime.rb +1 -1
  52. data/lib/ohai/plugins/virtualbox.rb +164 -19
  53. data/lib/ohai/plugins/windows/filesystem.rb +1 -1
  54. data/lib/ohai/plugins/windows/fips.rb +1 -1
  55. data/lib/ohai/plugins/windows/network.rb +3 -3
  56. data/lib/ohai/plugins/windows/virtualization.rb +2 -2
  57. data/lib/ohai/provides_map.rb +4 -4
  58. data/lib/ohai/runner.rb +1 -1
  59. data/lib/ohai/system.rb +15 -15
  60. data/lib/ohai/util/win32.rb +1 -1
  61. data/lib/ohai/version.rb +1 -1
  62. data/spec/unit/plugins/solaris2/network_spec.rb +10 -1
  63. data/spec/unit/plugins/vbox_host_spec.rb +14 -0
  64. data/spec/unit/plugins/virtualbox_spec.rb +310 -23
  65. metadata +3 -2
@@ -23,7 +23,7 @@ Ohai.plugin(:Filesystem) do
23
23
  #
24
24
  # @see https://docs.microsoft.com/en-us/windows/desktop/SecProv/getconversionstatus-win32-encryptablevolume#parameters
25
25
  #
26
- CONVERSION_STATUS = %w{FullyDecrypted FullyEncrypted EncryptionInProgress
26
+ CONVERSION_STATUS ||= %w{FullyDecrypted FullyEncrypted EncryptionInProgress
27
27
  DecryptionInProgress EncryptionPaused DecryptionPaused}.freeze
28
28
 
29
29
  # Returns a Mash loaded with logical details
@@ -28,7 +28,7 @@ Ohai.plugin(:Fips) do
28
28
  collect_data(:windows) do
29
29
  fips Mash.new
30
30
 
31
- require "openssl"
31
+ require "openssl" unless defined?(OpenSSL)
32
32
  if defined?(OpenSSL.fips_mode) && OpenSSL.fips_mode && !$FIPS_TEST_MODE
33
33
  fips["kernel"] = { "enabled" => true }
34
34
  else
@@ -120,13 +120,13 @@ Ohai.plugin(:Network) do
120
120
  iface_config = Mash.new
121
121
  iface_instance = Mash.new
122
122
  network Mash.new unless network
123
- network[:interfaces] = Mash.new unless network[:interfaces]
123
+ network[:interfaces] ||= Mash.new
124
124
  counters Mash.new unless counters
125
- counters[:network] = Mash.new unless counters[:network]
125
+ counters[:network] ||= Mash.new
126
126
 
127
127
  network_data[:addresses].each do |adapter|
128
128
  i = adapter["index"] || adapter["InterfaceIndex"]
129
- iface_config[i] = Mash.new unless iface_config[i]
129
+ iface_config[i] ||= Mash.new
130
130
  iface_config[i][:ip_address] ||= []
131
131
  iface_config[i][:ip_address] << adapter["IPAddress"]
132
132
 
@@ -20,14 +20,14 @@
20
20
 
21
21
  Ohai.plugin(:Virtualization) do
22
22
  provides "virtualization"
23
- require "ohai/mixin/dmi_decode"
23
+ require_relative "../../mixin/dmi_decode"
24
24
  include Ohai::Mixin::DmiDecode
25
25
 
26
26
  collect_data(:windows) do
27
27
  require "wmi-lite/wmi"
28
28
 
29
29
  virtualization Mash.new unless virtualization
30
- virtualization[:systems] = Mash.new unless virtualization[:systems]
30
+ virtualization[:systems] ||= Mash.new
31
31
 
32
32
  # Grab system DMI data from WMI to determine vendor information
33
33
  wmi = WmiLite::Wmi.new
@@ -17,10 +17,10 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require "ohai/mash"
21
- require "ohai/exception"
22
- require "ohai/mixin/os"
23
- require "ohai/dsl"
20
+ require_relative "mash"
21
+ require_relative "exception"
22
+ require_relative "mixin/os"
23
+ require_relative "dsl"
24
24
 
25
25
  module Ohai
26
26
  class ProvidesMap
@@ -17,7 +17,7 @@
17
17
  # limitations under the License
18
18
  #
19
19
 
20
- require "ohai/dsl"
20
+ require_relative "dsl"
21
21
  require "benchmark"
22
22
 
23
23
  module Ohai
@@ -16,21 +16,21 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "ohai/version"
20
- require "ohai/loader"
21
- require "ohai/log"
22
- require "ohai/mash"
23
- require "ohai/runner"
24
- require "ohai/dsl"
25
- require "ohai/mixin/command"
26
- require "ohai/mixin/os"
27
- require "ohai/mixin/string"
28
- require "ohai/mixin/constant_helper"
29
- require "ohai/provides_map"
30
- require "ohai/hints"
31
- require "mixlib/shellout"
32
- require "ohai/config"
33
- require "ffi_yajl"
19
+ require_relative "version"
20
+ require_relative "loader"
21
+ require_relative "log"
22
+ require_relative "mash"
23
+ require_relative "runner"
24
+ require_relative "dsl"
25
+ require_relative "mixin/command"
26
+ require_relative "mixin/os"
27
+ require_relative "mixin/string"
28
+ require_relative "mixin/constant_helper"
29
+ require_relative "provides_map"
30
+ require_relative "hints"
31
+ require "mixlib/shellout" unless defined?(Mixlib::ShellOut::DEFAULT_READ_TIMEOUT)
32
+ require_relative "config"
33
+ require "ffi_yajl" unless defined?(FFI_Yajl)
34
34
 
35
35
  module Ohai
36
36
  # The class used by Ohai::Application and Chef to actually collect data
@@ -21,7 +21,7 @@ module Ohai
21
21
  module Win32
22
22
  if RUBY_PLATFORM =~ /mswin|mingw|windows/
23
23
 
24
- require "ffi"
24
+ require "ffi" unless defined?(FFI)
25
25
 
26
26
  extend FFI::Library
27
27
 
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "15.0.35".freeze
21
+ VERSION = "15.1.3".freeze
22
22
  end
@@ -44,6 +44,9 @@ describe Ohai::System, "Solaris2.X network plugin" do
44
44
  ARP_RN
45
45
 
46
46
  @solaris_ifconfig = <<~ENDIFCONFIG
47
+ ipmp0: flags=108000000843<UP,BROADCAST,RUNNING,MULTICAST,IPMP,PHYSRUNNING> mtu 1500
48
+ inet 10.10.130.103 netmask fffffe00 broadcast 10.10.131.255
49
+ groupname ipmp0
47
50
  lo0:3: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
48
51
  inet 127.0.0.1 netmask ff000000
49
52
  e1000g0:3: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 3
@@ -143,7 +146,7 @@ describe Ohai::System, "Solaris2.X network plugin" do
143
146
  end
144
147
 
145
148
  it "detects the interfaces" do
146
- expect(@plugin["network"]["interfaces"].keys.sort).to eq(["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "ip6.tun0", "lo0", "lo0:3", "net0", "net1:1", "qfe1", "vni0"])
149
+ expect(@plugin["network"]["interfaces"].keys.sort).to eq(["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "ip6.tun0", "ipmp0", "lo0", "lo0:3", "net0", "net1:1", "qfe1", "vni0"])
147
150
  end
148
151
 
149
152
  it "detects the ip addresses of the interfaces" do
@@ -157,6 +160,12 @@ describe Ohai::System, "Solaris2.X network plugin" do
157
160
  it "detects the L3PROTECT network flag" do
158
161
  expect(@plugin["network"]["interfaces"]["net0"]["flags"]).to include("L3PROTECT")
159
162
  end
163
+
164
+ it "detects an interface with no index number" do
165
+ expect(@plugin["network"]["interfaces"]["ipmp0"]["index"]).to eq(nil)
166
+ expect(@plugin["network"]["interfaces"]["ipmp0"]["mtu"]).to eq("1500")
167
+ end
168
+
160
169
  end
161
170
 
162
171
  describe "gathering solaris 11 zone IP layer address info" do
@@ -0,0 +1,14 @@
1
+ # Author:: "Joshua Colson" <joshua.colson@gmail.com>
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
@@ -1,5 +1,5 @@
1
1
  # Author:: Tim Smith (<tsmith@chef.io>)
2
- # Copyright:: Copyright (c) 2015-2016 Chef Software, Inc.
2
+ # Copyright:: Copyright (c) 2015-2019 Chef Software, Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +17,255 @@
17
17
 
18
18
  require "spec_helper"
19
19
 
20
+ vbox_list_vms_stdout = <<~EOF
21
+ "ubuntu-18.04-amd64_1549746024485_35372" {6294f16b-4f05-4430-afb9-773bdb237aec}
22
+ EOF
23
+
24
+ vbox_vminfo_stdout = <<~EOF
25
+ name="ubuntu-18.04-amd64_1549746024485_35372"
26
+ groups="/"
27
+ ostype="Ubuntu (64-bit)"
28
+ UUID="6294f16b-4f05-4430-afb9-773bdb237aec"
29
+ CfgFile="/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64_1549746024485_35372.vbox"
30
+ SnapFldr="/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots"
31
+ LogFldr="/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Logs"
32
+ hardwareuuid="6294f16b-4f05-4430-afb9-773bdb237aec"
33
+ memory=1024
34
+ pagefusion="off"
35
+ vram=8
36
+ cpuexecutioncap=100
37
+ hpet="off"
38
+ chipset="piix3"
39
+ firmware="BIOS"
40
+ cpus=1
41
+ pae="on"
42
+ longmode="on"
43
+ triplefaultreset="off"
44
+ apic="on"
45
+ x2apic="on"
46
+ cpuid-portability-level=0
47
+ bootmenu="messageandmenu"
48
+ boot1="disk"
49
+ boot2="dvd"
50
+ boot3="none"
51
+ boot4="none"
52
+ acpi="on"
53
+ ioapic="on"
54
+ biosapic="apic"
55
+ biossystemtimeoffset=0
56
+ rtcuseutc="off"
57
+ hwvirtex="on"
58
+ nestedpaging="on"
59
+ largepages="on"
60
+ vtxvpid="on"
61
+ vtxux="on"
62
+ paravirtprovider="default"
63
+ effparavirtprovider="kvm"
64
+ VMState="poweroff"
65
+ VMStateChangeTime="2019-02-09T21:00:33.575000000"
66
+ monitorcount=1
67
+ accelerate3d="off"
68
+ accelerate2dvideo="off"
69
+ teleporterenabled="off"
70
+ teleporterport=0
71
+ teleporteraddress=""
72
+ teleporterpassword=""
73
+ tracing-enabled="off"
74
+ tracing-allow-vm-access="off"
75
+ tracing-config=""
76
+ autostart-enabled="off"
77
+ autostart-delay=0
78
+ defaultfrontend=""
79
+ storagecontrollername0="IDE Controller"
80
+ storagecontrollertype0="PIIX4"
81
+ storagecontrollerinstance0="0"
82
+ storagecontrollermaxportcount0="2"
83
+ storagecontrollerportcount0="2"
84
+ storagecontrollerbootable0="on"
85
+ storagecontrollername1="SATA Controller"
86
+ storagecontrollertype1="IntelAhci"
87
+ storagecontrollerinstance1="0"
88
+ storagecontrollermaxportcount1="30"
89
+ storagecontrollerportcount1="1"
90
+ storagecontrollerbootable1="on"
91
+ "IDE Controller-0-0"="none"
92
+ "IDE Controller-0-1"="none"
93
+ "IDE Controller-1-0"="none"
94
+ "IDE Controller-1-1"="none"
95
+ "SATA Controller-0-0"="/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk"
96
+ "SATA Controller-ImageUUID-0-0"="1c182745-4b09-41a1-a147-d3ced46f72f6"
97
+ natnet1="nat"
98
+ macaddress1="080027E5FA8F"
99
+ cableconnected1="on"
100
+ nic1="nat"
101
+ nictype1="82540EM"
102
+ nicspeed1="0"
103
+ mtu="0"
104
+ sockSnd="64"
105
+ sockRcv="64"
106
+ tcpWndSnd="64"
107
+ tcpWndRcv="64"
108
+ nic2="none"
109
+ nic3="none"
110
+ nic4="none"
111
+ nic5="none"
112
+ nic6="none"
113
+ nic7="none"
114
+ nic8="none"
115
+ hidpointing="ps2mouse"
116
+ hidkeyboard="ps2kbd"
117
+ uart1="off"
118
+ uart2="off"
119
+ uart3="off"
120
+ uart4="off"
121
+ lpt1="off"
122
+ lpt2="off"
123
+ audio="pulse"
124
+ audio_in="false"
125
+ audio_out="false"
126
+ clipboard="disabled"
127
+ draganddrop="disabled"
128
+ vrde="on"
129
+ vrdeport=-1
130
+ vrdeports="5947"
131
+ vrdeaddress="127.0.0.1"
132
+ vrdeauthtype="null"
133
+ vrdemulticon="off"
134
+ vrdereusecon="off"
135
+ vrdevideochannel="off"
136
+ vrdeproperty[TCP/Ports]="5947"
137
+ vrdeproperty[TCP/Address]="127.0.0.1"
138
+ usb="off"
139
+ ehci="off"
140
+ xhci="off"
141
+ GuestMemoryBalloon=0
142
+ SnapshotName="base"
143
+ SnapshotUUID="085cbbec-70cd-4864-9208-5d938dcabb71"
144
+ CurrentSnapshotName="base"
145
+ CurrentSnapshotUUID="085cbbec-70cd-4864-9208-5d938dcabb71"
146
+ CurrentSnapshotNode="SnapshotName"
147
+ EOF
148
+
149
+ vbox_list_hdds_stdout = <<~EOF
150
+ UUID: ebb6dca0-879f-480b-a50e-9efe330bd021
151
+ Parent UUID: base
152
+ State: locked read
153
+ Type: normal (base)
154
+ Location: /virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64-disk001.vmdk
155
+ Storage format: VMDK
156
+ Capacity: 65536 MBytes
157
+ Encryption: disabled
158
+
159
+ UUID: 1c182745-4b09-41a1-a147-d3ced46f72f6
160
+ Parent UUID: ebb6dca0-879f-480b-a50e-9efe330bd021
161
+ State: created
162
+ Type: normal (differencing)
163
+ Location: /virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk
164
+ Storage format: VMDK
165
+ Capacity: 65536 MBytes
166
+ Encryption: disabled
167
+
168
+ EOF
169
+
170
+ vbox_list_dvds_stdout = <<~EOF
171
+ UUID: 897aa7bc-1ec1-4e13-a16d-101d3716c72d
172
+ State: created
173
+ Type: normal (base)
174
+ Location: /tmp/test.dvd
175
+ Storage format: RAW
176
+ Capacity: 100 MBytes
177
+ Encryption: disabled
178
+
179
+ EOF
180
+
181
+ vbox_list_hostdvds_stdout = <<~EOF
182
+ UUID: 00445644-0000-0000-2f64-65762f737230
183
+ Name: /dev/sr0
184
+
185
+ EOF
186
+
187
+ vbox_list_hostfloppies_stdout = <<~EOF
188
+
189
+ EOF
190
+
191
+ vbox_list_hostonlyifs_stdout = <<~EOF
192
+ Name: vboxnet0
193
+ GUID: 786f6276-656e-4074-8000-0a0027000000
194
+ DHCP: Disabled
195
+ IPAddress: 192.168.33.1
196
+ NetworkMask: 255.255.255.0
197
+ IPV6Address:
198
+ IPV6NetworkMaskPrefixLength: 0
199
+ HardwareAddress: 0a:00:27:00:00:00
200
+ MediumType: Ethernet
201
+ Wireless: No
202
+ Status: Down
203
+ VBoxNetworkName: HostInterfaceNetworking-vboxnet0
204
+
205
+ Name: vboxnet1
206
+ GUID: 786f6276-656e-4174-8000-0a0027000001
207
+ DHCP: Disabled
208
+ IPAddress: 192.168.19.1
209
+ NetworkMask: 255.255.255.0
210
+ IPV6Address: fe80::800:27ff:fe00:1
211
+ IPV6NetworkMaskPrefixLength: 64
212
+ HardwareAddress: 0a:00:27:00:00:01
213
+ MediumType: Ethernet
214
+ Wireless: No
215
+ Status: Up
216
+ VBoxNetworkName: HostInterfaceNetworking-vboxnet1
217
+
218
+ EOF
219
+
220
+ vbox_list_bridgedifs_stdout = <<~EOF
221
+ Name: eno1
222
+ GUID: 316f6e65-0000-4000-8000-309c233b62a9
223
+ DHCP: Disabled
224
+ IPAddress: 10.143.72.133
225
+ NetworkMask: 255.255.255.224
226
+ IPV6Address: fe80::9226:82e9:1101:60e6
227
+ IPV6NetworkMaskPrefixLength: 64
228
+ HardwareAddress: 30:9c:23:3b:62:a9
229
+ MediumType: Ethernet
230
+ Wireless: No
231
+ Status: Up
232
+ VBoxNetworkName: HostInterfaceNetworking-eno1
233
+
234
+ EOF
235
+
236
+ vbox_list_dhcpservers_stdout = <<~EOF
237
+ NetworkName: HostInterfaceNetworking-vboxnet0
238
+ IP: 192.168.56.100
239
+ NetworkMask: 255.255.255.0
240
+ lowerIPAddress: 192.168.56.101
241
+ upperIPAddress: 192.168.56.254
242
+ Enabled: Yes
243
+
244
+ NetworkName: HostInterfaceNetworking-vboxnet1
245
+ IP: 192.168.19.2
246
+ NetworkMask: 255.255.255.0
247
+ lowerIPAddress: 192.168.19.3
248
+ upperIPAddress: 192.168.19.254
249
+ Enabled: Yes
250
+
251
+ EOF
252
+
253
+ # output of: VBoxManage list --sorted natnets
254
+ vbox_list_natnets_stdout = <<~EOF
255
+ NetworkName: NatNetwork
256
+ IP: 10.0.2.1
257
+ Network: 10.0.2.0/24
258
+ IPv6 Enabled: No
259
+ IPv6 Prefix: fd17:625c:f037:2::/64
260
+ DHCP Enabled: Yes
261
+ Enabled: Yes
262
+ loopback mappings (ipv4)
263
+ 127.0.0.1=2
264
+
265
+ EOF
266
+
267
+ expected_output = { "guests" => { "ubuntu-18.04-amd64_1549746024485_35372" => { "groups" => "/", "ostype" => "Ubuntu (64-bit)", "uuid" => "6294f16b-4f05-4430-afb9-773bdb237aec", "cfgfile" => "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64_1549746024485_35372.vbox", "snapfldr" => "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots", "logfldr" => "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Logs", "hardwareuuid" => "6294f16b-4f05-4430-afb9-773bdb237aec", "memory" => "1024", "pagefusion" => "off", "vram" => "8", "cpuexecutioncap" => "100", "hpet" => "off", "chipset" => "piix3", "firmware" => "BIOS", "cpus" => "1", "pae" => "on", "longmode" => "on", "triplefaultreset" => "off", "apic" => "on", "x2apic" => "on", "cpuid-portability-level" => "0", "bootmenu" => "messageandmenu", "boot1" => "disk", "boot2" => "dvd", "boot3" => "none", "boot4" => "none", "acpi" => "on", "ioapic" => "on", "biosapic" => "apic", "biossystemtimeoffset" => "0", "rtcuseutc" => "off", "hwvirtex" => "on", "nestedpaging" => "on", "largepages" => "on", "vtxvpid" => "on", "vtxux" => "on", "paravirtprovider" => "default", "effparavirtprovider" => "kvm", "vmstate" => "poweroff", "vmstatechangetime" => "2019-02-09T21:00:33.575000000", "monitorcount" => "1", "accelerate3d" => "off", "accelerate2dvideo" => "off", "teleporterenabled" => "off", "teleporterport" => "0", "teleporteraddress" => "", "teleporterpassword" => "", "tracing-enabled" => "off", "tracing-allow-vm-access" => "off", "tracing-config" => "", "autostart-enabled" => "off", "autostart-delay" => "0", "defaultfrontend" => "", "storagecontrollername0" => "IDE Controller", "storagecontrollertype0" => "PIIX4", "storagecontrollerinstance0" => "0", "storagecontrollermaxportcount0" => "2", "storagecontrollerportcount0" => "2", "storagecontrollerbootable0" => "on", "storagecontrollername1" => "SATA Controller", "storagecontrollertype1" => "IntelAhci", "storagecontrollerinstance1" => "0", "storagecontrollermaxportcount1" => "30", "storagecontrollerportcount1" => "1", "storagecontrollerbootable1" => "on", "ide controller-0-0" => "none", "ide controller-0-1" => "none", "ide controller-1-0" => "none", "ide controller-1-1" => "none", "sata controller-0-0" => "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk", "sata controller-imageuuid-0-0" => "1c182745-4b09-41a1-a147-d3ced46f72f6", "natnet1" => "nat", "macaddress1" => "080027E5FA8F", "cableconnected1" => "on", "nic1" => "nat", "nictype1" => "82540EM", "nicspeed1" => "0", "mtu" => "0", "socksnd" => "64", "sockrcv" => "64", "tcpwndsnd" => "64", "tcpwndrcv" => "64", "nic2" => "none", "nic3" => "none", "nic4" => "none", "nic5" => "none", "nic6" => "none", "nic7" => "none", "nic8" => "none", "hidpointing" => "ps2mouse", "hidkeyboard" => "ps2kbd", "uart1" => "off", "uart2" => "off", "uart3" => "off", "uart4" => "off", "lpt1" => "off", "lpt2" => "off", "audio" => "pulse", "audio_in" => "false", "audio_out" => "false", "clipboard" => "disabled", "draganddrop" => "disabled", "vrde" => "on", "vrdeport" => "-1", "vrdeports" => "5947", "vrdeaddress" => "127.0.0.1", "vrdeauthtype" => "null", "vrdemulticon" => "off", "vrdereusecon" => "off", "vrdevideochannel" => "off", "vrdeproperty[tcp/ports]" => "5947", "vrdeproperty[tcp/address]" => "127.0.0.1", "usb" => "off", "ehci" => "off", "xhci" => "off", "guestmemoryballoon" => "0", "snapshotname" => "base", "snapshotuuid" => "085cbbec-70cd-4864-9208-5d938dcabb71", "currentsnapshotname" => "base", "currentsnapshotuuid" => "085cbbec-70cd-4864-9208-5d938dcabb71", "currentsnapshotnode" => "SnapshotName" } }, "hdds" => { "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64-disk001.vmdk" => { "uuid" => "ebb6dca0-879f-480b-a50e-9efe330bd021", "parent uuid" => "base", "state" => "locked read", "type" => "normal (base)", "storage format" => "VMDK", "capacity" => "65536 MBytes", "encryption" => "disabled" }, "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk" => { "uuid" => "1c182745-4b09-41a1-a147-d3ced46f72f6", "parent uuid" => "ebb6dca0-879f-480b-a50e-9efe330bd021", "state" => "created", "type" => "normal (differencing)", "storage format" => "VMDK", "capacity" => "65536 MBytes", "encryption" => "disabled" } }, "dvds" => { "/tmp/test.dvd" => { "uuid" => "897aa7bc-1ec1-4e13-a16d-101d3716c72d", "state" => "created", "type" => "normal (base)", "storage format" => "RAW", "capacity" => "100 MBytes", "encryption" => "disabled" } }, "hostdvds" => { "/dev/sr0" => { "uuid" => "00445644-0000-0000-2f64-65762f737230" } }, "hostfloppies" => {}, "hostonlyifs" => { "vboxnet0" => { "guid" => "786f6276-656e-4074-8000-0a0027000000", "dhcp" => "Disabled", "ipaddress" => "192.168.33.1", "networkmask" => "255.255.255.0", "ipv6address" => "", "ipv6networkmaskprefixlength" => "0", "hardwareaddress" => "0a:00:27:00:00:00", "mediumtype" => "Ethernet", "wireless" => "No", "status" => "Down", "vboxnetworkname" => "HostInterfaceNetworking-vboxnet0" }, "vboxnet1" => { "guid" => "786f6276-656e-4174-8000-0a0027000001", "dhcp" => "Disabled", "ipaddress" => "192.168.19.1", "networkmask" => "255.255.255.0", "ipv6address" => "fe80::800:27ff:fe00:1", "ipv6networkmaskprefixlength" => "64", "hardwareaddress" => "0a:00:27:00:00:01", "mediumtype" => "Ethernet", "wireless" => "No", "status" => "Up", "vboxnetworkname" => "HostInterfaceNetworking-vboxnet1" } }, "bridgedifs" => { "eno1" => { "guid" => "316f6e65-0000-4000-8000-309c233b62a9", "dhcp" => "Disabled", "ipaddress" => "10.143.72.133", "networkmask" => "255.255.255.224", "ipv6address" => "fe80::9226:82e9:1101:60e6", "ipv6networkmaskprefixlength" => "64", "hardwareaddress" => "30:9c:23:3b:62:a9", "mediumtype" => "Ethernet", "wireless" => "No", "status" => "Up", "vboxnetworkname" => "HostInterfaceNetworking-eno1" } }, "dhcpservers" => { "HostInterfaceNetworking-vboxnet0" => { "ip" => "192.168.56.100", "networkmask" => "255.255.255.0", "loweripaddress" => "192.168.56.101", "upperipaddress" => "192.168.56.254", "enabled" => "Yes" }, "HostInterfaceNetworking-vboxnet1" => { "ip" => "192.168.19.2", "networkmask" => "255.255.255.0", "loweripaddress" => "192.168.19.3", "upperipaddress" => "192.168.19.254", "enabled" => "Yes" } }, "natnets" => { "NatNetwork" => { "ip" => "10.0.2.1", "network" => "10.0.2.0/24", "ipv6 enabled" => "No", "ipv6 prefix" => "fd17:625c:f037:2::/64", "dhcp enabled" => "Yes", "enabled" => "Yes" } } }
268
+
20
269
  vbox_output = <<~EOF
21
270
  Oracle VM VirtualBox Guest Additions Command Line Management Interface Version 5.0.2
22
271
  (C) 2008-2015 Oracle Corporation
@@ -48,41 +297,79 @@ vbox_output = <<~EOF
48
297
  EOF
49
298
 
50
299
  describe Ohai::System, "plugin virtualbox" do
51
- context "when VBoxControl shellout fails" do
300
+ let(:plugin) { get_plugin("virtualbox") }
301
+
302
+ before(:each) do
303
+ plugin[:virtualization] = Mash.new
304
+ plugin[:virtualization][:systems] = Mash.new
305
+ end
306
+
307
+ context "when not on a virtualbox guest" do
52
308
  it "should not set the virtualbox attribute" do
53
- plugin = get_plugin("virtualbox")
54
- allow(plugin).to receive(:shell_out).with("VBoxControl guestproperty enumerate").and_return(mock_shell_out(1, "", ""))
309
+ plugin[:virtualization][:systems][:vmware] = "host"
55
310
  plugin.run
56
311
  expect(plugin).not_to have_key(:virtualbox)
57
312
  end
58
313
  end
59
314
 
60
- context "when VBoxControl shellout succeeds" do
61
- let(:plugin) { get_plugin("virtualbox") }
62
-
63
- before(:each) do
64
- allow(plugin).to receive(:shell_out).with("VBoxControl guestproperty enumerate").and_return(mock_shell_out(0, vbox_output, ""))
65
- plugin.run
315
+ context "when on a vbox guest" do
316
+ context "when VBoxControl shellout fails" do
317
+ it "should not set the virtualbox attribute" do
318
+ plugin[:virtualization][:systems][:vbox] = "guest"
319
+ allow(plugin).to receive(:shell_out).with("VBoxControl guestproperty enumerate").and_return(mock_shell_out(1, "", ""))
320
+ plugin.run
321
+ expect(plugin).not_to have_key(:virtualbox)
322
+ end
66
323
  end
67
324
 
68
- it "should set the host version" do
69
- expect(plugin[:virtualbox][:host][:version]).to eql("5.0.10")
70
- end
325
+ context "when VBoxControl shellout succeeds" do
326
+ before(:each) do
327
+ plugin[:virtualization][:systems][:vbox] = "guest"
328
+ allow(plugin).to receive(:shell_out).with("VBoxControl guestproperty enumerate").and_return(mock_shell_out(0, vbox_output, ""))
329
+ plugin.run
330
+ end
71
331
 
72
- it "should set the host revision" do
73
- expect(plugin[:virtualbox][:host][:revision]).to eql("104061")
74
- end
332
+ it "should set the host version" do
333
+ expect(plugin[:virtualbox][:host][:version]).to eql("5.0.10")
334
+ end
75
335
 
76
- it "should set the host language" do
77
- expect(plugin[:virtualbox][:host][:language]).to eql("en_US")
78
- end
336
+ it "should set the host revision" do
337
+ expect(plugin[:virtualbox][:host][:revision]).to eql("104061")
338
+ end
339
+
340
+ it "should set the host language" do
341
+ expect(plugin[:virtualbox][:host][:language]).to eql("en_US")
342
+ end
79
343
 
80
- it "should set the guest additions version" do
81
- expect(plugin[:virtualbox][:guest][:guest_additions_version]).to eql("5.0.2")
344
+ it "should set the guest additions version" do
345
+ expect(plugin[:virtualbox][:guest][:guest_additions_version]).to eql("5.0.2")
346
+ end
347
+
348
+ it "should set the guest additions revision" do
349
+ expect(plugin[:virtualbox][:guest][:guest_additions_revision]).to eql("102096")
350
+ end
82
351
  end
352
+ end
83
353
 
84
- it "should set the guest additions revision" do
85
- expect(plugin[:virtualbox][:guest][:guest_additions_revision]).to eql("102096")
354
+ context "when on a vbox host" do
355
+ context "if the host has virtualbox installed" do
356
+ it "should create a vbox attribute with accurate data" do
357
+ plugin[:virtualization][:systems][:vbox] = "host"
358
+ allow(plugin).to receive(:which).with("VBoxManage").and_return("/usr/bin/VBoxManage")
359
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted vms").and_return(mock_shell_out(0, vbox_list_vms_stdout, ""))
360
+ allow(plugin).to receive(:shell_out).with("VBoxManage showvminfo 6294f16b-4f05-4430-afb9-773bdb237aec --machinereadable").and_return(mock_shell_out(0, vbox_vminfo_stdout, ""))
361
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hdds").and_return(mock_shell_out(0, vbox_list_hdds_stdout, ""))
362
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted dvds").and_return(mock_shell_out(0, vbox_list_dvds_stdout, ""))
363
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostdvds").and_return(mock_shell_out(0, vbox_list_hostdvds_stdout, ""))
364
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostfloppies").and_return(mock_shell_out(0, vbox_list_hostfloppies_stdout, ""))
365
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostonlyifs").and_return(mock_shell_out(0, vbox_list_hostonlyifs_stdout, ""))
366
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted bridgedifs").and_return(mock_shell_out(0, vbox_list_bridgedifs_stdout, ""))
367
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted dhcpservers").and_return(mock_shell_out(0, vbox_list_dhcpservers_stdout, ""))
368
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted natnets").and_return(mock_shell_out(0, vbox_list_natnets_stdout, ""))
369
+ plugin.run
370
+ expect(plugin).to have_key(:virtualbox)
371
+ expect(plugin[:virtualbox]).to eq(expected_output)
372
+ end
86
373
  end
87
374
  end
88
375
  end