summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortpowell-progress <104777878+tpowell-progress@users.noreply.github.com>2023-01-19 09:42:36 -0800
committerGitHub <noreply@github.com>2023-01-19 09:42:36 -0800
commitd72dac60794a713d4390bd7f1f2bfa84aac61601 (patch)
tree42b585716bed435edb3a5abf4c5ea299ed12e2b0
parentb59776be1a66db77473f729132b94085fd8fa49d (diff)
parent815d074bc7ab6c6ce44be9a56c61a8fb9f2650ac (diff)
downloadohai-d72dac60794a713d4390bd7f1f2bfa84aac61601.tar.gz
Merge pull request #1776 from jweyer8/jweyer/dev/virtualization
Darwin virtualization plugin: fix potential for false positive
-rw-r--r--lib/ohai/plugins/darwin/virtualization.rb15
-rw-r--r--spec/unit/plugins/darwin/virtualization_spec.rb128
2 files changed, 80 insertions, 63 deletions
diff --git a/lib/ohai/plugins/darwin/virtualization.rb b/lib/ohai/plugins/darwin/virtualization.rb
index ac5a096b..4ccdc19d 100644
--- a/lib/ohai/plugins/darwin/virtualization.rb
+++ b/lib/ohai/plugins/darwin/virtualization.rb
@@ -77,17 +77,14 @@ Ohai.plugin(:Virtualization) do
virtualization[:systems][:vmware] = "guest"
end
- if prlctl_exists?
+ if ioreg_exists? && /pci1ab8,4000/.match?(shell_out("ioreg -l").stdout)
+ virtualization[:system] = "parallels"
+ virtualization[:role] = "guest"
+ virtualization[:systems][:parallels] = "guest"
+ elsif prlctl_exists?
virtualization[:system] = "parallels"
virtualization[:role] = "host"
virtualization[:systems][:parallels] = "host"
- elsif ioreg_exists?
- so = shell_out("ioreg -l")
- if /pci1ab8,4000/.match?(so.stdout)
- virtualization[:system] = "parallels"
- virtualization[:role] = "guest"
- virtualization[:systems][:parallels] = "guest"
- end
end
end
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/darwin/virtualization_spec.rb b/spec/unit/plugins/darwin/virtualization_spec.rb
index 59d3d448..845d47f9 100644
--- a/spec/unit/plugins/darwin/virtualization_spec.rb
+++ b/spec/unit/plugins/darwin/virtualization_spec.rb
@@ -22,6 +22,55 @@ require "spec_helper"
describe Ohai::System, "Darwin virtualization platform" do
let(:plugin) { get_plugin("darwin/virtualization") }
+ let(:ioreg_vm) do
+ <<-IOREG
+ | | +-o pci1ab8,4000@3 <class IOPCIDevice, id 0x1000001d1, registered, matched, active, busy 0 (40 ms), retain 9>
+ | | | | {
+ | | | | "compatible" = <"pci1ab8,400","pci1ab8,4000","pciclass,ff0000">
+ | | | | "subsystem-vendor-id" = <b81a0000>
+ | | | | "IOName" = "pci1ab8,4000"
+ | | | | "reg" = <00180000000000000000000000000000000000001018000100000000000000000000000020000000>
+ | | | | "device-id" = <00400000>
+ | | | | "assigned-addresses" = <101800810000000040d200000000000020000000>
+ | | | | "IOPowerManagement" = {"MaxPowerState"=3,"ChildProxyPowerState"=2,"CurrentPowerState"=2}
+ | | | | "IOPCIResourced" = Yes
+ | | | | "IODeviceMemory" = ("IOSubMemoryDescriptor is not serializable")
+ | | | | "revision-id" = <00000000>
+ | | | | "IOInterruptControllers" = ("IOPCIMessagedInterruptController")
+ | | | | "vendor-id" = <b81a0000>
+ | | | | "pcidebug" = "0:3:0"
+ | | | | "class-code" = <0000ff00>
+ | | | | "IOInterruptSpecifiers" = (<0000000000000100>)
+ | | | | "IOPCIMSIMode" = Yes
+ | | | | "subsystem-id" = <00040000>
+ | | | | "name" = <"pci1ab8,4000">
+ | | | | }
+ IOREG
+ end
+ let(:ioreg_not_vm) do
+ <<-IOREG
+ | | +-o pci8086,2445@1F,4 <class IOPCIDevice, id 0x1000001d4, registered, matched, active, busy 0 (974 ms), retain 11>
+ | | | {
+ | | | "compatible" = <"pci1ab8,400","pci8086,2445","pciclass,040100">
+ | | | "subsystem-vendor-id" = <b81a0000>
+ | | | "IOName" = "pci8086,2445"
+ | | | "reg" = <00fc00000000000000000000000000000000000010fc00010000000000000000000000000001000014fc000100000000000000000000000000010000>
+ | | | "device-id" = <45240000>
+ | | | "assigned-addresses" = <10fc00810000000000d10000000000000001000014fc00810000000000d000000000000000010000>
+ | | | "IOPowerManagement" = {"ChildrenPowerState"=2,"CurrentPowerState"=2,"ChildProxyPowerState"=2,"MaxPowerState"=3}
+ | | | "IOPCIResourced" = Yes
+ | | | "IODeviceMemory" = ("IOSubMemoryDescriptor is not serializable","IOSubMemoryDescriptor is not serializable")
+ | | | "revision-id" = <02000000>
+ | | | "IOInterruptControllers" = ("io-apic-0")
+ | | | "vendor-id" = <86800000>
+ | | | "pcidebug" = "0:31:4"
+ | | | "class-code" = <00010400>
+ | | | "IOInterruptSpecifiers" = (<1100000007000000>)
+ | | | "subsystem-id" = <00040000>
+ | | | "name" = <"pci8086,2445">
+ | | | }
+ IOREG
+ end
before do
allow(plugin).to receive(:collect_os).and_return(:darwin)
@@ -80,41 +129,22 @@ describe Ohai::System, "Darwin virtualization platform" do
expect(plugin[:virtualization][:systems][:vbox]).to eq("guest")
end
- it "sets parallels host if /usr/bin/prlctl exists" do
- allow(plugin).to receive(:prlctl_exists?).and_return("/usr/bin/prlctl")
+ it "sets parallels guest if /usr/local/bin/prlctl exists, /usr/sbin/ioreg exists, and ioreg's output contains pci1ab8,4000" do
+ allow(plugin).to receive(:prlctl_exists?).and_return("/usr/local/bin/prlctl")
+ allow(plugin).to receive(:ioreg_exists?).and_return(true)
+ shellout = double("shellout")
+ allow(shellout).to receive(:stdout).and_return(ioreg_vm)
+ allow(plugin).to receive(:shell_out).with("ioreg -l").and_return(shellout)
plugin.run
expect(plugin[:virtualization][:system]).to eq("parallels")
- expect(plugin[:virtualization][:role]).to eq("host")
- expect(plugin[:virtualization][:systems][:parallels]).to eq("host")
+ expect(plugin[:virtualization][:role]).to eq("guest")
+ expect(plugin[:virtualization][:systems][:parallels]).to eq("guest")
end
- it "sets parallels guest if /usr/sbin/ioreg exists and its output contains pci1ab8,4000" do
+ it "sets parallels guest if /usr/local/bin/prlctl does not exists, /usr/sbin/ioreg exists, and ioreg's output contains pci1ab8,4000" do
allow(plugin).to receive(:ioreg_exists?).and_return(true)
- ioreg = <<-IOREG
- | | +-o pci1ab8,4000@3 <class IOPCIDevice, id 0x1000001d1, registered, matched, active, busy 0 (40 ms), retain 9>
- | | | | {
- | | | | "compatible" = <"pci1ab8,400","pci1ab8,4000","pciclass,ff0000">
- | | | | "subsystem-vendor-id" = <b81a0000>
- | | | | "IOName" = "pci1ab8,4000"
- | | | | "reg" = <00180000000000000000000000000000000000001018000100000000000000000000000020000000>
- | | | | "device-id" = <00400000>
- | | | | "assigned-addresses" = <101800810000000040d200000000000020000000>
- | | | | "IOPowerManagement" = {"MaxPowerState"=3,"ChildProxyPowerState"=2,"CurrentPowerState"=2}
- | | | | "IOPCIResourced" = Yes
- | | | | "IODeviceMemory" = ("IOSubMemoryDescriptor is not serializable")
- | | | | "revision-id" = <00000000>
- | | | | "IOInterruptControllers" = ("IOPCIMessagedInterruptController")
- | | | | "vendor-id" = <b81a0000>
- | | | | "pcidebug" = "0:3:0"
- | | | | "class-code" = <0000ff00>
- | | | | "IOInterruptSpecifiers" = (<0000000000000100>)
- | | | | "IOPCIMSIMode" = Yes
- | | | | "subsystem-id" = <00040000>
- | | | | "name" = <"pci1ab8,4000">
- | | | | }
- IOREG
shellout = double("shellout")
- allow(shellout).to receive(:stdout).and_return(ioreg)
+ allow(shellout).to receive(:stdout).and_return(ioreg_vm)
allow(plugin).to receive(:shell_out).with("ioreg -l").and_return(shellout)
plugin.run
expect(plugin[:virtualization][:system]).to eq("parallels")
@@ -122,35 +152,25 @@ describe Ohai::System, "Darwin virtualization platform" do
expect(plugin[:virtualization][:systems][:parallels]).to eq("guest")
end
- it "does not set parallels guest if /usr/sbin/ioreg exists and its output not contain pci1ab8,4000" do
+ it "sets parallels host if /usr/local/bin/prlctl exists, /usr/sbin/ioreg exists, and ioreg's output does not contain pci1ab8,4000" do
+ allow(plugin).to receive(:prlctl_exists?).and_return("/usr/local/bin/prlctl")
+ allow(plugin).to receive(:ioreg_exists?).and_return(true)
+ shellout = double("shellout")
+ allow(shellout).to receive(:stdout).and_return(ioreg_not_vm)
+ allow(plugin).to receive(:shell_out).with("ioreg -l").and_return(shellout)
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("parallels")
+ expect(plugin[:virtualization][:role]).to eq("host")
+ expect(plugin[:virtualization][:systems][:parallels]).to eq("host")
+ end
+
+ it "does not set parallels guest if /usr/local/bin/prlctl does not exist, /usr/sbin/ioreg exists, and ioreg's output does not contain pci1ab8,4000" do
allow(plugin).to receive(:ioreg_exists?).and_return(true)
- ioreg = <<-IOREG
- | | +-o pci8086,2445@1F,4 <class IOPCIDevice, id 0x1000001d4, registered, matched, active, busy 0 (974 ms), retain 11>
- | | | {
- | | | "compatible" = <"pci1ab8,400","pci8086,2445","pciclass,040100">
- | | | "subsystem-vendor-id" = <b81a0000>
- | | | "IOName" = "pci8086,2445"
- | | | "reg" = <00fc00000000000000000000000000000000000010fc00010000000000000000000000000001000014fc000100000000000000000000000000010000>
- | | | "device-id" = <45240000>
- | | | "assigned-addresses" = <10fc00810000000000d10000000000000001000014fc00810000000000d000000000000000010000>
- | | | "IOPowerManagement" = {"ChildrenPowerState"=2,"CurrentPowerState"=2,"ChildProxyPowerState"=2,"MaxPowerState"=3}
- | | | "IOPCIResourced" = Yes
- | | | "IODeviceMemory" = ("IOSubMemoryDescriptor is not serializable","IOSubMemoryDescriptor is not serializable")
- | | | "revision-id" = <02000000>
- | | | "IOInterruptControllers" = ("io-apic-0")
- | | | "vendor-id" = <86800000>
- | | | "pcidebug" = "0:31:4"
- | | | "class-code" = <00010400>
- | | | "IOInterruptSpecifiers" = (<1100000007000000>)
- | | | "subsystem-id" = <00040000>
- | | | "name" = <"pci8086,2445">
- | | | }
- IOREG
shellout = double("shellout")
- allow(shellout).to receive(:stdout).and_return(ioreg)
+ allow(shellout).to receive(:stdout).and_return(ioreg_not_vm)
allow(plugin).to receive(:shell_out).with("ioreg -l").and_return(shellout)
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
end
-end
+end \ No newline at end of file