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
@@ -22,52 +22,51 @@ require 'open-uri'
22
22
 
23
23
  describe Ohai::System, "plugin eucalyptus" do
24
24
  before(:each) do
25
- @ohai = Ohai::System.new
26
- @ohai.stub!(:require_plugin).and_return(true)
25
+ @plugin = get_plugin("eucalyptus")
27
26
  end
28
27
 
29
28
  shared_examples_for "!eucalyptus" do
30
29
  it "should NOT attempt to fetch the eucalyptus metadata" do
31
30
  OpenURI.should_not_receive(:open)
32
- @ohai._require_plugin("eucalyptus")
31
+ @plugin.run
33
32
  end
34
33
  end
35
34
 
36
35
  shared_examples_for "eucalyptus" do
37
36
  before(:each) do
38
- @http_client = mock("Net::HTTP client")
39
- @ohai.stub!(:http_client).and_return(@http_client)
37
+ @http_client = double("Net::HTTP client")
38
+ @plugin.stub(:http_client).and_return(@http_client)
40
39
 
41
40
  @http_client.should_receive(:get).
42
41
  with("/").twice.
43
- and_return(mock("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
42
+ and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
44
43
  @http_client.should_receive(:get).
45
44
  with("/2012-01-12/meta-data/").
46
- and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200"))
45
+ and_return(double("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200"))
47
46
  @http_client.should_receive(:get).
48
47
  with("/2012-01-12/meta-data/instance_type").
49
- and_return(mock("Net::HTTP Response", :body => "c1.medium", :code => "200"))
48
+ and_return(double("Net::HTTP Response", :body => "c1.medium", :code => "200"))
50
49
  @http_client.should_receive(:get).
51
50
  with("/2012-01-12/meta-data/ami_id").
52
- and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200"))
51
+ and_return(double("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200"))
53
52
  @http_client.should_receive(:get).
54
53
  with("/2012-01-12/meta-data/security-groups").
55
- and_return(mock("Net::HTTP Response", :body => "group1\ngroup2", :code => "200"))
54
+ and_return(double("Net::HTTP Response", :body => "group1\ngroup2", :code => "200"))
56
55
  @http_client.should_receive(:get).
57
56
  with("/2012-01-12/user-data/").
58
- and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
57
+ and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
59
58
  end
60
59
 
61
60
  it "should recursively fetch all the eucalyptus metadata" do
62
- IO.stub!(:select).and_return([[],[1],[]])
63
- t = mock("connection")
64
- t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS)
65
- Socket.stub!(:new).and_return(t)
66
- @ohai._require_plugin("eucalyptus")
67
- @ohai[:eucalyptus].should_not be_nil
68
- @ohai[:eucalyptus]['instance_type'].should == "c1.medium"
69
- @ohai[:eucalyptus]['ami_id'].should == "ami-5d2dc934"
70
- @ohai[:eucalyptus]['security_groups'].should eql ['group1', 'group2']
61
+ IO.stub(:select).and_return([[],[1],[]])
62
+ t = double("connection")
63
+ t.stub(:connect_nonblock).and_raise(Errno::EINPROGRESS)
64
+ Socket.stub(:new).and_return(t)
65
+ @plugin.run
66
+ @plugin[:eucalyptus].should_not be_nil
67
+ @plugin[:eucalyptus]['instance_type'].should == "c1.medium"
68
+ @plugin[:eucalyptus]['ami_id'].should == "ami-5d2dc934"
69
+ @plugin[:eucalyptus]['security_groups'].should eql ['group1', 'group2']
71
70
  end
72
71
  end
73
72
 
@@ -75,8 +74,8 @@ describe Ohai::System, "plugin eucalyptus" do
75
74
  it_should_behave_like "eucalyptus"
76
75
 
77
76
  before(:each) do
78
- IO.stub!(:select).and_return([[],[1],[]])
79
- @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
77
+ IO.stub(:select).and_return([[],[1],[]])
78
+ @plugin[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
80
79
  end
81
80
  end
82
81
 
@@ -84,7 +83,7 @@ describe Ohai::System, "plugin eucalyptus" do
84
83
  it_should_behave_like "!eucalyptus"
85
84
 
86
85
  before(:each) do
87
- @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
86
+ @plugin[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
88
87
  end
89
88
  end
90
89
 
@@ -92,10 +91,10 @@ describe Ohai::System, "plugin eucalyptus" do
92
91
  it_should_behave_like "eucalyptus"
93
92
 
94
93
  before(:each) do
95
- File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(true)
96
- File.stub!(:read).with('/etc/chef/ohai/hints/eucalyptus.json').and_return('')
97
- File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(true)
98
- File.stub!(:read).with('C:\chef\ohai\hints/eucalyptus.json').and_return('')
94
+ File.stub(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(true)
95
+ File.stub(:read).with('/etc/chef/ohai/hints/eucalyptus.json').and_return('')
96
+ File.stub(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(true)
97
+ File.stub(:read).with('C:\chef\ohai\hints/eucalyptus.json').and_return('')
99
98
  end
100
99
  end
101
100
 
@@ -103,8 +102,9 @@ describe Ohai::System, "plugin eucalyptus" do
103
102
  it_should_behave_like "!eucalyptus"
104
103
 
105
104
  before(:each) do
106
- File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false)
107
- File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false)
105
+ @plugin[:network] = {:interfaces => {}}
106
+ File.stub(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false)
107
+ File.stub(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false)
108
108
  end
109
109
  end
110
110
 
@@ -112,10 +112,14 @@ describe Ohai::System, "plugin eucalyptus" do
112
112
  it_should_behave_like "!eucalyptus"
113
113
 
114
114
  before(:each) do
115
- File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
116
- File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
117
- File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
118
- File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
115
+ @plugin[:network] = {:interfaces => {}}
116
+
117
+ File.stub(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false)
118
+ File.stub(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false)
119
+ File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
120
+ File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
121
+ File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
122
+ File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
119
123
  end
120
124
  end
121
125
 
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Toomas Pelberg (toomas.pelberg@playtech.com>)
3
- # Copyright:: Copyright (c) 2011 Opscode, Inc.
3
+ # Author:: Claire McQuin (claire@opscode.com)
4
+ # Copyright:: Copyright (c) 2011, 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,43 +21,295 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_he
20
21
 
21
22
  tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'
22
23
 
23
- describe Ohai::System, "plugin fail" do
24
-
24
+ shared_examples "a v7 loading failure" do
25
25
  before(:all) do
26
26
  begin
27
27
  Dir.mkdir("#{tmp}/plugins")
28
28
  rescue Errno::EEXIST
29
- # Ignore it
29
+ # ignore
30
30
  end
31
- fail_plugin=File.open("#{tmp}/plugins/fail.rb","w+")
32
- fail_plugin.write("provides \"fail\"require 'thiswillblowupinyourface'\nk=MissingClassName.new\nfail \"ohnoes\"")
33
- fail_plugin.close
34
- real_plugin=File.open("#{tmp}/plugins/real.rb","w+")
35
- real_plugin.write("provides \"real\"\nreal \"useful\"\n")
36
- real_plugin.close
37
- @plugin_path=Ohai::Config[:plugin_path]
38
31
  end
39
-
32
+
40
33
  before(:each) do
41
- Ohai::Config[:plugin_path]=["#{tmp}/plugins"]
42
- @ohai=Ohai::System.new
34
+ fail_file = File.open("#{tmp}/plugins/fail.rb", "w+")
35
+ fail_file.write(failstr)
36
+ fail_file.close
43
37
  end
44
-
38
+
39
+ after(:each) do
40
+ File.delete("#{tmp}/plugins/fail.rb")
41
+ end
42
+
45
43
  after(:all) do
44
+ begin
45
+ Dir.delete("#{tmp}/plugins")
46
+ rescue
47
+ # ignore
48
+ end
49
+ end
50
+
51
+ before(:each) do
52
+ @ohai = Ohai::System.new
53
+ @loader = Ohai::Loader.new(@ohai)
54
+ end
55
+
56
+ it "should not have attribute keys" do
57
+ @loader.load_plugin("#{tmp}/plugins/fail.rb")
58
+ #@ohai.attributes.should_not have_key("fail")
59
+ lambda { @ohai.provides_map.find_providers_for(["fail"]) }.should raise_error(Ohai::Exceptions::AttributeNotFound)
60
+ end
61
+
62
+ it "should not have source key" do
63
+ @loader.load_plugin("#{tmp}/plugins/fail.rb")
64
+ @ohai.v6_dependency_solver.should_not have_key("#{tmp}/plugins/fail.rb")
65
+ end
66
+
67
+ it "should write to Ohai::Log" do
68
+ Ohai::Log.should_receive(:warn).once
69
+ @loader.load_plugin("#{tmp}/plugins/fail.rb")
70
+ end
71
+ end
72
+
73
+ shared_examples "a v7 loading success" do
74
+ before(:all) do
75
+ begin
76
+ Dir.mkdir("#{tmp}/plugins")
77
+ rescue Errno::EEXIST
78
+ # ignore
79
+ end
80
+ end
81
+
82
+ before(:each) do
83
+ fail_file = File.open("#{tmp}/plugins/fail.rb", "w+")
84
+ fail_file.write(failstr)
85
+ fail_file.close
86
+ end
87
+
88
+ after(:each) do
46
89
  File.delete("#{tmp}/plugins/fail.rb")
47
- File.delete("#{tmp}/plugins/real.rb")
90
+ end
91
+
92
+ after(:all) do
48
93
  begin
49
94
  Dir.delete("#{tmp}/plugins")
50
95
  rescue
51
- # Don't care if it fails
96
+ # ignore
52
97
  end
53
- Ohai::Config[:plugin_path]=@plugin_path
54
98
  end
55
-
56
- it "should continue gracefully if plugin loading fails" do
57
- @ohai.require_plugin("fail")
58
- @ohai.require_plugin("real")
59
- @ohai.data[:real].should eql("useful")
99
+
100
+ before(:each) do
101
+ @ohai = Ohai::System.new
102
+ @loader = Ohai::Loader.new(@ohai)
103
+ end
104
+
105
+ it "should have attribute keys" do
106
+ @loader.load_plugin("#{tmp}/plugins/fail.rb")
107
+ @ohai.provides_map.should have_key("fail")
108
+ end
109
+
110
+ it "should have source key" do
111
+ @loader.load_plugin("#{tmp}/plugins/fail.rb")
112
+ @ohai.v6_dependency_solver.should have_key("#{tmp}/plugins/fail.rb")
113
+ end
114
+
115
+ it "should not write to Ohai::Log" do
116
+ Ohai::Log.should_not_receive(:warn)
117
+ @loader.load_plugin("#{tmp}/plugins/fail.rb")
118
+ end
119
+ end
120
+
121
+ shared_examples "a v7 run failure" do
122
+ before(:all) do
123
+ begin
124
+ Dir.mkdir("#{tmp}/plugins")
125
+ rescue Errno::EEXIST
126
+ # ignore
127
+ end
128
+ end
129
+
130
+ before(:each) do
131
+ fail_file = File.open("#{tmp}/plugins/fail.rb", "w+")
132
+ fail_file.write(failstr)
133
+ fail_file.close
134
+ end
135
+
136
+ after(:each) do
137
+ File.delete("#{tmp}/plugins/fail.rb")
138
+ end
139
+
140
+ after(:all) do
141
+ begin
142
+ Dir.delete("#{tmp}/plugins")
143
+ rescue
144
+ # ignore
145
+ end
146
+ end
147
+
148
+ before(:each) do
149
+ @ohai = Ohai::System.new
150
+ @loader = Ohai::Loader.new(@ohai)
151
+ end
152
+
153
+ it "should not have new attribute keys" do
154
+ @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run
155
+ @ohai.provides_map.should_not have_key("other")
156
+ end
157
+
158
+ it "should write to Ohai::Log" do
159
+ Ohai::Log.should_receive(:warn).once
160
+ @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run
161
+ end
162
+ end
163
+
164
+ =begin
165
+ shared_examples "a v6 run failure" do
166
+ before(:all) do
167
+ begin
168
+ Dir.mkdir("#{tmp}/plugins")
169
+ rescue Errno::EEXIST
170
+ # ignore
171
+ end
172
+ end
173
+
174
+ before(:each) do
175
+ fail_file = File.open("#{tmp}/plugins/fail.rb", "w+")
176
+ fail_file.write(failstr)
177
+ fail_file.close
178
+ end
179
+
180
+ after(:each) do
181
+ File.delete("#{tmp}/plugins/fail.rb")
182
+ end
183
+
184
+ after(:all) do
185
+ begin
186
+ Dir.delete("#{tmp}/plugins")
187
+ rescue
188
+ # ignore
189
+ end
190
+ end
191
+
192
+ before(:each) do
193
+ @ohai = Ohai::System.new
194
+ @loader = Ohai::Loader.new(@ohai)
195
+ end
196
+
197
+ it "should not add data keys" do
198
+ @loader.load_plugin("#{tmp}/plugins/fail.rb")
60
199
  @ohai.data.should_not have_key("fail")
61
200
  end
201
+
202
+ it "should write to Ohai::Log" do
203
+ Ohai::Log.should_receive(:warn).once
204
+ @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run
205
+ end
206
+ end
207
+ =end
208
+
209
+ describe "when using DSL commands outside Ohai.plugin block" do
210
+ failstr1 = <<EOF
211
+ provides "fail"
212
+ Ohai.plugin do
213
+ end
214
+ EOF
215
+
216
+ failstr2 = <<EOF
217
+ depends "fail"
218
+ Ohai.plugin do
219
+ end
220
+ EOF
221
+
222
+ failstr3 = <<EOF
223
+ collect_data do
224
+ end
225
+ Ohai.plugin do
226
+ end
227
+ EOF
228
+
229
+ it_behaves_like "a v7 loading failure" do
230
+ let(:failstr) { failstr1 }
231
+ end
232
+
233
+ it_behaves_like "a v7 loading failure" do
234
+ let(:failstr) { failstr2 }
235
+ end
236
+
237
+ it_behaves_like "a v7 loading failure" do
238
+ let(:failstr) { failstr3 }
239
+ end
240
+ end
241
+
242
+ describe "when using nonexistent DSL commands in Ohai.plugin block" do
243
+ failstr = "Ohai.plugin do\n\tcreates \"fail\"\nend\n"
244
+
245
+ it_behaves_like "a v7 loading failure" do
246
+ let(:failstr) { failstr }
247
+ end
248
+ end
249
+
250
+ =begin
251
+ describe "when using DSL commands in collect_data block" do
252
+ failstr1 = <<EOF
253
+ Ohai.plugin do
254
+ provides "fail"
255
+ collect_data do
256
+ provides "other"
257
+ end
258
+ end
259
+ EOF
260
+
261
+ failstr2 =<<EOF
262
+ Ohai.plugin do
263
+ provides "fail"
264
+ collect_data do
265
+ provides "other"
266
+ end
267
+ end
268
+ EOF
269
+
270
+ it_behaves_like "a v7 loading success" do
271
+ let(:failstr) { failstr1 }
272
+ end
273
+
274
+ it_behaves_like "a v7 run failure" do
275
+ let(:failstr) { failstr1 }
276
+ end
277
+
278
+ it_behaves_like "a v7 loading success" do
279
+ let(:failstr) { failstr2 }
280
+ end
281
+
282
+ it_behaves_like "a v7 run failure" do
283
+ let(:failstr) { failstr2 }
284
+ end
285
+ end
286
+
287
+ describe "when setting undeclared attribute in collect_data block" do
288
+ failstr = <<EOF
289
+ Ohai.plugin do
290
+ provides "fail"
291
+ collect_data do
292
+ creates "other"
293
+ end
294
+ end
295
+ EOF
296
+ it_behaves_like "a v7 loading success" do
297
+ let(:failstr) { failstr }
298
+ end
299
+
300
+ it_behaves_like "a v7 run failure" do
301
+ let(:failstr) { failstr }
302
+ end
303
+ end
304
+
305
+ describe "when setting undeclared attribute" do
306
+ failstr = <<EOF
307
+ provides "fail"
308
+ other "attribute"
309
+ EOF
310
+
311
+ it_behaves_like "a v6 run failure" do
312
+ let(:failstr) { failstr }
313
+ end
62
314
  end
315
+ =end