From 53860437a76e67b03835b9433549365aea176282 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 11 Oct 2023 17:58:05 -0500 Subject: [PATCH] instance ephemeral IP test passes --- nexus/src/external_api/http_entrypoints.rs | 4 ++-- nexus/test-utils/src/resource_helpers.rs | 2 +- nexus/tests/integration_tests/instances.rs | 14 +++++++++++--- nexus/types/src/external_api/views.rs | 4 ++++ openapi/nexus.json | 11 +++++++++-- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/nexus/src/external_api/http_entrypoints.rs b/nexus/src/external_api/http_entrypoints.rs index 5f502306e8..ea5d3b5159 100644 --- a/nexus/src/external_api/http_entrypoints.rs +++ b/nexus/src/external_api/http_entrypoints.rs @@ -1315,7 +1315,7 @@ async fn ip_pool_associate( path_params: Path, resource_assoc: TypedBody, // TODO: what does this return? Returning the association record seems silly -) -> Result { +) -> Result, HttpError> { let apictx = rqctx.context(); let handler = async { let opctx = crate::context::op_context_for_external_api(&rqctx).await?; @@ -1326,7 +1326,7 @@ async fn ip_pool_associate( nexus .ip_pool_associate_resource(&opctx, &pool_lookup, &resource_assoc) .await?; - Ok(HttpResponseUpdatedNoContent()) + Ok(HttpResponseCreated(views::IpPoolResource {})) }; apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await } diff --git a/nexus/test-utils/src/resource_helpers.rs b/nexus/test-utils/src/resource_helpers.rs index d2bcf5fb86..a0d1dbfb48 100644 --- a/nexus/test-utils/src/resource_helpers.rs +++ b/nexus/test-utils/src/resource_helpers.rs @@ -146,7 +146,7 @@ pub async fn create_ip_pool( .await; // make pool available for use anywhere in fleet - let _: () = object_create( + let _assoc: views::IpPoolResource = object_create( client, &format!("/v1/system/ip-pools/{pool_name}/associate"), ¶ms::IpPoolResource { diff --git a/nexus/tests/integration_tests/instances.rs b/nexus/tests/integration_tests/instances.rs index fff61bd7c4..d6d91efba0 100644 --- a/nexus/tests/integration_tests/instances.rs +++ b/nexus/tests/integration_tests/instances.rs @@ -44,7 +44,6 @@ use omicron_common::api::external::InstanceNetworkInterface; use omicron_common::api::external::InstanceState; use omicron_common::api::external::Ipv4Net; use omicron_common::api::external::Name; -use omicron_common::api::external::NameOrId; use omicron_common::api::external::Vni; use omicron_nexus::app::MAX_MEMORY_BYTES_PER_INSTANCE; use omicron_nexus::app::MAX_VCPU_PER_INSTANCE; @@ -3416,11 +3415,20 @@ async fn test_instance_ephemeral_ip_from_correct_pool( name: pool_name.parse().unwrap(), description: String::from("an ip pool"), }, - // silo: Some(NameOrId::Id(DEFAULT_SILO.id())), - // is_default: true, }, ) .await; + let params = params::IpPoolResource { + resource_id: DEFAULT_SILO.id(), + resource_type: params::IpPoolResourceType::Silo, + is_default: true, + }; + let assoc_url = format!("/v1/system/ip-pools/{pool_name}/associate"); + let _ = NexusRequest::objects_post(client, &assoc_url, ¶ms) + .authn_as(AuthnMode::PrivilegedUser) + .execute() + .await; + let silo_pool_range = IpRange::V4( Ipv4Range::new( std::net::Ipv4Addr::new(10, 2, 0, 1), diff --git a/nexus/types/src/external_api/views.rs b/nexus/types/src/external_api/views.rs index c5be6c565d..c2cba6f3e0 100644 --- a/nexus/types/src/external_api/views.rs +++ b/nexus/types/src/external_api/views.rs @@ -246,6 +246,10 @@ pub struct IpPool { pub identity: IdentityMetadata, } +// TODO: placeholder response for IP pool associate POST +#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] +pub struct IpPoolResource {} + #[derive(Clone, Copy, Debug, Deserialize, Serialize, JsonSchema)] pub struct IpPoolRange { pub id: Uuid, diff --git a/openapi/nexus.json b/openapi/nexus.json index 23948208da..b7a7e1b422 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -4606,8 +4606,15 @@ "required": true }, "responses": { - "204": { - "description": "resource updated" + "201": { + "description": "successful creation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/IpPoolResource" + } + } + } }, "4XX": { "$ref": "#/components/responses/Error"