rightscale-ohai 0.3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +98 -0
- data/Rakefile +59 -0
- data/bin/ohai +78 -0
- data/lib/ohai/config.rb +118 -0
- data/lib/ohai/exception.rb +23 -0
- data/lib/ohai/log/formatter.rb +57 -0
- data/lib/ohai/log.rb +89 -0
- data/lib/ohai/mixin/command.rb +203 -0
- data/lib/ohai/mixin/from_file.rb +36 -0
- data/lib/ohai/mixin/string.rb +29 -0
- data/lib/ohai/plugins/cloud.rb +35 -0
- data/lib/ohai/plugins/command.rb +21 -0
- data/lib/ohai/plugins/darwin/filesystem.rb +57 -0
- data/lib/ohai/plugins/darwin/hostname.rb +22 -0
- data/lib/ohai/plugins/darwin/kernel.rb +37 -0
- data/lib/ohai/plugins/darwin/network.rb +187 -0
- data/lib/ohai/plugins/darwin/platform.rb +36 -0
- data/lib/ohai/plugins/darwin/ps.rb +23 -0
- data/lib/ohai/plugins/darwin/ssh_host_key.rb +25 -0
- data/lib/ohai/plugins/darwin/system_profiler.rb +33 -0
- data/lib/ohai/plugins/darwin/uptime.rb +32 -0
- data/lib/ohai/plugins/dmi.rb +59 -0
- data/lib/ohai/plugins/ec2.rb +100 -0
- data/lib/ohai/plugins/erlang.rb +40 -0
- data/lib/ohai/plugins/freebsd/cpu.rb +52 -0
- data/lib/ohai/plugins/freebsd/filesystem.rb +57 -0
- data/lib/ohai/plugins/freebsd/hostname.rb +22 -0
- data/lib/ohai/plugins/freebsd/kernel.rb +37 -0
- data/lib/ohai/plugins/freebsd/memory.rb +50 -0
- data/lib/ohai/plugins/freebsd/network.rb +112 -0
- data/lib/ohai/plugins/freebsd/platform.rb +23 -0
- data/lib/ohai/plugins/freebsd/ps.rb +24 -0
- data/lib/ohai/plugins/freebsd/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/freebsd/uptime.rb +32 -0
- data/lib/ohai/plugins/freebsd/virtualization.rb +66 -0
- data/lib/ohai/plugins/hostname.rb +27 -0
- data/lib/ohai/plugins/java.rb +36 -0
- data/lib/ohai/plugins/kernel.rb +33 -0
- data/lib/ohai/plugins/keys.rb +22 -0
- data/lib/ohai/plugins/languages.rb +21 -0
- data/lib/ohai/plugins/linux/block_device.rb +38 -0
- data/lib/ohai/plugins/linux/cpu.rb +60 -0
- data/lib/ohai/plugins/linux/filesystem.rb +57 -0
- data/lib/ohai/plugins/linux/hostname.rb +26 -0
- data/lib/ohai/plugins/linux/kernel.rb +33 -0
- data/lib/ohai/plugins/linux/lsb.rb +38 -0
- data/lib/ohai/plugins/linux/memory.rb +83 -0
- data/lib/ohai/plugins/linux/network.rb +112 -0
- data/lib/ohai/plugins/linux/platform.rb +43 -0
- data/lib/ohai/plugins/linux/ps.rb +23 -0
- data/lib/ohai/plugins/linux/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/linux/uptime.rb +28 -0
- data/lib/ohai/plugins/linux/virtualization.rb +77 -0
- data/lib/ohai/plugins/network.rb +52 -0
- data/lib/ohai/plugins/ohai_time.rb +21 -0
- data/lib/ohai/plugins/os.rb +43 -0
- data/lib/ohai/plugins/perl.rb +37 -0
- data/lib/ohai/plugins/platform.rb +25 -0
- data/lib/ohai/plugins/python.rb +37 -0
- data/lib/ohai/plugins/rightscale.rb +53 -0
- data/lib/ohai/plugins/ruby.rb +37 -0
- data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
- data/lib/ohai/plugins/solaris2/hostname.rb +22 -0
- data/lib/ohai/plugins/solaris2/kernel.rb +21 -0
- data/lib/ohai/plugins/solaris2/network.rb +141 -0
- data/lib/ohai/plugins/solaris2/platform.rb +33 -0
- data/lib/ohai/plugins/solaris2/ps.rb +23 -0
- data/lib/ohai/plugins/solaris2/ssh_host_key.rb +26 -0
- data/lib/ohai/plugins/uptime.rb +42 -0
- data/lib/ohai/plugins/virtualization.rb +86 -0
- data/lib/ohai/plugins/windows/filesystem.rb +44 -0
- data/lib/ohai/plugins/windows/hostname.rb +25 -0
- data/lib/ohai/plugins/windows/kernel.rb +75 -0
- data/lib/ohai/plugins/windows/network.rb +114 -0
- data/lib/ohai/plugins/windows/platform.rb +26 -0
- data/lib/ohai/system.rb +226 -0
- data/lib/ohai.rb +27 -0
- data/spec/ohai/log/log_formatter_spec.rb +50 -0
- data/spec/ohai/log_spec.rb +63 -0
- data/spec/ohai/mixin/from_file_spec.rb +53 -0
- data/spec/ohai/plugins/cloud_spec.rb +64 -0
- data/spec/ohai/plugins/darwin/hostname_spec.rb +34 -0
- data/spec/ohai/plugins/darwin/kernel_spec.rb +46 -0
- data/spec/ohai/plugins/darwin/platform_spec.rb +67 -0
- data/spec/ohai/plugins/dmi_spec.rb +73 -0
- data/spec/ohai/plugins/ec2_spec.rb +77 -0
- data/spec/ohai/plugins/erlang_spec.rb +63 -0
- data/spec/ohai/plugins/freebsd/hostname_spec.rb +34 -0
- data/spec/ohai/plugins/freebsd/kernel_spec.rb +37 -0
- data/spec/ohai/plugins/freebsd/platform_spec.rb +40 -0
- data/spec/ohai/plugins/hostname_spec.rb +39 -0
- data/spec/ohai/plugins/java_spec.rb +70 -0
- data/spec/ohai/plugins/kernel_spec.rb +43 -0
- data/spec/ohai/plugins/linux/cpu_spec.rb +128 -0
- data/spec/ohai/plugins/linux/hostname_spec.rb +52 -0
- data/spec/ohai/plugins/linux/kernel_spec.rb +31 -0
- data/spec/ohai/plugins/linux/lsb_spec.rb +60 -0
- data/spec/ohai/plugins/linux/platform_spec.rb +81 -0
- data/spec/ohai/plugins/linux/uptime_spec.rb +61 -0
- data/spec/ohai/plugins/linux/virtualization_spec.rb +131 -0
- data/spec/ohai/plugins/ohai_time_spec.rb +46 -0
- data/spec/ohai/plugins/os_spec.rb +58 -0
- data/spec/ohai/plugins/perl_spec.rb +89 -0
- data/spec/ohai/plugins/platform_spec.rb +56 -0
- data/spec/ohai/plugins/python_spec.rb +53 -0
- data/spec/ohai/plugins/rightscale_spec.rb +71 -0
- data/spec/ohai/plugins/ruby_spec.rb +51 -0
- data/spec/ohai/system_spec.rb +130 -0
- data/spec/ohai_spec.rb +27 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +66 -0
- metadata +209 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
|
21
|
+
|
22
|
+
describe Ohai::System, "Linux hostname plugin" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@ohai[:os] = "linux"
|
27
|
+
@ohai.stub!(:from).with("hostname -s").and_return("katie")
|
28
|
+
@ohai.stub!(:from).with("hostname --fqdn").and_return("katie.bethell")
|
29
|
+
end
|
30
|
+
|
31
|
+
it_should_check_from("linux::hostname", "hostname", "hostname -s", "katie")
|
32
|
+
|
33
|
+
it_should_check_from("linux::hostname", "fqdn", "hostname --fqdn", "katie.bethell")
|
34
|
+
|
35
|
+
describe "when domain name is unset" do
|
36
|
+
before(:each) do
|
37
|
+
@ohai.should_receive(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not raise an error" do
|
41
|
+
lambda { @ohai._require_plugin("linux::hostname") }.should_not raise_error
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not set fqdn" do
|
45
|
+
@ohai._require_plugin("linux::hostname")
|
46
|
+
@ohai.fqdn.should == nil
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
|
21
|
+
|
22
|
+
describe Ohai::System, "Linux kernel plugin" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai._require_plugin("kernel")
|
26
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
27
|
+
@ohai.stub!(:from).with("uname -o").and_return("Linux")
|
28
|
+
end
|
29
|
+
|
30
|
+
it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", "Linux")
|
31
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
|
21
|
+
|
22
|
+
describe Ohai::System, "Linux lsb plugin" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai[:os] = "linux"
|
26
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
27
|
+
@mock_file = mock("/etc/lsb-release")
|
28
|
+
@mock_file.stub!(:each).
|
29
|
+
and_yield("DISTRIB_ID=Ubuntu").
|
30
|
+
and_yield("DISTRIB_RELEASE=8.04").
|
31
|
+
and_yield("DISTRIB_CODENAME=hardy").
|
32
|
+
and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"')
|
33
|
+
File.stub!(:open).with("/etc/lsb-release").and_return(@mock_file)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should set lsb[:id]" do
|
37
|
+
@ohai._require_plugin("linux::lsb")
|
38
|
+
@ohai[:lsb][:id].should == "Ubuntu"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set lsb[:release]" do
|
42
|
+
@ohai._require_plugin("linux::lsb")
|
43
|
+
@ohai[:lsb][:release].should == "8.04"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should set lsb[:codename]" do
|
47
|
+
@ohai._require_plugin("linux::lsb")
|
48
|
+
@ohai[:lsb][:codename].should == "hardy"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set lsb[:description]" do
|
52
|
+
@ohai._require_plugin("linux::lsb")
|
53
|
+
@ohai[:lsb][:description].should == "\"Ubuntu 8.04\""
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not set any lsb values if /etc/lsb-release cannot be read" do
|
57
|
+
File.stub!(:open).with("/etc/lsb-release").and_raise(IOError)
|
58
|
+
@ohai.attribute?(:lsb).should be(false)
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
|
21
|
+
|
22
|
+
describe Ohai::System, "Linux plugin platform" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@ohai.extend(SimpleFromFile)
|
27
|
+
@ohai[:os] = "linux"
|
28
|
+
@ohai[:lsb] = Mash.new
|
29
|
+
File.stub!(:exists?).with("/etc/debian_version").and_return(false)
|
30
|
+
File.stub!(:exists?).with("/etc/redhat-release").and_return(false)
|
31
|
+
File.stub!(:exists?).with("/etc/gentoo-release").and_return(false)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should require the lsb plugin" do
|
35
|
+
@ohai.should_receive(:require_plugin).with("linux::lsb").and_return(true)
|
36
|
+
@ohai._require_plugin("linux::platform")
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "on lsb compliant distributions" do
|
40
|
+
before(:each) do
|
41
|
+
@ohai[:lsb][:id] = "Ubuntu"
|
42
|
+
@ohai[:lsb][:release] = "8.04"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set platform to lowercased lsb[:id]" do
|
46
|
+
@ohai._require_plugin("linux::platform")
|
47
|
+
@ohai[:platform].should == "ubuntu"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set platform_version to lsb[:release]" do
|
51
|
+
@ohai._require_plugin("linux::platform")
|
52
|
+
@ohai[:platform_version].should == "8.04"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "on debian" do
|
57
|
+
before(:each) do
|
58
|
+
@ohai.lsb = nil
|
59
|
+
File.should_receive(:exists?).with("/etc/debian_version").and_return(true)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should check for the existance of debian_version" do
|
63
|
+
@ohai._require_plugin("linux::platform")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should read the version from /etc/debian_version" do
|
67
|
+
File.should_receive(:read).with("/etc/debian_version").and_return("5.0")
|
68
|
+
@ohai._require_plugin("linux::platform")
|
69
|
+
@ohai[:platform_version].should == "5.0"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should correctly strip any newlines" do
|
73
|
+
File.should_receive(:read).with("/etc/debian_version").and_return("5.0\n")
|
74
|
+
@ohai._require_plugin("linux::platform")
|
75
|
+
@ohai[:platform_version].should == "5.0"
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
|
21
|
+
|
22
|
+
describe Ohai::System, "Linux plugin uptime" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@ohai[:os] = "linux"
|
27
|
+
@ohai._require_plugin("uptime")
|
28
|
+
@mock_file = mock("/proc/uptime", { :gets => "18423 989" })
|
29
|
+
File.stub!(:open).with("/proc/uptime").and_return(@mock_file)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should check /proc/uptime for the uptime and idletime" do
|
33
|
+
File.should_receive(:open).with("/proc/uptime").and_return(@mock_file)
|
34
|
+
@ohai._require_plugin("linux::uptime")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should split the value of /proc uptime" do
|
38
|
+
@mock_file.gets.should_receive(:split).with(" ").and_return(["18423", "989"])
|
39
|
+
@ohai._require_plugin("linux::uptime")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set uptime_seconds to uptime" do
|
43
|
+
@ohai._require_plugin("linux::uptime")
|
44
|
+
@ohai[:uptime_seconds].should == 18423
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set uptime to a human readable date" do
|
48
|
+
@ohai._require_plugin("linux::uptime")
|
49
|
+
@ohai[:uptime].should == "5 hours 07 minutes 03 seconds"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should set idletime_seconds to uptime" do
|
53
|
+
@ohai._require_plugin("linux::uptime")
|
54
|
+
@ohai[:idletime_seconds].should == 989
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set idletime to a human readable date" do
|
58
|
+
@ohai._require_plugin("linux::uptime")
|
59
|
+
@ohai[:idletime].should == "16 minutes 29 seconds"
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Thom May (<thom@clearairturbulence.org>)
|
3
|
+
# Copyright:: Copyright (c) 2009 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '/spec_helper.rb')
|
20
|
+
|
21
|
+
describe Ohai::System, "Linux virtualization platform" do
|
22
|
+
before(:each) do
|
23
|
+
@ohai = Ohai::System.new
|
24
|
+
@ohai[:os] = "linux"
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@ohai.extend(SimpleFromFile)
|
27
|
+
|
28
|
+
# default to all requested Files not existing
|
29
|
+
File.stub!(:exists?).with("/proc/xen/capabilities").and_return(false)
|
30
|
+
File.stub!(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(false)
|
31
|
+
File.stub!(:exists?).with("/proc/modules").and_return(false)
|
32
|
+
File.stub!(:exists?).with("/proc/cpuinfo").and_return(false)
|
33
|
+
File.stub!(:exists?).with("/usr/sbin/dmidecode").and_return(false)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "when we are checking for xen" do
|
37
|
+
it "should set xen host if /proc/xen/capabilities contains control_d" do
|
38
|
+
File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
|
39
|
+
File.stub!(:read).with("/proc/xen/capabilities").and_return("control_d")
|
40
|
+
@ohai._require_plugin("linux::virtualization")
|
41
|
+
@ohai[:virtualization][:emulator].should == "xen"
|
42
|
+
@ohai[:virtualization][:role].should == "host"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set xen guest if /proc/sys/xen/independent_wallclock exists" do
|
46
|
+
File.should_receive(:exists?).with("/proc/sys/xen/independent_wallclock").and_return(true)
|
47
|
+
@ohai._require_plugin("linux::virtualization")
|
48
|
+
@ohai[:virtualization][:emulator].should == "xen"
|
49
|
+
@ohai[:virtualization][:role].should == "guest"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not set virtualization if xen isn't there" do
|
53
|
+
File.should_receive(:exists?).at_least(:once).and_return(false)
|
54
|
+
@ohai._require_plugin("linux::virtualization")
|
55
|
+
@ohai[:virtualization].should == {}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "when we are checking for kvm" do
|
60
|
+
it "should set kvm host if /proc/modules contains kvm" do
|
61
|
+
File.should_receive(:exists?).with("/proc/modules").and_return(true)
|
62
|
+
File.stub!(:read).with("/proc/modules").and_return("kvm 165872 1 kvm_intel")
|
63
|
+
@ohai._require_plugin("linux::virtualization")
|
64
|
+
@ohai[:virtualization][:emulator].should == "kvm"
|
65
|
+
@ohai[:virtualization][:role].should == "host"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set kvm guest if /proc/cpuinfo contains QEMU Virtual CPU" do
|
69
|
+
File.should_receive(:exists?).with("/proc/cpuinfo").and_return(true)
|
70
|
+
File.stub!(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
|
71
|
+
@ohai._require_plugin("linux::virtualization")
|
72
|
+
@ohai[:virtualization][:emulator].should == "kvm"
|
73
|
+
@ohai[:virtualization][:role].should == "guest"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should not set virtualization if kvm isn't there" do
|
77
|
+
File.should_receive(:exists?).at_least(:once).and_return(false)
|
78
|
+
@ohai._require_plugin("linux::virtualization")
|
79
|
+
@ohai[:virtualization].should == {}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "when we are parsing dmidecode" do
|
84
|
+
before(:each) do
|
85
|
+
File.should_receive(:exists?).with("/usr/sbin/dmidecode").and_return(true)
|
86
|
+
@stdin = mock("STDIN", { :close => true })
|
87
|
+
@pid = 10
|
88
|
+
@stderr = mock("STDERR")
|
89
|
+
@stdout = mock("STDOUT")
|
90
|
+
@status = 0
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should run dmidecode" do
|
94
|
+
@ohai.should_receive(:popen4).with("dmidecode").and_return(true)
|
95
|
+
@ohai._require_plugin("linux::virtualization")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should set virtualpc guest if dmidecode detects Microsoft Virtual Machine" do
|
99
|
+
@stdout.stub!(:each).
|
100
|
+
and_yield("Manufacturer: Microsoft").
|
101
|
+
and_yield(" Product Name: Virtual Machine")
|
102
|
+
@ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
103
|
+
@ohai._require_plugin("linux::virtualization")
|
104
|
+
@ohai[:virtualization][:emulator].should == "virtualpc"
|
105
|
+
@ohai[:virtualization][:role].should == "guest"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should set vmware guest if dmidecode detects VMware Virtual Platform" do
|
109
|
+
@stdout.stub!(:each).
|
110
|
+
and_yield("Manufacturer: VMware").
|
111
|
+
and_yield("Product Name: VMware Virtual Platform")
|
112
|
+
@ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
|
113
|
+
@ohai._require_plugin("linux::virtualization")
|
114
|
+
@ohai[:virtualization][:emulator].should == "vmware"
|
115
|
+
@ohai[:virtualization][:role].should == "guest"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should run dmidecode and not set virtualization if nothing is detected" do
|
119
|
+
@ohai.should_receive(:popen4).with("dmidecode").and_return(true)
|
120
|
+
@ohai._require_plugin("linux::virtualization")
|
121
|
+
@ohai[:virtualization].should == {}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should not set virtualization if no tests match" do
|
126
|
+
@ohai._require_plugin("linux::virtualization")
|
127
|
+
@ohai[:virtualization].should == {}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
|
21
|
+
|
22
|
+
describe Ohai::System, "plugin ohai_time" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should get the current time" do
|
29
|
+
Time.should_receive(:now)
|
30
|
+
@ohai._require_plugin("ohai_time")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should turn the time into a floating point number" do
|
34
|
+
time = Time.now
|
35
|
+
time.should_receive(:to_f)
|
36
|
+
Time.stub!(:now).and_return(time)
|
37
|
+
@ohai._require_plugin("ohai_time")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should set ohai_time to the current time" do
|
41
|
+
time = Time.now
|
42
|
+
Time.stub!(:now).and_return(time)
|
43
|
+
@ohai._require_plugin("ohai_time")
|
44
|
+
@ohai[:ohai_time].should == time.to_f
|
45
|
+
end
|
46
|
+
end
|