@@ -29,7 +29,6 @@ use nexus_types::deployment::BlueprintZoneFilter;
29
29
use nexus_types:: deployment:: OmicronZoneNic ;
30
30
use nexus_types:: deployment:: PlanningInput ;
31
31
use nexus_types:: deployment:: SledFilter ;
32
- use nexus_types:: deployment:: SledLookupErrorKind ;
33
32
use nexus_types:: deployment:: { Blueprint , UnstableReconfiguratorState } ;
34
33
use nexus_types:: internal_api:: params:: DnsConfigParams ;
35
34
use nexus_types:: inventory:: Collection ;
@@ -152,18 +151,6 @@ impl ReconfiguratorSim {
152
151
assert ! ( previous. is_none( ) ) ;
153
152
}
154
153
155
- fn blueprint_insert_loaded (
156
- & mut self ,
157
- blueprint : Blueprint ,
158
- ) -> Result < ( ) , anyhow:: Error > {
159
- let entry = self . blueprints . entry ( blueprint. id ) ;
160
- if let indexmap:: map:: Entry :: Occupied ( _) = & entry {
161
- return Err ( anyhow ! ( "blueprint already exists: {}" , blueprint. id) ) ;
162
- }
163
- let _ = entry. or_insert ( blueprint) ;
164
- Ok ( ( ) )
165
- }
166
-
167
154
fn planning_input (
168
155
& self ,
169
156
parent_blueprint : & Blueprint ,
@@ -1162,6 +1149,10 @@ fn cmd_load(
1162
1149
sim : & mut ReconfiguratorSim ,
1163
1150
args : LoadArgs ,
1164
1151
) -> anyhow:: Result < Option < String > > {
1152
+ if sim. user_made_system_changes ( ) {
1153
+ bail ! ( "changes made to simulated system: run `wipe` before loading" ) ;
1154
+ }
1155
+
1165
1156
let input_path = args. filename ;
1166
1157
let collection_id = args. collection_id ;
1167
1158
let loaded = read_file ( & input_path) ?;
@@ -1205,44 +1196,9 @@ fn cmd_load(
1205
1196
} ,
1206
1197
) ?;
1207
1198
1208
- let current_planning_input = sim
1209
- . system
1210
- . to_planning_input_builder ( )
1211
- . context ( "generating planning input" ) ?
1212
- . build ( ) ;
1213
1199
for ( sled_id, sled_details) in
1214
1200
loaded. planning_input . all_sleds ( SledFilter :: Commissioned )
1215
1201
{
1216
- match current_planning_input
1217
- . sled_lookup ( SledFilter :: Commissioned , sled_id)
1218
- {
1219
- Ok ( _) => {
1220
- swriteln ! (
1221
- s,
1222
- "sled {}: skipped (one with \
1223
- the same id is already loaded)",
1224
- sled_id
1225
- ) ;
1226
- continue ;
1227
- }
1228
- Err ( error) => match error. kind ( ) {
1229
- SledLookupErrorKind :: Filtered { .. } => {
1230
- swriteln ! (
1231
- s,
1232
- "error: load sled {}: turning a decommissioned sled \
1233
- into a commissioned one is not supported",
1234
- sled_id
1235
- ) ;
1236
- continue ;
1237
- }
1238
- SledLookupErrorKind :: Missing => {
1239
- // A sled being missing from the input is the only case in
1240
- // which we decide to load new sleds. The logic to do that
1241
- // is below.
1242
- }
1243
- } ,
1244
- }
1245
-
1246
1202
let Some ( inventory_sled_agent) =
1247
1203
primary_collection. sled_agents . get ( & sled_id)
1248
1204
else {
@@ -1290,32 +1246,38 @@ fn cmd_load(
1290
1246
}
1291
1247
1292
1248
for collection in loaded. collections {
1293
- if sim. collections . contains_key ( & collection. id ) {
1294
- swriteln ! (
1295
- s,
1296
- "collection {}: skipped (one with the \
1297
- same id is already loaded)",
1298
- collection. id
1299
- ) ;
1300
- } else {
1301
- swriteln ! ( s, "collection {} loaded" , collection. id) ;
1302
- sim. collections . insert ( collection. id , collection) ;
1249
+ match sim. collections . entry ( collection. id ) {
1250
+ indexmap:: map:: Entry :: Occupied ( _) => {
1251
+ // We started with an empty system, so the only way we can hit
1252
+ // this is if the serialized state contains a duplicate
1253
+ // collection ID.
1254
+ swriteln ! (
1255
+ s,
1256
+ "error: collection {} skipped (duplicate found)" ,
1257
+ collection. id
1258
+ )
1259
+ }
1260
+ indexmap:: map:: Entry :: Vacant ( entry) => {
1261
+ swriteln ! ( s, "collection {} loaded" , collection. id) ;
1262
+ entry. insert ( collection) ;
1263
+ }
1303
1264
}
1304
1265
}
1305
1266
1306
1267
for blueprint in loaded. blueprints {
1307
- let blueprint_id = blueprint. id ;
1308
- match sim. blueprint_insert_loaded ( blueprint) {
1309
- Ok ( _) => {
1310
- swriteln ! ( s, "blueprint {} loaded" , blueprint_id) ;
1311
- }
1312
- Err ( error) => {
1268
+ match sim. blueprints . entry ( blueprint. id ) {
1269
+ // We started with an empty system, so the only way we can hit this
1270
+ // is if the serialized state contains a duplicate blueprint ID.
1271
+ indexmap:: map:: Entry :: Occupied ( _) => {
1313
1272
swriteln ! (
1314
1273
s,
1315
- "blueprint {}: skipped ({:#})" ,
1316
- blueprint_id,
1317
- error
1318
- ) ;
1274
+ "error: blueprint {} skipped (duplicate found)" ,
1275
+ blueprint. id
1276
+ )
1277
+ }
1278
+ indexmap:: map:: Entry :: Vacant ( entry) => {
1279
+ swriteln ! ( s, "blueprint {} loaded" , blueprint. id) ;
1280
+ entry. insert ( blueprint) ;
1319
1281
}
1320
1282
}
1321
1283
}
@@ -1356,10 +1318,7 @@ fn cmd_load_example(
1356
1318
args : LoadExampleArgs ,
1357
1319
) -> anyhow:: Result < Option < String > > {
1358
1320
if sim. user_made_system_changes ( ) {
1359
- bail ! (
1360
- "changes made to simulated system: run `wipe system` before \
1361
- loading an example system"
1362
- ) ;
1321
+ bail ! ( "changes made to simulated system: run `wipe` before loading" ) ;
1363
1322
}
1364
1323
1365
1324
// Generate the example system.
0 commit comments