spec/unit/plugins/linux/virtualization_spec.rb in ohai-13.6.0 vs spec/unit/plugins/linux/virtualization_spec.rb in ohai-13.7.0
- old
+ new
@@ -38,10 +38,11 @@
allow(File).to receive(:exist?).with("/.dockerinit").and_return(false)
allow(File).to receive(:exist?).with("/proc/bus/pci/devices").and_return(false)
allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(false)
allow(File).to receive(:exist?).with("/dev/lxd/sock").and_return(false)
allow(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(false)
+ allow(File).to receive(:exist?).with("/proc/1/environ").and_return(false)
# default the which wrappers to nil
allow(plugin).to receive(:which).with("lxc-version").and_return(nil)
allow(plugin).to receive(:which).with("lxc-start").and_return(nil)
allow(plugin).to receive(:nova_exists?).and_return(false)
@@ -622,9 +623,21 @@
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
expect(plugin[:virtualization]).to eq({ "systems" => {} })
+ end
+ end
+
+ describe "when we are checking for systemd-nspawn" do
+ it "sets nspawn guest if /proc/1/environ has nspawn string in it" do
+ allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true)
+ one_environ = "container=systemd-nspawn_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)
+ allow(File).to receive(:read).with("/proc/self/cgroup").and_return("")
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("nspawn")
+ expect(plugin[:virtualization][:role]).to eq("guest")
end
end
describe "when we are checking for docker" do
it "sets docker guest if /proc/self/cgroup exist and there are /docker/<hexadecimal> mounts" do