Skip to content

Commit 8deb34f

Browse files
committed
add test_sled_move()
1 parent c010d14 commit 8deb34f

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

nexus/reconfigurator/planning/src/mgs_updates/host_phase_1.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,4 +900,82 @@ mod tests {
900900

901901
logctx.cleanup_successful();
902902
}
903+
904+
// Tests the case where a sled appears to move while a host OS update is
905+
// pending
906+
#[test]
907+
fn test_sled_move() {
908+
let test_name = "planning_mgs_updates_sled_move";
909+
let logctx = LogContext::new(
910+
test_name,
911+
&ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Debug },
912+
);
913+
let test_boards = TestBoards::new(test_name);
914+
915+
// Configure an update for one SP.
916+
let log = &logctx.log;
917+
let repo = test_boards.tuf_repo();
918+
let mut collection = test_boards
919+
.collection_builder()
920+
.host_active_exception(
921+
0,
922+
ARTIFACT_HASH_HOST_PHASE_1_V1,
923+
ARTIFACT_HASH_HOST_PHASE_2_V1,
924+
)
925+
.build();
926+
let nmax_updates = 1;
927+
let impossible_update_policy = ImpossibleUpdatePolicy::Reevaluate;
928+
let planned = plan_mgs_updates(
929+
log,
930+
&collection,
931+
&collection.baseboards,
932+
&PendingMgsUpdates::new(),
933+
&TargetReleaseDescription::TufRepo(repo.clone()),
934+
nmax_updates,
935+
impossible_update_policy,
936+
);
937+
assert!(!planned.pending_updates.is_empty());
938+
assert!(!planned.pending_host_phase_2_changes.is_empty());
939+
let update = planned
940+
.pending_updates
941+
.into_iter()
942+
.next()
943+
.expect("at least one update");
944+
945+
// Move an SP (as if someone had moved the sled to a different cubby).
946+
// This is awful, but at least it's easy.
947+
let sp_info = collection
948+
.sps
949+
.values_mut()
950+
.find(|sp| sp.sp_type == SpType::Sled && sp.sp_slot == 0)
951+
.expect("missing sled 0 SP");
952+
sp_info.sp_slot = 9;
953+
954+
// Plan again. The configured update should be updated to reflect the
955+
// new location.
956+
let new_planned = plan_mgs_updates(
957+
log,
958+
&collection,
959+
&collection.baseboards,
960+
&planned.pending_updates,
961+
&TargetReleaseDescription::TufRepo(repo.clone()),
962+
nmax_updates,
963+
impossible_update_policy,
964+
);
965+
assert!(!new_planned.pending_updates.is_empty());
966+
assert!(!new_planned.pending_host_phase_2_changes.is_empty());
967+
let new_update = new_planned
968+
.pending_updates
969+
.into_iter()
970+
.next()
971+
.expect("at least one update");
972+
assert_eq!(new_update.slot_id, 9);
973+
assert_eq!(new_update.baseboard_id, update.baseboard_id);
974+
assert_eq!(new_update.sp_type, update.sp_type);
975+
assert_eq!(new_update.artifact_hash, update.artifact_hash);
976+
assert_eq!(new_update.artifact_version, update.artifact_version);
977+
assert_eq!(new_update.details, update.details);
978+
979+
logctx.cleanup_successful();
980+
}
903981
}

nexus/reconfigurator/planning/src/mgs_updates/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ mod test {
19181918
assert!(!new_updates.is_empty());
19191919
let new_update =
19201920
new_updates.into_iter().next().expect("at least one update");
1921-
assert_ne!(new_update.slot_id, update.slot_id);
1921+
assert_eq!(new_update.slot_id, 9);
19221922
assert_eq!(new_update.baseboard_id, update.baseboard_id);
19231923
assert_eq!(new_update.sp_type, update.sp_type);
19241924
assert_eq!(new_update.artifact_hash, update.artifact_hash);

0 commit comments

Comments
 (0)