diff --git a/nexus/db-model/src/inventory.rs b/nexus/db-model/src/inventory.rs index cb40b0d1784..ff2132e58c1 100644 --- a/nexus/db-model/src/inventory.rs +++ b/nexus/db-model/src/inventory.rs @@ -1638,7 +1638,9 @@ mod test { assert_eq!(inv_firmware.current_version(), Some("ONE")); assert_eq!(inv_firmware.next_version(), Some("TWO")); - // A missing fw version string returns None + // A missing fw version string returns None (although technically + // invalid as a device _shouldn't_ report an empty slot as being + // activated upon reset) let inv_firmware = InvNvmeDiskFirmware { inv_collection_id: typed_uuid::DbTypedUuid(TypedUuid::new_v4()), sled_id: TypedUuid::new_v4().into(), @@ -1667,81 +1669,33 @@ mod test { assert_eq!(inv_firmware.current_version(), Some("ONE")); assert_eq!(inv_firmware.next_version(), None); - // Active slot is below 1 - let inv_firmware = InvNvmeDiskFirmware { - inv_collection_id: typed_uuid::DbTypedUuid(TypedUuid::new_v4()), - sled_id: TypedUuid::new_v4().into(), - slot: 1, - active_slot: 0.into(), - next_active_slot: None, - number_of_slots: 1.into(), - slot1_is_read_only: true, - slot_firmware_versions: vec![Some("ONE".to_string())], - }; - assert_eq!(inv_firmware.current_version(), None); - assert_eq!(inv_firmware.next_version(), None); - - // Active slot is above 7 - let inv_firmware = InvNvmeDiskFirmware { - inv_collection_id: typed_uuid::DbTypedUuid(TypedUuid::new_v4()), - sled_id: TypedUuid::new_v4().into(), - slot: 1, - active_slot: 8.into(), - next_active_slot: None, - number_of_slots: 8.into(), - slot1_is_read_only: true, - slot_firmware_versions: vec![ - None, - None, - None, - None, - None, - None, - None, - Some("EIGHT".to_string()), - ], - }; - assert_eq!(inv_firmware.current_version(), None); - assert_eq!(inv_firmware.next_version(), None); - - // Next active slot is below 1 - let inv_firmware = InvNvmeDiskFirmware { - inv_collection_id: typed_uuid::DbTypedUuid(TypedUuid::new_v4()), - sled_id: TypedUuid::new_v4().into(), - slot: 1, - active_slot: 1.into(), - next_active_slot: Some(0.into()), - number_of_slots: 2.into(), - slot1_is_read_only: true, - slot_firmware_versions: vec![ - Some("ONE".to_string()), - Some("TWO".to_string()), - ], - }; - assert_eq!(inv_firmware.current_version(), Some("ONE")); - assert_eq!(inv_firmware.next_version(), None); - - // Next active slot is above 7 - let inv_firmware = InvNvmeDiskFirmware { - inv_collection_id: typed_uuid::DbTypedUuid(TypedUuid::new_v4()), - sled_id: TypedUuid::new_v4().into(), - slot: 1, - active_slot: 1.into(), - next_active_slot: Some(8.into()), - number_of_slots: 8.into(), - slot1_is_read_only: true, - slot_firmware_versions: vec![ - None, - None, - None, - None, - None, - None, - None, - Some("EIGHT".to_string()), - ], - }; - assert_eq!(inv_firmware.current_version(), None); - assert_eq!(inv_firmware.next_version(), None); + // Verify active_slot and next_active_slot below 1 or above 7 results + // in `None` + for i in [0u8, 8] { + let inv_firmware = InvNvmeDiskFirmware { + inv_collection_id: typed_uuid::DbTypedUuid(TypedUuid::new_v4()), + sled_id: TypedUuid::new_v4().into(), + slot: 1, + active_slot: i.into(), + next_active_slot: Some(i.into()), + number_of_slots: 7.into(), + slot1_is_read_only: true, + slot_firmware_versions: vec![ + Some("ONE".to_string()), + Some("TWO".to_string()), + Some("THREE".to_string()), + Some("FOUR".to_string()), + Some("FIVE".to_string()), + Some("SIX".to_string()), + Some("SEVEN".to_string()), + // Invalid in the spec but we are testing that the active + // and next active slot can't reach this value + Some("EIGHT".to_string()), + ], + }; + + assert_eq!(inv_firmware.current_version(), None); + assert_eq!(inv_firmware.next_version(), None); + } } }