summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRein Henrichs <rein@puppetlabs.com>2010-08-06 14:34:35 -0700
committerRein Henrichs <rein@puppetlabs.com>2010-08-06 14:34:35 -0700
commitbd3af7e4ba4c20cb079237ca7c4f347d7465ac4f (patch)
tree0a241d8f6426b05847c92f742b5ab0da5cac2ccd
parent881249f967eb6d7f513b3bd502dcda29f4007510 (diff)
parentfaaa169d73e5132b7f2ea491461690324c1133ab (diff)
downloadfacter-bd3af7e4ba4c20cb079237ca7c4f347d7465ac4f.tar.gz
facter-bd3af7e4ba4c20cb079237ca7c4f347d7465ac4f.tar.xz
facter-bd3af7e4ba4c20cb079237ca7c4f347d7465ac4f.zip
Merge remote branch 'kubicek/ticket/master/4352'
-rw-r--r--lib/facter/util/virtual.rb12
-rw-r--r--lib/facter/virtual.rb6
-rw-r--r--spec/unit/util/virtual.rb16
-rw-r--r--spec/unit/virtual.rb13
4 files changed, 42 insertions, 5 deletions
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index 80f4e2c..2d18c33 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -43,11 +43,12 @@ module Facter::Util::Virtual
end
def self.kvm?
- if FileTest.exists?("/proc/cpuinfo")
- txt = File.read("/proc/cpuinfo")
- return true if txt =~ /QEMU Virtual CPU/
+ txt = if FileTest.exists?("/proc/cpuinfo")
+ File.read("/proc/cpuinfo")
+ elsif Facter.value(:kernel)=="FreeBSD"
+ Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model")
end
- return false
+ (txt =~ /QEMU Virtual CPU/) ? true : false
end
def self.kvm_type
@@ -57,5 +58,8 @@ module Facter::Util::Virtual
"kvm"
end
+ def self.jail?
+ Facter::Util::Resolution.exec("/sbin/sysctl -n security.jail.jailed") == "1"
+ end
end
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index c6d0f22..c14a715 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -38,6 +38,10 @@ Facter.add("virtual") do
result = Facter::Util::Virtual.kvm_type()
end
+ if Facter.value(:kernel)=="FreeBSD"
+ result = "jail" if Facter::Util::Virtual.jail?
+ end
+
if result == "physical"
output = Facter::Util::Resolution.exec('lspci')
if not output.nil?
@@ -76,7 +80,7 @@ Facter.add("is_virtual") do
setcode do
case Facter.value(:virtual)
- when "xenu", "openvzve", "vmware", "kvm", "vserver"
+ when "xenu", "openvzve", "vmware", "kvm", "vserver", "jail"
true
else
false
diff --git a/spec/unit/util/virtual.rb b/spec/unit/util/virtual.rb
index de339b8..5b59cf9 100644
--- a/spec/unit/util/virtual.rb
+++ b/spec/unit/util/virtual.rb
@@ -100,4 +100,20 @@ describe Facter::Util::Virtual do
Facter::Util::Virtual.should be_kvm
end
+ it "should detect kvm on FreeBSD" do
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
+ Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n hw.model").returns("QEMU Virtual CPU version 0.12.4")
+ Facter::Util::Virtual.should be_kvm
+ end
+
+ it "should identify FreeBSD jail when in jail" do
+ Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n security.jail.jailed").returns("1")
+ Facter::Util::Virtual.should be_jail
+ end
+
+ it "should not identify FreeBSD jail when not in jail" do
+ Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n security.jail.jailed").returns("0")
+ Facter::Util::Virtual.should_not be_jail
+ end
+
end
diff --git a/spec/unit/virtual.rb b/spec/unit/virtual.rb
index 7dbd146..8ee843b 100644
--- a/spec/unit/virtual.rb
+++ b/spec/unit/virtual.rb
@@ -17,6 +17,13 @@ describe "Virtual fact" do
Facter.fact(:virtual).value.should == "zone"
end
+ it "should be jail on FreeBSD when a jail in kvm" do
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
+ Facter::Util::Virtual.stubs(:jail?).returns(true)
+ Facter::Util::Virtual.stubs(:kvm?).returns(true)
+ Facter.fact(:virtual).value.should == "jail"
+ end
+
end
describe "is_virtual fact" do
@@ -55,4 +62,10 @@ describe "is_virtual fact" do
Facter.fact(:is_virtual).value.should == true
end
+ it "should be true when running in jail" do
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
+ Facter.fact(:virtual).stubs(:value).returns("jail")
+ Facter.fact(:is_virtual).value.should == true
+ end
+
end