diff options
| author | Jiri Kubicek <jiri.kubicek@kraxnet.cz> | 2010-07-25 03:44:41 +0200 |
|---|---|---|
| committer | Jiri Kubicek <jiri.kubicek@kraxnet.cz> | 2010-07-26 00:36:21 +0200 |
| commit | 82286e44cf91e2e8305ba03e7e183ff98593099f (patch) | |
| tree | d72b43275d32cc42b554b95dde6f5416ed64f3de | |
| parent | 1bd2ca29d8fd7d11e75096ceeeb704fe887cad31 (diff) | |
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@kraxnet.cz>
| -rw-r--r-- | lib/facter/util/virtual.rb | 3 | ||||
| -rw-r--r-- | lib/facter/virtual.rb | 6 | ||||
| -rw-r--r-- | spec/unit/util/virtual.rb | 10 | ||||
| -rw-r--r-- | spec/unit/virtual.rb | 6 |
4 files changed, 24 insertions, 1 deletions
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 |
