From 3456f1bcf98eafbcfa7e6987f6dcf411b42323e9 Mon Sep 17 00:00:00 2001 From: Dan Rosen Date: Thu, 15 Jan 2026 19:26:55 -0500 Subject: [PATCH] some cleanup Created using jj-spr 0.1.0 --- nexus/external-api/src/lib.rs | 12 ++++-- nexus/external-api/src/v2026010100.rs | 5 ++- nexus/external-api/src/v2026011300.rs | 8 +++- nexus/test-utils/src/resource_helpers.rs | 43 +------------------ nexus/tests/integration_tests/endpoints.rs | 2 +- nexus/tests/integration_tests/instances.rs | 39 ++++++++--------- .../integration_tests/internet_gateway.rs | 3 +- nexus/tests/integration_tests/vpc_routers.rs | 2 +- 8 files changed, 43 insertions(+), 71 deletions(-) diff --git a/nexus/external-api/src/lib.rs b/nexus/external-api/src/lib.rs index 66b4126ba73..8e6a065fcd6 100644 --- a/nexus/external-api/src/lib.rs +++ b/nexus/external-api/src/lib.rs @@ -3474,11 +3474,17 @@ pub trait NexusExternalApi { async fn v2026011300_instance_network_interface_create( rqctx: RequestContext, query_params: Query, - interface_params: TypedBody, + interface_params: TypedBody< + v2026011300::InstanceNetworkInterfaceCreate, + >, ) -> Result, HttpError> { let interface_params = interface_params.map(Into::into); - Self::instance_network_interface_create(rqctx, query_params, interface_params) - .await + Self::instance_network_interface_create( + rqctx, + query_params, + interface_params, + ) + .await } /// Create network interface diff --git a/nexus/external-api/src/v2026010100.rs b/nexus/external-api/src/v2026010100.rs index 3371d3bc687..11714bff6e0 100644 --- a/nexus/external-api/src/v2026010100.rs +++ b/nexus/external-api/src/v2026010100.rs @@ -545,7 +545,10 @@ mod tests { fn no_ip_no_transit_defaults_to_dual_stack() { let result: v2026011300::InstanceNetworkInterfaceCreate = make_nic(None, vec![]).try_into().unwrap(); - assert!(matches!(result.ip_config, PrivateIpStackCreate::DualStack { .. })); + assert!(matches!( + result.ip_config, + PrivateIpStackCreate::DualStack { .. } + )); } proptest! { diff --git a/nexus/external-api/src/v2026011300.rs b/nexus/external-api/src/v2026011300.rs index 80dbec7ac2d..1e424d3be61 100644 --- a/nexus/external-api/src/v2026011300.rs +++ b/nexus/external-api/src/v2026011300.rs @@ -103,8 +103,12 @@ impl From InstanceNetworkInterfaceAttachment::Create(nics) => { Self::Create(nics.into_iter().map(Into::into).collect()) } - InstanceNetworkInterfaceAttachment::DefaultIpv4 => Self::DefaultIpv4, - InstanceNetworkInterfaceAttachment::DefaultIpv6 => Self::DefaultIpv6, + InstanceNetworkInterfaceAttachment::DefaultIpv4 => { + Self::DefaultIpv4 + } + InstanceNetworkInterfaceAttachment::DefaultIpv6 => { + Self::DefaultIpv6 + } InstanceNetworkInterfaceAttachment::DefaultDualStack => { Self::DefaultDualStack } diff --git a/nexus/test-utils/src/resource_helpers.rs b/nexus/test-utils/src/resource_helpers.rs index 2a3e92799f6..e953b955ccf 100644 --- a/nexus/test-utils/src/resource_helpers.rs +++ b/nexus/test-utils/src/resource_helpers.rs @@ -78,54 +78,15 @@ use std::sync::Arc; use std::time::Duration; use uuid::Uuid; -/// Helper trait to convert various name types to `NameOrId` for test helpers. -pub trait IntoSubnetName { - fn into_name_or_id(self) -> NameOrId; -} - -impl IntoSubnetName for &Name { - fn into_name_or_id(self) -> NameOrId { - self.clone().into() - } -} - -impl IntoSubnetName for Name { - fn into_name_or_id(self) -> NameOrId { - self.into() - } -} - -impl IntoSubnetName for &str { - fn into_name_or_id(self) -> NameOrId { - self.parse::().expect("invalid subnet name").into() - } -} - -impl IntoSubnetName for &&str { - fn into_name_or_id(self) -> NameOrId { - (*self).into_name_or_id() - } -} - /// Creates a single-element subnet configuration for network interface creation. /// /// This is a convenience helper for tests that need to specify a single subnet /// without the `attached` flag (the common case). -/// -/// # Examples -/// ```ignore -/// // With a Name reference -/// let default_name: Name = "default".parse().unwrap(); -/// subnets: single_unattached_subnet(&default_name) -/// -/// // With a string literal -/// subnets: single_unattached_subnet("default") -/// ``` pub fn single_unattached_subnet( - name: impl IntoSubnetName, + name: &str, ) -> Vec { vec![params::NetworkInterfaceSubnetConfig { - subnet: name.into_name_or_id(), + subnet: name.parse::().expect("invalid subnet name").into(), attached: false, }] } diff --git a/nexus/tests/integration_tests/endpoints.rs b/nexus/tests/integration_tests/endpoints.rs index 797ce06f2d3..a5c1d9b386b 100644 --- a/nexus/tests/integration_tests/endpoints.rs +++ b/nexus/tests/integration_tests/endpoints.rs @@ -726,7 +726,7 @@ pub static DEMO_INSTANCE_NIC_CREATE: LazyLock< description: String::from(""), }, vpc_name: DEMO_VPC_NAME.clone(), - subnets: single_unattached_subnet(DEMO_VPC_SUBNET_NAME.clone()), + subnets: single_unattached_subnet(DEMO_VPC_SUBNET_NAME.as_str()), ip_config: PrivateIpStackCreate::auto_ipv4(), }); pub static DEMO_INSTANCE_NIC_PUT: LazyLock< diff --git a/nexus/tests/integration_tests/instances.rs b/nexus/tests/integration_tests/instances.rs index abe06118f72..304c09d6c0b 100644 --- a/nexus/tests/integration_tests/instances.rs +++ b/nexus/tests/integration_tests/instances.rs @@ -2690,7 +2690,7 @@ async fn test_instance_create_saga_removes_instance_database_record( description: String::from("first custom interface"), }, vpc_name: default_name.clone(), - subnets: single_unattached_subnet(&default_name), + subnets: single_unattached_subnet(default_name.as_str()), ip_config: PrivateIpStackCreate::from_ipv4(requested_address), }; let interface_params = @@ -2776,7 +2776,7 @@ async fn test_instance_create_saga_removes_instance_database_record( description: String::from("first custom interface"), }, vpc_name: default_name.clone(), - subnets: single_unattached_subnet(&default_name), + subnets: single_unattached_subnet(default_name.as_str()), ip_config: PrivateIpStackCreate::from_ipv4(requested_address), }; let interface_params = @@ -2878,7 +2878,7 @@ async fn test_instance_with_single_explicit_ip_address_impl( description: String::from("first custom interface"), }, vpc_name: default_name.clone(), - subnets: single_unattached_subnet(&default_name), + subnets: single_unattached_subnet(default_name.as_str()), ip_config: ip_config.clone(), }; let interface_params = @@ -3049,7 +3049,7 @@ async fn test_instance_with_new_custom_network_interfaces( description: String::from("first custom interface"), }, vpc_name: default_name.clone(), - subnets: single_unattached_subnet(&default_name), + subnets: single_unattached_subnet(default_name.as_str()), ip_config: PrivateIpStackCreate::auto_ipv4(), }; let if1_params = params::InstanceNetworkInterfaceCreate { @@ -3058,7 +3058,7 @@ async fn test_instance_with_new_custom_network_interfaces( description: String::from("second custom interface"), }, vpc_name: default_name.clone(), - subnets: single_unattached_subnet(&non_default_subnet_name), + subnets: single_unattached_subnet(non_default_subnet_name.as_str()), ip_config: PrivateIpStackCreate::auto_dual_stack(), }; let interface_params = @@ -3269,7 +3269,9 @@ async fn test_instance_create_delete_network_interface( description: String::from("a new nic"), }, vpc_name: "default".parse().unwrap(), - subnets: single_unattached_subnet(&secondary_subnet.identity.name), + subnets: single_unattached_subnet( + secondary_subnet.identity.name.as_str(), + ), ip_config: PrivateIpStackCreate::V4(PrivateIpv4StackCreate { ip: IpAssignment::Explicit("172.31.0.11".parse().unwrap()), transit_ips: vec!["192.168.1.0/24".parse().unwrap()], @@ -3532,7 +3534,9 @@ async fn test_instance_update_network_interfaces( description: String::from("a new nic"), }, vpc_name: "default".parse().unwrap(), - subnets: single_unattached_subnet(&secondary_subnet.identity.name), + subnets: single_unattached_subnet( + secondary_subnet.identity.name.as_str(), + ), ip_config: PrivateIpStackCreate::from_ipv4( "172.31.0.11".parse().unwrap(), ), @@ -3944,7 +3948,9 @@ async fn cannot_make_new_primary_nic_lacking_ip_stack_for_external_addresses( description: String::from("a new nic"), }, vpc_name: "default".parse().unwrap(), - subnets: single_unattached_subnet(&secondary_subnet.identity.name), + subnets: single_unattached_subnet( + secondary_subnet.identity.name.as_str(), + ), ip_config: PrivateIpStackCreate::auto_ipv6(), }; @@ -4260,7 +4266,7 @@ async fn test_instance_with_multiple_nics_unwinds_completely( description: String::from("first custom interface"), }, vpc_name: default_name.clone(), - subnets: single_unattached_subnet(&default_name), + subnets: single_unattached_subnet(default_name.as_str()), ip_config: PrivateIpStackCreate::from_ipv4( "172.30.0.6".parse().unwrap(), ), @@ -4271,7 +4277,7 @@ async fn test_instance_with_multiple_nics_unwinds_completely( description: String::from("second custom interface"), }, vpc_name: default_name.clone(), - subnets: single_unattached_subnet(&default_name), + subnets: single_unattached_subnet(default_name.as_str()), ip_config: PrivateIpStackCreate::from_ipv4( "172.30.0.7".parse().unwrap(), ), @@ -9104,10 +9110,7 @@ async fn test_instance_create_with_old_subnet_name_api_version( // Send request with old API version header let instance: Instance = NexusRequest::new( RequestBuilder::new(client, Method::POST, &get_instances_url()) - .header( - omicron_common::api::VERSION_HEADER, - "2026011300.0.0", - ) + .header(omicron_common::api::VERSION_HEADER, "2026011300.0.0") .body(Some(&body)) .expect_status(Some(StatusCode::CREATED)), ) @@ -9173,15 +9176,11 @@ async fn test_network_interface_create_with_old_subnet_name_api_version( // Send request with old API version header let url = format!( "/v1/network-interfaces?project={}&instance={}", - PROJECT_NAME, - instance.identity.name + PROJECT_NAME, instance.identity.name ); let nic: InstanceNetworkInterface = NexusRequest::new( RequestBuilder::new(client, Method::POST, &url) - .header( - omicron_common::api::VERSION_HEADER, - "2026011300.0.0", - ) + .header(omicron_common::api::VERSION_HEADER, "2026011300.0.0") .body(Some(&body)) .expect_status(Some(StatusCode::CREATED)), ) diff --git a/nexus/tests/integration_tests/internet_gateway.rs b/nexus/tests/integration_tests/internet_gateway.rs index 0b270341136..ca017ce9ac3 100644 --- a/nexus/tests/integration_tests/internet_gateway.rs +++ b/nexus/tests/integration_tests/internet_gateway.rs @@ -29,8 +29,7 @@ use nexus_types::identity::Resource; use omicron_common::{ address::{IpRange, Ipv4Range}, api::external::{ - IdentityMetadataCreateParams, NameOrId, RouteDestination, - RouteTarget, + IdentityMetadataCreateParams, NameOrId, RouteDestination, RouteTarget, }, }; diff --git a/nexus/tests/integration_tests/vpc_routers.rs b/nexus/tests/integration_tests/vpc_routers.rs index d35e10ed397..5b1b8232d4e 100644 --- a/nexus/tests/integration_tests/vpc_routers.rs +++ b/nexus/tests/integration_tests/vpc_routers.rs @@ -20,8 +20,8 @@ use nexus_test_utils::resource_helpers::create_router; use nexus_test_utils::resource_helpers::create_vpc_subnet; use nexus_test_utils::resource_helpers::object_delete; use nexus_test_utils::resource_helpers::objects_list_page_authz; -use nexus_test_utils::resource_helpers::{create_project, create_vpc}; use nexus_test_utils::resource_helpers::single_unattached_subnet; +use nexus_test_utils::resource_helpers::{create_project, create_vpc}; use nexus_test_utils::resource_helpers::{object_put, object_put_error}; use nexus_test_utils_macros::nexus_test; use nexus_types::external_api::params;