From ef11b93a56afead715e8b7c4dc07d56b33b797fb Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 30 Aug 2024 15:16:36 -0700 Subject: [PATCH] return 503 when instance is wayyyyy gone --- nexus/src/app/instance.rs | 10 ++++++++-- nexus/tests/integration_tests/instances.rs | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/nexus/src/app/instance.rs b/nexus/src/app/instance.rs index c6adba1f04c..fd63768fc7b 100644 --- a/nexus/src/app/instance.rs +++ b/nexus/src/app/instance.rs @@ -125,8 +125,14 @@ impl From for dropshot::HttpError { HttpError::for_internal_error(s) } // Error responses from sled-agent that indicate the instance is - // unhealthy should be mapped to a 500 error. - e if e.vmm_gone() => HttpError::for_internal_error(e.to_string()), + // unhealthy should be mapped to a 503 error. + e if e.vmm_gone() => { + let mut error = HttpError::for_unavail(None, e.to_string()); + error.external_message = "The instance was running but is no \ + longer reachable. It is being moved to the Failed state." + .to_string(); + error + } // Other client errors can be handled by the normal // `external::Error` to `HttpError` conversions. SledAgentInstanceError(e) => HttpError::from(Error::from(e)), diff --git a/nexus/tests/integration_tests/instances.rs b/nexus/tests/integration_tests/instances.rs index 9c7a04f3ac0..25c8056b223 100644 --- a/nexus/tests/integration_tests/instances.rs +++ b/nexus/tests/integration_tests/instances.rs @@ -1118,11 +1118,11 @@ async fn test_instance_failed_after_sled_agent_forgets_vmm_can_be_restarted( let instance_id = make_forgotten_instance(&cptestctx, instance_name).await; // Attempting to reboot the forgotten instance will result in a 404 - // NO_SUCH_INSTANCE from the sled-agent, which Nexus turns into a 500. + // NO_SUCH_INSTANCE from the sled-agent, which Nexus turns into a 503. expect_instance_reboot_fail( client, instance_name, - http::StatusCode::INTERNAL_SERVER_ERROR, + http::StatusCode::SERVICE_UNAVAILABLE, ) .await; @@ -1146,11 +1146,11 @@ async fn test_instance_failed_after_sled_agent_forgets_vmm_can_be_deleted( let instance_id = make_forgotten_instance(&cptestctx, instance_name).await; // Attempting to reboot the forgotten instance will result in a 404 - // NO_SUCH_INSTANCE from the sled-agent, which Nexus turns into a 500. + // NO_SUCH_INSTANCE from the sled-agent, which Nexus turns into a 503. expect_instance_reboot_fail( client, instance_name, - http::StatusCode::INTERNAL_SERVER_ERROR, + http::StatusCode::SERVICE_UNAVAILABLE, ) .await;