@@ -900,4 +900,82 @@ mod tests {
900
900
901
901
logctx. cleanup_successful ( ) ;
902
902
}
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
+ }
903
981
}
0 commit comments