[Pkg-puppet-devel] [facter] 144/180: (FACT-335) implement GCE virtual fact
Stig Sandbeck Mathisen
ssm at debian.org
Mon Jun 30 15:06:41 UTC 2014
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository facter.
commit 11f098f7a55f804177c00279909ba6d8df237dfe
Author: Adrien Thebo <git at somethingsinistral.net>
Date: Wed Jun 18 13:25:35 2014 -0700
(FACT-335) implement GCE virtual fact
---
lib/facter/util/virtual.rb | 4 ++++
lib/facter/virtual.rb | 9 +++++++++
spec/unit/util/virtual_spec.rb | 10 ++++++++++
spec/unit/virtual_spec.rb | 13 +++++++++++++
4 files changed, 36 insertions(+)
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index d98e720..a8f449d 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -120,6 +120,10 @@ module Facter::Util::Virtual
File.read("/sys/devices/virtual/dmi/id/product_name") =~ /oVirt Node/ rescue false
end
+ def self.gce?
+ File.read("/sys/devices/virtual/dmi/id/product_name") =~ /Google/ rescue false
+ end
+
def self.jail?
path = case Facter.value(:kernel)
when "FreeBSD" then "/sbin"
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index a316c7d..82329ef 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -276,6 +276,15 @@ Facter.add("virtual") do
end
end
+Facter.add("virtual") do
+ has_weight 600
+ confine :kernel => "Linux"
+
+ setcode do
+ "gce" if Facter::Util::Virtual.gce?
+ end
+end
+
# Fact: is_virtual
#
# Purpose: returning true or false for if a machine is virtualised or not.
diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb
index c20919e..dc540e5 100755
--- a/spec/unit/util/virtual_spec.rb
+++ b/spec/unit/util/virtual_spec.rb
@@ -127,6 +127,16 @@ describe Facter::Util::Virtual do
Facter::Util::Virtual.should_not be_ovirt
end
+ it "detects GCE if the DMI product name is Google" do
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").returns("Google")
+ expect(Facter::Util::Virtual.gce?).to be_true
+ end
+
+ it "does not detect GCE if the DMI product name is not Google" do
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").returns('')
+ expect(Facter::Util::Virtual.gce?).to be_false
+ end
+
fixture_path = fixtures('virtual', 'proc_self_status')
test_cases = [
diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb
index 7e5ae12..0f4b1c6 100755
--- a/spec/unit/virtual_spec.rb
+++ b/spec/unit/virtual_spec.rb
@@ -18,6 +18,7 @@ describe "Virtual fact" do
Facter::Util::Virtual.stubs(:virt_what).returns(nil)
Facter::Util::Virtual.stubs(:rhev?).returns(false)
Facter::Util::Virtual.stubs(:ovirt?).returns(false)
+ Facter::Util::Virtual.stubs(:gce?).returns(false)
Facter::Util::Virtual.stubs(:virtualbox?).returns(false)
end
@@ -161,6 +162,12 @@ describe "Virtual fact" do
Facter.fact(:virtual).value.should == "ovirt"
end
+ it "is gce based on DMI info" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::Virtual.stubs(:gce?).returns(true)
+ Facter.fact(:virtual).value.should == "gce"
+ end
+
it "should be hyperv with Microsoft vendor name from lspci 2>/dev/null" do
Facter::Core::Execution.stubs(:exec).with('lspci 2>/dev/null').returns("00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA")
Facter.fact(:virtual).value.should == "hyperv"
@@ -492,6 +499,12 @@ describe "is_virtual fact" do
Facter.fact(:is_virtual).value.should == "true"
end
+ it "should be true when running on ovirt" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter.fact(:virtual).stubs(:value).returns("gce")
+ Facter.fact(:is_virtual).value.should == "true"
+ end
+
it "should be true when running in LXC" do
Facter.fact(:kernel).stubs(:value).returns("Linux")
Facter.fact(:virtual).stubs(:value).returns("lxc")
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git
More information about the Pkg-puppet-devel
mailing list