spec/ohai/plugins/linux/virtualization_spec.rb in ohai-0.6.4 vs spec/ohai/plugins/linux/virtualization_spec.rb in ohai-0.6.6.rc.0
- old
+ new
@@ -25,28 +25,29 @@
@ohai.stub!(:require_plugin).and_return(true)
@ohai.extend(SimpleFromFile)
# default to all requested Files not existing
File.stub!(:exists?).with("/proc/xen/capabilities").and_return(false)
- File.stub!(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(false)
File.stub!(:exists?).with("/proc/modules").and_return(false)
File.stub!(:exists?).with("/proc/cpuinfo").and_return(false)
File.stub!(:exists?).with("/usr/sbin/dmidecode").and_return(false)
File.stub!(:exists?).with("/proc/self/status").and_return(false)
+ File.stub!(:exists?).with("/proc/user_beancounters").and_return(false)
end
describe "when we are checking for xen" do
it "should set xen host if /proc/xen/capabilities contains control_d" do
File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
File.stub!(:read).with("/proc/xen/capabilities").and_return("control_d")
@ohai._require_plugin("linux::virtualization")
- @ohai[:virtualization][:system].should == "xen"
+ @ohai[:virtualization][:system].should == "xen"
@ohai[:virtualization][:role].should == "host"
end
- it "should set xen guest if /proc/sys/xen/independent_wallclock exists" do
- File.should_receive(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(true)
+ it "should set xen guest if /proc/xen/capabilities exists" do
+ File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
+ File.stub!(:read).with("/proc/xen/capabilities").and_return("")
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:system].should == "xen"
@ohai[:virtualization][:role].should == "guest"
end
@@ -63,11 +64,11 @@
File.stub!(:read).with("/proc/modules").and_return("kvm 165872 1 kvm_intel")
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:system].should == "kvm"
@ohai[:virtualization][:role].should == "host"
end
-
+
it "should set kvm guest if /proc/cpuinfo contains QEMU Virtual CPU" do
File.should_receive(:exists?).with("/proc/cpuinfo").and_return(true)
File.stub!(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:system].should == "kvm"
@@ -79,10 +80,34 @@
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization].should == {}
end
end
+ describe "when we are checking for VirtualBox" do
+ it "should set vbox host if /proc/modules contains vboxdrv" do
+ File.should_receive(:exists?).with("/proc/modules").and_return(true)
+ File.stub!(:read).with("/proc/modules").and_return("vboxdrv 268268 3 vboxnetadp,vboxnetflt")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "vbox"
+ @ohai[:virtualization][:role].should == "host"
+ end
+
+ it "should set vbox guest if /proc/modules contains vboxguest" do
+ File.should_receive(:exists?).with("/proc/modules").and_return(true)
+ File.stub!(:read).with("/proc/modules").and_return("vboxguest 177749 2 vboxsf")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "vbox"
+ @ohai[:virtualization][:role].should == "guest"
+ end
+
+ it "should not set virtualization if vbox isn't there" do
+ File.should_receive(:exists?).at_least(:once).and_return(false)
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
+ end
+ end
+
describe "when we are parsing dmidecode" do
before(:each) do
File.should_receive(:exists?).with("/usr/sbin/dmidecode").and_return(true)
@stdin = mock("STDIN", { :close => true })
@pid = 10
@@ -104,12 +129,12 @@
Version: VS2005R2
Serial Number: 1688-7189-5337-7903-2297-1012-52
UUID: D29974A4-BE51-044C-BDC6-EFBC4B87A8E9
Wake-up Type: Power Switch
MSVPC
- @stdout.stub!(:read).and_return(ms_vpc_dmidecode)
-
+ @stdout.stub!(:read).and_return(ms_vpc_dmidecode)
+
@ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:system].should == "virtualpc"
@ohai[:virtualization][:role].should == "guest"
end
@@ -177,9 +202,32 @@
File.should_receive(:exists?).at_least(:once).and_return(false)
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization].should == {}
end
end
+ describe "when we are checking for openvz" do
+ it "should set openvz host if /proc/user_beancounters contains 0:" do
+ File.should_receive(:exists?).with("/proc/user_beancounters").and_return(true)
+ File.stub!(:read).with("/proc/user_beancounters").and_return("\n 0: ")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:emulator].should == "openvz"
+ @ohai[:virtualization][:role].should == "host"
+ end
+
+ it "should set openvz guest if /proc/user_beancounters doesn't contain 0:" do
+ File.should_receive(:exists?).with("/proc/user_beancounters").and_return(true)
+ File.stub!(:read).with("/proc/user_beancounters").and_return("101:")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:emulator].should == "openvz"
+ @ohai[:virtualization][:role].should == "guest"
+ end
+
+ it "should not set virtualization if openvz isn't there" do
+ File.should_receive(:exists?).at_least(:once).and_return(false)
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
+ end
+ end
it "should not set virtualization if no tests match" do
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization].should == {}
end