puppet 4.0.0-x86-mingw32 → 4.1.0-x86-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
@@ -164,6 +164,9 @@ describe "Puppet resource expressions" do
164
164
  path => '/somewhere',
165
165
  * => $y }" => "File[$t][mode] == '0666' and File[$t][owner] == 'the_x' and File[$t][path] == '/somewhere'")
166
166
 
167
+ produces("notify{title:}; Notify[title] { * => { message => set}}" => "Notify[title][message] == 'set'")
168
+ produces("Notify { * => { message => set}}; notify{title:}" => "Notify[title][message] == 'set'")
169
+
167
170
  fails("notify { title: unknown => value }" => /Invalid parameter: 'unknown'/)
168
171
 
169
172
  # this really needs to be a better error message.
@@ -36,8 +36,30 @@ describe "Two step scoping for variables" do
36
36
  end
37
37
  end
38
38
 
39
- it "when using a template ignores the dynamic value of the var when using the @varname syntax" do
40
- expect_the_message_to_be('node_msg') do <<-MANIFEST
39
+ it "issues error about built-in variable when reassigning to name" do
40
+ enc_node = Puppet::Node.new("the_node", { :parameters => { } })
41
+
42
+ expect {
43
+ compile_to_catalog("$name = 'never in a 0xF4240 years'", enc_node)
44
+ }.to raise_error(
45
+ Puppet::Error,
46
+ /Cannot reassign built in \(or already assigned\) variable '\$name' at line 1(\:7)? on node the_node/
47
+ )
48
+ end
49
+
50
+ it "issues error about built-in variable when reassigning to title" do
51
+ enc_node = Puppet::Node.new("the_node", { :parameters => { } })
52
+
53
+ expect {
54
+ compile_to_catalog("$title = 'never in a 0xF4240 years'", enc_node)
55
+ }.to raise_error(
56
+ Puppet::Error,
57
+ /Cannot reassign built in \(or already assigned\) variable '\$title' at line 1(\:8)? on node the_node/
58
+ )
59
+ end
60
+
61
+ it "when using a template ignores the dynamic value of the var when using the @varname syntax" do
62
+ expect_the_message_to_be('node_msg') do <<-MANIFEST
41
63
  node default {
42
64
  $var = "node_msg"
43
65
  include foo
@@ -589,12 +611,11 @@ describe "Two step scoping for variables" do
589
611
 
590
612
  it "does not allow the enc to specify an existing top scope var" do
591
613
  enc_node = Puppet::Node.new("the_node", { :parameters => { "var" => 'from_enc' } })
592
-
593
614
  expect {
594
615
  compile_to_catalog("$var = 'top scope'", enc_node)
595
616
  }.to raise_error(
596
- Puppet::Error,
597
- /Cannot reassign variable var at line 1(\:6)? on node the_node/
617
+ Puppet::Error,
618
+ /Cannot reassign variable '\$var' at line 1(\:6)? on node the_node/
598
619
  )
599
620
  end
600
621
 
@@ -229,7 +229,7 @@ describe Puppet::Transaction do
229
229
  notify.expects(:pre_run_check).raises(Puppet::Error, "fail for testing")
230
230
 
231
231
  catalog = mk_catalog(file, notify)
232
- catalog.apply
232
+ expect { catalog.apply }.to raise_error(Puppet::Error, /Some pre-run checks failed/)
233
233
  expect(Puppet::FileSystem.exist?(path)).not_to be_truthy
234
234
  end
235
235
 
@@ -93,20 +93,77 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
93
93
  expect(Puppet::FileSystem.exist?(source)).to be_falsey
94
94
  end
95
95
 
96
+ describe "when ensure is present using an empty file" do
97
+ before(:each) do
98
+ catalog.add_resource(described_class.new(:path => path, :ensure => :present, :backup => :false))
99
+ end
100
+
101
+ context "file is present" do
102
+ before(:each) do
103
+ FileUtils.touch(path)
104
+ end
105
+
106
+ it "should do nothing" do
107
+ report = catalog.apply.report
108
+ expect(report.resource_statuses["File[#{path}]"]).not_to be_failed
109
+ expect(Puppet::FileSystem.exist?(path)).to be_truthy
110
+ end
111
+
112
+ it "should log nothing" do
113
+ logs = catalog.apply.report.logs
114
+ expect(logs).to be_empty
115
+ end
116
+ end
117
+
118
+ context "file is not present" do
119
+ it "should create the file" do
120
+ report = catalog.apply.report
121
+ expect(report.resource_statuses["File[#{path}]"]).not_to be_failed
122
+ expect(Puppet::FileSystem.exist?(path)).to be_truthy
123
+ end
124
+
125
+ it "should log that the file was created" do
126
+ logs = catalog.apply.report.logs
127
+ expect(logs.first.source).to eq("/File[#{path}]/ensure")
128
+ expect(logs.first.message).to eq("created")
129
+ end
130
+ end
131
+ end
132
+
96
133
  describe "when ensure is absent" do
97
- it "should remove the file if present" do
98
- FileUtils.touch(path)
134
+ before(:each) do
99
135
  catalog.add_resource(described_class.new(:path => path, :ensure => :absent, :backup => :false))
100
- report = catalog.apply.report
101
- expect(report.resource_statuses["File[#{path}]"]).not_to be_failed
102
- expect(Puppet::FileSystem.exist?(path)).to be_falsey
103
136
  end
104
137
 
105
- it "should do nothing if file is not present" do
106
- catalog.add_resource(described_class.new(:path => path, :ensure => :absent, :backup => :false))
107
- report = catalog.apply.report
108
- expect(report.resource_statuses["File[#{path}]"]).not_to be_failed
109
- expect(Puppet::FileSystem.exist?(path)).to be_falsey
138
+ context "file is present" do
139
+ before(:each) do
140
+ FileUtils.touch(path)
141
+ end
142
+
143
+ it "should remove the file" do
144
+ report = catalog.apply.report
145
+ expect(report.resource_statuses["File[#{path}]"]).not_to be_failed
146
+ expect(Puppet::FileSystem.exist?(path)).to be_falsey
147
+ end
148
+
149
+ it "should log that the file was removed" do
150
+ logs = catalog.apply.report.logs
151
+ expect(logs.first.source).to eq("/File[#{path}]/ensure")
152
+ expect(logs.first.message).to eq("removed")
153
+ end
154
+ end
155
+
156
+ context "file is not present" do
157
+ it "should do nothing" do
158
+ report = catalog.apply.report
159
+ expect(report.resource_statuses["File[#{path}]"]).not_to be_failed
160
+ expect(Puppet::FileSystem.exist?(path)).to be_falsey
161
+ end
162
+
163
+ it "should log nothing" do
164
+ logs = catalog.apply.report.logs
165
+ expect(logs).to be_empty
166
+ end
110
167
  end
111
168
 
112
169
  # issue #14599
@@ -215,7 +272,7 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
215
272
  FileUtils.mkdir(path)
216
273
  set_mode(0777, path)
217
274
 
218
- catalog.add_resource described_class.new(:path => path, :ensure => :file, :mode => 0666, :backup => false, :force => true)
275
+ catalog.add_resource described_class.new(:path => path, :ensure => :file, :mode => '0666', :backup => false, :force => true)
219
276
  catalog.apply
220
277
 
221
278
  expect(get_mode(path) & 07777).to eq(0666)
@@ -356,14 +413,26 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
356
413
  expect(get_mode(path) & 07777).to eq(0600)
357
414
  end
358
415
 
359
- it "should overwrite the file" do
360
- FileUtils.touch(path)
416
+ context "overwriting a file" do
417
+ before :each do
418
+ FileUtils.touch(path)
419
+ set_mode(0644, path)
420
+ catalog.add_resource described_class.new(:path => path, :source => link, :mode => '0600', :links => :follow)
421
+ end
361
422
 
362
- catalog.add_resource described_class.new(:path => path, :source => link, :mode => '0600', :links => :follow)
363
- catalog.apply
423
+ it "should overwrite the file" do
424
+ catalog.apply
364
425
 
365
- expect(File).to be_file(path)
366
- expect(get_mode(path) & 07777).to eq(0600)
426
+ expect(File).to be_file(path)
427
+ expect(get_mode(path) & 07777).to eq(0600)
428
+ end
429
+
430
+ it "should log that the mode changed" do
431
+ report = catalog.apply.report
432
+
433
+ expect(report.logs.first.message).to eq("mode changed '0644' to '0600'")
434
+ expect(report.logs.first.source).to eq("/File[#{path}]/mode")
435
+ end
367
436
  end
368
437
  end
369
438
 
@@ -981,32 +1050,114 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
981
1050
  end
982
1051
 
983
1052
  CHECKSUM_TYPES_TO_TRY.each do |checksum_type, checksum|
984
- before(:each) do
985
- @options = {:path => path, :content => "this is some content, yo", :checksum => checksum_type}
986
- end
987
- it "should create a file with content if ensure is omitted" do
988
- catalog.add_resource described_class.send(:new, @options)
989
- catalog.apply
990
- expect(File.read(path)).to eq("this is some content, yo")
1053
+ describe "when checksum_type is #{checksum_type}" do
1054
+ before(:each) do
1055
+ @options = {:path => path, :content => CHECKSUM_PLAINTEXT, :checksum => checksum_type}
1056
+ end
991
1057
 
992
- second_catalog = Puppet::Resource::Catalog.new
993
- second_catalog.add_resource described_class.send(:new, @options)
994
- status = second_catalog.apply.report.resource_statuses["File[#{path}]"]
995
- expect(status).not_to be_failed
996
- expect(status).not_to be_changed
997
- end
1058
+ context "when changing the content" do
1059
+ before :each do
1060
+ FileUtils.touch(path)
1061
+ catalog.add_resource described_class.send(:new, @options)
1062
+ end
998
1063
 
999
- it "should create files with content if both content and ensure are set" do
1000
- @options[:ensure] = "file"
1001
- catalog.add_resource described_class.send(:new, @options)
1002
- catalog.apply
1003
- expect(File.read(path)).to eq("this is some content, yo")
1064
+ it "should overwrite contents" do
1065
+ catalog.apply
1066
+ expect(Puppet::FileSystem.binread(path)).to eq(CHECKSUM_PLAINTEXT)
1067
+ end
1068
+
1069
+ it "should log that content changed" do
1070
+ report = catalog.apply.report
1071
+ expect(report.logs.first.source).to eq("/File[#{path}]/content")
1072
+ expect(report.logs.first.message).to match(/content changed '{#{checksum_type}}[0-9a-f]*' to '{#{checksum_type}}#{checksum}'/)
1073
+ end
1074
+ end
1075
+
1076
+ context "ensure is present" do
1077
+ before(:each) do
1078
+ @options[:ensure] = "present"
1079
+ end
1004
1080
 
1005
- second_catalog = Puppet::Resource::Catalog.new
1006
- second_catalog.add_resource described_class.send(:new, @options)
1007
- status = second_catalog.apply.report.resource_statuses["File[#{path}]"]
1008
- expect(status).not_to be_failed
1009
- expect(status).not_to be_changed
1081
+ it "should create a file with content" do
1082
+ catalog.add_resource described_class.send(:new, @options)
1083
+ catalog.apply
1084
+ expect(Puppet::FileSystem.binread(path)).to eq(CHECKSUM_PLAINTEXT)
1085
+
1086
+ second_catalog = Puppet::Resource::Catalog.new
1087
+ second_catalog.add_resource described_class.send(:new, @options)
1088
+ status = second_catalog.apply.report.resource_statuses["File[#{path}]"]
1089
+ expect(status).not_to be_failed
1090
+ expect(status).not_to be_changed
1091
+ end
1092
+
1093
+ it "should log the content checksum" do
1094
+ catalog.add_resource described_class.send(:new, @options)
1095
+ report = catalog.apply.report
1096
+ expect(report.logs.first.source).to eq("/File[#{path}]/ensure")
1097
+ expect(report.logs.first.message).to eq("defined content as '{#{checksum_type}}#{checksum}'")
1098
+
1099
+ second_catalog = Puppet::Resource::Catalog.new
1100
+ second_catalog.add_resource described_class.send(:new, @options)
1101
+ logs = second_catalog.apply.report.logs
1102
+ expect(logs).to be_empty
1103
+ end
1104
+ end
1105
+
1106
+ context "ensure is omitted" do
1107
+ it "should create a file with content" do
1108
+ catalog.add_resource described_class.send(:new, @options)
1109
+ catalog.apply
1110
+ expect(Puppet::FileSystem.binread(path)).to eq(CHECKSUM_PLAINTEXT)
1111
+
1112
+ second_catalog = Puppet::Resource::Catalog.new
1113
+ second_catalog.add_resource described_class.send(:new, @options)
1114
+ status = second_catalog.apply.report.resource_statuses["File[#{path}]"]
1115
+ expect(status).not_to be_failed
1116
+ expect(status).not_to be_changed
1117
+ end
1118
+
1119
+ it "should log the content checksum" do
1120
+ catalog.add_resource described_class.send(:new, @options)
1121
+ report = catalog.apply.report
1122
+ expect(report.logs.first.source).to eq("/File[#{path}]/ensure")
1123
+ expect(report.logs.first.message).to eq("defined content as '{#{checksum_type}}#{checksum}'")
1124
+
1125
+ second_catalog = Puppet::Resource::Catalog.new
1126
+ second_catalog.add_resource described_class.send(:new, @options)
1127
+ logs = second_catalog.apply.report.logs
1128
+ expect(logs).to be_empty
1129
+ end
1130
+ end
1131
+
1132
+ context "both content and ensure are set" do
1133
+ before(:each) do
1134
+ @options[:ensure] = "file"
1135
+ end
1136
+
1137
+ it "should create files with content" do
1138
+ catalog.add_resource described_class.send(:new, @options)
1139
+ catalog.apply
1140
+ expect(Puppet::FileSystem.binread(path)).to eq(CHECKSUM_PLAINTEXT)
1141
+
1142
+ second_catalog = Puppet::Resource::Catalog.new
1143
+ second_catalog.add_resource described_class.send(:new, @options)
1144
+ status = second_catalog.apply.report.resource_statuses["File[#{path}]"]
1145
+ expect(status).not_to be_failed
1146
+ expect(status).not_to be_changed
1147
+ end
1148
+
1149
+ it "should log the content checksum" do
1150
+ catalog.add_resource described_class.send(:new, @options)
1151
+ report = catalog.apply.report
1152
+ expect(report.logs.first.source).to eq("/File[#{path}]/ensure")
1153
+ expect(report.logs.first.message).to eq("defined content as '{#{checksum_type}}#{checksum}'")
1154
+
1155
+ second_catalog = Puppet::Resource::Catalog.new
1156
+ second_catalog.add_resource described_class.send(:new, @options)
1157
+ logs = second_catalog.apply.report.logs
1158
+ expect(logs).to be_empty
1159
+ end
1160
+ end
1010
1161
  end
1011
1162
  end
1012
1163
 
@@ -1111,7 +1262,6 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
1111
1262
  @sids = {
1112
1263
  :current_user => Puppet::Util::Windows::SID.name_to_sid(Puppet::Util::Windows::ADSI::User.current_user_name),
1113
1264
  :system => Win32::Security::SID::LocalSystem,
1114
- :admin => Puppet::Util::Windows::SID.name_to_sid("Administrator"),
1115
1265
  :guest => Puppet::Util::Windows::SID.name_to_sid("Guest"),
1116
1266
  :users => Win32::Security::SID::BuiltinUsers,
1117
1267
  :power_users => Win32::Security::SID::PowerUsers,
@@ -1377,4 +1527,131 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
1377
1527
 
1378
1528
  raise "Got #{status_failures.length} failure(s) while applying: #{status_fail_msg}"
1379
1529
  end
1530
+
1531
+ describe "copying a file that is a link to a file", :if => Puppet.features.manages_symlinks? do
1532
+ let(:target) { tmpfile('target') }
1533
+ let(:link) { tmpfile('link') }
1534
+ let(:copy) { tmpfile('copy') }
1535
+ it "should copy the target of the link if :links => follow" do
1536
+ catalog.add_resource described_class.new(
1537
+ :name => target,
1538
+ :ensure => "present",
1539
+ :content => "Jenny I got your number / I need to make you mine")
1540
+ catalog.add_resource described_class.new(
1541
+ :name => link,
1542
+ :ensure => "link",
1543
+ :target => target)
1544
+ catalog.add_resource described_class.new(
1545
+ :name => copy,
1546
+ :ensure => "present",
1547
+ :source => link,
1548
+ :links => "follow")
1549
+ catalog.apply
1550
+ expect(Puppet::FileSystem).to be_file(copy)
1551
+ expect(File.read(target)).to eq(File.read(copy))
1552
+ end
1553
+
1554
+ it "should copy the link itself if :links => manage" do
1555
+ catalog.add_resource described_class.new(
1556
+ :name => target,
1557
+ :ensure => "present",
1558
+ :content => "Jenny I got your number / I need to make you mine")
1559
+ catalog.add_resource described_class.new(
1560
+ :name => link,
1561
+ :ensure => "link",
1562
+ :target => target)
1563
+ catalog.add_resource described_class.new(
1564
+ :name => copy,
1565
+ :ensure => "present",
1566
+ :source => link,
1567
+ :links => "manage")
1568
+ catalog.apply
1569
+ expect(Puppet::FileSystem).to be_symlink(copy)
1570
+ expect(File.read(link)).to eq(File.read(copy))
1571
+ end
1572
+ end
1573
+
1574
+ describe "copying a file that is a link to a directory", :if => Puppet.features.manages_symlinks? do
1575
+ let(:target) { tmpdir('target') }
1576
+ let(:link) { tmpfile('link') }
1577
+ let(:copy) { tmpfile('copy') }
1578
+ context "when the recurse attribute is false" do
1579
+ it "should copy the top-level directory if :links => follow" do
1580
+ catalog.add_resource described_class.new(
1581
+ :name => target,
1582
+ :ensure => "directory")
1583
+ catalog.add_resource described_class.new(
1584
+ :name => link,
1585
+ :ensure => "link",
1586
+ :target => target)
1587
+ catalog.add_resource described_class.new(
1588
+ :name => copy,
1589
+ :ensure => "present",
1590
+ :source => link,
1591
+ :recurse => false,
1592
+ :links => "follow")
1593
+ catalog.apply
1594
+ expect(Puppet::FileSystem).to be_directory(copy)
1595
+ end
1596
+
1597
+ it "should copy the link itself if :links => manage" do
1598
+ catalog.add_resource described_class.new(
1599
+ :name => target,
1600
+ :ensure => "directory")
1601
+ catalog.add_resource described_class.new(
1602
+ :name => link,
1603
+ :ensure => "link",
1604
+ :target => target)
1605
+ catalog.add_resource described_class.new(
1606
+ :name => copy,
1607
+ :ensure => "present",
1608
+ :source => link,
1609
+ :recurse => false,
1610
+ :links => "manage")
1611
+ catalog.apply
1612
+ expect(Puppet::FileSystem).to be_symlink(copy)
1613
+ expect(Dir.entries(link)).to eq(Dir.entries(copy))
1614
+ end
1615
+ end
1616
+
1617
+ context "and the recurse attribute is true" do
1618
+ it "should recursively copy the directory if :links => follow" do
1619
+ catalog.add_resource described_class.new(
1620
+ :name => target,
1621
+ :ensure => "directory")
1622
+ catalog.add_resource described_class.new(
1623
+ :name => link,
1624
+ :ensure => "link",
1625
+ :target => target)
1626
+ catalog.add_resource described_class.new(
1627
+ :name => copy,
1628
+ :ensure => "present",
1629
+ :source => link,
1630
+ :recurse => true,
1631
+ :links => "follow")
1632
+ catalog.apply
1633
+ expect(Puppet::FileSystem).to be_directory(copy)
1634
+ expect(Dir.entries(target)).to eq(Dir.entries(copy))
1635
+ end
1636
+
1637
+ it "should copy the link itself if :links => manage" do
1638
+ catalog.add_resource described_class.new(
1639
+ :name => target,
1640
+ :ensure => "directory")
1641
+ catalog.add_resource described_class.new(
1642
+ :name => link,
1643
+ :ensure => "link",
1644
+ :target => target)
1645
+ catalog.add_resource described_class.new(
1646
+ :name => copy,
1647
+ :ensure => "present",
1648
+ :source => link,
1649
+ :recurse => true,
1650
+ :links => "manage")
1651
+ catalog.apply
1652
+ expect(Puppet::FileSystem).to be_symlink(copy)
1653
+ expect(Dir.entries(link)).to eq(Dir.entries(copy))
1654
+ end
1655
+ end
1656
+ end
1380
1657
  end