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,14 +1,15 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Author:: Claire McQuin (<claire@opscode.com>)
4
+ # Copyright:: Copyright (c) 2008, 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");
7
8
  # you may not use this file except in compliance with the License.
8
9
  # You may obtain a copy of the License at
9
- #
10
+ #
10
11
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
+ #
12
13
  # Unless required by applicable law or agreed to in writing, software
13
14
  # distributed under the License is distributed on an "AS IS" BASIS,
14
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,140 +18,674 @@
17
18
  #
18
19
 
19
20
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
21
+ require 'ohai/mixin/os'
20
22
 
21
- describe Ohai::System, "initialize" do
22
- it "should return an Ohai::System object" do
23
- Ohai::System.new.should be_a_kind_of(Ohai::System)
24
- end
25
-
26
- it "should set @data to a Mash" do
27
- Ohai::System.new.data.should be_a_kind_of(Mash)
28
- end
29
-
30
- it "should set @seen_plugins to a Hash" do
31
- Ohai::System.new.seen_plugins.should be_a_kind_of(Hash)
23
+ describe "Ohai::System" do
24
+ extend IntegrationSupport
25
+
26
+ let(:ohai) { Ohai::System.new }
27
+
28
+ describe "#initialize" do
29
+ it "should return an Ohai::System object" do
30
+ ohai.should be_a_kind_of(Ohai::System)
31
+ end
32
+
33
+ it "should set @attributes to a ProvidesMap" do
34
+ ohai.provides_map.should be_a_kind_of(Ohai::ProvidesMap)
35
+ end
36
+
37
+ it "should set @v6_dependency_solver to a Hash" do
38
+ ohai.v6_dependency_solver.should be_a_kind_of(Hash)
39
+ end
32
40
  end
41
+
42
+ when_plugins_directory "contains v6 and v7 plugins" do
43
+ with_plugin("zoo.rb", <<EOF)
44
+ Ohai.plugin(:Zoo) do
45
+ provides 'seals'
33
46
  end
47
+ EOF
34
48
 
35
- describe Ohai::System, "method_missing" do
36
- before(:each) do
37
- @ohai = Ohai::System.new
49
+ with_plugin("lake.rb", <<EOF)
50
+ provides 'fish'
51
+ EOF
52
+
53
+ before do
54
+ @original_config = Ohai::Config[:plugin_path]
55
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
56
+ end
57
+
58
+ it "load_plugins() should load all the plugins" do
59
+ ohai.load_plugins
60
+ ohai.provides_map.map.keys.should include("seals")
61
+ ohai.v6_dependency_solver.keys.should include("lake.rb")
62
+ Ohai::NamedPlugin.const_get(:Zoo).should == Ohai::NamedPlugin::Zoo
63
+ end
38
64
  end
39
-
40
- it "should take a missing method and store the method name as a key, with its arguments as values" do
41
- @ohai.guns_n_roses("chinese democracy")
42
- @ohai.data["guns_n_roses"].should eql("chinese democracy")
65
+
66
+ when_plugins_directory "contains directories inside" do
67
+ with_plugin("repo1/zoo.rb", <<EOF)
68
+ Ohai.plugin(:Zoo) do
69
+ provides 'seals'
70
+ end
71
+ EOF
72
+
73
+ with_plugin("repo1/lake.rb", <<EOF)
74
+ provides 'fish'
75
+ EOF
76
+
77
+ with_plugin("repo2/nature.rb", <<EOF)
78
+ Ohai.plugin(:Nature) do
79
+ provides 'crabs'
80
+ end
81
+ EOF
82
+
83
+ with_plugin("repo2/mountain.rb", <<EOF)
84
+ provides 'bear'
85
+ EOF
86
+
87
+ before do
88
+ @original_config = Ohai::Config[:plugin_path]
89
+ Ohai::Config[:plugin_path] = [ path_to("repo1"), path_to("repo2") ]
90
+ end
91
+
92
+ after do
93
+ Ohai::Config[:plugin_path] = @original_config
94
+ end
95
+
96
+ it "load_plugins() should load all the plugins" do
97
+ ohai.load_plugins
98
+ ohai.provides_map.map.keys.should include("seals")
99
+ ohai.provides_map.map.keys.should include("crabs")
100
+ ohai.v6_dependency_solver.keys.should include("lake.rb")
101
+ ohai.v6_dependency_solver.keys.should include("mountain.rb")
102
+ Ohai::NamedPlugin.const_get(:Zoo).should == Ohai::NamedPlugin::Zoo
103
+ Ohai::NamedPlugin.const_get(:Nature).should == Ohai::NamedPlugin::Nature
104
+ end
105
+
43
106
  end
44
-
45
- it "should return the current value of the method name" do
46
- @ohai.guns_n_roses("chinese democracy").should eql("chinese democracy")
107
+
108
+ describe "when running plugins" do
109
+ before do
110
+ @original_config = Ohai::Config[:plugin_path]
111
+ end
112
+
113
+ after do
114
+ Ohai::Config[:plugin_path] = @original_config
115
+ end
116
+
117
+ when_plugins_directory "contains v6 plugins only" do
118
+ with_plugin("zoo.rb", <<EOF)
119
+ provides 'zoo'
120
+ zoo("animals")
121
+ EOF
122
+
123
+ with_plugin("park.rb", <<EOF)
124
+ provides 'park'
125
+ park("plants")
126
+ EOF
127
+
128
+ it "should collect data from all the plugins" do
129
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
130
+ ohai.all_plugins
131
+ ohai.data[:zoo].should == "animals"
132
+ ohai.data[:park].should == "plants"
133
+ end
134
+
135
+ describe "when using :disabled_plugins" do
136
+ before do
137
+ Ohai::Config[:disabled_plugins] = [ "zoo" ]
138
+ end
139
+
140
+ after do
141
+ Ohai::Config[:disabled_plugins] = [ ]
142
+ end
143
+
144
+ it "shouldn't run disabled version 6 plugins" do
145
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
146
+ ohai.all_plugins
147
+ ohai.data[:zoo].should be_nil
148
+ ohai.data[:park].should == "plants"
149
+ end
150
+ end
151
+
152
+ describe "when running in whitelist mode" do
153
+ let(:ohai_system) { Ohai::System.new }
154
+
155
+ let(:primary_plugin_class) do
156
+ Ohai.plugin(:Primary) do
157
+ provides "primary"
158
+ depends "dependency/one"
159
+ depends "dependency/two"
160
+ collect_data {}
161
+ end
162
+ end
163
+
164
+ let(:dependency_plugin_one_class) do
165
+ Ohai.plugin(:DependencyOne) do
166
+ provides "dependency/one"
167
+ collect_data {}
168
+ end
169
+ end
170
+
171
+ let(:dependency_plugin_two_class) do
172
+ Ohai.plugin(:DependencyTwo) do
173
+ provides "dependency/two"
174
+ collect_data {}
175
+ end
176
+ end
177
+
178
+ let(:unrelated_plugin_class) do
179
+ Ohai.plugin(:Unrelated) do
180
+ provides "whatever"
181
+ collect_data {}
182
+ end
183
+ end
184
+
185
+ let(:v6_plugin_class) do
186
+ Class.new(Ohai::DSL::Plugin::VersionVI) { collect_contents("v6_key('v6_data')") }
187
+ end
188
+
189
+ let(:primary_plugin) { primary_plugin_class.new(ohai_system) }
190
+ let(:dependency_plugin_one) { dependency_plugin_one_class.new(ohai_system) }
191
+ let(:dependency_plugin_two) { dependency_plugin_two_class.new(ohai_system) }
192
+ let(:unrelated_plugin) { unrelated_plugin_class.new(ohai_system) }
193
+ let(:v6_plugin) { v6_plugin_class.new(ohai_system, "/v6_plugin.rb", "/") }
194
+
195
+ before do
196
+ ohai_system.stub(:load_plugins) # TODO: temporary hack - don't run unrelated plugins...
197
+ [ primary_plugin, dependency_plugin_one, dependency_plugin_two, unrelated_plugin].each do |plugin|
198
+ plugin_provides = plugin.class.provides_attrs
199
+ ohai_system.provides_map.set_providers_for(plugin, plugin_provides)
200
+ end
201
+
202
+ ohai_system.v6_dependency_solver["v6_plugin"] = v6_plugin
203
+
204
+ # Instead of calling all plugins we call load and run directly so that the information we setup is not cleared by all_plugins
205
+ ohai_system.load_plugins
206
+ ohai_system.run_plugins(true, "primary")
207
+ end
208
+
209
+ # This behavior choice is somewhat arbitrary, based on what creates the
210
+ # least code complexity in legacy v6 plugin format support. Once we
211
+ # ship 7.0, though, we need to stick to the same behavior.
212
+ it "runs v6 plugins" do
213
+ expect(v6_plugin.has_run?).to be_true
214
+ end
215
+
216
+ it "runs plugins that provide the requested attributes" do
217
+ expect(primary_plugin.has_run?).to be_true
218
+ end
219
+
220
+ it "runs dependencies of plugins that provide requested attributes" do
221
+ expect(dependency_plugin_one.has_run?).to be_true
222
+ expect(dependency_plugin_two.has_run?).to be_true
223
+ end
224
+
225
+ it "does not run plugins that are irrelevant to the requested attributes" do
226
+ expect(unrelated_plugin.has_run?).to be_false
227
+ end
228
+
229
+ end
230
+ end
231
+
232
+ when_plugins_directory "contains a v7 plugins with :default and platform specific blocks" do
233
+ with_plugin("message.rb", <<EOF)
234
+ Ohai.plugin(:Message) do
235
+ provides 'message'
236
+
237
+ collect_data(:default) do
238
+ message("default")
47
239
  end
48
-
49
- it "should allow you to get the value of a key by calling method_missing with no arguments" do
50
- @ohai.guns_n_roses("chinese democracy")
51
- @ohai.guns_n_roses.should eql("chinese democracy")
240
+
241
+ collect_data(:#{Ohai::Mixin::OS.collect_os}) do
242
+ message("platform_specific_message")
52
243
  end
53
244
  end
245
+ EOF
54
246
 
55
- describe Ohai::System, "attribute?" do
56
- before(:each) do
57
- @ohai = Ohai::System.new
58
- @ohai.metallica("death magnetic")
59
- end
60
-
61
- it "should return true if an attribute exists with the given name" do
62
- @ohai.attribute?("metallica").should eql(true)
63
- end
64
-
65
- it "should return false if an attribute does not exist with the given name" do
66
- @ohai.attribute?("alice in chains").should eql(false)
247
+ it "should collect platform specific" do
248
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
249
+ ohai.all_plugins
250
+ ohai.data[:message].should == "platform_specific_message"
251
+ end
252
+ end
253
+
254
+ when_plugins_directory "contains v7 plugins only" do
255
+ with_plugin("zoo.rb", <<EOF)
256
+ Ohai.plugin(:Zoo) do
257
+ provides 'zoo'
258
+
259
+ collect_data(:default) do
260
+ zoo("animals")
67
261
  end
68
262
  end
263
+ EOF
69
264
 
70
- describe Ohai::System, "set_attribute" do
71
- before(:each) do
72
- @ohai = Ohai::System.new
265
+ with_plugin("park.rb", <<EOF)
266
+ Ohai.plugin(:Park) do
267
+ provides 'park'
268
+ collect_data(:default) do
269
+ park("plants")
73
270
  end
74
-
75
- it "should let you set an attribute" do
76
- @ohai.set_attribute(:tea, "is soothing")
77
- @ohai.data["tea"].should eql("is soothing")
78
- end
79
271
  end
272
+ EOF
273
+
274
+ it "should collect data from all the plugins" do
275
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
276
+ ohai.all_plugins
277
+ ohai.data[:zoo].should == "animals"
278
+ ohai.data[:park].should == "plants"
279
+ end
280
+
281
+ it "should write an error to Ohai::Log" do
282
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
283
+ # Make sure the stubbing of runner is not overriden with reset_system during test
284
+ ohai.stub(:reset_system)
285
+ ohai.instance_variable_get("@runner").stub(:run_plugin).and_raise(Ohai::Exceptions::AttributeNotFound)
286
+ Ohai::Log.should_receive(:error).with(/Encountered error while running plugins/)
287
+ expect { ohai.all_plugins }.to raise_error(Ohai::Exceptions::AttributeNotFound)
288
+ end
289
+
290
+ describe "when using :disabled_plugins" do
291
+ before do
292
+ Ohai::Config[:disabled_plugins] = [ :Zoo ]
293
+ end
294
+
295
+ after do
296
+ Ohai::Config[:disabled_plugins] = [ ]
297
+ end
298
+
299
+ it "shouldn't run disabled plugins" do
300
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
301
+ ohai.all_plugins
302
+ ohai.data[:zoo].should be_nil
303
+ ohai.data[:park].should == "plants"
304
+ end
305
+ end
306
+ end
307
+
308
+ when_plugins_directory "contains v6 & v7 plugins in different directories" do
309
+ with_plugin("my_plugins/zoo.rb", <<EOF)
310
+ Ohai.plugin(:Zoo) do
311
+ provides 'zoo'
80
312
 
81
- describe Ohai::System, "get_attribute" do
82
- before(:each) do
83
- @ohai = Ohai::System.new
84
- @ohai.set_attribute(:tea, "is soothing")
313
+ collect_data(:default) do
314
+ zoo("animals")
85
315
  end
86
-
87
- it "should let you get an attribute" do
88
- @ohai.get_attribute("tea").should eql("is soothing")
89
- end
90
316
  end
317
+ EOF
91
318
 
92
- describe Ohai::System, "require_plugin" do
93
- tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'
319
+ with_plugin("my_plugins/nature.rb", <<EOF)
320
+ Ohai.plugin(:Nature) do
321
+ provides 'nature'
94
322
 
95
- before(:each) do
96
- @plugin_path = Ohai::Config[:plugin_path]
97
- Ohai::Config[:plugin_path] = ["#{tmp}/plugins"]
98
- File.stub!(:exists?).and_return(true)
99
- @ohai = Ohai::System.new
100
- @ohai.stub!(:from_file).and_return(true)
323
+ collect_data(:default) do
324
+ nature("cougars")
101
325
  end
326
+ end
327
+ EOF
328
+
329
+ with_plugin("my_plugins/park.rb", <<EOF)
330
+ provides 'park'
331
+ park("plants")
332
+ EOF
333
+
334
+ with_plugin("my_plugins/home.rb", <<EOF)
335
+ provides 'home'
336
+ home("dog")
337
+ EOF
338
+
339
+ describe "when using :disabled_plugins" do
340
+ before do
341
+ Ohai::Config[:disabled_plugins] = [ :Zoo, 'my_plugins::park' ]
342
+ end
343
+
344
+ after do
345
+ Ohai::Config[:disabled_plugins] = [ ]
346
+ end
347
+
348
+ it "shouldn't run disabled plugins" do
349
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
350
+ ohai.all_plugins
351
+ ohai.data[:zoo].should be_nil
352
+ ohai.data[:nature].should == "cougars"
353
+ ohai.data[:park].should be_nil
354
+ ohai.data[:home].should == "dog"
355
+ end
356
+ end
357
+ end
358
+
359
+ when_plugins_directory "contains v6 plugins that depend on v7 plugins" do
360
+ with_plugin("messages.rb", <<EOF)
361
+ require_plugin 'v6message'
362
+ require_plugin 'v7message'
363
+
364
+ provides 'messages'
102
365
 
103
- after(:each) do
104
- Ohai::Config[:plugin_path] = @plugin_path
366
+ messages Mash.new
367
+ messages[:v6message] = v6message
368
+ messages[:v7message] = v7message
369
+ EOF
370
+
371
+ with_plugin("v6message.rb", <<EOF)
372
+ provides 'v6message'
373
+ v6message "update me!"
374
+ EOF
375
+
376
+ with_plugin("v7message.rb", <<EOF)
377
+ Ohai.plugin(:V7message) do
378
+ provides 'v7message'
379
+
380
+ collect_data(:default) do
381
+ v7message "v7 plugins are awesome!"
105
382
  end
106
-
107
- it "should convert the name of the plugin to a file path" do
108
- plugin_name = "foo::bar"
109
- plugin_name.should_receive(:gsub).with("::", File::SEPARATOR)
110
- @ohai.require_plugin(plugin_name)
383
+ end
384
+ EOF
385
+
386
+ before do
387
+ @original_config = Ohai::Config[:plugin_path]
388
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
389
+ end
390
+
391
+ after do
392
+ Ohai::Config[:plugin_path] = @original_config
393
+ end
394
+
395
+ it "should collect all data" do
396
+ ohai.all_plugins
397
+ [:v6message, :v7message, :messages].each do |attribute|
398
+ ohai.data.should have_key(attribute)
399
+ end
400
+
401
+ ohai.data[:v6message].should eql("update me!")
402
+ ohai.data[:v7message].should eql("v7 plugins are awesome!")
403
+ [:v6message, :v7message].each do |subattr|
404
+ ohai.data[:messages].should have_key(subattr)
405
+ ohai.data[:messages][subattr].should eql(ohai.data[subattr])
406
+ end
407
+ end
408
+ end
111
409
  end
112
-
113
- it "should check each part of the Ohai::Config[:plugin_path] for the plugin_filename.rb" do
114
- @ohai.should_receive(:from_file).with(File.expand_path("#{tmp}/plugins/foo.rb")).and_return(true)
115
- @ohai.require_plugin("foo")
410
+
411
+ describe "require_plugin()" do
412
+ when_plugins_directory "contains v6 and v7 plugin with the same name" do
413
+ with_plugin("message.rb", <<EOF)
414
+ provides 'message'
415
+
416
+ message "From Version 6"
417
+ EOF
418
+
419
+ with_plugin("v7/message.rb", <<EOF)
420
+ Ohai.plugin(:Message) do
421
+ provides 'message'
422
+
423
+ collect_data(:default) do
424
+ message "From Version 7"
116
425
  end
426
+ end
427
+ EOF
428
+
429
+ before do
430
+ @original_config = Ohai::Config[:plugin_path]
431
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
432
+ end
433
+
434
+ after do
435
+ Ohai::Config[:plugin_path] = @original_config
436
+ end
437
+
438
+ it "version 6 should run" do
439
+ ohai.load_plugins
440
+ ohai.require_plugin("message")
441
+ ohai.data[:message].should eql("From Version 6")
442
+ end
443
+ end
117
444
 
118
- it "should add a found plugin to the list of seen plugins" do
119
- @ohai.require_plugin("foo")
120
- @ohai.seen_plugins["foo"].should eql(true)
445
+ when_plugins_directory "a v6 plugin that requires a v7 plugin with dependencies" do
446
+ with_plugin("message.rb", <<EOF)
447
+ provides 'message'
448
+
449
+ require_plugin 'v7message'
450
+
451
+ message Mash.new
452
+ message[:v6message] = "Hellos from 6"
453
+ message[:copy_message] = v7message
454
+ EOF
455
+
456
+ with_plugin("v7message.rb", <<EOF)
457
+ Ohai.plugin(:V7message) do
458
+ provides 'v7message'
459
+ depends 'zoo'
460
+
461
+ collect_data(:default) do
462
+ v7message ("Hellos from 7: " + zoo)
121
463
  end
122
-
123
- it "should return true if the plugin has been seen" do
124
- @ohai.seen_plugins["foo"] = true
125
- @ohai.require_plugin("foo")
464
+ end
465
+ EOF
466
+
467
+ with_plugin("zoo.rb", <<EOF)
468
+ Ohai.plugin(:Zoo) do
469
+ provides 'zoo'
470
+
471
+ collect_data(:default) do
472
+ zoo "animals"
126
473
  end
127
-
128
- it "should return true if the plugin has been loaded" do
129
- @ohai.require_plugin("foo").should eql(true)
474
+ end
475
+ EOF
476
+
477
+ before do
478
+ @original_config = Ohai::Config[:plugin_path]
479
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
480
+ end
481
+
482
+ after do
483
+ Ohai::Config[:plugin_path] = @original_config
484
+ end
485
+
486
+ it "should collect all the data properly" do
487
+ ohai.all_plugins
488
+ ohai.data[:v7message].should == "Hellos from 7: animals"
489
+ ohai.data[:zoo].should == "animals"
490
+ ohai.data[:message][:v6message].should == "Hellos from 6"
491
+ ohai.data[:message][:copy_message].should == "Hellos from 7: animals"
492
+ end
493
+ end
494
+
495
+ when_plugins_directory "a v6 plugin that requires non-existing v7 plugin" do
496
+ with_plugin("message.rb", <<EOF)
497
+ provides 'message'
498
+
499
+ require_plugin 'v7message'
500
+
501
+ message v7message
502
+ EOF
503
+
504
+ before do
505
+ @original_config = Ohai::Config[:plugin_path]
506
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
507
+ end
508
+
509
+ after do
510
+ Ohai::Config[:plugin_path] = @original_config
511
+ end
512
+
513
+ it "should raise DependencyNotFound" do
514
+ lambda { ohai.all_plugins }.should raise_error(Ohai::Exceptions::DependencyNotFound)
515
+ end
516
+ end
130
517
  end
131
518
 
132
- it "should return false if the plugin is in the disabled plugins list" do
133
- Ohai::Config[:disabled_plugins] = [ "foo" ]
134
- Ohai::Log.should_receive(:debug).with("Skipping disabled plugin foo")
135
- @ohai.require_plugin("foo").should eql(false)
519
+ describe "when Chef OHAI resource executes :reload action" do
520
+ when_plugins_directory "contains a random plugin" do
521
+ with_plugin("random.rb", <<-E)
522
+ Ohai.plugin(:Random) do
523
+ provides 'random'
524
+
525
+ collect_data do
526
+ random rand(1 << 32)
527
+ end
528
+ end
529
+ E
530
+
531
+ before do
532
+ @original_config = Ohai::Config[:plugin_path]
533
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
534
+ end
535
+
536
+ after do
537
+ Ohai::Config[:plugin_path] = @original_config
538
+ end
539
+
540
+ it "should rerun the plugin providing the desired attributes" do
541
+ ohai.all_plugins
542
+ initial_value = ohai.data["random"]
543
+ ohai.all_plugins
544
+ updated_value = ohai.data["random"]
545
+ initial_value.should_not == updated_value
546
+ end
547
+
548
+ end
136
549
  end
137
- end
138
550
 
139
- describe Ohai::System, "all_plugins" do
140
- before(:each) do
141
- @ohai = Ohai::System.new
142
- @ohai.stub!(:from_file).and_return(true)
143
- @ohai.stub!(:require_plugin).and_return(false)
144
- @ohai.data[:os] = "ubuntu"
551
+ describe "when refreshing plugins" do
552
+ when_plugins_directory "contains v7 plugins" do
553
+ with_plugin("desired.rb", <<-E)
554
+ Ohai.plugin(:DesiredPlugin) do
555
+ provides 'desired_attr'
556
+ depends 'depended_attr'
557
+
558
+ collect_data do
559
+ desired_attr "hello"
560
+ self[:desired_attr_count] ||= 0
561
+ self[:desired_attr_count] += 1
562
+ end
563
+ end
564
+ E
565
+
566
+ with_plugin("depended.rb", <<-E)
567
+ Ohai.plugin(:DependedPlugin) do
568
+ provides 'depended_attr'
569
+
570
+ collect_data do
571
+ depended_attr "hello"
572
+ self[:depended_attr_count] ||= 0
573
+ self[:depended_attr_count] += 1
574
+ end
575
+ end
576
+ E
577
+
578
+ with_plugin("other.rb", <<-E)
579
+ Ohai.plugin(:OtherPlugin) do
580
+ provides 'other_attr'
581
+
582
+ collect_data do
583
+ other_attr "hello"
584
+ self[:other_attr_count] ||= 0
585
+ self[:other_attr_count] += 1
586
+ end
587
+ end
588
+ E
589
+
590
+ before do
591
+ @original_config = Ohai::Config[:plugin_path]
592
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
593
+ Ohai::Log.init(STDOUT)
594
+ Ohai::Log.level = :debug
595
+ ohai.all_plugins
596
+ end
597
+
598
+ after do
599
+ Ohai::Config[:plugin_path] = @original_config
600
+ end
601
+
602
+ it "should rerun the plugin providing the desired attributes" do
603
+ ohai.data[:desired_attr_count].should == 1
604
+ ohai.refresh_plugins("desired_attr")
605
+ ohai.data[:desired_attr_count].should == 2
606
+ end
607
+
608
+ it "should not re-run dependencies of the plugin providing the desired attributes" do
609
+ ohai.data[:depended_attr_count].should == 1
610
+ ohai.refresh_plugins("desired_attr")
611
+ ohai.data[:depended_attr_count].should == 1
612
+ end
613
+
614
+ it "should not re-run plugins unrelated to the plugin providing the desired attributes" do
615
+ ohai.data[:other_attr_count].should == 1
616
+ ohai.refresh_plugins("desired_attr")
617
+ ohai.data[:other_attr_count].should == 1
618
+ end
619
+
620
+ end
145
621
  end
146
622
 
147
- it "should load plugins when plugin_path has a trailing slash" do
148
- Ohai::Config[:plugin_path] = ["/tmp/plugins/"]
149
- File.stub(:expand_path).with("/tmp/plugins/").and_return("/tmp/plugins") # windows
150
- Dir.should_receive(:[]).with("/tmp/plugins/*").and_return(["/tmp/plugins/darius.rb"])
151
- Dir.should_receive(:[]).with("/tmp/plugins/ubuntu/**/*").and_return([])
152
- @ohai.should_receive(:require_plugin).with("darius")
153
- @ohai.all_plugins
623
+ describe "when running ohai for specific attributes" do
624
+ when_plugins_directory "contains v7 plugins" do
625
+ with_plugin("languages.rb", <<-E)
626
+ Ohai.plugin(:Languages) do
627
+ provides 'languages'
628
+
629
+ collect_data do
630
+ languages Mash.new
631
+ end
632
+ end
633
+ E
634
+
635
+ with_plugin("english.rb", <<-E)
636
+ Ohai.plugin(:English) do
637
+ provides 'languages/english'
638
+
639
+ depends 'languages'
640
+
641
+ collect_data do
642
+ languages[:english] = Mash.new
643
+ languages[:english][:version] = 2014
644
+ end
645
+ end
646
+ E
647
+
648
+ with_plugin("french.rb", <<-E)
649
+ Ohai.plugin(:French) do
650
+ provides 'languages/french'
651
+
652
+ depends 'languages'
653
+
654
+ collect_data do
655
+ languages[:french] = Mash.new
656
+ languages[:french][:version] = 2012
657
+ end
658
+ end
659
+ E
660
+
661
+ before do
662
+ @original_config = Ohai::Config[:plugin_path]
663
+ Ohai::Config[:plugin_path] = [ path_to(".") ]
664
+ end
665
+
666
+ after do
667
+ Ohai::Config[:plugin_path] = @original_config
668
+ end
669
+
670
+ it "should run all the plugins when a top level attribute is specified" do
671
+ ohai.all_plugins("languages")
672
+ ohai.data[:languages][:english][:version].should == 2014
673
+ ohai.data[:languages][:french][:version].should == 2012
674
+ end
675
+
676
+ it "should run the first parent when a non-existent child is specified" do
677
+ ohai.all_plugins("languages/english/version")
678
+ ohai.data[:languages][:english][:version].should == 2014
679
+ ohai.data[:languages][:french].should be_nil
680
+ end
681
+
682
+ it "should be able to run multiple plugins" do
683
+ ohai.all_plugins(["languages/english", "languages/french"])
684
+ ohai.data[:languages][:english][:version].should == 2014
685
+ ohai.data[:languages][:french][:version].should == 2012
686
+ end
687
+
688
+ end
154
689
  end
155
-
690
+
156
691
  end