[Pkg-puppet-devel] [facter] 01/18: (FACT-704) Fix docker detection for systemd slices

Stig Sandbeck Mathisen ssm at debian.org
Wed Jan 27 21:12:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit f07560017f2c56965043b06e86a70036eca6bfee
Author: Matt Dainty <matt at bodgit-n-scarper.com>
Date:   Thu Jun 11 10:31:55 2015 +0100

    (FACT-704) Fix docker detection for systemd slices
    
    Changes the detection logic to just look for '/docker' somewhere in the string
    rather than checking for '/docker/' at the beginning.
    
    Updates the LXC logic to match as it's probably also affected.
---
 lib/facter/util/virtual.rb                                    |  4 ++--
 .../proc_1_cgroup/in_a_docker_container_with_systemd_slices   | 10 ++++++++++
 spec/unit/util/virtual_spec.rb                                | 11 +++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index 6e855d7..089b25f 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -162,7 +162,7 @@ module Facter::Util::Virtual
     path = Pathname.new('/proc/1/cgroup')
     return false unless path.readable?
     begin
-      in_lxc = path.readlines.any? {|l| l.split(":")[2].to_s.start_with? '/lxc/' }
+      in_lxc = path.readlines.any? {|l| l.split(":")[2].to_s.include? '/lxc' }
     rescue Errno::EPERM => exc
       # If we get "operation not permitted" here, it probably means we are
       # running OpenVZ. We are not running LXC anyway, so...
@@ -179,7 +179,7 @@ module Facter::Util::Virtual
     path = Pathname.new('/proc/1/cgroup')
     return false unless path.readable?
     begin
-      in_docker = path.readlines.any? {|l| l.split(":")[2].to_s.start_with? '/docker/' }
+      in_docker = path.readlines.any? {|l| l.split(":")[2].to_s.include? '/docker' }
     rescue Errno::EPERM => exc
       # This can fail under OpenVZ, just like in .lxc?
       return false
diff --git a/spec/fixtures/virtual/proc_1_cgroup/in_a_docker_container_with_systemd_slices b/spec/fixtures/virtual/proc_1_cgroup/in_a_docker_container_with_systemd_slices
new file mode 100644
index 0000000..317e2a4
--- /dev/null
+++ b/spec/fixtures/virtual/proc_1_cgroup/in_a_docker_container_with_systemd_slices
@@ -0,0 +1,10 @@
+10:hugetlb:/
+9:perf_event:/
+8:blkio:/system.slice/docker-8255e18aa44c5809a33db5f324a4b34e3a73b246394e4070cff752cd84d79a6d.scope
+7:net_cls:/
+6:freezer:/system.slice/docker-8255e18aa44c5809a33db5f324a4b34e3a73b246394e4070cff752cd84d79a6d.scope
+5:devices:/system.slice/docker-8255e18aa44c5809a33db5f324a4b34e3a73b246394e4070cff752cd84d79a6d.scope
+4:memory:/system.slice/docker-8255e18aa44c5809a33db5f324a4b34e3a73b246394e4070cff752cd84d79a6d.scope
+3:cpuacct,cpu:/system.slice/docker-8255e18aa44c5809a33db5f324a4b34e3a73b246394e4070cff752cd84d79a6d.scope
+2:cpuset:/system.slice/docker-8255e18aa44c5809a33db5f324a4b34e3a73b246394e4070cff752cd84d79a6d.scope
+1:name=systemd:/system.slice/docker-8255e18aa44c5809a33db5f324a4b34e3a73b246394e4070cff752cd84d79a6d.scope
diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb
index 805a181..0c78acb 100755
--- a/spec/unit/util/virtual_spec.rb
+++ b/spec/unit/util/virtual_spec.rb
@@ -368,6 +368,17 @@ describe Facter::Util::Virtual do
       end
     end
 
+    context '/proc/1/cgroup has at least one hierarchy with docker underneath a systemd slice parent' do
+      before :each do
+        fakepath = Pathname.new(File.join(fixture_path, 'in_a_docker_container_with_systemd_slices'))
+        Pathname.stubs(:new).with('/proc/1/cgroup').returns(fakepath)
+      end
+
+      it 'is true' do
+        subject.should be_true
+      end
+    end
+
     context '/proc/1/cgroup has no hierarchies rooted in /docker/' do
       before :each do
         fakepath = Pathname.new(File.join(fixture_path, 'not_in_a_container'))

-- 
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