Skip to content

Commit c6b8e28

Browse files
authored
Merge pull request #8689 from gimmyxd/PUP-10308
(PUP-10308) Fix Puppet.lookup(:current_environment)
2 parents c0071fc + 5dd6454 commit c6b8e28

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/puppet/configurer.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ def run_internal(options)
383383
@environment = catalog.environment
384384
report.environment = @environment
385385

386+
new_env = Puppet::Node::Environment.remote(@environment)
387+
Puppet.push_context(
388+
{
389+
:current_environment => new_env,
390+
:loaders => Puppet::Pops::Loaders.new(new_env, true)
391+
},
392+
"Local node environment #{@environment} for configurer transaction"
393+
)
394+
386395
query_options, facts = get_facts(options)
387396
query_options[:configured_environment] = configured_environment
388397

spec/unit/configurer_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,23 @@ def expects_neither_new_or_cached_catalog
947947
expect(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(apple, banana, banana)
948948

949949
allow(Puppet).to receive(:notice)
950+
allow(Puppet).to receive(:push_context)
950951
expect(Puppet).to receive(:notice).with("Local environment: 'production' doesn't match server specified environment 'apple', restarting agent run with environment 'apple'")
951952
expect(Puppet).to receive(:notice).with("Local environment: 'apple' doesn't match server specified environment 'banana', restarting agent run with environment 'banana'")
952953

954+
expect(Puppet).to receive(:push_context).with(
955+
hash_including(current_environment: an_object_having_attributes(name: :production)),
956+
'Local node environment production for configurer transaction'
957+
)
958+
expect(Puppet).to receive(:push_context).with(
959+
hash_including(current_environment: an_object_having_attributes(name: :apple)),
960+
'Local node environment apple for configurer transaction'
961+
)
962+
expect(Puppet).to receive(:push_context).with(
963+
hash_including(current_environment: an_object_having_attributes(name: :banana)),
964+
'Local node environment banana for configurer transaction'
965+
)
966+
953967
configurer.run
954968
end
955969

0 commit comments

Comments
 (0)