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
@@ -0,0 +1,77 @@
1
+ #
2
+ # Author:: Tim Dysinger (<tim@dysinger.net>)
3
+ # Author:: Christopher Brown (cb@opscode.com)
4
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
21
+ require 'open-uri'
22
+
23
+ describe Ohai::System, "plugin ec2" do
24
+ before(:each) do
25
+ @ohai = Ohai::System.new
26
+ @ohai.stub!(:require_plugin).and_return(true)
27
+ @ohai[:network] = {:interfaces => {:eth0 => {} } }
28
+ end
29
+
30
+ describe "!ec2", :shared => true do
31
+ it "should NOT attempt to fetch the ec2 metadata" do
32
+ OpenURI.should_not_receive(:open)
33
+ @ohai._require_plugin("ec2")
34
+ end
35
+ end
36
+
37
+ describe "ec2", :shared => true do
38
+ before(:each) do
39
+ OpenURI.stub!(:open_uri).
40
+ with("http://169.254.169.254/2008-02-01/meta-data/").
41
+ and_return(mock(IO, :read => "instance_type\nami_id\n"))
42
+ OpenURI.stub!(:open_uri).
43
+ with("http://169.254.169.254/2008-02-01/meta-data/instance_type").
44
+ and_return(mock(IO, :gets => "c1.medium"))
45
+ OpenURI.stub!(:open_uri).
46
+ with("http://169.254.169.254/2008-02-01/meta-data/ami_id").
47
+ and_return(mock(IO, :gets => "ami-5d2dc934"))
48
+ OpenURI.stub!(:open_uri).
49
+ with("http://169.254.169.254/2008-02-01/user-data/").
50
+ and_return(mock(IO, :gets => "By the pricking of my thumb..."))
51
+ end
52
+
53
+ it "should recursively fetch all the ec2 metadata" do
54
+ @ohai._require_plugin("ec2")
55
+ @ohai[:ec2].should_not be_nil
56
+ @ohai[:ec2]['instance_type'].should == "c1.medium"
57
+ @ohai[:ec2]['ami_id'].should == "ami-5d2dc934"
58
+ end
59
+ end
60
+
61
+ describe "with ec2 mac and metadata address connected" do
62
+ it_should_behave_like "ec2"
63
+
64
+ before(:each) do
65
+ IO.stub!(:select).and_return([[],[1],[]])
66
+ @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"}
67
+ end
68
+ end
69
+
70
+ describe "without ec2 mac and metadata address connected" do
71
+ it_should_behave_like "!ec2"
72
+
73
+ before(:each) do
74
+ @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"}
75
+ end
76
+ end
77
+ 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
+
20
+ require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
21
+
22
+ describe Ohai::System, "plugin erlang" 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
+ @stdin = ""
30
+ @stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"
31
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr])
32
+ end
33
+
34
+ it "should get the erlang version from erl +V" do
35
+ @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([0, "", "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"])
36
+ @ohai._require_plugin("erlang")
37
+ end
38
+
39
+ it "should set languages[:erlang][:version]" do
40
+ @ohai._require_plugin("erlang")
41
+ @ohai.languages[:erlang][:version].should eql("5.6.2")
42
+ end
43
+
44
+ it "should set languages[:erlang][:options]" do
45
+ @ohai._require_plugin("erlang")
46
+ @ohai.languages[:erlang][:options].should eql(["ASYNC_THREADS", "SMP", "HIPE"])
47
+ end
48
+
49
+ it "should set languages[:erlang][:emulator]" do
50
+ @ohai._require_plugin("erlang")
51
+ @ohai.languages[:erlang][:emulator].should eql("BEAM")
52
+ end
53
+
54
+ it "should not set the languages[:erlang] tree up if erlang command fails" do
55
+ @status = 1
56
+ @stdin = ""
57
+ @stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"
58
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr])
59
+ @ohai._require_plugin("erlang")
60
+ @ohai.languages.should_not have_key(:erlang)
61
+ end
62
+
63
+ 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, "FreeBSD hostname plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "freebsd"
27
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
28
+ @ohai.stub!(:from).with("hostname -f").and_return("katie.bethell")
29
+ end
30
+
31
+ it_should_check_from("freebsd::hostname", "hostname", "hostname -s", "katie")
32
+
33
+ it_should_check_from("freebsd::hostname", "fqdn", "hostname -f", "katie.bethell")
34
+ end
@@ -0,0 +1,37 @@
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, "FreeBSD kernel plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai.stub!(:from).with("uname -i").and_return("foo")
27
+ @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1")
28
+ @ohai[:kernel] = Mash.new
29
+ @ohai[:kernel][:name] = "freebsd"
30
+ end
31
+
32
+ it "should set the kernel_os to the kernel_name value" do
33
+ @ohai._require_plugin("freebsd::kernel")
34
+ @ohai[:kernel][:os].should == @ohai[:kernel][:name]
35
+ end
36
+
37
+ end
@@ -0,0 +1,40 @@
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, "FreeBSD plugin platform" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai.stub!(:from).with("uname -s").and_return("FreeBSD")
27
+ @ohai.stub!(:from).with("uname -r").and_return("7.1")
28
+ @ohai[:os] = "freebsd"
29
+ end
30
+
31
+ it "should set platform to lowercased lsb[:id]" do
32
+ @ohai._require_plugin("freebsd::platform")
33
+ @ohai[:platform].should == "freebsd"
34
+ end
35
+
36
+ it "should set platform_version to lsb[:release]" do
37
+ @ohai._require_plugin("freebsd::platform")
38
+ @ohai[:platform_version].should == "7.1"
39
+ end
40
+ end
@@ -0,0 +1,39 @@
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, "hostname plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ end
27
+
28
+ it "should set the domain to everything after the first dot of the fqdn" do
29
+ @ohai[:fqdn] = "katie.bethell"
30
+ @ohai._require_plugin("hostname")
31
+ @ohai.domain.should == "bethell"
32
+ end
33
+
34
+ it "should not set a domain if fqdn is not set" do
35
+ @ohai._require_plugin("hostname")
36
+ @ohai.domain.should == nil
37
+ end
38
+
39
+ end
@@ -0,0 +1,70 @@
1
+ #
2
+ # Author:: Benjamin Black (<bb@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 java" do
22
+ before(:each) do
23
+ @ohai = Ohai::System.new
24
+ @ohai.stub!(:require_plugin).and_return(true)
25
+ @ohai[:languages] = Mash.new
26
+ @status = 0
27
+ @stdout = ""
28
+ @stderr = "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)"
29
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
30
+ end
31
+
32
+ it "should run java -version" do
33
+ @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([0, "", "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)"])
34
+ @ohai._require_plugin("java")
35
+ end
36
+
37
+ it "should set java[:version]" do
38
+ @ohai._require_plugin("java")
39
+ @ohai.languages[:java][:version].should eql("1.5.0_16")
40
+ end
41
+
42
+ it "should set java[:runtime][:name] to runtime name" do
43
+ @ohai._require_plugin("java")
44
+ @ohai.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment, Standard Edition")
45
+ end
46
+
47
+ it "should set java[:runtime][:build] to runtime build" do
48
+ @ohai._require_plugin("java")
49
+ @ohai.languages[:java][:runtime][:build].should eql("1.5.0_16-b06-284")
50
+ end
51
+
52
+ it "should set java[:hotspot][:name] to hotspot name" do
53
+ @ohai._require_plugin("java")
54
+ @ohai.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Client VM")
55
+ end
56
+
57
+ it "should set java[:hotspot][:build] to hotspot build" do
58
+ @ohai._require_plugin("java")
59
+ @ohai.languages[:java][:hotspot][:build].should eql("1.5.0_16-133, mixed mode, sharing")
60
+ end
61
+
62
+ it "should not set the languages[:java] tree up if java command fails" do
63
+ @status = 1
64
+ @stdout = ""
65
+ @stderr = "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)"
66
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
67
+ @ohai._require_plugin("java")
68
+ @ohai.languages.should_not have_key(:java)
69
+ end
70
+ end
@@ -0,0 +1,43 @@
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 kernel" 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.stub!(:from).with("uname -s").and_return("Darwin")
29
+ @ohai.stub!(:from).with("uname -r").and_return("9.5.0")
30
+ @ohai.stub!(:from).with("uname -v").and_return("Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386")
31
+ @ohai.stub!(:from).with("uname -m").and_return("i386")
32
+ @ohai.stub!(:from).with("uname -o").and_return("Linux")
33
+ end
34
+
35
+ it_should_check_from_mash("kernel", "name", "uname -s", "Darwin")
36
+
37
+ it_should_check_from_mash("kernel", "release", "uname -r", "9.5.0")
38
+
39
+ it_should_check_from_mash("kernel", "version", "uname -v", "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386")
40
+
41
+ it_should_check_from_mash("kernel", "machine", "uname -m", "i386")
42
+
43
+ end
@@ -0,0 +1,128 @@
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 cpu plugin" do
23
+ before(:each) do
24
+ @ohai = Ohai::System.new
25
+ @ohai.stub!(:require_plugin).and_return(true)
26
+ @ohai[:os] = "linux"
27
+ @mock_file = mock("/proc/cpuinfo")
28
+ @mock_file.stub!(:each).
29
+ and_yield("processor : 0").
30
+ and_yield("vendor_id : GenuineIntel").
31
+ and_yield("cpu family : 6").
32
+ and_yield("model : 23").
33
+ and_yield("model name : Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz").
34
+ and_yield("stepping : 6").
35
+ and_yield("cpu MHz : 1968.770").
36
+ and_yield("cache size : 64 KB").
37
+ and_yield("fdiv_bug : no").
38
+ and_yield("hlt_bug : no").
39
+ and_yield("f00f_bug : no").
40
+ and_yield("coma_bug : no").
41
+ and_yield("fpu : yes").
42
+ and_yield("fpu_exception : yes").
43
+ and_yield("cpuid level : 10").
44
+ and_yield("wp : yes").
45
+ and_yield("flags : fpu pse tsc msr mce cx8 sep mtrr pge cmov").
46
+ and_yield("bogomips : 2575.86").
47
+ and_yield("clflush size : 32")
48
+ File.stub!(:open).with("/proc/cpuinfo").and_return(@mock_file)
49
+ end
50
+
51
+ it "should set cpu[:total] to 1" do
52
+ @ohai._require_plugin("linux::cpu")
53
+ @ohai[:cpu][:total].should == 1
54
+ end
55
+
56
+ it "should set cpu[:real] to 0" do
57
+ @ohai._require_plugin("linux::cpu")
58
+ @ohai[:cpu][:real].should == 0
59
+ end
60
+
61
+ it "should have a cpu 0" do
62
+ @ohai._require_plugin("linux::cpu")
63
+ @ohai[:cpu].should have_key("0")
64
+ end
65
+
66
+ it "should have a vendor_id for cpu 0" do
67
+ @ohai._require_plugin("linux::cpu")
68
+ @ohai[:cpu]["0"].should have_key("vendor_id")
69
+ @ohai[:cpu]["0"]["vendor_id"].should eql("GenuineIntel")
70
+ end
71
+
72
+ it "should have a family for cpu 0" do
73
+ @ohai._require_plugin("linux::cpu")
74
+ @ohai[:cpu]["0"].should have_key("family")
75
+ @ohai[:cpu]["0"]["family"].should eql("6")
76
+ end
77
+
78
+ it "should have a model for cpu 0" do
79
+ @ohai._require_plugin("linux::cpu")
80
+ @ohai[:cpu]["0"].should have_key("model")
81
+ @ohai[:cpu]["0"]["model"].should eql("23")
82
+ end
83
+
84
+ it "should have a stepping for cpu 0" do
85
+ @ohai._require_plugin("linux::cpu")
86
+ @ohai[:cpu]["0"].should have_key("stepping")
87
+ @ohai[:cpu]["0"]["stepping"].should eql("6")
88
+ end
89
+
90
+ it "should not have a phyiscal_id for cpu 0" do
91
+ @ohai._require_plugin("linux::cpu")
92
+ @ohai[:cpu]["0"].should_not have_key("physical_id")
93
+ end
94
+
95
+ it "should not have a core_id for cpu 0" do
96
+ @ohai._require_plugin("linux::cpu")
97
+ @ohai[:cpu]["0"].should_not have_key("core_id")
98
+ end
99
+
100
+ it "should not have a cores for cpu 0" do
101
+ @ohai._require_plugin("linux::cpu")
102
+ @ohai[:cpu]["0"].should_not have_key("cores")
103
+ end
104
+
105
+ it "should have a model name for cpu 0" do
106
+ @ohai._require_plugin("linux::cpu")
107
+ @ohai[:cpu]["0"].should have_key("model_name")
108
+ @ohai[:cpu]["0"]["model_name"].should eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz")
109
+ end
110
+
111
+ it "should have a mhz for cpu 0" do
112
+ @ohai._require_plugin("linux::cpu")
113
+ @ohai[:cpu]["0"].should have_key("mhz")
114
+ @ohai[:cpu]["0"]["mhz"].should eql("1968.770")
115
+ end
116
+
117
+ it "should have a cache_size for cpu 0" do
118
+ @ohai._require_plugin("linux::cpu")
119
+ @ohai[:cpu]["0"].should have_key("cache_size")
120
+ @ohai[:cpu]["0"]["cache_size"].should eql("64 KB")
121
+ end
122
+
123
+ it "should have flags for cpu 0" do
124
+ @ohai._require_plugin("linux::cpu")
125
+ @ohai[:cpu]["0"].should have_key("flags")
126
+ @ohai[:cpu]["0"]["flags"].should == %w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}
127
+ end
128
+ end