summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colson <joshua.colson@gmail.com>2019-02-17 19:33:16 -0700
committerJoshua Colson <joshua.colson@gmail.com>2019-02-17 19:33:16 -0700
commit722f280745a55fe7bc938165f27f2bc6adb04974 (patch)
tree1f53fbddd460a3720d6666418e1d7b668ed75353
parent2e1a35b6ecefe54bb9331d17e27420d0191a569c (diff)
downloadohai-722f280745a55fe7bc938165f27f2bc6adb04974.tar.gz
cleaned up to support rspec, and added rspec tests
Signed-off-by: Joshua Colson <joshua.colson@gmail.com>
-rw-r--r--lib/ohai/plugins/vbox_host.rb166
-rw-r--r--spec/unit/plugins/vbox_host_spec.rb331
2 files changed, 420 insertions, 77 deletions
diff --git a/lib/ohai/plugins/vbox_host.rb b/lib/ohai/plugins/vbox_host.rb
index a2b0640c..edb31f2a 100644
--- a/lib/ohai/plugins/vbox_host.rb
+++ b/lib/ohai/plugins/vbox_host.rb
@@ -16,7 +16,7 @@
Ohai.plugin(:VboxHost) do
depends 'virtualization'
- provides 'virtualization/vbox'
+ provides 'vbox'
# determine if this host is configured with virtualbox or not
# the determination is ultimately controlled by the 'virtualization' plugin
@@ -33,17 +33,19 @@ Ohai.plugin(:VboxHost) do
def vboxmanage_list_vms
vms = Mash.new
if vbox_host?
- so = shell_out('VBoxManage list --sorted vms')
- # raise an exception if the command fails
- so.error!
-
- # parse the output
- so.stdout.lines.each do |line|
- case line
- when /^"(\S*)" \{(\S*)\}$/
- name = Regexp.last_match(1)
- uuid = Regexp.last_match(2)
- vms[name] = vboxmanage_vminfo(uuid)
+ so_cmd = 'VBoxManage list --sorted vms'
+ logger.trace(so_cmd)
+ so = shell_out(so_cmd)
+
+ if so.exitstatus == 0
+ # parse the output
+ so.stdout.lines.each do |line|
+ case line
+ when /^"(\S*)" \{(\S*)\}$/
+ name = Regexp.last_match(1)
+ uuid = Regexp.last_match(2)
+ vms[name] = vboxmanage_vminfo(uuid)
+ end
end
end
end
@@ -58,41 +60,43 @@ Ohai.plugin(:VboxHost) do
vm = Mash.new
if vbox_host?
- so = shell_out("VBoxManage showvminfo #{machine_id} --machinereadable")
- # raise an exception if the command fails
- so.error!
-
- so.stdout.lines.each do |line|
- line.chomp!
- left, right = line.split('=')
-
- # remove enclosing quotes, if needed
- key =
- case left
- when /^"(.*)"$/
- Regexp.last_match(1)
- else
- left
- end
-
- # skip the name attribute since that is the parent key
- next if left == 'name'
-
- # remove enclosing quotes, if needed
- value =
- case right
- when /^"(.*)"$/
- Regexp.last_match(1)
- else
- right
- end
-
- vm[key.downcase] = value
+ so_cmd = "VBoxManage showvminfo #{machine_id} --machinereadable"
+ logger.trace(so_cmd)
+ so = shell_out(so_cmd)
+
+ if so.exitstatus == 0
+ so.stdout.lines.each do |line|
+ line.chomp!
+ left, right = line.split('=')
+
+ # remove enclosing quotes, if needed
+ key =
+ case left
+ when /^"(.*)"$/
+ Regexp.last_match(1)
+ else
+ left
+ end
+
+ # skip the name attribute since that is the parent key
+ next if left == 'name'
+
+ # remove enclosing quotes, if needed
+ value =
+ case right
+ when /^"(.*)"$/
+ Regexp.last_match(1)
+ else
+ right
+ end
+
+ vm[key.downcase] = value
+ end
end
end
vm
rescue Ohai::Exceptions::Exec
- logger.trace("Plugin VboxHost: Could not run 'VBoxManage showvminfo #{machine_id} --machinereadable'. Skipping data")
+ logger.trace("Plugin VboxHost: Could not run '#{so_cmd}'. Skipping data")
end
# query virtualbox for a list of #{query_type} items
@@ -110,40 +114,46 @@ Ohai.plugin(:VboxHost) do
results = Mash.new
if vbox_host?
- so = shell_out("VBoxManage list --sorted #{query_type}")
+ so_cmd = "VBoxManage list --sorted #{query_type}"
+ logger.trace(so_cmd)
+ so = shell_out(so_cmd)
# raise an exception if the command fails
- so.error!
-
- # break the result into paragraph blocks, on successive newlines
- so.stdout.each_line('') do |blk|
- # remove the multiple newlines of each record
- blk.chomp!.chomp!
- # initialize a blank record hash
- record = Mash.new
- # parse the record block into key/value pairs
- blk.each_line() do |line|
- # split the line into key/value pair
- key, right = line.split(':')
- # strip the leading/trailing whitespace if the value is not nil
- value = right.nil? ? '' : right.strip
- record[key.downcase] = value
- end
+ # so.error!
+
+ if so.exitstatus == 0
+ # break the result into paragraph blocks, on successive newlines
+ so.stdout.each_line('') do |blk|
+ # remove the multiple newlines of each record
+ blk.chomp!.chomp!
+ # initialize a blank record hash
+ record = Mash.new
+ # parse the record block into key/value pairs
+ blk.each_line() do |line|
+ next unless line.include? ':'
+ # split the line into key/value pair
+ key, right = line.split(':', 2)
+
+ # strip the leading/trailing whitespace if the value is not nil
+ value = right.nil? ? '' : right.strip
+ record[key.downcase] = value
+ end
- # compile the block of data into the Mash
- if record.key? name_key.downcase
- name = record.delete(name_key.downcase)
- results[name] = record
+ # insert the record into the list of results
+ if record.key? name_key.downcase
+ name = record.delete(name_key.downcase)
+ results[name] = record
+ end
end
end
end
results
rescue Ohai::Exceptions::Exec
- logger.trace("Plugin VboxHost: Could not run 'VBoxManage list --sorted #{query_type}'. Skipping data")
+ logger.trace("Plugin VboxHost: Could not run '#{so_cmd}'. Skipping data")
end
# collect the data for a virtualization host running VirtualBox
collect_data(:default) do
- vbox = 'vbox'
+ # vbox = Mash.new
ostypes = 'ostypes'
guests = 'guests'
natnets = 'natnets'
@@ -156,38 +166,40 @@ Ohai.plugin(:VboxHost) do
hostfloppies = 'hostfloppies'
if vbox_host?
- virtualization[vbox] = Mash.new unless virtualization[vbox]
+ # virtualization[vbox] = Mash.new unless virtualization[vbox]
+ vbox Mash.new unless vbox
# get a list of virtualbox virtual hard disk drives
- virtualization[vbox][ostypes] = vboxmanage_list_blocks(ostypes, 'ID')
+ vbox[ostypes] = vboxmanage_list_blocks(ostypes, 'ID')
# get a list of virtualbox guest vms
- virtualization[vbox][guests] = vboxmanage_list_vms
+ vbox[guests] = vboxmanage_list_vms
# get a list of virtualbox virtual hard disk drives
- virtualization[vbox][hdds] = vboxmanage_list_blocks(hdds, 'UUID')
+ vbox[hdds] = vboxmanage_list_blocks(hdds, 'Location')
# get a list of virtualbox virtual dvd drives
- virtualization[vbox][dvds] = vboxmanage_list_blocks(dvds, 'UUID')
+ vbox[dvds] = vboxmanage_list_blocks(dvds, 'Location')
# get a list of virtualbox host dvd drives
- virtualization[vbox][hostdvds] = vboxmanage_list_blocks(hostdvds, 'Name')
+ vbox[hostdvds] = vboxmanage_list_blocks(hostdvds, 'Name')
# get a list of virtualbox host floppy drives
- virtualization[vbox][hostfloppies] = vboxmanage_list_blocks(hostfloppies, 'Name')
+ vbox[hostfloppies] = vboxmanage_list_blocks(hostfloppies, 'Name')
# get a list of virtualbox hostonly network interfaces
- virtualization[vbox][hostonlyifs] = vboxmanage_list_blocks(hostonlyifs, 'Name')
+ vbox[hostonlyifs] = vboxmanage_list_blocks(hostonlyifs, 'Name')
# get a list of virtualbox bridged network interfaces
- virtualization[vbox][bridgedifs] = vboxmanage_list_blocks(bridgedifs, 'Name')
+ vbox[bridgedifs] = vboxmanage_list_blocks(bridgedifs, 'Name')
# get a list of virtualbox dhcp servers
- virtualization[vbox][dhcpservers] = vboxmanage_list_blocks(dhcpservers, 'NetworkName')
+ vbox[dhcpservers] = vboxmanage_list_blocks(dhcpservers, 'NetworkName')
# get a list of virtualbox nat networks
- virtualization[vbox][natnets] = vboxmanage_list_blocks(natnets, 'NetworkName')
+ vbox[natnets] = vboxmanage_list_blocks(natnets, 'NetworkName')
end
+ vbox
rescue Ohai::Exceptions::Exec
logger.trace('Plugin VboxHost: Could not collect data for VirtualBox host. Skipping data')
end
diff --git a/spec/unit/plugins/vbox_host_spec.rb b/spec/unit/plugins/vbox_host_spec.rb
new file mode 100644
index 00000000..725a1ac8
--- /dev/null
+++ b/spec/unit/plugins/vbox_host_spec.rb
@@ -0,0 +1,331 @@
+# Author:: "Joshua Colson" <joshua.colson@gmail.com>
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require_relative "../../spec_helper.rb"
+
+vbox_list_ostypes_stdout = <<~EOF
+ID: Other
+Description: Other/Unknown
+Family ID: Other
+Family Desc: Other
+64 bit: false
+
+ID: Other_64
+Description: Other/Unknown (64-bit)
+Family ID: Other
+Family Desc: Other
+64 bit: true
+
+ID: Windows31
+Description: Windows 3.1
+Family ID: Windows
+Family Desc: Microsoft Windows
+64 bit: false
+
+EOF
+
+vbox_list_vms_stdout = <<~EOF
+"ubuntu-18.04-amd64_1549746024485_35372" {6294f16b-4f05-4430-afb9-773bdb237aec}
+EOF
+
+vbox_vminfo_stdout = <<~EOF
+name="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"
+EOF
+
+vbox_list_hdds_stdout = <<~EOF
+UUID: ebb6dca0-879f-480b-a50e-9efe330bd021
+Parent UUID: base
+State: locked read
+Type: normal (base)
+Location: /virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64-disk001.vmdk
+Storage format: VMDK
+Capacity: 65536 MBytes
+Encryption: disabled
+
+UUID: 1c182745-4b09-41a1-a147-d3ced46f72f6
+Parent UUID: ebb6dca0-879f-480b-a50e-9efe330bd021
+State: created
+Type: normal (differencing)
+Location: /virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk
+Storage format: VMDK
+Capacity: 65536 MBytes
+Encryption: disabled
+
+EOF
+
+vbox_list_dvds_stdout = <<~EOF
+UUID: 897aa7bc-1ec1-4e13-a16d-101d3716c72d
+State: created
+Type: normal (base)
+Location: /tmp/test.dvd
+Storage format: RAW
+Capacity: 100 MBytes
+Encryption: disabled
+
+EOF
+
+vbox_list_hostdvds_stdout = <<~EOF
+UUID: 00445644-0000-0000-2f64-65762f737230
+Name: /dev/sr0
+
+EOF
+
+vbox_list_hostfloppies_stdout = <<~EOF
+
+EOF
+
+vbox_list_hostonlyifs_stdout = <<~EOF
+Name: 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
+
+Name: 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
+
+EOF
+
+vbox_list_bridgedifs_stdout = <<~EOF
+Name: 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
+
+EOF
+
+vbox_list_dhcpservers_stdout = <<~EOF
+NetworkName: HostInterfaceNetworking-vboxnet0
+IP: 192.168.56.100
+NetworkMask: 255.255.255.0
+lowerIPAddress: 192.168.56.101
+upperIPAddress: 192.168.56.254
+Enabled: Yes
+
+NetworkName: HostInterfaceNetworking-vboxnet1
+IP: 192.168.19.2
+NetworkMask: 255.255.255.0
+lowerIPAddress: 192.168.19.3
+upperIPAddress: 192.168.19.254
+Enabled: Yes
+
+EOF
+
+# output of: VBoxManage list --sorted natnets
+vbox_list_natnets_stdout = <<~EOF
+NetworkName: 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
+loopback mappings (ipv4)
+ 127.0.0.1=2
+
+EOF
+
+expected_output = {"ostypes"=>{"Other"=>{"description"=>"Other/Unknown", "family id"=>"Other", "family desc"=>"Other", "64 bit"=>"false"}, "Other_64"=>{"description"=>"Other/Unknown (64-bit)", "family id"=>"Other", "family desc"=>"Other", "64 bit"=>"true"}, "Windows31"=>{"description"=>"Windows 3.1", "family id"=>"Windows", "family desc"=>"Microsoft Windows", "64 bit"=>"false"}}, "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"}}}
+
+describe Ohai::System, "plugin vbox_host" do
+ let(:plugin) { get_plugin("vbox_host") }
+
+ context "if the host does not have virtualbox installed" do
+ it "should not create a vbox attribute" do
+ plugin[:virtualization] = Mash.new
+ plugin[:virtualization][:systems] = Mash.new
+ plugin.run
+ expect(plugin).not_to have_key(:vbox)
+ end
+ end
+
+ context "if the host has virtualbox installed" do
+ it "should create a vbox attribute with accurate data" do
+ plugin[:virtualization] = Mash.new
+ plugin[:virtualization][:systems] = Mash.new
+ plugin[:virtualization][:systems][:vbox] = "host"
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted ostypes").and_return(mock_shell_out(0, vbox_list_ostypes_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted vms").and_return(mock_shell_out(0, vbox_list_vms_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage showvminfo 6294f16b-4f05-4430-afb9-773bdb237aec --machinereadable").and_return(mock_shell_out(0, vbox_vminfo_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hdds").and_return(mock_shell_out(0, vbox_list_hdds_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted dvds").and_return(mock_shell_out(0, vbox_list_dvds_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostdvds").and_return(mock_shell_out(0, vbox_list_hostdvds_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostfloppies").and_return(mock_shell_out(0, vbox_list_hostfloppies_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostonlyifs").and_return(mock_shell_out(0, vbox_list_hostonlyifs_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted bridgedifs").and_return(mock_shell_out(0, vbox_list_bridgedifs_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted dhcpservers").and_return(mock_shell_out(0, vbox_list_dhcpservers_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted natnets").and_return(mock_shell_out(0, vbox_list_natnets_stdout, ""))
+ plugin.run
+ expect(plugin).to have_key(:vbox)
+ # expect(plugin[:vbox]['ostypes']).to eq(expected_output['ostypes'])
+ # expect(plugin[:vbox]['guests']).to eq(expected_output['guests'])
+ # expect(plugin[:vbox]['hdds']).to eq(expected_output['hdds'])
+ # expect(plugin[:vbox]['dvds']).to eq(expected_output['dvds'])
+ # expect(plugin[:vbox]['hostdvds']).to eq(expected_output['hostdvds'])
+ # expect(plugin[:vbox]['hostfloppies']).to eq(expected_output['hostfloppies'])
+ # expect(plugin[:vbox]['hostonlyifs']).to eq(expected_output['hostonlyifs'])
+ # expect(plugin[:vbox]['bridgedifs']).to eq(expected_output['bridgedifs'])
+ # expect(plugin[:vbox]['dhcpservers']).to eq(expected_output['dhcpservers'])
+ # expect(plugin[:vbox]['natnets']).to eq(expected_output['natnets'])
+ expect(plugin[:vbox]).to eq(expected_output)
+ end
+ end
+end