Skip to content

Commit

Permalink
Cleanup list uninitialized sled API (#4698)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andrewjstone authored Dec 18, 2023
1 parent 6d3b8be commit 8ad838e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 46 deletions.
2 changes: 1 addition & 1 deletion nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UninitializedSled> {
Expand Down
12 changes: 6 additions & 6 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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<Arc<ServerContext>>,
) -> Result<HttpResponseOk<Vec<UninitializedSled>>, HttpError> {
) -> Result<HttpResponseOk<ResultsPage<UninitializedSled>>, 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
}
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
15 changes: 9 additions & 6 deletions nexus/tests/integration_tests/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Vec<UninitializedSled>>()
.unwrap();
.parsed_body::<ResultsPage<UninitializedSled>>()
.unwrap()
.items;
debug!(cptestctx.logctx.log, "{:#?}", uninitialized_sleds);

// There are currently two fake sim gimlets created in the latest inventory
Expand Down Expand Up @@ -137,8 +139,9 @@ async fn test_uninitialized_sled_list(cptestctx: &ControlPlaneTestContext) {
.execute()
.await
.expect("failed to get uninitialized sleds")
.parsed_body::<Vec<UninitializedSled>>()
.unwrap();
.parsed_body::<ResultsPage<UninitializedSled>>()
.unwrap()
.items;
debug!(cptestctx.logctx.log, "{:#?}", uninitialized_sleds);
assert_eq!(1, uninitialized_sleds_2.len());
assert_eq!(uninitialized_sleds, uninitialized_sleds_2);
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/output/nexus_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 48 additions & 31 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 8ad838e

Please sign in to comment.