summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/facter/util/virtual.rb4
-rw-r--r--lib/facter/virtual.rb10
-rw-r--r--spec/unit/util/virtual.rb11
-rw-r--r--spec/unit/virtual.rb11
4 files changed, 33 insertions, 3 deletions
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index bc00e1c..e94070d 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -62,4 +62,8 @@ module Facter::Util::Virtual
Facter::Util::Resolution.exec("/sbin/sysctl -n security.jail.jailed") == "1"
end
+ def self.hpvm?
+ Facter::Util::Resolution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/
+ end
+
end
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index 242422c..a8afb60 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -1,7 +1,7 @@
require 'facter/util/virtual'
Facter.add("virtual") do
- confine :kernel => %w{Linux FreeBSD OpenBSD SunOS}
+ confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX}
result = "physical"
@@ -9,6 +9,10 @@ Facter.add("virtual") do
result = "zone" if Facter::Util::Virtual.zone?
+ if Facter.value(:kernel)=="HP-UX"
+ result = "hpvm" if Facter::Util::Virtual.hpvm?
+ end
+
if Facter::Util::Virtual.openvz?
result = Facter::Util::Virtual.openvz_type()
end
@@ -76,11 +80,11 @@ Facter.add("virtual") do
end
Facter.add("is_virtual") do
- confine :kernel => %w{Linux FreeBSD OpenBSD SunOS}
+ confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX}
setcode do
case Facter.value(:virtual)
- when "xenu", "openvzve", "vmware", "kvm", "vserver", "jail", "zone"
+ when "xenu", "openvzve", "vmware", "kvm", "vserver", "jail", "zone", "hpvm"
"true"
else
"false"
diff --git a/spec/unit/util/virtual.rb b/spec/unit/util/virtual.rb
index 7ba946a..72186f7 100644
--- a/spec/unit/util/virtual.rb
+++ b/spec/unit/util/virtual.rb
@@ -137,4 +137,15 @@ describe Facter::Util::Virtual do
Facter::Util::Virtual.should_not be_jail
end
+ it "should detect hpvm on HP-UX" do
+ Facter.fact(:kernel).stubs(:value).returns("HP-UX")
+ Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server Integrity Virtual Machine')
+ Facter::Util::Virtual.should be_hpvm
+ end
+
+ it "should not detect hpvm on HP-UX when not in hpvm" do
+ Facter.fact(:kernel).stubs(:value).returns("HP-UX")
+ Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server rx660')
+ Facter::Util::Virtual.should_not be_hpvm
+ end
end
diff --git a/spec/unit/virtual.rb b/spec/unit/virtual.rb
index b79ced7..a7767c9 100644
--- a/spec/unit/virtual.rb
+++ b/spec/unit/virtual.rb
@@ -24,6 +24,11 @@ describe "Virtual fact" do
Facter.fact(:virtual).value.should == "jail"
end
+ it "should be hpvm on HP-UX when in HP-VM" do
+ Facter.fact(:kernel).stubs(:value).returns("HP-UX")
+ Facter::Util::Virtual.stubs(:hpvm?).returns(true)
+ Facter.fact(:virtual).value.should == "hpvm"
+ end
end
describe "is_virtual fact" do
@@ -74,4 +79,10 @@ describe "is_virtual fact" do
Facter.fact(:is_virtual).value.should == "true"
end
+ it "should be true when running on hp-vm" do
+ Facter.fact(:kernel).stubs(:value).returns("HP-UX")
+ Facter.fact(:virtual).stubs(:value).returns("hpvm")
+ Facter.fact(:is_virtual).value.should == "true"
+ end
+
end