ohai 6.24.2 → 7.0.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. data/lib/ohai.rb +1 -1
  2. data/lib/ohai/application.rb +5 -12
  3. data/lib/ohai/common/dmi.rb +126 -0
  4. data/lib/ohai/config.rb +9 -9
  5. data/lib/ohai/{plugins/darwin/hostname.rb → dsl.rb} +7 -7
  6. data/lib/ohai/dsl/plugin.rb +186 -0
  7. data/lib/ohai/dsl/plugin/versionvi.rb +62 -0
  8. data/lib/ohai/dsl/plugin/versionvii.rb +106 -0
  9. data/lib/ohai/exception.rb +11 -2
  10. data/lib/ohai/hints.rb +48 -0
  11. data/lib/ohai/loader.rb +205 -0
  12. data/lib/ohai/mixin/command.rb +14 -18
  13. data/lib/ohai/mixin/constant_helper.rb +53 -0
  14. data/lib/ohai/mixin/gce_metadata.rb +0 -2
  15. data/lib/ohai/{plugins/freebsd/uptime.rb → mixin/network_constants.rb} +15 -13
  16. data/lib/ohai/mixin/os.rb +59 -0
  17. data/lib/ohai/mixin/seconds_to_human.rb +48 -0
  18. data/lib/ohai/plugins/aix/cpu.rb +26 -22
  19. data/lib/ohai/plugins/aix/filesystem.rb +47 -48
  20. data/lib/ohai/plugins/aix/kernel.rb +11 -7
  21. data/lib/ohai/plugins/aix/memory.rb +8 -4
  22. data/lib/ohai/plugins/aix/network.rb +73 -82
  23. data/lib/ohai/plugins/aix/platform.rb +9 -6
  24. data/lib/ohai/plugins/aix/uptime.rb +14 -12
  25. data/lib/ohai/plugins/azure.rb +33 -11
  26. data/lib/ohai/plugins/c.rb +103 -78
  27. data/lib/ohai/plugins/chef.rb +20 -8
  28. data/lib/ohai/plugins/cloud.rb +234 -230
  29. data/lib/ohai/plugins/command.rb +6 -2
  30. data/lib/ohai/plugins/darwin/cpu.rb +10 -4
  31. data/lib/ohai/plugins/darwin/filesystem.rb +32 -32
  32. data/lib/ohai/plugins/darwin/network.rb +157 -154
  33. data/lib/ohai/plugins/darwin/platform.rb +18 -16
  34. data/lib/ohai/plugins/darwin/system_profiler.rb +49 -46
  35. data/lib/ohai/plugins/dmi.rb +102 -102
  36. data/lib/ohai/plugins/ec2.rb +30 -28
  37. data/lib/ohai/plugins/erlang.rb +19 -16
  38. data/lib/ohai/plugins/eucalyptus.rb +37 -36
  39. data/lib/ohai/plugins/freebsd/cpu.rb +34 -29
  40. data/lib/ohai/plugins/freebsd/filesystem.rb +32 -32
  41. data/lib/ohai/plugins/freebsd/memory.rb +35 -25
  42. data/lib/ohai/plugins/freebsd/network.rb +94 -89
  43. data/lib/ohai/plugins/freebsd/platform.rb +10 -4
  44. data/lib/ohai/plugins/freebsd/virtualization.rb +62 -61
  45. data/lib/ohai/plugins/gce.rb +30 -36
  46. data/lib/ohai/plugins/groovy.rb +14 -11
  47. data/lib/ohai/plugins/hostname.rb +132 -10
  48. data/lib/ohai/plugins/ip_scopes.rb +31 -16
  49. data/lib/ohai/plugins/java.rb +45 -21
  50. data/lib/ohai/plugins/kernel.rb +186 -19
  51. data/lib/ohai/plugins/keys.rb +6 -2
  52. data/lib/ohai/plugins/languages.rb +6 -2
  53. data/lib/ohai/plugins/linode.rb +38 -30
  54. data/lib/ohai/plugins/linux/block_device.rb +19 -15
  55. data/lib/ohai/plugins/linux/cpu.rb +42 -38
  56. data/lib/ohai/plugins/linux/filesystem.rb +70 -130
  57. data/lib/ohai/plugins/linux/lsb.rb +35 -35
  58. data/lib/ohai/plugins/linux/memory.rb +65 -61
  59. data/lib/ohai/plugins/linux/network.rb +343 -362
  60. data/lib/ohai/plugins/linux/platform.rb +90 -88
  61. data/lib/ohai/plugins/linux/virtualization.rb +95 -90
  62. data/lib/ohai/plugins/lua.rb +14 -10
  63. data/lib/ohai/plugins/mono.rb +17 -13
  64. data/lib/ohai/plugins/netbsd/cpu.rb +25 -23
  65. data/lib/ohai/plugins/netbsd/filesystem.rb +32 -32
  66. data/lib/ohai/plugins/netbsd/memory.rb +59 -59
  67. data/lib/ohai/plugins/netbsd/network.rb +92 -88
  68. data/lib/ohai/plugins/netbsd/platform.rb +10 -3
  69. data/lib/ohai/plugins/netbsd/virtualization.rb +41 -38
  70. data/lib/ohai/plugins/network.rb +131 -130
  71. data/lib/ohai/plugins/network_listeners.rb +26 -22
  72. data/lib/ohai/plugins/nodejs.rb +14 -10
  73. data/lib/ohai/plugins/ohai.rb +11 -6
  74. data/lib/ohai/plugins/ohai_time.rb +6 -2
  75. data/lib/ohai/plugins/openbsd/cpu.rb +20 -15
  76. data/lib/ohai/plugins/openbsd/filesystem.rb +32 -32
  77. data/lib/ohai/plugins/openbsd/memory.rb +59 -59
  78. data/lib/ohai/plugins/openbsd/network.rb +92 -88
  79. data/lib/ohai/plugins/openbsd/platform.rb +10 -4
  80. data/lib/ohai/plugins/openbsd/virtualization.rb +41 -39
  81. data/lib/ohai/plugins/openstack.rb +23 -21
  82. data/lib/ohai/plugins/os.rb +8 -32
  83. data/lib/ohai/plugins/passwd.rb +27 -22
  84. data/lib/ohai/plugins/perl.rb +21 -16
  85. data/lib/ohai/plugins/php.rb +15 -12
  86. data/lib/ohai/plugins/platform.rb +9 -9
  87. data/lib/ohai/plugins/{linux/kernel.rb → ps.rb} +13 -12
  88. data/lib/ohai/plugins/python.rb +16 -12
  89. data/lib/ohai/plugins/rackspace.rb +82 -77
  90. data/lib/ohai/plugins/root_group.rb +13 -9
  91. data/lib/ohai/plugins/ruby.rb +50 -48
  92. data/lib/ohai/plugins/sigar/cpu.rb +21 -17
  93. data/lib/ohai/plugins/sigar/filesystem.rb +26 -23
  94. data/lib/ohai/plugins/sigar/memory.rb +17 -14
  95. data/lib/ohai/plugins/sigar/network.rb +133 -67
  96. data/lib/ohai/plugins/sigar/network_route.rb +33 -28
  97. data/lib/ohai/plugins/sigar/platform.rb +10 -6
  98. data/lib/ohai/plugins/solaris2/cpu.rb +41 -33
  99. data/lib/ohai/plugins/solaris2/dmi.rb +146 -146
  100. data/lib/ohai/plugins/solaris2/filesystem.rb +74 -77
  101. data/lib/ohai/plugins/{aix/hostname.rb → solaris2/memory.rb} +7 -4
  102. data/lib/ohai/plugins/solaris2/network.rb +91 -86
  103. data/lib/ohai/plugins/solaris2/platform.rb +40 -36
  104. data/lib/ohai/plugins/solaris2/virtualization.rb +54 -59
  105. data/lib/ohai/plugins/solaris2/zpools.rb +38 -38
  106. data/lib/ohai/plugins/ssh_host_key.rb +49 -45
  107. data/lib/ohai/plugins/uptime.rb +87 -25
  108. data/lib/ohai/plugins/virtualization.rb +59 -55
  109. data/lib/ohai/plugins/windows/cpu.rb +44 -40
  110. data/lib/ohai/plugins/windows/filesystem.rb +28 -22
  111. data/lib/ohai/plugins/windows/network.rb +88 -79
  112. data/lib/ohai/plugins/windows/platform.rb +10 -3
  113. data/lib/ohai/provides_map.rb +184 -0
  114. data/lib/ohai/runner.rb +109 -0
  115. data/lib/ohai/system.rb +103 -184
  116. data/lib/ohai/version.rb +4 -3
  117. data/spec/data/plugins/___lib64___libc.so.6.output +135 -0
  118. data/spec/data/plugins/___lib___libc.so.6.output +135 -0
  119. data/spec/data/plugins/cc.output +135 -0
  120. data/spec/data/plugins/cl.output +135 -0
  121. data/spec/data/plugins/devenv.com.output +135 -0
  122. data/spec/data/plugins/env.output +71 -0
  123. data/spec/data/plugins/erl.output +144 -0
  124. data/spec/data/plugins/gcc.output +135 -0
  125. data/spec/data/plugins/groovy.output +159 -0
  126. data/spec/data/plugins/java.output +143 -0
  127. data/spec/data/plugins/lua.output +143 -0
  128. data/spec/data/plugins/messages.rb +8 -0
  129. data/spec/data/plugins/node.output +143 -0
  130. data/spec/data/plugins/perl.output +143 -0
  131. data/spec/data/plugins/php.output +143 -0
  132. data/spec/data/plugins/python.output +143 -0
  133. data/spec/data/plugins/uname.output +71 -0
  134. data/spec/data/plugins/v6message.rb +2 -0
  135. data/spec/data/plugins/v7message.rb +7 -0
  136. data/spec/data/plugins/what.output +135 -0
  137. data/spec/data/plugins/xlc.output +135 -0
  138. data/spec/spec_helper.rb +52 -18
  139. data/spec/support/integration_helper.rb +44 -0
  140. data/spec/unit/dsl/plugin_spec.rb +298 -0
  141. data/spec/unit/hints_spec.rb +65 -0
  142. data/spec/unit/loader_spec.rb +226 -0
  143. data/spec/unit/mixin/ec2_metadata_spec.rb +9 -9
  144. data/spec/unit/plugins/aix/cpu_spec.rb +17 -18
  145. data/spec/unit/plugins/aix/filesystem_spec.rb +20 -18
  146. data/spec/unit/plugins/aix/hostname_spec.rb +8 -4
  147. data/spec/unit/plugins/aix/kernel_spec.rb +13 -12
  148. data/spec/unit/plugins/aix/network_spec.rb +66 -45
  149. data/spec/unit/plugins/aix/platform_spec.rb +11 -10
  150. data/spec/unit/plugins/aix/uptime_spec.rb +7 -8
  151. data/spec/unit/plugins/azure_spec.rb +20 -21
  152. data/spec/unit/plugins/c_spec.rb +88 -87
  153. data/spec/unit/plugins/chef_spec.rb +5 -6
  154. data/spec/unit/plugins/cloud_spec.rb +81 -82
  155. data/spec/unit/plugins/darwin/cpu_spec.rb +8 -9
  156. data/spec/unit/plugins/darwin/hostname_spec.rb +23 -11
  157. data/spec/unit/plugins/darwin/kernel_spec.rb +39 -16
  158. data/spec/unit/plugins/darwin/network_spec.rb +375 -378
  159. data/spec/unit/plugins/darwin/platform_spec.rb +23 -50
  160. data/spec/unit/plugins/darwin/system_profiler_spec.rb +7 -8
  161. data/spec/unit/plugins/dmi_spec.rb +7 -12
  162. data/spec/unit/plugins/ec2_spec.rb +70 -59
  163. data/spec/unit/plugins/erlang_spec.rb +18 -20
  164. data/spec/unit/plugins/eucalyptus_spec.rb +37 -33
  165. data/spec/unit/plugins/fail_spec.rb +276 -23
  166. data/spec/unit/plugins/freebsd/hostname_spec.rb +11 -9
  167. data/spec/unit/plugins/freebsd/kernel_spec.rb +8 -8
  168. data/spec/unit/plugins/freebsd/platform_spec.rb +9 -10
  169. data/spec/unit/plugins/freebsd/virtualization_spec.rb +32 -32
  170. data/spec/unit/plugins/gce_spec.rb +19 -25
  171. data/spec/unit/plugins/groovy_spec.rb +10 -16
  172. data/spec/unit/plugins/hostname_spec.rb +45 -20
  173. data/spec/unit/plugins/ip_scopes_spec.rb +97 -0
  174. data/spec/unit/plugins/java_spec.rb +145 -99
  175. data/spec/unit/plugins/kernel_spec.rb +51 -15
  176. data/spec/unit/plugins/linode_spec.rb +31 -29
  177. data/spec/unit/plugins/linux/cpu_spec.rb +42 -43
  178. data/spec/unit/plugins/linux/filesystem_spec.rb +143 -324
  179. data/spec/unit/plugins/linux/hostname_spec.rb +16 -23
  180. data/spec/unit/plugins/linux/kernel_spec.rb +22 -8
  181. data/spec/unit/plugins/linux/lsb_spec.rb +54 -56
  182. data/spec/unit/plugins/linux/network_spec.rb +196 -238
  183. data/spec/unit/plugins/linux/platform_spec.rb +186 -205
  184. data/spec/unit/plugins/linux/uptime_spec.rb +13 -25
  185. data/spec/unit/plugins/linux/virtualization_spec.rb +149 -129
  186. data/spec/unit/plugins/lua_spec.rb +12 -15
  187. data/spec/unit/plugins/mono_spec.rb +10 -15
  188. data/spec/unit/plugins/netbsd/hostname_spec.rb +17 -7
  189. data/spec/unit/plugins/netbsd/kernel_spec.rb +8 -8
  190. data/spec/unit/plugins/netbsd/platform_spec.rb +8 -10
  191. data/spec/unit/plugins/network_spec.rb +358 -235
  192. data/spec/unit/plugins/nodejs_spec.rb +13 -15
  193. data/spec/unit/plugins/ohai_spec.rb +3 -4
  194. data/spec/unit/plugins/ohai_time_spec.rb +8 -9
  195. data/spec/unit/plugins/openbsd/hostname_spec.rb +21 -11
  196. data/spec/unit/plugins/openbsd/kernel_spec.rb +8 -8
  197. data/spec/unit/plugins/openbsd/platform_spec.rb +6 -12
  198. data/spec/unit/plugins/openstack_spec.rb +214 -0
  199. data/spec/unit/plugins/os_spec.rb +13 -16
  200. data/spec/unit/plugins/passwd_spec.rb +12 -13
  201. data/spec/unit/plugins/perl_spec.rb +20 -44
  202. data/spec/unit/plugins/php_spec.rb +20 -15
  203. data/spec/unit/plugins/platform_spec.rb +24 -29
  204. data/spec/unit/plugins/python_spec.rb +13 -17
  205. data/spec/unit/plugins/rackspace_spec.rb +90 -57
  206. data/spec/unit/plugins/root_group_spec.rb +17 -19
  207. data/spec/unit/plugins/ruby_spec.rb +15 -16
  208. data/spec/unit/plugins/sigar/network_route_spec.rb +12 -13
  209. data/spec/unit/plugins/solaris2/cpu_spec.rb +82 -0
  210. data/spec/unit/plugins/solaris2/hostname_spec.rb +12 -13
  211. data/spec/unit/plugins/solaris2/kernel_spec.rb +11 -15
  212. data/{lib/ohai/plugins/openbsd/uptime.rb → spec/unit/plugins/solaris2/memory_spec.rb} +10 -12
  213. data/spec/unit/plugins/solaris2/network_spec.rb +44 -20
  214. data/spec/unit/plugins/solaris2/platform_spec.rb +13 -22
  215. data/spec/unit/plugins/solaris2/virtualization_spec.rb +37 -45
  216. data/spec/unit/plugins/ssh_host_keys_spec.rb +11 -15
  217. data/spec/unit/provides_map_spec.rb +208 -0
  218. data/spec/unit/runner_spec.rb +488 -0
  219. data/spec/unit/system_spec.rb +639 -104
  220. metadata +151 -87
  221. checksums.yaml +0 -7
  222. data/lib/ohai/mixin/from_file.rb +0 -36
  223. data/lib/ohai/plugins/aix/ps.rb +0 -23
  224. data/lib/ohai/plugins/darwin/kernel.rb +0 -37
  225. data/lib/ohai/plugins/darwin/ps.rb +0 -23
  226. data/lib/ohai/plugins/darwin/uptime.rb +0 -32
  227. data/lib/ohai/plugins/dmi_common.rb +0 -121
  228. data/lib/ohai/plugins/freebsd/hostname.rb +0 -22
  229. data/lib/ohai/plugins/freebsd/kernel.rb +0 -37
  230. data/lib/ohai/plugins/freebsd/ps.rb +0 -24
  231. data/lib/ohai/plugins/hpux/cpu.rb +0 -19
  232. data/lib/ohai/plugins/hpux/filesystem.rb +0 -19
  233. data/lib/ohai/plugins/hpux/hostname.rb +0 -19
  234. data/lib/ohai/plugins/hpux/memory.rb +0 -19
  235. data/lib/ohai/plugins/hpux/network.rb +0 -19
  236. data/lib/ohai/plugins/hpux/platform.rb +0 -19
  237. data/lib/ohai/plugins/hpux/ps.rb +0 -23
  238. data/lib/ohai/plugins/hpux/uptime.rb +0 -19
  239. data/lib/ohai/plugins/linux/hostname.rb +0 -40
  240. data/lib/ohai/plugins/linux/ps.rb +0 -23
  241. data/lib/ohai/plugins/linux/uptime.rb +0 -28
  242. data/lib/ohai/plugins/netbsd/hostname.rb +0 -22
  243. data/lib/ohai/plugins/netbsd/kernel.rb +0 -35
  244. data/lib/ohai/plugins/netbsd/ps.rb +0 -24
  245. data/lib/ohai/plugins/netbsd/uptime.rb +0 -31
  246. data/lib/ohai/plugins/openbsd/hostname.rb +0 -22
  247. data/lib/ohai/plugins/openbsd/kernel.rb +0 -35
  248. data/lib/ohai/plugins/openbsd/ps.rb +0 -24
  249. data/lib/ohai/plugins/sigar/hostname.rb +0 -28
  250. data/lib/ohai/plugins/sigar/uptime.rb +0 -27
  251. data/lib/ohai/plugins/solaris2/hostname.rb +0 -34
  252. data/lib/ohai/plugins/solaris2/kernel.rb +0 -40
  253. data/lib/ohai/plugins/solaris2/ps.rb +0 -23
  254. data/lib/ohai/plugins/solaris2/uptime.rb +0 -36
  255. data/lib/ohai/plugins/windows/hostname.rb +0 -33
  256. data/lib/ohai/plugins/windows/kernel.rb +0 -58
  257. data/lib/ohai/plugins/windows/kernel_devices.rb +0 -39
  258. data/lib/ohai/plugins/windows/uptime.rb +0 -23
  259. data/spec/unit/mixin/from_file_spec.rb +0 -53
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Benjamin Black (<bb@opscode.com>)
3
- # Copyright:: Copyright (c) 2009 Opscode, Inc.
3
+ # Author:: Theodore Nordsieck (<theo@opscode.com>)
4
+ # Copyright:: Copyright (c) 2009-2013 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,104 +21,149 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
20
21
 
21
22
  describe Ohai::System, "plugin java (Java5 Client VM)" do
22
23
  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 -mx64m -version"}).and_return([@status, @stdout, @stderr])
24
+ @plugin = get_plugin("java")
25
+ @plugin[:languages] = Mash.new
26
+ end
27
+
28
+ shared_examples_for "when the JRE is installed" do
29
+ before do
30
+ @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)"
31
+ @plugin.stub(:shell_out).with("java -version").and_return(mock_shell_out(0, "", @stderr))
32
+ end
33
+
34
+ it "should run java -version" do
35
+ @plugin.should_receive(:shell_out).with("java -version").and_return(mock_shell_out(0, "", @stderr))
36
+ @plugin.run
37
+ end
38
+
39
+ it "should set java[:version]" do
40
+ @plugin.run
41
+ @plugin[:languages][:java][:version].should eql("1.5.0_16")
42
+ end
43
+
44
+ it "should set java[:runtime][:name] to runtime name" do
45
+ @plugin.run
46
+ @plugin[:languages][:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment, Standard Edition")
47
+ end
48
+
49
+ it "should set java[:runtime][:build] to runtime build" do
50
+ @plugin.run
51
+ @plugin[:languages][:java][:runtime][:build].should eql("1.5.0_16-b06-284")
52
+ end
53
+
54
+ it "should set java[:hotspot][:name] to hotspot name" do
55
+ @plugin.run
56
+ @plugin[:languages][:java][:hotspot][:name].should eql("Java HotSpot(TM) Client VM")
57
+ end
58
+
59
+ it "should set java[:hotspot][:build] to hotspot build" do
60
+ @plugin.run
61
+ @plugin[:languages][:java][:hotspot][:build].should eql("1.5.0_16-133, mixed mode, sharing")
62
+ end
63
+
64
+ it "should not set the languages[:java] tree up if java command fails" do
65
+ @stderr = "Some error output here"
66
+ @plugin.stub(:shell_out).with("java -version").and_return(mock_shell_out(1, "", @stderr))
67
+ @plugin.run
68
+ @plugin[:languages].should_not have_key(:java)
69
+ end
70
+ end
71
+
72
+ shared_examples_for "when the Server JRE is installed" do
73
+
74
+ before(:each) do
75
+ @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)"
76
+ @plugin.stub(:shell_out).with("java -version").and_return(mock_shell_out(0, "", @stderr))
77
+ end
78
+
79
+ it "should run java -version" do
80
+ @plugin.should_receive(:shell_out).with("java -version").and_return(mock_shell_out(0, "", @stderr))
81
+ @plugin.run
82
+ end
83
+
84
+ it "should set java[:version]" do
85
+ @plugin.run
86
+ @plugin[:languages][:java][:version].should eql("1.6.0_22")
87
+ end
88
+
89
+ it "should set java[:runtime][:name] to runtime name" do
90
+ @plugin.run
91
+ @plugin[:languages][:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment")
92
+ end
93
+
94
+ it "should set java[:runtime][:build] to runtime build" do
95
+ @plugin.run
96
+ @plugin[:languages][:java][:runtime][:build].should eql("1.6.0_22-b04")
97
+ end
98
+
99
+ it "should set java[:hotspot][:name] to hotspot name" do
100
+ @plugin.run
101
+ @plugin[:languages][:java][:hotspot][:name].should eql("Java HotSpot(TM) Server VM")
102
+ end
103
+
104
+ it "should set java[:hotspot][:build] to hotspot build" do
105
+ @plugin.run
106
+ @plugin[:languages][:java][:hotspot][:build].should eql("17.1-b03, mixed mode")
107
+ end
108
+
109
+ it "should not set the languages[:java] tree up if java command fails" do
110
+ @stderr = "Some error output here"
111
+ @plugin.stub(:shell_out).with("java -version").and_return(mock_shell_out(0, "", @stderr))
112
+ @plugin.run
113
+ @plugin[:languages].should_not have_key(:java)
114
+ end
115
+ end
116
+
117
+ context "when not on Mac OS X" do
118
+ before do
119
+ stub_const("RUBY_PLATFORM", "x86_64-linux")
120
+ end
121
+
122
+ context "and the client JRE is installed" do
123
+ include_examples "when the JRE is installed"
124
+ end
125
+ context "and the server JRE is installed" do
126
+ include_examples "when the Server JRE is installed"
127
+ end
128
+ end
129
+
130
+ context "when on Mac OS X with Java installed" do
131
+ before do
132
+ stub_const("RUBY_PLATFORM", "x86_64-darwin12.3.0")
133
+ end
134
+
135
+ it "detects that it is on a darwin platform" do
136
+ @plugin.should be_on_darwin
137
+ end
138
+
139
+ context "and real Java is installed" do
140
+ before do
141
+ java_home_status = double(Process::Status, :success? => true)
142
+ java_home_cmd = double(Mixlib::ShellOut, :status => java_home_status)
143
+ @plugin.should_receive(:shell_out).with("/usr/libexec/java_home").and_return(java_home_cmd)
144
+ end
145
+
146
+ context "and the client JRE is installed" do
147
+ include_examples "when the JRE is installed"
148
+ end
149
+ context "and the server JRE is installed" do
150
+ include_examples "when the Server JRE is installed"
151
+ end
152
+ end
153
+
154
+ context "and the JVM stubs are installed" do
155
+ before do
156
+ java_home_status = double(Process::Status, :success? => false)
157
+ java_home_cmd = double(Mixlib::ShellOut, :status => java_home_status)
158
+ @plugin.should_receive(:shell_out).with("/usr/libexec/java_home").and_return(java_home_cmd)
159
+ end
160
+
161
+ it "does not attempt to get java info" do
162
+ @plugin.should_not_receive(:shell_out).with("java -version")
163
+ @plugin.run
164
+ @plugin[:languages].should_not have_key(:java)
165
+ end
166
+ end
30
167
  end
31
168
 
32
- it "should run java -mx64m -version" do
33
- @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "java -mx64m -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 = "Some error output here"
66
- @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -mx64m -version"}).and_return([@status, @stdout, @stderr])
67
- @ohai._require_plugin("java")
68
- @ohai.languages.should_not have_key(:java)
69
- end
70
169
  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 -mx64m -version"}).and_return([@status, @stdout, @stderr])
81
- end
82
-
83
- it "should run java -mx64m -version" do
84
- @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "java -mx64m -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 -mx64m -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
-
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,23 +21,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
21
21
 
22
22
  describe Ohai::System, "plugin kernel" do
23
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")
24
+ @plugin = get_plugin("kernel")
25
+ @plugin.stub(:collect_os).and_return(:default) # for debugging
26
+ @plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "Darwin\n", ""))
27
+ @plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "9.5.0\n", ""))
28
+ @plugin.stub(:shell_out).with("uname -v").and_return(mock_shell_out(0, "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386\n", ""))
29
+ @plugin.stub(:shell_out).with("uname -m").and_return(mock_shell_out(0, "i386\n", ""))
30
+ @plugin.stub(:shell_out).with("uname -o").and_return(mock_shell_out(0, "Linux\n", ""))
33
31
  end
34
32
 
35
- it_should_check_from_mash("kernel", "name", "uname -s", "Darwin")
33
+ it_should_check_from_mash("kernel", "name", "uname -s", [0, "Darwin\n", ""])
34
+ it_should_check_from_mash("kernel", "release", "uname -r", [0, "9.5.0\n", ""])
35
+ it_should_check_from_mash("kernel", "version", "uname -v", [0, "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386\n", ""])
36
+ it_should_check_from_mash("kernel", "machine", "uname -m", [0, "i386\n", ""])
37
+
38
+ describe "when running on windows", :windows_only do
39
+ before do
40
+ require 'ruby-wmi'
41
+
42
+ @ohai_system = Ohai::System.new
43
+ @plugin = get_plugin("kernel", @ohai_system)
36
44
 
37
- it_should_check_from_mash("kernel", "release", "uname -r", "9.5.0")
45
+ caption = double("WIN32OLE", :name => "caption")
46
+ version = double("WIN32OLE", :name => "version")
47
+ build_number = double("WIN32OLE", :name => "BuildNumber")
48
+ csd_version = double("WIN32OLE", :name => "CsdVersion")
49
+ os_type = double("WIN32OLE", :name => "OsType")
50
+ os_properties = [ caption, version, build_number, csd_version, os_type ]
38
51
 
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")
52
+ os = double("WIN32OLE",
53
+ :properties_ => os_properties,
54
+ :caption => "Microsoft Windows 7 Ultimate",
55
+ :version => "6.1.7601",
56
+ :BuildNumber => "7601",
57
+ :CsdVersion => "Service Pack 1",
58
+ :OsType => 18)
59
+ WMI::Win32_OperatingSystem.should_receive(:find).with(:first).and_return(os)
40
60
 
41
- it_should_check_from_mash("kernel", "machine", "uname -m", "i386")
61
+ cs = double("WIN32OLE",
62
+ :properties_ => [ double("WIN32OLE", :name => "SystemType") ],
63
+ :SystemType => "x64-based PC")
64
+ WMI::Win32_ComputerSystem.should_receive(:find).with(:first).and_return(cs)
65
+
66
+ WMI::Win32_PnPSignedDriver.should_receive(:find).with(:all).and_return([ ])
67
+
68
+ @plugin.run
69
+ end
70
+ it "should set the corrent system information" do
71
+ @ohai_system.data[:kernel][:name].should == "Microsoft Windows 7 Ultimate"
72
+ @ohai_system.data[:kernel][:release].should == "6.1.7601"
73
+ @ohai_system.data[:kernel][:version].should == "6.1.7601 Service Pack 1 Build 7601"
74
+ @ohai_system.data[:kernel][:os].should == "WINNT"
75
+ @ohai_system.data[:kernel][:machine].should == "x86_64"
76
+ end
77
+ end
42
78
 
43
79
  end
@@ -22,9 +22,8 @@ describe Ohai::System, "plugin linode" do
22
22
  let(:hint_path_win) { 'C:\chef\ohai\hints/linode.json' }
23
23
 
24
24
  before do
25
- @ohai = Ohai::System.new
26
- @ohai.stub!(:require_plugin).and_return(true)
27
- @ohai[:network] = {
25
+ @plugin = get_plugin("linode")
26
+ @plugin[:network] = {
28
27
  "interfaces"=> {
29
28
  "eth0"=> {
30
29
  "addresses"=> {
@@ -49,32 +48,32 @@ describe Ohai::System, "plugin linode" do
49
48
 
50
49
  shared_examples_for "!linode" do
51
50
  it "does not create the linode mash" do
52
- @ohai._require_plugin("linode")
53
- @ohai[:linode].should be_nil
51
+ @plugin.run
52
+ @plugin[:linode].should be_nil
54
53
  end
55
54
  end
56
55
 
57
56
  shared_examples_for "linode" do
58
57
  it "creates a linode mash" do
59
- @ohai._require_plugin("linode")
60
- @ohai[:linode].should_not be_nil
58
+ @plugin.run
59
+ @plugin[:linode].should_not be_nil
61
60
  end
62
61
 
63
62
  it "has all required attributes" do
64
- @ohai._require_plugin("linode")
65
- @ohai[:linode][:public_ip].should_not be_nil
63
+ @plugin.run
64
+ @plugin[:linode][:public_ip].should_not be_nil
66
65
  end
67
66
 
68
67
  it "has correct values for all attributes" do
69
- @ohai._require_plugin("linode")
70
- @ohai[:linode][:public_ip].should == "1.2.3.4"
68
+ @plugin.run
69
+ @plugin[:linode][:public_ip].should == "1.2.3.4"
71
70
  end
72
71
 
73
72
  end
74
73
 
75
74
  context "without linode kernel" do
76
75
  before do
77
- @ohai[:kernel] = { "release" => "3.5.2-x86_64" }
76
+ @plugin[:kernel] = { "release" => "3.5.2-x86_64" }
78
77
  end
79
78
 
80
79
  it_should_behave_like "!linode"
@@ -82,7 +81,7 @@ describe Ohai::System, "plugin linode" do
82
81
 
83
82
  context "with linode kernel" do
84
83
  before do
85
- @ohai[:kernel] = { "release" => "3.5.2-x86_64-linode24" }
84
+ @plugin[:kernel] = { "release" => "3.5.2-x86_64-linode24" }
86
85
  end
87
86
 
88
87
  it_should_behave_like "linode"
@@ -91,7 +90,7 @@ describe Ohai::System, "plugin linode" do
91
90
  # http://library.linode.com/networking/configuring-static-ip-interfaces
92
91
  context "with configured private ip address as suggested by linode" do
93
92
  before do
94
- @ohai[:network][:interfaces]["eth0:1"] = {
93
+ @plugin[:network][:interfaces]["eth0:1"] = {
95
94
  "addresses" => {
96
95
  "5.6.7.8"=> {
97
96
  "broadcast"=> "10.176.191.255",
@@ -111,9 +110,9 @@ describe Ohai::System, "plugin linode" do
111
110
  end
112
111
 
113
112
  it "detects and sets the private ip" do
114
- @ohai._require_plugin("linode")
115
- @ohai[:linode][:private_ip].should_not be_nil
116
- @ohai[:linode][:private_ip].should == "5.6.7.8"
113
+ @plugin.run
114
+ @plugin[:linode][:private_ip].should_not be_nil
115
+ @plugin[:linode][:private_ip].should == "5.6.7.8"
117
116
  end
118
117
  end
119
118
 
@@ -121,10 +120,10 @@ describe Ohai::System, "plugin linode" do
121
120
 
122
121
  describe "with linode cloud file" do
123
122
  before do
124
- File.stub!(:exist?).with(hint_path_nix).and_return(true)
125
- File.stub!(:read).with(hint_path_nix).and_return('')
126
- File.stub!(:exist?).with(hint_path_win).and_return(true)
127
- File.stub!(:read).with(hint_path_win).and_return('')
123
+ File.stub(:exist?).with(hint_path_nix).and_return(true)
124
+ File.stub(:read).with(hint_path_nix).and_return('')
125
+ File.stub(:exist?).with(hint_path_win).and_return(true)
126
+ File.stub(:read).with(hint_path_win).and_return('')
128
127
  end
129
128
 
130
129
  it_should_behave_like "linode"
@@ -132,22 +131,25 @@ describe Ohai::System, "plugin linode" do
132
131
 
133
132
  describe "without cloud file" do
134
133
  before do
135
- File.stub!(:exist?).with(hint_path_nix).and_return(false)
136
- File.stub!(:exist?).with(hint_path_win).and_return(false)
134
+ File.stub(:exist?).with(hint_path_nix).and_return(false)
135
+ File.stub(:exist?).with(hint_path_win).and_return(false)
137
136
  end
138
137
 
139
138
  it_should_behave_like "!linode"
140
139
  end
141
140
 
142
141
  context "with ec2 cloud file" do
143
- let(:hint_path_nix) { '/etc/chef/ohai/hints/ec2.json' }
144
- let(:hint_path_win) { 'C:\chef\ohai\hints/ec2.json' }
142
+ let(:ec2_hint_path_nix) { '/etc/chef/ohai/hints/ec2.json' }
143
+ let(:ec2_hint_path_win) { 'C:\chef\ohai\hints/ec2.json' }
145
144
 
146
145
  before do
147
- File.stub!(:exist?).with(hint_path_nix).and_return(true)
148
- File.stub!(:read).with(hint_path_nix).and_return('')
149
- File.stub!(:exist?).with(hint_path_win).and_return(true)
150
- File.stub!(:read).with(hint_path_win).and_return('')
146
+ File.stub(:exist?).with(hint_path_nix).and_return(false)
147
+ File.stub(:exist?).with(hint_path_win).and_return(false)
148
+
149
+ File.stub(:exist?).with(ec2_hint_path_nix).and_return(true)
150
+ File.stub(:read).with(ec2_hint_path_nix).and_return('')
151
+ File.stub(:exist?).with(ec2_hint_path_win).and_return(true)
152
+ File.stub(:read).with(ec2_hint_path_win).and_return('')
151
153
  end
152
154
 
153
155
  it_should_behave_like "!linode"