puppet 2.7.11 → 2.7.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (220) hide show
  1. data/CHANGELOG +188 -0
  2. data/conf/osx/createpackage.sh +1 -0
  3. data/conf/redhat/puppet.spec +12 -9
  4. data/conf/suse/puppet.spec +4 -1
  5. data/install.rb +9 -22
  6. data/lib/puppet.rb +1 -31
  7. data/lib/puppet/agent.rb +3 -5
  8. data/lib/puppet/agent/locker.rb +15 -1
  9. data/lib/puppet/application.rb +7 -4
  10. data/lib/puppet/application/agent.rb +4 -25
  11. data/lib/puppet/application/apply.rb +3 -3
  12. data/lib/puppet/application/device.rb +2 -16
  13. data/lib/puppet/application/doc.rb +2 -2
  14. data/lib/puppet/application/face_base.rb +22 -5
  15. data/lib/puppet/application/filebucket.rb +2 -0
  16. data/lib/puppet/application/inspect.rb +2 -1
  17. data/lib/puppet/application/kick.rb +25 -9
  18. data/lib/puppet/application/queue.rb +0 -23
  19. data/lib/puppet/configurer.rb +1 -0
  20. data/lib/puppet/configurer/downloader.rb +7 -3
  21. data/lib/puppet/defaults.rb +34 -29
  22. data/lib/puppet/face/ca.rb +1 -1
  23. data/lib/puppet/face/catalog.rb +1 -0
  24. data/lib/puppet/face/file/store.rb +1 -1
  25. data/lib/puppet/face/module/list.rb +23 -3
  26. data/lib/puppet/face/module/search.rb +21 -32
  27. data/lib/puppet/face/module/uninstall.rb +56 -15
  28. data/lib/puppet/file_bucket/dipper.rb +2 -2
  29. data/lib/puppet/file_serving/base.rb +6 -5
  30. data/lib/puppet/file_serving/configuration/parser.rb +1 -1
  31. data/lib/puppet/file_serving/content.rb +1 -1
  32. data/lib/puppet/forge.rb +153 -0
  33. data/lib/puppet/{module_tool → forge}/cache.rb +1 -2
  34. data/lib/puppet/{module_tool → forge}/repository.rb +46 -4
  35. data/lib/puppet/indirector/exec.rb +1 -1
  36. data/lib/puppet/indirector/file_bucket_file/file.rb +3 -3
  37. data/lib/puppet/interface/action.rb +6 -2
  38. data/lib/puppet/module.rb +70 -10
  39. data/lib/puppet/module_tool.rb +2 -38
  40. data/lib/puppet/module_tool/applications.rb +15 -11
  41. data/lib/puppet/module_tool/applications/application.rb +2 -5
  42. data/lib/puppet/module_tool/applications/cleaner.rb +1 -1
  43. data/lib/puppet/module_tool/applications/installer.rb +10 -45
  44. data/lib/puppet/module_tool/applications/searcher.rb +2 -26
  45. data/lib/puppet/module_tool/applications/uninstaller.rb +39 -13
  46. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  47. data/lib/puppet/module_tool/dependency.rb +1 -1
  48. data/lib/puppet/network/authconfig.rb +1 -1
  49. data/lib/puppet/network/handler/fileserver.rb +1 -1
  50. data/lib/puppet/network/http/handler.rb +4 -1
  51. data/lib/puppet/network/http/webrick.rb +4 -2
  52. data/lib/puppet/node/environment.rb +32 -6
  53. data/lib/puppet/parameter/path.rb +0 -4
  54. data/lib/puppet/parser/ast/relationship.rb +3 -16
  55. data/lib/puppet/parser/collector.rb +5 -3
  56. data/lib/puppet/parser/compiler.rb +2 -1
  57. data/lib/puppet/parser/functions/file.rb +1 -1
  58. data/lib/puppet/parser/functions/generate.rb +8 -2
  59. data/lib/puppet/parser/grammar.ra +16 -15
  60. data/lib/puppet/parser/parser.rb +959 -881
  61. data/lib/puppet/parser/relationship.rb +32 -15
  62. data/lib/puppet/parser/resource.rb +0 -1
  63. data/lib/puppet/parser/type_loader.rb +1 -2
  64. data/lib/puppet/provider/augeas/augeas.rb +17 -29
  65. data/lib/puppet/provider/exec/windows.rb +25 -3
  66. data/lib/puppet/provider/file/posix.rb +1 -1
  67. data/lib/puppet/provider/file/windows.rb +1 -1
  68. data/lib/puppet/provider/group/windows_adsi.rb +1 -1
  69. data/lib/puppet/provider/package/aix.rb +1 -1
  70. data/lib/puppet/provider/package/appdmg.rb +1 -1
  71. data/lib/puppet/provider/package/dpkg.rb +1 -1
  72. data/lib/puppet/provider/package/gem.rb +21 -23
  73. data/lib/puppet/provider/package/macports.rb +1 -1
  74. data/lib/puppet/provider/package/msi.rb +7 -1
  75. data/lib/puppet/provider/package/openbsd.rb +13 -16
  76. data/lib/puppet/provider/package/pacman.rb +1 -1
  77. data/lib/puppet/provider/package/pip.rb +3 -0
  78. data/lib/puppet/provider/package/pkg.rb +1 -1
  79. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  80. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  81. data/lib/puppet/provider/package/portage.rb +2 -2
  82. data/lib/puppet/provider/package/rpm.rb +1 -1
  83. data/lib/puppet/provider/package/sun.rb +1 -1
  84. data/lib/puppet/provider/package/zypper.rb +35 -3
  85. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +6 -2
  86. data/lib/puppet/provider/selmodule/semodule.rb +2 -2
  87. data/lib/puppet/provider/service/base.rb +1 -1
  88. data/lib/puppet/provider/service/launchd.rb +4 -0
  89. data/lib/puppet/provider/service/src.rb +2 -2
  90. data/lib/puppet/provider/service/upstart.rb +1 -1
  91. data/lib/puppet/provider/service/windows.rb +5 -4
  92. data/lib/puppet/provider/user/aix.rb +3 -3
  93. data/lib/puppet/provider/user/pw.rb +6 -0
  94. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  95. data/lib/puppet/resource/catalog.rb +6 -6
  96. data/lib/puppet/resource/type.rb +2 -0
  97. data/lib/puppet/ssl/certificate_request.rb +0 -70
  98. data/lib/puppet/transaction.rb +1 -1
  99. data/lib/puppet/transaction/report.rb +3 -2
  100. data/lib/puppet/type.rb +1 -1
  101. data/lib/puppet/type/cron.rb +5 -2
  102. data/lib/puppet/type/exec.rb +8 -0
  103. data/lib/puppet/type/file.rb +27 -18
  104. data/lib/puppet/type/file/checksum.rb +2 -2
  105. data/lib/puppet/type/file/content.rb +14 -9
  106. data/lib/puppet/type/file/ensure.rb +5 -4
  107. data/lib/puppet/type/file/group.rb +10 -2
  108. data/lib/puppet/type/file/mode.rb +46 -18
  109. data/lib/puppet/type/file/owner.rb +10 -2
  110. data/lib/puppet/type/file/source.rb +27 -40
  111. data/lib/puppet/type/file/target.rb +6 -6
  112. data/lib/puppet/type/group.rb +13 -9
  113. data/lib/puppet/type/k5login.rb +1 -1
  114. data/lib/puppet/type/package.rb +24 -8
  115. data/lib/puppet/type/scheduled_task.rb +77 -131
  116. data/lib/puppet/type/service.rb +22 -8
  117. data/lib/puppet/type/user.rb +29 -9
  118. data/lib/puppet/util.rb +24 -33
  119. data/lib/puppet/util/colors.rb +98 -0
  120. data/lib/puppet/util/diff.rb +3 -1
  121. data/lib/puppet/util/log.rb +5 -1
  122. data/lib/puppet/util/log/destinations.rb +37 -44
  123. data/lib/puppet/util/monkey_patches.rb +32 -0
  124. data/lib/puppet/util/pidlock.rb +70 -21
  125. data/lib/puppet/util/rdoc/parser.rb +4 -2
  126. data/lib/puppet/util/selinux.rb +1 -1
  127. data/lib/puppet/util/suidmanager.rb +2 -12
  128. data/lib/puppet/util/windows.rb +2 -0
  129. data/lib/puppet/util/windows/process.rb +33 -0
  130. data/lib/puppet/util/windows/security.rb +6 -4
  131. data/lib/puppet/util/windows/user.rb +44 -0
  132. data/lib/semver.rb +55 -4
  133. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail +19 -0
  134. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.list +10 -0
  135. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.query +1 -0
  136. data/spec/fixtures/unit/provider/package/zypper/zypper-list-updates-SLES11sp1.out +369 -0
  137. data/spec/integration/defaults_spec.rb +10 -0
  138. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  139. data/spec/integration/module_tool_spec.rb +10 -12
  140. data/spec/integration/parser/compiler_spec.rb +147 -0
  141. data/spec/integration/type/file_spec.rb +1 -1
  142. data/spec/integration/util/windows/user_spec.rb +59 -0
  143. data/spec/lib/puppet/face/basetest.rb +5 -0
  144. data/spec/lib/puppet_spec/modules.rb +26 -0
  145. data/spec/spec_helper.rb +25 -0
  146. data/spec/unit/agent/locker_spec.rb +12 -0
  147. data/spec/unit/agent_backward_compatibility_spec.rb +152 -0
  148. data/spec/unit/agent_spec.rb +28 -8
  149. data/spec/unit/application/agent_spec.rb +4 -36
  150. data/spec/unit/application/device_spec.rb +55 -10
  151. data/spec/unit/application/face_base_spec.rb +32 -10
  152. data/spec/unit/application/filebucket_spec.rb +5 -0
  153. data/spec/unit/application/kick_spec.rb +6 -0
  154. data/spec/unit/application_spec.rb +8 -1
  155. data/spec/unit/configurer/downloader_spec.rb +4 -5
  156. data/spec/unit/face/ca_spec.rb +15 -4
  157. data/spec/unit/file_bucket/dipper_spec.rb +1 -1
  158. data/spec/unit/file_serving/base_spec.rb +60 -42
  159. data/spec/unit/file_serving/configuration/parser_spec.rb +5 -3
  160. data/spec/unit/file_serving/content_spec.rb +26 -27
  161. data/spec/unit/file_serving/metadata_spec.rb +22 -21
  162. data/spec/unit/forge/repository_spec.rb +86 -0
  163. data/spec/unit/forge_spec.rb +114 -0
  164. data/spec/unit/indirector/exec_spec.rb +8 -6
  165. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +0 -1
  166. data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
  167. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  168. data/spec/unit/indirector/resource/active_record_spec.rb +0 -4
  169. data/spec/unit/interface/action_builder_spec.rb +7 -5
  170. data/spec/unit/module_spec.rb +228 -9
  171. data/spec/unit/module_tool/application_spec.rb +3 -3
  172. data/spec/unit/module_tool/uninstaller_spec.rb +107 -27
  173. data/spec/unit/module_tool_spec.rb +0 -33
  174. data/spec/unit/network/authconfig_spec.rb +22 -21
  175. data/spec/unit/network/http/webrick_spec.rb +13 -9
  176. data/spec/unit/node/environment_spec.rb +159 -66
  177. data/spec/unit/parser/collector_spec.rb +16 -8
  178. data/spec/unit/parser/functions/generate_spec.rb +60 -18
  179. data/spec/unit/parser/resource_spec.rb +44 -0
  180. data/spec/unit/provider/augeas/augeas_spec.rb +160 -179
  181. data/spec/unit/provider/confine/feature_spec.rb +3 -5
  182. data/spec/unit/provider/package/dpkg_spec.rb +4 -2
  183. data/spec/unit/provider/package/gem_spec.rb +59 -43
  184. data/spec/unit/provider/package/openbsd_spec.rb +114 -0
  185. data/spec/unit/provider/package/pacman_spec.rb +1 -1
  186. data/spec/unit/provider/package/pip_spec.rb +10 -4
  187. data/spec/unit/provider/package/zypper_spec.rb +56 -14
  188. data/spec/unit/provider/selmodule_spec.rb +3 -3
  189. data/spec/unit/provider/service/launchd_spec.rb +22 -21
  190. data/spec/unit/provider/service/{upstart.rb → upstart_spec.rb} +7 -3
  191. data/spec/unit/provider/user/pw_spec.rb +19 -0
  192. data/spec/unit/resource/catalog_spec.rb +3 -3
  193. data/spec/unit/semver_spec.rb +117 -24
  194. data/spec/unit/transaction/report_spec.rb +11 -1
  195. data/spec/unit/type/cron_spec.rb +200 -213
  196. data/spec/unit/type/exec_spec.rb +7 -0
  197. data/spec/unit/type/file/content_spec.rb +2 -2
  198. data/spec/unit/type/file_spec.rb +12 -9
  199. data/spec/unit/type/package_spec.rb +25 -0
  200. data/spec/unit/type/schedule_spec.rb +31 -31
  201. data/spec/unit/util/diff_spec.rb +30 -0
  202. data/spec/unit/util/execution_stub_spec.rb +1 -2
  203. data/spec/unit/util/log/destinations_spec.rb +51 -0
  204. data/spec/unit/util/log_spec.rb +17 -1
  205. data/spec/unit/util/monkey_patches_spec.rb +119 -0
  206. data/spec/unit/util/rdoc/parser_spec.rb +25 -1
  207. data/spec/unit/util/selinux_spec.rb +2 -2
  208. data/spec/unit/util/suidmanager_spec.rb +6 -51
  209. data/spec/unit/util_spec.rb +82 -24
  210. data/test/lib/puppettest/certificates.rb +16 -0
  211. data/test/lib/puppettest/servertest.rb +4 -0
  212. data/test/util/pidlock.rb +125 -0
  213. metadata +23 -14
  214. data/ext/puppetstoredconfigclean.rb +0 -103
  215. data/lib/puppet/agent/disabler.rb +0 -27
  216. data/lib/puppet/util/anonymous_filelock.rb +0 -36
  217. data/spec/unit/agent/disabler_spec.rb +0 -60
  218. data/spec/unit/module_tool/repository_spec.rb +0 -52
  219. data/spec/unit/util/anonymous_filelock_spec.rb +0 -78
  220. data/spec/unit/util/pidlock_spec.rb +0 -208
@@ -5,6 +5,7 @@ require 'tmpdir'
5
5
 
6
6
  require 'puppet/node/environment'
7
7
  require 'puppet/util/execution'
8
+ require 'puppet_spec/modules'
8
9
 
9
10
  describe Puppet::Node::Environment do
10
11
  let(:env) { Puppet::Node::Environment.new("testing") }
@@ -124,8 +125,10 @@ describe Puppet::Node::Environment do
124
125
 
125
126
  describe "when validating modulepath or manifestdir directories" do
126
127
  before :each do
127
- @path_one = make_absolute('/one')
128
- @path_two = make_absolute('/two')
128
+ @path_one = tmpdir("path_one")
129
+ @path_two = tmpdir("path_one")
130
+ sep = File::PATH_SEPARATOR
131
+ Puppet[:modulepath] = "#{@path_one}#{sep}#{@path_two}"
129
132
  end
130
133
 
131
134
  it "should not return non-directories" do
@@ -167,15 +170,13 @@ describe Puppet::Node::Environment do
167
170
  end
168
171
 
169
172
  it "should return nil if asked for a module that does not exist in its path" do
170
-
171
- mod = mock 'module'
172
- Puppet::Module.expects(:new).with("one", :environment => env).returns mod
173
- mod.expects(:exist?).returns false
173
+ modpath = tmpdir('modpath')
174
+ env.modulepath = [modpath]
174
175
 
175
176
  env.module("one").should be_nil
176
177
  end
177
178
 
178
- describe ".modules_by_path" do
179
+ describe "module data" do
179
180
  before do
180
181
  dir = tmpdir("deep_path")
181
182
 
@@ -187,75 +188,167 @@ describe Puppet::Node::Environment do
187
188
  FileUtils.mkdir_p(@second)
188
189
  end
189
190
 
190
- it "should return an empty list if there are no modules" do
191
- env.modules_by_path.should == {
192
- @first => [],
193
- @second => []
194
- }
195
- end
196
-
197
- it "should include modules even if they exist in multiple dirs in the modulepath" do
198
- modpath1 = File.join(@first, "foo")
199
- FileUtils.mkdir_p(modpath1)
200
- modpath2 = File.join(@second, "foo")
201
- FileUtils.mkdir_p(modpath2)
202
-
203
- env.modules_by_path.should == {
204
- @first => [Puppet::Module.new('foo', :environment => env, :path => modpath1)],
205
- @second => [Puppet::Module.new('foo', :environment => env, :path => modpath2)]
206
- }
207
- end
208
- end
209
-
210
- describe ".modules" do
211
- it "should return an empty list if there are no modules" do
212
- env.modulepath = %w{/a /b}
213
- Dir.expects(:entries).with("/a").returns []
214
- Dir.expects(:entries).with("/b").returns []
215
-
216
- env.modules.should == []
217
- end
218
-
219
- it "should return a module named for every directory in each module path" do
220
- env.modulepath = %w{/a /b}
221
- Dir.expects(:entries).with("/a").returns %w{foo bar}
222
- Dir.expects(:entries).with("/b").returns %w{bee baz}
223
-
224
- env.modules.collect{|mod| mod.name}.sort.should == %w{foo bar bee baz}.sort
191
+ describe "#modules_by_path" do
192
+ it "should return an empty list if there are no modules" do
193
+ env.modules_by_path.should == {
194
+ @first => [],
195
+ @second => []
196
+ }
197
+ end
198
+
199
+ it "should include modules even if they exist in multiple dirs in the modulepath" do
200
+ modpath1 = File.join(@first, "foo")
201
+ FileUtils.mkdir_p(modpath1)
202
+ modpath2 = File.join(@second, "foo")
203
+ FileUtils.mkdir_p(modpath2)
204
+
205
+ env.modules_by_path.should == {
206
+ @first => [Puppet::Module.new('foo', :environment => env, :path => modpath1)],
207
+ @second => [Puppet::Module.new('foo', :environment => env, :path => modpath2)]
208
+ }
209
+ end
225
210
  end
226
211
 
227
- it "should remove duplicates" do
228
- env.modulepath = %w{/a /b}
229
- Dir.expects(:entries).with("/a").returns %w{foo}
230
- Dir.expects(:entries).with("/b").returns %w{foo}
231
-
232
- env.modules.collect{|mod| mod.name}.sort.should == %w{foo}
212
+ describe "#module_requirements" do
213
+ it "should return a list of what modules depend on other modules" do
214
+ PuppetSpec::Modules.create(
215
+ 'foo',
216
+ @first,
217
+ :metadata => {
218
+ :author => 'puppetlabs',
219
+ :dependencies => [{ 'name' => 'puppetlabs/bar', "version_requirement" => ">= 1.0.0" }]
220
+ }
221
+ )
222
+ PuppetSpec::Modules.create(
223
+ 'bar',
224
+ @second,
225
+ :metadata => {
226
+ :author => 'puppetlabs',
227
+ :dependencies => [{ 'name' => 'puppetlabs/foo', "version_requirement" => "<= 2.0.0" }]
228
+ }
229
+ )
230
+ PuppetSpec::Modules.create(
231
+ 'baz',
232
+ @first,
233
+ :metadata => {
234
+ :author => 'puppetlabs',
235
+ :dependencies => [{ 'name' => 'puppetlabs/bar', "version_requirement" => "3.0.0" }]
236
+ }
237
+ )
238
+ PuppetSpec::Modules.create(
239
+ 'alpha',
240
+ @first,
241
+ :metadata => {
242
+ :author => 'puppetlabs',
243
+ :dependencies => [{ 'name' => 'puppetlabs/bar', "version_requirement" => "~3.0.0" }]
244
+ }
245
+ )
246
+
247
+ env.module_requirements.should == {
248
+ 'puppetlabs/alpha' => [],
249
+ 'puppetlabs/foo' => [
250
+ {
251
+ "name" => "puppetlabs/bar",
252
+ "version" => "9.9.9",
253
+ "version_requirement" => "<= 2.0.0"
254
+ }
255
+ ],
256
+ 'puppetlabs/bar' => [
257
+ {
258
+ "name" => "puppetlabs/alpha",
259
+ "version" => "9.9.9",
260
+ "version_requirement" => "~3.0.0"
261
+ },
262
+ {
263
+ "name" => "puppetlabs/baz",
264
+ "version" => "9.9.9",
265
+ "version_requirement" => "3.0.0"
266
+ },
267
+ {
268
+ "name" => "puppetlabs/foo",
269
+ "version" => "9.9.9",
270
+ "version_requirement" => ">= 1.0.0"
271
+ }
272
+ ],
273
+ 'puppetlabs/baz' => []
274
+ }
275
+ end
233
276
  end
234
277
 
235
- it "should ignore invalid modules" do
236
- env.modulepath = %w{/a}
237
- Dir.expects(:entries).with("/a").returns %w{foo bar}
238
-
239
- Puppet::Module.expects(:new).with { |name, env| name == "foo" }.returns mock("foomod", :name => "foo")
240
- Puppet::Module.expects(:new).with { |name, env| name == "bar" }.raises( Puppet::Module::InvalidName, "name is invalid" )
241
-
242
- env.modules.collect{|mod| mod.name}.sort.should == %w{foo}
278
+ describe ".module_by_forge_name" do
279
+ it "should find modules by forge_name" do
280
+ mod = PuppetSpec::Modules.create(
281
+ 'baz',
282
+ @first,
283
+ :metadata => {:author => 'puppetlabs'},
284
+ :environment => env
285
+ )
286
+ env.module_by_forge_name('puppetlabs/baz').should == mod
287
+ end
288
+
289
+ it "should not find modules with same name by the wrong author" do
290
+ mod = PuppetSpec::Modules.create(
291
+ 'baz',
292
+ @first,
293
+ :metadata => {:author => 'sneakylabs'},
294
+ :environment => env
295
+ )
296
+ env.module_by_forge_name('puppetlabs/baz').should == nil
297
+ end
298
+
299
+ it "should return nil when the module can't be found" do
300
+ env.module_by_forge_name('ima/nothere').should be_nil
301
+ end
243
302
  end
244
303
 
245
- it "should create modules with the correct environment" do
246
- env.modulepath = %w{/a}
247
- Dir.expects(:entries).with("/a").returns %w{foo}
304
+ describe ".modules" do
305
+ it "should return an empty list if there are no modules" do
306
+ env.modules.should == []
307
+ end
308
+
309
+ it "should return a module named for every directory in each module path" do
310
+ %w{foo bar}.each do |mod_name|
311
+ FileUtils.mkdir_p(File.join(@first, mod_name))
312
+ end
313
+ %w{bee baz}.each do |mod_name|
314
+ FileUtils.mkdir_p(File.join(@second, mod_name))
315
+ end
316
+ env.modules.collect{|mod| mod.name}.sort.should == %w{foo bar bee baz}.sort
317
+ end
318
+
319
+ it "should remove duplicates" do
320
+ FileUtils.mkdir_p(File.join(@first, 'foo'))
321
+ FileUtils.mkdir_p(File.join(@second, 'foo'))
322
+
323
+ env.modules.collect{|mod| mod.name}.sort.should == %w{foo}
324
+ end
325
+
326
+ it "should ignore modules with invalid names" do
327
+ FileUtils.mkdir_p(File.join(@first, 'foo'))
328
+ FileUtils.mkdir_p(File.join(@first, 'foo2'))
329
+ FileUtils.mkdir_p(File.join(@first, 'foo-bar'))
330
+ FileUtils.mkdir_p(File.join(@first, 'foo_bar'))
331
+ FileUtils.mkdir_p(File.join(@first, 'foo=bar'))
332
+ FileUtils.mkdir_p(File.join(@first, 'foo bar'))
333
+
334
+ env.modules.collect{|mod| mod.name}.sort.should == %w{foo foo-bar foo2 foo_bar}
335
+ end
336
+
337
+ it "should create modules with the correct environment" do
338
+ FileUtils.mkdir_p(File.join(@first, 'foo'))
339
+
340
+ env.modules.each {|mod| mod.environment.should == env }
341
+ end
248
342
 
249
- env.modules.each {|mod| mod.environment.should == env }
250
343
  end
344
+ end
251
345
 
252
- it "should cache the module list" do
253
- env.modulepath = %w{/a}
254
- Dir.expects(:entries).once.with("/a").returns %w{foo}
346
+ it "should cache the module list" do
347
+ env.modulepath = %w{/a}
348
+ Dir.expects(:entries).once.with("/a").returns %w{foo}
255
349
 
256
- env.modules
257
- env.modules
258
- end
350
+ env.modules
351
+ env.modules
259
352
  end
260
353
  end
261
354
 
@@ -287,21 +287,16 @@ describe Puppet::Parser::Collector, "when collecting exported resources", :if =>
287
287
 
288
288
  context "with storeconfigs enabled" do
289
289
  before :each do
290
- ActiveRecord::Base.remove_connection
291
-
292
290
  dir = Pathname(tmpdir('puppet-var'))
293
291
  Puppet[:vardir] = dir.to_s
294
292
  Puppet[:dbadapter] = 'sqlite3'
295
293
  Puppet[:dblocation] = (dir + 'storeconfigs.sqlite').to_s
296
294
  Puppet[:storeconfigs] = true
297
295
  Puppet[:environment] = "production"
296
+ Puppet[:storeconfigs_backend] = "active_record"
298
297
  Puppet::Rails.init
299
298
  end
300
299
 
301
- after :each do
302
- ActiveRecord::Base.remove_connection
303
- end
304
-
305
300
  it "should return all matching resources from the current compile and mark them non-virtual and non-exported" do
306
301
  one = Puppet::Parser::Resource.new('notify', 'one',
307
302
  :virtual => true,
@@ -336,7 +331,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources", :if =>
336
331
  one.should_not be_virtual
337
332
  end
338
333
 
339
- it "should convert all found resources into parser resources" do
334
+ it "should convert all found resources into parser resources if necessary" do
340
335
  host = Puppet::Rails::Host.create!(:name => 'one.local')
341
336
  Puppet::Rails::Resource.
342
337
  create!(:host => host,
@@ -350,6 +345,19 @@ describe Puppet::Parser::Collector, "when collecting exported resources", :if =>
350
345
  result.first.title.should == 'whammo'
351
346
  end
352
347
 
348
+ it "should leave parser resources alone" do
349
+ resource = Puppet::Parser::Resource.new(:file, "/tmp/foo", :scope => @scope)
350
+ resource2 = Puppet::Parser::Resource.new(:file, "/tmp/bar", :scope => @scope)
351
+ resource.expects(:to_resource).never
352
+ resource2.expects(:to_resource).never
353
+
354
+ resources = [resource, resource2]
355
+
356
+ Puppet::Resource.indirection.stubs(:search).returns resources
357
+
358
+ @collector.evaluate.should == resources
359
+ end
360
+
353
361
  it "should override all exported collected resources if collector has an override" do
354
362
  host = Puppet::Rails::Host.create!(:name => 'one.local')
355
363
  Puppet::Rails::Resource.
@@ -408,7 +416,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources", :if =>
408
416
  @compiler.add_resource(@scope, local)
409
417
 
410
418
  expect { @collector.evaluate }.
411
- to raise_error Puppet::ParseError, /cannot override local resource/
419
+ to raise_error Puppet::ParseError, /exists with the type and title/
412
420
  end
413
421
 
414
422
  it "should ignore exported resources that match already-collected resources" do
@@ -6,38 +6,80 @@ describe "the generate function" do
6
6
  Puppet::Parser::Functions.autoloader.loadall
7
7
  end
8
8
 
9
- before :each do
10
- @scope = Puppet::Parser::Scope.new
11
- end
9
+ let(:scope) { Puppet::Parser::Scope.new }
12
10
 
13
11
  it "should exist" do
14
12
  Puppet::Parser::Functions.function("generate").should == "function_generate"
15
13
  end
16
14
 
17
- it "should accept a fully-qualified path as a command" do
18
- command = File::SEPARATOR + "command"
19
- Puppet::Util.expects(:execute).with([command]).returns("yay")
20
- lambda { @scope.function_generate([command]) }.should_not raise_error(Puppet::ParseError)
15
+ it " accept a fully-qualified path as a command" do
16
+ command = File.expand_path('/command/foo')
17
+ Dir.expects(:chdir).with(File.dirname(command)).returns("yay")
18
+ scope.function_generate([command]).should == "yay"
21
19
  end
22
20
 
23
21
  it "should not accept a relative path as a command" do
24
- command = "command"
25
- lambda { @scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
22
+ lambda { scope.function_generate(["command"]) }.should raise_error(Puppet::ParseError)
23
+ end
24
+
25
+ it "should not accept a command containing illegal characters" do
26
+ lambda { scope.function_generate([File.expand_path('/##/command')]) }.should raise_error(Puppet::ParseError)
26
27
  end
27
28
 
28
- # Really not sure how to implement this test, just sure it needs
29
- # to be implemented.
30
- it "should not accept a command containing illegal characters"
29
+ it "should not accept a command containing spaces" do
30
+ lambda { scope.function_generate([File.expand_path('/com mand')]) }.should raise_error(Puppet::ParseError)
31
+ end
31
32
 
32
33
  it "should not accept a command containing '..'" do
33
- command = File::SEPARATOR + "command#{File::SEPARATOR}..#{File::SEPARATOR}"
34
- lambda { @scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
34
+ command = File.expand_path("/command/../")
35
+ lambda { scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
35
36
  end
36
37
 
37
38
  it "should execute the generate script with the correct working directory" do
38
- command = File::SEPARATOR + "command"
39
- Dir.expects(:chdir).with(File.dirname(command)).yields
40
- Puppet::Util.expects(:execute).with([command]).returns("yay")
41
- lambda { @scope.function_generate([command]) }.should_not raise_error(Puppet::ParseError)
39
+ command = File.expand_path("/command")
40
+ Dir.expects(:chdir).with(File.dirname(command)).returns("yay")
41
+ scope.function_generate([command]).should == 'yay'
42
+ end
43
+
44
+ describe "on Windows" do
45
+ before :each do
46
+ Puppet.features.stubs(:microsoft_windows?).returns(true)
47
+ end
48
+
49
+ it "should accept lower-case drive letters" do
50
+ command = 'd:/command/foo'
51
+ Dir.expects(:chdir).with(File.dirname(command)).returns("yay")
52
+ scope.function_generate([command]).should == 'yay'
53
+ end
54
+
55
+ it "should accept upper-case drive letters" do
56
+ command = 'D:/command/foo'
57
+ Dir.expects(:chdir).with(File.dirname(command)).returns("yay")
58
+ scope.function_generate([command]).should == 'yay'
59
+ end
60
+
61
+ it "should accept forward and backslashes in the path" do
62
+ command = 'D:\command/foo\bar'
63
+ Dir.expects(:chdir).with(File.dirname(command)).returns("yay")
64
+ scope.function_generate([command]).should == 'yay'
65
+ end
66
+
67
+ it "should reject colons when not part of the drive letter" do
68
+ lambda { scope.function_generate(['C:/com:mand']) }.should raise_error(Puppet::ParseError)
69
+ end
70
+
71
+ it "should reject root drives" do
72
+ lambda { scope.function_generate(['C:/']) }.should raise_error(Puppet::ParseError)
73
+ end
74
+ end
75
+
76
+ describe "on non-Windows" do
77
+ before :each do
78
+ Puppet.features.stubs(:microsoft_windows?).returns(false)
79
+ end
80
+
81
+ it "should reject backslashes" do
82
+ lambda { scope.function_generate(['/com\\mand']) }.should raise_error(Puppet::ParseError)
83
+ end
42
84
  end
43
85
  end
@@ -200,6 +200,50 @@ describe Puppet::Parser::Resource do
200
200
  @compiler.catalog.should be_edge(foo_stage, resource)
201
201
  end
202
202
 
203
+ it "should allow edges to propagate multiple levels down the scope hierarchy" do
204
+ Puppet[:code] = <<-MANIFEST
205
+ stage { before: before => Stage[main] }
206
+
207
+ class alpha {
208
+ include beta
209
+ }
210
+ class beta {
211
+ include gamma
212
+ }
213
+ class gamma { }
214
+ class { alpha: stage => before }
215
+ MANIFEST
216
+
217
+ catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new 'anyone')
218
+
219
+ # Stringify them to make for easier lookup
220
+ edges = catalog.edges.map {|e| [e.source.ref, e.target.ref]}
221
+
222
+ edges.should include(["Stage[before]", "Class[Alpha]"])
223
+ edges.should include(["Stage[before]", "Class[Beta]"])
224
+ edges.should include(["Stage[before]", "Class[Gamma]"])
225
+ end
226
+
227
+ it "should use the specified stage even if the parent scope specifies one" do
228
+ Puppet[:code] = <<-MANIFEST
229
+ stage { before: before => Stage[main], }
230
+ stage { after: require => Stage[main], }
231
+
232
+ class alpha {
233
+ class { beta: stage => after }
234
+ }
235
+ class beta { }
236
+ class { alpha: stage => before }
237
+ MANIFEST
238
+
239
+ catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new 'anyone')
240
+
241
+ edges = catalog.edges.map {|e| [e.source.ref, e.target.ref]}
242
+
243
+ edges.should include(["Stage[before]", "Class[Alpha]"])
244
+ edges.should include(["Stage[after]", "Class[Beta]"])
245
+ end
246
+
203
247
  it "should add edges from top-level class resources to the main stage if no stage is specified", :'fails_on_ruby_1.9.2' => true do
204
248
  main = @compiler.catalog.resource(:stage, :main)
205
249
  @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '')