Skip to content

Commit

Permalink
orphan pool test that almost works
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Nov 6, 2023
1 parent 32b2f75 commit 71ecaf4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
60 changes: 60 additions & 0 deletions nexus/tests/integration_tests/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
&params::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::<dropshot::HttpErrorResponseBody>()
.await;

dbg!(error);
}

async fn create_instance_with_pool(
client: &ClientTestContext,
instance_name: &str,
Expand Down
18 changes: 6 additions & 12 deletions nexus/tests/integration_tests/ip_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
&params,
)
.await;
let _: IpPoolResource =
object_create(client, "/v1/system/ip-pools/p0/associations", &params)
.await;

// get silo ID so we can test association by ID as well
let silo_url = format!("/v1/system/silos/{}", cptestctx.silo_name);
Expand Down Expand Up @@ -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"),
&params,
)
.await;
let _: IpPoolResource =
object_create(client, "/v1/system/ip-pools/p1/associations", &params)
.await;

// association should look the same as the other one, except different pool ID
let assocs_p1 = get_associations(client, "p1").await;
Expand Down

0 comments on commit 71ecaf4

Please sign in to comment.