puppet 6.19.0-x86-mingw32 → 6.22.1-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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +2 -16
  3. data/Gemfile +3 -1
  4. data/Gemfile.lock +50 -39
  5. data/ext/project_data.yaml +2 -2
  6. data/lib/puppet/application.rb +10 -6
  7. data/lib/puppet/application/agent.rb +1 -0
  8. data/lib/puppet/application/apply.rb +3 -2
  9. data/lib/puppet/application/device.rb +1 -0
  10. data/lib/puppet/application/filebucket.rb +2 -2
  11. data/lib/puppet/application/script.rb +1 -0
  12. data/lib/puppet/application/ssl.rb +11 -0
  13. data/lib/puppet/application_support.rb +7 -0
  14. data/lib/puppet/configurer.rb +28 -18
  15. data/lib/puppet/defaults.rb +46 -20
  16. data/lib/puppet/environments.rb +54 -55
  17. data/lib/puppet/face/config.rb +10 -0
  18. data/lib/puppet/face/epp.rb +12 -2
  19. data/lib/puppet/face/facts.rb +158 -0
  20. data/lib/puppet/ffi/posix.rb +10 -0
  21. data/lib/puppet/ffi/posix/constants.rb +14 -0
  22. data/lib/puppet/ffi/posix/functions.rb +24 -0
  23. data/lib/puppet/file_system/memory_file.rb +8 -1
  24. data/lib/puppet/file_system/windows.rb +2 -0
  25. data/lib/puppet/functions/epp.rb +1 -0
  26. data/lib/puppet/functions/inline_epp.rb +1 -0
  27. data/lib/puppet/functions/partition.rb +8 -0
  28. data/lib/puppet/indirector/fact_search.rb +60 -0
  29. data/lib/puppet/indirector/facts/facter.rb +24 -3
  30. data/lib/puppet/indirector/facts/json.rb +27 -0
  31. data/lib/puppet/indirector/facts/yaml.rb +3 -58
  32. data/lib/puppet/indirector/json.rb +5 -1
  33. data/lib/puppet/indirector/node/json.rb +8 -0
  34. data/lib/puppet/indirector/report/json.rb +34 -0
  35. data/lib/puppet/module_tool/applications/installer.rb +48 -2
  36. data/lib/puppet/module_tool/errors/shared.rb +17 -2
  37. data/lib/puppet/network/formats.rb +69 -1
  38. data/lib/puppet/network/http/factory.rb +4 -0
  39. data/lib/puppet/pal/pal_impl.rb +70 -17
  40. data/lib/puppet/parser/ast/leaf.rb +3 -2
  41. data/lib/puppet/parser/templatewrapper.rb +1 -1
  42. data/lib/puppet/pops/evaluator/deferred_resolver.rb +5 -3
  43. data/lib/puppet/pops/evaluator/evaluator_impl.rb +22 -3
  44. data/lib/puppet/pops/model/ast_transformer.rb +1 -1
  45. data/lib/puppet/property/list.rb +1 -1
  46. data/lib/puppet/provider/group/groupadd.rb +13 -8
  47. data/lib/puppet/provider/package/apt.rb +34 -2
  48. data/lib/puppet/provider/package/aptitude.rb +6 -0
  49. data/lib/puppet/provider/package/dnfmodule.rb +1 -1
  50. data/lib/puppet/provider/service/debian.rb +2 -0
  51. data/lib/puppet/provider/service/systemd.rb +1 -1
  52. data/lib/puppet/provider/user/aix.rb +2 -2
  53. data/lib/puppet/provider/user/useradd.rb +62 -8
  54. data/lib/puppet/reference/configuration.rb +6 -5
  55. data/lib/puppet/settings.rb +43 -15
  56. data/lib/puppet/settings/alias_setting.rb +37 -0
  57. data/lib/puppet/settings/base_setting.rb +26 -2
  58. data/lib/puppet/settings/environment_conf.rb +1 -0
  59. data/lib/puppet/type/package.rb +3 -3
  60. data/lib/puppet/util/autoload.rb +1 -8
  61. data/lib/puppet/util/fact_dif.rb +81 -0
  62. data/lib/puppet/util/monkey_patches.rb +7 -0
  63. data/lib/puppet/util/posix.rb +54 -5
  64. data/lib/puppet/util/rubygems.rb +5 -1
  65. data/lib/puppet/util/windows/adsi.rb +46 -0
  66. data/lib/puppet/util/windows/api_types.rb +1 -1
  67. data/lib/puppet/util/windows/principal.rb +9 -2
  68. data/lib/puppet/util/windows/service.rb +1 -1
  69. data/lib/puppet/util/windows/sid.rb +4 -2
  70. data/lib/puppet/version.rb +1 -1
  71. data/locales/puppet.pot +295 -219
  72. data/man/man5/puppet.conf.5 +15 -7
  73. data/man/man8/puppet-agent.8 +2 -2
  74. data/man/man8/puppet-apply.8 +2 -2
  75. data/man/man8/puppet-catalog.8 +1 -1
  76. data/man/man8/puppet-config.8 +1 -1
  77. data/man/man8/puppet-describe.8 +1 -1
  78. data/man/man8/puppet-device.8 +2 -2
  79. data/man/man8/puppet-doc.8 +1 -1
  80. data/man/man8/puppet-epp.8 +1 -1
  81. data/man/man8/puppet-facts.8 +90 -1
  82. data/man/man8/puppet-filebucket.8 +3 -3
  83. data/man/man8/puppet-generate.8 +1 -1
  84. data/man/man8/puppet-help.8 +1 -1
  85. data/man/man8/puppet-key.8 +1 -1
  86. data/man/man8/puppet-lookup.8 +1 -1
  87. data/man/man8/puppet-man.8 +1 -1
  88. data/man/man8/puppet-module.8 +1 -1
  89. data/man/man8/puppet-node.8 +4 -1
  90. data/man/man8/puppet-parser.8 +1 -1
  91. data/man/man8/puppet-plugin.8 +1 -1
  92. data/man/man8/puppet-report.8 +4 -1
  93. data/man/man8/puppet-resource.8 +1 -1
  94. data/man/man8/puppet-script.8 +2 -2
  95. data/man/man8/puppet-ssl.8 +5 -1
  96. data/man/man8/puppet-status.8 +1 -1
  97. data/man/man8/puppet.8 +2 -2
  98. data/spec/fixtures/integration/application/agent/cached_deferred_catalog.json +91 -0
  99. data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services_vendor_preset +9 -0
  100. data/spec/fixtures/unit/provider/user/aix/aix_passwd_file.out +4 -0
  101. data/spec/integration/application/agent_spec.rb +160 -3
  102. data/spec/integration/application/apply_spec.rb +19 -0
  103. data/spec/integration/application/plugin_spec.rb +1 -1
  104. data/spec/integration/defaults_spec.rb +0 -7
  105. data/spec/integration/environments/setting_hooks_spec.rb +1 -1
  106. data/spec/integration/http/client_spec.rb +12 -0
  107. data/spec/integration/indirector/direct_file_server_spec.rb +1 -3
  108. data/spec/integration/resource/type_collection_spec.rb +2 -6
  109. data/spec/integration/transaction_spec.rb +4 -9
  110. data/spec/integration/util/windows/adsi_spec.rb +21 -1
  111. data/spec/integration/util/windows/principal_spec.rb +21 -0
  112. data/spec/integration/util/windows/registry_spec.rb +6 -10
  113. data/spec/lib/puppet_spec/settings.rb +6 -1
  114. data/spec/spec_helper.rb +12 -5
  115. data/spec/unit/agent_spec.rb +8 -6
  116. data/spec/unit/application/agent_spec.rb +0 -1
  117. data/spec/unit/application/config_spec.rb +224 -4
  118. data/spec/unit/application/facts_spec.rb +482 -3
  119. data/spec/unit/application/filebucket_spec.rb +0 -2
  120. data/spec/unit/application/ssl_spec.rb +23 -0
  121. data/spec/unit/application_spec.rb +51 -9
  122. data/spec/unit/confine/feature_spec.rb +1 -1
  123. data/spec/unit/confine_spec.rb +8 -2
  124. data/spec/unit/defaults_spec.rb +36 -1
  125. data/spec/unit/environments_spec.rb +221 -68
  126. data/spec/unit/face/config_spec.rb +27 -32
  127. data/spec/unit/face/facts_spec.rb +4 -0
  128. data/spec/unit/face/node_spec.rb +0 -11
  129. data/spec/unit/file_serving/configuration/parser_spec.rb +0 -1
  130. data/spec/unit/file_serving/metadata_spec.rb +3 -3
  131. data/spec/unit/file_serving/terminus_helper_spec.rb +11 -4
  132. data/spec/unit/file_system_spec.rb +9 -0
  133. data/spec/unit/forge/module_release_spec.rb +2 -7
  134. data/spec/unit/functions/inline_epp_spec.rb +26 -1
  135. data/spec/unit/http/service/compiler_spec.rb +49 -0
  136. data/spec/unit/http/service_spec.rb +1 -1
  137. data/spec/unit/indirector/face_spec.rb +0 -1
  138. data/spec/unit/indirector/facts/facter_spec.rb +95 -1
  139. data/spec/unit/indirector/facts/json_spec.rb +255 -0
  140. data/spec/unit/indirector/file_bucket_file/selector_spec.rb +26 -8
  141. data/spec/unit/indirector/indirection_spec.rb +8 -12
  142. data/spec/unit/indirector/key/file_spec.rb +0 -1
  143. data/spec/unit/indirector/node/json_spec.rb +33 -0
  144. data/spec/{integration/indirector/report/yaml.rb → unit/indirector/report/json_spec.rb} +13 -24
  145. data/spec/unit/indirector/report/yaml_spec.rb +72 -8
  146. data/spec/unit/indirector_spec.rb +2 -2
  147. data/spec/unit/module_tool/applications/installer_spec.rb +66 -0
  148. data/spec/unit/network/authconfig_spec.rb +0 -3
  149. data/spec/unit/network/formats_spec.rb +41 -0
  150. data/spec/unit/network/http/api/indirected_routes_spec.rb +0 -9
  151. data/spec/unit/network/http/factory_spec.rb +19 -0
  152. data/spec/unit/network/http/handler_spec.rb +0 -5
  153. data/spec/unit/parser/compiler_spec.rb +3 -19
  154. data/spec/unit/parser/resource_spec.rb +14 -8
  155. data/spec/unit/parser/templatewrapper_spec.rb +4 -3
  156. data/spec/unit/pops/evaluator/deferred_resolver_spec.rb +20 -0
  157. data/spec/unit/property_spec.rb +1 -0
  158. data/spec/unit/provider/group/groupadd_spec.rb +5 -2
  159. data/spec/unit/provider/nameservice_spec.rb +66 -65
  160. data/spec/unit/provider/package/apt_spec.rb +28 -23
  161. data/spec/unit/provider/package/aptitude_spec.rb +1 -1
  162. data/spec/unit/provider/package/base_spec.rb +6 -5
  163. data/spec/unit/provider/package/dnfmodule_spec.rb +10 -1
  164. data/spec/unit/provider/package/pacman_spec.rb +18 -12
  165. data/spec/unit/provider/package/pip_spec.rb +6 -11
  166. data/spec/unit/provider/package/pkgdmg_spec.rb +0 -4
  167. data/spec/unit/provider/service/systemd_spec.rb +11 -0
  168. data/spec/unit/provider/user/aix_spec.rb +5 -0
  169. data/spec/unit/provider/user/hpux_spec.rb +1 -1
  170. data/spec/unit/provider/user/pw_spec.rb +2 -0
  171. data/spec/unit/provider/user/useradd_spec.rb +71 -3
  172. data/spec/unit/provider_spec.rb +8 -10
  173. data/spec/unit/puppet_pal_catalog_spec.rb +45 -0
  174. data/spec/unit/resource/capability_finder_spec.rb +6 -1
  175. data/spec/unit/resource/catalog_spec.rb +1 -1
  176. data/spec/unit/resource/type_spec.rb +1 -1
  177. data/spec/unit/resource_spec.rb +11 -10
  178. data/spec/unit/settings_spec.rb +543 -228
  179. data/spec/unit/ssl/base_spec.rb +0 -1
  180. data/spec/unit/ssl/host_spec.rb +0 -5
  181. data/spec/unit/ssl/ssl_provider_spec.rb +14 -8
  182. data/spec/unit/transaction/additional_resource_generator_spec.rb +3 -7
  183. data/spec/unit/transaction/event_manager_spec.rb +14 -11
  184. data/spec/unit/transaction_spec.rb +13 -4
  185. data/spec/unit/type/file/content_spec.rb +0 -1
  186. data/spec/unit/type/file/selinux_spec.rb +0 -2
  187. data/spec/unit/type/file_spec.rb +0 -6
  188. data/spec/unit/type/group_spec.rb +13 -6
  189. data/spec/unit/type/resources_spec.rb +7 -7
  190. data/spec/unit/type/service_spec.rb +1 -1
  191. data/spec/unit/type/tidy_spec.rb +0 -1
  192. data/spec/unit/type_spec.rb +2 -2
  193. data/spec/unit/util/at_fork_spec.rb +2 -2
  194. data/spec/unit/util/autoload_spec.rb +5 -1
  195. data/spec/unit/util/backups_spec.rb +1 -2
  196. data/spec/unit/util/execution_spec.rb +15 -11
  197. data/spec/unit/util/inifile_spec.rb +6 -14
  198. data/spec/unit/util/log_spec.rb +8 -7
  199. data/spec/unit/util/logging_spec.rb +3 -3
  200. data/spec/unit/util/posix_spec.rb +363 -15
  201. data/spec/unit/util/rubygems_spec.rb +2 -2
  202. data/spec/unit/util/selinux_spec.rb +76 -52
  203. data/spec/unit/util/storage_spec.rb +3 -1
  204. data/spec/unit/util/suidmanager_spec.rb +44 -41
  205. data/spec/unit/util/windows/sid_spec.rb +6 -0
  206. data/spec/unit/util_spec.rb +13 -6
  207. metadata +31 -16
  208. data/spec/integration/application/config_spec.rb +0 -74
  209. data/spec/lib/matchers/include.rb +0 -27
  210. data/spec/lib/matchers/include_spec.rb +0 -32
  211. data/spec/unit/face/catalog_spec.rb +0 -6
  212. data/spec/unit/face/module_spec.rb +0 -3
@@ -42,7 +42,6 @@ describe Puppet::Application::Filebucket do
42
42
  describe "during setup" do
43
43
  before :each do
44
44
  allow(Puppet::Log).to receive(:newdestination)
45
- allow(Puppet).to receive(:settraps)
46
45
  allow(Puppet::FileBucket::Dipper).to receive(:new)
47
46
  allow(@filebucket.options).to receive(:[])
48
47
  end
@@ -157,7 +156,6 @@ describe Puppet::Application::Filebucket do
157
156
  describe "when running" do
158
157
  before :each do
159
158
  allow(Puppet::Log).to receive(:newdestination)
160
- allow(Puppet).to receive(:settraps)
161
159
  allow(Puppet::FileBucket::Dipper).to receive(:new)
162
160
  allow(@filebucket.options).to receive(:[])
163
161
 
@@ -432,4 +432,27 @@ describe Puppet::Application::Ssl, unless: Puppet::Util::Platform.jruby? do
432
432
  expects_command_to_pass
433
433
  end
434
434
  end
435
+
436
+ context 'when showing' do
437
+ before do
438
+ ssl.command_line.args << 'show'
439
+ File.write(Puppet[:hostcert], @host[:cert].to_pem)
440
+ end
441
+
442
+ it 'reports if the key is missing' do
443
+ File.delete(Puppet[:hostprivkey])
444
+
445
+ expects_command_to_fail(/The private key is missing from/)
446
+ end
447
+
448
+ it 'reports if the cert is missing' do
449
+ File.delete(Puppet[:hostcert])
450
+
451
+ expects_command_to_fail(/The client certificate is missing from/)
452
+ end
453
+
454
+ it 'prints certificate information' do
455
+ expects_command_to_pass(@host[:cert].to_text)
456
+ end
457
+ end
435
458
  end
@@ -7,8 +7,10 @@ require 'timeout'
7
7
 
8
8
  describe Puppet::Application do
9
9
  before(:each) do
10
- @app = Class.new(Puppet::Application).new
11
- @appclass = @app.class
10
+ @appclass = Class.new(Puppet::Application) do
11
+ def handle_unknown(opt, arg); end
12
+ end
13
+ @app = @appclass.new
12
14
 
13
15
  allow(@app).to receive(:name).and_return("test_app")
14
16
  end
@@ -511,6 +513,40 @@ describe Puppet::Application do
511
513
 
512
514
  expect { @app.configure_indirector_routes }.to raise_error(Puppet::Error, /mapping values are not allowed/)
513
515
  end
516
+
517
+ it "should treat master routes on server application" do
518
+ allow(@app).to receive(:name).and_return("server")
519
+
520
+ Puppet[:route_file] = tmpfile('routes')
521
+ File.open(Puppet[:route_file], 'w') do |f|
522
+ f.print <<-ROUTES
523
+ master:
524
+ node:
525
+ terminus: exec
526
+ ROUTES
527
+ end
528
+
529
+ @app.configure_indirector_routes
530
+
531
+ expect(Puppet::Node.indirection.terminus_class).to eq('exec')
532
+ end
533
+
534
+ it "should treat server routes on master application" do
535
+ allow(@app).to receive(:name).and_return("master")
536
+
537
+ Puppet[:route_file] = tmpfile('routes')
538
+ File.open(Puppet[:route_file], 'w') do |f|
539
+ f.print <<-ROUTES
540
+ server:
541
+ node:
542
+ terminus: exec
543
+ ROUTES
544
+ end
545
+
546
+ @app.configure_indirector_routes
547
+
548
+ expect(Puppet::Node.indirection.terminus_class).to eq('exec')
549
+ end
514
550
  end
515
551
 
516
552
  describe "when running" do
@@ -560,13 +596,6 @@ describe Puppet::Application do
560
596
  end
561
597
 
562
598
  it "should raise an error if dispatch returns no command" do
563
- allow(@app).to receive(:get_command).and_return(nil)
564
- expect(Puppet).to receive(:send_log).with(:err, "Could not run: No valid command or main")
565
- expect { @app.run }.to exit_with 1
566
- end
567
-
568
- it "should raise an error if dispatch returns an invalid command" do
569
- allow(@app).to receive(:get_command).and_return(:this_function_doesnt_exist)
570
599
  expect(Puppet).to receive(:send_log).with(:err, "Could not run: No valid command or main")
571
600
  expect { @app.run }.to exit_with 1
572
601
  end
@@ -684,5 +713,18 @@ describe Puppet::Application do
684
713
 
685
714
  @app.handle_logdest_arg(nil)
686
715
  end
716
+
717
+ it "accepts multiple destinations as a comma sepparated list" do
718
+ dest1 = '/tmp/path1'
719
+ dest2 = 'console'
720
+ dest3 = '/tmp/path2'
721
+ dest_args = [dest1, dest2, dest3].join(' , ')
722
+
723
+ [dest1, dest2, dest3].each do |dest|
724
+ expect(Puppet::Util::Log).to receive(:newdestination).with(dest)
725
+ end
726
+
727
+ @app.handle_logdest_arg(dest_args)
728
+ end
687
729
  end
688
730
  end
@@ -22,7 +22,7 @@ describe Puppet::Confine::Feature do
22
22
  end
23
23
 
24
24
  it "should use the Puppet features instance to test validity" do
25
- expect(Puppet.features).to receive(:myfeature?)
25
+ Puppet.features.add(:myfeature) do true end
26
26
  @confine.valid?
27
27
  end
28
28
 
@@ -2,6 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  require 'puppet/confine'
4
4
 
5
+ class Puppet::TestConfine < Puppet::Confine
6
+ def pass?(value)
7
+ false
8
+ end
9
+ end
10
+
5
11
  describe Puppet::Confine do
6
12
  it "should require a value" do
7
13
  expect { Puppet::Confine.new }.to raise_error(ArgumentError)
@@ -33,7 +39,7 @@ describe Puppet::Confine do
33
39
 
34
40
  describe "when testing all values" do
35
41
  before do
36
- @confine = Puppet::Confine.new(%w{a b c})
42
+ @confine = Puppet::TestConfine.new(%w{a b c})
37
43
  @confine.label = "foo"
38
44
  end
39
45
 
@@ -64,7 +70,7 @@ describe Puppet::Confine do
64
70
  end
65
71
 
66
72
  describe "when testing the result of the values" do
67
- before { @confine = Puppet::Confine.new(%w{a b c d}) }
73
+ before { @confine = Puppet::TestConfine.new(%w{a b c d}) }
68
74
 
69
75
  it "should return an array with the result of the test for each value" do
70
76
  allow(@confine).to receive(:pass?).and_return(true)
@@ -189,6 +189,7 @@ describe "Defaults" do
189
189
 
190
190
  it "raises an exception if facter-ng could not be loaded" do
191
191
  allow_any_instance_of(Puppet::Settings::BooleanSetting).to receive(:require).with('facter-ng').and_raise(LoadError)
192
+ allow(Facter).to receive(:value).with('facterversion').and_return('3.11.4')
192
193
 
193
194
  expect{ Puppet.settings[:facterng] = true }.to raise_exception ArgumentError, 'facter-ng could not be loaded'
194
195
  end
@@ -198,7 +199,9 @@ describe "Defaults" do
198
199
  @original_facter = Object.const_get(:Facter)
199
200
 
200
201
  Object.send(:remove_const, :Facter)
201
- Object.const_set(:Facter, Module.new)
202
+ facter = double('facter')
203
+ allow(facter).to receive(:value).with('facterversion').and_return('3.11.4')
204
+ Object.const_set(:Facter, facter)
202
205
 
203
206
  allow_any_instance_of(Puppet::Settings::BooleanSetting).to receive(:require).with('facter-ng').and_return(true)
204
207
  allow(Facter).to receive(:respond_to?).and_return(false)
@@ -215,4 +218,36 @@ describe "Defaults" do
215
218
  end
216
219
  end
217
220
  end
221
+
222
+ describe "deprecated settings" do
223
+ it 'does not issue a deprecation warning by default' do
224
+ expect(Puppet).to receive(:deprecation_warning).never
225
+
226
+ Puppet.initialize_settings
227
+ end
228
+
229
+ it 'issues a deprecation warning when func3x_check is disabled' do
230
+ Puppet[:func3x_check] = false
231
+
232
+ expect(Puppet).to receive(:deprecation_warning).with("The 'func3x_check' setting is deprecated and will be removed in a future release.")
233
+
234
+ Puppet.initialize_settings
235
+ end
236
+ end
237
+
238
+ describe "the default cadir", :unless => Puppet::Util::Platform.windows? do
239
+ it 'defaults to inside the ssldir if not migrated' do
240
+ expect(File).to receive(:exist?).with('/etc/puppetlabs/puppetserver/ca/ca_crt.pem').and_return(false)
241
+ expect(Puppet.default_cadir).to eq("#{Puppet[:ssldir]}/ca")
242
+ end
243
+
244
+ it 'returns the new location if there is CA content there' do
245
+ expect(File).to receive(:exist?).with('/etc/puppetlabs/puppetserver/ca/ca_crt.pem').and_return(true)
246
+ expect(Puppet.default_cadir).to eq('/etc/puppetlabs/puppetserver/ca')
247
+ end
248
+
249
+ it 'returns an empty string for Windows platforms', :if => Puppet::Util::Platform.windows? do
250
+ expect(Puppet.default_cadir).to eq("")
251
+ end
252
+ end
218
253
  end
@@ -1,13 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'puppet/environments'
3
3
  require 'puppet/file_system'
4
- require 'matchers/include'
5
- require 'matchers/include_in_order'
6
4
 
7
- module PuppetEnvironments
8
5
  describe Puppet::Environments do
9
- include Matchers::Include
10
-
11
6
  FS = Puppet::FileSystem
12
7
 
13
8
  before(:each) do
@@ -49,7 +44,7 @@ describe Puppet::Environments do
49
44
  loader_from(:filesystem => [directory_tree, global_path_1, global_path_2],
50
45
  :directory => directory_tree.children.first,
51
46
  :modulepath => [global_path_1_location, global_path_2_location]) do |loader|
52
- expect(loader.list).to include_in_any_order(
47
+ expect(loader.list).to contain_exactly(
53
48
  environment(:an_environment).
54
49
  with_manifest("#{FS.path_string(directory_tree)}/envdir/an_environment/manifests").
55
50
  with_modulepath(["#{FS.path_string(directory_tree)}/envdir/an_environment/modules",
@@ -87,7 +82,7 @@ describe Puppet::Environments do
87
82
 
88
83
  loader_from(:filesystem => [envdir],
89
84
  :directory => envdir) do |loader|
90
- expect(loader.list).to include_in_any_order(environment(:env1), environment(:env2))
85
+ expect(loader.list).to contain_exactly(environment(:env1), environment(:env2))
91
86
  end
92
87
  end
93
88
 
@@ -406,33 +401,29 @@ config_version=$vardir/random/scripts
406
401
  ]),
407
402
  ])
408
403
 
409
- FS.overlay(original_envdir) do
410
- dir_loader = Puppet::Environments::Directories.new(original_envdir, [])
411
- loader = Puppet::Environments::Cached.new(dir_loader)
412
- Puppet.override(:environments => loader) do
413
- original_env = loader.get("env3") # force the environment.conf to be read
414
-
415
- changed_envdir = FS::MemoryFile.a_directory(base_dir, [
416
- FS::MemoryFile.a_directory("env3", [
417
- FS::MemoryFile.a_regular_file_containing("environment.conf", <<-EOF)
418
- manifest=/manifest_changed
419
- modulepath=/modules_changed
420
- environment_timeout=0
421
- EOF
422
- ]),
423
- ])
404
+ cached_loader_from(:filesystem => [original_envdir], :directory => original_envdir) do |loader|
405
+ original_env = loader.get("env3") # force the environment.conf to be read
406
+
407
+ changed_envdir = FS::MemoryFile.a_directory(base_dir, [
408
+ FS::MemoryFile.a_directory("env3", [
409
+ FS::MemoryFile.a_regular_file_containing("environment.conf", <<-EOF)
410
+ manifest=/manifest_changed
411
+ modulepath=/modules_changed
412
+ environment_timeout=0
413
+ EOF
414
+ ]),
415
+ ])
424
416
 
425
- FS.overlay(changed_envdir) do
426
- changed_env = loader.get("env3")
417
+ FS.overlay(changed_envdir) do
418
+ changed_env = loader.get("env3")
427
419
 
428
- expect(original_env).to environment(:env3).
429
- with_manifest(File.expand_path("/manifest_orig")).
430
- with_full_modulepath([File.expand_path("/modules_orig")])
420
+ expect(original_env).to environment(:env3).
421
+ with_manifest(File.expand_path("/manifest_orig")).
422
+ with_full_modulepath([File.expand_path("/modules_orig")])
431
423
 
432
- expect(changed_env).to environment(:env3).
433
- with_manifest(File.expand_path("/manifest_changed")).
434
- with_full_modulepath([File.expand_path("/modules_changed")])
435
- end
424
+ expect(changed_env).to environment(:env3).
425
+ with_manifest(File.expand_path("/manifest_changed")).
426
+ with_full_modulepath([File.expand_path("/modules_changed")])
436
427
  end
437
428
  end
438
429
  end
@@ -558,24 +549,49 @@ config_version=$vardir/random/scripts
558
549
 
559
550
  describe "cached loaders" do
560
551
  it "lists environments" do
561
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
562
- expect(Puppet::Environments::Cached.new(loader).list).to include_in_any_order(
552
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
553
+ expect(loader.list).to contain_exactly(
563
554
  environment(:an_environment),
564
555
  environment(:another_environment),
565
556
  environment(:symlinked_environment))
566
557
  end
567
558
  end
568
559
 
560
+ it "returns the same cached environment object for list and get methods" do
561
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
562
+ env = loader.list.find { |e| e.name == :an_environment }
563
+
564
+ expect(env).to equal(loader.get(:an_environment)) # same object
565
+ end
566
+ end
567
+
568
+ it "returns the same cached environment object for multiple list calls" do
569
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
570
+ expect(loader.list.first).to equal(loader.list.first) # same object
571
+ end
572
+ end
573
+
574
+ it "expires environments and returns a new environment object with the same value" do
575
+ Puppet[:environment_timeout] = "0"
576
+
577
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
578
+ a = loader.list.first
579
+ b = loader.list.first
580
+ expect(a).to eq(b) # same value
581
+ expect(a).to_not equal(b) # not same object
582
+ end
583
+ end
584
+
569
585
  it "has search_paths" do
570
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
571
- expect(Puppet::Environments::Cached.new(loader).search_paths).to eq(["file://#{directory_tree.children.first}"])
586
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
587
+ expect(loader.search_paths).to eq(["file://#{directory_tree.children.first}"])
572
588
  end
573
589
  end
574
590
 
575
591
  context "#get" do
576
592
  it "gets an environment" do
577
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
578
- expect(Puppet::Environments::Cached.new(loader).get(:an_environment)).to environment(:an_environment)
593
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
594
+ expect(loader.get(:an_environment)).to environment(:an_environment)
579
595
  end
580
596
  end
581
597
 
@@ -592,16 +608,16 @@ config_version=$vardir/random/scripts
592
608
  end
593
609
 
594
610
  it "returns nil if env not found" do
595
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
596
- expect(Puppet::Environments::Cached.new(loader).get(:doesnotexist)).to be_nil
611
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
612
+ expect(loader.get(:doesnotexist)).to be_nil
597
613
  end
598
614
  end
599
615
  end
600
616
 
601
617
  context "#get!" do
602
618
  it "gets an environment" do
603
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
604
- expect(Puppet::Environments::Cached.new(loader).get!(:an_environment)).to environment(:an_environment)
619
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
620
+ expect(loader.get!(:an_environment)).to environment(:an_environment)
605
621
  end
606
622
  end
607
623
 
@@ -618,29 +634,43 @@ config_version=$vardir/random/scripts
618
634
  end
619
635
 
620
636
  it "raises error if environment is not found" do
621
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
637
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
622
638
  expect do
623
- Puppet::Environments::Cached.new(loader).get!(:doesnotexist)
639
+ loader.get!(:doesnotexist)
624
640
  end.to raise_error(Puppet::Environments::EnvironmentNotFound)
625
641
  end
626
642
  end
627
643
  end
628
644
 
629
- context "expiration policies" do
630
- let(:service) { ReplayExpirationService.new }
645
+ context "#get_conf" do
646
+ it "loads environment.conf" do
647
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
648
+ expect(loader.get_conf(:an_environment)).to match_environment_conf(:an_environment).
649
+ with_env_path(directory_tree.children.first).
650
+ with_global_module_path([])
651
+ end
652
+ end
631
653
 
632
- # The environment named `:an_environment` will already be loaded when the
633
- # block is yielded to
634
- def with_environment_loaded(service, &block)
635
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
636
- using_expiration_service(service) do
637
- cached = Puppet::Environments::Cached.new(loader)
638
- cached.get!(:an_environment)
654
+ it "always reloads environment.conf" do
655
+ env = Puppet::Node::Environment.create(:cached, [])
656
+ mocked_loader = double('loader')
657
+ expect(mocked_loader).to receive(:get_conf).with(:cached).and_return(Puppet::Settings::EnvironmentConf.static_for(env, 20)).twice
639
658
 
640
- yield cached if block_given?
641
- end
659
+ cached = Puppet::Environments::Cached.new(mocked_loader)
660
+
661
+ cached.get_conf(:cached)
662
+ cached.get_conf(:cached)
663
+ end
664
+
665
+ it "returns nil if environment is not found" do
666
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
667
+ expect(loader.get_conf(:doesnotexist)).to be_nil
642
668
  end
643
669
  end
670
+ end
671
+
672
+ context "expiration policies" do
673
+ let(:service) { ReplayExpirationService.new }
644
674
 
645
675
  it "notifies when the environment is first created" do
646
676
  with_environment_loaded(service)
@@ -660,12 +690,7 @@ config_version=$vardir/random/scripts
660
690
  end
661
691
 
662
692
  it "evicts an expired environment" do
663
- service = ReplayExpirationService.new
664
-
665
- # The `Cached#clear_all_expired` method tries to optimize the case where
666
- # no entries are expired. But if `Time.now < @next_expiration` and there is
667
- # an expired entry, then the `service#expired?` method is called twice.
668
- expect(service).to receive(:expired?).twice.and_return(true)
693
+ expect(service).to receive(:expired?).and_return(true)
669
694
 
670
695
  with_environment_loaded(service) do |cached|
671
696
  cached.get!(:an_environment)
@@ -709,8 +734,7 @@ config_version=$vardir/random/scripts
709
734
  Puppet[:environment_timeout] = 60
710
735
  Puppet[:environment_timeout_mode] = :from_last_used
711
736
 
712
- # see note above about "twice"
713
- expect(service).to receive(:expired?).twice.and_return(true)
737
+ expect(service).to receive(:expired?).and_return(true)
714
738
 
715
739
  with_environment_loaded(service) do |cached|
716
740
  # even though the environment was recently touched, it's been expired
@@ -720,13 +744,116 @@ config_version=$vardir/random/scripts
720
744
  expect(service.created_envs).to eq([:an_environment, :an_environment])
721
745
  expect(service.evicted_envs).to eq([:an_environment])
722
746
  end
747
+
748
+ it "evicts expired environments when listing" do
749
+ expect(service).to receive(:expired?).with(:an_environment).and_return(true)
750
+
751
+ with_environment_loaded(service) do |cached|
752
+ cached.list
753
+ end
754
+
755
+ expect(service.evicted_envs).to eq([:an_environment])
756
+ end
723
757
  end
724
758
 
725
- it "gets an environment.conf" do
726
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
727
- expect(Puppet::Environments::Cached.new(loader).get_conf(:an_environment)).to match_environment_conf(:an_environment).
728
- with_env_path(directory_tree.children.first).
729
- with_global_module_path([])
759
+ context '#clear' do
760
+ let(:service) { ReplayExpirationService.new }
761
+
762
+ it "evicts an environment" do
763
+ with_environment_loaded(service) do |cached|
764
+ cached.clear(:an_environment)
765
+ end
766
+
767
+ expect(service.evicted_envs).to eq([:an_environment])
768
+ end
769
+ end
770
+
771
+ context '#clear_all' do
772
+ let(:service) { ReplayExpirationService.new }
773
+ let(:envdir) { File.expand_path("envdir") }
774
+ let(:default_dir) { File.join(envdir, "cached_env", "modules") }
775
+ let(:expected_dir) { File.join(envdir, "cached_env", "site") }
776
+
777
+ let(:base_dir) do
778
+ FS::MemoryFile.a_directory(envdir, [
779
+ FS::MemoryFile.a_directory("cached_env", [
780
+ FS::MemoryFile.a_missing_file("environment.conf")
781
+ ])
782
+ ])
783
+ end
784
+
785
+ let(:updated_dir) do
786
+ FS::MemoryFile.a_directory(envdir, [
787
+ FS::MemoryFile.a_directory("cached_env", [
788
+ FS::MemoryFile.a_directory("site"),
789
+ FS::MemoryFile.a_missing_directory("modules"),
790
+ FS::MemoryFile.a_regular_file_containing("environment.conf", <<-EOF)
791
+ modulepath=site
792
+ environment_timeout=unlimited
793
+ EOF
794
+ ])
795
+ ])
796
+ end
797
+
798
+ it 'evicts all environments' do
799
+ with_environment_loaded(service) do |cached|
800
+ cached.get(:an_environment)
801
+ cached.get(:another_environment)
802
+ cached.clear_all
803
+
804
+ expect(service.evicted_envs).to match([:an_environment, :another_environment])
805
+ end
806
+ end
807
+
808
+ it "recomputes modulepath if 'get' is called before 'clear_all'" do
809
+ cached_loader_from(:filesystem => [base_dir], :directory => base_dir) do |loader|
810
+ loader.get(:cached_env)
811
+
812
+ expect(Puppet.settings.value(:modulepath, :cached_env)).to eq(default_dir)
813
+
814
+ FS.overlay(updated_dir) do
815
+ loader.clear_all
816
+
817
+ expect(loader.get(:cached_env).modulepath).to contain_exactly(expected_dir)
818
+ end
819
+ end
820
+ end
821
+
822
+ it "recomputes modulepath if 'list' is called before 'clear_all'" do
823
+ cached_loader_from(:filesystem => [base_dir], :directory => base_dir) do |loader|
824
+ loader.list
825
+
826
+ expect(Puppet.settings.value(:modulepath, :cached_env)).to eq(default_dir)
827
+
828
+ FS.overlay(updated_dir) do
829
+ loader.clear_all
830
+
831
+ expect(loader.get(:cached_env).modulepath).to contain_exactly(expected_dir)
832
+ end
833
+ end
834
+ end
835
+
836
+ it "recomputes modulepath if 'get_conf' is called before 'clear_all'" do
837
+ cached_loader_from(:filesystem => [base_dir], :directory => base_dir) do |loader|
838
+ loader.get_conf(:cached_env)
839
+
840
+ expect(Puppet.settings.value(:modulepath, :cached_env)).to eq(default_dir)
841
+
842
+ FS.overlay(updated_dir) do
843
+ loader.clear_all
844
+
845
+ expect(loader.get(:cached_env).modulepath).to contain_exactly(expected_dir)
846
+ end
847
+ end
848
+ end
849
+
850
+ it 'deletes environment text domains' do
851
+ with_environment_loaded(service) do |cached|
852
+ cached.get(:an_environment)
853
+ cached.clear_all
854
+
855
+ expect(FastGettext.text_domain).to eq(Puppet::GettextConfig::DEFAULT_TEXT_DOMAIN)
856
+ end
730
857
  end
731
858
  end
732
859
  end
@@ -801,6 +928,20 @@ config_version=$vardir/random/scripts
801
928
  end
802
929
  end
803
930
 
931
+ def cached_loader_from(options, &block)
932
+ FS.overlay(*options[:filesystem]) do
933
+ environments = Puppet::Environments::Cached.new(
934
+ Puppet::Environments::Directories.new(
935
+ options[:directory],
936
+ options[:modulepath] || []
937
+ )
938
+ )
939
+ Puppet.override(:environments => environments) do
940
+ yield environments
941
+ end
942
+ end
943
+ end
944
+
804
945
  def loader_from(options, &block)
805
946
  FS.overlay(*options[:filesystem]) do
806
947
  environments = Puppet::Environments::Directories.new(
@@ -823,6 +964,19 @@ config_version=$vardir/random/scripts
823
964
  end
824
965
  end
825
966
 
967
+ # The environment named `:an_environment` will already be loaded when the
968
+ # block is yielded to
969
+ def with_environment_loaded(service, &block)
970
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
971
+ using_expiration_service(service) do
972
+ cached = Puppet::Environments::Cached.new(loader)
973
+ cached.get!(:an_environment)
974
+
975
+ yield cached if block_given?
976
+ end
977
+ end
978
+ end
979
+
826
980
  class ReplayExpirationService < Puppet::Environments::Cached::DefaultCacheExpirationService
827
981
  attr_reader :created_envs, :evicted_envs
828
982
 
@@ -840,4 +994,3 @@ config_version=$vardir/random/scripts
840
994
  end
841
995
  end
842
996
  end
843
- end