From e81e14faa000383c5bd104013b609447f4d7323b Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Fri, 10 May 2024 11:36:46 -0700 Subject: [PATCH 1/3] initial attempt --- nexus/db-model/src/external_ip.rs | 1 + nexus/tests/integration_tests/external_ips.rs | 7 +++++++ nexus/types/src/external_api/views.rs | 2 ++ 3 files changed, 10 insertions(+) diff --git a/nexus/db-model/src/external_ip.rs b/nexus/db-model/src/external_ip.rs index 1fdc4f8ce62..2a68b4d7d06 100644 --- a/nexus/db-model/src/external_ip.rs +++ b/nexus/db-model/src/external_ip.rs @@ -590,6 +590,7 @@ impl From for views::FloatingIp { views::FloatingIp { ip: ip.ip.ip(), + ip_pool_id: ip.ip_pool_id, identity, project_id: ip.project_id, instance_id: ip.parent_id, diff --git a/nexus/tests/integration_tests/external_ips.rs b/nexus/tests/integration_tests/external_ips.rs index 32b1cbc72c3..646ce3350f2 100644 --- a/nexus/tests/integration_tests/external_ips.rs +++ b/nexus/tests/integration_tests/external_ips.rs @@ -230,6 +230,7 @@ async fn test_floating_ip_create(cptestctx: &ControlPlaneTestContext) { assert_eq!(fip.project_id, project.identity.id); assert_eq!(fip.instance_id, None); assert_eq!(fip.ip, IpAddr::from(Ipv4Addr::new(10, 1, 0, 1))); + // assert_eq!(fip.ip_pool_id, "how to get the expected pool id?"); assert_ip_pool_utilization(client, "other-pool", 1, 5, 0, 0).await; @@ -249,6 +250,12 @@ async fn test_floating_ip_create(cptestctx: &ControlPlaneTestContext) { assert_eq!(fip.instance_id, None); assert_eq!(fip.ip, ip_addr); + let url = format!("/v1/system/ip-pools/{}/utilization", "default"); + // let utilization: views::IpPoolUtilization = object_get(client, &url).await; + let ip_pool = views::IpPool::objects_get(client, &url).await; + + // assert_eq!(fip.ip_pool_id, "how to get the expected pool id?"); + assert_ip_pool_utilization(client, "other-pool", 2, 5, 0, 0).await; } diff --git a/nexus/types/src/external_api/views.rs b/nexus/types/src/external_api/views.rs index e0ba36f1604..1e90d04b55b 100644 --- a/nexus/types/src/external_api/views.rs +++ b/nexus/types/src/external_api/views.rs @@ -450,6 +450,8 @@ pub struct FloatingIp { pub identity: IdentityMetadata, /// The IP address held by this resource. pub ip: IpAddr, + /// The ID of the IP pool this resource belongs to. + pub ip_pool_id: Uuid, /// The project this resource exists within. pub project_id: Uuid, /// The ID of the instance that this Floating IP is attached to, From 2b085cbdea1f84a4a808b7b5b74d10f4e578d0d8 Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Fri, 10 May 2024 12:28:19 -0700 Subject: [PATCH 2/3] Update tests --- nexus/tests/integration_tests/external_ips.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/nexus/tests/integration_tests/external_ips.rs b/nexus/tests/integration_tests/external_ips.rs index 646ce3350f2..9d7ef34b35f 100644 --- a/nexus/tests/integration_tests/external_ips.rs +++ b/nexus/tests/integration_tests/external_ips.rs @@ -153,7 +153,7 @@ async fn test_floating_ip_create(cptestctx: &ControlPlaneTestContext) { let client = &cptestctx.external_client; // automatically linked to current silo - create_default_ip_pool(&client).await; + let default_pool = create_default_ip_pool(&client).await; assert_ip_pool_utilization(client, "default", 0, 65536, 0, 0).await; @@ -162,7 +162,8 @@ async fn test_floating_ip_create(cptestctx: &ControlPlaneTestContext) { .unwrap(), ); // not automatically linked to currently silo. see below - create_ip_pool(&client, "other-pool", Some(other_pool_range)).await; + let (other_pool, ..) = + create_ip_pool(&client, "other-pool", Some(other_pool_range)).await; assert_ip_pool_utilization(client, "other-pool", 0, 5, 0, 0).await; @@ -182,6 +183,7 @@ async fn test_floating_ip_create(cptestctx: &ControlPlaneTestContext) { assert_eq!(fip.project_id, project.identity.id); assert_eq!(fip.instance_id, None); assert_eq!(fip.ip, IpAddr::from(Ipv4Addr::new(10, 0, 0, 0))); + assert_eq!(fip.ip_pool_id, default_pool.identity.id); assert_ip_pool_utilization(client, "default", 1, 65536, 0, 0).await; @@ -200,6 +202,7 @@ async fn test_floating_ip_create(cptestctx: &ControlPlaneTestContext) { assert_eq!(fip.project_id, project.identity.id); assert_eq!(fip.instance_id, None); assert_eq!(fip.ip, ip_addr); + assert_eq!(fip.ip_pool_id, default_pool.identity.id); assert_ip_pool_utilization(client, "default", 2, 65536, 0, 0).await; @@ -230,11 +233,11 @@ async fn test_floating_ip_create(cptestctx: &ControlPlaneTestContext) { assert_eq!(fip.project_id, project.identity.id); assert_eq!(fip.instance_id, None); assert_eq!(fip.ip, IpAddr::from(Ipv4Addr::new(10, 1, 0, 1))); - // assert_eq!(fip.ip_pool_id, "how to get the expected pool id?"); + assert_eq!(fip.ip_pool_id, other_pool.identity.id); assert_ip_pool_utilization(client, "other-pool", 1, 5, 0, 0).await; - // Create with chosen IP from fleet-scoped named pool. + // Create with chosen IP from non-default pool. let fip_name = FIP_NAMES[3]; let ip_addr = "10.1.0.5".parse().unwrap(); let fip = create_floating_ip( @@ -249,12 +252,7 @@ async fn test_floating_ip_create(cptestctx: &ControlPlaneTestContext) { assert_eq!(fip.project_id, project.identity.id); assert_eq!(fip.instance_id, None); assert_eq!(fip.ip, ip_addr); - - let url = format!("/v1/system/ip-pools/{}/utilization", "default"); - // let utilization: views::IpPoolUtilization = object_get(client, &url).await; - let ip_pool = views::IpPool::objects_get(client, &url).await; - - // assert_eq!(fip.ip_pool_id, "how to get the expected pool id?"); + assert_eq!(fip.ip_pool_id, other_pool.identity.id); assert_ip_pool_utilization(client, "other-pool", 2, 5, 0, 0).await; } From 15048ff7315f08cd332296ded7f5d78150b36b33 Mon Sep 17 00:00:00 2001 From: Charlie Park Date: Fri, 10 May 2024 13:12:10 -0700 Subject: [PATCH 3/3] regen OpenAPI schema --- openapi/nexus.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/openapi/nexus.json b/openapi/nexus.json index 4a24eb7f797..c50291cf38a 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -12420,6 +12420,11 @@ "type": "string", "format": "ip" }, + "ip_pool_id": { + "description": "The ID of the IP pool this resource belongs to.", + "type": "string", + "format": "uuid" + }, "kind": { "type": "string", "enum": [ @@ -12454,6 +12459,7 @@ "description", "id", "ip", + "ip_pool_id", "kind", "name", "project_id", @@ -12896,6 +12902,11 @@ "type": "string", "format": "ip" }, + "ip_pool_id": { + "description": "The ID of the IP pool this resource belongs to.", + "type": "string", + "format": "uuid" + }, "name": { "description": "unique, mutable, user-controlled identifier for each resource", "allOf": [ @@ -12924,6 +12935,7 @@ "description", "id", "ip", + "ip_pool_id", "name", "project_id", "time_created",