Skip to content

Commit 5c62815

Browse files
author
lif
committed
WIP: start adding a (temporary, to be replaced by a RPW) timeout to the api
1 parent b444aa2 commit 5c62815

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

openapi/sled-agent.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4729,6 +4729,12 @@
47294729
"description": "The response sent from a request to move an instance into a specific runtime state.",
47304730
"type": "object",
47314731
"properties": {
4732+
"expect_callback_in_seconds": {
4733+
"nullable": true,
4734+
"description": "The amount of time Nexus should wait before giving up on getting a response from an instance_put_state call with an asynchronous implementation (i.e. instance creation zone installation).",
4735+
"type": "number",
4736+
"format": "double"
4737+
},
47324738
"updated_runtime": {
47334739
"nullable": true,
47344740
"description": "The current runtime state of the instance after handling the request to change its state. If the instance's state did not change, this field is `None`.",

sled-agent/src/instance_manager.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ impl InstanceManager {
353353
InstanceStateRequested::Stopped => {
354354
return Ok(InstancePutStateResponse {
355355
updated_runtime: None,
356+
expect_callback_in_seconds: None,
356357
});
357358
}
358359
_ => {
@@ -406,13 +407,17 @@ impl InstanceManager {
406407
}
407408
};
408409
});
409-
Ok(InstancePutStateResponse { updated_runtime: None })
410+
Ok(InstancePutStateResponse {
411+
updated_runtime: None,
412+
expect_callback_in_seconds: Some(120.0f64),
413+
})
410414
}
411415
InstanceStateRequested::Stopped
412416
| InstanceStateRequested::Reboot => {
413417
let new_state = instance.put_state(target).await?;
414418
Ok(InstancePutStateResponse {
415419
updated_runtime: Some(new_state),
420+
expect_callback_in_seconds: None,
416421
})
417422
}
418423
}

sled-agent/src/params.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ pub struct InstancePutStateResponse {
120120
/// change its state. If the instance's state did not change, this field is
121121
/// `None`.
122122
pub updated_runtime: Option<SledInstanceState>,
123+
/// The amount of time Nexus should wait before giving up on getting a
124+
/// response from an instance_put_state call with an asynchronous
125+
/// implementation (i.e. instance creation zone installation).
126+
pub expect_callback_in_seconds: Option<f64>,
123127
}
124128

125129
/// The response sent from a request to unregister an instance.

sled-agent/src/sim/sled_agent.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use std::collections::HashMap;
4545
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
4646
use std::str::FromStr;
4747
use std::sync::Arc;
48+
use std::time::Duration;
4849
use uuid::Uuid;
4950

5051
/// Simulates management of the control plane on a sled
@@ -375,6 +376,7 @@ impl SledAgent {
375376
InstanceStateRequested::Stopped => {
376377
return Ok(InstancePutStateResponse {
377378
updated_runtime: None,
379+
expect_callback_in_seconds: None,
378380
});
379381
}
380382
_ => {
@@ -395,7 +397,37 @@ impl SledAgent {
395397
));
396398
}
397399
InstanceStateRequested::Running => {
398-
propolis_client::types::InstanceStateRequested::Run
400+
let instances = self.instances.clone();
401+
let nexus_client = self.nexus_client.clone();
402+
tokio::spawn(async move {
403+
tokio::time::sleep(Duration::from_secs(10)).await;
404+
match instances
405+
.sim_ensure(&instance_id, current, Some(state))
406+
.await
407+
{
408+
Ok(state) => {
409+
let instance_state: nexus_client::types::SledInstanceState = state.into();
410+
let _: Result<_, _> = nexus_client
411+
.cpapi_handle_instance_put_success(
412+
&instance_id,
413+
&instance_state,
414+
)
415+
.await;
416+
}
417+
Err(instance_put_error) => {
418+
let _: Result<_, _> = nexus_client
419+
.cpapi_handle_instance_put_failure(
420+
&instance_id,
421+
&instance_put_error.to_string(),
422+
)
423+
.await;
424+
}
425+
}
426+
});
427+
return Ok(InstancePutStateResponse {
428+
updated_runtime: None,
429+
expect_callback_in_seconds: Some(120.0f64),
430+
});
399431
}
400432
InstanceStateRequested::Stopped => {
401433
propolis_client::types::InstanceStateRequested::Stop
@@ -420,7 +452,10 @@ impl SledAgent {
420452
self.detach_disks_from_instance(instance_id).await?;
421453
}
422454

423-
Ok(InstancePutStateResponse { updated_runtime: Some(new_state) })
455+
Ok(InstancePutStateResponse {
456+
updated_runtime: Some(new_state),
457+
expect_callback_in_seconds: None,
458+
})
424459
}
425460

426461
pub async fn set_instance_ensure_state_error(&self, error: Option<Error>) {

0 commit comments

Comments
 (0)