spec/unit/plugins/linux/virtualization_spec.rb in ohai-8.11.1 vs spec/unit/plugins/linux/virtualization_spec.rb in ohai-8.12.0

- old
+ new

@@ -35,10 +35,16 @@ allow(File).to receive(:exist?).with("/proc/vz").and_return(false) allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(false) allow(File).to receive(:exist?).with("/.dockerenv").and_return(false) allow(File).to receive(:exist?).with("/.dockerinit").and_return(false) allow(File).to receive(:exist?).with("/proc/bus/pci/devices").and_return(false) + allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(false) + + # default the which wrappers to nil + allow(plugin).to receive(:lxc_version_exists?).and_return(false) + allow(plugin).to receive(:docker_exists?).and_return(false) + allow(plugin).to receive(:nova_exists?).and_return(false) end describe "when we are checking for xen" do it "sets xen guest if /proc/xen exists but /proc/xen/capabilities does not" do expect(File).to receive(:exist?).with("/proc/xen").and_return(true) @@ -74,13 +80,32 @@ plugin.run expect(plugin[:virtualization]).to eq({ "systems" => {} }) end end + describe "when we are checking for openstack" do + it "sets openstack host if nova binary exists" do + allow(plugin).to receive(:nova_exists?).and_return("/usr/bin/nova") + plugin.run + expect(plugin[:virtualization][:system]).to eq("openstack") + expect(plugin[:virtualization][:role]).to eq("host") + expect(plugin[:virtualization][:systems][:openstack]).to eq("host") + end + end + describe "when we are checking for kvm" do - it "sets kvm host if /proc/modules contains kvm" do - expect(File).to receive(:exist?).with("/proc/modules").and_return(true) - allow(File).to receive(:read).with("/proc/modules").and_return("kvm 165872 1 kvm_intel") + it "sets kvm guest if /sys/devices/virtual/misc/kvm exists & hypervisor cpu feature is present" do + allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(true) + allow(File).to receive(:read).with("/proc/cpuinfo").and_return("fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon rep_good nopl pni vmx ssse3 cx16 sse4_1 sse4_2 x2apic popcnt hypervisor lahf_lm vnmi ept tsc_adjust") + plugin.run + expect(plugin[:virtualization][:system]).to eq("kvm") + expect(plugin[:virtualization][:role]).to eq("guest") + expect(plugin[:virtualization][:systems][:kvm]).to eq("guest") + end + + it "sets kvm host if /sys/devices/virtual/misc/kvm exists & hypervisor cpu feature is not present" do + allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(true) + allow(File).to receive(:read).with("/proc/cpuinfo").and_return("fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt lahf_lm ida dtherm tpr_shadow vnmi flexpriority ept vpid") plugin.run expect(plugin[:virtualization][:system]).to eq("kvm") expect(plugin[:virtualization][:role]).to eq("host") expect(plugin[:virtualization][:systems][:kvm]).to eq("host") end