I guess the options here are drop Cloudlinux detection and let them
maintain their own patch/fact to detect themselves as working OpenVZ
support is more important. Accept this patch as acceptable, or find a
better way of doing it. Opinions gratefully received.
As an aside, I am using the better OpenVZ detecting methods as outlined in
#2242, which work by parsing /proc/self/status.
It checks if /proc/vz/ actually has anything in it, which if it doesn't,
is Cloudlinux. Uses the better OpenVZ detection methodology from #2242,
which is reading /proc/self/status for the envID which OpenVZ uses.
---
lib/facter/util/virtual.rb | 25 ++++++++++++++++++-------
spec/unit/util/virtual_spec.rb | 24 ++++++++++++++++++++----
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index 4355451..1961432 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -1,15 +1,26 @@
module Facter::Util::Virtual
def self.openvz?
- FileTest.directory?("/proc/vz")
+ FileTest.directory?("/proc/vz") and not self.openvz_cloudlinux?
end
+ # So one can either have #6728 work on OpenVZ or Cloudlinux. Whoo.
def self.openvz_type
- return nil unless self.openvz?
- if FileTest.exists?("/proc/vz/version")
- result = "openvzhn"
- else
- result = "openvzve"
- end
+ return false unless self.openvz?
+ return false unless FileTest.exists?( '/proc/self/status' )
+
+ envid = Facter::Util::Resolution.exec( 'grep "envID" /proc/self/status' )
+ if envid =~ /^envID:\s+0$/i
+ return 'openvzhn'
+ elsif envid =~ /^envID:\s+(\d+)$/i
+ return 'openvzve'
+ else
+ return 'unknown'
+ end
+ end
+
+ # Cloudlinux uses OpenVZ to a degree, but always has an empty /proc/vz/
+ def self.openvz_cloudlinux?
+ Dir.glob( '/proc/vz/*' ).empty?
end
def self.zone?
diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb
index aa2de5a..be22eda 100644
--- a/spec/unit/util/virtual_spec.rb
+++ b/spec/unit/util/virtual_spec.rb
@@ -9,21 +9,37 @@ describe Facter::Util::Virtual do
end
it "should detect openvz" do
FileTest.stubs(:directory?).with("/proc/vz").returns(true)
+ Dir.stubs(:glob).with("/proc/vz/*").returns(['vzquota'])
Facter::Util::Virtual.should be_openvz
end
- it "should identify openvzhn when version file exists" do
+ it "should not detect openvz when /proc/vz/ is empty" do
+ FileTest.stubs(:directory?).with("/proc/vz").returns(true)
+ Dir.stubs(:glob).with("/proc/vz/*").returns([])
+ Facter::Util::Virtual.should_not be_openvz
+ end
+
+ it "should identify openvzhn when /proc/self/status has envID of 0" do
Facter::Util::Virtual.stubs(:openvz?).returns(true)
- FileTest.stubs(:exists?).with("/proc/vz/version").returns(true)
+ FileTest.stubs(:exists?).with("/proc/self/status").returns(true)
+ Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("envID: 0")
Facter::Util::Virtual.openvz_type().should == "openvzhn"
end
- it "should identify openvzve when no version file exists" do
+ it "should identify openvzve when /proc/self/status has envID of 0" do
Facter::Util::Virtual.stubs(:openvz?).returns(true)
- FileTest.stubs(:exists?).with("/proc/vz/version").returns(false)
+ FileTest.stubs(:exists?).with('/proc/self/status').returns(true)
+ Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("envID: 666")
Facter::Util::Virtual.openvz_type().should == "openvzve"
end
+ it "should identify unknown when /proc/self/status has no envID" do
+ Facter::Util::Virtual.stubs(:openvz?).returns(true)
+ FileTest.stubs(:exists?).with('/proc/self/status').returns(true)
+ Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("")
+ Facter::Util::Virtual.openvz_type().should == "unknown"
+ end
+
it "should identify Solaris zones when non-global zone" do
Facter::Util::Resolution.stubs(:exec).with("/sbin/zonename").returns("somezone")
Facter::Util::Virtual.should be_zone
--
1.7.5.4
Daniel
> --
> You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
> To post to this group, send email to puppe...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
>
>
--
⎋ Puppet Labs Developer – http://puppetlabs.com
✉ Daniel Pittman <dan...@puppetlabs.com>
✆ Contact me via gtalk, email, or phone: +1 (877) 575-9775
♲ Made with 100 percent post-consumer electrons