summaryrefslogtreecommitdiff
path: root/spec/unit/plugins/vmware_spec.rb
blob: c61700f02f06d37f584b2db002b8189bba20e1c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#
# Author:: "Christopher M. Luciano" <cmlucian@us.ibm.com>
# Copyright (C) 2015 IBM Corp.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "spec_helper"

describe Ohai::System, "plugin vmware" do
  let(:plugin) { get_plugin("vmware") }
  let(:path) { "/usr/bin/vmware-toolbox-cmd" }

  before do
    allow(plugin).to receive(:collect_os).and_return(:linux)
  end

  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", "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
      plugin.run
    end

    it "gets the speed" do
      expect(plugin[:vmware][:speed]).to eq("2000 MHz")
    end

    it "gets the hosttime" do
      expect(plugin[:vmware][:hosttime]).to eq("04 Jun 2015 19:21:16")
    end

    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
    it "does not create a vmware attribute" do
      plugin[:virtualization] = Mash.new
      plugin[:virtualization][:systems] = Mash.new
      plugin[:virtualization][:systems][:vmware] = Mash.new
      allow(File).to receive(:exist?).with("/usr/bin/vmware-toolbox-cmd").and_return(false)
      plugin.run
      expect(plugin).not_to have_key(:vmware)
    end
  end

  context "when on vbox guest" do
    it "does not create a vmware attribute" do
      plugin[:virtualization] = Mash.new
      plugin[:virtualization][:systems] = Mash.new
      plugin[:virtualization][:systems][:vbox] = Mash.new
      plugin.run
      expect(plugin).not_to have_key(:vmware)
    end
  end
end