Please review pull request #201: (#14366) is_virtual/virtual should be triggered by EC2 opened by (kjoconnor)
Description:
Uses the built-in EC2 checks that populate the ec2_* facts to see
if we're running on EC2 and populate the is_virtual/virtual facts
appropriately.
This is my first commit, I've tried gathering the right way to do things from viewing other pull requests/commits but please let me know if anything looks off.
Thanks!
- Opened: Thu May 10 00:47:57 UTC 2012
- Based on: puppetlabs:master (1bd98fd94b5e577216b80789ee9f933dd5cc74f8)
- Requested merge: kjoconnor:virtual_ec2 (3035b91afa2e99a29a71978875ad5730a0acc37b)
Diff follows:
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index aed961e..d1d5879 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -1,3 +1,5 @@
+require 'facter/util/ec2'
+
module Facter::Util::Virtual
def self.openvz?
FileTest.directory?("/proc/vz") and not self.openvz_cloudlinux?
@@ -87,4 +89,10 @@ def self.hpvm?
def self.zlinux?
"zlinux"
end
+
+ def self.ec2?
+ if Facter::Util::EC2.can_connect?
+ "ec2"
+ end
+ end
end
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index 78d0841..83b9bb6 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -92,6 +92,10 @@
result = "jail" if Facter::Util::Virtual.jail?
end
+ if Facter::Util::Virtual.ec2?
+ result = "ec2"
+ end
+
if result == "physical"
output = Facter::Util::Resolution.exec('lspci 2>/dev/null')
if not output.nil?
diff --git a/spec/unit/virtual_spec.rb b/spec/unit/virtual_spec.rb
index 5d7b1ac..acb081b 100755
--- a/spec/unit/virtual_spec.rb
+++ b/spec/unit/virtual_spec.rb
@@ -13,6 +13,7 @@
Facter::Util::Virtual.stubs(:kvm?).returns(false)
Facter::Util::Virtual.stubs(:hpvm?).returns(false)
Facter::Util::Virtual.stubs(:zlinux?).returns(false)
+ Facter::Util::EC2.stubs(:can_connect?).returns(false)
end
it "should be zone on Solaris when a zone" do
@@ -233,6 +234,12 @@
Facter::Util::Resolution.stubs(:exec).with('sysctl -n hw.product 2>/dev/null').returns("HVM domU")
Facter.fact(:virtual).value.should == "xenhvm"
end
+
+ it "should be ec2 with EC2 can_connect?" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::EC2.stubs(:can_connect?).returns(true)
+ Facter.fact(:virtual).value.should == "ec2"
+ end
end
end
@@ -334,4 +341,10 @@
Facter.fact(:virtual).stubs(:value).returns("hyperv")
Facter.fact(:is_virtual).value.should == "true"
end
+
+ it "should be true when running on ec2" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter::Util::EC2.stubs(:can_connect?).returns(true)
+ Facter.fact(:is_virtual).value.should == "true"
+ end
end
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
