diff options
-rw-r--r-- | lib/ohai/plugins/linux/virtualization.rb | 11 | ||||
-rw-r--r-- | spec/unit/plugins/linux/virtualization_spec.rb | 13 |
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb index ad9a4689..f4abc93a 100644 --- a/lib/ohai/plugins/linux/virtualization.rb +++ b/lib/ohai/plugins/linux/virtualization.rb @@ -150,6 +150,17 @@ Ohai.plugin(:Virtualization) do end end + # Detect Hyper-V gest and host hostname + if File.exist?("/var/lib/hyperv/.kvp_pool_3") + logger.trace('Plugin Virtualization: /var/lib/hyperv/.kvp_pool_3 contains string indicating Hyper-V guest') + data = File.read("/var/lib/hyperv/.kvp_pool_3") + hyperv_host = data[/\HostName(.*?)HostingSystemEditionId/, 1].scan(/[[:print:]]/).join.downcase + virtualization[:system] = 'hyperv' + virtualization[:role] = 'guest' + virtualization[:systems][:hyperv] = 'guest' + virtualization[:host] = hyperv_host + end + # Detect Linux-VServer if File.exist?("/proc/self/status") proc_self_status = File.read("/proc/self/status") diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index fa1eb767..264a357d 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -30,6 +30,7 @@ describe Ohai::System, "Linux virtualization platform" do allow(File).to receive(:exist?).with("/proc/modules").and_return(false) allow(File).to receive(:exist?).with("/proc/cpuinfo").and_return(false) allow(File).to receive(:exist?).with("/usr/sbin/dmidecode").and_return(false) + allow(File).to receive(:exist?).with("/var/lib/hyperv/.kvp_pool_3").and_return(false) allow(File).to receive(:exist?).with("/proc/self/status").and_return(false) allow(File).to receive(:exist?).with("/proc/bc/0").and_return(false) allow(File).to receive(:exist?).with("/proc/vz").and_return(false) @@ -384,6 +385,18 @@ VEERTU end end + describe "when we are checking for Hyper-V guest and host hostname" do + it "sets Hyper-V guest if /var/lib/hyperv/.kvp_pool_3 contains hyper_v.example.com" do + expect(File).to receive(:exist?).with("/var/lib/hyperv/.kvp_pool_3").and_return(true) + allow(File).to receive(:read).with("/var/lib/hyperv/.kvp_pool_3").and_return("HostNamehyper_v.example.comHostingSystemEditionId") + plugin.run + expect(plugin[:virtualization][:system]).to eq("hyperv") + expect(plugin[:virtualization][:role]).to eq("guest") + expect(plugin[:virtualization][:systems]["hyperv"]).to eq("guest") + expect(plugin[:virtualization]["host"]).to eq("hyper_v.example.com") + end + end + describe "when we are checking for Linux-VServer" do it "sets Linux-VServer host if /proc/self/status contains s_context: 0" do expect(File).to receive(:exist?).with("/proc/self/status").and_return(true) |