ohai 0.5.8 → 0.6.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/Rakefile +16 -48
  2. data/bin/ohai +1 -1
  3. data/lib/ohai.rb +1 -3
  4. data/lib/ohai/mash.rb +211 -0
  5. data/lib/ohai/mixin/command.rb +157 -44
  6. data/lib/ohai/mixin/ec2_metadata.rb +87 -0
  7. data/lib/ohai/plugins/c.rb +16 -13
  8. data/lib/ohai/plugins/chef.rb +2 -1
  9. data/lib/ohai/plugins/cloud.rb +25 -0
  10. data/lib/ohai/plugins/darwin/network.rb +10 -1
  11. data/lib/ohai/plugins/dmi.rb +100 -37
  12. data/lib/ohai/plugins/dmi_common.rb +117 -0
  13. data/lib/ohai/plugins/ec2.rb +12 -61
  14. data/lib/ohai/plugins/eucalyptus.rb +65 -0
  15. data/lib/ohai/plugins/freebsd/network.rb +11 -2
  16. data/lib/ohai/plugins/java.rb +4 -4
  17. data/lib/ohai/plugins/linux/filesystem.rb +24 -0
  18. data/lib/ohai/plugins/linux/network.rb +14 -1
  19. data/lib/ohai/plugins/linux/platform.rb +3 -0
  20. data/lib/ohai/plugins/linux/virtualization.rb +28 -6
  21. data/lib/ohai/plugins/netbsd/network.rb +10 -1
  22. data/lib/ohai/plugins/network.rb +3 -1
  23. data/lib/ohai/plugins/ohai.rb +1 -0
  24. data/lib/ohai/plugins/openbsd/network.rb +10 -1
  25. data/lib/ohai/plugins/ruby.rb +1 -1
  26. data/lib/ohai/plugins/sigar/filesystem.rb +2 -0
  27. data/lib/ohai/plugins/solaris2/dmi.rb +176 -0
  28. data/lib/ohai/plugins/solaris2/filesystem.rb +101 -0
  29. data/lib/ohai/plugins/solaris2/hostname.rb +10 -1
  30. data/lib/ohai/plugins/solaris2/network.rb +6 -1
  31. data/lib/ohai/plugins/solaris2/uptime.rb +36 -0
  32. data/lib/ohai/plugins/solaris2/virtualization.rb +91 -0
  33. data/lib/ohai/plugins/virtualization.rb +1 -1
  34. data/lib/ohai/plugins/windows/network.rb +17 -11
  35. data/lib/ohai/system.rb +22 -32
  36. data/lib/ohai/version.rb +23 -0
  37. data/spec/ohai/plugins/c_spec.rb +58 -7
  38. data/spec/ohai/plugins/cloud_spec.rb +24 -0
  39. data/spec/ohai/plugins/dmi_spec.rb +107 -47
  40. data/spec/ohai/plugins/ec2_spec.rb +3 -3
  41. data/spec/ohai/plugins/eucalyptus_spec.rb +84 -0
  42. data/spec/ohai/plugins/java_spec.rb +55 -2
  43. data/spec/ohai/plugins/linux/platform_spec.rb +13 -0
  44. data/spec/ohai/plugins/linux/virtualization_spec.rb +47 -6
  45. data/spec/ohai/plugins/perl_spec.rb +15 -14
  46. data/spec/ohai/plugins/rackspace_spec.rb +14 -14
  47. data/spec/ohai/plugins/solaris2/hostname_spec.rb +3 -8
  48. data/spec/ohai/plugins/solaris2/kernel_spec.rb +6 -6
  49. data/spec/ohai/plugins/solaris2/network_spec.rb +22 -22
  50. data/spec/ohai/plugins/solaris2/virtualization_spec.rb +133 -0
  51. data/spec/spec_helper.rb +5 -13
  52. metadata +182 -179
@@ -1,4 +1,4 @@
1
- #
1
+
2
2
  # Author:: Doug MacEachern <dougm@vmware.com>
3
3
  # Copyright:: Copyright (c) 2010 VMware, Inc.
4
4
  # License:: Apache License, Version 2.0
@@ -27,7 +27,7 @@ Thread model: posix
27
27
  gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
28
28
  EOF
29
29
 
30
- C_GLIBC = <<EOF
30
+ C_GLIBC_2_3_4 = <<EOF
31
31
  GNU C Library stable release version 2.3.4, by Roland McGrath et al.
32
32
  Copyright (C) 2005 Free Software Foundation, Inc.
33
33
  This is free software; see the source for copying conditions.
@@ -50,6 +50,28 @@ For bug reporting instructions, please see:
50
50
  <http://www.gnu.org/software/libc/bugs.html>.
51
51
  EOF
52
52
 
53
+ C_GLIBC_2_5 = <<EOF
54
+ GNU C Library stable release version 2.5, by Roland McGrath et al.
55
+ Copyright (C) 2006 Free Software Foundation, Inc.
56
+ This is free software; see the source for copying conditions.
57
+ There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
58
+ PARTICULAR PURPOSE.
59
+ Compiled by GNU CC version 4.1.2 20080704 (Red Hat 4.1.2-44).
60
+ Compiled on a Linux 2.6.9 system on 2009-09-02.
61
+ Available extensions:
62
+ The C stubs add-on version 2.1.2.
63
+ crypt add-on version 2.1 by Michael Glad and others
64
+ GNU Libidn by Simon Josefsson
65
+ GNU libio by Per Bothner
66
+ NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
67
+ Native POSIX Threads Library by Ulrich Drepper et al
68
+ BIND-8.2.3-T5B
69
+ RT using linux kernel aio
70
+ Thread-local storage support included.
71
+ For bug reporting instructions, please see:
72
+ <http://www.gnu.org/software/libc/bugs.html>.
73
+ EOF
74
+
53
75
  C_CL = <<EOF
54
76
  Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
55
77
  Copyright (C) Microsoft Corporation. All rights reserved.
@@ -87,7 +109,7 @@ describe Ohai::System, "plugin c" do
87
109
  #gcc
88
110
  @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC])
89
111
  #glibc
90
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC, ""])
112
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""])
91
113
  #ms cl
92
114
  @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL])
93
115
  #ms vs
@@ -123,8 +145,8 @@ describe Ohai::System, "plugin c" do
123
145
  end
124
146
 
125
147
  #glibc
126
- it "should get the glibc version from running gcc -v" do
127
- @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC, ""])
148
+ it "should get the glibc x.x.x version from running /lib/libc.so.6" do
149
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""])
128
150
  @ohai._require_plugin("c")
129
151
  end
130
152
 
@@ -135,7 +157,7 @@ describe Ohai::System, "plugin c" do
135
157
 
136
158
  it "should set languages[:c][:glibc][:description]" do
137
159
  @ohai._require_plugin("c")
138
- @ohai.languages[:c][:glibc][:description].should eql(C_GLIBC.split($/).first)
160
+ @ohai.languages[:c][:glibc][:description].should eql(C_GLIBC_2_3_4.split($/).first)
139
161
  end
140
162
 
141
163
  it "should not set the languages[:c][:glibc] tree up if glibc command fails" do
@@ -144,6 +166,13 @@ describe Ohai::System, "plugin c" do
144
166
  @ohai[:languages][:c].should_not have_key(:glibc) if @ohai[:languages][:c]
145
167
  end
146
168
 
169
+ it "should get the glibc x.x version from running /lib/libc.so.6" do
170
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_5, ""])
171
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_5, ""])
172
+ @ohai._require_plugin("c")
173
+ @ohai.languages[:c][:glibc][:version].should eql("2.5")
174
+ end
175
+
147
176
  #ms cl
148
177
  it "should get the cl version from running cl /?" do
149
178
  @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL])
@@ -196,7 +225,7 @@ describe Ohai::System, "plugin c" do
196
225
 
197
226
  it "should set languages[:c][:xlc][:version]" do
198
227
  @ohai._require_plugin("c")
199
- @ohai.languages[:c][:xlc][:version].should eql("09.00.0000.0000")
228
+ @ohai.languages[:c][:xlc][:version].should eql("9.0")
200
229
  end
201
230
 
202
231
  it "should set languages[:c][:xlc][:description]" do
@@ -210,6 +239,12 @@ describe Ohai::System, "plugin c" do
210
239
  @ohai[:languages][:c].should_not have_key(:xlc) if @ohai[:languages][:c]
211
240
  end
212
241
 
242
+ it "should set the languages[:c][:xlc] tree up if xlc exit status is 249" do
243
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([63744, "", ""])
244
+ @ohai._require_plugin("c")
245
+ @ohai[:languages][:c].should_not have_key(:xlc) if @ohai[:languages][:c]
246
+ end
247
+
213
248
  #sun pro
214
249
  it "should get the cc version from running cc -V -flags" do
215
250
  @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN])
@@ -232,6 +267,22 @@ describe Ohai::System, "plugin c" do
232
267
  @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c]
233
268
  end
234
269
 
270
+
271
+ it "should not set the languages[:c][:sunpro] tree if the corresponding cc command fails on linux" do
272
+ fedora_error_message = "cc: error trying to exec 'i686-redhat-linux-gcc--flags': execvp: No such file or directory"
273
+
274
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", fedora_error_message])
275
+ @ohai._require_plugin("c")
276
+ @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c]
277
+ end
278
+
279
+ it "should not set the languages[:c][:sunpro] tree if the corresponding cc command fails on hpux" do
280
+ hpux_error_message = "cc: warning 901: unknown option: `-flags': use +help for online documentation.\ncc: HP C/aC++ B3910B A.06.25 [Nov 30 2009]"
281
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", hpux_error_message])
282
+ @ohai._require_plugin("c")
283
+ @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c]
284
+ end
285
+
235
286
  #hpux cc
236
287
  it "should get the cc version from running what cc" do
237
288
  @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""])
@@ -29,6 +29,7 @@ describe Ohai::System, "plugin cloud" do
29
29
  it "should NOT populate the cloud data" do
30
30
  @ohai[:ec2] = nil
31
31
  @ohai[:rackspace] = nil
32
+ @ohai[:eucalyptus] = nil
32
33
  @ohai._require_plugin("cloud")
33
34
  @ohai[:cloud].should be_nil
34
35
  end
@@ -86,4 +87,27 @@ describe Ohai::System, "plugin cloud" do
86
87
  end
87
88
  end
88
89
 
90
+ describe "with eucalyptus" do
91
+ before(:each) do
92
+ @ohai[:eucalyptus] = Mash.new()
93
+ end
94
+
95
+ it "should populate cloud public ip" do
96
+ @ohai[:eucalyptus]['public_ipv4'] = "174.129.150.8"
97
+ @ohai._require_plugin("cloud")
98
+ @ohai[:cloud][:public_ips][0].should == @ohai[:eucalyptus]['public_ipv4']
99
+ end
100
+
101
+ it "should populate cloud private ip" do
102
+ @ohai[:eucalyptus]['local_ipv4'] = "10.252.42.149"
103
+ @ohai._require_plugin("cloud")
104
+ @ohai[:cloud][:private_ips][0].should == @ohai[:eucalyptus]['local_ipv4']
105
+ end
106
+
107
+ it "should populate cloud provider" do
108
+ @ohai._require_plugin("cloud")
109
+ @ohai[:cloud][:provider].should == "eucalyptus"
110
+ end
111
+ end
112
+
89
113
  end
@@ -16,58 +16,118 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
-
20
19
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
21
20
 
21
+ # NOTE: These data lines must be prefixed with one or two tabs, not spaces.
22
+ DMI_OUT = <<-EOS
23
+ # dmidecode 2.9
24
+ SMBIOS 2.4 present.
25
+ 98 structures occupying 3699 bytes.
26
+ Table at 0x000E0010.
27
+
28
+ Handle 0x0000, DMI type 0, 24 bytes
29
+ BIOS Information
30
+ Vendor: Phoenix Technologies LTD
31
+ Version: 6.00
32
+ Release Date: 12/31/2009
33
+ Address: 0xEA2E0
34
+ Runtime Size: 89376 bytes
35
+ ROM Size: 64 kB
36
+ Characteristics:
37
+ ISA is supported
38
+ PCI is supported
39
+ PC Card (PCMCIA) is supported
40
+ PNP is supported
41
+ APM is supported
42
+ BIOS is upgradeable
43
+ BIOS shadowing is allowed
44
+ ESCD support is available
45
+ USB legacy is supported
46
+ Smart battery is supported
47
+ BIOS boot specification is supported
48
+ Targeted content distribution is supported
49
+ BIOS Revision: 4.6
50
+ Firmware Revision: 0.0
51
+
52
+ Handle 0x0001, DMI type 1, 27 bytes
53
+ System Information
54
+ Manufacturer: VMware, Inc.
55
+ Product Name: VMware Virtual Platform
56
+ Version: None
57
+ Serial Number: VMware-56 4d 71 d1 65 70 83 a8-df c8 14 12 19 41 71 45
58
+ UUID: 564D71D1-6570-83A8-DFC8-141219417145
59
+ Wake-up Type: Power Switch
60
+ SKU Number: Not Specified
61
+ Family: Not Specified
62
+
63
+ Handle 0x0002, DMI type 2, 15 bytes
64
+ Base Board Information
65
+ Manufacturer: Intel Corporation
66
+ Product Name: 440BX Desktop Reference Platform
67
+ Version: None
68
+ Serial Number: None
69
+ Asset Tag: Not Specified
70
+ Features: None
71
+ Location In Chassis: Not Specified
72
+ Chassis Handle: 0x0000
73
+ Type: Unknown
74
+ Contained Object Handles: 0
75
+
76
+ Handle 0x0003, DMI type 3, 21 bytes
77
+ Chassis Information
78
+ Manufacturer: No Enclosure
79
+ Type: Other
80
+ Lock: Not Present
81
+ Version: N/A
82
+ Serial Number: None
83
+ Asset Tag: No Asset Tag
84
+ Boot-up State: Safe
85
+ Power Supply State: Safe
86
+ Thermal State: Safe
87
+ Security Status: None
88
+ OEM Information: 0x00001234
89
+ Height: Unspecified
90
+ Number Of Power Cords: Unspecified
91
+ Contained Elements: 0
92
+ EOS
93
+
22
94
  describe Ohai::System, "plugin dmi" do
23
95
  before(:each) do
24
96
  @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")
97
+ @ohai.stub!(:require_plugin).and_return(true)
98
+ @stdin = mock("STDIN", { :close => true })
99
+ @pid = 10
100
+ @stderr = mock("STDERR")
101
+ @stdout = StringIO.new(DMI_OUT)
102
+ @status = 0
103
+ @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
104
+ end
105
+
106
+ it "should run dmidecode" do
107
+ @ohai.should_receive(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
108
+ @ohai._require_plugin("dmi")
48
109
  end
49
110
 
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")
111
+ # Test some simple sample data
112
+ {
113
+ :bios => {
114
+ :vendor => "Phoenix Technologies LTD",
115
+ :release_date => "12/31/2009"
116
+ },
117
+ :system => {
118
+ :manufacturer => "VMware, Inc.",
119
+ :product_name => "VMware Virtual Platform"
120
+ },
121
+ :chassis => {
122
+ :lock => "Not Present",
123
+ :asset_tag => "No Asset Tag"
124
+ }
125
+ }.each do |id, data|
126
+ data.each do |attribute, value|
127
+ it "should have [:dmi][:#{id}][:#{attribute}] set" do
128
+ @ohai._require_plugin("dmi")
129
+ @ohai[:dmi][id][attribute].should eql(value)
130
+ end
131
+ end
132
+ end
73
133
  end
@@ -27,14 +27,14 @@ describe Ohai::System, "plugin ec2" do
27
27
  @ohai[:network] = {:interfaces => {:eth0 => {} } }
28
28
  end
29
29
 
30
- describe "!ec2", :shared => true do
30
+ shared_examples_for "!ec2" do
31
31
  it "should NOT attempt to fetch the ec2 metadata" do
32
32
  OpenURI.should_not_receive(:open)
33
33
  @ohai._require_plugin("ec2")
34
34
  end
35
35
  end
36
36
 
37
- describe "ec2", :shared => true do
37
+ shared_examples_for "ec2" do
38
38
  before(:each) do
39
39
  OpenURI.stub!(:open_uri).
40
40
  with("http://169.254.169.254/2008-02-01/meta-data/").
@@ -77,7 +77,7 @@ describe Ohai::System, "plugin ec2" do
77
77
 
78
78
  describe "without ec2 mac and metadata address connected" do
79
79
  it_should_behave_like "!ec2"
80
-
80
+
81
81
  before(:each) do
82
82
  @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"}
83
83
  end
@@ -0,0 +1,84 @@
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.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
21
+ require 'open-uri'
22
+
23
+ describe Ohai::System, "plugin eucalyptus" do
24
+ before(:each) do
25
+ @ohai = Ohai::System.new
26
+ @ohai.stub!(:require_plugin).and_return(true)
27
+ end
28
+
29
+ shared_examples_for "!eucalyptus" do
30
+ it "should NOT attempt to fetch the eucalyptus metadata" do
31
+ OpenURI.should_not_receive(:open)
32
+ @ohai._require_plugin("eucalyptus")
33
+ end
34
+ end
35
+
36
+ shared_examples_for "eucalyptus" do
37
+ before(:each) do
38
+ OpenURI.stub!(:open_uri).
39
+ with("http://169.254.169.254/2008-02-01/meta-data/").
40
+ and_return(mock(IO, :read => "instance_type\nami_id\nsecurity-groups"))
41
+ OpenURI.stub!(:open_uri).
42
+ with("http://169.254.169.254/2008-02-01/meta-data/instance_type").
43
+ and_return(mock(IO, :read => "c1.medium"))
44
+ OpenURI.stub!(:open_uri).
45
+ with("http://169.254.169.254/2008-02-01/meta-data/ami_id").
46
+ and_return(mock(IO, :read => "ami-5d2dc934"))
47
+ OpenURI.stub!(:open_uri).
48
+ with("http://169.254.169.254/2008-02-01/meta-data/security-groups").
49
+ and_return(mock(IO, :read => "group1\ngroup2"))
50
+ OpenURI.stub!(:open_uri).
51
+ with("http://169.254.169.254/2008-02-01/user-data/").
52
+ and_return(mock(IO, :gets => "By the pricking of my thumb..."))
53
+ end
54
+
55
+ it "should recursively fetch all the eucalyptus metadata" do
56
+ IO.stub!(:select).and_return([[],[1],[]])
57
+ t = mock("connection")
58
+ t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS)
59
+ Socket.stub!(:new).and_return(t)
60
+ @ohai._require_plugin("eucalyptus")
61
+ @ohai[:eucalyptus].should_not be_nil
62
+ @ohai[:eucalyptus]['instance_type'].should == "c1.medium"
63
+ @ohai[:eucalyptus]['ami_id'].should == "ami-5d2dc934"
64
+ @ohai[:eucalyptus]['security_groups'].should eql ['group1', 'group2']
65
+ end
66
+ end
67
+
68
+ describe "with eucalyptus mac and metadata address connected" do
69
+ it_should_behave_like "eucalyptus"
70
+
71
+ before(:each) do
72
+ IO.stub!(:select).and_return([[],[1],[]])
73
+ @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
74
+ end
75
+ end
76
+
77
+ describe "without eucalyptus mac and metadata address connected" do
78
+ it_should_behave_like "!eucalyptus"
79
+
80
+ before(:each) do
81
+ @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
82
+ end
83
+ end
84
+ end
@@ -18,7 +18,7 @@
18
18
 
19
19
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
20
20
 
21
- describe Ohai::System, "plugin java" do
21
+ describe Ohai::System, "plugin java (Java5 Client VM)" do
22
22
  before(:each) do
23
23
  @ohai = Ohai::System.new
24
24
  @ohai.stub!(:require_plugin).and_return(true)
@@ -62,9 +62,62 @@ describe Ohai::System, "plugin java" do
62
62
  it "should not set the languages[:java] tree up if java command fails" do
63
63
  @status = 1
64
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)"
65
+ @stderr = "Some error output here"
66
66
  @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
67
67
  @ohai._require_plugin("java")
68
68
  @ohai.languages.should_not have_key(:java)
69
69
  end
70
70
  end
71
+
72
+ describe Ohai::System, "plugin java (Java6 Server VM)" do
73
+ before(:each) do
74
+ @ohai = Ohai::System.new
75
+ @ohai.stub!(:require_plugin).and_return(true)
76
+ @ohai[:languages] = Mash.new
77
+ @status = 0
78
+ @stdout = ""
79
+ @stderr = "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)"
80
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
81
+ end
82
+
83
+ it "should run java -version" do
84
+ @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([0, "", "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)"])
85
+ @ohai._require_plugin("java")
86
+ end
87
+
88
+ it "should set java[:version]" do
89
+ @ohai._require_plugin("java")
90
+ @ohai.languages[:java][:version].should eql("1.6.0_22")
91
+ end
92
+
93
+ it "should set java[:runtime][:name] to runtime name" do
94
+ @ohai._require_plugin("java")
95
+ @ohai.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment")
96
+ end
97
+
98
+ it "should set java[:runtime][:build] to runtime build" do
99
+ @ohai._require_plugin("java")
100
+ @ohai.languages[:java][:runtime][:build].should eql("1.6.0_22-b04")
101
+ end
102
+
103
+ it "should set java[:hotspot][:name] to hotspot name" do
104
+ @ohai._require_plugin("java")
105
+ @ohai.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Server VM")
106
+ end
107
+
108
+ it "should set java[:hotspot][:build] to hotspot build" do
109
+ @ohai._require_plugin("java")
110
+ @ohai.languages[:java][:hotspot][:build].should eql("17.1-b03, mixed mode")
111
+ end
112
+
113
+ it "should not set the languages[:java] tree up if java command fails" do
114
+ @status = 1
115
+ @stdout = ""
116
+ @stderr = "Some error output here"
117
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
118
+ @ohai._require_plugin("java")
119
+ @ohai.languages.should_not have_key(:java)
120
+ end
121
+ end
122
+
123
+