From 8ad838eac6b972134f3689c728126eb0f6311ffb Mon Sep 17 00:00:00 2001 From: "Andrew J. Stone" Date: Mon, 18 Dec 2023 16:20:31 -0500 Subject: [PATCH] Cleanup list uninitialized sled API (#4698) * Rename `uninitialized_sled_list` to `sled_list_uninitialized` * Rename endpoint from `v1/system/hardware/uninitialized-sleds` to `v1/system/hardware/sleds-uninitialized` * Add fake pagination to this API endpoint Fixes part of #4607 --- nexus/src/app/rack.rs | 2 +- nexus/src/external_api/http_entrypoints.rs | 12 ++-- nexus/tests/integration_tests/endpoints.rs | 2 +- nexus/tests/integration_tests/rack.rs | 15 ++-- nexus/tests/output/nexus_tags.txt | 2 +- openapi/nexus.json | 79 +++++++++++++--------- 6 files changed, 66 insertions(+), 46 deletions(-) diff --git a/nexus/src/app/rack.rs b/nexus/src/app/rack.rs index 168e9eeaa3..c0307e5b5b 100644 --- a/nexus/src/app/rack.rs +++ b/nexus/src/app/rack.rs @@ -866,7 +866,7 @@ impl super::Nexus { // // TODO-multirack: We currently limit sleds to a single rack and we also // retrieve the `rack_uuid` from the Nexus instance used. - pub(crate) async fn uninitialized_sled_list( + pub(crate) async fn sled_list_uninitialized( &self, opctx: &OpContext, ) -> ListResultVec { diff --git a/nexus/src/external_api/http_entrypoints.rs b/nexus/src/external_api/http_entrypoints.rs index 042ee294b7..8a4aeaeff5 100644 --- a/nexus/src/external_api/http_entrypoints.rs +++ b/nexus/src/external_api/http_entrypoints.rs @@ -227,7 +227,7 @@ pub(crate) fn external_api() -> NexusApiDescription { api.register(physical_disk_list)?; api.register(switch_list)?; api.register(switch_view)?; - api.register(uninitialized_sled_list)?; + api.register(sled_list_uninitialized)?; api.register(add_sled_to_initialized_rack)?; api.register(user_builtin_list)?; @@ -4654,18 +4654,18 @@ async fn rack_view( /// List uninitialized sleds in a given rack #[endpoint { method = GET, - path = "/v1/system/hardware/uninitialized-sleds", + path = "/v1/system/hardware/sleds-uninitialized", tags = ["system/hardware"] }] -async fn uninitialized_sled_list( +async fn sled_list_uninitialized( rqctx: RequestContext>, -) -> Result>, HttpError> { +) -> Result>, HttpError> { let apictx = rqctx.context(); let handler = async { let nexus = &apictx.nexus; let opctx = crate::context::op_context_for_external_api(&rqctx).await?; - let sleds = nexus.uninitialized_sled_list(&opctx).await?; - Ok(HttpResponseOk(sleds)) + let sleds = nexus.sled_list_uninitialized(&opctx).await?; + Ok(HttpResponseOk(ResultsPage { items: sleds, next_page: None })) }; apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await } diff --git a/nexus/tests/integration_tests/endpoints.rs b/nexus/tests/integration_tests/endpoints.rs index c41fcdbed9..545129d567 100644 --- a/nexus/tests/integration_tests/endpoints.rs +++ b/nexus/tests/integration_tests/endpoints.rs @@ -47,7 +47,7 @@ lazy_static! { pub static ref HARDWARE_RACK_URL: String = format!("/v1/system/hardware/racks/{}", RACK_UUID); pub static ref HARDWARE_UNINITIALIZED_SLEDS: String = - format!("/v1/system/hardware/uninitialized-sleds"); + format!("/v1/system/hardware/sleds-uninitialized"); pub static ref HARDWARE_SLED_URL: String = format!("/v1/system/hardware/sleds/{}", SLED_AGENT_UUID); pub static ref HARDWARE_SLED_PROVISION_STATE_URL: String = diff --git a/nexus/tests/integration_tests/rack.rs b/nexus/tests/integration_tests/rack.rs index 9f77223871..a6fc93e92a 100644 --- a/nexus/tests/integration_tests/rack.rs +++ b/nexus/tests/integration_tests/rack.rs @@ -2,6 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +use dropshot::ResultsPage; use http::Method; use http::StatusCode; use nexus_test_utils::http_testing::AuthnMode; @@ -85,18 +86,19 @@ async fn test_rack_initialization(cptestctx: &ControlPlaneTestContext) { } #[nexus_test] -async fn test_uninitialized_sled_list(cptestctx: &ControlPlaneTestContext) { +async fn test_sled_list_uninitialized(cptestctx: &ControlPlaneTestContext) { let internal_client = &cptestctx.internal_client; let external_client = &cptestctx.external_client; - let list_url = "/v1/system/hardware/uninitialized-sleds"; + let list_url = "/v1/system/hardware/sleds-uninitialized"; let mut uninitialized_sleds = NexusRequest::object_get(external_client, &list_url) .authn_as(AuthnMode::PrivilegedUser) .execute() .await .expect("failed to get uninitialized sleds") - .parsed_body::>() - .unwrap(); + .parsed_body::>() + .unwrap() + .items; debug!(cptestctx.logctx.log, "{:#?}", uninitialized_sleds); // There are currently two fake sim gimlets created in the latest inventory @@ -137,8 +139,9 @@ async fn test_uninitialized_sled_list(cptestctx: &ControlPlaneTestContext) { .execute() .await .expect("failed to get uninitialized sleds") - .parsed_body::>() - .unwrap(); + .parsed_body::>() + .unwrap() + .items; debug!(cptestctx.logctx.log, "{:#?}", uninitialized_sleds); assert_eq!(1, uninitialized_sleds_2.len()); assert_eq!(uninitialized_sleds, uninitialized_sleds_2); diff --git a/nexus/tests/output/nexus_tags.txt b/nexus/tests/output/nexus_tags.txt index 7e1dc306d5..10e7df7286 100644 --- a/nexus/tests/output/nexus_tags.txt +++ b/nexus/tests/output/nexus_tags.txt @@ -126,12 +126,12 @@ rack_list GET /v1/system/hardware/racks rack_view GET /v1/system/hardware/racks/{rack_id} sled_instance_list GET /v1/system/hardware/sleds/{sled_id}/instances sled_list GET /v1/system/hardware/sleds +sled_list_uninitialized GET /v1/system/hardware/sleds-uninitialized sled_physical_disk_list GET /v1/system/hardware/sleds/{sled_id}/disks sled_set_provision_state PUT /v1/system/hardware/sleds/{sled_id}/provision-state sled_view GET /v1/system/hardware/sleds/{sled_id} switch_list GET /v1/system/hardware/switches switch_view GET /v1/system/hardware/switches/{switch_id} -uninitialized_sled_list GET /v1/system/hardware/uninitialized-sleds API operations found with tag "system/metrics" OPERATION ID METHOD URL PATH diff --git a/openapi/nexus.json b/openapi/nexus.json index 2a18934718..4c89706a1c 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -4015,6 +4015,33 @@ } } }, + "/v1/system/hardware/sleds-uninitialized": { + "get": { + "tags": [ + "system/hardware" + ], + "summary": "List uninitialized sleds in a given rack", + "operationId": "sled_list_uninitialized", + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UninitializedSledResultsPage" + } + } + } + }, + "4XX": { + "$ref": "#/components/responses/Error" + }, + "5XX": { + "$ref": "#/components/responses/Error" + } + } + } + }, "/v1/system/hardware/switch-port": { "get": { "tags": [ @@ -4290,37 +4317,6 @@ } } }, - "/v1/system/hardware/uninitialized-sleds": { - "get": { - "tags": [ - "system/hardware" - ], - "summary": "List uninitialized sleds in a given rack", - "operationId": "uninitialized_sled_list", - "responses": { - "200": { - "description": "successful operation", - "content": { - "application/json": { - "schema": { - "title": "Array_of_UninitializedSled", - "type": "array", - "items": { - "$ref": "#/components/schemas/UninitializedSled" - } - } - } - } - }, - "4XX": { - "$ref": "#/components/responses/Error" - }, - "5XX": { - "$ref": "#/components/responses/Error" - } - } - } - }, "/v1/system/identity-providers": { "get": { "tags": [ @@ -14888,6 +14884,27 @@ "rack_id" ] }, + "UninitializedSledResultsPage": { + "description": "A single page of results", + "type": "object", + "properties": { + "items": { + "description": "list of items on this page of results", + "type": "array", + "items": { + "$ref": "#/components/schemas/UninitializedSled" + } + }, + "next_page": { + "nullable": true, + "description": "token used to fetch the next page of results (if any)", + "type": "string" + } + }, + "required": [ + "items" + ] + }, "User": { "description": "View of a User", "type": "object",