summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-09-07 09:40:31 +0100
committerGitHub <noreply@github.com>2016-09-07 09:40:31 +0100
commitd9584633fe261a0caec6ec4dc9bd8e7609a55fcf (patch)
treef2ac04d9b6471ebe6805d8a2d3ae0a19c261437b
parent24c7ece2ce511b250e60a77ed2f9b157720f3d69 (diff)
parent7dd82d25e70b1d58076a25eccec97bf272bb02b3 (diff)
downloadohai-d9584633fe261a0caec6ec4dc9bd8e7609a55fcf.tar.gz
Merge pull request #871 from jeunito/lxd_detection
Detect lxd
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb10
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb20
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb
index 145ec953..ec101314 100644
--- a/lib/ohai/plugins/linux/virtualization.rb
+++ b/lib/ohai/plugins/linux/virtualization.rb
@@ -194,5 +194,15 @@ Ohai.plugin(:Virtualization) do
virtualization[:role] = "guest"
virtualization[:systems][:docker] = "guest"
end
+
+ # Detect LXD
+ # See https://github.com/lxc/lxd/blob/master/doc/dev-lxd.md
+ if File.exist?("/dev/lxd/sock")
+ virtualization[:system] = "lxd"
+ virtualization[:role] = "guest"
+ elsif File.exist?("/var/lib/lxd/devlxd")
+ virtualization[:system] = "lxd"
+ virtualization[:role] = "host"
+ end
end
end
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index e9e6b15f..84870b95 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -38,6 +38,8 @@ describe Ohai::System, "Linux virtualization platform" do
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)
# default the which wrappers to nil
allow(plugin).to receive(:lxc_version_exists?).and_return(false)
@@ -464,6 +466,24 @@ OUTPUT
end
end
+ describe "when we are checking for lxd" do
+ it "sets lxc guest if /dev/lxd/sock exists" do
+ expect(File).to receive(:exist?).with("/dev/lxd/sock").and_return(true)
+
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("lxd")
+ expect(plugin[:virtualization][:role]).to eq("guest")
+ end
+
+ it "setx lxd host if /var/lib/lxd/devlxd exists" do
+ expect(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(true)
+
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("lxd")
+ expect(plugin[:virtualization][:role]).to eq("host")
+ end
+ end
+
describe "when we are checking for lxc" do
it "sets lxc guest if /proc/self/cgroup exist and there are /lxc/<hexadecimal> mounts" do
self_cgroup = <<-CGROUP