Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'OHAI-183'

  • Loading branch information...
commit 1c0505c638ee7fbbfc9bb431cb66dbef49183f8e 2 parents 472ffad + b6163ba
@btm btm authored
View
17 lib/ohai/plugins/linux/virtualization.rb
@@ -77,3 +77,20 @@
end
end
+
+# Detect Linux-VServer
+if File.exists?("/proc/self/status")
+ proc_self_status = File.read("/proc/self/status")
+ vxid = proc_self_status.match(/^(s_context|VxID): (\d+)$/)
+ if vxid and vxid[2]
+ virtualization[:system] = "linux-vserver"
+ if vxid[2] == "0"
+ virtualization[:role] = "host"
+ else
+ virtualization[:role] = "guest"
+ end
+ end
+end
+
+# Detect OpenVZ
+# something in /proc/vz/veinfo
View
41 spec/ohai/plugins/linux/virtualization_spec.rb
@@ -31,6 +31,7 @@
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)
end
describe "when we are checking for xen" do
@@ -139,6 +140,46 @@
end
end
+ describe "when we are checking for Linux-VServer" do
+ it "should set Linux-VServer host if /proc/self/status contains s_context: 0" do
+ File.should_receive(:exists?).with("/proc/self/status").and_return(true)
+ File.stub!(:read).with("/proc/self/status").and_return("s_context: 0")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "linux-vserver"
+ @ohai[:virtualization][:role].should == "host"
+ end
+
+ it "should set Linux-VServer host if /proc/self/status contains VxID: 0" do
+ File.should_receive(:exists?).with("/proc/self/status").and_return(true)
+ File.stub!(:read).with("/proc/self/status").and_return("VxID: 0")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "linux-vserver"
+ @ohai[:virtualization][:role].should == "host"
+ end
+
+ it "should set Linux-VServer guest if /proc/self/status contains s_context > 0" do
+ File.should_receive(:exists?).with("/proc/self/status").and_return(true)
+ File.stub!(:read).with("/proc/self/status").and_return("s_context: 2")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "linux-vserver"
+ @ohai[:virtualization][:role].should == "guest"
+ end
+
+ it "should set Linux-VServer guest if /proc/self/status contains VxID > 0" do
+ File.should_receive(:exists?).with("/proc/self/status").and_return(true)
+ File.stub!(:read).with("/proc/self/status").and_return("VxID: 2")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "linux-vserver"
+ @ohai[:virtualization][:role].should == "guest"
+ end
+
+ it "should not set virtualization if Linux-VServer 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 == {}
Please sign in to comment.
Something went wrong with that request. Please try again.