Skip to content

Commit

Permalink
fix broken network interface test
Browse files Browse the repository at this point in the history
The new "instances are in the VMM state iff they have a Propolis ID"
check breaks
db::queries::network_interface::tests::test_insert_running_instance_fails. This
test suite assumes it can move an instance to the Vmm state and assign it a
Propolis ID in separate statements. That's no longer allowed; do it in one
statement instead.
  • Loading branch information
gjcolombo committed Jun 4, 2024
1 parent a6bfd3f commit 4498bad
Showing 1 changed file with 6 additions and 34 deletions.
40 changes: 6 additions & 34 deletions nexus/db-queries/src/db/queries/network_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1938,42 +1938,21 @@ mod tests {
mut instance: Instance,
state: InstanceState,
) -> Instance {
let new_runtime = model::InstanceRuntimeState {
nexus_state: state,
gen: instance.runtime_state.gen.next().into(),
..instance.runtime_state.clone()
let propolis_id = match state {
InstanceState::Vmm => Some(Uuid::new_v4()),
_ => None,
};
let res = db_datastore
.instance_update_runtime(&instance.id(), &new_runtime)
.await;
assert!(matches!(res, Ok(true)), "Failed to change instance state");
instance.runtime_state = new_runtime;
instance
}

/// Sets or clears the active Propolis ID in the supplied instance record.
/// This can be used to exercise the "does this instance have an active
/// VMM?" test that determines in part whether an instance's network
/// interfaces can change.
///
/// Note that this routine does not construct a VMM record for the
/// corresponding ID, so any functions that expect such a record to exist
/// will fail in strange and exciting ways.
async fn instance_set_active_vmm(
db_datastore: &DataStore,
mut instance: Instance,
propolis_id: Option<Uuid>,
) -> Instance {
let new_runtime = model::InstanceRuntimeState {
nexus_state: state,
propolis_id,
gen: instance.runtime_state.gen.next().into(),
..instance.runtime_state.clone()
};

let res = db_datastore
.instance_update_runtime(&instance.id(), &new_runtime)
.await;
assert!(matches!(res, Ok(true)), "Failed to change instance VMM ref");
assert!(matches!(res, Ok(true)), "Failed to change instance state");
instance.runtime_state = new_runtime;
instance
}
Expand Down Expand Up @@ -2104,7 +2083,7 @@ mod tests {
}

async fn create_running_instance(&self) -> Instance {
let instance = instance_set_state(
instance_set_state(
&self.db_datastore,
create_instance(
&self.opctx,
Expand All @@ -2114,13 +2093,6 @@ mod tests {
.await,
InstanceState::Vmm,
)
.await;

instance_set_active_vmm(
&self.db_datastore,
instance,
Some(Uuid::new_v4()),
)
.await
}
}
Expand Down

0 comments on commit 4498bad

Please sign in to comment.