summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2016-03-08 20:17:47 -0800
committerTim Smith <tsmith@chef.io>2016-03-08 20:17:47 -0800
commit97d8a882e8e153cd4a27d861493500d3053aa472 (patch)
treeae7e85a841e169806762b72d63f77cb78228d3a5
parent7a59cf991eaea00fa115bbfbe5e2bd40af285b57 (diff)
parent0a626034cfe572c94606b2ebae1aae29201620cf (diff)
downloadohai-97d8a882e8e153cd4a27d861493500d3053aa472.tar.gz
Merge pull request #751 from tas50/private_clouds_4_life
Detect Openstack hosts
-rw-r--r--lib/ohai/plugins/linux/virtualization.rb11
-rw-r--r--lib/ohai/util/file_helper.rb6
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb15
-rw-r--r--spec/unit/util/file_helper_spec.rb1
4 files changed, 32 insertions, 1 deletions
diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb
index 4ac4d212..189bf444 100644
--- a/lib/ohai/plugins/linux/virtualization.rb
+++ b/lib/ohai/plugins/linux/virtualization.rb
@@ -33,6 +33,10 @@ Ohai.plugin(:Virtualization) do
which("docker")
end
+ def nova_exists?
+ which("nova")
+ end
+
collect_data(:linux) do
virtualization Mash.new unless virtualization
virtualization[:systems] = Mash.new unless virtualization[:systems]
@@ -74,6 +78,13 @@ Ohai.plugin(:Virtualization) do
end
end
+ # if nova binary is present we're on an openstack host
+ if nova_exists?
+ virtualization[:system] = "openstack"
+ virtualization[:role] = "host"
+ virtualization[:systems][:openstack] = "host"
+ end
+
# Detect paravirt KVM/QEMU from cpuinfo, report as KVM
if File.exist?("/proc/cpuinfo")
if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/
diff --git a/lib/ohai/util/file_helper.rb b/lib/ohai/util/file_helper.rb
index 1f78d5a6..5b08e2db 100644
--- a/lib/ohai/util/file_helper.rb
+++ b/lib/ohai/util/file_helper.rb
@@ -25,8 +25,12 @@ module Ohai
paths = ENV["PATH"].split(File::PATH_SEPARATOR) + [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ]
paths.each do |path|
filename = File.join(path, cmd)
- return filename if File.executable?(filename)
+ if File.executable?(filename)
+ Ohai::Log.debug("#{self.name} plugin: found #{cmd} at #{filename}")
+ return filename
+ end
end
+ Ohai::Log.debug("#{self.name} plugin: did not find #{cmd}")
false
end
end
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index 1c6d8258..cb148acd 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -38,6 +38,11 @@ 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)
+
+ # default the which wrappers to nil
+ allow(plugin).to receive(:lxc_version_exists?).and_return(false)
+ allow(plugin).to receive(:docker_exists?).and_return(false)
+ allow(plugin).to receive(:nova_exists?).and_return(false)
end
describe "when we are checking for xen" do
@@ -77,6 +82,16 @@ describe Ohai::System, "Linux virtualization platform" do
end
end
+ describe "when we are checking for openstack" do
+ it "sets openstack host if nova binary exists" do
+ allow(plugin).to receive(:nova_exists?).and_return("/usr/bin/nova")
+ plugin.run
+ expect(plugin[:virtualization][:system]).to eq("openstack")
+ expect(plugin[:virtualization][:role]).to eq("host")
+ expect(plugin[:virtualization][:systems][:openstack]).to eq("host")
+ end
+ end
+
describe "when we are checking for kvm" do
it "sets kvm guest if /sys/devices/virtual/misc/kvm exists & hypervisor cpu feature is present" do
allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(true)
diff --git a/spec/unit/util/file_helper_spec.rb b/spec/unit/util/file_helper_spec.rb
index be68a321..f6c91cb1 100644
--- a/spec/unit/util/file_helper_spec.rb
+++ b/spec/unit/util/file_helper_spec.rb
@@ -27,6 +27,7 @@ describe "Ohai::Util::FileHelper" do
let(:file_helper) { FileHelperMock.new }
before(:each) do
+ allow(file_helper).to receive(:name).and_return("Fakeclass")
allow(File).to receive(:executable?).and_return(false)
end