[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, upstream, updated. 51bcebe38cab6088c901f1006339bbe40a36d161
Jiri Kubicek
jiri.kubicek at kraxnet.cz
Wed Aug 18 05:55:54 UTC 2010
The following commit has been merged in the upstream branch:
commit 82286e44cf91e2e8305ba03e7e183ff98593099f
Author: Jiri Kubicek <jiri.kubicek at kraxnet.cz>
Date: Sun Jul 25 03:44:41 2010 +0200
Fix #4352 - Support for detecting virtuals (jails) on FreeBSD
There was no support for detecting FreeBSD jails as a virtual in facter. This patch detects jail by getting "security.jail.jailed" kernel state via sysctl.
Signed-off-by: Jiri Kubicek <jiri.kubicek at kraxnet.cz>
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index 80f4e2c..900375f 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -57,5 +57,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..f1ccf1e 100644
--- a/spec/unit/util/virtual.rb
+++ b/spec/unit/util/virtual.rb
@@ -100,4 +100,14 @@ describe Facter::Util::Virtual do
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..311001d 100644
--- a/spec/unit/virtual.rb
+++ b/spec/unit/virtual.rb
@@ -55,4 +55,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
--
Packaging of Facter for debian
More information about the Pkg-puppet-devel
mailing list