@@ -1251,88 +1251,120 @@ def expects_neither_new_or_cached_catalog
1251
1251
converged_environment: #{ last_server_specified_environment }
1252
1252
run_mode: agent
1253
1253
SUMMARY
1254
+ end
1254
1255
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 )
1256
1259
. with ( anything , hash_including ( :ignore_cache => true , :fail_on_404 => true ) )
1257
- end
1260
+ end
1258
1261
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
1262
1265
1263
- expect ( configurer . environment ) . to eq ( 'usethis' )
1264
- end
1266
+ expect ( configurer . environment ) . to eq ( 'usethis' )
1267
+ end
1265
1268
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
1273
1276
1274
- Puppet . initialize_settings
1275
- configurer . run
1277
+ Puppet . initialize_settings
1278
+ configurer . run
1276
1279
1277
- expect ( configurer . environment ) . to eq ( last_server_specified_environment )
1278
- end
1280
+ expect ( configurer . environment ) . to eq ( last_server_specified_environment )
1281
+ end
1279
1282
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 )
1282
1285
1283
- expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1284
- end
1286
+ expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1287
+ end
1285
1288
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
1290
1293
1291
- expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1292
- end
1294
+ expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1295
+ end
1293
1296
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
1297
1300
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
1299
1340
end
1341
+ end
1300
1342
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 ] ) }
1306
1346
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
1311
1350
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 )
1313
1355
end
1314
1356
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 ) )
1318
1360
1319
- expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1361
+ configurer . run
1320
1362
end
1321
1363
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
1333
1365
configurer . run
1334
1366
1335
- expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1367
+ expect ( configurer . environment ) . to eq ( node_environment . name . to_s )
1336
1368
end
1337
1369
end
1338
1370
end
0 commit comments