From d0fd0875db4a977c2712df14e75c6f52ed55da08 Mon Sep 17 00:00:00 2001 From: Phil Dibowitz Date: Tue, 23 Feb 2021 21:32:09 -0800 Subject: Detect docker properly even if it's within virtualization Docker is docker even if it is within other things. Closes #1626 Signed-off-by: Phil Dibowitz --- spec/unit/plugins/linux/virtualization_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec') diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index 3e29533c..2466dbf2 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -674,6 +674,18 @@ describe Ohai::System, "Linux virtualization platform" do expect(plugin[:virtualization][:systems][:docker]).to eq("guest") end + it "sets virtualization if /.dockerenv exists even if /proc/self/cgroup exists" do + allow(plugin).to receive(:file_exist?).with("/proc/self/cgroup").and_return(true) + allow(plugin).to receive(:file_read).with("/proc/self/cgroup").and_return("") + allow(plugin).to receive(:file_read).with("/proc/1/environ").and_return("") + allow(plugin).to receive(:file_exist?).with("/.dockerenv").and_return(true) + 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 virtualization if /.dockerinit exists" do allow(plugin).to receive(:file_exist?).with("/.dockerinit").and_return(true) plugin.run -- cgit v1.2.1