@@ -76,6 +76,7 @@ impl DataStore {
7676 opctx : & OpContext ,
7777 reason_for_creation : & ' static str ,
7878 this_nexus_id : OmicronZoneUuid ,
79+ user_comment : Option < String > ,
7980 ) -> CreateResult < SupportBundle > {
8081 opctx. authorize ( authz:: Action :: Modify , & authz:: FLEET ) . await ?;
8182 let conn = self . pool_connection_authorized ( opctx) . await ?;
@@ -89,6 +90,7 @@ impl DataStore {
8990 self . transaction_retry_wrapper ( "support_bundle_create" )
9091 . transaction ( & conn, |conn| {
9192 let err = err. clone ( ) ;
93+ let user_comment = user_comment. clone ( ) ;
9294
9395 async move {
9496 use nexus_db_schema:: schema:: rendezvous_debug_dataset:: dsl as dataset_dsl;
@@ -129,6 +131,7 @@ impl DataStore {
129131 dataset. pool_id ( ) ,
130132 dataset. id ( ) ,
131133 this_nexus_id,
134+ user_comment,
132135 ) ;
133136
134137 diesel:: insert_into ( support_bundle_dsl:: support_bundle)
@@ -438,6 +441,42 @@ impl DataStore {
438441 }
439442 }
440443
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+
441480 /// Deletes a support bundle.
442481 ///
443482 /// This should only be invoked after all storage for the support bundle has
@@ -628,7 +667,7 @@ mod test {
628667 this_nexus_id : OmicronZoneUuid ,
629668 ) {
630669 let err = datastore
631- . support_bundle_create ( & opctx, "for tests" , this_nexus_id)
670+ . support_bundle_create ( & opctx, "for tests" , this_nexus_id, None )
632671 . await
633672 . expect_err ( "Shouldn't provision bundle without datasets" ) ;
634673 let Error :: InsufficientCapacity { message } = err else {
@@ -674,15 +713,15 @@ mod test {
674713 // Create two bundles on "nexus A", one bundle on "nexus B"
675714
676715 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 )
678717 . await
679718 . expect ( "Should be able to create bundle" ) ;
680719 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 )
682721 . await
683722 . expect ( "Should be able to create bundle" ) ;
684723 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 )
686725 . await
687726 . expect ( "Should be able to create bundle" ) ;
688727
@@ -800,6 +839,7 @@ mod test {
800839 & opctx,
801840 "for the test" ,
802841 this_nexus_id,
842+ None ,
803843 )
804844 . await
805845 . expect ( "Should be able to create bundle" ) ,
@@ -846,7 +886,7 @@ mod test {
846886 . await
847887 . expect ( "Should be able to destroy this bundle" ) ;
848888 datastore
849- . support_bundle_create ( & opctx, "for the test" , this_nexus_id)
889+ . support_bundle_create ( & opctx, "for the test" , this_nexus_id, None )
850890 . await
851891 . expect ( "Should be able to create bundle" ) ;
852892
@@ -867,7 +907,7 @@ mod test {
867907 // Create the bundle, then observe it through the "getter" APIs
868908
869909 let mut bundle = datastore
870- . support_bundle_create ( & opctx, reason, this_nexus_id)
910+ . support_bundle_create ( & opctx, reason, this_nexus_id, None )
871911 . await
872912 . expect ( "Should be able to create bundle" ) ;
873913 assert_eq ! ( bundle. reason_for_creation, reason) ;
@@ -1031,7 +1071,7 @@ mod test {
10311071 // When we create a bundle, it should exist on a dataset provisioned by
10321072 // the blueprint.
10331073 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 )
10351075 . await
10361076 . expect ( "Should be able to create bundle" ) ;
10371077 assert_eq ! ( bundle. assigned_nexus, Some ( this_nexus_id. into( ) ) ) ;
@@ -1136,7 +1176,7 @@ mod test {
11361176 // When we create a bundle, it should exist on a dataset provisioned by
11371177 // the blueprint.
11381178 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 )
11401180 . await
11411181 . expect ( "Should be able to create bundle" ) ;
11421182 assert_eq ! ( bundle. assigned_nexus, Some ( this_nexus_id. into( ) ) ) ;
@@ -1237,7 +1277,7 @@ mod test {
12371277 // When we create a bundle, it should exist on a dataset provisioned by
12381278 // the blueprint.
12391279 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 )
12411281 . await
12421282 . expect ( "Should be able to create bundle" ) ;
12431283
@@ -1358,7 +1398,7 @@ mod test {
13581398 // When we create a bundle, it should exist on a dataset provisioned by
13591399 // the blueprint.
13601400 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 )
13621402 . await
13631403 . expect ( "Should be able to create bundle" ) ;
13641404
@@ -1442,6 +1482,7 @@ mod test {
14421482 & opctx,
14431483 "Bundle for time ordering test" ,
14441484 this_nexus_id,
1485+ None ,
14451486 )
14461487 . await
14471488 . expect ( "Should be able to create bundle" ) ;
0 commit comments