Skip to content

Instantly share code, notes, and snippets.

@btm
Created January 31, 2009 13:23
Show Gist options
  • Save btm/55541 to your computer and use it in GitHub Desktop.
Save btm/55541 to your computer and use it in GitHub Desktop.
1)
'Ohai::System Linux virtualization platform should set xen host if /proc/xen/capabilities contains control_d' FAILED
expected "xen", got "kvm" (using .eql?)
./spec/ohai/plugins/linux/virtualization_spec.rb:32:
2)
NoMethodError in 'Ohai::System Linux virtualization platform should set xen guest if /proc/sys/xen/independent_wallclock exists'
undefined method `exists?' for File:Class
/home/btm/ohai/spec/../lib/ohai/mixin/from_file.rb:28:in `from_file'
/home/btm/ohai/spec/../lib/ohai/system.rb:117:in `_require_plugin'
/home/btm/ohai/spec/../lib/ohai/system.rb:112:in `each'
/home/btm/ohai/spec/../lib/ohai/system.rb:112:in `_require_plugin'
./spec/ohai/plugins/linux/virtualization_spec.rb:41:
3)
NoMethodError in 'Ohai::System Linux virtualization platform should set kvm host if /proc/modules reports such'
undefined method `exists?' for File:Class
/home/btm/ohai/spec/../lib/ohai/mixin/from_file.rb:28:in `from_file'
/home/btm/ohai/spec/../lib/ohai/system.rb:117:in `_require_plugin'
/home/btm/ohai/spec/../lib/ohai/system.rb:112:in `each'
/home/btm/ohai/spec/../lib/ohai/system.rb:112:in `_require_plugin'
./spec/ohai/plugins/linux/virtualization_spec.rb:57:
virtualization Mash.new
# if it is possible to detect paravirt vs hardware virt, it should be put in
# virtualization[:mechanism]
if File.exists?("/proc/xen/capabilities")
if File.read("/proc/xen/capabilities") =~ /control_d/i
virtualization[:system] = "xen"
virtualization[:role] = "host"
end
elsif File.exists?("/proc/sys/xen/independent_wallclock")
virtualization[:system] = "xen"
virtualization[:role] = "guest"
end
# Detect KVM hosts by kernel module
if File.exists?("/proc/modules")
if File.read("/proc/modules") =~ /^kvm/
virtualization[:system] = "kvm"
virtualization[:role] = "host"
end
end
# Detect KVM/QEMU from cpuinfo, report as KVM
# We could pick KVM from 'Booting paravirtualized kernel on KVM' in dmesg
# 2.6.27-9-server (intrepid) has this / 2.6.18-6-amd64 (etch) does not
# It would be great if we could read pv_info in the kernel
# Wait for reply to: http://article.gmane.org/gmane.comp.emulators.kvm.devel/27885
if File.exists?("/proc/cpuinfo")
if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU/
virtualization[:system] = "kvm"
virtualization[:role] = "guest"
end
end
# http://www.dmo.ca/blog/detecting-virtualization-on-linux
if File.exists?("/usr/sbin/dmidecode")
popen4("dmidecode") do |pid, stdin, stdout, stderr|
stdin.close
stdout.each do |line|
case line
when /Manufacturer: Microsoft/
found_virt_manufacturer = "virtualpc"
when / Product Name: Virtual Machine/
if found_virt_manufacturer == "virtualpc"
virtualization[:system] = "virtualpc"
virtualization[:role] = "guest"
end
when /Manufacturer: VMware/
found_virt_manufacturer = "vmware"
when /Product Name: VMware Virtual Platform/
if found_virt_manufacturer == "vmware"
virtualization[:system] = "vmware"
virtualization[:role] = "guest"
end
end
end
end
end
require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
describe Ohai::System, "Linux virtualization platform" do
before(:each) do
@ohai = Ohai::System.new
@ohai[:os] = "linux"
@ohai.stub!(:require_plugin).and_return(true)
end
it "should set xen host if /proc/xen/capabilities contains control_d" do
@mock_cap = mock("/proc/xen/capabilities")
@mock_cap.stub!(:each).and_yield("control_d")
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:system].should eql("xen")
@ohai[:virtualization][:role].should eql("host")
end
it "should set xen guest if /proc/sys/xen/independent_wallclock exists" do
@mock_cap = mock("/proc/xen/capabilities")
@mock_cap.stub!(:each).and_yield("control_d")
File.stub!(:exists?).with("/proc/xen/capabilities").and_return(false)
File.stub!(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(true)
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:system].should eql("xen")
@ohai[:virtualization][:role].should eql("guest")
end
it "should not set virtualization if xen isn't there" do
@mock_cap = mock("/proc/xen/capabilities")
@mock_cap.stub!(:each).and_yield("control_d")
File.stub!(:exists?).with("/proc/xen/capabilities").and_return(false)
File.stub!(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(false)
@ohai[:virtualization].should eql(nil)
end
it "should set kvm host if /proc/modules reports such" do
File.stub!(:exists?).with("/proc/modules").and_return(true)
File.stub!(:read).and_return("kvm 165872 1 kvm_intel")
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization][:system].should eql("kvm")
@ohai[:virtualization][:role].should eql("host")
end
it "should not set kvm host if /proc/modules does not exist" do
File.stub!(:exists?).and_return(false)
@ohai._require_plugin("linux::virtualization")
@ohai[:virtualization].should eql(nil)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment