@@ -76,6 +76,7 @@ impl DataStore {
76
76
opctx : & OpContext ,
77
77
reason_for_creation : & ' static str ,
78
78
this_nexus_id : OmicronZoneUuid ,
79
+ user_comment : Option < String > ,
79
80
) -> CreateResult < SupportBundle > {
80
81
opctx. authorize ( authz:: Action :: Modify , & authz:: FLEET ) . await ?;
81
82
let conn = self . pool_connection_authorized ( opctx) . await ?;
@@ -89,6 +90,7 @@ impl DataStore {
89
90
self . transaction_retry_wrapper ( "support_bundle_create" )
90
91
. transaction ( & conn, |conn| {
91
92
let err = err. clone ( ) ;
93
+ let user_comment = user_comment. clone ( ) ;
92
94
93
95
async move {
94
96
use nexus_db_schema:: schema:: rendezvous_debug_dataset:: dsl as dataset_dsl;
@@ -129,6 +131,7 @@ impl DataStore {
129
131
dataset. pool_id ( ) ,
130
132
dataset. id ( ) ,
131
133
this_nexus_id,
134
+ user_comment,
132
135
) ;
133
136
134
137
diesel:: insert_into ( support_bundle_dsl:: support_bundle)
@@ -438,6 +441,42 @@ impl DataStore {
438
441
}
439
442
}
440
443
444
+ /// Updates the user comment of a support bundle.
445
+ ///
446
+ /// Returns:
447
+ /// - "Ok" if the bundle was updated successfully.
448
+ /// - "Err::InvalidRequest" if the comment exceeds the maximum length.
449
+ pub async fn support_bundle_update_user_comment (
450
+ & self ,
451
+ opctx : & OpContext ,
452
+ authz_bundle : & authz:: SupportBundle ,
453
+ user_comment : Option < String > ,
454
+ ) -> Result < ( ) , Error > {
455
+ opctx. authorize ( authz:: Action :: Modify , authz_bundle) . await ?;
456
+
457
+ if let Some ( ref comment) = user_comment {
458
+ if comment. len ( ) > 4096 {
459
+ return Err ( Error :: invalid_request (
460
+ "User comment cannot exceed 4096 bytes" ,
461
+ ) ) ;
462
+ }
463
+ }
464
+
465
+ use nexus_db_schema:: schema:: support_bundle:: dsl;
466
+
467
+ let id = authz_bundle. id ( ) . into_untyped_uuid ( ) ;
468
+ let conn = self . pool_connection_authorized ( opctx) . await ?;
469
+ diesel:: update ( dsl:: support_bundle)
470
+ . filter ( dsl:: id. eq ( id) )
471
+ . set ( dsl:: user_comment. eq ( user_comment) )
472
+ . execute_async ( & * conn)
473
+ . await
474
+ . map ( |_rows_modified| ( ) )
475
+ . map_err ( |e| public_error_from_diesel ( e, ErrorHandler :: Server ) ) ?;
476
+
477
+ Ok ( ( ) )
478
+ }
479
+
441
480
/// Deletes a support bundle.
442
481
///
443
482
/// This should only be invoked after all storage for the support bundle has
@@ -628,7 +667,7 @@ mod test {
628
667
this_nexus_id : OmicronZoneUuid ,
629
668
) {
630
669
let err = datastore
631
- . support_bundle_create ( & opctx, "for tests" , this_nexus_id)
670
+ . support_bundle_create ( & opctx, "for tests" , this_nexus_id, None )
632
671
. await
633
672
. expect_err ( "Shouldn't provision bundle without datasets" ) ;
634
673
let Error :: InsufficientCapacity { message } = err else {
@@ -674,15 +713,15 @@ mod test {
674
713
// Create two bundles on "nexus A", one bundle on "nexus B"
675
714
676
715
let bundle_a1 = datastore
677
- . support_bundle_create ( & opctx, "for the test" , nexus_a)
716
+ . support_bundle_create ( & opctx, "for the test" , nexus_a, None )
678
717
. await
679
718
. expect ( "Should be able to create bundle" ) ;
680
719
let bundle_a2 = datastore
681
- . support_bundle_create ( & opctx, "for the test" , nexus_a)
720
+ . support_bundle_create ( & opctx, "for the test" , nexus_a, None )
682
721
. await
683
722
. expect ( "Should be able to create bundle" ) ;
684
723
let bundle_b1 = datastore
685
- . support_bundle_create ( & opctx, "for the test" , nexus_b)
724
+ . support_bundle_create ( & opctx, "for the test" , nexus_b, None )
686
725
. await
687
726
. expect ( "Should be able to create bundle" ) ;
688
727
@@ -800,6 +839,7 @@ mod test {
800
839
& opctx,
801
840
"for the test" ,
802
841
this_nexus_id,
842
+ None ,
803
843
)
804
844
. await
805
845
. expect ( "Should be able to create bundle" ) ,
@@ -846,7 +886,7 @@ mod test {
846
886
. await
847
887
. expect ( "Should be able to destroy this bundle" ) ;
848
888
datastore
849
- . support_bundle_create ( & opctx, "for the test" , this_nexus_id)
889
+ . support_bundle_create ( & opctx, "for the test" , this_nexus_id, None )
850
890
. await
851
891
. expect ( "Should be able to create bundle" ) ;
852
892
@@ -867,7 +907,7 @@ mod test {
867
907
// Create the bundle, then observe it through the "getter" APIs
868
908
869
909
let mut bundle = datastore
870
- . support_bundle_create ( & opctx, reason, this_nexus_id)
910
+ . support_bundle_create ( & opctx, reason, this_nexus_id, None )
871
911
. await
872
912
. expect ( "Should be able to create bundle" ) ;
873
913
assert_eq ! ( bundle. reason_for_creation, reason) ;
@@ -1031,7 +1071,7 @@ mod test {
1031
1071
// When we create a bundle, it should exist on a dataset provisioned by
1032
1072
// the blueprint.
1033
1073
let bundle = datastore
1034
- . support_bundle_create ( & opctx, "for the test" , this_nexus_id)
1074
+ . support_bundle_create ( & opctx, "for the test" , this_nexus_id, None )
1035
1075
. await
1036
1076
. expect ( "Should be able to create bundle" ) ;
1037
1077
assert_eq ! ( bundle. assigned_nexus, Some ( this_nexus_id. into( ) ) ) ;
@@ -1136,7 +1176,7 @@ mod test {
1136
1176
// When we create a bundle, it should exist on a dataset provisioned by
1137
1177
// the blueprint.
1138
1178
let bundle = datastore
1139
- . support_bundle_create ( & opctx, "for the test" , this_nexus_id)
1179
+ . support_bundle_create ( & opctx, "for the test" , this_nexus_id, None )
1140
1180
. await
1141
1181
. expect ( "Should be able to create bundle" ) ;
1142
1182
assert_eq ! ( bundle. assigned_nexus, Some ( this_nexus_id. into( ) ) ) ;
@@ -1237,7 +1277,7 @@ mod test {
1237
1277
// When we create a bundle, it should exist on a dataset provisioned by
1238
1278
// the blueprint.
1239
1279
let bundle = datastore
1240
- . support_bundle_create ( & opctx, "for the test" , nexus_ids[ 0 ] )
1280
+ . support_bundle_create ( & opctx, "for the test" , nexus_ids[ 0 ] , None )
1241
1281
. await
1242
1282
. expect ( "Should be able to create bundle" ) ;
1243
1283
@@ -1358,7 +1398,7 @@ mod test {
1358
1398
// When we create a bundle, it should exist on a dataset provisioned by
1359
1399
// the blueprint.
1360
1400
let bundle = datastore
1361
- . support_bundle_create ( & opctx, "for the test" , nexus_ids[ 0 ] )
1401
+ . support_bundle_create ( & opctx, "for the test" , nexus_ids[ 0 ] , None )
1362
1402
. await
1363
1403
. expect ( "Should be able to create bundle" ) ;
1364
1404
@@ -1442,6 +1482,7 @@ mod test {
1442
1482
& opctx,
1443
1483
"Bundle for time ordering test" ,
1444
1484
this_nexus_id,
1485
+ None ,
1445
1486
)
1446
1487
. await
1447
1488
. expect ( "Should be able to create bundle" ) ;
0 commit comments