@@ -1128,88 +1128,120 @@ def expects_neither_new_or_cached_catalog
1128
1128
converged_environment: #{ last_server_specified_environment }
1129
1129
run_mode: agent
1130
1130
SUMMARY
1131
+ end
1131
1132
1132
- expect ( Puppet ::Node . indirection ) . not_to receive ( :find )
1133
+ describe "when the use_last_environment is set to true" do
1134
+ before do
1135
+ expect ( Puppet ::Node . indirection ) . not_to receive ( :find )
1133
1136
. with ( anything , hash_including ( :ignore_cache => true , :fail_on_404 => true ) )
1134
- end
1137
+ end
1135
1138
1136
- it "prefers the environment set via cli" do
1137
- Puppet . settings . handlearg ( '--environment' , 'usethis' )
1138
- configurer . run
1139
+ it "prefers the environment set via cli" do
1140
+ Puppet . settings . handlearg ( '--environment' , 'usethis' )
1141
+ configurer . run
1139
1142
1140
- expect ( configurer . environment ) . to eq ( 'usethis' )
1141
- end
1143
+ expect ( configurer . environment ) . to eq ( 'usethis' )
1144
+ end
1142
1145
1143
- it "prefers the environment set via lastrunfile over config" do
1144
- FileUtils . mkdir_p ( Puppet [ :confdir ] )
1145
- set_puppet_conf ( Puppet [ :confdir ] , <<~CONF )
1146
- [main]
1147
- environment = usethis
1148
- lastrunfile = #{ Puppet [ :lastrunfile ] }
1149
- CONF
1146
+ it "prefers the environment set via lastrunfile over config" do
1147
+ FileUtils . mkdir_p ( Puppet [ :confdir ] )
1148
+ set_puppet_conf ( Puppet [ :confdir ] , <<~CONF )
1149
+ [main]
1150
+ environment = usethis
1151
+ lastrunfile = #{ Puppet [ :lastrunfile ] }
1152
+ CONF
1150
1153
1151
- Puppet . initialize_settings
1152
- configurer . run
1154
+ Puppet . initialize_settings
1155
+ configurer . run
1153
1156
1154
- expect ( configurer . environment ) . to eq ( last_server_specified_environment )
1155
- end
1157
+ expect ( configurer . environment ) . to eq ( last_server_specified_environment )
1158
+ end
1156
1159
1157
- it "uses the environment from Puppet[:environment] if given a catalog" do
1158
- configurer . run ( catalog : catalog )
1160
+ it "uses the environment from Puppet[:environment] if given a catalog" do
1161
+ configurer . run ( catalog : catalog )
1159
1162
1160
- expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1161
- end
1163
+ expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1164
+ end
1162
1165
1163
- it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1164
- Puppet [ :use_cached_catalog ] = true
1165
- expects_cached_catalog_only ( catalog )
1166
- configurer . run
1166
+ it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1167
+ Puppet [ :use_cached_catalog ] = true
1168
+ expects_cached_catalog_only ( catalog )
1169
+ configurer . run
1167
1170
1168
- expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1169
- end
1171
+ expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1172
+ end
1170
1173
1171
- describe "when the environment is not set via CLI" do
1172
- it "uses the environment found in lastrunfile if the key exists" do
1173
- configurer . run
1174
+ describe "when the environment is not set via CLI" do
1175
+ it "uses the environment found in lastrunfile if the key exists" do
1176
+ configurer . run
1174
1177
1175
- expect ( configurer . environment ) . to eq ( last_server_specified_environment )
1178
+ expect ( configurer . environment ) . to eq ( last_server_specified_environment )
1179
+ end
1180
+
1181
+ it "pushes the converged environment found in lastrunfile over the existing context" do
1182
+ initial_env = Puppet ::Node ::Environment . remote ( 'production' )
1183
+ Puppet . push_context (
1184
+ current_environment : initial_env ,
1185
+ loaders : Puppet ::Pops ::Loaders . new ( initial_env , true ) )
1186
+
1187
+ expect ( Puppet ) . to receive ( :push_context ) . with (
1188
+ hash_including ( :current_environment , :loaders ) ,
1189
+ "Local node environment #{ last_server_specified_environment } for configurer transaction"
1190
+ ) . once . and_call_original
1191
+
1192
+ configurer . run
1193
+ end
1194
+
1195
+ it "uses the environment from Puppet[:environment] if strict_environment_mode is set" do
1196
+ Puppet [ :strict_environment_mode ] = true
1197
+ configurer . run
1198
+
1199
+ expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1200
+ end
1201
+
1202
+ it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1203
+ Puppet [ :lastrunfile ] = file_containing ( 'last_run_summary.yaml' , <<~SUMMARY )
1204
+ ---
1205
+ version:
1206
+ config: 1624882680
1207
+ puppet: 6.24.0
1208
+ application:
1209
+ initial_environment: development
1210
+ converged_environment: development
1211
+ run_mode: agent
1212
+ SUMMARY
1213
+ configurer . run
1214
+
1215
+ expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1216
+ end
1176
1217
end
1218
+ end
1177
1219
1178
- it "pushes the converged environment found in lastrunfile over the existing context" do
1179
- initial_env = Puppet ::Node ::Environment . remote ( 'production' )
1180
- Puppet . push_context (
1181
- current_environment : initial_env ,
1182
- loaders : Puppet ::Pops ::Loaders . new ( initial_env , true ) )
1220
+ describe "when the use_last_environment setting is set to false" do
1221
+ let ( :node_environment ) { Puppet ::Node ::Environment . remote ( :salam ) }
1222
+ let ( :node ) { Puppet ::Node . new ( Puppet [ :node_name_value ] ) }
1183
1223
1184
- expect ( Puppet ) . to receive ( :push_context ) . with (
1185
- hash_including ( :current_environment , :loaders ) ,
1186
- "Local node environment #{ last_server_specified_environment } for configurer transaction"
1187
- ) . once . and_call_original
1224
+ before do
1225
+ Puppet [ :use_last_environment ] = false
1226
+ node . environment = node_environment
1188
1227
1189
- configurer . run
1228
+ allow ( Puppet ::Node . indirection ) . to receive ( :find )
1229
+ allow ( Puppet ::Node . indirection ) . to receive ( :find )
1230
+ . with ( anything , hash_including ( :ignore_cache => true , :fail_on_404 => true ) )
1231
+ . and_return ( node )
1190
1232
end
1191
1233
1192
- it "uses the environment from Puppet[:environment] if strict_environment_mode is set " do
1193
- Puppet [ :strict_environment_mode ] = true
1194
- configurer . run
1234
+ it "does a node request " do
1235
+ expect ( Puppet :: Node . indirection ) . to receive ( :find )
1236
+ . with ( anything , hash_including ( :ignore_cache => true , :fail_on_404 => true ) )
1195
1237
1196
- expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1238
+ configurer . run
1197
1239
end
1198
1240
1199
- it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1200
- Puppet [ :lastrunfile ] = file_containing ( 'last_run_summary.yaml' , <<~SUMMARY )
1201
- ---
1202
- version:
1203
- config: 1624882680
1204
- puppet: 6.24.0
1205
- application:
1206
- initial_environment: development
1207
- converged_environment: development
1208
- run_mode: agent
1209
- SUMMARY
1241
+ it "uses the node environment from the node request" do
1210
1242
configurer . run
1211
1243
1212
- expect ( configurer . environment ) . to eq ( Puppet [ :environment ] )
1244
+ expect ( configurer . environment ) . to eq ( node_environment . name . to_s )
1213
1245
end
1214
1246
end
1215
1247
end
0 commit comments