puppet 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +20 -20
  4. data/Guardfile.example +76 -0
  5. data/LICENSE +189 -4
  6. data/README.md +3 -3
  7. data/Rakefile +5 -2
  8. data/ext/solaris/smf/svc-puppetd +8 -1
  9. data/ext/solaris/smf/svc-puppetmasterd +8 -1
  10. data/lib/puppet/application/apply.rb +100 -59
  11. data/lib/puppet/application/cert.rb +4 -114
  12. data/lib/puppet/application/device.rb +48 -32
  13. data/lib/puppet/application/script.rb +1 -1
  14. data/lib/puppet/application/ssl.rb +135 -51
  15. data/lib/puppet/application.rb +5 -0
  16. data/lib/puppet/configurer.rb +2 -3
  17. data/lib/puppet/defaults.rb +33 -49
  18. data/lib/puppet/etc.rb +20 -0
  19. data/lib/puppet/face/config.rb +3 -3
  20. data/lib/puppet/face/key.rb +1 -1
  21. data/lib/puppet/face/node/clean.rb +0 -1
  22. data/lib/puppet/feature/base.rb +1 -1
  23. data/lib/puppet/file_bucket/dipper.rb +1 -1
  24. data/lib/puppet/file_serving/fileset.rb +1 -1
  25. data/lib/puppet/functions/abs.rb +1 -1
  26. data/lib/puppet/functions/new.rb +1 -1
  27. data/lib/puppet/module/task.rb +29 -38
  28. data/lib/puppet/pal/catalog_compiler.rb +96 -0
  29. data/lib/puppet/pal/compiler.rb +221 -0
  30. data/lib/puppet/pal/function_signature.rb +52 -0
  31. data/lib/puppet/pal/json_catalog_encoder.rb +67 -0
  32. data/lib/puppet/pal/pal_api.rb +15 -0
  33. data/lib/puppet/pal/pal_impl.rb +523 -0
  34. data/lib/puppet/pal/plan_signature.rb +71 -0
  35. data/lib/puppet/pal/script_compiler.rb +71 -0
  36. data/lib/puppet/pal/task_signature.rb +58 -0
  37. data/lib/puppet/parser/catalog_compiler.rb +24 -0
  38. data/lib/puppet/parser/compiler.rb +3 -1
  39. data/lib/puppet/parser/functions/generate.rb +7 -6
  40. data/lib/puppet/plugins/configuration.rb +5 -1
  41. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +3 -1
  42. data/lib/puppet/pops/evaluator/deferred_resolver.rb +3 -0
  43. data/lib/puppet/pops/evaluator/evaluator_impl.rb +5 -1
  44. data/lib/puppet/pops/evaluator/external_syntax_support.rb +3 -3
  45. data/lib/puppet/pops/evaluator/runtime3_converter.rb +2 -2
  46. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +19 -10
  47. data/lib/puppet/pops/loader/task_instantiator.rb +13 -70
  48. data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
  49. data/lib/puppet/pops/parser/lexer2.rb +1 -1
  50. data/lib/puppet/pops/pcore.rb +10 -33
  51. data/lib/puppet/pops/serialization/to_data_converter.rb +9 -1
  52. data/lib/puppet/pops/serialization.rb +1 -0
  53. data/lib/puppet/pops/types/p_timespan_type.rb +2 -2
  54. data/lib/puppet/pops/types/string_converter.rb +18 -4
  55. data/lib/puppet/pops/validation/checker4_0.rb +17 -2
  56. data/lib/puppet/provider/exec.rb +59 -57
  57. data/lib/puppet/provider/group/aix.rb +18 -2
  58. data/lib/puppet/provider/group/windows_adsi.rb +7 -3
  59. data/lib/puppet/provider/nameservice.rb +1 -25
  60. data/lib/puppet/provider/package/dnf.rb +2 -0
  61. data/lib/puppet/provider/package/pkgng.rb +37 -21
  62. data/lib/puppet/provider/package/portage.rb +2 -2
  63. data/lib/puppet/provider/package/windows/exe_package.rb +16 -10
  64. data/lib/puppet/provider/package/windows/msi_package.rb +8 -0
  65. data/lib/puppet/provider/package/windows/package.rb +9 -1
  66. data/lib/puppet/provider/package/windows.rb +2 -2
  67. data/lib/puppet/provider/package/yum.rb +1 -1
  68. data/lib/puppet/provider/parsedfile.rb +25 -4
  69. data/lib/puppet/provider/service/launchd.rb +19 -3
  70. data/lib/puppet/provider/service/smf.rb +54 -0
  71. data/lib/puppet/provider/service/systemd.rb +19 -0
  72. data/lib/puppet/provider/service/upstart.rb +1 -0
  73. data/lib/puppet/provider/service/windows.rb +22 -5
  74. data/lib/puppet/provider/user/aix.rb +48 -2
  75. data/lib/puppet/provider/user/useradd.rb +2 -10
  76. data/lib/puppet/provider/user/windows_adsi.rb +9 -1
  77. data/lib/puppet/resource/catalog.rb +1 -5
  78. data/lib/puppet/resource.rb +3 -1
  79. data/lib/puppet/ssl/host.rb +26 -16
  80. data/lib/puppet/syntax_checkers/epp.rb +34 -0
  81. data/lib/puppet/syntax_checkers/pp.rb +34 -0
  82. data/lib/puppet/transaction/event_manager.rb +13 -1
  83. data/lib/puppet/transaction/persistence.rb +1 -1
  84. data/lib/puppet/transaction/resource_harness.rb +3 -1
  85. data/lib/puppet/type/group.rb +29 -1
  86. data/lib/puppet/type/package.rb +5 -1
  87. data/lib/puppet/type/resources.rb +12 -2
  88. data/lib/puppet/type/schedule.rb +7 -0
  89. data/lib/puppet/type/service.rb +12 -0
  90. data/lib/puppet/type/user.rb +5 -2
  91. data/lib/puppet/type.rb +6 -0
  92. data/lib/puppet/util/command_line.rb +2 -3
  93. data/lib/puppet/util/execution.rb +15 -1
  94. data/lib/puppet/util/filetype.rb +56 -8
  95. data/lib/puppet/util/log/destinations.rb +3 -2
  96. data/lib/puppet/util/logging.rb +3 -2
  97. data/lib/puppet/util/posix.rb +15 -0
  98. data/lib/puppet/util/selinux.rb +1 -1
  99. data/lib/puppet/util/storage.rb +12 -0
  100. data/lib/puppet/util/windows/adsi.rb +79 -2
  101. data/lib/puppet/util/windows/api_types.rb +1 -1
  102. data/lib/puppet/util/windows/process.rb +23 -3
  103. data/lib/puppet/util/windows/registry.rb +29 -5
  104. data/lib/puppet/util/windows/security.rb +14 -0
  105. data/lib/puppet/util/windows/service.rb +294 -74
  106. data/lib/puppet/util/windows/user.rb +3 -5
  107. data/lib/puppet/util.rb +7 -3
  108. data/lib/puppet/version.rb +1 -1
  109. data/lib/puppet.rb +1 -0
  110. data/lib/puppet_pal.rb +5 -1099
  111. data/locales/ja/puppet.po +952 -986
  112. data/locales/puppet.pot +592 -347
  113. data/man/man5/puppet.conf.5 +26 -31
  114. data/man/man8/puppet-agent.8 +1 -1
  115. data/man/man8/puppet-apply.8 +1 -1
  116. data/man/man8/puppet-catalog.8 +1 -1
  117. data/man/man8/puppet-config.8 +4 -4
  118. data/man/man8/puppet-describe.8 +1 -1
  119. data/man/man8/puppet-device.8 +23 -19
  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-filebucket.8 +1 -1
  124. data/man/man8/puppet-generate.8 +1 -1
  125. data/man/man8/puppet-help.8 +1 -1
  126. data/man/man8/puppet-key.8 +2 -2
  127. data/man/man8/puppet-lookup.8 +1 -1
  128. data/man/man8/puppet-man.8 +1 -1
  129. data/man/man8/puppet-module.8 +1 -1
  130. data/man/man8/puppet-node.8 +1 -1
  131. data/man/man8/puppet-parser.8 +1 -1
  132. data/man/man8/puppet-plugin.8 +1 -1
  133. data/man/man8/puppet-report.8 +1 -1
  134. data/man/man8/puppet-resource.8 +1 -1
  135. data/man/man8/puppet-script.8 +1 -1
  136. data/man/man8/puppet-ssl.8 +26 -3
  137. data/man/man8/puppet-status.8 +1 -1
  138. data/man/man8/puppet.8 +2 -2
  139. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/usee/lib/puppet/parser/functions/bad_func_load.rb +11 -0
  140. data/spec/fixtures/unit/provider/package/pkgng/pkg.query +7 -1
  141. data/spec/fixtures/unit/provider/package/pkgng/pkg.query.zsh +1 -0
  142. data/spec/fixtures/unit/provider/service/smf/svcs_fmri.out +6 -0
  143. data/spec/fixtures/unit/provider/service/smf/svcs_multiple_fmris.out +13 -0
  144. data/spec/integration/application/apply_spec.rb +4 -1
  145. data/spec/integration/parser/collection_spec.rb +4 -8
  146. data/spec/integration/provider/service/windows_spec.rb +5 -5
  147. data/spec/integration/ssl/key_spec.rb +0 -4
  148. data/spec/integration/transaction_spec.rb +559 -0
  149. data/spec/integration/type/file_spec.rb +6 -6
  150. data/spec/integration/util/windows/registry_spec.rb +39 -0
  151. data/spec/integration/util/windows/security_spec.rb +10 -7
  152. data/spec/integration/util/windows/user_spec.rb +37 -17
  153. data/spec/lib/puppet/test_ca.rb +1 -1
  154. data/spec/spec_helper.rb +1 -1
  155. data/spec/unit/agent_spec.rb +2 -2
  156. data/spec/unit/application/apply_spec.rb +55 -2
  157. data/spec/unit/application/device_spec.rb +10 -7
  158. data/spec/unit/application/face_base_spec.rb +1 -1
  159. data/spec/unit/application/lookup_spec.rb +2 -1
  160. data/spec/unit/application/ssl_spec.rb +178 -109
  161. data/spec/unit/application_spec.rb +29 -11
  162. data/spec/unit/configurer/downloader_spec.rb +1 -1
  163. data/spec/unit/configurer_spec.rb +16 -5
  164. data/spec/unit/etc_spec.rb +25 -0
  165. data/spec/unit/face/node_spec.rb +1 -3
  166. data/spec/unit/face/parser_spec.rb +15 -0
  167. data/spec/unit/file_serving/fileset_spec.rb +11 -11
  168. data/spec/unit/functions/logging_spec.rb +10 -3
  169. data/spec/unit/indirector/catalog/json_spec.rb +9 -3
  170. data/spec/unit/indirector/yaml_spec.rb +1 -1
  171. data/spec/unit/network/http/connection_spec.rb +2 -2
  172. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +36 -0
  173. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +22 -4
  174. data/spec/unit/pops/loaders/loader_spec.rb +9 -17
  175. data/spec/unit/pops/loaders/loaders_spec.rb +48 -0
  176. data/spec/unit/pops/loaders/module_loaders_spec.rb +7 -7
  177. data/spec/unit/pops/parser/parse_heredoc_spec.rb +16 -0
  178. data/spec/unit/pops/serialization/to_from_hr_spec.rb +9 -0
  179. data/spec/unit/pops/types/p_timespan_type_spec.rb +22 -0
  180. data/spec/unit/pops/types/p_timestamp_type_spec.rb +19 -0
  181. data/spec/unit/pops/types/string_converter_spec.rb +25 -1
  182. data/spec/unit/pops/types/task_spec.rb +42 -116
  183. data/spec/unit/pops/validator/validator_spec.rb +24 -10
  184. data/spec/unit/provider/exec/posix_spec.rb +24 -0
  185. data/spec/unit/provider/group/aix_spec.rb +20 -6
  186. data/spec/unit/provider/group/ldap_spec.rb +22 -25
  187. data/spec/unit/provider/group/pw_spec.rb +7 -10
  188. data/spec/unit/provider/group/windows_adsi_spec.rb +42 -33
  189. data/spec/unit/provider/nameservice/directoryservice_spec.rb +97 -103
  190. data/spec/unit/provider/package/aix_spec.rb +5 -8
  191. data/spec/unit/provider/package/apt_spec.rb +3 -6
  192. data/spec/unit/provider/package/dnf_spec.rb +38 -25
  193. data/spec/unit/provider/package/dpkg_spec.rb +18 -21
  194. data/spec/unit/provider/package/freebsd_spec.rb +4 -7
  195. data/spec/unit/provider/package/gem_spec.rb +41 -41
  196. data/spec/unit/provider/package/hpux_spec.rb +7 -10
  197. data/spec/unit/provider/package/macports_spec.rb +13 -15
  198. data/spec/unit/provider/package/nim_spec.rb +3 -10
  199. data/spec/unit/provider/package/openbsd_spec.rb +14 -17
  200. data/spec/unit/provider/package/pip3_spec.rb +3 -6
  201. data/spec/unit/provider/package/pip_spec.rb +45 -49
  202. data/spec/unit/provider/package/pkgin_spec.rb +13 -18
  203. data/spec/unit/provider/package/pkgng_spec.rb +32 -27
  204. data/spec/unit/provider/package/puppet_gem_spec.rb +6 -9
  205. data/spec/unit/provider/package/tdnf_spec.rb +9 -12
  206. data/spec/unit/provider/package/windows/exe_package_spec.rb +3 -3
  207. data/spec/unit/provider/package/windows_spec.rb +4 -4
  208. data/spec/unit/provider/package/yum_spec.rb +30 -16
  209. data/spec/unit/provider/package/zypper_spec.rb +17 -19
  210. data/spec/unit/provider/service/bsd_spec.rb +7 -9
  211. data/spec/unit/provider/service/daemontools_spec.rb +12 -16
  212. data/spec/unit/provider/service/debian_spec.rb +6 -10
  213. data/spec/unit/provider/service/freebsd_spec.rb +2 -2
  214. data/spec/unit/provider/service/launchd_spec.rb +19 -0
  215. data/spec/unit/provider/service/openbsd_spec.rb +13 -17
  216. data/spec/unit/provider/service/rcng_spec.rb +2 -4
  217. data/spec/unit/provider/service/redhat_spec.rb +12 -11
  218. data/spec/unit/provider/service/runit_spec.rb +7 -14
  219. data/spec/unit/provider/service/smf_spec.rb +77 -13
  220. data/spec/unit/provider/service/src_spec.rb +11 -16
  221. data/spec/unit/provider/service/systemd_spec.rb +39 -1
  222. data/spec/unit/provider/service/windows_spec.rb +39 -7
  223. data/spec/unit/provider/user/aix_spec.rb +43 -2
  224. data/spec/unit/provider/user/hpux_spec.rb +3 -5
  225. data/spec/unit/provider/user/ldap_spec.rb +29 -32
  226. data/spec/unit/provider/user/pw_spec.rb +10 -13
  227. data/spec/unit/provider/user/useradd_spec.rb +2 -2
  228. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  229. data/spec/unit/puppet_pal_2pec.rb +6 -6
  230. data/spec/unit/puppet_pal_catalog_spec.rb +58 -0
  231. data/spec/unit/resource/catalog_spec.rb +2 -2
  232. data/spec/unit/resource_spec.rb +31 -0
  233. data/spec/unit/ssl/host_spec.rb +22 -1
  234. data/spec/unit/ssl/key_spec.rb +2 -4
  235. data/spec/unit/task_spec.rb +50 -5
  236. data/spec/unit/transaction/event_manager_spec.rb +12 -1
  237. data/spec/unit/transaction/persistence_spec.rb +4 -4
  238. data/spec/unit/transaction/resource_harness_spec.rb +18 -0
  239. data/spec/unit/type/group_spec.rb +11 -3
  240. data/spec/unit/type/resources_spec.rb +18 -0
  241. data/spec/unit/type/service_spec.rb +27 -1
  242. data/spec/unit/util/execution_spec.rb +77 -0
  243. data/spec/unit/util/filetype_spec.rb +13 -5
  244. data/spec/unit/util/log/destinations_spec.rb +10 -0
  245. data/spec/unit/util/logging_spec.rb +58 -41
  246. data/spec/unit/util/monkey_patches_spec.rb +18 -5
  247. data/spec/unit/util/posix_spec.rb +28 -0
  248. data/spec/unit/util/selinux_spec.rb +4 -0
  249. data/spec/unit/util/storage_spec.rb +107 -0
  250. data/spec/unit/util/suidmanager_spec.rb +1 -3
  251. data/spec/unit/util/windows/adsi_spec.rb +95 -0
  252. data/spec/unit/util/windows/service_spec.rb +377 -131
  253. metadata +24 -11
  254. data/ext/autotest/Rakefile +0 -8
  255. data/ext/autotest/config +0 -43
  256. data/ext/autotest/readme.rst +0 -16
  257. data/spec/fixtures/unit/provider/package/pkgng/pkg.info +0 -7
  258. data/spec/fixtures/unit/provider/package/pkgng/pkg.query_absent +0 -1
  259. data/spec/watchr.rb +0 -137
@@ -12,17 +12,17 @@ describe test_title, '(integration)', :if => Puppet::Util::Platform.windows? do
12
12
  Puppet::Type.type(:service).stubs(:defaultprovider).returns provider_class
13
13
  end
14
14
 
15
- context 'should fail querying services that do not exist' do
15
+ context 'should return valid values when querying a service that does not exist' do
16
16
  let(:service) do
17
17
  Puppet::Type.type(:service).new(:name => 'foobarservice1234')
18
18
  end
19
19
 
20
- it "with a Puppet::Error when querying enabled?" do
21
- expect { service.provider.enabled? }.to raise_error(Puppet::Error)
20
+ it "with :false when asked if enabled" do
21
+ expect(service.provider.enabled?).to eql(:false)
22
22
  end
23
23
 
24
- it "with a Puppet::Error when querying status" do
25
- expect { service.provider.status }.to raise_error(Puppet::Error)
24
+ it "with :stopped when asked about status" do
25
+ expect(service.provider.status).to eql(:stopped)
26
26
  end
27
27
  end
28
28
 
@@ -41,8 +41,6 @@ describe Puppet::SSL::Key, unless: Puppet::Util::Platform.jruby? do
41
41
  end
42
42
 
43
43
  it "should be able to read an existing private key given the correct password" do
44
- Puppet[:keylength] = '50'
45
-
46
44
  key_name = 'test'
47
45
  # use OpenSSL APIs to generate a private key
48
46
  private_key = OpenSSL::PKey::RSA.generate(512)
@@ -69,8 +67,6 @@ describe Puppet::SSL::Key, unless: Puppet::Util::Platform.jruby? do
69
67
  end
70
68
 
71
69
  it 'should export the private key to PEM using the password' do
72
- Puppet[:keylength] = '50'
73
-
74
70
  key_name = 'test'
75
71
 
76
72
  # uses specified :passfile when writing the private key
@@ -0,0 +1,559 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet_spec/compiler'
4
+
5
+ require 'puppet/transaction'
6
+
7
+ Puppet::Type.newtype(:devicetype) do
8
+ apply_to_device
9
+ newparam(:name)
10
+ end
11
+
12
+ describe Puppet::Transaction do
13
+ include PuppetSpec::Files
14
+ include PuppetSpec::Compiler
15
+
16
+ before do
17
+ Puppet::Util::Storage.stubs(:store)
18
+ end
19
+
20
+ def mk_catalog(*resources)
21
+ catalog = Puppet::Resource::Catalog.new(Puppet::Node.new("mynode"))
22
+ resources.each { |res| catalog.add_resource res }
23
+ catalog
24
+ end
25
+
26
+ def touch_path
27
+ Puppet.features.microsoft_windows? ? "#{ENV['windir']}\\system32" : "/usr/bin:/bin"
28
+ end
29
+
30
+ def usr_bin_touch(path)
31
+ Puppet.features.microsoft_windows? ? "#{ENV['windir']}\\system32\\cmd.exe /c \"type NUL >> \"#{path}\"\"" : "/usr/bin/touch #{path}"
32
+ end
33
+
34
+ def touch(path)
35
+ Puppet.features.microsoft_windows? ? "cmd.exe /c \"type NUL >> \"#{path}\"\"" : "touch #{path}"
36
+ end
37
+
38
+ it "should not apply generated resources if the parent resource fails" do
39
+ catalog = Puppet::Resource::Catalog.new
40
+ resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false
41
+ catalog.add_resource resource
42
+
43
+ child_resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar/baz"), :backup => false
44
+
45
+ resource.expects(:eval_generate).returns([child_resource])
46
+
47
+ transaction = Puppet::Transaction.new(catalog, nil, Puppet::Graph::SequentialPrioritizer.new)
48
+
49
+ resource.expects(:retrieve).raises "this is a failure"
50
+ resource.stubs(:err)
51
+
52
+ child_resource.expects(:retrieve).never
53
+
54
+ transaction.evaluate
55
+ end
56
+
57
+ it "should not apply virtual resources" do
58
+ catalog = Puppet::Resource::Catalog.new
59
+ resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false
60
+ resource.virtual = true
61
+ catalog.add_resource resource
62
+
63
+ transaction = Puppet::Transaction.new(catalog, nil, Puppet::Graph::SequentialPrioritizer.new)
64
+
65
+ resource.expects(:evaluate).never
66
+
67
+ transaction.evaluate
68
+ end
69
+
70
+ it "should apply exported resources" do
71
+ catalog = Puppet::Resource::Catalog.new
72
+ path = tmpfile("exported_files")
73
+ resource = Puppet::Type.type(:file).new :path => path, :backup => false, :ensure => :file
74
+ resource.exported = true
75
+ catalog.add_resource resource
76
+
77
+ catalog.apply
78
+ expect(Puppet::FileSystem.exist?(path)).to be_truthy
79
+ end
80
+
81
+ it "should not apply virtual exported resources" do
82
+ catalog = Puppet::Resource::Catalog.new
83
+ resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false
84
+ resource.exported = true
85
+ resource.virtual = true
86
+ catalog.add_resource resource
87
+
88
+ transaction = Puppet::Transaction.new(catalog, nil, Puppet::Graph::SequentialPrioritizer.new)
89
+
90
+ resource.expects(:evaluate).never
91
+
92
+ transaction.evaluate
93
+ end
94
+
95
+ it "should not apply device resources on normal host" do
96
+ catalog = Puppet::Resource::Catalog.new
97
+ resource = Puppet::Type.type(:devicetype).new :name => "FastEthernet 0/1"
98
+ catalog.add_resource resource
99
+
100
+ transaction = Puppet::Transaction.new(catalog, nil, Puppet::Graph::SequentialPrioritizer.new)
101
+ transaction.for_network_device = false
102
+
103
+ transaction.expects(:apply).never.with(resource, nil)
104
+
105
+ transaction.evaluate
106
+ expect(transaction.resource_status(resource)).to be_skipped
107
+ end
108
+
109
+ it "should not apply host resources on device" do
110
+ catalog = Puppet::Resource::Catalog.new
111
+ resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false
112
+ catalog.add_resource resource
113
+
114
+ transaction = Puppet::Transaction.new(catalog, nil, Puppet::Graph::SequentialPrioritizer.new)
115
+ transaction.for_network_device = true
116
+
117
+ transaction.expects(:apply).never.with(resource, nil)
118
+
119
+ transaction.evaluate
120
+ expect(transaction.resource_status(resource)).to be_skipped
121
+ end
122
+
123
+ it "should apply device resources on device" do
124
+ catalog = Puppet::Resource::Catalog.new
125
+ resource = Puppet::Type.type(:devicetype).new :name => "FastEthernet 0/1"
126
+ catalog.add_resource resource
127
+
128
+ transaction = Puppet::Transaction.new(catalog, nil, Puppet::Graph::SequentialPrioritizer.new)
129
+ transaction.for_network_device = true
130
+
131
+ transaction.expects(:apply).with(resource, nil)
132
+
133
+ transaction.evaluate
134
+ expect(transaction.resource_status(resource)).not_to be_skipped
135
+ end
136
+
137
+ it "should apply resources appliable on host and device on a device" do
138
+ catalog = Puppet::Resource::Catalog.new
139
+ resource = Puppet::Type.type(:schedule).new :name => "test"
140
+ catalog.add_resource resource
141
+
142
+ transaction = Puppet::Transaction.new(catalog, nil, Puppet::Graph::SequentialPrioritizer.new)
143
+ transaction.for_network_device = true
144
+
145
+ transaction.expects(:apply).with(resource, nil)
146
+
147
+ transaction.evaluate
148
+ expect(transaction.resource_status(resource)).not_to be_skipped
149
+ end
150
+
151
+ # Verify that one component requiring another causes the contained
152
+ # resources in the requiring component to get refreshed.
153
+ it "should propagate events from a contained resource through its container to its dependent container's contained resources" do
154
+ file = Puppet::Type.type(:file).new :path => tmpfile("event_propagation"), :ensure => :present
155
+ execfile = File.join(tmpdir("exec_event"), "exectestingness2")
156
+ exec = Puppet::Type.type(:exec).new :command => touch(execfile), :path => ENV['PATH']
157
+ catalog = mk_catalog(file)
158
+
159
+ fcomp = Puppet::Type.type(:component).new(:name => "Foo[file]")
160
+ catalog.add_resource fcomp
161
+ catalog.add_edge(fcomp, file)
162
+
163
+ ecomp = Puppet::Type.type(:component).new(:name => "Foo[exec]")
164
+ catalog.add_resource ecomp
165
+ catalog.add_resource exec
166
+ catalog.add_edge(ecomp, exec)
167
+
168
+ ecomp[:subscribe] = Puppet::Resource.new(:foo, "file")
169
+ exec[:refreshonly] = true
170
+
171
+ exec.expects(:refresh)
172
+ catalog.apply
173
+ end
174
+
175
+ # Make sure that multiple subscriptions get triggered.
176
+ it "should propagate events to all dependent resources", :unless => RUBY_PLATFORM == 'java' do
177
+ path = tmpfile("path")
178
+ file1 = tmpfile("file1")
179
+ file2 = tmpfile("file2")
180
+
181
+ file = Puppet::Type.type(:file).new(
182
+ :path => path,
183
+ :ensure => "file"
184
+ )
185
+
186
+ exec1 = Puppet::Type.type(:exec).new(
187
+ :path => ENV["PATH"],
188
+ :command => touch(file1),
189
+ :refreshonly => true,
190
+ :subscribe => Puppet::Resource.new(:file, path)
191
+ )
192
+
193
+ exec2 = Puppet::Type.type(:exec).new(
194
+ :path => ENV["PATH"],
195
+ :command => touch(file2),
196
+ :refreshonly => true,
197
+ :subscribe => Puppet::Resource.new(:file, path)
198
+ )
199
+
200
+ catalog = mk_catalog(file, exec1, exec2)
201
+ catalog.apply
202
+ expect(Puppet::FileSystem.exist?(file1)).to be_truthy
203
+ expect(Puppet::FileSystem.exist?(file2)).to be_truthy
204
+ end
205
+
206
+ it "does not refresh resources that have 'noop => true'" do
207
+ path = tmpfile("path")
208
+
209
+ notify = Puppet::Type.type(:notify).new(
210
+ :name => "trigger",
211
+ :notify => Puppet::Resource.new(:exec, "noop exec")
212
+ )
213
+
214
+ noop_exec = Puppet::Type.type(:exec).new(
215
+ :name => "noop exec",
216
+ :path => ENV["PATH"],
217
+ :command => touch(path),
218
+ :noop => true
219
+ )
220
+
221
+ catalog = mk_catalog(notify, noop_exec)
222
+ catalog.apply
223
+ expect(Puppet::FileSystem.exist?(path)).to be_falsey
224
+ end
225
+
226
+ it "should apply no resources whatsoever if a pre_run_check fails" do
227
+ path = tmpfile("path")
228
+ file = Puppet::Type.type(:file).new(
229
+ :path => path,
230
+ :ensure => "file"
231
+ )
232
+ notify = Puppet::Type.type(:notify).new(
233
+ :title => "foo"
234
+ )
235
+ notify.expects(:pre_run_check).raises(Puppet::Error, "fail for testing")
236
+
237
+ catalog = mk_catalog(file, notify)
238
+ expect { catalog.apply }.to raise_error(Puppet::Error, /Some pre-run checks failed/)
239
+ expect(Puppet::FileSystem.exist?(path)).not_to be_truthy
240
+ end
241
+
242
+ it "one failed refresh should propagate its failure to dependent refreshes", :unless => RUBY_PLATFORM == 'java' do
243
+ path = tmpfile("path")
244
+ newfile = tmpfile("file")
245
+ file = Puppet::Type.type(:file).new(
246
+ :path => path,
247
+ :ensure => "file"
248
+ )
249
+
250
+ exec1 = Puppet::Type.type(:exec).new(
251
+ :path => ENV["PATH"],
252
+ :command => touch(File.expand_path("/this/cannot/possibly/exist")),
253
+ :logoutput => true,
254
+ :refreshonly => true,
255
+ :subscribe => file,
256
+ :title => "one"
257
+ )
258
+
259
+ exec2 = Puppet::Type.type(:exec).new(
260
+ :path => ENV["PATH"],
261
+ :command => touch(newfile),
262
+ :logoutput => true,
263
+ :refreshonly => true,
264
+ :subscribe => [file, exec1],
265
+ :title => "two"
266
+ )
267
+
268
+ exec1.stubs(:err)
269
+
270
+ catalog = mk_catalog(file, exec1, exec2)
271
+ catalog.apply
272
+ expect(Puppet::FileSystem.exist?(newfile)).to be_falsey
273
+ end
274
+
275
+ # Ensure when resources have been generated with eval_generate that event
276
+ # propagation still works when filtering with tags
277
+ context "when filtering with tags", :unless => RUBY_PLATFORM == 'java' do
278
+ context "when resources are dependent on dynamically generated resources" do
279
+ it "should trigger (only) appropriately tagged dependent resources" do
280
+ source = dir_containing('sourcedir', {'foo' => 'bar'})
281
+ target = tmpdir('targetdir')
282
+ file1 = tmpfile("file1")
283
+ file2 = tmpfile("file2")
284
+
285
+ file = Puppet::Type.type(:file).new(
286
+ :path => target,
287
+ :source => source,
288
+ :ensure => :present,
289
+ :recurse => true,
290
+ :tag => "foo_tag",
291
+ )
292
+
293
+ exec1 = Puppet::Type.type(:exec).new(
294
+ :path => ENV["PATH"],
295
+ :command => touch(file1),
296
+ :refreshonly => true,
297
+ :subscribe => file,
298
+ :tag => "foo_tag",
299
+ )
300
+
301
+ exec2 = Puppet::Type.type(:exec).new(
302
+ :path => ENV["PATH"],
303
+ :command => touch(file2),
304
+ :refreshonly => true,
305
+ :subscribe => file,
306
+ )
307
+
308
+ Puppet[:tags] = "foo_tag"
309
+ catalog = mk_catalog(file, exec1, exec2)
310
+ catalog.apply
311
+ expect(Puppet::FileSystem.exist?(file1)).to be_truthy
312
+ expect(Puppet::FileSystem.exist?(file2)).to be_falsey
313
+ end
314
+
315
+ it "should trigger implicitly tagged dependent resources, ie via type name" do
316
+ file1 = tmpfile("file1")
317
+ file2 = tmpfile("file2")
318
+
319
+ exec1 = Puppet::Type.type(:exec).new(
320
+ :name => "exec1",
321
+ :path => ENV["PATH"],
322
+ :command => touch(file1),
323
+ )
324
+
325
+ exec1.stubs(:eval_generate).returns(
326
+ [ (Puppet::Type.type(:notify).new :name => "eval1_notify")]
327
+ )
328
+
329
+ exec2 = Puppet::Type.type(:exec).new(
330
+ :name => "exec2",
331
+ :path => ENV["PATH"],
332
+ :command => touch(file2),
333
+ :refreshonly => true,
334
+ :subscribe => exec1,
335
+ )
336
+ exec2.stubs(:eval_generate).returns(
337
+ [ (Puppet::Type.type(:notify).new :name => "eval2_notify")]
338
+ )
339
+
340
+ Puppet[:tags] = "exec"
341
+ catalog = mk_catalog(exec1, exec2)
342
+ catalog.apply
343
+ expect(Puppet::FileSystem.exist?(file1)).to be_truthy
344
+ expect(Puppet::FileSystem.exist?(file2)).to be_truthy
345
+ end
346
+ end
347
+
348
+ it "should propagate events correctly from a tagged container when running with tags" do
349
+ file1 = tmpfile("original_tag")
350
+ file2 = tmpfile("tag_propagation")
351
+ command1 = usr_bin_touch(file1)
352
+ command2 = usr_bin_touch(file2)
353
+ manifest = <<-"MANIFEST"
354
+ class foo {
355
+ exec { 'notify test':
356
+ command => '#{command1}',
357
+ refreshonly => true,
358
+ }
359
+ }
360
+
361
+ class test {
362
+ include foo
363
+
364
+ exec { 'test':
365
+ command => '#{command2}',
366
+ notify => Class['foo'],
367
+ }
368
+ }
369
+
370
+ include test
371
+ MANIFEST
372
+
373
+ Puppet[:tags] = 'test'
374
+ apply_compiled_manifest(manifest)
375
+ expect(Puppet::FileSystem.exist?(file1)).to be_truthy
376
+ expect(Puppet::FileSystem.exist?(file2)).to be_truthy
377
+ end
378
+ end
379
+
380
+ describe "skipping resources" do
381
+ let(:fname) { tmpfile("exec") }
382
+
383
+ let(:file) do
384
+ Puppet::Type.type(:file).new(
385
+ :name => tmpfile("file"),
386
+ :ensure => "file",
387
+ :backup => false
388
+ )
389
+ end
390
+
391
+ let(:exec) do
392
+ Puppet::Type.type(:exec).new(
393
+ :name => touch(fname),
394
+ :path => touch_path,
395
+ :subscribe => Puppet::Resource.new("file", file.name)
396
+ )
397
+ end
398
+
399
+ it "does not trigger unscheduled resources", :unless => RUBY_PLATFORM == 'java' do
400
+ catalog = mk_catalog
401
+ catalog.add_resource(*Puppet::Type.type(:schedule).mkdefaultschedules)
402
+
403
+ Puppet[:ignoreschedules] = false
404
+
405
+ exec[:schedule] = "monthly"
406
+
407
+ catalog.add_resource(file, exec)
408
+
409
+ # Run it once so further runs don't schedule the resource
410
+ catalog.apply
411
+ expect(Puppet::FileSystem.exist?(fname)).to be_truthy
412
+
413
+ # Now remove it, so it can get created again
414
+ Puppet::FileSystem.unlink(fname)
415
+
416
+ file[:content] = "some content"
417
+
418
+ catalog.apply
419
+ expect(Puppet::FileSystem.exist?(fname)).to be_falsey
420
+ end
421
+
422
+ it "does not trigger untagged resources" do
423
+ catalog = mk_catalog
424
+
425
+ Puppet[:tags] = "runonly"
426
+ file.tag("runonly")
427
+
428
+ catalog.add_resource(file, exec)
429
+ catalog.apply
430
+ expect(Puppet::FileSystem.exist?(fname)).to be_falsey
431
+ end
432
+
433
+ it "does not trigger skip-tagged resources" do
434
+ catalog = mk_catalog
435
+
436
+ Puppet[:skip_tags] = "skipme"
437
+ exec.tag("skipme")
438
+
439
+ catalog.add_resource(file, exec)
440
+ catalog.apply
441
+ expect(Puppet::FileSystem.exist?(fname)).to be_falsey
442
+ end
443
+
444
+ it "does not trigger resources with failed dependencies" do
445
+ catalog = mk_catalog
446
+ file[:path] = make_absolute("/foo/bar/baz")
447
+
448
+ catalog.add_resource(file, exec)
449
+ catalog.apply
450
+
451
+ expect(Puppet::FileSystem.exist?(fname)).to be_falsey
452
+ end
453
+ end
454
+
455
+ it "should not attempt to evaluate resources with failed dependencies", :unless => RUBY_PLATFORM == 'java' do
456
+
457
+ exec = Puppet::Type.type(:exec).new(
458
+ :command => "#{File.expand_path('/bin/mkdir')} /this/path/cannot/possibly/exist",
459
+ :title => "mkdir"
460
+ )
461
+
462
+ file1 = Puppet::Type.type(:file).new(
463
+ :title => "file1",
464
+ :path => tmpfile("file1"),
465
+ :require => exec,
466
+ :ensure => :file
467
+ )
468
+
469
+ file2 = Puppet::Type.type(:file).new(
470
+ :title => "file2",
471
+ :path => tmpfile("file2"),
472
+ :require => file1,
473
+ :ensure => :file
474
+ )
475
+
476
+ catalog = mk_catalog(exec, file1, file2)
477
+ transaction = catalog.apply
478
+
479
+ expect(Puppet::FileSystem.exist?(file1[:path])).to be_falsey
480
+ expect(Puppet::FileSystem.exist?(file2[:path])).to be_falsey
481
+
482
+ expect(transaction.resource_status(file1).skipped).to be_truthy
483
+ expect(transaction.resource_status(file2).skipped).to be_truthy
484
+
485
+ expect(transaction.resource_status(file1).failed_dependencies).to eq([exec])
486
+ expect(transaction.resource_status(file2).failed_dependencies).to eq([exec])
487
+ end
488
+
489
+ it "on failure, skips dynamically-generated dependents", :unless => RUBY_PLATFORM == 'java' do
490
+ exec = Puppet::Type.type(:exec).new(
491
+ :command => "#{File.expand_path('/bin/mkdir')} /this/path/cannot/possibly/exist",
492
+ :title => "mkdir"
493
+ )
494
+
495
+ tmp = tmpfile("dir1")
496
+ FileUtils.mkdir_p(tmp)
497
+ FileUtils.mkdir_p(File.join(tmp, "foo"))
498
+
499
+ purge_dir = Puppet::Type.type(:file).new(
500
+ :title => "dir1",
501
+ :path => tmp,
502
+ :require => exec,
503
+ :ensure => :directory,
504
+ :recurse => true,
505
+ :purge => true
506
+ )
507
+
508
+ catalog = mk_catalog(exec, purge_dir)
509
+ txn = catalog.apply
510
+
511
+ expect(txn.resource_status(purge_dir).skipped).to be_truthy
512
+
513
+ children = catalog.relationship_graph.direct_dependents_of(purge_dir)
514
+
515
+ children.each do |child|
516
+ expect(txn.resource_status(child).skipped).to be_truthy
517
+ end
518
+
519
+ expect(Puppet::FileSystem.exist?(File.join(tmp, "foo"))).to be_truthy
520
+ end
521
+
522
+ it "should not trigger subscribing resources on failure", :unless => RUBY_PLATFORM == 'java' do
523
+ file1 = tmpfile("file1")
524
+ file2 = tmpfile("file2")
525
+
526
+ create_file1 = Puppet::Type.type(:exec).new(
527
+ :command => usr_bin_touch(file1)
528
+ )
529
+
530
+ exec = Puppet::Type.type(:exec).new(
531
+ :command => "#{File.expand_path('/bin/mkdir')} /this/path/cannot/possibly/exist",
532
+ :title => "mkdir",
533
+ :notify => create_file1
534
+ )
535
+
536
+ create_file2 = Puppet::Type.type(:exec).new(
537
+ :command => usr_bin_touch(file2),
538
+ :subscribe => exec
539
+ )
540
+
541
+ catalog = mk_catalog(exec, create_file1, create_file2)
542
+ catalog.apply
543
+
544
+ expect(Puppet::FileSystem.exist?(file1)).to be_falsey
545
+ expect(Puppet::FileSystem.exist?(file2)).to be_falsey
546
+ end
547
+
548
+ # #801 -- resources only checked in noop should be rescheduled immediately.
549
+ it "should immediately reschedule noop resources" do
550
+ Puppet::Type.type(:schedule).mkdefaultschedules
551
+ resource = Puppet::Type.type(:notify).new(:name => "mymessage", :noop => true)
552
+ catalog = Puppet::Resource::Catalog.new
553
+ catalog.add_resource resource
554
+
555
+ trans = catalog.apply
556
+
557
+ expect(trans.resource_harness).to be_scheduled(resource)
558
+ end
559
+ end
@@ -579,7 +579,7 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
579
579
  if Puppet::Util::Platform.windows? && ['sha512', 'sha384'].include?(example.metadata[:digest_algorithm])
580
580
  skip "PUP-8257: Skip file bucket test on windows for #{example.metadata[:digest_algorithm]} due to long path names"
581
581
  end
582
-
582
+
583
583
  bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
584
584
  file = described_class.new({:path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo", :force => true}.merge(resource_options))
585
585
  catalog.add_resource file
@@ -1283,7 +1283,7 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
1283
1283
  describe "when sourcing" do
1284
1284
  it "should give a deprecation warning when the user sets source_permissions" do
1285
1285
  Puppet.expects(:puppet_deprecation_warning).with(
1286
- 'The `source_permissions` parameter is deprecated. Explicitly set `owner`, `group`, and `mode`.',
1286
+ 'The `source_permissions` parameter is deprecated. Explicitly set `owner`, `group`, and `mode`.',
1287
1287
  {:file => 'my/file.pp', :line => 5})
1288
1288
 
1289
1289
  catalog.add_resource described_class.new(:path => path, :content => 'this is content', :source_permissions => :use_when_creating)
@@ -1525,12 +1525,12 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
1525
1525
  catalog.apply
1526
1526
  end
1527
1527
 
1528
- it "should allow the user to explicitly set the mode to 4" do
1528
+ it "should not allow the user to explicitly set the mode to 4 ,and correct to 7" do
1529
1529
  system_aces = get_aces_for_path_by_sid(path, @sids[:system])
1530
1530
  expect(system_aces).not_to be_empty
1531
1531
 
1532
1532
  system_aces.each do |ace|
1533
- expect(ace.mask).to eq(Puppet::Util::Windows::File::FILE_GENERIC_READ)
1533
+ expect(ace.mask).to eq(Puppet::Util::Windows::File::FILE_ALL_ACCESS)
1534
1534
  end
1535
1535
  end
1536
1536
 
@@ -1612,13 +1612,13 @@ describe Puppet::Type.type(:file), :uses_checksums => true do
1612
1612
  catalog.apply
1613
1613
  end
1614
1614
 
1615
- it "should allow the user to explicitly set the mode to 4" do
1615
+ it "should not allow the user to explicitly set the mode to 4, and correct to 7" do
1616
1616
  system_aces = get_aces_for_path_by_sid(dir, @sids[:system])
1617
1617
  expect(system_aces).not_to be_empty
1618
1618
 
1619
1619
  system_aces.each do |ace|
1620
1620
  # unlike files, Puppet sets execute bit on directories that are readable
1621
- expect(ace.mask).to eq(Puppet::Util::Windows::File::FILE_GENERIC_READ | Puppet::Util::Windows::File::FILE_GENERIC_EXECUTE)
1621
+ expect(ace.mask).to eq(Puppet::Util::Windows::File::FILE_ALL_ACCESS)
1622
1622
  end
1623
1623
  end
1624
1624
 
@@ -253,5 +253,44 @@ describe Puppet::Util::Windows::Registry do
253
253
  end
254
254
  end
255
255
  end
256
+
257
+ context "#values_by_name" do
258
+ let(:hkey) { stub 'hklm' }
259
+ let(:subkey) { stub 'subkey' }
260
+
261
+ before :each do
262
+ subject.stubs(:root).returns(hkey)
263
+ end
264
+
265
+ context "when reading values" do
266
+ let (:hklm) { Win32::Registry::HKEY_LOCAL_MACHINE }
267
+ let (:puppet_key) { "SOFTWARE\\Puppet Labs"}
268
+ let (:subkey_name) { "PuppetRegistryTest#{SecureRandom.uuid}" }
269
+
270
+ before(:each) do
271
+ hklm.create("#{puppet_key}\\#{subkey_name}", Win32::Registry::KEY_ALL_ACCESS) do |reg|
272
+ reg.write('valuename1', Win32::Registry::REG_SZ, 'value1')
273
+ reg.write('valuename2', Win32::Registry::REG_SZ, 'value2')
274
+ end
275
+ end
276
+
277
+ after(:each) do
278
+ hklm.open(puppet_key, Win32::Registry::KEY_ALL_ACCESS) do |reg|
279
+ subject.delete_key(reg, subkey_name)
280
+ end
281
+ end
282
+
283
+ it "should return only the values for the names specified" do
284
+ hklm.open("#{puppet_key}\\#{subkey_name}", Win32::Registry::KEY_ALL_ACCESS) do |reg_key|
285
+ vals = subject.values_by_name(reg_key, ['valuename1', 'missingname'])
286
+
287
+ expect(vals).to have_key('valuename1')
288
+ expect(vals).to_not have_key('valuename2')
289
+ expect(vals['valuename1']).to eq('value1')
290
+ expect(vals['missingname']).to be_nil
291
+ end
292
+ end
293
+ end
294
+ end
256
295
  end
257
296
  end