spec/unit/virtual_spec.rb in facter-1.6.1 vs spec/unit/virtual_spec.rb in facter-1.6.2

- old
+ new

@@ -70,12 +70,16 @@ end describe "on Linux" do before do - Facter::Util::Resolution.expects(:exec).with("vmware -v").returns false + Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false Facter.fact(:operatingsystem).stubs(:value).returns(true) + # Ensure the tests don't fail on Xen + FileTest.stubs(:exists?).with("/proc/sys/xen").returns false + FileTest.stubs(:exists?).with("/sys/bus/xen").returns false + FileTest.stubs(:exists?).with("/proc/xen").returns false Facter.fact(:architecture).stubs(:value).returns(true) end it "should be parallels with Parallels vendor id from lspci" do Facter.fact(:kernel).stubs(:value).returns("Linux") @@ -133,39 +137,74 @@ Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("BIOS Information\nVendor: innotek GmbH\nVersion: VirtualBox\n\nSystem Information\nManufacturer: innotek GmbH\nProduct Name: VirtualBox\nFamily: Virtual Machine") Facter.fact(:virtual).value.should == "virtualbox" end + it "should be hyperv with Microsoft vendor name from lspci" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA") + Facter.fact(:virtual).value.should == "hyperv" + end + + it "should be hyperv with Microsoft vendor name from dmidecode" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) + Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Microsoft Corporation\nProduct Name: Virtual Machine") + Facter.fact(:virtual).value.should == "hyperv" + end + end describe "on Solaris" do before(:each) do - Facter::Util::Resolution.expects(:exec).with("vmware -v").returns false + Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false end it "should be vmware with VMWare vendor name from prtdiag" do Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter.fact(:hardwaremodel).stubs(:value).returns(nil) Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform") Facter.fact(:virtual).value.should == "vmware" end it "should be parallels with Parallels vendor name from prtdiag" do Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter.fact(:hardwaremodel).stubs(:value).returns(nil) Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform") Facter.fact(:virtual).value.should == "parallels" end it "should be virtualbox with VirtualBox vendor name from prtdiag" do Facter.fact(:kernel).stubs(:value).returns("SunOS") + Facter.fact(:hardwaremodel).stubs(:value).returns(nil) Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil) Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil) Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox") Facter.fact(:virtual).value.should == "virtualbox" end + + it "should be xen0 with xen dom0 files in /proc" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:operatingsystem).stubs(:value).returns("Linux") + Facter.fact(:hardwaremodel).stubs(:value).returns("i386") + Facter::Util::Virtual.expects(:xen?).returns(true) + FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(true) + Facter.fact(:virtual).value.should == "xen0" + end + + it "should be xenu with xen domU files in /proc" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:operatingsystem).stubs(:value).returns("Linux") + Facter.fact(:hardwaremodel).stubs(:value).returns("i386") + Facter::Util::Virtual.expects(:xen?).returns(true) + FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(false) + FileTest.expects(:exists?).with("/proc/xen/capabilities").returns(true) + Facter.fact(:virtual).value.should == "xenu" + end end end describe "is_virtual fact" do @@ -256,7 +295,13 @@ it "should be false on openvz host nodes" do Facter.fact(:kernel).stubs(:value).returns("Linux") Facter.fact(:virtual).stubs(:value).returns("openvzhn") Facter.fact(:is_virtual).value.should == "false" + end + + it "should be true when running on hyperv" do + Facter.fact(:kernel).stubs(:value).returns("Linux") + Facter.fact(:virtual).stubs(:value).returns("hyperv") + Facter.fact(:is_virtual).value.should == "true" end end