summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeal Jagannatha <zealjagannatha@gmail.com>2017-10-29 14:39:32 -0700
committerZeal Jagannatha <zealjagannatha@gmail.com>2017-11-20 10:33:34 -0800
commitef143fdc2097700d3e5efff195178e2cdf119cd8 (patch)
tree83c37839b113eb768856324b8c1ad4e7675b261e
parent73a12b4d2d26273e5fbbb504382b2f764dcb3be8 (diff)
downloadohai-ef143fdc2097700d3e5efff195178e2cdf119cd8.tar.gz
Added systemd-nspawn virtualization detection
Signed-off-by: Zeal Jagannatha <zealjagannatha@gmail.com>
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb7
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb14
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb
index d745bd49..f08df6aa 100644
--- a/lib/ohai/plugins/linux/virtualization.rb
+++ b/lib/ohai/plugins/linux/virtualization.rb
@@ -159,7 +159,7 @@ Ohai.plugin(:Virtualization) do
end
end
- # Detect LXC/Docker
+ # Detect LXC/Docker/Nspawn
#
# /proc/self/cgroup will look like this inside a docker container:
# <index #>:<subsystem>:/lxc/<hexadecimal container id>
@@ -190,6 +190,11 @@ Ohai.plugin(:Virtualization) do
virtualization[:system] = "lxc"
virtualization[:role] = "guest"
virtualization[:systems][:lxc] = "guest"
+ elsif File.read("/proc/1/environ") =~ /container=systemd-nspawn/
+ Ohai::Log.debug("Plugin Virtualization: /proc/1/environ indicates nspawn container. Detecting as nspawn guest")
+ virtualization[:system] = "nspawn"
+ virtualization[:role] = "guest"
+ virtualization[:systems][:nspawn] = "guest"
elsif lxc_version_exists? && File.read("/proc/self/cgroup") =~ %r{\d:[^:]+:/$}
# lxc-version shouldn't be installed by default
# Even so, it is likely we are on an LXC capable host that is not being used as such
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index eb67e89b..aea96b13 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -40,6 +40,7 @@ describe Ohai::System, "Linux virtualization platform" do
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)
@@ -627,6 +628,19 @@ CGROUP
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)
+ allow(File).to receive(:exist?).with("/proc/1/environ").and_return(false)
+ 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
self_cgroup = <<-CGROUP