puppet 6.21.0-x64-mingw32 → 6.24.0-x64-mingw32

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

Potentially problematic release.


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

Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +5 -5
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +29 -23
  5. data/README.md +4 -4
  6. data/ext/osx/puppet.plist +2 -0
  7. data/ext/project_data.yaml +3 -2
  8. data/lib/puppet.rb +3 -3
  9. data/lib/puppet/application/agent.rb +12 -5
  10. data/lib/puppet/application/apply.rb +2 -1
  11. data/lib/puppet/application/device.rb +2 -1
  12. data/lib/puppet/application/filebucket.rb +1 -0
  13. data/lib/puppet/application/resource.rb +17 -3
  14. data/lib/puppet/application/script.rb +2 -1
  15. data/lib/puppet/application/ssl.rb +12 -0
  16. data/lib/puppet/configurer/downloader.rb +2 -1
  17. data/lib/puppet/defaults.rb +27 -5
  18. data/lib/puppet/environments.rb +26 -1
  19. data/lib/puppet/face/facts.rb +128 -30
  20. data/lib/puppet/face/help/action.erb +1 -0
  21. data/lib/puppet/face/help/face.erb +1 -0
  22. data/lib/puppet/face/node/clean.rb +11 -0
  23. data/lib/puppet/file_serving/fileset.rb +14 -2
  24. data/lib/puppet/file_system/file_impl.rb +1 -1
  25. data/lib/puppet/file_system/memory_file.rb +8 -1
  26. data/lib/puppet/file_system/windows.rb +4 -2
  27. data/lib/puppet/forge.rb +3 -3
  28. data/lib/puppet/functions/all.rb +1 -1
  29. data/lib/puppet/functions/camelcase.rb +1 -1
  30. data/lib/puppet/functions/capitalize.rb +2 -2
  31. data/lib/puppet/functions/downcase.rb +2 -2
  32. data/lib/puppet/functions/empty.rb +8 -0
  33. data/lib/puppet/functions/get.rb +5 -5
  34. data/lib/puppet/functions/group_by.rb +13 -5
  35. data/lib/puppet/functions/lest.rb +1 -1
  36. data/lib/puppet/functions/new.rb +100 -100
  37. data/lib/puppet/functions/partition.rb +12 -4
  38. data/lib/puppet/functions/require.rb +5 -5
  39. data/lib/puppet/functions/sort.rb +3 -3
  40. data/lib/puppet/functions/strftime.rb +1 -0
  41. data/lib/puppet/functions/tree_each.rb +7 -9
  42. data/lib/puppet/functions/type.rb +4 -4
  43. data/lib/puppet/functions/unwrap.rb +17 -2
  44. data/lib/puppet/functions/upcase.rb +2 -2
  45. data/lib/puppet/http/resolver/server_list.rb +15 -4
  46. data/lib/puppet/http/service/compiler.rb +69 -0
  47. data/lib/puppet/http/service/file_server.rb +2 -1
  48. data/lib/puppet/indirector/catalog/compiler.rb +1 -0
  49. data/lib/puppet/indirector/facts/facter.rb +24 -3
  50. data/lib/puppet/indirector/file_metadata/rest.rb +1 -0
  51. data/lib/puppet/indirector/resource/ral.rb +6 -1
  52. data/lib/puppet/interface/documentation.rb +1 -0
  53. data/lib/puppet/module_tool/applications/installer.rb +4 -0
  54. data/lib/puppet/module_tool/errors/shared.rb +17 -0
  55. data/lib/puppet/network/formats.rb +67 -0
  56. data/lib/puppet/network/http/factory.rb +4 -0
  57. data/lib/puppet/parser/functions/fqdn_rand.rb +14 -6
  58. data/lib/puppet/pops/types/p_sem_ver_type.rb +8 -2
  59. data/lib/puppet/pops/types/p_sensitive_type.rb +10 -0
  60. data/lib/puppet/pops/types/type_mismatch_describer.rb +1 -1
  61. data/lib/puppet/provider/exec/posix.rb +16 -4
  62. data/lib/puppet/provider/package/dnfmodule.rb +1 -1
  63. data/lib/puppet/provider/package/nim.rb +11 -6
  64. data/lib/puppet/provider/package/pip.rb +15 -3
  65. data/lib/puppet/provider/parsedfile.rb +3 -0
  66. data/lib/puppet/provider/service/systemd.rb +14 -4
  67. data/lib/puppet/provider/service/windows.rb +38 -0
  68. data/lib/puppet/provider/user/directoryservice.rb +25 -12
  69. data/lib/puppet/provider/user/useradd.rb +9 -2
  70. data/lib/puppet/reference/configuration.rb +1 -1
  71. data/lib/puppet/settings.rb +30 -7
  72. data/lib/puppet/settings/environment_conf.rb +1 -0
  73. data/lib/puppet/transaction/additional_resource_generator.rb +1 -1
  74. data/lib/puppet/type/exec.rb +16 -3
  75. data/lib/puppet/type/file.rb +19 -1
  76. data/lib/puppet/type/file/mode.rb +6 -0
  77. data/lib/puppet/type/file/selcontext.rb +1 -1
  78. data/lib/puppet/type/service.rb +18 -38
  79. data/lib/puppet/type/tidy.rb +22 -3
  80. data/lib/puppet/type/user.rb +38 -20
  81. data/lib/puppet/util/fact_dif.rb +36 -17
  82. data/lib/puppet/util/monkey_patches.rb +7 -0
  83. data/lib/puppet/util/selinux.rb +30 -4
  84. data/lib/puppet/util/symbolic_file_mode.rb +29 -17
  85. data/lib/puppet/util/windows/adsi.rb +46 -0
  86. data/lib/puppet/util/windows/api_types.rb +1 -1
  87. data/lib/puppet/util/windows/principal.rb +9 -2
  88. data/lib/puppet/util/windows/sid.rb +6 -2
  89. data/lib/puppet/version.rb +1 -1
  90. data/locales/puppet.pot +360 -280
  91. data/man/man5/puppet.conf.5 +279 -251
  92. data/man/man8/puppet-agent.8 +1 -1
  93. data/man/man8/puppet-apply.8 +1 -1
  94. data/man/man8/puppet-catalog.8 +9 -9
  95. data/man/man8/puppet-config.8 +1 -1
  96. data/man/man8/puppet-describe.8 +1 -1
  97. data/man/man8/puppet-device.8 +1 -1
  98. data/man/man8/puppet-doc.8 +1 -1
  99. data/man/man8/puppet-epp.8 +1 -1
  100. data/man/man8/puppet-facts.8 +65 -7
  101. data/man/man8/puppet-filebucket.8 +1 -1
  102. data/man/man8/puppet-generate.8 +1 -1
  103. data/man/man8/puppet-help.8 +1 -1
  104. data/man/man8/puppet-key.8 +7 -7
  105. data/man/man8/puppet-lookup.8 +1 -1
  106. data/man/man8/puppet-man.8 +1 -1
  107. data/man/man8/puppet-module.8 +1 -1
  108. data/man/man8/puppet-node.8 +5 -5
  109. data/man/man8/puppet-parser.8 +1 -1
  110. data/man/man8/puppet-plugin.8 +1 -1
  111. data/man/man8/puppet-report.8 +5 -5
  112. data/man/man8/puppet-resource.8 +1 -1
  113. data/man/man8/puppet-script.8 +1 -1
  114. data/man/man8/puppet-ssl.8 +5 -1
  115. data/man/man8/puppet-status.8 +4 -4
  116. data/man/man8/puppet.8 +2 -2
  117. data/spec/fixtures/ssl/127.0.0.1-key.pem +107 -57
  118. data/spec/fixtures/ssl/127.0.0.1.pem +52 -31
  119. data/spec/fixtures/ssl/bad-basic-constraints.pem +57 -35
  120. data/spec/fixtures/ssl/bad-int-basic-constraints.pem +57 -35
  121. data/spec/fixtures/ssl/ca.pem +57 -35
  122. data/spec/fixtures/ssl/crl.pem +28 -18
  123. data/spec/fixtures/ssl/ec-key.pem +11 -11
  124. data/spec/fixtures/ssl/ec.pem +33 -24
  125. data/spec/fixtures/ssl/encrypted-ec-key.pem +12 -12
  126. data/spec/fixtures/ssl/encrypted-key.pem +108 -58
  127. data/spec/fixtures/ssl/intermediate-agent-crl.pem +28 -19
  128. data/spec/fixtures/ssl/intermediate-agent.pem +57 -36
  129. data/spec/fixtures/ssl/intermediate-crl.pem +31 -21
  130. data/spec/fixtures/ssl/intermediate.pem +57 -36
  131. data/spec/fixtures/ssl/oid-key.pem +117 -0
  132. data/spec/fixtures/ssl/oid.pem +69 -0
  133. data/spec/fixtures/ssl/pluto-key.pem +107 -57
  134. data/spec/fixtures/ssl/pluto.pem +52 -30
  135. data/spec/fixtures/ssl/request-key.pem +107 -57
  136. data/spec/fixtures/ssl/request.pem +47 -26
  137. data/spec/fixtures/ssl/revoked-key.pem +107 -57
  138. data/spec/fixtures/ssl/revoked.pem +52 -30
  139. data/spec/fixtures/ssl/signed-key.pem +107 -57
  140. data/spec/fixtures/ssl/signed.pem +52 -30
  141. data/spec/fixtures/ssl/tampered-cert.pem +52 -30
  142. data/spec/fixtures/ssl/tampered-csr.pem +47 -26
  143. data/spec/fixtures/ssl/trusted_oid_mapping.yaml +5 -0
  144. data/spec/fixtures/ssl/unknown-127.0.0.1-key.pem +107 -57
  145. data/spec/fixtures/ssl/unknown-127.0.0.1.pem +50 -29
  146. data/spec/fixtures/ssl/unknown-ca-key.pem +107 -57
  147. data/spec/fixtures/ssl/unknown-ca.pem +55 -33
  148. data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services_vendor_preset +9 -0
  149. data/spec/integration/application/filebucket_spec.rb +11 -0
  150. data/spec/integration/application/module_spec.rb +21 -0
  151. data/spec/integration/application/plugin_spec.rb +1 -1
  152. data/spec/integration/application/resource_spec.rb +64 -0
  153. data/spec/integration/application/ssl_spec.rb +20 -0
  154. data/spec/integration/environments/settings_interpolation_spec.rb +0 -4
  155. data/spec/integration/http/client_spec.rb +12 -0
  156. data/spec/integration/indirector/direct_file_server_spec.rb +1 -3
  157. data/spec/integration/indirector/facts/facter_spec.rb +90 -36
  158. data/spec/integration/type/exec_spec.rb +70 -45
  159. data/spec/integration/util/windows/adsi_spec.rb +18 -0
  160. data/spec/integration/util/windows/principal_spec.rb +21 -0
  161. data/spec/integration/util/windows/registry_spec.rb +6 -0
  162. data/spec/lib/puppet/test_ca.rb +7 -2
  163. data/spec/lib/puppet_spec/settings.rb +1 -0
  164. data/spec/spec_helper.rb +11 -1
  165. data/spec/unit/application/agent_spec.rb +7 -2
  166. data/spec/unit/application/facts_spec.rb +482 -3
  167. data/spec/unit/application/ssl_spec.rb +23 -0
  168. data/spec/unit/configurer/downloader_spec.rb +6 -0
  169. data/spec/unit/configurer_spec.rb +23 -0
  170. data/spec/unit/defaults_spec.rb +16 -0
  171. data/spec/unit/environments_spec.rb +199 -88
  172. data/spec/unit/face/facts_spec.rb +4 -0
  173. data/spec/unit/file_serving/fileset_spec.rb +60 -0
  174. data/spec/unit/file_system_spec.rb +15 -0
  175. data/spec/unit/functions/assert_type_spec.rb +1 -1
  176. data/spec/unit/functions/empty_spec.rb +10 -0
  177. data/spec/unit/functions/unwrap_spec.rb +8 -0
  178. data/spec/unit/functions4_spec.rb +2 -2
  179. data/spec/unit/gettext/config_spec.rb +12 -0
  180. data/spec/unit/http/service/compiler_spec.rb +123 -0
  181. data/spec/unit/indirector/catalog/compiler_spec.rb +14 -10
  182. data/spec/unit/indirector/facts/facter_spec.rb +95 -0
  183. data/spec/unit/indirector/resource/ral_spec.rb +40 -75
  184. data/spec/unit/module_tool/applications/installer_spec.rb +12 -0
  185. data/spec/unit/network/formats_spec.rb +41 -0
  186. data/spec/unit/network/http/factory_spec.rb +19 -0
  187. data/spec/unit/parser/functions/fqdn_rand_spec.rb +15 -1
  188. data/spec/unit/parser/templatewrapper_spec.rb +12 -2
  189. data/spec/unit/pops/types/p_sem_ver_type_spec.rb +18 -0
  190. data/spec/unit/pops/types/p_sensitive_type_spec.rb +18 -0
  191. data/spec/unit/provider/package/dnfmodule_spec.rb +10 -1
  192. data/spec/unit/provider/package/nim_spec.rb +42 -0
  193. data/spec/unit/provider/package/pip_spec.rb +37 -0
  194. data/spec/unit/provider/parsedfile_spec.rb +10 -0
  195. data/spec/unit/provider/service/init_spec.rb +1 -0
  196. data/spec/unit/provider/service/openwrt_spec.rb +3 -1
  197. data/spec/unit/provider/service/systemd_spec.rb +53 -8
  198. data/spec/unit/provider/service/windows_spec.rb +202 -0
  199. data/spec/unit/provider/user/directoryservice_spec.rb +67 -35
  200. data/spec/unit/provider/user/useradd_spec.rb +21 -6
  201. data/spec/unit/resource/catalog_spec.rb +1 -1
  202. data/spec/unit/settings_spec.rb +97 -56
  203. data/spec/unit/ssl/state_machine_spec.rb +19 -5
  204. data/spec/unit/transaction/additional_resource_generator_spec.rb +0 -2
  205. data/spec/unit/transaction_spec.rb +18 -20
  206. data/spec/unit/type/exec_spec.rb +76 -29
  207. data/spec/unit/type/file/selinux_spec.rb +3 -3
  208. data/spec/unit/type/file/source_spec.rb +4 -4
  209. data/spec/unit/type/service_spec.rb +59 -188
  210. data/spec/unit/type/tidy_spec.rb +24 -7
  211. data/spec/unit/type/user_spec.rb +45 -0
  212. data/spec/unit/util/selinux_spec.rb +87 -16
  213. data/spec/unit/util/windows/sid_spec.rb +41 -0
  214. data/tasks/generate_cert_fixtures.rake +12 -3
  215. metadata +24 -9
  216. data/spec/lib/matchers/include.rb +0 -27
  217. data/spec/lib/matchers/include_spec.rb +0 -32
@@ -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
@@ -81,6 +81,12 @@ describe Puppet::Configurer::Downloader do
81
81
  expect(file[:source_permissions]).to eq(:ignore)
82
82
  end
83
83
 
84
+ it "should ignore the max file limit" do
85
+ file = generate_file_resource
86
+
87
+ expect(file[:max_files]).to eq(-1)
88
+ end
89
+
84
90
  describe "on POSIX", :if => Puppet.features.posix? do
85
91
  it "should allow source_permissions to be overridden" do
86
92
  file = generate_file_resource(:source_permissions => :use)
@@ -1072,6 +1072,29 @@ describe Puppet::Configurer do
1072
1072
  }.to raise_error(Puppet::Error, /Could not select a functional puppet server from server_list: 'myserver:123,someotherservername'/)
1073
1073
  end
1074
1074
 
1075
+ it "should warn when servers in 'server_list' are unreachable" do
1076
+ Puppet.settings[:server_list] = "mybadserver1:123,mybadserver2:123,mygoodserver"
1077
+ Puppet[:usecacheonfailure] = false
1078
+
1079
+ stub_request(:get, 'https://mybadserver1:123/status/v1/simple/master').and_raise(Puppet::HTTP::HTTPError)
1080
+ stub_request(:get, 'https://mybadserver2:123/status/v1/simple/master').and_raise(Puppet::HTTP::HTTPError)
1081
+ stub_request(:get, 'https://mygoodserver:8140/status/v1/simple/master').to_return(status: 200)
1082
+
1083
+ expect(Puppet).to receive(:warning).with(/^Unable to connect to server from server_list setting:.*Trying with next server from server_list.$/).twice
1084
+ configurer.run
1085
+ end
1086
+
1087
+ it "should warn when servers in 'server_list' respond with error" do
1088
+ Puppet.settings[:server_list] = "mybadserver:123,someotherservername"
1089
+ Puppet[:usecacheonfailure] = false
1090
+
1091
+ stub_request(:get, 'https://mybadserver:123/status/v1/simple/master').to_return(status: 400)
1092
+ stub_request(:get, 'https://someotherservername:8140/status/v1/simple/master').to_return(status: 200)
1093
+
1094
+ expect(Puppet).to receive(:warning).with(/^Puppet server mybadserver:123 is unavailable: 400 Trying with next server from server_list.$/)
1095
+ configurer.run
1096
+ end
1097
+
1075
1098
  it "should not error when usecacheonfailure is true and no servers in 'server_list' are reachable" do
1076
1099
  Puppet.settings[:server_list] = "myserver:123,someotherservername"
1077
1100
  Puppet[:usecacheonfailure] = true
@@ -234,4 +234,20 @@ describe "Defaults" do
234
234
  Puppet.initialize_settings
235
235
  end
236
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
237
253
  end
@@ -1,15 +1,18 @@
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
 
8
+ module FsRemove
9
+ def remove
10
+ @properties[:directory?] = false
11
+ @properties[:exist?] = false
12
+ @properties[:executable?] = false
13
+ end
14
+ end
15
+
13
16
  before(:each) do
14
17
  Puppet.settings.initialize_global_settings
15
18
  Puppet[:environment_timeout] = "unlimited"
@@ -49,7 +52,7 @@ describe Puppet::Environments do
49
52
  loader_from(:filesystem => [directory_tree, global_path_1, global_path_2],
50
53
  :directory => directory_tree.children.first,
51
54
  :modulepath => [global_path_1_location, global_path_2_location]) do |loader|
52
- expect(loader.list).to include_in_any_order(
55
+ expect(loader.list).to contain_exactly(
53
56
  environment(:an_environment).
54
57
  with_manifest("#{FS.path_string(directory_tree)}/envdir/an_environment/manifests").
55
58
  with_modulepath(["#{FS.path_string(directory_tree)}/envdir/an_environment/modules",
@@ -87,7 +90,7 @@ describe Puppet::Environments do
87
90
 
88
91
  loader_from(:filesystem => [envdir],
89
92
  :directory => envdir) do |loader|
90
- expect(loader.list).to include_in_any_order(environment(:env1), environment(:env2))
93
+ expect(loader.list).to contain_exactly(environment(:env1), environment(:env2))
91
94
  end
92
95
  end
93
96
 
@@ -406,33 +409,29 @@ config_version=$vardir/random/scripts
406
409
  ]),
407
410
  ])
408
411
 
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
- ])
412
+ cached_loader_from(:filesystem => [original_envdir], :directory => original_envdir) do |loader|
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
+ ])
424
424
 
425
- FS.overlay(changed_envdir) do
426
- changed_env = loader.get("env3")
425
+ FS.overlay(changed_envdir) do
426
+ changed_env = loader.get("env3")
427
427
 
428
- expect(original_env).to environment(:env3).
429
- with_manifest(File.expand_path("/manifest_orig")).
430
- with_full_modulepath([File.expand_path("/modules_orig")])
428
+ expect(original_env).to environment(:env3).
429
+ with_manifest(File.expand_path("/manifest_orig")).
430
+ with_full_modulepath([File.expand_path("/modules_orig")])
431
431
 
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
432
+ expect(changed_env).to environment(:env3).
433
+ with_manifest(File.expand_path("/manifest_changed")).
434
+ with_full_modulepath([File.expand_path("/modules_changed")])
436
435
  end
437
436
  end
438
437
  end
@@ -558,24 +557,49 @@ config_version=$vardir/random/scripts
558
557
 
559
558
  describe "cached loaders" do
560
559
  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(
560
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
561
+ expect(loader.list).to contain_exactly(
563
562
  environment(:an_environment),
564
563
  environment(:another_environment),
565
564
  environment(:symlinked_environment))
566
565
  end
567
566
  end
568
567
 
568
+ it "returns the same cached environment object for list and get methods" do
569
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
570
+ env = loader.list.find { |e| e.name == :an_environment }
571
+
572
+ expect(env).to equal(loader.get(:an_environment)) # same object
573
+ end
574
+ end
575
+
576
+ it "returns the same cached environment object for multiple list calls" do
577
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
578
+ expect(loader.list.first).to equal(loader.list.first) # same object
579
+ end
580
+ end
581
+
582
+ it "expires environments and returns a new environment object with the same value" do
583
+ Puppet[:environment_timeout] = "0"
584
+
585
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
586
+ a = loader.list.first
587
+ b = loader.list.first
588
+ expect(a).to eq(b) # same value
589
+ expect(a).to_not equal(b) # not same object
590
+ end
591
+ end
592
+
569
593
  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}"])
594
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
595
+ expect(loader.search_paths).to eq(["file://#{directory_tree.children.first}"])
572
596
  end
573
597
  end
574
598
 
575
599
  context "#get" do
576
600
  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)
601
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
602
+ expect(loader.get(:an_environment)).to environment(:an_environment)
579
603
  end
580
604
  end
581
605
 
@@ -591,17 +615,44 @@ config_version=$vardir/random/scripts
591
615
  cached.get(:cached)
592
616
  end
593
617
 
618
+ it "does not list deleted environments" do
619
+ env3 = FS::MemoryFile.a_directory("env3", [
620
+ FS::MemoryFile.a_regular_file_containing("environment.conf", '')
621
+ ])
622
+
623
+ envdir = FS::MemoryFile.a_directory(File.expand_path("envdir"), [
624
+ FS::MemoryFile.a_directory("env1", [
625
+ FS::MemoryFile.a_regular_file_containing("environment.conf", '')
626
+ ]),
627
+ FS::MemoryFile.a_directory("env2", [
628
+ FS::MemoryFile.a_regular_file_containing("environment.conf", '')
629
+ ]),
630
+ env3
631
+ ])
632
+
633
+ loader_from(:filesystem => [envdir], :directory => envdir) do |loader|
634
+ cached = Puppet::Environments::Cached.new(loader)
635
+ cached.get(:env1)
636
+ cached.get(:env2)
637
+ cached.get(:env3)
638
+ env3.extend(FsRemove).remove
639
+
640
+ expect(cached.list).to contain_exactly(environment(:env1),environment(:env2))
641
+ expect(cached.get(:env3)).to be_nil
642
+ end
643
+ end
644
+
594
645
  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
646
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
647
+ expect(loader.get(:doesnotexist)).to be_nil
597
648
  end
598
649
  end
599
650
  end
600
651
 
601
652
  context "#get!" do
602
653
  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)
654
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
655
+ expect(loader.get!(:an_environment)).to environment(:an_environment)
605
656
  end
606
657
  end
607
658
 
@@ -618,14 +669,41 @@ config_version=$vardir/random/scripts
618
669
  end
619
670
 
620
671
  it "raises error if environment is not found" do
621
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
672
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
622
673
  expect do
623
- Puppet::Environments::Cached.new(loader).get!(:doesnotexist)
674
+ loader.get!(:doesnotexist)
624
675
  end.to raise_error(Puppet::Environments::EnvironmentNotFound)
625
676
  end
626
677
  end
627
678
  end
628
679
 
680
+ context "#get_conf" do
681
+ it "loads environment.conf" do
682
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
683
+ expect(loader.get_conf(:an_environment)).to match_environment_conf(:an_environment).
684
+ with_env_path(directory_tree.children.first).
685
+ with_global_module_path([])
686
+ end
687
+ end
688
+
689
+ it "always reloads environment.conf" do
690
+ env = Puppet::Node::Environment.create(:cached, [])
691
+ mocked_loader = double('loader')
692
+ expect(mocked_loader).to receive(:get_conf).with(:cached).and_return(Puppet::Settings::EnvironmentConf.static_for(env, 20)).twice
693
+
694
+ cached = Puppet::Environments::Cached.new(mocked_loader)
695
+
696
+ cached.get_conf(:cached)
697
+ cached.get_conf(:cached)
698
+ end
699
+
700
+ it "returns nil if environment is not found" do
701
+ cached_loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
702
+ expect(loader.get_conf(:doesnotexist)).to be_nil
703
+ end
704
+ end
705
+ end
706
+
629
707
  context "expiration policies" do
630
708
  let(:service) { ReplayExpirationService.new }
631
709
 
@@ -647,8 +725,6 @@ config_version=$vardir/random/scripts
647
725
  end
648
726
 
649
727
  it "evicts an expired environment" do
650
- service = ReplayExpirationService.new
651
-
652
728
  expect(service).to receive(:expired?).and_return(true)
653
729
 
654
730
  with_environment_loaded(service) do |cached|
@@ -703,13 +779,15 @@ config_version=$vardir/random/scripts
703
779
  expect(service.created_envs).to eq([:an_environment, :an_environment])
704
780
  expect(service.evicted_envs).to eq([:an_environment])
705
781
  end
706
- end
707
782
 
708
- it "gets an environment.conf" do
709
- loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
710
- expect(Puppet::Environments::Cached.new(loader).get_conf(:an_environment)).to match_environment_conf(:an_environment).
711
- with_env_path(directory_tree.children.first).
712
- with_global_module_path([])
783
+ it "evicts expired environments when listing" do
784
+ expect(service).to receive(:expired?).with(:an_environment).and_return(true)
785
+
786
+ with_environment_loaded(service) do |cached|
787
+ cached.list
788
+ end
789
+
790
+ expect(service.evicted_envs).to eq([:an_environment])
713
791
  end
714
792
  end
715
793
 
@@ -727,6 +805,30 @@ config_version=$vardir/random/scripts
727
805
 
728
806
  context '#clear_all' do
729
807
  let(:service) { ReplayExpirationService.new }
808
+ let(:envdir) { File.expand_path("envdir") }
809
+ let(:default_dir) { File.join(envdir, "cached_env", "modules") }
810
+ let(:expected_dir) { File.join(envdir, "cached_env", "site") }
811
+
812
+ let(:base_dir) do
813
+ FS::MemoryFile.a_directory(envdir, [
814
+ FS::MemoryFile.a_directory("cached_env", [
815
+ FS::MemoryFile.a_missing_file("environment.conf")
816
+ ])
817
+ ])
818
+ end
819
+
820
+ let(:updated_dir) do
821
+ FS::MemoryFile.a_directory(envdir, [
822
+ FS::MemoryFile.a_directory("cached_env", [
823
+ FS::MemoryFile.a_directory("site"),
824
+ FS::MemoryFile.a_missing_directory("modules"),
825
+ FS::MemoryFile.a_regular_file_containing("environment.conf", <<-EOF)
826
+ modulepath=site
827
+ environment_timeout=unlimited
828
+ EOF
829
+ ])
830
+ ])
831
+ end
730
832
 
731
833
  it 'evicts all environments' do
732
834
  with_environment_loaded(service) do |cached|
@@ -738,48 +840,44 @@ config_version=$vardir/random/scripts
738
840
  end
739
841
  end
740
842
 
741
- it 'clears cached environment settings' do
742
- base_dir = File.expand_path("envdir")
743
- original_envdir = FS::MemoryFile.a_directory(base_dir, [
744
- FS::MemoryFile.a_directory("env3", [
745
- FS::MemoryFile.a_regular_file_containing("environment.conf", <<-EOF)
746
- manifest=/manifest_orig
747
- modulepath=/modules_orig
748
- environment_timeout=60
749
- EOF
750
- ]),
751
- ])
843
+ it "recomputes modulepath if 'get' is called before 'clear_all'" do
844
+ cached_loader_from(:filesystem => [base_dir], :directory => base_dir) do |loader|
845
+ loader.get(:cached_env)
752
846
 
753
- FS.overlay(original_envdir) do
754
- dir_loader = Puppet::Environments::Directories.new(original_envdir, [])
755
- loader = Puppet::Environments::Cached.new(dir_loader)
756
- Puppet.override(:environments => loader) do
757
- original_env = loader.get("env3") # force the environment.conf to be read
758
-
759
- changed_envdir = FS::MemoryFile.a_directory(base_dir, [
760
- FS::MemoryFile.a_directory("env3", [
761
- FS::MemoryFile.a_regular_file_containing("environment.conf", <<-EOF)
762
- manifest=/manifest_changed
763
- modulepath=/modules_changed
764
- environment_timeout=60
765
- EOF
766
- ]),
767
- ])
847
+ expect(Puppet.settings.value(:modulepath, :cached_env)).to eq(default_dir)
768
848
 
769
- #Clear all cached environments
849
+ FS.overlay(updated_dir) do
770
850
  loader.clear_all
771
851
 
772
- FS.overlay(changed_envdir) do
773
- changed_env = loader.get("env3")
852
+ expect(loader.get(:cached_env).modulepath).to contain_exactly(expected_dir)
853
+ end
854
+ end
855
+ end
774
856
 
775
- expect(original_env).to environment(:env3).
776
- with_manifest(File.expand_path("/manifest_orig")).
777
- with_full_modulepath([File.expand_path("/modules_orig")])
857
+ it "recomputes modulepath if 'list' is called before 'clear_all'" do
858
+ cached_loader_from(:filesystem => [base_dir], :directory => base_dir) do |loader|
859
+ loader.list
860
+
861
+ expect(Puppet.settings.value(:modulepath, :cached_env)).to eq(default_dir)
862
+
863
+ FS.overlay(updated_dir) do
864
+ loader.clear_all
778
865
 
779
- expect(changed_env).to environment(:env3).
780
- with_manifest(File.expand_path("/manifest_changed")).
781
- with_full_modulepath([File.expand_path("/modules_changed")])
782
- end
866
+ expect(loader.get(:cached_env).modulepath).to contain_exactly(expected_dir)
867
+ end
868
+ end
869
+ end
870
+
871
+ it "recomputes modulepath if 'get_conf' is called before 'clear_all'" do
872
+ cached_loader_from(:filesystem => [base_dir], :directory => base_dir) do |loader|
873
+ loader.get_conf(:cached_env)
874
+
875
+ expect(Puppet.settings.value(:modulepath, :cached_env)).to eq(default_dir)
876
+
877
+ FS.overlay(updated_dir) do
878
+ loader.clear_all
879
+
880
+ expect(loader.get(:cached_env).modulepath).to contain_exactly(expected_dir)
783
881
  end
784
882
  end
785
883
  end
@@ -865,6 +963,20 @@ config_version=$vardir/random/scripts
865
963
  end
866
964
  end
867
965
 
966
+ def cached_loader_from(options, &block)
967
+ FS.overlay(*options[:filesystem]) do
968
+ environments = Puppet::Environments::Cached.new(
969
+ Puppet::Environments::Directories.new(
970
+ options[:directory],
971
+ options[:modulepath] || []
972
+ )
973
+ )
974
+ Puppet.override(:environments => environments) do
975
+ yield environments
976
+ end
977
+ end
978
+ end
979
+
868
980
  def loader_from(options, &block)
869
981
  FS.overlay(*options[:filesystem]) do
870
982
  environments = Puppet::Environments::Directories.new(
@@ -917,4 +1029,3 @@ config_version=$vardir/random/scripts
917
1029
  end
918
1030
  end
919
1031
  end
920
- end