@@ -27,15 +27,13 @@ use async_bb8_diesel::AsyncRunQueryDsl;
27
27
use chrono:: Utc ;
28
28
use diesel:: prelude:: * ;
29
29
use diesel:: upsert:: excluded;
30
- use futures:: FutureExt ;
31
30
use omicron_common:: api:: external:: CreateResult ;
32
31
use omicron_common:: api:: external:: DataPageParams ;
33
32
use omicron_common:: api:: external:: Error ;
34
33
use omicron_common:: api:: external:: ListResultVec ;
35
34
use omicron_common:: api:: external:: LookupResult ;
36
35
use omicron_common:: api:: external:: LookupType ;
37
36
use omicron_common:: api:: external:: ResourceType ;
38
- use omicron_uuid_kinds:: BlueprintUuid ;
39
37
use omicron_uuid_kinds:: DatasetUuid ;
40
38
use omicron_uuid_kinds:: GenericUuid ;
41
39
use uuid:: Uuid ;
@@ -73,31 +71,6 @@ impl DataStore {
73
71
} )
74
72
}
75
73
76
- pub async fn crucible_dataset_upsert_if_blueprint_is_current_target (
77
- & self ,
78
- opctx : & OpContext ,
79
- bp_id : BlueprintUuid ,
80
- dataset : CrucibleDataset ,
81
- ) -> CreateResult < CrucibleDataset > {
82
- let conn = self . pool_connection_unauthorized ( ) . await ?;
83
-
84
- self . transaction_if_current_blueprint_is (
85
- & conn,
86
- "dataset_upsert_if_blueprint_is_current_target" ,
87
- opctx,
88
- bp_id,
89
- |conn| {
90
- let dataset = dataset. clone ( ) ;
91
- async move {
92
- Self :: crucible_dataset_upsert_on_connection ( & conn, dataset)
93
- . await
94
- }
95
- . boxed ( )
96
- } ,
97
- )
98
- . await
99
- }
100
-
101
74
async fn crucible_dataset_upsert_on_connection (
102
75
conn : & async_bb8_diesel:: Connection < db:: DbConnection > ,
103
76
dataset : CrucibleDataset ,
@@ -277,15 +250,12 @@ impl DataStore {
277
250
#[ cfg( test) ]
278
251
mod test {
279
252
use super :: * ;
280
- use crate :: db:: datastore:: test:: bp_insert_and_make_target;
281
253
use crate :: db:: pub_test_utils:: TestDatabase ;
282
254
use nexus_db_model:: Generation ;
283
255
use nexus_db_model:: SledBaseboard ;
284
256
use nexus_db_model:: SledSystemHardware ;
285
257
use nexus_db_model:: SledUpdate ;
286
- use nexus_reconfigurator_planning:: blueprint_builder:: BlueprintBuilder ;
287
258
use omicron_test_utils:: dev;
288
- use omicron_uuid_kinds:: BlueprintUuid ;
289
259
use omicron_uuid_kinds:: DatasetUuid ;
290
260
use omicron_uuid_kinds:: PhysicalDiskUuid ;
291
261
use omicron_uuid_kinds:: SledUuid ;
@@ -418,68 +388,4 @@ mod test {
418
388
db. terminate ( ) . await ;
419
389
logctx. cleanup_successful ( ) ;
420
390
}
421
-
422
- fn new_dataset_on ( zpool_id : ZpoolUuid ) -> CrucibleDataset {
423
- CrucibleDataset :: new (
424
- DatasetUuid :: new_v4 ( ) ,
425
- * zpool_id. as_untyped_uuid ( ) ,
426
- "[::1]:0" . parse ( ) . unwrap ( ) ,
427
- )
428
- }
429
-
430
- #[ tokio:: test]
431
- async fn test_upsert_while_blueprint_changes ( ) {
432
- let logctx = dev:: test_setup_log ( "upsert_while_blueprint_changes" ) ;
433
- let db = TestDatabase :: new_with_datastore ( & logctx. log ) . await ;
434
- let ( opctx, datastore) = ( db. opctx ( ) , db. datastore ( ) ) ;
435
-
436
- let ( sled_id, zpool_id) =
437
- create_sled_and_zpool ( & datastore, opctx) . await ;
438
-
439
- // The datastore methods don't actually read the blueprint, but they do
440
- // guard against concurrent changes to the current target.
441
- //
442
- // We can test behavior by swapping between empty blueprints.
443
- let bp0 = BlueprintBuilder :: build_empty_with_sleds (
444
- [ sled_id] . into_iter ( ) ,
445
- "test" ,
446
- ) ;
447
- bp_insert_and_make_target ( & opctx, & datastore, & bp0) . await ;
448
-
449
- let bp1 = {
450
- let mut bp1 = bp0. clone ( ) ;
451
- bp1. id = BlueprintUuid :: new_v4 ( ) ;
452
- bp1. parent_blueprint_id = Some ( bp0. id ) ;
453
- bp1
454
- } ;
455
- bp_insert_and_make_target ( & opctx, & datastore, & bp1) . await ;
456
-
457
- let old_blueprint_id = bp0. id ;
458
- let current_blueprint_id = bp1. id ;
459
-
460
- // Upsert referencing old blueprint: Error
461
- datastore
462
- . crucible_dataset_upsert_if_blueprint_is_current_target (
463
- & opctx,
464
- old_blueprint_id,
465
- new_dataset_on ( zpool_id) ,
466
- )
467
- . await
468
- . expect_err (
469
- "Shouldn't be able to insert referencing old blueprint" ,
470
- ) ;
471
-
472
- // Upsert referencing current blueprint: OK
473
- datastore
474
- . crucible_dataset_upsert_if_blueprint_is_current_target (
475
- & opctx,
476
- current_blueprint_id,
477
- new_dataset_on ( zpool_id) ,
478
- )
479
- . await
480
- . expect ( "Should be able to insert while blueprint is active" ) ;
481
-
482
- db. terminate ( ) . await ;
483
- logctx. cleanup_successful ( ) ;
484
- }
485
391
}
0 commit comments