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,58 @@
|
|
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 os" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@ohai[:languages] = Mash.new
|
27
|
+
@ohai[:languages][:ruby] = Mash.new
|
28
|
+
@ohai[:kernel] = Mash.new
|
29
|
+
@ohai[:kernel][:release] = "kings of leon"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set os_version to kernel_release" do
|
33
|
+
@ohai._require_plugin("os")
|
34
|
+
@ohai[:os_version].should == @ohai[:kernel][:release]
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "on linux" do
|
38
|
+
before(:each) do
|
39
|
+
@ohai[:languages][:ruby][:host_os] = "linux"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set the os to linux" do
|
43
|
+
@ohai._require_plugin("os")
|
44
|
+
@ohai[:os].should == "linux"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "on darwin" do
|
49
|
+
before(:each) do
|
50
|
+
@ohai[:languages][:ruby][:host_os] = "darwin"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set the os to darwin" do
|
54
|
+
@ohai._require_plugin("os")
|
55
|
+
@ohai[:os].should == "darwin"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Joshua Timberman(<joshua@opscode.com>)
|
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, "plugin perl" do
|
22
|
+
before(:each) do
|
23
|
+
@ohai = Ohai::System.new
|
24
|
+
@ohai[:languages] = Mash.new
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@pid = mock("PID", :null_object => true)
|
27
|
+
@stderr = mock("STDERR", :null_object => true)
|
28
|
+
@stdout = mock("STDOUT", :null_object => true)
|
29
|
+
@stdout.stub!(:each).and_yield("version='5.8.8';").
|
30
|
+
and_yield("archname='darwin-thread-multi-2level';")
|
31
|
+
@stdin = mock("STDIN", :null_object => true)
|
32
|
+
@status = 0
|
33
|
+
@ohai.stub!(:popen4).with("perl -V:version -V:archname").and_yield(
|
34
|
+
@pid,
|
35
|
+
@stdin,
|
36
|
+
@stdout,
|
37
|
+
@stderr
|
38
|
+
).and_return(@status)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should run perl -V:version -V:archname" do
|
42
|
+
@ohai.should_receive(:popen4).with("perl -V:version -V:archname").and_return(true)
|
43
|
+
@ohai._require_plugin("perl")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should close perl command's stdin" do
|
47
|
+
@stdin.should_receive(:close)
|
48
|
+
@ohai._require_plugin("perl")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should iterate over each line of perl command's stdout" do
|
52
|
+
@stdout.should_receive(:each).and_return(true)
|
53
|
+
@ohai._require_plugin("perl")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set languages[:perl][:version]" do
|
57
|
+
@ohai._require_plugin("perl")
|
58
|
+
@ohai.languages[:perl][:version].should eql("5.8.8")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set languages[:perl][:archname]" do
|
62
|
+
@ohai._require_plugin("perl")
|
63
|
+
@ohai.languages[:perl][:archname].should eql("darwin-thread-multi-2level")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should set languages[:perl] if perl command succeeds" do
|
67
|
+
@status = 0
|
68
|
+
@ohai.stub!(:popen4).with("perl -V:version -V:archname").and_yield(
|
69
|
+
@pid,
|
70
|
+
@stdin,
|
71
|
+
@stdout,
|
72
|
+
@stderr
|
73
|
+
).and_return(@status)
|
74
|
+
@ohai._require_plugin("perl")
|
75
|
+
@ohai.languages.should have_key(:perl)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not set languages[:perl] if perl command fails" do
|
79
|
+
@status = 1
|
80
|
+
@ohai.stub!(:popen4).with("perl -V:version -V:archname").and_yield(
|
81
|
+
@pid,
|
82
|
+
@stdin,
|
83
|
+
@stdout,
|
84
|
+
@stderr
|
85
|
+
).and_return(@status)
|
86
|
+
@ohai._require_plugin("perl")
|
87
|
+
@ohai.languages.should_not have_key(:perl)
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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 platform" do
|
23
|
+
before(:each) do
|
24
|
+
@ohai = Ohai::System.new
|
25
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
26
|
+
@ohai[:os] = 'monkey'
|
27
|
+
@ohai[:os_version] = 'poop'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should require the os platform plugin" do
|
31
|
+
@ohai.should_receive(:require_plugin).with("monkey::platform")
|
32
|
+
@ohai._require_plugin("platform")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should set the platform to the os if it was not set earlier" do
|
36
|
+
@ohai._require_plugin("platform")
|
37
|
+
@ohai[:platform].should eql("monkey")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not set the platform to the os if it was set earlier" do
|
41
|
+
@ohai[:platform] = 'lars'
|
42
|
+
@ohai._require_plugin("platform")
|
43
|
+
@ohai[:platform].should eql("lars")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should set the platform_version to the os_version if it was not set earlier" do
|
47
|
+
@ohai._require_plugin("platform")
|
48
|
+
@ohai[:os_version].should eql("poop")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not set the platform to the os if it was set earlier" do
|
52
|
+
@ohai[:platform_version] = 'ulrich'
|
53
|
+
@ohai._require_plugin("platform")
|
54
|
+
@ohai[:platform_version].should eql("ulrich")
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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 python" do
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
@ohai = Ohai::System.new
|
26
|
+
@ohai[:languages] = Mash.new
|
27
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
28
|
+
@status = 0
|
29
|
+
@stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n"
|
30
|
+
@stderr = ""
|
31
|
+
@ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr])
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should get the python version from printing sys.version and sys.platform" do
|
35
|
+
@ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([0, "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n", ""])
|
36
|
+
@ohai._require_plugin("python")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set languages[:python][:version]" do
|
40
|
+
@ohai._require_plugin("python")
|
41
|
+
@ohai.languages[:python][:version].should eql("2.5.2")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not set the languages[:python] tree up if python command fails" do
|
45
|
+
@status = 1
|
46
|
+
@stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n"
|
47
|
+
@stderr = ""
|
48
|
+
@ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr])
|
49
|
+
@ohai._require_plugin("python")
|
50
|
+
@ohai.languages.should_not have_key(:python)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Cary Penniman (<cary@rightscale.com>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
|
19
|
+
|
20
|
+
describe Ohai::System, "plugin rightscale" do
|
21
|
+
before(:each) do
|
22
|
+
@ohai = Ohai::System.new
|
23
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "ec2 with RightScale platform" do
|
27
|
+
before(:each) do
|
28
|
+
@ohai[:ec2] = Mash.new()
|
29
|
+
@ohai[:ec2][:userdata] = "RS_api_url=https:\/\/my.rightscale.com\/api\/inst\/ec2_instances\/c18c07eb8d33456db3d75fe65c56e8bae94d8f59&RS_server=my.rightscale.com&RS_sketchy=sketchy1-12.rightscale.com&RS_token=e668bb0be59d061b8b60f08765902a90"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should create rightscale mash" do
|
33
|
+
@ohai._require_plugin("rightscale")
|
34
|
+
@ohai[:rightscale].should_not be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should create rightscale server mash" do
|
38
|
+
@ohai._require_plugin("rightscale")
|
39
|
+
@ohai[:rightscale][:server].should_not be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should populate sketchy server attribute" do
|
43
|
+
@ohai._require_plugin("rightscale")
|
44
|
+
@ohai[:rightscale][:server]['sketchy'].should == "sketchy1-12.rightscale.com"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should populate core server attribute" do
|
48
|
+
@ohai._require_plugin("rightscale")
|
49
|
+
@ohai[:rightscale][:server][:core].should == "my.rightscale.com"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should populate token attribute" do
|
53
|
+
@ohai._require_plugin("rightscale")
|
54
|
+
@ohai[:rightscale][:token].should == "e668bb0be59d061b8b60f08765902a90"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "ec2 without rightscale" do
|
60
|
+
before(:each) do
|
61
|
+
@ohai[:ec2] = Mash.new()
|
62
|
+
@ohai[:ec2][:userdata] = "some other form of userdata"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should NOT populate the rightscale data" do
|
66
|
+
@ohai._require_plugin("rightscale")
|
67
|
+
@ohai[:rightscale].should be_nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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 ruby" do
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
@ohai = Ohai::System.new
|
26
|
+
@ohai[:languages] = Mash.new
|
27
|
+
@ohai.stub!(:require_plugin).and_return(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
{
|
31
|
+
:platform => RUBY_PLATFORM,
|
32
|
+
:version => RUBY_VERSION,
|
33
|
+
:release_date => RUBY_RELEASE_DATE,
|
34
|
+
:target => ::Config::CONFIG['target'],
|
35
|
+
:target_cpu => ::Config::CONFIG['target_cpu'],
|
36
|
+
:target_vendor => ::Config::CONFIG['target_vendor'],
|
37
|
+
:target_os => ::Config::CONFIG['target_os'],
|
38
|
+
:host => ::Config::CONFIG['host'],
|
39
|
+
:host_cpu => ::Config::CONFIG['host_cpu'],
|
40
|
+
:host_os => ::Config::CONFIG['host_os'],
|
41
|
+
:host_vendor => ::Config::CONFIG['host_vendor'],
|
42
|
+
:gems_dir => %x{#{::Config::CONFIG['bindir']}/gem env gemdir}.chomp!,
|
43
|
+
:ruby_bin => File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name'])
|
44
|
+
}.each do |attribute, value|
|
45
|
+
it "should have #{attribute} set" do
|
46
|
+
@ohai._require_plugin("ruby")
|
47
|
+
@ohai[:languages][:ruby][attribute].should eql(value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,130 @@
|
|
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
|
+
require File.join(File.dirname(__FILE__), '..', '/spec_helper.rb')
|
20
|
+
|
21
|
+
describe Ohai::System, "initialize" do
|
22
|
+
it "should return an Ohai::System object" do
|
23
|
+
Ohai::System.new.should be_a_kind_of(Ohai::System)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should set @data to a Mash" do
|
27
|
+
Ohai::System.new.data.should be_a_kind_of(Mash)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set @seen_plugins to a Hash" do
|
31
|
+
Ohai::System.new.seen_plugins.should be_a_kind_of(Hash)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Ohai::System, "method_missing" do
|
36
|
+
before(:each) do
|
37
|
+
@ohai = Ohai::System.new
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should take a missing method and store the method name as a key, with its arguments as values" do
|
41
|
+
@ohai.guns_n_roses("chinese democracy")
|
42
|
+
@ohai.data["guns_n_roses"].should eql("chinese democracy")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the current value of the method name" do
|
46
|
+
@ohai.guns_n_roses("chinese democracy").should eql("chinese democracy")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should allow you to get the value of a key by calling method_missing with no arguments" do
|
50
|
+
@ohai.guns_n_roses("chinese democracy")
|
51
|
+
@ohai.guns_n_roses.should eql("chinese democracy")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe Ohai::System, "attribute?" do
|
56
|
+
before(:each) do
|
57
|
+
@ohai = Ohai::System.new
|
58
|
+
@ohai.metallica("death magnetic")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return true if an attribute exists with the given name" do
|
62
|
+
@ohai.attribute?("metallica").should eql(true)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return false if an attribute does not exist with the given name" do
|
66
|
+
@ohai.attribute?("alice in chains").should eql(false)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe Ohai::System, "set_attribute" do
|
71
|
+
before(:each) do
|
72
|
+
@ohai = Ohai::System.new
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should let you set an attribute" do
|
76
|
+
@ohai.set_attribute(:tea, "is soothing")
|
77
|
+
@ohai.data["tea"].should eql("is soothing")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe Ohai::System, "get_attribute" do
|
82
|
+
before(:each) do
|
83
|
+
@ohai = Ohai::System.new
|
84
|
+
@ohai.set_attribute(:tea, "is soothing")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should let you get an attribute" do
|
88
|
+
@ohai.get_attribute("tea").should eql("is soothing")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe Ohai::System, "require_plugin" do
|
93
|
+
before(:each) do
|
94
|
+
@plugin_path = Ohai::Config[:plugin_path]
|
95
|
+
Ohai::Config[:plugin_path] = ["/tmp/plugins"]
|
96
|
+
File.stub!(:exists?).and_return(true)
|
97
|
+
@ohai = Ohai::System.new
|
98
|
+
@ohai.stub!(:from_file).and_return(true)
|
99
|
+
end
|
100
|
+
|
101
|
+
after(:each) do
|
102
|
+
Ohai::Config[:plugin_path] = @plugin_path
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should convert the name of the plugin to a file path" do
|
106
|
+
plugin_name = "foo::bar"
|
107
|
+
plugin_name.should_receive(:gsub).with("::", File::SEPARATOR)
|
108
|
+
@ohai.require_plugin(plugin_name)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should check each part of the Ohai::Config[:plugin_path] for the plugin_filename.rb" do
|
112
|
+
@ohai.should_receive(:from_file).with("/tmp/plugins/foo.rb").and_return(true)
|
113
|
+
@ohai.require_plugin("foo")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should add a found plugin to the list of seen plugins" do
|
117
|
+
@ohai.require_plugin("foo")
|
118
|
+
@ohai.seen_plugins["foo"].should eql(true)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should return true if the plugin has been seen" do
|
122
|
+
@ohai.seen_plugins["foo"] = true
|
123
|
+
@ohai.require_plugin("foo")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return true if the plugin has been loaded" do
|
127
|
+
@ohai.require_plugin("foo").should eql(true)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|