spec/unit/plugins/linux/virtualization_spec.rb in ohai-13.3.0 vs spec/unit/plugins/linux/virtualization_spec.rb in ohai-13.4.0

- old
+ new

@@ -550,10 +550,11 @@ 4:memory:/Charlie 3:cpuacct:/Charlie 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 expect(plugin[:virtualization]).to eq({ "systems" => {} }) end @@ -570,10 +571,11 @@ 2:cpu:/ 1:cpuset:/ CGROUP 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) + allow(File).to receive(:read).with("/proc/1/environ").and_return("") end it "sets lxc host if lxc-version exists" do allow(plugin).to receive(:lxc_version_exists?).and_return("/usr/bin/lxc-version") plugin.run @@ -598,10 +600,18 @@ 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 expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(false) plugin.run @@ -680,9 +690,10 @@ 2:cpu:/Charlie 1:cpuset:/Charlie 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 context "/proc/self/cgroup only has / mounts" do