summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJose Asuncion <jeunito@gmail.com>2017-09-06 22:16:49 -0700
committerJose Asuncion <jose.asuncion@gmail.com>2017-09-07 17:28:01 -0700
commite8c765800ae3409085d86b9e6f38444fb00ff08e (patch)
treebfb5c0241d2d58d8caf691bfcecb3d86d881be3c /spec
parent4816b15d3e83515b508379936a70ab82cec80464 (diff)
downloadohai-e8c765800ae3409085d86b9e6f38444fb00ff08e.tar.gz
detect lxc guest using /proc/1/environ
Signed-off-by: Jose Asuncion <jeunito@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index 481c0f6f..cc9dbac5 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -552,6 +552,7 @@ CGROUP
2:cpu:/Charlie
1:cpuset:/Charlie
CGROUP
+ allow(File).to receive(:read).with("/proc/1/environ").and_return("")
expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
plugin.run
@@ -575,6 +576,7 @@ CGROUP
end
it "sets lxc host if lxc-version exists" do
+ allow(File).to receive(:read).with("/proc/1/environ").and_return("")
allow(plugin).to receive(:lxc_version_exists?).and_return("/usr/bin/lxc-version")
plugin.run
expect(plugin[:virtualization][:system]).to eq("lxc")
@@ -583,6 +585,7 @@ CGROUP
end
it "does not set the old virtualization attributes if they are already set" do
+ allow(File).to receive(:read).with("/proc/1/environ").and_return("")
allow(plugin).to receive(:lxc_version_exists?).and_return("/usr/bin/lxc-version")
plugin[:virtualization] = Mash.new
plugin[:virtualization][:system] = "the cloud"
@@ -594,12 +597,21 @@ CGROUP
it "does not set lxc host if lxc-version does not exist" do
allow(plugin).to receive(:lxc_version_exists?).and_return(false)
+ allow(File).to receive(:read).with("/proc/1/environ").and_return("")
plugin.run
expect(plugin[:virtualization][:system]).to be_nil
expect(plugin[:virtualization][:role]).to be_nil
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end
+ it "sets lxc guest if /proc/1/environ has lxccontainer string in it" do
+ one_environ = "container=lxccontainer_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3".chomp
+ allow(File).to receive(:read).with("/proc/1/environ").and_return(one_environ)
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("lxc")
+ expect(plugin[:virtualization][:role]).to eq("guest")
+ end
+
end
it "does not set virtualization if /proc/self/cgroup isn't there" do
@@ -682,6 +694,7 @@ CGROUP
CGROUP
allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup)
+ allow(File).to receive(:read).with("/proc/1/environ").and_return("")
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end