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
@@ -0,0 +1,44 @@
1
+ require 'tmpdir'
2
+
3
+ module IntegrationSupport
4
+ def when_plugins_directory(description, &block)
5
+ context "When the plugins directory #{description}" do
6
+
7
+ before(:each) do
8
+ @plugins_directory = Dir.mktmpdir('ohai-plugins')
9
+ end
10
+
11
+ after(:each) do
12
+ if @plugins_directory
13
+ begin
14
+ FileUtils.remove_entry_secure(@plugins_directory)
15
+ ensure
16
+ @plugins_directory = nil
17
+ end
18
+ end
19
+ end
20
+
21
+ def with_plugin(plugin_path, contents)
22
+ filename = path_to(plugin_path)
23
+ dir = File.dirname(filename)
24
+ FileUtils.mkdir_p(dir) unless dir == '.'
25
+ File.open(filename, 'w') do |file|
26
+ file.write(contents)
27
+ end
28
+ end
29
+
30
+ def path_to(plugin_path)
31
+ File.expand_path(plugin_path, @plugins_directory)
32
+ end
33
+
34
+ def self.with_plugin(plugin_path, contents)
35
+ before :each do
36
+ with_plugin(plugin_path, contents)
37
+ end
38
+ end
39
+
40
+ instance_eval(&block)
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,298 @@
1
+ #
2
+ # Author:: Claire McQuin (<claire@opscode.com>)
3
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
7
+ # may not use this file except in compliance with the License. You may
8
+ # obtain a copy of the license at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or
15
+ # implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License
18
+ #
19
+
20
+ require File.expand_path("../../../spec_helper.rb", __FILE__)
21
+
22
+ shared_examples "Ohai::DSL::Plugin" do
23
+ context "#initialize" do
24
+ it "should set has_run? to false" do
25
+ plugin.has_run?.should be_false
26
+ end
27
+
28
+ it "should set the correct plugin version" do
29
+ plugin.version.should eql(version)
30
+ end
31
+ end
32
+
33
+ context "#run" do
34
+ it "should set has_run? to true" do
35
+ plugin.stub(:run_plugin).and_return(true)
36
+ plugin.run
37
+ plugin.has_run?.should be_true
38
+ end
39
+ end
40
+
41
+ context "when accessing data via method_missing" do
42
+ it "should take a missing method and store the method name as a key, with its arguments as values" do
43
+ plugin.guns_n_roses("chinese democracy")
44
+ plugin.data["guns_n_roses"].should eql("chinese democracy")
45
+ end
46
+
47
+ it "should return the current value of the method name" do
48
+ plugin.guns_n_roses("chinese democracy").should eql("chinese democracy")
49
+ end
50
+
51
+ it "should allow you to get the value of a key by calling method_missing with no arguments" do
52
+ plugin.guns_n_roses("chinese democracy")
53
+ plugin.guns_n_roses.should eql("chinese democracy")
54
+ end
55
+ end
56
+
57
+ context "when checking attribute existence" do
58
+ before(:each) do
59
+ plugin.metallica("death magnetic")
60
+ end
61
+
62
+ it "should return true if an attribute exists with the given name" do
63
+ plugin.attribute?("metallica").should eql(true)
64
+ end
65
+
66
+ it "should return false if an attribute does not exist with the given name" do
67
+ plugin.attribute?("alice in chains").should eql(false)
68
+ end
69
+ end
70
+
71
+ context "when setting attributes" do
72
+ it "should let you set an attribute" do
73
+ plugin.set_attribute(:tea, "is soothing")
74
+ plugin.data["tea"].should eql("is soothing")
75
+ end
76
+ end
77
+
78
+ context "when getting attributes" do
79
+ before(:each) do
80
+ plugin.set_attribute(:tea, "is soothing")
81
+ end
82
+
83
+ it "should let you get an attribute" do
84
+ plugin.get_attribute("tea").should eql("is soothing")
85
+ end
86
+ end
87
+ end
88
+
89
+ describe Ohai::DSL::Plugin::VersionVII do
90
+ before(:each) do
91
+ @name = :Test
92
+ end
93
+
94
+ describe "when the plugin is named incorrectly" do
95
+ context "because the plugin name doesn't start with a capital letter" do
96
+ it "should raise an Ohai::Exceptions::InvalidPluginName exception" do
97
+ expect{ Ohai.plugin(:badName) { } }.to raise_error(Ohai::Exceptions::InvalidPluginName, /badName is not a valid plugin name/)
98
+ end
99
+ end
100
+
101
+ context "because the plugin name contains an underscore" do
102
+ it "should raise an Ohai::Exceptions::InvalidPluginName exception" do
103
+ expect{ Ohai.plugin(:Bad_Name) { } }.to raise_error(Ohai::Exceptions::InvalidPluginName, /Bad_Name is not a valid plugin name/)
104
+ end
105
+ end
106
+
107
+ context "because the plugin name isn't a symbol" do
108
+ it "should raise an Ohai::Exceptions::InvalidPluginName exception" do
109
+ expect{ Ohai.plugin(1138) { } }.to raise_error(Ohai::Exceptions::InvalidPluginName, /1138 is not a valid plugin name/)
110
+ end
111
+ end
112
+ end
113
+
114
+ describe "#version" do
115
+ it "should save the plugin version as :version7" do
116
+ plugin = Ohai.plugin(@name) { }
117
+ plugin.version.should eql(:version7)
118
+ end
119
+ end
120
+
121
+ describe "#provides" do
122
+ it "should collect a single attribute" do
123
+ plugin = Ohai.plugin(@name) { provides("one") }
124
+ plugin.provides_attrs.should eql(["one"])
125
+ end
126
+
127
+ it "should collect a list of attributes" do
128
+ plugin = Ohai.plugin(@name) { provides("one", "two", "three") }
129
+ plugin.provides_attrs.should eql(["one", "two", "three"])
130
+ end
131
+
132
+ it "should collect from multiple provides statements" do
133
+ plugin = Ohai.plugin(@name) {
134
+ provides("one")
135
+ provides("two", "three")
136
+ provides("four")
137
+ }
138
+ plugin.provides_attrs.should eql(["one", "two", "three", "four"])
139
+ end
140
+
141
+ it "should collect attributes across multiple plugin files" do
142
+ plugin = Ohai.plugin(@name) { provides("one") }
143
+ plugin = Ohai.plugin(@name) { provides("two", "three") }
144
+ plugin.provides_attrs.should eql(["one", "two", "three"])
145
+ end
146
+
147
+ it "should collect unique attributes" do
148
+ plugin = Ohai.plugin(@name) { provides("one") }
149
+ plugin = Ohai.plugin(@name) { provides("one", "two") }
150
+ plugin.provides_attrs.should eql(["one", "two"])
151
+ end
152
+ end
153
+
154
+ describe "#depends" do
155
+ it "should collect a single dependency" do
156
+ plugin = Ohai.plugin(@name) { depends("one") }
157
+ plugin.depends_attrs.should eql(["one"])
158
+ end
159
+
160
+ it "should collect a list of dependencies" do
161
+ plugin = Ohai.plugin(@name) { depends("one", "two", "three") }
162
+ plugin.depends_attrs.should eql(["one", "two", "three"])
163
+ end
164
+
165
+ it "should collect from multiple depends statements" do
166
+ plugin = Ohai.plugin(@name) {
167
+ depends("one")
168
+ depends("two", "three")
169
+ depends("four")
170
+ }
171
+ plugin.depends_attrs.should eql(["one", "two", "three", "four"])
172
+ end
173
+
174
+ it "should collect dependencies across multiple plugin files" do
175
+ plugin = Ohai.plugin(@name) { depends("one") }
176
+ plugin = Ohai.plugin(@name) { depends("two", "three") }
177
+ plugin.depends_attrs.should eql(["one", "two", "three"])
178
+ end
179
+
180
+ it "should collect unique attributes" do
181
+ plugin = Ohai.plugin(@name) { depends("one") }
182
+ plugin = Ohai.plugin(@name) { depends("one", "two") }
183
+ plugin.depends_attrs.should eql(["one", "two"])
184
+ end
185
+ end
186
+
187
+ describe "#collect_data" do
188
+ it "should save as :default if no platform is given" do
189
+ plugin = Ohai.plugin(@name) { collect_data { } }
190
+ plugin.data_collector.should have_key(:default)
191
+ end
192
+
193
+ it "should save a single given platform" do
194
+ plugin = Ohai.plugin(@name) { collect_data(:ubuntu) { } }
195
+ plugin.data_collector.should have_key(:ubuntu)
196
+ end
197
+
198
+ it "should save a list of platforms" do
199
+ plugin = Ohai.plugin(@name) { collect_data(:freebsd, :netbsd, :openbsd) { } }
200
+ [:freebsd, :netbsd, :openbsd].each do |platform|
201
+ plugin.data_collector.should have_key(platform)
202
+ end
203
+ end
204
+
205
+ it "should save multiple collect_data blocks" do
206
+ plugin = Ohai.plugin(@name) {
207
+ collect_data { }
208
+ collect_data(:windows) { }
209
+ collect_data(:darwin) { }
210
+ }
211
+ [:darwin, :default, :windows].each do |platform|
212
+ plugin.data_collector.should have_key(platform)
213
+ end
214
+ end
215
+
216
+ it "should save platforms across multiple plugins" do
217
+ plugin = Ohai.plugin(@name) { collect_data { } }
218
+ plugin = Ohai.plugin(@name) { collect_data(:aix, :sigar) { } }
219
+ [:aix, :default, :sigar].each do |platform|
220
+ plugin.data_collector.should have_key(platform)
221
+ end
222
+ end
223
+
224
+ it "should fail a platform has already been defined in the same plugin" do
225
+ expect {
226
+ Ohai.plugin(@name) {
227
+ collect_data { }
228
+ collect_data { }
229
+ }
230
+ }.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/)
231
+ end
232
+
233
+ it "should fail if a platform has already been defined in another plugin file" do
234
+ Ohai.plugin(@name) { collect_data { } }
235
+ expect {
236
+ Ohai.plugin(@name) {
237
+ collect_data { }
238
+ }
239
+ }.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/)
240
+ end
241
+ end
242
+
243
+ describe "#provides (deprecated)" do
244
+ it "should log a warning" do
245
+ plugin = Ohai::DSL::Plugin::VersionVII.new(Mash.new)
246
+ Ohai::Log.should_receive(:warn).with(/\[UNSUPPORTED OPERATION\]/)
247
+ plugin.provides("attribute")
248
+ end
249
+ end
250
+
251
+ describe "#require_plugin (deprecated)" do
252
+ it "should log a warning" do
253
+ plugin = Ohai::DSL::Plugin::VersionVII.new(Mash.new)
254
+ Ohai::Log.should_receive(:warn).with(/\[UNSUPPORTED OPERATION\]/)
255
+ plugin.require_plugin("plugin")
256
+ end
257
+ end
258
+
259
+ it_behaves_like "Ohai::DSL::Plugin" do
260
+ let(:ohai) { Ohai::System.new }
261
+ let(:plugin) { Ohai::DSL::Plugin::VersionVII.new(ohai.data) }
262
+ let(:version) { :version7 }
263
+ end
264
+ end
265
+
266
+ describe Ohai::DSL::Plugin::VersionVI do
267
+ describe "#version" do
268
+ it "should save the plugin version as :version6" do
269
+ plugin = Class.new(Ohai::DSL::Plugin::VersionVI) { }
270
+ plugin.version.should eql(:version6)
271
+ end
272
+ end
273
+
274
+ describe "#provides" do
275
+ before(:each) do
276
+ @ohai = Ohai::System.new
277
+ end
278
+
279
+ it "should log a debug message when provides is used" do
280
+ Ohai::Log.should_receive(:debug).with(/Skipping provides/)
281
+ plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "/some/plugin/path.rb", "/some/plugin")
282
+ plugin.provides("attribute")
283
+ end
284
+
285
+ it "should not update the provides map for version 6 plugins." do
286
+ plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "/some/plugin/path.rb", "/some/plugin")
287
+ plugin.provides("attribute")
288
+ @ohai.provides_map.map.should be_empty
289
+ end
290
+
291
+ end
292
+
293
+ it_behaves_like "Ohai::DSL::Plugin" do
294
+ let(:ohai) { Ohai::System.new }
295
+ let(:plugin) { Ohai::DSL::Plugin::VersionVI.new(ohai, "/some/plugin/path.rb", "/some/plugin") }
296
+ let(:version) { :version6 }
297
+ end
298
+ end
@@ -0,0 +1,65 @@
1
+ #
2
+ # Author:: Serdar Sutay (<serdar@opscode.com>)
3
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # 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
+
22
+ describe "Ohai::Hints" do
23
+ # We are using the plugins directory infrastructure to test hints
24
+ extend IntegrationSupport
25
+
26
+ before do
27
+ @original_hints = Ohai::Config[:hints_path]
28
+ end
29
+
30
+ after do
31
+ Ohai::Config[:hints_path] = @original_hints
32
+ end
33
+
34
+ when_plugins_directory "doesn't contain any hints" do
35
+ before do
36
+ Ohai::Config[:hints_path] = [ path_to(".") ]
37
+ end
38
+
39
+ it "hint? should return nil" do
40
+ Ohai::Hints.hint?("cloud").should be_nil
41
+ end
42
+ end
43
+
44
+ when_plugins_directory "contains empty and full hints" do
45
+ with_plugin("cloud.json", <<EOF)
46
+ {"name":"circus"}
47
+ EOF
48
+
49
+ with_plugin("cloud_empty.json", <<EOF)
50
+ EOF
51
+
52
+ before do
53
+ Ohai::Config[:hints_path] = [ path_to(".") ]
54
+ end
55
+
56
+ it "hint? should return the data for full hints" do
57
+ Ohai::Hints.hint?("cloud").should == {"name" => "circus"}
58
+ end
59
+
60
+ it "hint? should return empty hash for empty hints" do
61
+ Ohai::Hints.hint?("cloud_empty").should == { }
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,226 @@
1
+ #
2
+ # Author:: Claire McQuin (<claire@opscode.com>)
3
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ # 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
+
22
+ describe Ohai::Loader do
23
+ extend IntegrationSupport
24
+
25
+ before(:each) do
26
+ @plugin_data = Mash.new
27
+ @provides_map = Ohai::ProvidesMap.new
28
+
29
+ @ohai = double('Ohai::System', :data => @plugin_data, :provides_map => @provides_map)
30
+ @loader = Ohai::Loader.new(@ohai)
31
+ end
32
+
33
+ describe "#initialize" do
34
+ it "should return an Ohai::Loader object" do
35
+ loader = Ohai::Loader.new(@ohai)
36
+ loader.should be_a_kind_of(Ohai::Loader)
37
+ end
38
+ end
39
+
40
+ when_plugins_directory "contains both V6 & V7 plugins" do
41
+ with_plugin("zoo.rb", <<EOF)
42
+ Ohai.plugin(:Zoo) do
43
+ provides 'seals'
44
+ end
45
+ EOF
46
+
47
+ with_plugin("zoo_too.rb", <<EOF)
48
+ Ohai.plugin(:Zoo) do
49
+ provides 'elephants'
50
+ end
51
+ EOF
52
+
53
+ with_plugin("lake.rb", <<EOF)
54
+ provides 'fish'
55
+ EOF
56
+
57
+ describe "load_plugin() method" do
58
+ describe "when loading a v7 plugin" do
59
+ before(:each) do
60
+ @plugin = @loader.load_plugin(path_to("zoo.rb"))
61
+ end
62
+
63
+ it "should save the plugin according to its attribute" do
64
+ @provides_map.map.keys.should include("seals")
65
+ end
66
+
67
+ it "should save a single plugin source" do
68
+ @plugin.source.should eql([path_to("zoo.rb")])
69
+ end
70
+
71
+ it "should save all plugin sources" do
72
+ @loader.load_plugin(path_to("zoo_too.rb"))
73
+ @plugin.source.should eql([path_to("zoo.rb"), path_to("zoo_too.rb")])
74
+ end
75
+ end
76
+
77
+ describe "when loading a v6 plugin" do
78
+ before(:each) do
79
+ Ohai::Log.should_receive(:warn).with(/\[DEPRECATION\]/)
80
+ @plugin = @loader.load_plugin(path_to("lake.rb"), path_to("."))
81
+ end
82
+
83
+ it "should not add this plugin's provided attributes to the provides map" do
84
+ @provides_map.map.should be_empty
85
+ end
86
+
87
+ it "should save the plugin's source" do
88
+ @plugin.source.should eql(path_to("lake.rb"))
89
+ end
90
+ end
91
+
92
+ it "should log a warning if a plugin doesn't exist" do
93
+ Ohai::Log.should_receive(:warn).with(/Unable to open or read plugin/)
94
+ @loader.load_plugin(path_to("rainier.rb"), path_to("."))
95
+ @provides_map.map.should be_empty
96
+ end
97
+ end
98
+ end
99
+
100
+ when_plugins_directory "contains invalid plugins" do
101
+ with_plugin("extra_s.rb", <<EOF)
102
+ Ohai.plugins(:ExtraS) do
103
+ provides "the_letter_s"
104
+ end
105
+ EOF
106
+
107
+ with_plugin("no_method.rb", <<EOF)
108
+ Ohai.plugin(:NoMethod) do
109
+ really_wants "this_attribute"
110
+ end
111
+ EOF
112
+
113
+ with_plugin("illegal_def.rb", <<EOF)
114
+ Ohai.plugin(:Zoo) do
115
+ collect_data(:darwin) do
116
+ end
117
+ collect_data(:darwin) do
118
+ end
119
+ end
120
+ EOF
121
+
122
+ with_plugin("unexpected_error.rb", <<EOF)
123
+ Ohai.plugin(:Zoo) do
124
+ raise "You aren't expecting this."
125
+ end
126
+ EOF
127
+
128
+ with_plugin("bad_symbol.rb", <<EOF)
129
+ Ohai.plugin(:1nval!d) do
130
+ provides "not_a_symbol"
131
+ end
132
+ EOF
133
+
134
+ with_plugin("no_end.rb", <<EOF)
135
+ Ohai.plugin(:NoEnd) do
136
+ provides "fish_oil"
137
+ collect_data do
138
+ end
139
+ EOF
140
+
141
+ with_plugin("bad_name.rb", <<EOF)
142
+ Ohai.plugin(:you_give_plugins_a_bad_name) do
143
+ provides "that/one/song"
144
+ end
145
+ EOF
146
+
147
+ describe "load_plugin() method" do
148
+ describe "when the plugin uses Ohai.plugin instead of Ohai.plugins" do
149
+ it "should log an unsupported operation warning" do
150
+ Ohai::Log.should_receive(:warn).with(/Plugin Method Error: <#{path_to("extra_s.rb")}>:/)
151
+ @loader.load_plugin(path_to("extra_s.rb"))
152
+ end
153
+
154
+ it "should not raise an error" do
155
+ expect{ @loader.load_plugin(path_to("extra_s.rb")) }.not_to raise_error
156
+ end
157
+ end
158
+
159
+ describe "when the plugin tries to call an unexisting method" do
160
+ it "shoud log an unsupported operation warning" do
161
+ Ohai::Log.should_receive(:warn).with(/Plugin Method Error: <#{path_to("no_method.rb")}>:/)
162
+ @loader.load_plugin(path_to("no_method.rb"))
163
+ end
164
+
165
+ it "should not raise an error" do
166
+ expect{ @loader.load_plugin(path_to("no_method.rb")) }.not_to raise_error
167
+ end
168
+ end
169
+
170
+ describe "when the plugin defines collect_data on the same platform more than once" do
171
+ it "shoud log an illegal plugin definition warning" do
172
+ Ohai::Log.should_receive(:warn).with(/Plugin Definition Error: <#{path_to("illegal_def.rb")}>:/)
173
+ @loader.load_plugin(path_to("illegal_def.rb"))
174
+ end
175
+
176
+ it "should not raise an error" do
177
+ expect{ @loader.load_plugin(path_to("illegal_def.rb")) }.not_to raise_error
178
+ end
179
+ end
180
+
181
+ describe "when an unexpected error is encountered" do
182
+ it "should log a warning" do
183
+ Ohai::Log.should_receive(:warn).with(/Plugin Error: <#{path_to("unexpected_error.rb")}>:/)
184
+ @loader.load_plugin(path_to("unexpected_error.rb"))
185
+ end
186
+
187
+ it "should not raise an error" do
188
+ expect{ @loader.load_plugin(path_to("unexpected_error.rb")) }.not_to raise_error
189
+ end
190
+ end
191
+
192
+ describe "when the plugin name symbol has bad syntax" do
193
+ it "should log a syntax error warning" do
194
+ Ohai::Log.should_receive(:warn).with(/Plugin Syntax Error: <#{path_to("bad_symbol.rb")}>:/)
195
+ @loader.load_plugin(path_to("bad_symbol.rb"))
196
+ end
197
+
198
+ it "should not raise an error" do
199
+ expect{ @loader.load_plugin(path_to("bad_symbol.rb")) }.not_to raise_error
200
+ end
201
+ end
202
+
203
+ describe "when the plugin forgets an 'end'" do
204
+ it "should log a syntax error warning" do
205
+ Ohai::Log.should_receive(:warn).with(/Plugin Syntax Error: <#{path_to("no_end.rb")}>:/)
206
+ @loader.load_plugin(path_to("no_end.rb"))
207
+ end
208
+
209
+ it "should not raise an error" do
210
+ expect{ @loader.load_plugin(path_to("no_end.rb")) }.not_to raise_error
211
+ end
212
+ end
213
+
214
+ describe "when the plugin has an invalid name" do
215
+ it "should log an invalid plugin name warning" do
216
+ Ohai::Log.should_receive(:warn).with(/Plugin Name Error: <#{path_to("bad_name.rb")}>:/)
217
+ @loader.load_plugin(path_to("bad_name.rb"))
218
+ end
219
+
220
+ it "should not raise an error" do
221
+ expect{ @loader.load_plugin(path_to("bad_name.rb")) }.not_to raise_error
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end