summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Baptiste Favre <jean-baptiste.favre@blablacar.com>2015-06-26 15:40:09 +0200
committerThom May <thom@may.lt>2015-08-13 15:08:18 +0100
commitf3152b4f5fae2d43e26696fe43fa71749027b931 (patch)
tree04959a7789e1390ea1d468216c8e722f0a8500fa
parente62882a47032ac2b208a65feeec0f97f03e8161f (diff)
downloadohai-f3152b4f5fae2d43e26696fe43fa71749027b931.tar.gz
Fix #531: Docker changed their cgroups format
Take into account new cgroup format for docker. Tested with docker 1.6.2 on Debian sid with kernel 4.0.5
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb4
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb21
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb
index 231363a1..6f7dad5d 100644
--- a/lib/ohai/plugins/linux/virtualization.rb
+++ b/lib/ohai/plugins/linux/virtualization.rb
@@ -190,7 +190,9 @@ Ohai.plugin(:Virtualization) do
# Full notes, https://tickets.opscode.com/browse/OHAI-551
# Kernel docs, https://www.kernel.org/doc/Documentation/cgroups
if File.exists?("/proc/self/cgroup")
- if File.read("/proc/self/cgroup") =~ %r{^\d+:[^:]+:/(lxc|docker)/.+$}
+ cgroup_content = File.read("/proc/self/cgroup")
+ if cgroup_content =~ %r{^\d+:[^:]+:/(lxc|docker)/.+$} ||
+ cgroup_content =~ %r{^\d+:[^:]+:/[^/]+/(lxc|docker)-.+$}
virtualization[:system] = $1
virtualization[:role] = "guest"
virtualization[:systems][$1.to_sym] = "guest"
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index fd3af519..8692fb7a 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -513,6 +513,27 @@ CGROUP
expect(plugin[:virtualization][:systems][:docker]).to eq("guest")
end
+ # Relevant at least starting docker 1.6.2, kernel 4.0.5 & systemd 224-1.
+ # Doi not exactly know which software/version really matters here.
+ it "should set docker guest if /proc/self/cgroup exists and there are /system.slice/docker-<hexadecimal> mounts (systemd managed cgroup)" do
+ self_cgroup=<<-CGROUP
+8:devices:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
+7:cpuset:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
+6:blkio:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
+5:freezer:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
+4:net_cls:/
+3:memory:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
+2:cpu,cpuacct:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
+1:name=systemd:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope
+CGROUP
+ allow(File).to receive(:exists?).with("/proc/self/cgroup").and_return(true)
+ allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("docker")
+ expect(plugin[:virtualization][:role]).to eq("guest")
+ expect(plugin[:virtualization][:systems][:docker]).to eq("guest")
+ end
+
it "sets not set anything if /proc/self/cgroup exist and the cgroup is named arbitrarily, it isn't necessarily lxc." do
self_cgroup=<<-CGROUP
8:blkio:/Charlie