Skip to content

Commit

Permalink
update tests to new migrate saga unwinding behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Aug 6, 2024
1 parent 7f6765d commit 58683ad
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
42 changes: 31 additions & 11 deletions nexus/src/app/sagas/instance_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,24 +717,44 @@ mod tests {
let after_saga = || -> futures::future::BoxFuture<'_, ()> {
Box::pin({
async {
// Unwinding at any step should clear the migration IDs from
// the instance record and leave the instance's location
// otherwise untouched.
let new_state =
test_helpers::instance_fetch(cptestctx, instance_id)
.await;
let new_state = test_helpers::instance_fetch_all(
cptestctx,
instance_id,
)
.await;

let new_instance = new_state.instance();
let new_vmm =
new_state.vmm().as_ref().expect("vmm should be active");
let new_instance = new_state.instance;
let new_vmm = new_state
.active_vmm
.as_ref()
.expect("vmm should be active");

assert!(new_instance.runtime().migration_id.is_none());
assert!(new_instance.runtime().dst_propolis_id.is_none());
assert_eq!(
new_instance.runtime().propolis_id.unwrap(),
new_vmm.id
);

// If the instance has had migration IDs set, then both
// sides of the migration should be marked as failed.
if let Some(migration) = new_state.migration {
assert_eq!(
migration.source_state,
db::model::MigrationState::FAILED
);
assert_eq!(
migration.target_state,
db::model::MigrationState::FAILED
);
}
// If the instance has a target VMM ID left behind by the
// unwinding saga, that VMM must be in the `SagaUnwound` state.
if let Some(target_vmm) = new_state.target_vmm {
assert_eq!(
target_vmm.runtime.state,
db::model::VmmState::SagaUnwound
);
}

info!(
&log,
"migration saga unwind: stopping instance after failed \
Expand Down
33 changes: 32 additions & 1 deletion nexus/src/app/sagas/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ use nexus_db_model::InstanceState;
use nexus_db_queries::{
authz,
context::OpContext,
db::{datastore::InstanceAndActiveVmm, lookup::LookupPath, DataStore},
db::{
datastore::{InstanceAndActiveVmm, InstanceGestalt},
lookup::LookupPath,
DataStore,
},
};
use nexus_test_interface::NexusServer;
use nexus_test_utils::start_sled_agent;
Expand Down Expand Up @@ -214,6 +218,33 @@ pub async fn instance_fetch(
db_state
}

pub async fn instance_fetch_all(
cptestctx: &ControlPlaneTestContext,
instance_id: InstanceUuid,
) -> InstanceGestalt {
let datastore = cptestctx.server.server_context().nexus.datastore().clone();
let opctx = test_opctx(&cptestctx);
let (.., authz_instance) = LookupPath::new(&opctx, &datastore)
.instance_id(instance_id.into_untyped_uuid())
.lookup_for(authz::Action::Read)
.await
.expect("test instance should be present in datastore");

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

info!(&cptestctx.logctx.log, "refetched all instance info from db";
"instance_id" => %instance_id,
"instance" => ?db_state.instance,
"active_vmm" => ?db_state.active_vmm,
"target_vmm" => ?db_state.target_vmm,
"migration" => ?db_state.migration,
);

db_state
}
pub async fn instance_fetch_by_name(
cptestctx: &ControlPlaneTestContext,
name: &str,
Expand Down

0 comments on commit 58683ad

Please sign in to comment.