summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-11-28 15:01:40 -0800
committerGitHub <noreply@github.com>2017-11-28 15:01:40 -0800
commit33f711936b9b8dfe0c5a6c5decef3d43c207ddee (patch)
treeab61e9a091117902e4def51cba13b21ed09bbd07
parent2adc1391d60ef9618d24f57c21869779c0747498 (diff)
parente3229973f96fe0920567558404b4dabde692c428 (diff)
downloadohai-33f711936b9b8dfe0c5a6c5decef3d43c207ddee.tar.gz
Merge pull request #1081 from zfjagann/master
Added systemd-nspawn virtualization detection
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb7
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb13
2 files changed, 19 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..972550b0 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,18 @@ 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)
+ 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