@@ -3146,20 +3146,16 @@ mod tests {
31463146 use nexus_types:: deployment:: BlueprintHostPhase2DesiredContents ;
31473147 use nexus_types:: deployment:: BlueprintHostPhase2DesiredSlots ;
31483148 use nexus_types:: deployment:: BlueprintPhysicalDiskDisposition ;
3149- use nexus_types:: deployment:: BlueprintZoneConfig ;
31503149 use nexus_types:: deployment:: BlueprintZoneDisposition ;
31513150 use nexus_types:: deployment:: BlueprintZoneImageSource ;
3152- use nexus_types:: deployment:: BlueprintZoneType ;
31533151 use nexus_types:: deployment:: ExpectedActiveRotSlot ;
3154- use nexus_types:: deployment:: OmicronZoneExternalFloatingIp ;
31553152 use nexus_types:: deployment:: PendingMgsUpdate ;
31563153 use nexus_types:: deployment:: PlanningInput ;
31573154 use nexus_types:: deployment:: PlanningInputBuilder ;
31583155 use nexus_types:: deployment:: SledDetails ;
31593156 use nexus_types:: deployment:: SledDisk ;
31603157 use nexus_types:: deployment:: SledFilter ;
31613158 use nexus_types:: deployment:: SledResources ;
3162- use nexus_types:: deployment:: blueprint_zone_type;
31633159 use nexus_types:: external_api:: views:: PhysicalDiskPolicy ;
31643160 use nexus_types:: external_api:: views:: PhysicalDiskState ;
31653161 use nexus_types:: external_api:: views:: SledPolicy ;
@@ -3168,36 +3164,24 @@ mod tests {
31683164 use nexus_types:: inventory:: Collection ;
31693165 use omicron_common:: address:: IpRange ;
31703166 use omicron_common:: address:: Ipv6Subnet ;
3171- use omicron_common:: api:: external:: MacAddr ;
3172- use omicron_common:: api:: external:: Name ;
31733167 use omicron_common:: api:: external:: TufArtifactMeta ;
31743168 use omicron_common:: api:: external:: TufRepoDescription ;
31753169 use omicron_common:: api:: external:: TufRepoMeta ;
3176- use omicron_common:: api:: external:: Vni ;
3177- use omicron_common:: api:: internal:: shared:: NetworkInterface ;
3178- use omicron_common:: api:: internal:: shared:: NetworkInterfaceKind ;
31793170 use omicron_common:: disk:: DiskIdentity ;
31803171 use omicron_common:: disk:: M2Slot ;
31813172 use omicron_common:: update:: ArtifactId ;
3182- use omicron_common:: zpool_name:: ZpoolName ;
31833173 use omicron_test_utils:: dev;
31843174 use omicron_test_utils:: dev:: poll:: CondCheckError ;
31853175 use omicron_test_utils:: dev:: poll:: wait_for_condition;
3186- use omicron_uuid_kinds:: ExternalIpUuid ;
31873176 use omicron_uuid_kinds:: OmicronZoneUuid ;
31883177 use omicron_uuid_kinds:: PhysicalDiskUuid ;
31893178 use omicron_uuid_kinds:: SledUuid ;
31903179 use omicron_uuid_kinds:: ZpoolUuid ;
3191- use oxnet:: IpNet ;
31923180 use pretty_assertions:: assert_eq;
31933181 use rand:: Rng ;
31943182 use std:: collections:: BTreeSet ;
31953183 use std:: mem;
3196- use std:: net:: IpAddr ;
3197- use std:: net:: Ipv4Addr ;
31983184 use std:: net:: Ipv6Addr ;
3199- use std:: net:: SocketAddrV6 ;
3200- use std:: str:: FromStr ;
32013185 use std:: sync:: Arc ;
32023186 use std:: sync:: LazyLock ;
32033187 use std:: sync:: atomic:: AtomicBool ;
@@ -4283,104 +4267,46 @@ mod tests {
42834267 logctx. cleanup_successful ( ) ;
42844268 }
42854269
4286- async fn create_blueprint_with_external_ip (
4287- datastore : & DataStore ,
4288- opctx : & OpContext ,
4289- ) -> Blueprint {
4290- // Create an initial blueprint and a child.
4291- let sled_id = SledUuid :: new_v4 ( ) ;
4292- let mut blueprint = BlueprintBuilder :: build_empty_with_sleds (
4293- [ sled_id] . into_iter ( ) ,
4294- "test1" ,
4295- ) ;
4296-
4297- // To observe realistic database behavior, we need the invocation of
4298- // "blueprint_ensure_external_networking_resources" to actually write something
4299- // back to the database.
4300- //
4301- // While this is *mostly* made-up blueprint contents, the part that matters
4302- // is that it's provisioning a zone (Nexus) which does have resources
4303- // to be allocated.
4304- let ip_range = IpRange :: try_from ( (
4305- Ipv4Addr :: new ( 10 , 0 , 0 , 1 ) ,
4306- Ipv4Addr :: new ( 10 , 0 , 0 , 10 ) ,
4307- ) )
4308- . unwrap ( ) ;
4309- let ( service_authz_ip_pool, service_ip_pool) = datastore
4310- . ip_pools_service_lookup ( & opctx, IpVersion :: V4 )
4311- . await
4312- . expect ( "lookup service ip pool" ) ;
4313- datastore
4314- . ip_pool_add_range (
4315- & opctx,
4316- & service_authz_ip_pool,
4317- & service_ip_pool,
4318- & ip_range,
4319- )
4320- . await
4321- . expect ( "add range to service ip pool" ) ;
4322- let zone_id = OmicronZoneUuid :: new_v4 ( ) ;
4323- blueprint
4324- . sleds
4325- . get_mut ( & sled_id)
4326- . unwrap ( )
4327- . zones
4328- . insert_unique ( BlueprintZoneConfig {
4329- disposition : BlueprintZoneDisposition :: InService ,
4330- id : zone_id,
4331- filesystem_pool : ZpoolName :: new_external ( ZpoolUuid :: new_v4 ( ) ) ,
4332- zone_type : BlueprintZoneType :: Nexus (
4333- blueprint_zone_type:: Nexus {
4334- internal_address : SocketAddrV6 :: new (
4335- Ipv6Addr :: LOCALHOST ,
4336- 0 ,
4337- 0 ,
4338- 0 ,
4339- ) ,
4340- lockstep_port : 0 ,
4341- external_ip : OmicronZoneExternalFloatingIp {
4342- id : ExternalIpUuid :: new_v4 ( ) ,
4343- ip : "10.0.0.1" . parse ( ) . unwrap ( ) ,
4344- } ,
4345- nic : NetworkInterface {
4346- id : Uuid :: new_v4 ( ) ,
4347- kind : NetworkInterfaceKind :: Service {
4348- id : * zone_id. as_untyped_uuid ( ) ,
4349- } ,
4350- name : Name :: from_str ( "mynic" ) . unwrap ( ) ,
4351- ip : "172.30.2.6" . parse ( ) . unwrap ( ) ,
4352- mac : MacAddr :: random_system ( ) ,
4353- subnet : IpNet :: host_net ( IpAddr :: V6 (
4354- Ipv6Addr :: LOCALHOST ,
4355- ) ) ,
4356- vni : Vni :: random ( ) ,
4357- primary : true ,
4358- slot : 1 ,
4359- transit_ips : vec ! [ ] ,
4360- } ,
4361- external_tls : false ,
4362- external_dns_servers : vec ! [ ] ,
4363- nexus_generation : Generation :: new ( ) ,
4364- } ,
4365- ) ,
4366- image_source : BlueprintZoneImageSource :: InstallDataset ,
4367- } )
4368- . expect ( "freshly generated zone IDs are unique" ) ;
4369-
4370- blueprint
4371- }
4372-
43734270 #[ tokio:: test]
43744271 async fn test_ensure_external_networking_works_with_good_target ( ) {
4272+ const TEST_NAME : & str =
4273+ "test_ensure_external_networking_works_with_good_target" ;
43754274 // Setup
4376- let logctx = dev:: test_setup_log (
4377- "test_ensure_external_networking_works_with_good_target" ,
4378- ) ;
4275+ let logctx = dev:: test_setup_log ( TEST_NAME ) ;
43794276 let db = TestDatabase :: new_with_datastore ( & logctx. log ) . await ;
43804277 let ( opctx, datastore) = ( db. opctx ( ) , db. datastore ( ) ) ;
43814278
4382- let blueprint =
4383- create_blueprint_with_external_ip ( & datastore, & opctx) . await ;
4279+ let ( example, mut blueprint) =
4280+ ExampleSystemBuilder :: new ( & opctx. log , TEST_NAME ) . build ( ) ;
4281+
4282+ // Insert the IP pool ranges used by our example system.
4283+ for pool_range in
4284+ example. system . external_ip_policy ( ) . clone ( ) . into_raw_ranges ( )
4285+ {
4286+ // This looks up the pool again for each range; we only need at most
4287+ // two (one V4, one V6), but our example system doesn't have many
4288+ // ranges so this should be fine.
4289+ let ( service_authz_ip_pool, service_ip_pool) = datastore
4290+ . ip_pools_service_lookup ( & opctx, pool_range. version ( ) . into ( ) )
4291+ . await
4292+ . expect ( "lookup service ip pool" ) ;
4293+ datastore
4294+ . ip_pool_add_range (
4295+ & opctx,
4296+ & service_authz_ip_pool,
4297+ & service_ip_pool,
4298+ & pool_range,
4299+ )
4300+ . await
4301+ . expect ( "add range to service IP pool" ) ;
4302+ }
4303+
4304+ // `ExampleSystemBuilder` returns a blueprint that has an empty parent.
4305+ // To make `blueprint` the target, we have to either insert that parent
4306+ // and make it the target first, or modify `blueprint` to make it look
4307+ // like it's the original. The latter is shorter.
4308+ blueprint. parent_blueprint_id = None ;
4309+
43844310 datastore. blueprint_insert ( & opctx, & blueprint) . await . unwrap ( ) ;
43854311
43864312 let bp_target = BlueprintTarget {
0 commit comments