rightscale-ohai 0.3.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +98 -0
  3. data/Rakefile +59 -0
  4. data/bin/ohai +78 -0
  5. data/lib/ohai/config.rb +118 -0
  6. data/lib/ohai/exception.rb +23 -0
  7. data/lib/ohai/log/formatter.rb +57 -0
  8. data/lib/ohai/log.rb +89 -0
  9. data/lib/ohai/mixin/command.rb +203 -0
  10. data/lib/ohai/mixin/from_file.rb +36 -0
  11. data/lib/ohai/mixin/string.rb +29 -0
  12. data/lib/ohai/plugins/cloud.rb +35 -0
  13. data/lib/ohai/plugins/command.rb +21 -0
  14. data/lib/ohai/plugins/darwin/filesystem.rb +57 -0
  15. data/lib/ohai/plugins/darwin/hostname.rb +22 -0
  16. data/lib/ohai/plugins/darwin/kernel.rb +37 -0
  17. data/lib/ohai/plugins/darwin/network.rb +187 -0
  18. data/lib/ohai/plugins/darwin/platform.rb +36 -0
  19. data/lib/ohai/plugins/darwin/ps.rb +23 -0
  20. data/lib/ohai/plugins/darwin/ssh_host_key.rb +25 -0
  21. data/lib/ohai/plugins/darwin/system_profiler.rb +33 -0
  22. data/lib/ohai/plugins/darwin/uptime.rb +32 -0
  23. data/lib/ohai/plugins/dmi.rb +59 -0
  24. data/lib/ohai/plugins/ec2.rb +100 -0
  25. data/lib/ohai/plugins/erlang.rb +40 -0
  26. data/lib/ohai/plugins/freebsd/cpu.rb +52 -0
  27. data/lib/ohai/plugins/freebsd/filesystem.rb +57 -0
  28. data/lib/ohai/plugins/freebsd/hostname.rb +22 -0
  29. data/lib/ohai/plugins/freebsd/kernel.rb +37 -0
  30. data/lib/ohai/plugins/freebsd/memory.rb +50 -0
  31. data/lib/ohai/plugins/freebsd/network.rb +112 -0
  32. data/lib/ohai/plugins/freebsd/platform.rb +23 -0
  33. data/lib/ohai/plugins/freebsd/ps.rb +24 -0
  34. data/lib/ohai/plugins/freebsd/ssh_host_key.rb +26 -0
  35. data/lib/ohai/plugins/freebsd/uptime.rb +32 -0
  36. data/lib/ohai/plugins/freebsd/virtualization.rb +66 -0
  37. data/lib/ohai/plugins/hostname.rb +27 -0
  38. data/lib/ohai/plugins/java.rb +36 -0
  39. data/lib/ohai/plugins/kernel.rb +33 -0
  40. data/lib/ohai/plugins/keys.rb +22 -0
  41. data/lib/ohai/plugins/languages.rb +21 -0
  42. data/lib/ohai/plugins/linux/block_device.rb +38 -0
  43. data/lib/ohai/plugins/linux/cpu.rb +60 -0
  44. data/lib/ohai/plugins/linux/filesystem.rb +57 -0
  45. data/lib/ohai/plugins/linux/hostname.rb +26 -0
  46. data/lib/ohai/plugins/linux/kernel.rb +33 -0
  47. data/lib/ohai/plugins/linux/lsb.rb +38 -0
  48. data/lib/ohai/plugins/linux/memory.rb +83 -0
  49. data/lib/ohai/plugins/linux/network.rb +112 -0
  50. data/lib/ohai/plugins/linux/platform.rb +43 -0
  51. data/lib/ohai/plugins/linux/ps.rb +23 -0
  52. data/lib/ohai/plugins/linux/ssh_host_key.rb +26 -0
  53. data/lib/ohai/plugins/linux/uptime.rb +28 -0
  54. data/lib/ohai/plugins/linux/virtualization.rb +77 -0
  55. data/lib/ohai/plugins/network.rb +52 -0
  56. data/lib/ohai/plugins/ohai_time.rb +21 -0
  57. data/lib/ohai/plugins/os.rb +43 -0
  58. data/lib/ohai/plugins/perl.rb +37 -0
  59. data/lib/ohai/plugins/platform.rb +25 -0
  60. data/lib/ohai/plugins/python.rb +37 -0
  61. data/lib/ohai/plugins/rightscale.rb +53 -0
  62. data/lib/ohai/plugins/ruby.rb +37 -0
  63. data/lib/ohai/plugins/solaris2/cpu.rb +33 -0
  64. data/lib/ohai/plugins/solaris2/hostname.rb +22 -0
  65. data/lib/ohai/plugins/solaris2/kernel.rb +21 -0
  66. data/lib/ohai/plugins/solaris2/network.rb +141 -0
  67. data/lib/ohai/plugins/solaris2/platform.rb +33 -0
  68. data/lib/ohai/plugins/solaris2/ps.rb +23 -0
  69. data/lib/ohai/plugins/solaris2/ssh_host_key.rb +26 -0
  70. data/lib/ohai/plugins/uptime.rb +42 -0
  71. data/lib/ohai/plugins/virtualization.rb +86 -0
  72. data/lib/ohai/plugins/windows/filesystem.rb +44 -0
  73. data/lib/ohai/plugins/windows/hostname.rb +25 -0
  74. data/lib/ohai/plugins/windows/kernel.rb +75 -0
  75. data/lib/ohai/plugins/windows/network.rb +114 -0
  76. data/lib/ohai/plugins/windows/platform.rb +26 -0
  77. data/lib/ohai/system.rb +226 -0
  78. data/lib/ohai.rb +27 -0
  79. data/spec/ohai/log/log_formatter_spec.rb +50 -0
  80. data/spec/ohai/log_spec.rb +63 -0
  81. data/spec/ohai/mixin/from_file_spec.rb +53 -0
  82. data/spec/ohai/plugins/cloud_spec.rb +64 -0
  83. data/spec/ohai/plugins/darwin/hostname_spec.rb +34 -0
  84. data/spec/ohai/plugins/darwin/kernel_spec.rb +46 -0
  85. data/spec/ohai/plugins/darwin/platform_spec.rb +67 -0
  86. data/spec/ohai/plugins/dmi_spec.rb +73 -0
  87. data/spec/ohai/plugins/ec2_spec.rb +77 -0
  88. data/spec/ohai/plugins/erlang_spec.rb +63 -0
  89. data/spec/ohai/plugins/freebsd/hostname_spec.rb +34 -0
  90. data/spec/ohai/plugins/freebsd/kernel_spec.rb +37 -0
  91. data/spec/ohai/plugins/freebsd/platform_spec.rb +40 -0
  92. data/spec/ohai/plugins/hostname_spec.rb +39 -0
  93. data/spec/ohai/plugins/java_spec.rb +70 -0
  94. data/spec/ohai/plugins/kernel_spec.rb +43 -0
  95. data/spec/ohai/plugins/linux/cpu_spec.rb +128 -0
  96. data/spec/ohai/plugins/linux/hostname_spec.rb +52 -0
  97. data/spec/ohai/plugins/linux/kernel_spec.rb +31 -0
  98. data/spec/ohai/plugins/linux/lsb_spec.rb +60 -0
  99. data/spec/ohai/plugins/linux/platform_spec.rb +81 -0
  100. data/spec/ohai/plugins/linux/uptime_spec.rb +61 -0
  101. data/spec/ohai/plugins/linux/virtualization_spec.rb +131 -0
  102. data/spec/ohai/plugins/ohai_time_spec.rb +46 -0
  103. data/spec/ohai/plugins/os_spec.rb +58 -0
  104. data/spec/ohai/plugins/perl_spec.rb +89 -0
  105. data/spec/ohai/plugins/platform_spec.rb +56 -0
  106. data/spec/ohai/plugins/python_spec.rb +53 -0
  107. data/spec/ohai/plugins/rightscale_spec.rb +71 -0
  108. data/spec/ohai/plugins/ruby_spec.rb +51 -0
  109. data/spec/ohai/system_spec.rb +130 -0
  110. data/spec/ohai_spec.rb +27 -0
  111. data/spec/rcov.opts +2 -0
  112. data/spec/spec.opts +2 -0
  113. data/spec/spec_helper.rb +66 -0
  114. metadata +209 -0
data/lib/ohai.rb ADDED
@@ -0,0 +1,27 @@
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
+ $:.unshift(File.dirname(__FILE__)) unless
20
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
21
+
22
+ require 'ohai/config'
23
+ require 'ohai/system'
24
+
25
+ module Ohai
26
+ VERSION = '0.3.3'
27
+ end
@@ -0,0 +1,50 @@
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 'time'
20
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
21
+
22
+ describe Ohai::Log::Formatter do
23
+ before(:each) do
24
+ @formatter = Ohai::Log::Formatter.new
25
+ end
26
+
27
+ it "should print raw strings with msg2str(string)" do
28
+ @formatter.msg2str("nuthin new").should == "nuthin new"
29
+ end
30
+
31
+ it "should format exceptions properly with msg2str(e)" do
32
+ e = IOError.new("legendary roots crew")
33
+ @formatter.msg2str(e).should == "legendary roots crew (IOError)\n"
34
+ end
35
+
36
+ it "should format random objects via inspect with msg2str(Object)" do
37
+ @formatter.msg2str([ "black thought", "?uestlove" ]).should == '["black thought", "?uestlove"]'
38
+ end
39
+
40
+ it "should return a formatted string with call" do
41
+ time = Time.new
42
+ Ohai::Log::Formatter.show_time = true
43
+ @formatter.call("monkey", time, "test", "mos def").should == "[#{time.rfc2822}] monkey: mos def\n"
44
+ end
45
+
46
+ it "should allow you to turn the time on and off in the output" do
47
+ Ohai::Log::Formatter.show_time = false
48
+ @formatter.call("monkey", Time.new, "test", "mos def").should == "monkey: mos def\n"
49
+ end
50
+ end
@@ -0,0 +1,63 @@
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 'tempfile'
20
+ require 'logger'
21
+
22
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
23
+
24
+ describe Ohai::Log do
25
+ it "should accept regular options to Logger.new via init" do
26
+ tf = Tempfile.new("chef-test-log")
27
+ tf.open
28
+ lambda { Ohai::Log.init(STDOUT) }.should_not raise_error
29
+ lambda { Ohai::Log.init(tf) }.should_not raise_error
30
+ end
31
+
32
+ it "should set the log level with :debug, :info, :warn, :error, or :fatal" do
33
+ levels = {
34
+ :debug => Logger::DEBUG,
35
+ :info => Logger::INFO,
36
+ :warn => Logger::WARN,
37
+ :error => Logger::ERROR,
38
+ :fatal => Logger::FATAL
39
+ }
40
+ levels.each do |symbol, constant|
41
+ Ohai::Log.level(symbol)
42
+ Ohai::Log.logger.level.should == constant
43
+ end
44
+ end
45
+
46
+ it "should raise an ArgumentError if you try and set the level to something strange" do
47
+ lambda { Ohai::Log.level(:the_roots) }.should raise_error(ArgumentError)
48
+ end
49
+
50
+ it "should pass other method calls directly to logger" do
51
+ Ohai::Log.level(:debug)
52
+ Ohai::Log.should be_debug
53
+ lambda { Ohai::Log.debug("Gimme some sugar!") }.should_not raise_error
54
+ end
55
+
56
+ it "should default to STDOUT if init is called with no arguments" do
57
+ logger_mock = mock(Logger, :null_object => true)
58
+ Logger.stub!(:new).and_return(logger_mock)
59
+ Logger.should_receive(:new).with(STDOUT).and_return(logger_mock)
60
+ Ohai::Log.init
61
+ end
62
+
63
+ 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
+ require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
20
+
21
+ describe Ohai::System, "from_file" do
22
+ before(:each) do
23
+ @ohai = Ohai::System.new
24
+ File.stub!(:exists?).and_return(true)
25
+ File.stub!(:readable?).and_return(true)
26
+ IO.stub!(:read).and_return("king 'herod'")
27
+ end
28
+
29
+ it "should check to see that the file exists" do
30
+ File.should_receive(:exists?).and_return(true)
31
+ @ohai.from_file("/tmp/foo")
32
+ end
33
+
34
+ it "should check to see that the file is readable" do
35
+ File.should_receive(:readable?).and_return(true)
36
+ @ohai.from_file("/tmp/foo")
37
+ end
38
+
39
+ it "should actually read the file" do
40
+ IO.should_receive(:read).and_return("king 'herod'")
41
+ @ohai.from_file("/tmp/foo")
42
+ end
43
+
44
+ it "should call instance_eval with the contents of the file, file name, and line 1" do
45
+ @ohai.should_receive(:instance_eval).with("king 'herod'", "/tmp/foo", 1)
46
+ @ohai.from_file("/tmp/foo")
47
+ end
48
+
49
+ it "should raise an IOError if it cannot read the file" do
50
+ File.stub!(:exists?).and_return(false)
51
+ lambda { @ohai.from_file("/tmp/foo") }.should raise_error(IOError)
52
+ end
53
+ end
@@ -0,0 +1,64 @@
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 cloud" do
21
+ before(:each) do
22
+ @ohai = Ohai::System.new
23
+ @ohai.stub!(:require_plugin).and_return(true)
24
+ end
25
+
26
+ describe "no cloud" do
27
+ it "should NOT populate the cloud data" do
28
+ @ohai[:e2] = nil
29
+ @ohai._require_plugin("cloud")
30
+ @ohai[:cloud].should be_nil
31
+ end
32
+ end
33
+
34
+ describe "with EC2" do
35
+ before(:each) do
36
+ @ohai[:ec2] = Mash.new()
37
+ end
38
+
39
+ it "should populate cloud id" do
40
+ @ohai[:ec2]['instance_id'] = "i-05714c6c"
41
+ @ohai._require_plugin("cloud")
42
+ @ohai[:cloud].should_not be_nil
43
+ @ohai[:cloud][:instance_id].should == @ohai[:ec2]['instance_id']
44
+ end
45
+
46
+ it "should populate cloud public ip" do
47
+ @ohai[:ec2]['public_ipv4'] = "174.129.150.8"
48
+ @ohai._require_plugin("cloud")
49
+ @ohai[:cloud][:public_ip].should == @ohai[:ec2]['public_ipv4']
50
+ end
51
+
52
+ it "should populate cloud private ip" do
53
+ @ohai[:ec2]['local_ipv4'] = "10.252.42.149"
54
+ @ohai._require_plugin("cloud")
55
+ @ohai[:cloud][:private_ip].should == @ohai[:ec2]['local_ipv4']
56
+ end
57
+
58
+ it "should populate cloud provider" do
59
+ @ohai._require_plugin("cloud")
60
+ @ohai[:cloud][:provider].should == "ec2"
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,34 @@
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, "Darwin hostname plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "darwin"
27
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
28
+ @ohai.stub!(:from).with("hostname").and_return("katie.bethell")
29
+ end
30
+
31
+ it_should_check_from("darwin::hostname", "hostname", "hostname -s", "katie")
32
+
33
+ it_should_check_from("darwin::hostname", "fqdn", "hostname", "katie.bethell")
34
+ end
@@ -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, "Darwin kernel plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:kernel] = Mash.new
27
+ @ohai[:kernel][:name] = "darwin"
28
+ end
29
+
30
+ it "should not set kernel_machine to x86_64" do
31
+ @ohai.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("0")
32
+ @ohai._require_plugin("darwin::kernel")
33
+ @ohai[:kernel][:machine].should_not == 'x86_64'
34
+ end
35
+
36
+ it "should set kernel_machine to x86_64" do
37
+ @ohai.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("1")
38
+ @ohai._require_plugin("darwin::kernel")
39
+ @ohai[:kernel][:machine].should == 'x86_64'
40
+ end
41
+
42
+ it "should set the kernel_os to the kernel_name value" do
43
+ @ohai._require_plugin("darwin::kernel")
44
+ @ohai[:kernel][:os].should == @ohai[:kernel][:name]
45
+ end
46
+ end
@@ -0,0 +1,67 @@
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, "Darwin plugin platform" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "darwin"
27
+ @pid = 10
28
+ @stdin = mock("STDIN", { :close => true })
29
+ @stdout = mock("STDOUT")
30
+ @stdout.stub!(:each).
31
+ and_yield("ProductName: Mac OS X").
32
+ and_yield("ProductVersion: 10.5.5").
33
+ and_yield("BuildVersion: 9F33")
34
+ @stderr = mock("STDERR")
35
+ @ohai.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr)
36
+ end
37
+
38
+ it "should run sw_vers" do
39
+ @ohai.should_receive(:popen4).with("/usr/bin/sw_vers").and_return(true)
40
+ @ohai._require_plugin("darwin::platform")
41
+ end
42
+
43
+ it "should close sw_vers stdin" do
44
+ @stdin.should_receive(:close)
45
+ @ohai._require_plugin("darwin::platform")
46
+ end
47
+
48
+ it "should iterate over each line of sw_vers stdout" do
49
+ @stdout.should_receive(:each).and_return(true)
50
+ @ohai._require_plugin("darwin::platform")
51
+ end
52
+
53
+ it "should set platform to ProductName, downcased with _ for \\s" do
54
+ @ohai._require_plugin("darwin::platform")
55
+ @ohai[:platform].should == "mac_os_x"
56
+ end
57
+
58
+ it "should set platform_version to ProductVersion" do
59
+ @ohai._require_plugin("darwin::platform")
60
+ @ohai[:platform_version].should == "10.5.5"
61
+ end
62
+
63
+ it "should set platform_build to BuildVersion" do
64
+ @ohai._require_plugin("darwin::platform")
65
+ @ohai[:platform_build].should == "9F33"
66
+ end
67
+ end
@@ -0,0 +1,73 @@
1
+ #
2
+ # Author:: Bryan McLellan (<btm@loftninjas.org>)
3
+ # Copyright:: Copyright (c) 2009 Bryan McLellan
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 dmi" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:from).with("dmidecode --version").and_return("2.9")
26
+ @ohai.stub!(:from).with("dmidecode -s bios-vendor").and_return("Dell Inc.")
27
+ @ohai.stub!(:from).with("dmidecode -s bios-version").and_return("2.6.1")
28
+ @ohai.stub!(:from).with("dmidecode -s bios-release-date").and_return("12\/06\/2007")
29
+ @ohai.stub!(:from).with("dmidecode -s system-manufacturer").and_return("Dell Inc.")
30
+ @ohai.stub!(:from).with("dmidecode -s system-product-name").and_return("OptiPlex 745")
31
+ @ohai.stub!(:from).with("dmidecode -s system-version").and_return("Not Specified")
32
+ @ohai.stub!(:from).with("dmidecode -s system-serial-number").and_return("XXXXXXX")
33
+ @ohai.stub!(:from).with("dmidecode -s system-uuid").and_return("44454C4C-4700-1032-8035-B9C04F474331")
34
+ @ohai.stub!(:from).with("dmidecode -s baseboard-manufacturer").and_return("Dell Inc.")
35
+ @ohai.stub!(:from).with("dmidecode -s baseboard-product-name").and_return("0RF703")
36
+ @ohai.stub!(:from).with("dmidecode -s baseboard-version").and_return("Not Specified")
37
+ @ohai.stub!(:from).with("dmidecode -s baseboard-serial-number").and_return("..CN137406CP0289.")
38
+ @ohai.stub!(:from).with("dmidecode -s baseboard-asset-tag").and_return("None")
39
+ @ohai.stub!(:from).with("dmidecode -s chassis-manufacturer").and_return("Dell Inc.")
40
+ @ohai.stub!(:from).with("dmidecode -s chassis-type").and_return("Mini Tower")
41
+ @ohai.stub!(:from).with("dmidecode -s chassis-version").and_return("Not Specified")
42
+ @ohai.stub!(:from).with("dmidecode -s chassis-serial-number").and_return("XXXXXXX")
43
+ @ohai.stub!(:from).with("dmidecode -s chassis-asset-tag").and_return("None")
44
+ @ohai.stub!(:from).with("dmidecode -s processor-family").and_return("Not Specified")
45
+ @ohai.stub!(:from).with("dmidecode -s processor-manufacturer").and_return("Intel")
46
+ @ohai.stub!(:from).with("dmidecode -s processor-version").and_return("Not Specified")
47
+ @ohai.stub!(:from).with("dmidecode -s processor-frequency").and_return("2000 Mhz")
48
+ end
49
+
50
+ it_should_check_from_deep_mash("dmi", "dmi", "version", "dmidecode --version", "2.9")
51
+ it_should_check_from_deep_mash("dmi", [ "dmi", "bios" ], "vendor", "dmidecode -s bios-vendor", "Dell Inc.")
52
+ it_should_check_from_deep_mash("dmi", [ "dmi", "bios" ], "version", "dmidecode -s bios-version", "2.6.1")
53
+ it_should_check_from_deep_mash("dmi", [ "dmi", "bios" ], "release_date", "dmidecode -s bios-release-date", "12\/06\/2007")
54
+ it_should_check_from_deep_mash("dmi", [ "dmi", "system" ], "manufacturer", "dmidecode -s system-manufacturer", "Dell Inc.")
55
+ it_should_check_from_deep_mash("dmi", [ "dmi", "system" ], "product_name", "dmidecode -s system-product-name", "OptiPlex 745")
56
+ it_should_check_from_deep_mash("dmi", [ "dmi", "system" ], "version", "dmidecode -s system-version", "Not Specified")
57
+ it_should_check_from_deep_mash("dmi", [ "dmi", "system" ], "serial_number", "dmidecode -s system-serial-number", "XXXXXXX")
58
+ it_should_check_from_deep_mash("dmi", [ "dmi", "system" ], "uuid", "dmidecode -s system-uuid", "44454C4C-4700-1032-8035-B9C04F474331")
59
+ it_should_check_from_deep_mash("dmi", [ "dmi", "baseboard" ], "manufacturer", "dmidecode -s baseboard-manufacturer", "Dell Inc.")
60
+ it_should_check_from_deep_mash("dmi", [ "dmi", "baseboard" ], "product_name", "dmidecode -s baseboard-product-name", "0RF703")
61
+ it_should_check_from_deep_mash("dmi", [ "dmi", "baseboard" ], "version", "dmidecode -s baseboard-version", "Not Specified")
62
+ it_should_check_from_deep_mash("dmi", [ "dmi", "baseboard" ], "serial_number", "dmidecode -s baseboard-serial-number", "..CN137406CP0289.")
63
+ it_should_check_from_deep_mash("dmi", [ "dmi", "baseboard" ], "asset_tag", "dmidecode -s baseboard-asset-tag", "None")
64
+ it_should_check_from_deep_mash("dmi", [ "dmi", "chassis" ], "manufacturer", "dmidecode -s chassis-manufacturer", "Dell Inc.")
65
+ it_should_check_from_deep_mash("dmi", [ "dmi", "chassis" ], "type", "dmidecode -s chassis-type", "Mini Tower")
66
+ it_should_check_from_deep_mash("dmi", [ "dmi", "chassis" ], "version", "dmidecode -s chassis-version", "Not Specified")
67
+ it_should_check_from_deep_mash("dmi", [ "dmi", "chassis" ], "serial_number", "dmidecode -s chassis-serial-number", "XXXXXXX")
68
+ it_should_check_from_deep_mash("dmi", [ "dmi", "chassis" ], "asset_tag", "dmidecode -s chassis-asset-tag", "None")
69
+ it_should_check_from_deep_mash("dmi", [ "dmi", "processor" ], "family", "dmidecode -s processor-family", "Not Specified")
70
+ it_should_check_from_deep_mash("dmi", [ "dmi", "processor" ], "manufacturer", "dmidecode -s processor-manufacturer", "Intel")
71
+ it_should_check_from_deep_mash("dmi", [ "dmi", "processor" ], "version", "dmidecode -s processor-version", "Not Specified")
72
+ it_should_check_from_deep_mash("dmi", [ "dmi", "processor" ], "frequency", "dmidecode -s processor-frequency", "2000 Mhz")
73
+ end