From c0246bf3bace069a80948acae28d56dcd5452bea Mon Sep 17 00:00:00 2001 From: James MacMahon Date: Thu, 16 Jan 2025 19:44:53 -0500 Subject: [PATCH] Fix `test_sled_instance_list` (#7367) `test_sled_instance_list` was broken by the most recent change to the control plane test context: previously only one of the two sled agents (the first one) was provisionable for instances, and the test would check that one to test the sled instances list endpoint. The most recent change to the test context made all sled agents provisionable but didn't update the test to check all the sleds for the provisioned instance. This resulted in a test flake: if the instance was allocated to the first sled, it would pass. If it was allocated to the second sled, it would time out. Fixes #7365 --- nexus/tests/integration_tests/sleds.rs | 43 ++++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/nexus/tests/integration_tests/sleds.rs b/nexus/tests/integration_tests/sleds.rs index 1f0b36ca09..6d0b3bae73 100644 --- a/nexus/tests/integration_tests/sleds.rs +++ b/nexus/tests/integration_tests/sleds.rs @@ -162,14 +162,18 @@ async fn test_sled_instance_list(cptestctx: &ControlPlaneTestContext) { // Verify that there are two sleds to begin with. let sleds_url = "/v1/system/hardware/sleds"; - assert_eq!(sleds_list(&external_client, &sleds_url).await.len(), 2); - - // Verify that there are no instances. - let instances_url = - format!("/v1/system/hardware/sleds/{SLED_AGENT_UUID}/instances"); - assert!(sled_instance_list(&external_client, &instances_url) - .await - .is_empty()); + let sleds = sleds_list(&external_client, &sleds_url).await; + assert_eq!(sleds.len(), 2); + + // Verify that there are no instances on the sleds. + for sled in &sleds { + let sled_id = sled.identity.id; + let instances_url = + format!("/v1/system/hardware/sleds/{sled_id}/instances"); + assert!(sled_instance_list(&external_client, &instances_url) + .await + .is_empty()); + } // Create an IP pool and project that we'll use for testing. create_default_ip_pool(&external_client).await; @@ -181,14 +185,27 @@ async fn test_sled_instance_list(cptestctx: &ControlPlaneTestContext) { // Ensure 1 instance was created on a sled let sled_instances = wait_for_condition( || { - let instances_url = instances_url.clone(); + let sleds = sleds.clone(); async move { - let sled_instances = - sled_instance_list(&external_client, &instances_url).await; + let mut total_instances = vec![]; + + for sled in &sleds { + let sled_id = sled.identity.id; + + let instances_url = format!( + "/v1/system/hardware/sleds/{sled_id}/instances" + ); + + let mut sled_instances = + sled_instance_list(&external_client, &instances_url) + .await; + + total_instances.append(&mut sled_instances); + } - if sled_instances.len() == 1 { - Ok(sled_instances) + if total_instances.len() == 1 { + Ok(total_instances) } else { Err(CondCheckError::<()>::NotYet) }