Skip to content

Commit 8ea8c45

Browse files
authored
Merge pull request #8523 from joshcooper/envconf_caching_10942
(PUP-10942) Don't leak environment state when creating a new instance
2 parents 72955cc + 8d569e8 commit 8ea8c45

File tree

7 files changed

+190
-152
lines changed

7 files changed

+190
-152
lines changed

lib/puppet/environments.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ def get_conf(name)
225225
private
226226

227227
def create_environment(name)
228+
# interpolated modulepaths may be cached from prior environment instances
229+
Puppet.settings.clear_environment_settings(name)
230+
228231
env_symbol = name.intern
229232
setting_values = Puppet.settings.values(env_symbol, Puppet.settings.preferred_run_mode)
230233
env = Puppet::Node::Environment.create(
@@ -350,7 +353,19 @@ def initialize(loader)
350353

351354
# @!macro loader_list
352355
def list
353-
@loader.list
356+
# Evict all that have expired, in the same way as `get`
357+
clear_all_expired
358+
359+
@loader.list.map do |env|
360+
name = env.name
361+
old_entry = @cache[name]
362+
if old_entry
363+
old_entry.value
364+
else
365+
add_entry(name, entry(env))
366+
env
367+
end
368+
end
354369
end
355370

356371
# @!macro loader_search_paths

lib/puppet/file_system/memory_file.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ def self.a_missing_file(path)
77
new(path, :exist? => false, :executable? => false)
88
end
99

10+
def self.a_missing_directory(path)
11+
new(path,
12+
:exist? => false,
13+
:executable? => false,
14+
:directory? => true)
15+
end
16+
1017
def self.a_regular_file_containing(path, content)
1118
new(path, :exist? => true, :executable? => false, :content => content)
1219
end
@@ -18,7 +25,7 @@ def self.an_executable(path)
1825
def self.a_directory(path, children = [])
1926
new(path,
2027
:exist? => true,
21-
:excutable? => true,
28+
:executable? => true,
2229
:directory? => true,
2330
:children => children)
2431
end

lib/puppet/settings/environment_conf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def self.load_from(path_to_env, global_module_path)
2929
section = config.sections[:main]
3030
rescue Errno::ENOENT
3131
# environment.conf is an optional file
32+
Puppet.debug { "Path to #{path_to_env} does not exist, using default environment.conf" }
3233
end
3334

3435
new(path_to_env, section, global_module_path)

spec/integration/indirector/direct_file_server_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'spec_helper'
2-
require 'matchers/include'
32

43
require 'puppet/indirector/file_content/file'
54
require 'puppet/indirector/file_metadata/file'
@@ -30,7 +29,6 @@
3029

3130
describe Puppet::Indirector::DirectFileServer, " when interacting with FileServing::Fileset and the model" do
3231
include PuppetSpec::Files
33-
include Matchers::Include
3432

3533
matcher :file_with_content do |name, content|
3634
match do |actual|
@@ -52,7 +50,7 @@
5250
terminus = Puppet::Indirector::FileContent::File.new
5351
request = terminus.indirection.request(:search, Puppet::Util.path_to_uri(path).to_s, nil, :recurse => true)
5452

55-
expect(terminus.search(request)).to include_in_any_order(
53+
expect(terminus.search(request)).to contain_exactly(
5654
file_with_content(File.join(path, "one"), "one content"),
5755
file_with_content(File.join(path, "two"), "two content"),
5856
directory_named(path))

spec/lib/matchers/include.rb

Lines changed: 0 additions & 27 deletions
This file was deleted.

spec/lib/matchers/include_spec.rb

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)