Skip to content

Commit

Permalink
also make snapshot_create tests wait for NoVmm
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Jul 4, 2024
1 parent 0f986e1 commit 9da775b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions nexus/src/app/sagas/snapshot_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,9 +1625,11 @@ mod test {
use omicron_common::api::external::InstanceCpuCount;
use omicron_common::api::external::Name;
use omicron_common::api::external::NameOrId;
use omicron_test_utils::dev::poll;
use sled_agent_client::types::CrucibleOpts;
use sled_agent_client::TestInterfaces as SledAgentTestInterfaces;
use std::str::FromStr;
use std::time::Duration;

type DiskTest<'a> =
nexus_test_utils::resource_helpers::DiskTest<'a, crate::Server>;
Expand Down Expand Up @@ -2184,6 +2186,31 @@ mod test {
PROJECT_NAME,
)
.await;
// Wait until the instance has advanced to the `NoVmm`
// state before deleting it. This may not happen
// immediately, as the `Nexus::cpapi_instances_put` API
// endpoint simply writes the new VMM state to the
// database and *starts* an `instance-update` saga, and
// the instance record isn't updated until that saga
// completes.
poll::wait_for_condition(
|| async {
let new_state = test_helpers::instance_fetch_by_name(
cptestctx,
INSTANCE_NAME,
PROJECT_NAME,
)
.await;
if new_state.instance().runtime().nexus_state != nexus_db_model::InstanceState::NoVmm {
Err(poll::CondCheckError::<()>::NotYet)
} else {
Ok(())
}
},
&Duration::from_secs(5),
&Duration::from_secs(300),
)
.await.expect("instance did not advance to NoVmm after 400 seconds");
test_helpers::instance_delete_by_name(
cptestctx,
INSTANCE_NAME,
Expand Down
32 changes: 32 additions & 0 deletions nexus/src/app/sagas/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,38 @@ pub async fn instance_fetch(
db_state
}

pub async fn instance_fetch_by_name(
cptestctx: &ControlPlaneTestContext,
name: &str,
project_name: &str,
) -> InstanceAndActiveVmm {
let datastore = cptestctx.server.server_context().nexus.datastore().clone();

let nexus = &cptestctx.server.server_context().nexus;
let opctx = test_opctx(&cptestctx);
let instance_selector =
nexus_types::external_api::params::InstanceSelector {
project: Some(project_name.to_string().try_into().unwrap()),
instance: name.to_string().try_into().unwrap(),
};

let instance_lookup =
nexus.instance_lookup(&opctx, instance_selector).unwrap();
let (_, _, authz_instance, ..) = instance_lookup.fetch().await.unwrap();

let db_state = datastore
.instance_fetch_with_vmm(&opctx, &authz_instance)
.await
.expect("test instance's info should be fetchable");

info!(&cptestctx.logctx.log, "fetched instance info from db";
"instance_name" => %name,
"project_name" => %project_name,
"instance_id" => %authz_instance.id(),
"instance_and_vmm" => ?db_state);

db_state
}
pub async fn no_virtual_provisioning_resource_records_exist(
cptestctx: &ControlPlaneTestContext,
) -> bool {
Expand Down

0 comments on commit 9da775b

Please sign in to comment.