Skip to content

Commit f31d35f

Browse files
(maint) Merge up 24de536 to main
Generated by CI * commit '24de5369552e6b13775c268b1552b2ded214413f': (packaging) Updating manpage file for 6.x (PUP-11379) Agent no longer calls local enc script
2 parents d90aaec + 24de536 commit f31d35f

File tree

3 files changed

+102
-59
lines changed

3 files changed

+102
-59
lines changed

lib/puppet/configurer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def run_internal(options)
392392
Puppet.debug(_("Environment not passed via CLI and no catalog was given, attempting to find out the last server-specified environment"))
393393
initial_environment, loaded_last_environment = last_server_specified_environment
394394

395-
unless loaded_last_environment
395+
unless Puppet[:use_last_environment] && loaded_last_environment
396396
Puppet.debug(_("Requesting environment from the server"))
397397
initial_environment = current_server_specified_environment(@environment, configured_environment, options)
398398
end

lib/puppet/defaults.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ def self.initialize_default_settings!(settings)
421421
<https://puppet.com/docs/puppet/latest/environments_about.html>",
422422
:type => :path,
423423
},
424+
:use_last_environment => {
425+
:type => :boolean,
426+
:default => true,
427+
:desc => <<-'EOT'
428+
Puppet saves both the initial and converged environment in the last_run_summary file.
429+
If they differ, and this setting is set to true, we will use the last converged
430+
environment and skip the node request.
431+
432+
When set to false, we will do the node request and ignore the environment data from the last_run_summary file.
433+
EOT
434+
},
424435
:always_retry_plugins => {
425436
:type => :boolean,
426437
:default => true,

spec/unit/configurer_spec.rb

Lines changed: 90 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,88 +1251,120 @@ def expects_neither_new_or_cached_catalog
12511251
converged_environment: #{last_server_specified_environment}
12521252
run_mode: agent
12531253
SUMMARY
1254+
end
12541255

1255-
expect(Puppet::Node.indirection).not_to receive(:find)
1256+
describe "when the use_last_environment is set to true" do
1257+
before do
1258+
expect(Puppet::Node.indirection).not_to receive(:find)
12561259
.with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1257-
end
1260+
end
12581261

1259-
it "prefers the environment set via cli" do
1260-
Puppet.settings.handlearg('--environment', 'usethis')
1261-
configurer.run
1262+
it "prefers the environment set via cli" do
1263+
Puppet.settings.handlearg('--environment', 'usethis')
1264+
configurer.run
12621265

1263-
expect(configurer.environment).to eq('usethis')
1264-
end
1266+
expect(configurer.environment).to eq('usethis')
1267+
end
12651268

1266-
it "prefers the environment set via lastrunfile over config" do
1267-
FileUtils.mkdir_p(Puppet[:confdir])
1268-
set_puppet_conf(Puppet[:confdir], <<~CONF)
1269-
[main]
1270-
environment = usethis
1271-
lastrunfile = #{Puppet[:lastrunfile]}
1272-
CONF
1269+
it "prefers the environment set via lastrunfile over config" do
1270+
FileUtils.mkdir_p(Puppet[:confdir])
1271+
set_puppet_conf(Puppet[:confdir], <<~CONF)
1272+
[main]
1273+
environment = usethis
1274+
lastrunfile = #{Puppet[:lastrunfile]}
1275+
CONF
12731276

1274-
Puppet.initialize_settings
1275-
configurer.run
1277+
Puppet.initialize_settings
1278+
configurer.run
12761279

1277-
expect(configurer.environment).to eq(last_server_specified_environment)
1278-
end
1280+
expect(configurer.environment).to eq(last_server_specified_environment)
1281+
end
12791282

1280-
it "uses the environment from Puppet[:environment] if given a catalog" do
1281-
configurer.run(catalog: catalog)
1283+
it "uses the environment from Puppet[:environment] if given a catalog" do
1284+
configurer.run(catalog: catalog)
12821285

1283-
expect(configurer.environment).to eq(Puppet[:environment])
1284-
end
1286+
expect(configurer.environment).to eq(Puppet[:environment])
1287+
end
12851288

1286-
it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1287-
Puppet[:use_cached_catalog] = true
1288-
expects_cached_catalog_only(catalog)
1289-
configurer.run
1289+
it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1290+
Puppet[:use_cached_catalog] = true
1291+
expects_cached_catalog_only(catalog)
1292+
configurer.run
12901293

1291-
expect(configurer.environment).to eq(Puppet[:environment])
1292-
end
1294+
expect(configurer.environment).to eq(Puppet[:environment])
1295+
end
12931296

1294-
describe "when the environment is not set via CLI" do
1295-
it "uses the environment found in lastrunfile if the key exists" do
1296-
configurer.run
1297+
describe "when the environment is not set via CLI" do
1298+
it "uses the environment found in lastrunfile if the key exists" do
1299+
configurer.run
12971300

1298-
expect(configurer.environment).to eq(last_server_specified_environment)
1301+
expect(configurer.environment).to eq(last_server_specified_environment)
1302+
end
1303+
1304+
it "pushes the converged environment found in lastrunfile over the existing context" do
1305+
initial_env = Puppet::Node::Environment.remote('production')
1306+
Puppet.push_context(
1307+
current_environment: initial_env,
1308+
loaders: Puppet::Pops::Loaders.new(initial_env, true))
1309+
1310+
expect(Puppet).to receive(:push_context).with(
1311+
hash_including(:current_environment, :loaders),
1312+
"Local node environment #{last_server_specified_environment} for configurer transaction"
1313+
).once.and_call_original
1314+
1315+
configurer.run
1316+
end
1317+
1318+
it "uses the environment from Puppet[:environment] if strict_environment_mode is set" do
1319+
Puppet[:strict_environment_mode] = true
1320+
configurer.run
1321+
1322+
expect(configurer.environment).to eq(Puppet[:environment])
1323+
end
1324+
1325+
it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1326+
Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1327+
---
1328+
version:
1329+
config: 1624882680
1330+
puppet: 6.24.0
1331+
application:
1332+
initial_environment: development
1333+
converged_environment: development
1334+
run_mode: agent
1335+
SUMMARY
1336+
configurer.run
1337+
1338+
expect(configurer.environment).to eq(Puppet[:environment])
1339+
end
12991340
end
1341+
end
13001342

1301-
it "pushes the converged environment found in lastrunfile over the existing context" do
1302-
initial_env = Puppet::Node::Environment.remote('production')
1303-
Puppet.push_context(
1304-
current_environment: initial_env,
1305-
loaders: Puppet::Pops::Loaders.new(initial_env, true))
1343+
describe "when the use_last_environment setting is set to false" do
1344+
let(:node_environment) { Puppet::Node::Environment.remote(:salam) }
1345+
let(:node) { Puppet::Node.new(Puppet[:node_name_value]) }
13061346

1307-
expect(Puppet).to receive(:push_context).with(
1308-
hash_including(:current_environment, :loaders),
1309-
"Local node environment #{last_server_specified_environment} for configurer transaction"
1310-
).once.and_call_original
1347+
before do
1348+
Puppet[:use_last_environment] = false
1349+
node.environment = node_environment
13111350

1312-
configurer.run
1351+
allow(Puppet::Node.indirection).to receive(:find)
1352+
allow(Puppet::Node.indirection).to receive(:find)
1353+
.with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1354+
.and_return(node)
13131355
end
13141356

1315-
it "uses the environment from Puppet[:environment] if strict_environment_mode is set" do
1316-
Puppet[:strict_environment_mode] = true
1317-
configurer.run
1357+
it "does a node request" do
1358+
expect(Puppet::Node.indirection).to receive(:find)
1359+
.with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
13181360

1319-
expect(configurer.environment).to eq(Puppet[:environment])
1361+
configurer.run
13201362
end
13211363

1322-
it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1323-
Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1324-
---
1325-
version:
1326-
config: 1624882680
1327-
puppet: 6.24.0
1328-
application:
1329-
initial_environment: development
1330-
converged_environment: development
1331-
run_mode: agent
1332-
SUMMARY
1364+
it "uses the node environment from the node request" do
13331365
configurer.run
13341366

1335-
expect(configurer.environment).to eq(Puppet[:environment])
1367+
expect(configurer.environment).to eq(node_environment.name.to_s)
13361368
end
13371369
end
13381370
end

0 commit comments

Comments
 (0)