From 25fe11a5ccf5e1ed15dc943a16050e2dffd1891c Mon Sep 17 00:00:00 2001 From: Jacob Zaval Date: Tue, 14 Nov 2023 13:31:27 -0800 Subject: [PATCH] determine if we are an Apple Virtualization Framework guest (#1814) * determine if we are an Apple Virtualization Framework guest based on machine_model --------- Signed-off-by: Jacob Zaval --- lib/ohai/plugins/darwin/virtualization.rb | 5 +++++ spec/unit/plugins/darwin/virtualization_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/ohai/plugins/darwin/virtualization.rb b/lib/ohai/plugins/darwin/virtualization.rb index 30981a404..b2cc00e4e 100644 --- a/lib/ohai/plugins/darwin/virtualization.rb +++ b/lib/ohai/plugins/darwin/virtualization.rb @@ -95,5 +95,10 @@ def sysctl_exists? virtualization[:role] = "host" virtualization[:systems][:parallels] = "host" end + + if hardware["machine_model"].include? "VirtualMac" + virtualization[:system] = "apple" + virtualization[:role] = "guest" + end end end diff --git a/spec/unit/plugins/darwin/virtualization_spec.rb b/spec/unit/plugins/darwin/virtualization_spec.rb index f3d65ac37..049aa2719 100644 --- a/spec/unit/plugins/darwin/virtualization_spec.rb +++ b/spec/unit/plugins/darwin/virtualization_spec.rb @@ -82,6 +82,7 @@ allow(plugin).to receive(:docker_exists?).and_return(false) plugin[:hardware] = Mash.new plugin[:hardware][:boot_rom_version] = "not_a_vm" + plugin[:hardware][:machine_model] = "not_a_vm" end describe "when detecting OS X virtualization" do @@ -181,5 +182,12 @@ plugin.run expect(plugin[:virtualization]).to eq({ "systems" => {} }) end + + it "sets apple guest if hardware attributes mention VirtualMac" do + plugin[:hardware][:machine_model] = "VirtualMac2,1" + plugin.run + expect(plugin[:virtualization][:system]).to eq("apple") + expect(plugin[:virtualization][:role]).to eq("guest") + end end end