summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Heinen <theinen@tecracer.de>2021-12-09 15:59:26 +0100
committerThomas Heinen <theinen@tecracer.de>2021-12-09 15:59:26 +0100
commit1da5761c8954c1b3555dedaa09ee8788f25f7f7f (patch)
treee09e645be605f666d8e9b4a531fba2eb5d9a3fee
parenta60d6f11dbd214790a09cb350927a9061c627cb3 (diff)
downloadohai-1da5761c8954c1b3555dedaa09ee8788f25f7f7f.tar.gz
Add some tests
Signed-off-by: Thomas Heinen <theinen@tecracer.de>
-rw-r--r--lib/ohai/plugins/vmware.rb2
-rw-r--r--spec/unit/plugins/vmware_spec.rb32
2 files changed, 22 insertions, 12 deletions
diff --git a/lib/ohai/plugins/vmware.rb b/lib/ohai/plugins/vmware.rb
index d5759a76..250a9e24 100644
--- a/lib/ohai/plugins/vmware.rb
+++ b/lib/ohai/plugins/vmware.rb
@@ -64,7 +64,7 @@ Ohai.plugin(:VMware) do
vmware[param] = from_cmd([vmtools_path, param, "status"])
end
# Distinguish hypervisors by presence of raw session data (vSphere only)
- raw_session = from_cmd([vmtools_path, %w{stat raw json session}])
+ raw_session = from_cmd([vmtools_path, "stat", "raw", "json", "session"])
if raw_session.empty?
vmware[:host] = {
type: "vmware_desktop",
diff --git a/spec/unit/plugins/vmware_spec.rb b/spec/unit/plugins/vmware_spec.rb
index 86d13dc4..c61700f0 100644
--- a/spec/unit/plugins/vmware_spec.rb
+++ b/spec/unit/plugins/vmware_spec.rb
@@ -28,17 +28,19 @@ describe Ohai::System, "plugin vmware" do
context "when on vmware guest with toolbox installed" do
before do
allow(File).to receive(:exist?).with("/usr/bin/vmware-toolbox-cmd").and_return(true)
- allow(plugin).to receive(:shell_out).with("#{path} stat speed").and_return(mock_shell_out(0, "2000 MHz", nil))
- allow(plugin).to receive(:shell_out).with("#{path} stat hosttime").and_return(mock_shell_out(0, "04 Jun 2015 19:21:16", nil))
- allow(plugin).to receive(:shell_out).with("#{path} stat sessionid").and_return(mock_shell_out(0, "0x0000000000000000", nil))
- allow(plugin).to receive(:shell_out).with("#{path} stat balloon").and_return(mock_shell_out(0, "0 MB", nil))
- allow(plugin).to receive(:shell_out).with("#{path} stat swap").and_return(mock_shell_out(0, "0 MB", nil))
- allow(plugin).to receive(:shell_out).with("#{path} stat memlimit").and_return(mock_shell_out(0, "4000000000 MB", nil))
- allow(plugin).to receive(:shell_out).with("#{path} stat memres").and_return(mock_shell_out(0, "0 MB", nil))
- allow(plugin).to receive(:shell_out).with("#{path} stat cpures").and_return(mock_shell_out(0, "0 MHz", nil))
- allow(plugin).to receive(:shell_out).with("#{path} stat cpulimit").and_return(mock_shell_out(0, "4000000000 MB", nil))
- allow(plugin).to receive(:shell_out).with("#{path} upgrade status").and_return(mock_shell_out(0, "VMware Tools are up-to-date.", nil))
- allow(plugin).to receive(:shell_out).with("#{path} timesync status").and_return(mock_shell_out(0, "Disabled", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "speed"]).and_return(mock_shell_out(0, "2000 MHz", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "hosttime"]).and_return(mock_shell_out(0, "04 Jun 2015 19:21:16", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "sessionid"]).and_return(mock_shell_out(0, "0x0000000000000000", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "balloon"]).and_return(mock_shell_out(0, "0 MB", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "swap"]).and_return(mock_shell_out(0, "0 MB", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "memlimit"]).and_return(mock_shell_out(0, "4000000000 MB", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "memres"]).and_return(mock_shell_out(0, "0 MB", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "cpures"]).and_return(mock_shell_out(0, "0 MHz", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "cpulimit"]).and_return(mock_shell_out(0, "4000000000 MB", nil))
+ allow(plugin).to receive(:shell_out).with([path, "upgrade", "status"]).and_return(mock_shell_out(0, "VMware Tools are up-to-date.", nil))
+ allow(plugin).to receive(:shell_out).with([path, "timesync", "status"]).and_return(mock_shell_out(0, "Disabled", nil))
+ allow(plugin).to receive(:shell_out).with([path, "stat", "raw", "json", "session"]).and_return(mock_shell_out(0, '{ "version": "VMware ESX 7.0.0 build-15843807" }', nil))
+ allow(plugin).to receive(:shell_out).with([path, "-v"]).and_return(mock_shell_out(0, "10.3.0.5330", nil))
plugin[:virtualization] = Mash.new
plugin[:virtualization][:systems] = Mash.new
plugin[:virtualization][:systems][:vmware] = Mash.new
@@ -56,6 +58,14 @@ describe Ohai::System, "plugin vmware" do
it "gets tools update status" do
expect(plugin[:vmware][:upgrade]).to eq("VMware Tools are up-to-date.")
end
+
+ it "gets tools version" do
+ expect(plugin[:vmware][:guest][:vmware_tools_version]).to eq("10.3.0.5330")
+ end
+
+ it "gets vSphere version" do
+ expect(plugin[:vmware][:host][:version]).to eq("VMware ESX 7.0.0 build-15843807")
+ end
end
context "when on vmware guest without toolbox" do