puppet 4.0.0-x64-mingw32 → 4.1.0-x64-mingw32

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 (219) hide show
  1. checksums.yaml +4 -4
  2. data/ext/build_defaults.yaml +8 -35
  3. data/ext/debian/puppet.default +0 -5
  4. data/ext/debian/puppet.init +1 -15
  5. data/lib/hiera/puppet_function.rb +15 -4
  6. data/lib/puppet/application/agent.rb +5 -0
  7. data/lib/puppet/application/apply.rb +23 -2
  8. data/lib/puppet/application/device.rb +8 -3
  9. data/lib/puppet/application/master.rb +16 -5
  10. data/lib/puppet/configurer.rb +7 -5
  11. data/lib/puppet/defaults.rb +18 -0
  12. data/lib/puppet/environments.rb +1 -1
  13. data/lib/puppet/error.rb +27 -1
  14. data/lib/puppet/file_serving/metadata.rb +13 -8
  15. data/lib/puppet/file_serving/terminus_helper.rb +7 -8
  16. data/lib/puppet/file_system.rb +13 -0
  17. data/lib/puppet/file_system/file_impl.rb +4 -0
  18. data/lib/puppet/file_system/memory_impl.rb +4 -0
  19. data/lib/puppet/file_system/windows.rb +8 -0
  20. data/lib/puppet/functions.rb +33 -3
  21. data/lib/puppet/functions/defined.rb +130 -0
  22. data/lib/puppet/functions/regsubst.rb +1 -1
  23. data/lib/puppet/functions/split.rb +1 -1
  24. data/lib/puppet/indirector/catalog/compiler.rb +1 -1
  25. data/lib/puppet/indirector/facts/facter.rb +11 -0
  26. data/lib/puppet/loaders.rb +1 -0
  27. data/lib/puppet/node.rb +17 -1
  28. data/lib/puppet/node/environment.rb +4 -0
  29. data/lib/puppet/parser/ast/pops_bridge.rb +4 -0
  30. data/lib/puppet/parser/compiler.rb +9 -0
  31. data/lib/puppet/parser/functions/defined.rb +25 -1
  32. data/lib/puppet/parser/functions/file.rb +3 -1
  33. data/lib/puppet/parser/scope.rb +11 -2
  34. data/lib/puppet/parser/templatewrapper.rb +2 -1
  35. data/lib/puppet/pops.rb +4 -0
  36. data/lib/puppet/pops/evaluator/access_operator.rb +25 -5
  37. data/lib/puppet/pops/evaluator/closure.rb +28 -2
  38. data/lib/puppet/pops/evaluator/collector_transformer.rb +1 -11
  39. data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +4 -0
  40. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +4 -0
  41. data/lib/puppet/pops/evaluator/compare_operator.rb +43 -0
  42. data/lib/puppet/pops/evaluator/epp_evaluator.rb +7 -2
  43. data/lib/puppet/pops/evaluator/evaluator_impl.rb +48 -14
  44. data/lib/puppet/pops/evaluator/runtime3_support.rb +10 -5
  45. data/lib/puppet/pops/functions/dispatch.rb +6 -1
  46. data/lib/puppet/pops/functions/dispatcher.rb +7 -1
  47. data/lib/puppet/pops/issue_reporter.rb +42 -16
  48. data/lib/puppet/pops/issues.rb +116 -2
  49. data/lib/puppet/pops/loader/loader.rb +11 -0
  50. data/lib/puppet/pops/loader/loader_paths.rb +67 -6
  51. data/lib/puppet/pops/loader/module_loaders.rb +19 -8
  52. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +78 -0
  53. data/lib/puppet/pops/loaders.rb +6 -4
  54. data/lib/puppet/pops/migration/migration_checker.rb +54 -0
  55. data/lib/puppet/pops/model/factory.rb +5 -1
  56. data/lib/puppet/pops/model/model_label_provider.rb +2 -0
  57. data/lib/puppet/pops/model/model_meta.rb +5 -1
  58. data/lib/puppet/pops/parser/egrammar.ra +9 -10
  59. data/lib/puppet/pops/parser/eparser.rb +1061 -1047
  60. data/lib/puppet/pops/parser/epp_support.rb +18 -9
  61. data/lib/puppet/pops/parser/evaluating_parser.rb +7 -1
  62. data/lib/puppet/pops/parser/heredoc_support.rb +12 -11
  63. data/lib/puppet/pops/parser/interpolation_support.rb +7 -1
  64. data/lib/puppet/pops/parser/lexer2.rb +29 -12
  65. data/lib/puppet/pops/parser/lexer_support.rb +52 -23
  66. data/lib/puppet/pops/parser/parser_support.rb +11 -14
  67. data/lib/puppet/pops/parser/slurp_support.rb +22 -6
  68. data/lib/puppet/pops/types/type_calculator.rb +156 -55
  69. data/lib/puppet/pops/types/type_factory.rb +66 -13
  70. data/lib/puppet/pops/types/type_parser.rb +22 -13
  71. data/lib/puppet/pops/types/types.rb +23 -4
  72. data/lib/puppet/pops/types/types_meta.rb +13 -2
  73. data/lib/puppet/pops/validation.rb +25 -2
  74. data/lib/puppet/pops/validation/checker4_0.rb +63 -31
  75. data/lib/puppet/provider/group/windows_adsi.rb +8 -4
  76. data/lib/puppet/provider/mount/parsed.rb +145 -2
  77. data/lib/puppet/provider/package/apt.rb +1 -1
  78. data/lib/puppet/provider/package/pip.rb +11 -2
  79. data/lib/puppet/provider/package/pkgng.rb +134 -0
  80. data/lib/puppet/provider/package/portage.rb +1 -1
  81. data/lib/puppet/provider/package/ports.rb +0 -3
  82. data/lib/puppet/provider/package/windows/exe_package.rb +0 -1
  83. data/lib/puppet/provider/package/windows/msi_package.rb +0 -1
  84. data/lib/puppet/provider/package/zypper.rb +50 -15
  85. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +32 -7
  86. data/lib/puppet/provider/service/debian.rb +1 -1
  87. data/lib/puppet/provider/service/init.rb +7 -0
  88. data/lib/puppet/provider/user/openbsd.rb +1 -0
  89. data/lib/puppet/provider/user/windows_adsi.rb +45 -2
  90. data/lib/puppet/reference/indirection.rb +1 -1
  91. data/lib/puppet/resource.rb +1 -1
  92. data/lib/puppet/resource/catalog.rb +0 -4
  93. data/lib/puppet/settings.rb +19 -0
  94. data/lib/puppet/type/file.rb +1 -0
  95. data/lib/puppet/type/file/ensure.rb +1 -1
  96. data/lib/puppet/type/mount.rb +9 -1
  97. data/lib/puppet/type/scheduled_task.rb +13 -0
  98. data/lib/puppet/type/tidy.rb +3 -1
  99. data/lib/puppet/type/user.rb +32 -0
  100. data/lib/puppet/type/yumrepo.rb +5 -5
  101. data/lib/puppet/util/log.rb +50 -8
  102. data/lib/puppet/util/log/destinations.rb +23 -2
  103. data/lib/puppet/util/logging.rb +37 -1
  104. data/lib/puppet/util/run_mode.rb +1 -14
  105. data/lib/puppet/util/windows/adsi.rb +130 -58
  106. data/lib/puppet/version.rb +1 -1
  107. data/man/man5/puppet.conf.5 +48 -6
  108. data/man/man8/extlookup2hiera.8 +1 -1
  109. data/man/man8/puppet-agent.8 +4 -1
  110. data/man/man8/puppet-apply.8 +4 -1
  111. data/man/man8/puppet-ca.8 +1 -1
  112. data/man/man8/puppet-catalog.8 +1 -1
  113. data/man/man8/puppet-cert.8 +1 -1
  114. data/man/man8/puppet-certificate.8 +1 -1
  115. data/man/man8/puppet-certificate_request.8 +1 -1
  116. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  117. data/man/man8/puppet-config.8 +1 -1
  118. data/man/man8/puppet-describe.8 +1 -1
  119. data/man/man8/puppet-device.8 +6 -3
  120. data/man/man8/puppet-doc.8 +1 -1
  121. data/man/man8/puppet-epp.8 +1 -1
  122. data/man/man8/puppet-facts.8 +1 -1
  123. data/man/man8/puppet-file.8 +1 -1
  124. data/man/man8/puppet-filebucket.8 +1 -1
  125. data/man/man8/puppet-help.8 +1 -1
  126. data/man/man8/puppet-inspect.8 +1 -1
  127. data/man/man8/puppet-key.8 +1 -1
  128. data/man/man8/puppet-man.8 +1 -1
  129. data/man/man8/puppet-master.8 +4 -1
  130. data/man/man8/puppet-module.8 +1 -1
  131. data/man/man8/puppet-node.8 +1 -1
  132. data/man/man8/puppet-parser.8 +1 -1
  133. data/man/man8/puppet-plugin.8 +1 -1
  134. data/man/man8/puppet-report.8 +1 -1
  135. data/man/man8/puppet-resource.8 +1 -1
  136. data/man/man8/puppet-resource_type.8 +1 -1
  137. data/man/man8/puppet-status.8 +1 -1
  138. data/man/man8/puppet.8 +1 -1
  139. data/spec/fixtures/unit/data_providers/environments/production/lib/puppet/functions/environment/data.rb +3 -1
  140. data/spec/fixtures/unit/data_providers/environments/production/modules/xyz/functions/data.pp +6 -0
  141. data/spec/fixtures/unit/data_providers/environments/production/modules/xyz/lib/puppet/bindings/xyz/default.rb +9 -0
  142. data/spec/fixtures/unit/data_providers/environments/production/modules/xyz/manifests/init.pp +9 -0
  143. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/user/functions/puppetcalled.pp +3 -0
  144. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/user/functions/puppetcaller.pp +3 -0
  145. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/user/functions/puppetcaller4.pp +3 -0
  146. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/user/lib/puppet/functions/user/callingpuppet.rb +5 -0
  147. data/spec/fixtures/unit/pops/loaders/loaders/module_no_lib/modules/modulea/functions/hello.pp +3 -0
  148. data/spec/fixtures/unit/pops/loaders/loaders/module_no_lib/modules/modulea/manifests/init.pp +3 -0
  149. data/spec/fixtures/unit/pops/loaders/loaders/module_no_lib/modules/modulea/metadata.json +10 -0
  150. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/functions/hello.pp +3 -0
  151. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/functions/subspace/hello.pp +3 -0
  152. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/metadata.json +1 -10
  153. data/spec/fixtures/unit/provider/mount/parsed/aix.filesystems +93 -85
  154. data/spec/fixtures/unit/provider/mount/parsed/aix.mount +11 -7
  155. data/spec/fixtures/unit/provider/package/pkgng/pkg.info +8 -0
  156. data/spec/fixtures/unit/provider/package/pkgng/pkg.query +1 -0
  157. data/spec/fixtures/unit/provider/package/pkgng/pkg.query_absent +1 -0
  158. data/spec/fixtures/unit/provider/package/pkgng/pkg.version +3 -0
  159. data/spec/fixtures/unit/provider/package/zypper/zypper-list-updates-empty.out +3 -0
  160. data/spec/integration/application/apply_spec.rb +49 -0
  161. data/spec/integration/faces/plugin_spec.rb +0 -4
  162. data/spec/integration/indirector/facts/facter_spec.rb +59 -0
  163. data/spec/integration/parser/compiler_spec.rb +850 -0
  164. data/spec/integration/parser/resource_expressions_spec.rb +3 -0
  165. data/spec/integration/parser/scope_spec.rb +26 -5
  166. data/spec/integration/transaction_spec.rb +1 -1
  167. data/spec/integration/type/file_spec.rb +318 -41
  168. data/spec/integration/util/windows/security_spec.rb +14 -5
  169. data/spec/lib/matchers/resource.rb +22 -1
  170. data/spec/lib/puppet_spec/matchers.rb +6 -4
  171. data/spec/unit/application/master_spec.rb +33 -7
  172. data/spec/unit/data_providers/function_data_provider_spec.rb +10 -1
  173. data/spec/unit/file_serving/metadata_spec.rb +1 -1
  174. data/spec/unit/file_serving/terminus_helper_spec.rb +2 -3
  175. data/spec/unit/file_system_spec.rb +38 -0
  176. data/spec/unit/functions/defined_spec.rb +289 -0
  177. data/spec/unit/functions/hiera_spec.rb +8 -6
  178. data/spec/unit/functions/regsubst_spec.rb +4 -0
  179. data/spec/unit/functions/split_spec.rb +8 -0
  180. data/spec/unit/functions4_spec.rb +97 -2
  181. data/spec/unit/indirector/facts/facter_spec.rb +7 -0
  182. data/spec/unit/node_spec.rb +6 -0
  183. data/spec/unit/parser/functions/file_spec.rb +7 -1
  184. data/spec/unit/parser/functions/template_spec.rb +1 -1
  185. data/spec/unit/parser/scope_spec.rb +2 -2
  186. data/spec/unit/parser/templatewrapper_spec.rb +1 -1
  187. data/spec/unit/pops/evaluator/access_ops_spec.rb +19 -0
  188. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +84 -18
  189. data/spec/unit/pops/evaluator/variables_spec.rb +1 -1
  190. data/spec/unit/pops/issues_spec.rb +16 -16
  191. data/spec/unit/pops/loaders/loaders_spec.rb +106 -48
  192. data/spec/unit/pops/migration_spec.rb +53 -0
  193. data/spec/unit/pops/parser/lexer2_spec.rb +142 -1
  194. data/spec/unit/pops/parser/parse_heredoc_spec.rb +26 -0
  195. data/spec/unit/pops/types/type_calculator_spec.rb +205 -12
  196. data/spec/unit/pops/validation_spec.rb +66 -0
  197. data/spec/unit/pops/validator/validator_spec.rb +1 -1
  198. data/spec/unit/provider/group/windows_adsi_spec.rb +57 -9
  199. data/spec/unit/provider/mount/parsed_spec.rb +31 -5
  200. data/spec/unit/provider/package/apt_spec.rb +5 -0
  201. data/spec/unit/provider/package/pip_spec.rb +9 -0
  202. data/spec/unit/provider/package/pkgng_spec.rb +172 -0
  203. data/spec/unit/provider/package/windows/exe_package_spec.rb +0 -1
  204. data/spec/unit/provider/package/windows/msi_package_spec.rb +0 -1
  205. data/spec/unit/provider/package/zypper_spec.rb +50 -19
  206. data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +312 -70
  207. data/spec/unit/provider/service/base_spec.rb +38 -27
  208. data/spec/unit/provider/service/debian_spec.rb +8 -0
  209. data/spec/unit/provider/service/freebsd_spec.rb +1 -0
  210. data/spec/unit/provider/service/gentoo_spec.rb +1 -0
  211. data/spec/unit/provider/service/init_spec.rb +18 -0
  212. data/spec/unit/provider/service/openbsd_spec.rb +1 -0
  213. data/spec/unit/provider/service/redhat_spec.rb +1 -0
  214. data/spec/unit/provider/user/windows_adsi_spec.rb +134 -5
  215. data/spec/unit/settings_spec.rb +11 -0
  216. data/spec/unit/util/log_spec.rb +113 -0
  217. data/spec/unit/util/windows/adsi_spec.rb +135 -41
  218. data/spec/unit/util/windows/sid_spec.rb +0 -10
  219. metadata +48 -2
@@ -15,7 +15,6 @@ describe "Puppet::Util::Windows::Security", :if => Puppet.features.microsoft_win
15
15
  @sids = {
16
16
  :current_user => Puppet::Util::Windows::SID.name_to_sid(Puppet::Util::Windows::ADSI::User.current_user_name),
17
17
  :system => Win32::Security::SID::LocalSystem,
18
- :admin => Puppet::Util::Windows::SID.name_to_sid("Administrator"),
19
18
  :administrators => Win32::Security::SID::BuiltinAdministrators,
20
19
  :guest => Puppet::Util::Windows::SID.name_to_sid("Guest"),
21
20
  :users => Win32::Security::SID::BuiltinUsers,
@@ -387,9 +386,14 @@ describe "Puppet::Util::Windows::Security", :if => Puppet.features.microsoft_win
387
386
  end
388
387
 
389
388
  describe "#owner=" do
389
+ it "should accept the guest sid" do
390
+ winsec.set_owner(sids[:guest], path)
391
+ expect(winsec.get_owner(path)).to eq(sids[:guest])
392
+ end
393
+
390
394
  it "should accept a user sid" do
391
- winsec.set_owner(sids[:admin], path)
392
- expect(winsec.get_owner(path)).to eq(sids[:admin])
395
+ winsec.set_owner(sids[:current_user], path)
396
+ expect(winsec.get_owner(path)).to eq(sids[:current_user])
393
397
  end
394
398
 
395
399
  it "should accept a group sid" do
@@ -407,14 +411,19 @@ describe "Puppet::Util::Windows::Security", :if => Puppet.features.microsoft_win
407
411
  end
408
412
 
409
413
  describe "#group=" do
414
+ it "should accept the test group" do
415
+ winsec.set_group(sids[:guest], path)
416
+ expect(winsec.get_group(path)).to eq(sids[:guest])
417
+ end
418
+
410
419
  it "should accept a group sid" do
411
420
  winsec.set_group(sids[:power_users], path)
412
421
  expect(winsec.get_group(path)).to eq(sids[:power_users])
413
422
  end
414
423
 
415
424
  it "should accept a user sid" do
416
- winsec.set_group(sids[:admin], path)
417
- expect(winsec.get_group(path)).to eq(sids[:admin])
425
+ winsec.set_group(sids[:current_user], path)
426
+ expect(winsec.get_group(path)).to eq(sids[:current_user])
418
427
  end
419
428
 
420
429
  it "should combine owner and group rights when they are the same sid" do
@@ -36,7 +36,7 @@ module Matchers; module Resource
36
36
  if resource = actual_catalog.resource(expected_resource)
37
37
  resource_match(expected_resource, resource)
38
38
  else
39
- @mismatch = "expected #{@actual.to_dot} to include #{@expected[0]}"
39
+ @mismatch = "expected #{@actual.to_dot} to include #{expected_resource}"
40
40
  false
41
41
  end
42
42
  end
@@ -50,4 +50,25 @@ module Matchers; module Resource
50
50
  @mismatch
51
51
  end
52
52
  end
53
+
54
+
55
+ matcher :be_resource do |expected_resource|
56
+ def resource_match(expected_resource, actual_resource)
57
+ if actual_resource.ref == expected_resource
58
+ true
59
+ else
60
+ @mismatch = "expected #{expected_resource} but was #{actual_resource.ref}"
61
+ false
62
+ end
63
+ end
64
+
65
+ match do |actual_resource|
66
+ resource_match(expected_resource, actual_resource)
67
+ end
68
+
69
+ def failure_message
70
+ @mismatch
71
+ end
72
+ end
73
+
53
74
  end; end
@@ -58,10 +58,10 @@ end
58
58
  RSpec::Matchers.define :have_printed do |expected|
59
59
 
60
60
  case expected
61
- when String, Regexp
62
- expected = expected
63
- else
64
- expected = expected.to_s
61
+ when String, Regexp, Proc
62
+ expected = expected
63
+ else
64
+ expected = expected.to_s
65
65
  end
66
66
 
67
67
  chain :and_exit_with do |code|
@@ -79,6 +79,8 @@ RSpec::Matchers.define :have_printed do |expected|
79
79
  actual.include?(expected)
80
80
  when Regexp
81
81
  expected.match(actual)
82
+ when Proc
83
+ expected.call(actual)
82
84
  else
83
85
  raise ArgumentError, "No idea how to match a #{actual.class.name}"
84
86
  end
@@ -314,10 +314,32 @@ describe Puppet::Application::Master, :unless => Puppet.features.microsoft_windo
314
314
  @master.main
315
315
  end
316
316
 
317
- it "should drop privileges if running as root" do
318
- Puppet.features.stubs(:root?).returns true
317
+ def a_user_type_for(username)
318
+ user = mock 'user'
319
+ Puppet::Type.type(:user).expects(:new).with { |args| args[:name] == username }.returns user
320
+ user
321
+ end
322
+
323
+ context "user privileges" do
324
+ it "should drop privileges if running as root and the puppet user exists" do
325
+ Puppet.features.stubs(:root?).returns true
326
+ a_user_type_for("puppet").expects(:exists?).returns true
327
+
328
+ Puppet::Util.expects(:chuser)
329
+
330
+ @master.main
331
+ end
332
+
333
+ it "should exit and log an error if running as root and the puppet user does not exist" do
334
+ Puppet.features.stubs(:root?).returns true
335
+ a_user_type_for("puppet").expects(:exists?).returns false
336
+
337
+ expect { @master.main }.to raise_error(Puppet::Error, /Could not change user to puppet\. User does not exist and is required to continue\./)
338
+ end
339
+ end
319
340
 
320
- Puppet::Util.expects(:chuser)
341
+ it "should log a deprecation notice when running a WEBrick server" do
342
+ Puppet.expects(:deprecation_warning).with("The WEBrick Puppet master server is deprecated and will be removed in a future release. Please use Puppet Server instead. See http://links.puppetlabs.com/deprecate-rack-webrick-servers for more information.")
321
343
 
322
344
  @master.main
323
345
  end
@@ -340,22 +362,26 @@ describe Puppet::Application::Master, :unless => Puppet.features.microsoft_windo
340
362
  before do
341
363
  require 'puppet/network/http/rack'
342
364
  Puppet::Network::HTTP::Rack.stubs(:new).returns(@app)
343
- end
344
365
 
345
- it "it should not start a daemon" do
346
366
  @master.options.stubs(:[]).with(:rack).returns(:true)
367
+ end
347
368
 
369
+ it "it should not start a daemon" do
348
370
  @daemon.expects(:start).never
349
371
 
350
372
  @master.main
351
373
  end
352
374
 
353
375
  it "it should return the app" do
354
- @master.options.stubs(:[]).with(:rack).returns(:true)
355
-
356
376
  app = @master.main
357
377
  expect(app).to equal(@app)
358
378
  end
379
+
380
+ it "should log a deprecation notice" do
381
+ Puppet.expects(:deprecation_warning).with("The Rack Puppet master server is deprecated and will be removed in a future release. Please use Puppet Server instead. See http://links.puppetlabs.com/deprecate-rack-webrick-servers for more information.")
382
+
383
+ @master.main
384
+ end
359
385
  end
360
386
  end
361
387
  end
@@ -38,7 +38,7 @@ describe "when using function data provider" do
38
38
  # The result should be that the data set in the environment wins over those set in the
39
39
  # module.
40
40
  #
41
- it 'it gets data from module and environment functions and combines them with env having higher precedence' do
41
+ it 'gets data from module and environment functions and combines them with env having higher precedence' do
42
42
  Puppet[:code] = 'include abc'
43
43
  node = Puppet::Node.new("testnode", :facts => Puppet::Node::Facts.new("facts", {}), :environment => 'production')
44
44
  compiler = Puppet::Parser::Compiler.new(node)
@@ -47,6 +47,15 @@ describe "when using function data provider" do
47
47
  expect(resources_in(catalog)).to include(*resources_created_in_fixture)
48
48
  end
49
49
 
50
+ it 'gets data from module having a puppet function delivering module data' do
51
+ Puppet[:code] = 'include xyz'
52
+ node = Puppet::Node.new("testnode", :facts => Puppet::Node::Facts.new("facts", {}), :environment => 'production')
53
+ compiler = Puppet::Parser::Compiler.new(node)
54
+ catalog = compiler.compile()
55
+ resources_created_in_fixture = ["Notify[env_test1]", "Notify[env_test2]", "Notify[module_test3]"]
56
+ expect(resources_in(catalog)).to include(*resources_created_in_fixture)
57
+ end
58
+
50
59
  it 'raises an error if the environment data function does not return a hash' do
51
60
  Puppet[:code] = 'include abc'
52
61
  # find the loaders to patch with faulty function
@@ -179,7 +179,7 @@ describe Puppet::FileServing::Metadata, :uses_checksums => true do
179
179
 
180
180
  stat = Puppet::FileSystem.stat(path)
181
181
 
182
- win_stat = Puppet::FileServing::Metadata::WindowsStat.new(stat, path)
182
+ win_stat = Puppet::FileServing::Metadata::WindowsStat.new(stat, path, :ignore)
183
183
 
184
184
  expect(win_stat.owner).to eq('S-1-5-32-544')
185
185
  expect(win_stat.group).to eq('S-1-0-0')
@@ -26,12 +26,11 @@ describe Puppet::FileServing::TerminusHelper do
26
26
 
27
27
  it "should pass through links, checksum_type, and source_permissions" do
28
28
  file = stub 'file', :checksum_type= => nil, :links= => nil, :collect => nil
29
- [[:checksum_type, :sha256], [:links, true]].each {|k, v|
29
+ [[:checksum_type, :sha256], [:links, true], [:source_permissions, :use]].each {|k, v|
30
30
  file.expects(k.to_s+'=').with(v)
31
31
  @request.options[k] = v
32
32
  }
33
- @request.options[:source_permissions] = :yes
34
- file.expects(:collect).with(:yes)
33
+ file.expects(:collect)
35
34
  @model.expects(:new).with("/my/file", {:relative_path => :file}).returns(file)
36
35
  @helper.path2instance(@request, "/my/file", {:relative_path => :file})
37
36
  end
@@ -5,6 +5,18 @@ require 'puppet/util/platform'
5
5
  describe "Puppet::FileSystem" do
6
6
  include PuppetSpec::Files
7
7
 
8
+ def with_file_content(content)
9
+ path = tmpfile('file-system')
10
+ file = File.new(path, 'wb')
11
+ file.sync = true
12
+ file.print content
13
+
14
+ yield path
15
+
16
+ ensure
17
+ file.close
18
+ end
19
+
8
20
  context "#exclusive_open" do
9
21
  it "opens ands allows updating of an existing file" do
10
22
  file = file_containing("file_to_update", "the contents")
@@ -96,6 +108,32 @@ describe "Puppet::FileSystem" do
96
108
  end
97
109
  end
98
110
 
111
+ context "read_preserve_line_endings" do
112
+ it "should read a file with line feed" do
113
+ with_file_content("file content \n") do |file|
114
+ expect(Puppet::FileSystem.read_preserve_line_endings(file)).to eq("file content \n")
115
+ end
116
+ end
117
+
118
+ it "should read a file with carriage return line feed" do
119
+ with_file_content("file content \r\n") do |file|
120
+ expect(Puppet::FileSystem.read_preserve_line_endings(file)).to eq("file content \r\n")
121
+ end
122
+ end
123
+
124
+ it "should read a mixed file using only the first line newline when lf" do
125
+ with_file_content("file content \nsecond line \r\n") do |file|
126
+ expect(Puppet::FileSystem.read_preserve_line_endings(file)).to eq("file content \nsecond line \r\n")
127
+ end
128
+ end
129
+
130
+ it "should read a mixed file using only the first line newline when crlf" do
131
+ with_file_content("file content \r\nsecond line \n") do |file|
132
+ expect(Puppet::FileSystem.read_preserve_line_endings(file)).to eq("file content \r\nsecond line \n")
133
+ end
134
+ end
135
+ end
136
+
99
137
  describe "symlink",
100
138
  :if => ! Puppet.features.manages_symlinks? &&
101
139
  Puppet.features.microsoft_windows? do
@@ -0,0 +1,289 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/pops'
4
+ require 'puppet/loaders'
5
+
6
+ describe "the 'defined' function" do
7
+ after(:all) { Puppet::Pops::Loaders.clear }
8
+
9
+ # This loads the function once and makes it easy to call it
10
+ # It does not matter that it is not bound to the env used later since the function
11
+ # looks up everything via the scope that is given to it.
12
+ # The individual tests needs to have a fresh env/catalog set up
13
+ #
14
+ let(:loaders) { Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, [])) }
15
+ let(:func) { loaders.puppet_system_loader.load(:function, 'defined') }
16
+
17
+ before :each do
18
+ # A fresh environment is needed for each test since tests creates types and resources
19
+ environment = Puppet::Node::Environment.create(:testing, [])
20
+ @node = Puppet::Node.new('yaynode', :environment => environment)
21
+ @known_resource_types = environment.known_resource_types
22
+ @compiler = Puppet::Parser::Compiler.new(@node)
23
+ @scope = Puppet::Parser::Scope.new(@compiler)
24
+ end
25
+
26
+ def newclass(name)
27
+ @known_resource_types.add Puppet::Resource::Type.new(:hostclass, name)
28
+ end
29
+
30
+ def newdefine(name)
31
+ @known_resource_types.add Puppet::Resource::Type.new(:definition, name)
32
+ end
33
+
34
+ def newresource(type, title)
35
+ resource = Puppet::Resource.new(type, title)
36
+ @compiler.add_resource(@scope, resource)
37
+ resource
38
+ end
39
+
40
+ #--- CLASS
41
+ #
42
+ context 'can determine if a class' do
43
+ context 'is defined' do
44
+
45
+ it 'by using the class name in string form' do
46
+ newclass 'yayness'
47
+ expect(func.call(@scope, 'yayness')).to be_truthy
48
+ end
49
+
50
+ it 'by using a Type[Class[name]] type reference' do
51
+ name = 'yayness'
52
+ newclass name
53
+ class_type = Puppet::Pops::Types::TypeFactory.host_class(name)
54
+ type_type = Puppet::Pops::Types::TypeFactory.type_type(class_type)
55
+ expect(func.call(@scope, type_type)).to be_truthy
56
+ end
57
+ end
58
+
59
+ context 'is not defined' do
60
+ it 'by using the class name in string form' do
61
+ expect(func.call(@scope, 'yayness')).to be_falsey
62
+ end
63
+
64
+ it 'even if there is a define, by using a Type[Class[name]] type reference' do
65
+ name = 'yayness'
66
+ newdefine name
67
+ class_type = Puppet::Pops::Types::TypeFactory.host_class(name)
68
+ type_type = Puppet::Pops::Types::TypeFactory.type_type(class_type)
69
+ expect(func.call(@scope, type_type)).to be_falsey
70
+ end
71
+ end
72
+
73
+ context 'is defined and realized' do
74
+ it 'by using a Class[name] reference' do
75
+ name = 'cowabunga'
76
+ newclass name
77
+ newresource(:class, name)
78
+ class_type = Puppet::Pops::Types::TypeFactory.host_class(name)
79
+ expect(func.call(@scope, class_type)).to be_truthy
80
+ end
81
+ end
82
+
83
+ context 'is not realized' do
84
+ it '(although defined) by using a Class[name] reference' do
85
+ name = 'cowabunga'
86
+ newclass name
87
+ class_type = Puppet::Pops::Types::TypeFactory.host_class(name)
88
+ expect(func.call(@scope, class_type)).to be_falsey
89
+ end
90
+
91
+ it '(and not defined) by using a Class[name] reference' do
92
+ name = 'cowabunga'
93
+ class_type = Puppet::Pops::Types::TypeFactory.host_class(name)
94
+ expect(func.call(@scope, class_type)).to be_falsey
95
+ end
96
+ end
97
+ end
98
+
99
+ #---RESOURCE TYPE
100
+ #
101
+ context 'can determine if a resource type' do
102
+ context 'is defined' do
103
+
104
+ it 'by using the type name (of a built in type) in string form' do
105
+ expect(func.call(@scope, 'file')).to be_truthy
106
+ end
107
+
108
+ it 'by using the type name (of a resource type) in string form' do
109
+ newdefine 'yayness'
110
+ expect(func.call(@scope, 'yayness')).to be_truthy
111
+ end
112
+
113
+ it 'by using a File type reference (built in type)' do
114
+ resource_type = Puppet::Pops::Types::TypeFactory.resource('file')
115
+ type_type = Puppet::Pops::Types::TypeFactory.type_type(resource_type)
116
+ expect(func.call(@scope, type_type)).to be_truthy
117
+ end
118
+
119
+ it 'by using a Type[File] type reference' do
120
+ resource_type = Puppet::Pops::Types::TypeFactory.resource('file')
121
+ type_type = Puppet::Pops::Types::TypeFactory.type_type(resource_type)
122
+ expect(func.call(@scope, type_type)).to be_truthy
123
+ end
124
+
125
+ it 'by using a Resource[T] type reference (defined type)' do
126
+ name = 'yayness'
127
+ newdefine name
128
+ resource_type = Puppet::Pops::Types::TypeFactory.resource(name)
129
+ expect(func.call(@scope, resource_type)).to be_truthy
130
+ end
131
+
132
+ it 'by using a Type[Resource[T]] type reference (defined type)' do
133
+ name = 'yayness'
134
+ newdefine name
135
+ resource_type = Puppet::Pops::Types::TypeFactory.resource(name)
136
+ type_type = Puppet::Pops::Types::TypeFactory.type_type(resource_type)
137
+ expect(func.call(@scope, type_type)).to be_truthy
138
+ end
139
+ end
140
+
141
+ context 'is not defined' do
142
+ it 'by using the resource name in string form' do
143
+ expect(func.call(@scope, 'notatype')).to be_falsey
144
+ end
145
+
146
+ it 'even if there is a class with the same name, by using a Type[Resource[T]] type reference' do
147
+ name = 'yayness'
148
+ newclass name
149
+ resource_type = Puppet::Pops::Types::TypeFactory.resource(name)
150
+ type_type = Puppet::Pops::Types::TypeFactory.type_type(resource_type)
151
+ expect(func.call(@scope, type_type)).to be_falsey
152
+ end
153
+ end
154
+
155
+ context 'is defined and instance realized' do
156
+ it 'by using a Resource[T, title] reference for a built in type' do
157
+ type_name = 'file'
158
+ title = '/tmp/myfile'
159
+ newdefine type_name
160
+ newresource(type_name, title)
161
+ class_type = Puppet::Pops::Types::TypeFactory.resource(type_name, title)
162
+ expect(func.call(@scope, class_type)).to be_truthy
163
+ end
164
+
165
+ it 'by using a Resource[T, title] reference for a defined type' do
166
+ type_name = 'meme'
167
+ title = 'cowabunga'
168
+ newdefine type_name
169
+ newresource(type_name, title)
170
+ class_type = Puppet::Pops::Types::TypeFactory.resource(type_name, title)
171
+ expect(func.call(@scope, class_type)).to be_truthy
172
+ end
173
+ end
174
+
175
+ context 'is not realized' do
176
+ it '(although defined) by using a Resource[T, title] reference or Type[Resource[T, title]] reference' do
177
+ type_name = 'meme'
178
+ title = 'cowabunga'
179
+ newdefine type_name
180
+ resource_type = Puppet::Pops::Types::TypeFactory.resource(type_name, title)
181
+ expect(func.call(@scope, resource_type)).to be_falsey
182
+
183
+ type_type = Puppet::Pops::Types::TypeFactory.type_type(resource_type)
184
+ expect(func.call(@scope, type_type)).to be_falsey
185
+ end
186
+
187
+ it '(and not defined) by using a Resource[T, title] reference or Type[Resource[T, title]] reference' do
188
+ type_name = 'meme'
189
+ title = 'cowabunga'
190
+ resource_type = Puppet::Pops::Types::TypeFactory.resource(type_name, title)
191
+ expect(func.call(@scope, resource_type)).to be_falsey
192
+
193
+ type_type = Puppet::Pops::Types::TypeFactory.type_type(resource_type)
194
+ expect(func.call(@scope, type_type)).to be_falsey
195
+ end
196
+ end
197
+ end
198
+
199
+ #---VARIABLES
200
+ #
201
+ context 'can determine if a variable' do
202
+ context 'is defined' do
203
+ it 'by giving the variable in string form' do
204
+ @scope['x'] = 'something'
205
+ expect(func.call(@scope, '$x')).to be_truthy
206
+ end
207
+
208
+ it 'by giving a :: prefixed variable in string form' do
209
+ @compiler.topscope['x'] = 'something'
210
+ expect(func.call(@scope, '$::x')).to be_truthy
211
+ end
212
+
213
+ it 'by giving a numeric variable in string form (when there is a match scope)' do
214
+ # with no match scope, there are no numeric variables defined
215
+ expect(func.call(@scope, '$0')).to be_falsey
216
+ expect(func.call(@scope, '$42')).to be_falsey
217
+ pattern = Regexp.new('.*')
218
+ @scope.new_match_scope(pattern.match('anything'))
219
+
220
+ # with a match scope, all numeric variables are set (the match defines if they have a value or not, but they are defined)
221
+ # even if their value is undef.
222
+ expect(func.call(@scope, '$0')).to be_truthy
223
+ expect(func.call(@scope, '$42')).to be_truthy
224
+ end
225
+ end
226
+
227
+ context 'is undefined' do
228
+ it 'by giving a :: prefixed or regular variable in string form' do
229
+ expect(func.call(@scope, '$x')).to be_falsey
230
+ expect(func.call(@scope, '$::x')).to be_falsey
231
+ end
232
+ end
233
+ end
234
+
235
+ context 'has any? semantics when given multiple arguments' do
236
+ it 'and one of the names is a defined user defined type' do
237
+ newdefine 'yayness'
238
+ expect(func.call(@scope, 'meh', 'yayness', 'booness')).to be_truthy
239
+ end
240
+
241
+ it 'and one of the names is a built type' do
242
+ expect(func.call(@scope, 'meh', 'file', 'booness')).to be_truthy
243
+ end
244
+
245
+ it 'and one of the names is a defined class' do
246
+ newclass 'yayness'
247
+ expect(func.call(@scope, 'meh', 'yayness', 'booness')).to be_truthy
248
+ end
249
+
250
+ it 'is true when at least one variable exists in scope' do
251
+ @scope['x'] = 'something'
252
+ expect(func.call(@scope, '$y', '$x', '$z')).to be_truthy
253
+ end
254
+
255
+ it 'is false when none of the names are defined' do
256
+ expect(func.call(@scope, 'meh', 'yayness', 'booness')).to be_falsey
257
+ end
258
+ end
259
+
260
+ it 'raises an argument error when asking if Resource type is defined' do
261
+ resource_type = Puppet::Pops::Types::TypeFactory.resource
262
+ expect { func.call(@scope, resource_type)}.to raise_error(ArgumentError, /reference to all.*type/)
263
+ end
264
+
265
+ it 'raises an argument error if you ask if Class is defined' do
266
+ class_type = Puppet::Pops::Types::TypeFactory.host_class
267
+ expect { func.call(@scope, class_type) }.to raise_error(ArgumentError, /reference to all.*class/)
268
+ end
269
+
270
+ it 'raises error if referencing undef' do
271
+ expect{func.call(@scope, nil)}.to raise_error(ArgumentError, /mis-matched arguments/)
272
+ end
273
+
274
+ it 'raises error if referencing a number' do
275
+ expect{func.call(@scope, 42)}.to raise_error(ArgumentError, /mis-matched arguments/)
276
+ end
277
+
278
+ it 'is false if referencing empty string' do
279
+ expect(func.call(@scope, '')).to be_falsey
280
+ end
281
+
282
+ it "is true if referencing 'main'" do
283
+ # mimic what compiler does with "main" in intial import
284
+ newclass ''
285
+ newresource :class, ''
286
+ expect(func.call(@scope, 'main')).to be_truthy
287
+ end
288
+
289
+ end