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
@@ -2,8 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
2
2
 
3
3
  describe Ohai::System, "plugin etc" do
4
4
  before(:each) do
5
- @ohai = Ohai::System.new
6
- @ohai.stub!(:require_plugin).and_return(true)
5
+ @plugin = get_plugin("passwd")
7
6
  end
8
7
 
9
8
  PasswdEntry = Struct.new(:name, :uid, :gid, :dir, :shell, :gecos)
@@ -12,31 +11,31 @@ describe Ohai::System, "plugin etc" do
12
11
  it "should include a list of all users" do
13
12
  Etc.should_receive(:passwd).and_yield(PasswdEntry.new("root", 1, 1, '/root', '/bin/zsh', 'BOFH')).
14
13
  and_yield(PasswdEntry.new('www', 800, 800, '/var/www', '/bin/false', 'Serving the web since 1970'))
15
- @ohai._require_plugin("passwd")
16
- @ohai[:etc][:passwd]['root'].should == Mash.new(:shell => '/bin/zsh', :gecos => 'BOFH', :gid => 1, :uid => 1, :dir => '/root')
17
- @ohai[:etc][:passwd]['www'].should == Mash.new(:shell => '/bin/false', :gecos => 'Serving the web since 1970', :gid => 800, :uid => 800, :dir => '/var/www')
14
+ @plugin.run
15
+ @plugin[:etc][:passwd]['root'].should == Mash.new(:shell => '/bin/zsh', :gecos => 'BOFH', :gid => 1, :uid => 1, :dir => '/root')
16
+ @plugin[:etc][:passwd]['www'].should == Mash.new(:shell => '/bin/false', :gecos => 'Serving the web since 1970', :gid => 800, :uid => 800, :dir => '/var/www')
18
17
  end
19
18
 
20
19
  it "should set the current user" do
21
20
  Etc.should_receive(:getlogin).and_return('chef')
22
- @ohai._require_plugin("passwd")
23
- @ohai[:current_user].should == 'chef'
21
+ @plugin.run
22
+ @plugin[:current_user].should == 'chef'
24
23
  end
25
24
 
26
25
  it "should set the available groups" do
27
26
  Etc.should_receive(:group).and_yield(GroupEntry.new("admin", 100, ['root', 'chef'])).and_yield(GroupEntry.new('www', 800, ['www', 'deploy']))
28
- @ohai._require_plugin("passwd")
29
- @ohai[:etc][:group]['admin'].should == Mash.new(:gid => 100, :members => ['root', 'chef'])
30
- @ohai[:etc][:group]['www'].should == Mash.new(:gid => 800, :members => ['www', 'deploy'])
27
+ @plugin.run
28
+ @plugin[:etc][:group]['admin'].should == Mash.new(:gid => 100, :members => ['root', 'chef'])
29
+ @plugin[:etc][:group]['www'].should == Mash.new(:gid => 800, :members => ['www', 'deploy'])
31
30
  end
32
31
 
33
32
  if "".respond_to?(:force_encoding)
34
33
  it "sets the encoding of strings to the default external encoding" do
35
34
  fields = ["root", 1, 1, '/root', '/bin/zsh', 'BOFH']
36
35
  fields.each {|f| f.force_encoding(Encoding::ASCII_8BIT) if f.respond_to?(:force_encoding) }
37
- Etc.stub!(:passwd).and_yield(PasswdEntry.new(*fields))
38
- @ohai._require_plugin("passwd")
39
- root = @ohai[:etc][:passwd]['root']
36
+ Etc.stub(:passwd).and_yield(PasswdEntry.new(*fields))
37
+ @plugin.run
38
+ root = @plugin[:etc][:passwd]['root']
40
39
  root['gecos'].encoding.should == Encoding.default_external
41
40
  end
42
41
  end
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Joshua Timberman(<joshua@opscode.com>)
3
- # Copyright:: Copyright (c) 2009 Opscode, Inc.
3
+ # Author:: Theodore Nordsieck (<theo@opscode.com>)
4
+ # Copyright:: Copyright (c) 2009-2013 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,63 +21,38 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
20
21
 
21
22
  describe Ohai::System, "plugin perl" do
22
23
  before(:each) do
23
- @ohai = Ohai::System.new
24
- @ohai[:languages] = Mash.new
25
- @ohai.stub!(:require_plugin).and_return(true)
26
- @pid = 2342
27
- @stderr = StringIO.new
28
- @stdout = StringIO.new(<<-OUT)
29
- version='5.8.8';
30
- archname='darwin-thread-multi-2level';
31
- OUT
32
- @stdin = StringIO.new
33
- @status = 0
34
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
35
- @status,
36
- @stdout,
37
- @stderr
38
- ])
24
+ @plugin = get_plugin("perl")
25
+ @plugin[:languages] = Mash.new
26
+ @stdout = "version='5.8.8';#{$/}archname='darwin-thread-multi-2level';"
27
+ @plugin.stub(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, ""))
39
28
  end
40
29
 
41
30
  it "should run perl -V:version -V:archname" do
42
- @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return(true)
43
- @ohai._require_plugin("perl")
44
- end
45
-
46
- it "should iterate over each line of perl command's stdout" do
47
- @stdout.should_receive(:each_line).and_return(true)
48
- @ohai._require_plugin("perl")
31
+ @plugin.should_receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, ""))
32
+ @plugin.run
49
33
  end
50
34
 
51
35
  it "should set languages[:perl][:version]" do
52
- @ohai._require_plugin("perl")
53
- @ohai.languages[:perl][:version].should eql("5.8.8")
36
+ @plugin.run
37
+ @plugin.languages[:perl][:version].should eql("5.8.8")
54
38
  end
55
39
 
56
40
  it "should set languages[:perl][:archname]" do
57
- @ohai._require_plugin("perl")
58
- @ohai.languages[:perl][:archname].should eql("darwin-thread-multi-2level")
41
+ @plugin.run
42
+ @plugin.languages[:perl][:archname].should eql("darwin-thread-multi-2level")
59
43
  end
60
44
 
61
45
  it "should set languages[:perl] if perl command succeeds" do
62
- @status = 0
63
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
64
- @status,
65
- @stdout,
66
- @stderr
67
- ])
68
- @ohai._require_plugin("perl")
69
- @ohai.languages.should have_key(:perl)
46
+ @plugin.stub(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, ""))
47
+ @plugin.run
48
+ @plugin.languages.should have_key(:perl)
70
49
  end
71
50
 
72
51
  it "should not set languages[:perl] if perl command fails" do
73
- @status = 1
74
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
75
- @status,
76
- @stdout,
77
- @stderr
78
- ])
79
- @ohai._require_plugin("perl")
80
- @ohai.languages.should_not have_key(:perl)
52
+ @status = 1
53
+ @plugin.stub(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(1, @stdout, ""))
54
+ @plugin.run
55
+ @plugin.languages.should_not have_key(:perl)
81
56
  end
57
+
82
58
  end
@@ -1,6 +1,8 @@
1
1
  #
2
2
  # Author:: Doug MacEachern <dougm@vmware.com>
3
+ # Author:: Theodore Nordsieck (<theo@opscode.com>)
3
4
  # Copyright:: Copyright (c) 2009 VMware, Inc.
5
+ # Copyright:: Copyright (c) 2013 Opscode, Inc.
4
6
  # License:: Apache License, Version 2.0
5
7
  #
6
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,37 +18,40 @@
16
18
  # limitations under the License.
17
19
  #
18
20
 
21
+ require 'json'
19
22
  require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb'))
20
23
 
21
24
  describe Ohai::System, "plugin php" do
22
25
 
23
26
  before(:each) do
24
- @ohai = Ohai::System.new
25
- @ohai[:languages] = Mash.new
26
- @ohai.stub!(:require_plugin).and_return(true)
27
- @status = 0
27
+ @plugin = get_plugin("php")
28
+ @plugin[:languages] = Mash.new
28
29
  @stdout = "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n"
29
- @stderr = ""
30
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr])
30
+ @plugin.stub(:shell_out).with("php -v").and_return(mock_shell_out(0, @stdout, ""))
31
31
  end
32
32
 
33
33
  it "should get the php version from running php -V" do
34
- @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([0, "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n", ""])
35
- @ohai._require_plugin("php")
34
+ @plugin.should_receive(:shell_out).with("php -v").and_return(mock_shell_out(0, @stdout, ""))
35
+ @plugin.run
36
36
  end
37
37
 
38
38
  it "should set languages[:php][:version]" do
39
- @ohai._require_plugin("php")
40
- @ohai.languages[:php][:version].should eql("5.1.6")
39
+ @plugin.run
40
+ @plugin.languages[:php][:version].should eql("5.1.6")
41
41
  end
42
42
 
43
43
  it "should not set the languages[:php] tree up if php command fails" do
44
- @status = 1
45
44
  @stdout = "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n"
46
- @stderr = ""
47
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr])
48
- @ohai._require_plugin("php")
49
- @ohai.languages.should_not have_key(:php)
45
+ @plugin.stub(:shell_out).with("php -v").and_return(mock_shell_out(1, @stdout, ""))
46
+ @plugin.run
47
+ @plugin.languages.should_not have_key(:php)
48
+ end
49
+
50
+ it "should parse builddate even if it's suhosin patched" do
51
+ @stdout = "PHP 5.3.27 with Suhosin-Patch (cli) (built: Aug 30 2013 04:30:30) \nCopyright (c) 1997-2013 The PHP Group\nZend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies"
52
+ @plugin.stub(:shell_out).with("php -v").and_return(mock_shell_out(0, @stdout, ""))
53
+ @plugin.run
54
+ @plugin.languages[:php][:builddate].should eql("Aug 30 2013 04:30:30")
50
55
  end
51
56
 
52
57
  end
@@ -21,51 +21,46 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
21
21
 
22
22
  describe Ohai::System, "plugin platform" do
23
23
  before(:each) do
24
- @ohai = Ohai::System.new
25
- @ohai.stub!(:require_plugin).and_return(true)
26
- @ohai[:os] = 'monkey'
27
- @ohai[:os_version] = 'poop'
24
+ @plugin = get_plugin("platform")
25
+ @plugin.stub(:collect_os).and_return(:default)
26
+ @plugin[:os] = 'monkey'
27
+ @plugin[:os_version] = 'poop'
28
28
  end
29
-
30
- it "should require the os platform plugin" do
31
- @ohai.should_receive(:require_plugin).with("monkey::platform")
32
- @ohai._require_plugin("platform")
33
- end
34
-
29
+
35
30
  it "should set the platform and platform family to the os if it was not set earlier" do
36
- @ohai._require_plugin("platform")
37
- @ohai[:platform].should eql("monkey")
38
- @ohai[:platform_family].should eql("monkey")
31
+ @plugin.run
32
+ @plugin[:platform].should eql("monkey")
33
+ @plugin[:platform_family].should eql("monkey")
39
34
  end
40
35
 
41
36
  it "should not set the platform to the os if it was set earlier" do
42
- @ohai[:platform] = 'lars'
43
- @ohai._require_plugin("platform")
44
- @ohai[:platform].should eql("lars")
37
+ @plugin[:platform] = 'lars'
38
+ @plugin.run
39
+ @plugin[:platform].should eql("lars")
45
40
  end
46
41
 
47
42
  it "should set the platform_family to the platform if platform was set earlier but not platform_family" do
48
- @ohai[:platform] = 'lars'
49
- @ohai[:platform_family] = 'jack'
50
- @ohai._require_plugin("platform")
51
- @ohai[:platform_family].should eql("jack")
43
+ @plugin[:platform] = 'lars'
44
+ @plugin[:platform_family] = 'jack'
45
+ @plugin.run
46
+ @plugin[:platform_family].should eql("jack")
52
47
  end
53
48
 
54
49
  it "should not set the platform_family if the platform_family was set earlier." do
55
- @ohai[:platform] = 'lars'
56
- @ohai._require_plugin("platform")
57
- @ohai[:platform].should eql("lars")
58
- @ohai[:platform_family].should eql("lars")
50
+ @plugin[:platform] = 'lars'
51
+ @plugin.run
52
+ @plugin[:platform].should eql("lars")
53
+ @plugin[:platform_family].should eql("lars")
59
54
  end
60
55
 
61
56
  it "should set the platform_version to the os_version if it was not set earlier" do
62
- @ohai._require_plugin("platform")
63
- @ohai[:os_version].should eql("poop")
57
+ @plugin.run
58
+ @plugin[:os_version].should eql("poop")
64
59
  end
65
60
 
66
61
  it "should not set the platform to the os if it was set earlier" do
67
- @ohai[:platform_version] = 'ulrich'
68
- @ohai._require_plugin("platform")
69
- @ohai[:platform_version].should eql("ulrich")
62
+ @plugin[:platform_version] = 'ulrich'
63
+ @plugin.run
64
+ @plugin[:platform_version].should eql("ulrich")
70
65
  end
71
66
  end
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Author:: Theodore Nordsieck (<theo@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");
@@ -22,32 +23,27 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
22
23
  describe Ohai::System, "plugin python" do
23
24
 
24
25
  before(:each) do
25
- @ohai = Ohai::System.new
26
- @ohai[:languages] = Mash.new
27
- @ohai.stub!(:require_plugin).and_return(true)
28
- @status = 0
26
+ @plugin = get_plugin("python")
27
+ @plugin[:languages] = Mash.new
29
28
  @stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n"
30
- @stderr = ""
31
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr])
29
+ @plugin.stub(:shell_out).with("python -c \"import sys; print sys.version\"").and_return(mock_shell_out(0, @stdout, ""))
32
30
  end
33
31
 
34
32
  it "should get the python version from printing sys.version and sys.platform" do
35
- @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([0, "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n", ""])
36
- @ohai._require_plugin("python")
33
+ @plugin.should_receive(:shell_out).with("python -c \"import sys; print sys.version\"").and_return(mock_shell_out(0, @stdout, ""))
34
+ @plugin.run
37
35
  end
38
36
 
39
37
  it "should set languages[:python][:version]" do
40
- @ohai._require_plugin("python")
41
- @ohai.languages[:python][:version].should eql("2.5.2")
38
+ @plugin.run
39
+ @plugin.languages[:python][:version].should eql("2.5.2")
42
40
  end
43
41
 
44
42
  it "should not set the languages[:python] tree up if python command fails" do
45
- @status = 1
46
43
  @stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n"
47
- @stderr = ""
48
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr])
49
- @ohai._require_plugin("python")
50
- @ohai.languages.should_not have_key(:python)
44
+ @plugin.stub(:shell_out).with("python -c \"import sys; print sys.version\"").and_return(mock_shell_out(1, @stdout, ""))
45
+ @plugin.run
46
+ @plugin.languages.should_not have_key(:python)
51
47
  end
52
-
48
+
53
49
  end
@@ -19,9 +19,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
19
19
 
20
20
  describe Ohai::System, "plugin rackspace" do
21
21
  before(:each) do
22
- @ohai = Ohai::System.new
23
- @ohai.stub!(:require_plugin).and_return(true)
24
- @ohai[:network] = {:interfaces => {:eth0 => {"addresses"=> {
22
+ @plugin = get_plugin("rackspace")
23
+ @plugin[:hostname] = "katie"
24
+ @plugin[:network] = {:interfaces => {:eth0 => {"addresses"=> {
25
25
  "1.2.3.4"=> {
26
26
  "broadcast"=> "67.23.20.255",
27
27
  "netmask"=> "255.255.255.0",
@@ -40,64 +40,70 @@ describe Ohai::System, "plugin rackspace" do
40
40
  "40:40:95:47:6E:ED"=> {
41
41
  "family"=> "lladdr"
42
42
  }
43
- }}}}
44
-
45
- @ohai[:network][:interfaces][:eth1] = {:addresses => {
46
- "fe80::4240:f5ff:feab:2836" => {
47
- "scope"=> "Link",
48
- "prefixlen"=> "64",
49
- "family"=> "inet6"
50
- },
51
- "5.6.7.8"=> {
52
- "broadcast"=> "10.176.191.255",
53
- "netmask"=> "255.255.224.0",
54
- "family"=> "inet"
55
- },
56
- "40:40:F5:AB:28:36" => {
57
- "family"=> "lladdr"
58
- }
43
+ }}
44
+ }
45
+ }
46
+
47
+ @plugin[:network][:interfaces][:eth1] = {:addresses => {
48
+ "fe80::4240:f5ff:feab:2836" => {
49
+ "scope"=> "Link",
50
+ "prefixlen"=> "64",
51
+ "family"=> "inet6"
52
+ },
53
+ "5.6.7.8"=> {
54
+ "broadcast"=> "10.176.191.255",
55
+ "netmask"=> "255.255.224.0",
56
+ "family"=> "inet"
57
+ },
58
+ "40:40:F5:AB:28:36" => {
59
+ "family"=> "lladdr"
60
+ }
59
61
  }}
60
62
 
61
63
  # In olden days we could detect rackspace by a -rscloud suffix on the kernel
62
64
  # This is here to make #has_rackspace_kernel? fail until we remove that check
63
- @ohai[:kernel] = { :release => "1.2.13-not-rackspace" }
65
+ @plugin[:kernel] = { :release => "1.2.13-not-rackspace" }
64
66
 
65
67
  # We need a generic stub here for the later stubs with arguments to work
66
68
  # Because, magic.
67
- @ohai.stub(:run_command).and_return(false)
69
+ @plugin.stub(:shell_out).and_return(mock_shell_out(1, "", ""))
68
70
  end
69
71
 
70
72
  shared_examples_for "!rackspace" do
71
73
  it "should NOT create rackspace" do
72
- @ohai._require_plugin("rackspace")
73
- @ohai[:rackspace].should be_nil
74
+ @plugin.run
75
+ @plugin[:rackspace].should be_nil
74
76
  end
75
77
  end
76
78
 
77
79
  shared_examples_for "rackspace" do
78
80
 
79
81
  it "should create rackspace" do
80
- @ohai._require_plugin("rackspace")
81
- @ohai[:rackspace].should_not be_nil
82
+ @plugin.run
83
+ @plugin[:rackspace].should_not be_nil
82
84
  end
83
85
 
84
86
  it "should have all required attributes" do
85
- @ohai._require_plugin("rackspace")
86
- @ohai[:rackspace][:public_ip].should_not be_nil
87
- @ohai[:rackspace][:private_ip].should_not be_nil
88
- @ohai[:rackspace][:public_ipv4].should_not be_nil
89
- @ohai[:rackspace][:local_ipv4].should_not be_nil
90
- @ohai[:rackspace][:public_ipv6].should_not be_nil
91
- @ohai[:rackspace][:local_ipv6].should be_nil
87
+ @plugin.run
88
+ @plugin[:rackspace][:public_ip].should_not be_nil
89
+ @plugin[:rackspace][:private_ip].should_not be_nil
90
+ @plugin[:rackspace][:public_ipv4].should_not be_nil
91
+ @plugin[:rackspace][:local_ipv4].should_not be_nil
92
+ @plugin[:rackspace][:public_ipv6].should_not be_nil
93
+ @plugin[:rackspace][:local_ipv6].should be_nil
94
+ @plugin[:rackspace][:local_hostname].should_not be_nil
95
+ @plugin[:rackspace][:public_hostname].should_not be_nil
92
96
  end
93
97
 
94
98
  it "should have correct values for all attributes" do
95
- @ohai._require_plugin("rackspace")
96
- @ohai[:rackspace][:public_ip].should == "1.2.3.4"
97
- @ohai[:rackspace][:private_ip].should == "5.6.7.8"
98
- @ohai[:rackspace][:public_ipv4].should == "1.2.3.4"
99
- @ohai[:rackspace][:local_ipv4].should == "5.6.7.8"
100
- @ohai[:rackspace][:public_ipv6].should == "2a00:1a48:7805:111:e875:efaf:ff08:75"
99
+ @plugin.run
100
+ @plugin[:rackspace][:public_ip].should == "1.2.3.4"
101
+ @plugin[:rackspace][:private_ip].should == "5.6.7.8"
102
+ @plugin[:rackspace][:public_ipv4].should == "1.2.3.4"
103
+ @plugin[:rackspace][:local_ipv4].should == "5.6.7.8"
104
+ @plugin[:rackspace][:public_ipv6].should == "2a00:1a48:7805:111:e875:efaf:ff08:75"
105
+ @plugin[:rackspace][:local_hostname].should == 'katie'
106
+ @plugin[:rackspace][:public_hostname].should == "1-2-3-4.static.cloud-ips.com"
101
107
  end
102
108
 
103
109
  it "should capture region information" do
@@ -108,9 +114,9 @@ server_id = "21301000"
108
114
  created_at = "2012-12-06T22:08:16Z"
109
115
  region = "dfw"
110
116
  OUT
111
- @ohai.stub(:run_command).with({:no_status_check=>true, :command=>"xenstore-ls vm-data/provider_data"}).and_return([ 0, provider_data, ""])
112
- @ohai._require_plugin("rackspace")
113
- @ohai[:rackspace][:region].should == "dfw"
117
+ @plugin.stub(:shell_out).with("xenstore-ls vm-data/provider_data").and_return(mock_shell_out(0, provider_data, ""))
118
+ @plugin.run
119
+ @plugin[:rackspace][:region].should == "dfw"
114
120
  end
115
121
  end
116
122
 
@@ -118,10 +124,38 @@ OUT
118
124
  it_should_behave_like "rackspace"
119
125
 
120
126
  before(:each) do
121
- File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
122
- File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
123
- File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
124
- File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
127
+ File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
128
+ File.stub(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
129
+ File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
130
+ File.stub(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
131
+ end
132
+
133
+ describe 'with no public interfaces (empty eth0)' do
134
+ before do
135
+ # unset public (eth0) addresses
136
+ @plugin[:network][:interfaces][:eth0]['addresses'] = {}
137
+ end
138
+
139
+ it "should have all required attributes" do
140
+ @plugin.run
141
+ # expliticly nil
142
+ @plugin[:rackspace][:public_ip].should be_nil
143
+ @plugin[:rackspace][:public_ipv4].should be_nil
144
+ @plugin[:rackspace][:public_ipv6].should be_nil
145
+ @plugin[:rackspace][:public_hostname].should be_nil
146
+ # per normal
147
+ @plugin[:rackspace][:private_ip].should_not be_nil
148
+ @plugin[:rackspace][:local_ipv4].should_not be_nil
149
+ @plugin[:rackspace][:local_ipv6].should be_nil
150
+ @plugin[:rackspace][:local_hostname].should_not be_nil
151
+ end
152
+
153
+ it "should have correct values for all attributes" do
154
+ @plugin.run
155
+ @plugin[:rackspace][:private_ip].should == "5.6.7.8"
156
+ @plugin[:rackspace][:local_ipv4].should == "5.6.7.8"
157
+ @plugin[:rackspace][:local_hostname].should == 'katie'
158
+ end
125
159
  end
126
160
  end
127
161
 
@@ -129,8 +163,8 @@ OUT
129
163
  it_should_behave_like "!rackspace"
130
164
 
131
165
  before(:each) do
132
- File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false)
133
- File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false)
166
+ File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false)
167
+ File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false)
134
168
  end
135
169
  end
136
170
 
@@ -138,10 +172,13 @@ OUT
138
172
  it_should_behave_like "!rackspace"
139
173
 
140
174
  before(:each) do
141
- File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
142
- File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
143
- File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
144
- File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
175
+ File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
176
+ File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
177
+ File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
178
+ File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
179
+
180
+ File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false)
181
+ File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false)
145
182
  end
146
183
  end
147
184
 
@@ -149,10 +186,8 @@ OUT
149
186
  it_should_behave_like "rackspace"
150
187
 
151
188
  before(:each) do
152
- stderr = StringIO.new
153
189
  stdout = "Rackspace\n"
154
- status = 0
155
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ])
190
+ @plugin.stub(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
156
191
  end
157
192
  end
158
193
 
@@ -160,10 +195,8 @@ OUT
160
195
  it_should_behave_like "!rackspace"
161
196
 
162
197
  before(:each) do
163
- stderr = StringIO.new
164
198
  stdout = "cumulonimbus\n"
165
- status = 0
166
- @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ])
199
+ @plugin.stub(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
167
200
  end
168
201
  end
169
202
  end