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
@@ -21,11 +21,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
21
21
 
22
22
  describe Ohai::System, "Linux cpu plugin" do
23
23
  before(:each) do
24
- @ohai = Ohai::System.new
25
- @ohai.stub!(:require_plugin).and_return(true)
26
- @ohai[:os] = "linux"
27
- @mock_file = mock("/proc/cpuinfo")
28
- @mock_file.stub!(:each).
24
+ @plugin = get_plugin("linux/cpu")
25
+ @plugin.stub(:collect_os).and_return(:linux)
26
+ @double_file = double("/proc/cpuinfo")
27
+ @double_file.stub(:each).
29
28
  and_yield("processor : 0").
30
29
  and_yield("vendor_id : GenuineIntel").
31
30
  and_yield("cpu family : 6").
@@ -45,84 +44,84 @@ describe Ohai::System, "Linux cpu plugin" do
45
44
  and_yield("flags : fpu pse tsc msr mce cx8 sep mtrr pge cmov").
46
45
  and_yield("bogomips : 2575.86").
47
46
  and_yield("clflush size : 32")
48
- File.stub!(:open).with("/proc/cpuinfo").and_return(@mock_file)
47
+ File.stub(:open).with("/proc/cpuinfo").and_return(@double_file)
49
48
  end
50
49
 
51
50
  it "should set cpu[:total] to 1" do
52
- @ohai._require_plugin("linux::cpu")
53
- @ohai[:cpu][:total].should == 1
51
+ @plugin.run
52
+ @plugin[:cpu][:total].should == 1
54
53
  end
55
54
 
56
55
  it "should set cpu[:real] to 0" do
57
- @ohai._require_plugin("linux::cpu")
58
- @ohai[:cpu][:real].should == 0
56
+ @plugin.run
57
+ @plugin[:cpu][:real].should == 0
59
58
  end
60
59
 
61
60
  it "should have a cpu 0" do
62
- @ohai._require_plugin("linux::cpu")
63
- @ohai[:cpu].should have_key("0")
61
+ @plugin.run
62
+ @plugin[:cpu].should have_key("0")
64
63
  end
65
64
 
66
65
  it "should have a vendor_id for cpu 0" do
67
- @ohai._require_plugin("linux::cpu")
68
- @ohai[:cpu]["0"].should have_key("vendor_id")
69
- @ohai[:cpu]["0"]["vendor_id"].should eql("GenuineIntel")
66
+ @plugin.run
67
+ @plugin[:cpu]["0"].should have_key("vendor_id")
68
+ @plugin[:cpu]["0"]["vendor_id"].should eql("GenuineIntel")
70
69
  end
71
70
 
72
71
  it "should have a family for cpu 0" do
73
- @ohai._require_plugin("linux::cpu")
74
- @ohai[:cpu]["0"].should have_key("family")
75
- @ohai[:cpu]["0"]["family"].should eql("6")
72
+ @plugin.run
73
+ @plugin[:cpu]["0"].should have_key("family")
74
+ @plugin[:cpu]["0"]["family"].should eql("6")
76
75
  end
77
76
 
78
77
  it "should have a model for cpu 0" do
79
- @ohai._require_plugin("linux::cpu")
80
- @ohai[:cpu]["0"].should have_key("model")
81
- @ohai[:cpu]["0"]["model"].should eql("23")
78
+ @plugin.run
79
+ @plugin[:cpu]["0"].should have_key("model")
80
+ @plugin[:cpu]["0"]["model"].should eql("23")
82
81
  end
83
82
 
84
83
  it "should have a stepping for cpu 0" do
85
- @ohai._require_plugin("linux::cpu")
86
- @ohai[:cpu]["0"].should have_key("stepping")
87
- @ohai[:cpu]["0"]["stepping"].should eql("6")
84
+ @plugin.run
85
+ @plugin[:cpu]["0"].should have_key("stepping")
86
+ @plugin[:cpu]["0"]["stepping"].should eql("6")
88
87
  end
89
88
 
90
89
  it "should not have a phyiscal_id for cpu 0" do
91
- @ohai._require_plugin("linux::cpu")
92
- @ohai[:cpu]["0"].should_not have_key("physical_id")
90
+ @plugin.run
91
+ @plugin[:cpu]["0"].should_not have_key("physical_id")
93
92
  end
94
93
 
95
94
  it "should not have a core_id for cpu 0" do
96
- @ohai._require_plugin("linux::cpu")
97
- @ohai[:cpu]["0"].should_not have_key("core_id")
95
+ @plugin.run
96
+ @plugin[:cpu]["0"].should_not have_key("core_id")
98
97
  end
99
98
 
100
99
  it "should not have a cores for cpu 0" do
101
- @ohai._require_plugin("linux::cpu")
102
- @ohai[:cpu]["0"].should_not have_key("cores")
100
+ @plugin.run
101
+ @plugin[:cpu]["0"].should_not have_key("cores")
103
102
  end
104
103
 
105
104
  it "should have a model name for cpu 0" do
106
- @ohai._require_plugin("linux::cpu")
107
- @ohai[:cpu]["0"].should have_key("model_name")
108
- @ohai[:cpu]["0"]["model_name"].should eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz")
105
+ @plugin.run
106
+ @plugin[:cpu]["0"].should have_key("model_name")
107
+ @plugin[:cpu]["0"]["model_name"].should eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz")
109
108
  end
110
109
 
111
110
  it "should have a mhz for cpu 0" do
112
- @ohai._require_plugin("linux::cpu")
113
- @ohai[:cpu]["0"].should have_key("mhz")
114
- @ohai[:cpu]["0"]["mhz"].should eql("1968.770")
111
+ @plugin.run
112
+ @plugin[:cpu]["0"].should have_key("mhz")
113
+ @plugin[:cpu]["0"]["mhz"].should eql("1968.770")
115
114
  end
116
115
 
117
116
  it "should have a cache_size for cpu 0" do
118
- @ohai._require_plugin("linux::cpu")
119
- @ohai[:cpu]["0"].should have_key("cache_size")
120
- @ohai[:cpu]["0"]["cache_size"].should eql("64 KB")
117
+ @plugin.run
118
+ @plugin[:cpu]["0"].should have_key("cache_size")
119
+ @plugin[:cpu]["0"]["cache_size"].should eql("64 KB")
121
120
  end
122
121
 
123
122
  it "should have flags for cpu 0" do
124
- @ohai._require_plugin("linux::cpu")
125
- @ohai[:cpu]["0"].should have_key("flags")
126
- @ohai[:cpu]["0"]["flags"].should == %w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}
123
+ @plugin.run
124
+ @plugin[:cpu]["0"].should have_key("flags")
125
+ @plugin[:cpu]["0"]["flags"].should == %w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}
127
126
  end
128
- end
127
+ end
@@ -20,418 +20,237 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
20
20
 
21
21
  describe Ohai::System, "Linux filesystem plugin" do
22
22
  before(:each) do
23
- @ohai = Ohai::System.new
24
- @ohai[:os] = "linux"
25
- @ohai.stub!(:require_plugin).and_return(true)
26
- @ohai.extend(SimpleFromFile)
23
+ @plugin = get_plugin("linux/filesystem")
24
+ @plugin.stub(:collect_os).and_return(:linux)
27
25
 
28
- stdout = mock("STDOUT_SKEL")
29
- stderr = mock("STDERR_SKEL")
30
- stdout.stub!(:each_line).and_yield('')
31
- stderr.stub!(:each_line).and_yield('')
26
+ @plugin.stub(:shell_out).with("df -P").and_return(mock_shell_out(0, "", ""))
27
+ @plugin.stub(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
28
+ @plugin.stub(:shell_out).with("blkid -s TYPE").and_return(mock_shell_out(0, "", ""))
29
+ @plugin.stub(:shell_out).with("blkid -s UUID").and_return(mock_shell_out(0, "", ""))
30
+ @plugin.stub(:shell_out).with("blkid -s LABEL").and_return(mock_shell_out(0, "", ""))
32
31
 
33
- @df_cmd = {
34
- :command => "df -P",
35
- :timeout => 120,
36
- :no_status_check => true
37
- }
38
- @mount_cmd = {
39
- :command => "mount",
40
- :timeout => 120,
41
- }
42
-
43
- @ohai.stub!(:run_command).with(@df_cmd).and_return([0,stdout,stderr])
44
- @ohai.stub!(:run_command).with(@mount_cmd).and_return([0,stdout,stderr])
45
- File.stub!(:exists?).with("/bin/lsblk").and_return(false)
46
- @ohai.stub!(:popen4).with("blkid -s TYPE").and_return(false)
47
- @ohai.stub!(:popen4).with("blkid -s UUID").and_return(false)
48
- @ohai.stub!(:popen4).with("blkid -s LABEL").and_return(false)
49
-
50
- @ohai.stub!(:popen4).with("lsblk -r -o NAME,FSTYPE -n").and_return(false)
51
- @ohai.stub!(:popen4).with("lsblk -r -o NAME,UUID -n").and_return(false)
52
- @ohai.stub!(:popen4).with("lsblk -r -o NAME,LABEL -n").and_return(false)
53
-
54
- File.stub!(:exists?).with("/proc/mounts").and_return(false)
55
-
56
- %w{sdb1 sdb2 sda1 sda2 md0 md1 md2}.each do |name|
57
- File.stub!(:exist?).with("/dev/#{name}").and_return(true)
58
- end
59
- %w{
60
- sys.vg-root.lv
61
- sys.vg-swap.lv
62
- sys.vg-tmp.lv
63
- sys.vg-usr.lv
64
- sys.vg-var.lv
65
- sys.vg-home.lv
66
- }.each do |name|
67
- File.stub!(:exist?).with("/dev/#{name}").and_return(false)
68
- File.stub!(:exist?).with("/dev/mapper/#{name}").and_return(true)
69
- end
32
+ File.stub(:exists?).with("/proc/mounts").and_return(false)
70
33
  end
71
34
 
72
35
  describe "when gathering filesystem usage data from df" do
73
36
  before(:each) do
74
- @stdin = mock("STDIN", { :close => true })
75
- @pid = 10
76
- @stderr = mock("STDERR")
77
- @stdout = mock("STDOUT")
78
- @status = 0
79
-
80
- @stdout.stub!(:each_line).
81
- and_yield("Filesystem 1024-blocks Used Available Capacity Mounted on").
82
- and_yield("/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /").
83
- and_yield("tmpfs 2030944 0 2030944 0% /lib/init/rw").
84
- and_yield("udev 2025576 228 2025348 1% /dev").
85
- and_yield("tmpfs 2030944 2960 2027984 1% /dev/shm").
86
- and_yield("/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home").
87
- and_yield("/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special").
88
- and_yield("/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp").
89
- and_yield("/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr").
90
- and_yield("/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var").
91
- and_yield("/dev/md0 960492 36388 875312 4% /boot")
37
+ @stdout = <<-DF
38
+ Filesystem 1024-blocks Used Available Capacity Mounted on
39
+ /dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /
40
+ tmpfs 2030944 0 2030944 0% /lib/init/rw
41
+ udev 2025576 228 2025348 1% /dev
42
+ tmpfs 2030944 2960 2027984 1% /dev/shm
43
+ /dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home
44
+ /dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special
45
+ /dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp
46
+ /dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr
47
+ /dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var
48
+ /dev/md0 960492 36388 875312 4% /boot
49
+ DF
50
+ @plugin.stub(:shell_out).with("df -P").and_return(mock_shell_out(0, @stdout, ""))
92
51
  end
93
52
 
94
53
  it "should run df -P" do
95
- @ohai.should_receive(:run_command).with(@df_cmd).and_return(true)
96
- @ohai._require_plugin("linux::filesystem")
54
+ @plugin.should_receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @stdout, ""))
55
+ @plugin.run
97
56
  end
98
57
 
99
58
  it "should set kb_size to value from df -P" do
100
- @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr])
101
- @ohai._require_plugin("linux::filesystem")
102
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_size].should be == "97605057"
59
+ @plugin.run
60
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_size].should be == "97605057"
103
61
  end
104
62
 
105
63
  it "should set kb_used to value from df -P" do
106
- @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr])
107
- @ohai._require_plugin("linux::filesystem")
108
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_used].should be == "53563253"
64
+ @plugin.run
65
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_used].should be == "53563253"
109
66
  end
110
67
 
111
68
  it "should set kb_available to value from df -P" do
112
- @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr])
113
- @ohai._require_plugin("linux::filesystem")
114
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_available].should be == "44041805"
69
+ @plugin.run
70
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_available].should be == "44041805"
115
71
  end
116
72
 
117
73
  it "should set percent_used to value from df -P" do
118
- @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr])
119
- @ohai._require_plugin("linux::filesystem")
120
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:percent_used].should be == "56%"
74
+ @plugin.run
75
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:percent_used].should be == "56%"
121
76
  end
122
77
 
123
78
  it "should set mount to value from df -P" do
124
- @ohai.stub!(:run_command).with(@df_cmd).and_return([@status, @stdout, @stderr])
125
- @ohai._require_plugin("linux::filesystem")
126
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
79
+ @plugin.run
80
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
127
81
  end
128
82
  end
129
83
 
130
84
  describe "when gathering mounted filesystem data from mount" do
131
85
  before(:each) do
132
- @stdin = mock("STDIN", { :close => true })
133
- @pid = 10
134
- @stderr = mock("STDERR")
135
- @stdout = mock("STDOUT")
136
- @status = 0
137
-
138
- @stdout.stub!(:each_line).
139
- and_yield("/dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro)").
140
- and_yield("tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)").
141
- and_yield("proc on /proc type proc (rw,noexec,nosuid,nodev)").
142
- and_yield("sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)").
143
- and_yield("udev on /dev type tmpfs (rw,mode=0755)").
144
- and_yield("tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)").
145
- and_yield("devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)").
146
- and_yield("/dev/mapper/sys.vg-home.lv on /home type xfs (rw,noatime)").
147
- and_yield("/dev/mapper/sys.vg-special.lv on /special type xfs (ro,noatime)").
148
- and_yield("/dev/mapper/sys.vg-tmp.lv on /tmp type ext4 (rw,noatime)").
149
- and_yield("/dev/mapper/sys.vg-usr.lv on /usr type ext4 (rw,noatime)").
150
- and_yield("/dev/mapper/sys.vg-var.lv on /var type ext4 (rw,noatime)").
151
- and_yield("/dev/md0 on /boot type ext3 (rw,noatime,errors=remount-ro)").
152
- and_yield("fusectl on /sys/fs/fuse/connections type fusectl (rw)").
153
- and_yield("binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)")
86
+ @stdout = <<-MOUNT
87
+ /dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro)
88
+ tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
89
+ proc on /proc type proc (rw,noexec,nosuid,nodev)
90
+ sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
91
+ udev on /dev type tmpfs (rw,mode=0755)
92
+ tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
93
+ devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
94
+ /dev/mapper/sys.vg-home.lv on /home type xfs (rw,noatime)
95
+ /dev/mapper/sys.vg-special.lv on /special type xfs (ro,noatime)
96
+ /dev/mapper/sys.vg-tmp.lv on /tmp type ext4 (rw,noatime)
97
+ /dev/mapper/sys.vg-usr.lv on /usr type ext4 (rw,noatime)
98
+ /dev/mapper/sys.vg-var.lv on /var type ext4 (rw,noatime)
99
+ /dev/md0 on /boot type ext3 (rw,noatime,errors=remount-ro)
100
+ fusectl on /sys/fs/fuse/connections type fusectl (rw)
101
+ binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
102
+ MOUNT
103
+ @plugin.stub(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, ""))
154
104
  end
155
105
 
156
106
  it "should run mount" do
157
- @ohai.stub!(:run_command).with(@mount_cmd).and_return([@status, @stdout, @stderr])
158
- @ohai._require_plugin("linux::filesystem")
107
+ @plugin.should_receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, ""))
108
+ @plugin.run
159
109
  end
160
110
 
161
111
  it "should set mount to value from mount" do
162
- @ohai.stub!(:run_command).with(@mount_cmd).and_return([@status, @stdout, @stderr])
163
- @ohai._require_plugin("linux::filesystem")
164
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
112
+ @plugin.run
113
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
165
114
  end
166
115
 
167
116
  it "should set fs_type to value from mount" do
168
- @ohai.stub!(:run_command).with(@mount_cmd).and_return([@status, @stdout, @stderr])
169
- @ohai._require_plugin("linux::filesystem")
170
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
117
+ @plugin.run
118
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
171
119
  end
172
120
 
173
121
  it "should set mount_options to an array of values from mount" do
174
- @ohai.stub!(:run_command).with(@mount_cmd).and_return([@status, @stdout, @stderr])
175
- @ohai._require_plugin("linux::filesystem")
176
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime" ]
122
+ @plugin.run
123
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime" ]
177
124
  end
178
125
  end
179
126
 
180
127
  describe "when gathering filesystem type data from blkid" do
181
128
  before(:each) do
182
- @stdin = mock("STDIN", { :close => true })
183
- @pid = 10
184
- @stderr = mock("STDERR")
185
- @stdout = mock("STDOUT")
186
- @status = 0
187
-
188
- @stdout.stub!(:each).
189
- and_yield("/dev/sdb1: TYPE=\"linux_raid_member\" ").
190
- and_yield("/dev/sdb2: TYPE=\"linux_raid_member\" ").
191
- and_yield("/dev/sda1: TYPE=\"linux_raid_member\" ").
192
- and_yield("/dev/sda2: TYPE=\"linux_raid_member\" ").
193
- and_yield("/dev/md0: TYPE=\"ext3\" ").
194
- and_yield("/dev/md1: TYPE=\"LVM2_member\" ").
195
- and_yield("/dev/mapper/sys.vg-root.lv: TYPE=\"ext4\" ").
196
- and_yield("/dev/mapper/sys.vg-swap.lv: TYPE=\"swap\" ").
197
- and_yield("/dev/mapper/sys.vg-tmp.lv: TYPE=\"ext4\" ").
198
- and_yield("/dev/mapper/sys.vg-usr.lv: TYPE=\"ext4\" ").
199
- and_yield("/dev/mapper/sys.vg-var.lv: TYPE=\"ext4\" ").
200
- and_yield("/dev/mapper/sys.vg-home.lv: TYPE=\"xfs\" ")
129
+ @stdout = <<-BLKID_TYPE
130
+ dev/sdb1: TYPE=\"linux_raid_member\"
131
+ /dev/sdb2: TYPE=\"linux_raid_member\"
132
+ /dev/sda1: TYPE=\"linux_raid_member\"
133
+ /dev/sda2: TYPE=\"linux_raid_member\"
134
+ /dev/md0: TYPE=\"ext3\"
135
+ /dev/md1: TYPE=\"LVM2_member\"
136
+ /dev/mapper/sys.vg-root.lv: TYPE=\"ext4\"
137
+ /dev/mapper/sys.vg-swap.lv: TYPE=\"swap\"
138
+ /dev/mapper/sys.vg-tmp.lv: TYPE=\"ext4\"
139
+ /dev/mapper/sys.vg-usr.lv: TYPE=\"ext4\"
140
+ /dev/mapper/sys.vg-var.lv: TYPE=\"ext4\"
141
+ /dev/mapper/sys.vg-home.lv: TYPE=\"xfs\"
142
+ BLKID_TYPE
143
+ @plugin.stub(:shell_out).with("blkid -s TYPE").and_return(mock_shell_out(0, @stdout, ""))
201
144
  end
202
145
 
203
146
  it "should run blkid -s TYPE" do
204
- @ohai.should_receive(:popen4).with("blkid -s TYPE").and_return(true)
205
- @ohai._require_plugin("linux::filesystem")
147
+ @plugin.should_receive(:shell_out).with("blkid -s TYPE").and_return(mock_shell_out(0, @stdout, ""))
148
+ @plugin.run
206
149
  end
207
150
 
208
151
  it "should set kb_size to value from blkid -s TYPE" do
209
- @ohai.stub!(:popen4).with("blkid -s TYPE").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
210
- @ohai._require_plugin("linux::filesystem")
211
- @ohai[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member"
212
- end
213
- end
214
-
215
- describe "when gathering filesystem type data from lsblk" do
216
- before(:each) do
217
- File.stub!(:exists?).with('/bin/lsblk').and_return(true)
218
- @stdin = mock("STDIN", { :close => true })
219
- @pid = 10
220
- @stderr = mock("STDERR")
221
- @stdout = mock("STDOUT")
222
- @status = 0
223
-
224
- @stdout.stub!(:each).
225
- and_yield("sdb1 linux_raid_member").
226
- and_yield("sdb2 linux_raid_member").
227
- and_yield("sda1 linux_raid_member").
228
- and_yield("sda2 linux_raid_member").
229
- and_yield("md0 ext3").
230
- and_yield("md1 LVM2_member").
231
- and_yield("sys.vg-root.lv ext4").
232
- and_yield("sys.vg-swap.lv swap").
233
- and_yield("sys.vg-tmp.lv ext4").
234
- and_yield("sys.vg-usr.lv ext4").
235
- and_yield("sys.vg-var.lv ext4").
236
- and_yield("sys.vg-home.lv xfs")
237
- end
238
-
239
- it "should run lsblk -r -o NAME,FSTYPE -n" do
240
- @ohai.should_receive(:popen4).with("lsblk -r -o NAME,FSTYPE -n").
241
- and_return(true)
242
- @ohai._require_plugin("linux::filesystem")
152
+ @plugin.run
153
+ @plugin[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member"
243
154
  end
244
155
  end
245
156
 
246
157
  describe "when gathering filesystem uuid data from blkid" do
247
158
  before(:each) do
248
- @stdin = mock("STDIN", { :close => true })
249
- @pid = 10
250
- @stderr = mock("STDERR")
251
- @stdout = mock("STDOUT")
252
- @status = 0
253
-
254
- @stdout.stub!(:each).
255
- and_yield("/dev/sdb1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" ").
256
- and_yield("/dev/sdb2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" ").
257
- and_yield("/dev/sda1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" ").
258
- and_yield("/dev/sda2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" ").
259
- and_yield("/dev/md0: UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" ").
260
- and_yield("/dev/md1: UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" ").
261
- and_yield("/dev/mapper/sys.vg-root.lv: UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" ").
262
- and_yield("/dev/mapper/sys.vg-swap.lv: UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" ").
263
- and_yield("/dev/mapper/sys.vg-tmp.lv: UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" ").
264
- and_yield("/dev/mapper/sys.vg-usr.lv: UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" ").
265
- and_yield("/dev/mapper/sys.vg-var.lv: UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" ").
266
- and_yield("/dev/mapper/sys.vg-home.lv: UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" ")
159
+ @stdout = <<-BLKID_UUID
160
+ /dev/sdb1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\"
161
+ /dev/sdb2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\"
162
+ /dev/sda1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\"
163
+ /dev/sda2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\"
164
+ /dev/md0: UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\"
165
+ /dev/md1: UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\"
166
+ /dev/mapper/sys.vg-root.lv: UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\"
167
+ /dev/mapper/sys.vg-swap.lv: UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\"
168
+ /dev/mapper/sys.vg-tmp.lv: UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\"
169
+ /dev/mapper/sys.vg-usr.lv: UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\"
170
+ /dev/mapper/sys.vg-var.lv: UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\"
171
+ /dev/mapper/sys.vg-home.lv: UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\"
172
+ BLKID_UUID
173
+ @plugin.stub(:shell_out).with("blkid -s UUID").and_return(mock_shell_out(0, @stdout, ""))
267
174
  end
268
175
 
269
176
  it "should run blkid -s UUID" do
270
- @ohai.should_receive(:popen4).with("blkid -s UUID").and_return(true)
271
- @ohai._require_plugin("linux::filesystem")
177
+ @plugin.should_receive(:shell_out).with("blkid -s UUID").and_return(mock_shell_out(0, @stdout, ""))
178
+ @plugin.run
272
179
  end
273
180
 
274
181
  it "should set kb_size to value from blkid -s UUID" do
275
- @ohai.stub!(:popen4).with("blkid -s UUID").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
276
- @ohai._require_plugin("linux::filesystem")
277
- @ohai[:filesystem]["/dev/sda2"][:uuid].should be == "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
278
- end
279
- end
280
-
281
- describe "when gathering filesystem uuid data from lsblk" do
282
- before(:each) do
283
- File.stub!(:exists?).with('/bin/lsblk').and_return(true)
284
- @stdin = mock("STDIN", { :close => true })
285
- @pid = 10
286
- @stderr = mock("STDERR")
287
- @stdout = mock("STDOUT")
288
- @status = 0
289
-
290
- @stdout.stub!(:each).
291
- and_yield("sdb1 bd1197e0-6997-1f3a-e27e-7801388308b5").
292
- and_yield("sdb2 e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa").
293
- and_yield("sda1 bd1197e0-6997-1f3a-e27e-7801388308b5").
294
- and_yield("sda2 e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa").
295
- and_yield("md0 37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32").
296
- and_yield("md1 YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK").
297
- and_yield("sys.vg-root.lv 7742d14b-80a3-4e97-9a32-478be9ea9aea").
298
- and_yield("sys.vg-swap.lv 9bc2e515-8ddc-41c3-9f63-4eaebde9ce96").
299
- and_yield("sys.vg-tmp.lv 74cf7eb9-428f-479e-9a4a-9943401e81e5").
300
- and_yield("sys.vg-usr.lv 26ec33c5-d00b-4f88-a550-492def013bbc").
301
- and_yield("sys.vg-var.lv 6b559c35-7847-4ae2-b512-c99012d3f5b3").
302
- and_yield("sys.vg-home.lv d6efda02-1b73-453c-8c74-7d8dee78fa5e")
303
- end
304
-
305
- it "should run lsblk -r -o NAME,UUID -n" do
306
- @ohai.should_receive(:popen4).with("lsblk -r -o NAME,UUID -n").
307
- and_return(true)
308
- @ohai._require_plugin("linux::filesystem")
309
- end
310
-
311
- it "should set kb_size to value from lsblk -r -o NAME,UUID -n" do
312
- @ohai.stub!(:popen4).with("lsblk -r -o NAME,UUID -n").
313
- and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
314
- @ohai._require_plugin("linux::filesystem")
315
- @ohai[:filesystem]["/dev/sda2"][:uuid].should be == "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
182
+ @plugin.run
183
+ @plugin[:filesystem]["/dev/sda2"][:uuid].should be == "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
316
184
  end
317
185
  end
318
186
 
319
187
  describe "when gathering filesystem label data from blkid" do
320
188
  before(:each) do
321
- @stdin = mock("STDIN", { :close => true })
322
- @pid = 10
323
- @stderr = mock("STDERR")
324
- @stdout = mock("STDOUT")
325
- @status = 0
326
-
327
- @stdout.stub!(:each).
328
- and_yield("/dev/sda1: LABEL=\"fuego:0\" ").
329
- and_yield("/dev/sda2: LABEL=\"fuego:1\" ").
330
- and_yield("/dev/sdb1: LABEL=\"fuego:0\" ").
331
- and_yield("/dev/sdb2: LABEL=\"fuego:1\" ").
332
- and_yield("/dev/md0: LABEL=\"/boot\" ").
333
- and_yield("/dev/mapper/sys.vg-root.lv: LABEL=\"/\" ").
334
- and_yield("/dev/mapper/sys.vg-tmp.lv: LABEL=\"/tmp\" ").
335
- and_yield("/dev/mapper/sys.vg-usr.lv: LABEL=\"/usr\" ").
336
- and_yield("/dev/mapper/sys.vg-var.lv: LABEL=\"/var\" ").
337
- and_yield("/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" ")
189
+ @stdout = <<-BLKID_LABEL
190
+ /dev/sda1: LABEL=\"fuego:0\"
191
+ /dev/sda2: LABEL=\"fuego:1\"
192
+ /dev/sdb1: LABEL=\"fuego:0\"
193
+ /dev/sdb2: LABEL=\"fuego:1\"
194
+ /dev/md0: LABEL=\"/boot\"
195
+ /dev/mapper/sys.vg-root.lv: LABEL=\"/\"
196
+ /dev/mapper/sys.vg-tmp.lv: LABEL=\"/tmp\"
197
+ /dev/mapper/sys.vg-usr.lv: LABEL=\"/usr\"
198
+ /dev/mapper/sys.vg-var.lv: LABEL=\"/var\"
199
+ /dev/mapper/sys.vg-home.lv: LABEL=\"/home\"
200
+ BLKID_LABEL
201
+ @plugin.stub(:shell_out).with("blkid -s LABEL").and_return(mock_shell_out(0, @stdout, ""))
338
202
  end
339
203
 
340
204
  it "should run blkid -s LABEL" do
341
- @ohai.should_receive(:popen4).with("blkid -s LABEL").and_return(true)
342
- @ohai._require_plugin("linux::filesystem")
205
+ @plugin.should_receive(:shell_out).with("blkid -s LABEL").and_return(mock_shell_out(0, @stdout, ""))
206
+ @plugin.run
343
207
  end
344
208
 
345
209
  it "should set kb_size to value from blkid -s LABEL" do
346
- @ohai.stub!(:popen4).with("blkid -s LABEL").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
347
- @ohai._require_plugin("linux::filesystem")
348
- @ohai[:filesystem]["/dev/md0"][:label].should be == "/boot"
210
+ @plugin.run
211
+ @plugin[:filesystem]["/dev/md0"][:label].should be == "/boot"
349
212
  end
350
213
  end
351
214
 
352
- describe "when gathering filesystem label data from lsblk" do
353
- before(:each) do
354
- File.stub!(:exists?).with('/bin/lsblk').and_return(true)
355
- @stdin = mock("STDIN", { :close => true })
356
- @pid = 10
357
- @stderr = mock("STDERR")
358
- @stdout = mock("STDOUT")
359
- @status = 0
360
-
361
- @stdout.stub!(:each).
362
- and_yield("sda1 fuego:0").
363
- and_yield("sda2 fuego:1").
364
- and_yield("sdb1 fuego:0").
365
- and_yield("sdb2 fuego:1").
366
- and_yield("md0 /boot").
367
- and_yield("sys.vg-root.lv /").
368
- and_yield("sys.vg-tmp.lv /tmp").
369
- and_yield("sys.vg-usr.lv /usr").
370
- and_yield("sys.vg-var.lv /var").
371
- and_yield("sys.vg-home.lv /home")
372
- end
373
-
374
- it "should run lsblk -r -o NAME,LABEL -n" do
375
- @ohai.should_receive(:popen4).with("lsblk -r -o NAME,LABEL -n").
376
- and_return(true)
377
- @ohai._require_plugin("linux::filesystem")
378
- end
379
-
380
- it "should set kb_size to value from lsblk -r -o NAME,LABEL -n" do
381
- @ohai.stub!(:popen4).with("lsblk -r -o NAME,LABEL -n").
382
- and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
383
- @ohai._require_plugin("linux::filesystem")
384
- @ohai[:filesystem]["/dev/md0"][:label].should be == "/boot"
385
- end
386
- end
387
-
388
-
389
215
  describe "when gathering data from /proc/mounts" do
390
216
  before(:each) do
391
- File.stub!(:exists?).with("/proc/mounts").and_return(true)
392
- @mock_file = mock("/proc/mounts")
393
- @mock_file.stub!(:read_nonblock).and_return(@mock_file)
394
- @mounts = <<-MOUNTS
395
- rootfs / rootfs rw 0 0
396
- none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
397
- none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
398
- none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0
399
- none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
400
- /dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0
401
- tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0
402
- tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
403
- /dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0
404
- /dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0
405
- /dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0
406
- /dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0
407
- /dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0
408
- /dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0
409
- fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
410
- binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
411
- MOUNTS
412
- @counter = 0
413
- @mock_file.stub(:read_nonblock) do
414
- @counter += 1
415
- raise EOFError if @counter == 2
416
- @mounts
417
- end
418
- @mock_file.stub(:close)
419
- File.stub!(:open).with("/proc/mounts").and_return(@mock_file)
217
+ File.stub(:exists?).with("/proc/mounts").and_return(true)
218
+ @double_file = double("/proc/mounts")
219
+ @double_file.stub(:read_nonblock).and_return(@double_file)
220
+ @double_file.stub(:each_line).
221
+ and_yield("rootfs / rootfs rw 0 0").
222
+ and_yield("none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0").
223
+ and_yield("none /proc proc rw,nosuid,nodev,noexec,relatime 0 0").
224
+ and_yield("none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0").
225
+ and_yield("none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0").
226
+ and_yield("/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0").
227
+ and_yield("tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0").
228
+ and_yield("tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0").
229
+ and_yield("/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0").
230
+ and_yield("/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0").
231
+ and_yield("/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0").
232
+ and_yield("/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0").
233
+ and_yield("/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0").
234
+ and_yield("/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0").
235
+ and_yield("fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0").
236
+ and_yield("binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0")
237
+ File.stub(:open).with("/proc/mounts").and_return(@double_file)
420
238
  end
421
239
 
422
240
  it "should set mount to value from /proc/mounts" do
423
- @ohai._require_plugin("linux::filesystem")
424
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
241
+ @plugin.run
242
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
425
243
  end
426
244
 
427
245
  it "should set fs_type to value from /proc/mounts" do
428
- @ohai._require_plugin("linux::filesystem")
429
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
246
+ @plugin.run
247
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
430
248
  end
431
249
 
432
250
  it "should set mount_options to an array of values from /proc/mounts" do
433
- @ohai._require_plugin("linux::filesystem")
434
- @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime", "attr2", "noquota" ]
251
+ @plugin.run
252
+ @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime", "attr2", "noquota" ]
435
253
  end
436
254
  end
255
+
437
256
  end