From 71ecaf40cb4257e0217a4f8e1551792ab30b0a81 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Mon, 6 Nov 2023 17:16:50 -0600 Subject: [PATCH] orphan pool test that almost works --- nexus/tests/integration_tests/instances.rs | 60 ++++++++++++++++++++++ nexus/tests/integration_tests/ip_pools.rs | 18 +++---- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/nexus/tests/integration_tests/instances.rs b/nexus/tests/integration_tests/instances.rs index a6aee0b87ee..b2971f44eeb 100644 --- a/nexus/tests/integration_tests/instances.rs +++ b/nexus/tests/integration_tests/instances.rs @@ -3654,6 +3654,66 @@ async fn test_instance_ephemeral_ip_from_correct_pool( ); } +#[nexus_test] +async fn test_instance_ephemeral_ip_from_orphan_pool( + cptestctx: &ControlPlaneTestContext, +) { + let client = &cptestctx.external_client; + + let _ = create_project(&client, PROJECT_NAME).await; + + let range = IpRange::V4( + Ipv4Range::new( + std::net::Ipv4Addr::new(10, 0, 0, 1), + std::net::Ipv4Addr::new(10, 0, 0, 5), + ) + .unwrap(), + ); + + let orphan_pool: views::IpPool = object_create( + client, + "/v1/system/ip-pools", + ¶ms::IpPoolCreate { + identity: IdentityMetadataCreateParams { + name: String::from("orphan-pool").parse().unwrap(), + description: String::from("an ip pool"), + }, + }, + ) + .await; + + // add range to pool + + // this should 404 + let instance_name = "orphan-pool-inst"; + let body = params::InstanceCreate { + identity: IdentityMetadataCreateParams { + name: instance_name.parse().unwrap(), + description: format!("instance {:?}", instance_name), + }, + ncpus: InstanceCpuCount(4), + memory: ByteCount::from_gibibytes_u32(1), + hostname: String::from("the_host"), + user_data: + b"#cloud-config\nsystem_info:\n default_user:\n name: oxide" + .to_vec(), + network_interfaces: params::InstanceNetworkInterfaceAttachment::Default, + external_ips: vec![params::ExternalIpCreate::Ephemeral { + pool_name: Some("orphan-pool".parse().unwrap()), + }], + disks: vec![], + start: true, + }; + + let url = format!("/v1/instances?project={}", PROJECT_NAME); + let error = NexusRequest::objects_post(client, &url, &body) + .authn_as(AuthnMode::PrivilegedUser) + .execute_and_parse_unwrap::() + .await; + + dbg!(error); +} + async fn create_instance_with_pool( client: &ClientTestContext, instance_name: &str, diff --git a/nexus/tests/integration_tests/ip_pools.rs b/nexus/tests/integration_tests/ip_pools.rs index bb62749689b..13bbf44bc99 100644 --- a/nexus/tests/integration_tests/ip_pools.rs +++ b/nexus/tests/integration_tests/ip_pools.rs @@ -391,12 +391,9 @@ async fn test_ip_pool_with_silo(cptestctx: &ControlPlaneTestContext) { silo: NameOrId::Name(cptestctx.silo_name.clone()), is_default: false, }); - let _: IpPoolResource = object_create( - client, - &format!("/v1/system/ip-pools/p0/associations"), - ¶ms, - ) - .await; + let _: IpPoolResource = + object_create(client, "/v1/system/ip-pools/p0/associations", ¶ms) + .await; // get silo ID so we can test association by ID as well let silo_url = format!("/v1/system/silos/{}", cptestctx.silo_name); @@ -425,12 +422,9 @@ async fn test_ip_pool_with_silo(cptestctx: &ControlPlaneTestContext) { silo: NameOrId::Id(silo.identity.id), is_default: false, }); - let _: IpPoolResource = object_create( - client, - &format!("/v1/system/ip-pools/p1/associations"), - ¶ms, - ) - .await; + let _: IpPoolResource = + object_create(client, "/v1/system/ip-pools/p1/associations", ¶ms) + .await; // association should look the same as the other one, except different pool ID let assocs_p1 = get_associations(client, "p1").await;