Skip to content

Commit

Permalink
wip: start adding test that will eventually validate behavior of resp…
Browse files Browse the repository at this point in the history
…onding to TimedOut answers from nexus
  • Loading branch information
lif committed Feb 15, 2024
1 parent ff779ee commit d18090d
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 15 deletions.
2 changes: 1 addition & 1 deletion openapi/nexus-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@
"/instances/{instance_id}/creation-success": {
"put": {
"summary": "Asynchronously report the successful result of certain instance_put calls",
"description": "(such as the potentially long-running one made during instance creation)",
"description": "(such as the potentially long-running one made during instance creation). If Nexus has already marked the instance as failed, this returns `TimedOut` so the sled-agent making the request knows to terminate the instance.",
"operationId": "cpapi_handle_instance_put_success",
"parameters": [
{
Expand Down
127 changes: 113 additions & 14 deletions sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,33 @@ mod tests {
) -> Instance {
let id = Uuid::new_v4();
let propolis_id = Uuid::new_v4();

let ticket = InstanceTicket::new_without_manager_for_test(id);

let initial_state =
fake_instance_initial_state(propolis_id, propolis_addr);

let services = fake_instance_manager_services(
logctx,
storage_handle,
nexus_client_with_resolver,
);

Instance::new(
logctx.log.new(o!("component" => "Instance")),
id,
propolis_id,
ticket,
initial_state,
services,
)
.unwrap()
}

fn fake_instance_initial_state(
propolis_id: Uuid,
propolis_addr: SocketAddr,
) -> InstanceInitialState {
let hardware = InstanceHardware {
properties: InstanceProperties {
ncpus: InstanceCpuCount(1),
Expand All @@ -1495,7 +1521,7 @@ mod tests {
cloud_init_bytes: None,
};

let initial_state = InstanceInitialState {
InstanceInitialState {
hardware,
instance_runtime: InstanceRuntimeState {
propolis_id: Some(propolis_id),
Expand All @@ -1510,8 +1536,14 @@ mod tests {
time_updated: Default::default(),
},
propolis_addr,
};
}
}

fn fake_instance_manager_services(
logctx: &LogContext,
storage_handle: StorageHandle,
nexus_client_with_resolver: NexusClientWithResolver,
) -> InstanceManagerServices {
let vnic_allocator =
VnicAllocator::new("Foo", Etherstub("mystub".to_string()));
let port_manager = PortManager::new(
Expand All @@ -1526,24 +1558,14 @@ mod tests {
cleanup_context,
);

let services = InstanceManagerServices {
InstanceManagerServices {
nexus_client: nexus_client_with_resolver,
vnic_allocator,
port_manager,
storage: storage_handle,
zone_bundler,
zone_builder_factory: ZoneBuilderFactory::fake(),
};

Instance::new(
logctx.log.new(o!("component" => "Instance")),
id,
propolis_id,
ticket,
initial_state,
services,
)
.unwrap()
}
}

#[tokio::test]
Expand Down Expand Up @@ -1724,4 +1746,81 @@ mod tests {

logctx.cleanup_successful();
}

#[tokio::test]
async fn test_instance_manager_creation_nexus_timeout() {
let logctx = omicron_test_utils::dev::test_setup_log(
"test_instance_manager_creation_nexus_timeout",
);

let storage_handle = fake_storage_manager_with_u2().await;

let (nexus_client, nexus_server, state_rx) = fake_nexus_server(&logctx);

let (_dns_server, resolver, _dns_config_dir) =
timeout(TIMEOUT_DURATION, dns_server(&logctx, &nexus_server))
.await
.expect("timed out making DNS server and Resolver");

let nexus_client_with_resolver =
NexusClientWithResolver::new_with_client(nexus_client, resolver);

let InstanceManagerServices {
nexus_client,
vnic_allocator: _,
port_manager,
storage,
zone_bundler,
zone_builder_factory,
} = fake_instance_manager_services(
&logctx,
storage_handle,
nexus_client_with_resolver,
);

let etherstub = Etherstub("mystub".to_string());

let mgr = crate::instance_manager::InstanceManager::new(
logctx.log.new(o!("component" => "InstanceManager")),
nexus_client,
etherstub,
port_manager,
storage,
zone_bundler,
zone_builder_factory,
)
.unwrap();

let (propolis_server, _propolis_client) =
propolis_mock_server(&logctx.log);
let propolis_addr = propolis_server.local_addr();

// automock'd things used during this test
let _mock_vnic_contexts = mock_vnic_contexts();
let _mock_zone_contexts = mock_zone_contexts();

let instance_id = Uuid::new_v4();
let propolis_id = Uuid::new_v4();
let InstanceInitialState {
hardware,
instance_runtime,
vmm_runtime,
propolis_addr,
} = fake_instance_initial_state(propolis_id, propolis_addr);

mgr.ensure_registered(
instance_id,
propolis_id,
hardware,
instance_runtime,
vmm_runtime,
propolis_addr,
)
.await
.unwrap();

todo!();

logctx.cleanup_successful();
}
}

0 comments on commit d18090d

Please sign in to comment.