@@ -28,7 +28,9 @@ use similar_asserts;
28
28
use slog:: Logger ;
29
29
use slog_error_chain:: InlineErrorChain ;
30
30
use std:: collections:: BTreeMap ;
31
+ use std:: collections:: HashMap ;
31
32
use std:: net:: IpAddr ;
33
+ use std:: str:: FromStr ;
32
34
use std:: sync:: Mutex ;
33
35
use tokio:: time:: Duration ;
34
36
use tokio:: time:: timeout;
@@ -2711,6 +2713,84 @@ fn after_164_0_0<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> {
2711
2713
} )
2712
2714
}
2713
2715
2716
+ const ROUTE_CONFIG_PORT_SETTINGS_ID_0 : & str =
2717
+ "1e700b64-79e0-4515-9771-bcc2391b6d4d" ;
2718
+ const ROUTE_CONFIG_PORT_SETTINGS_ID_1 : & str =
2719
+ "c6b015ff-1c98-474f-b9e9-dfc30546094f" ;
2720
+ const ROUTE_CONFIG_PORT_SETTINGS_ID_2 : & str =
2721
+ "8b777d9b-62a3-4c4d-b0b7-314315c2a7fc" ;
2722
+ const ROUTE_CONFIG_PORT_SETTINGS_ID_3 : & str =
2723
+ "7c675e89-74b1-45da-9577-cf75f028107a" ;
2724
+ const ROUTE_CONFIG_PORT_SETTINGS_ID_4 : & str =
2725
+ "e2413d63-9307-4918-b9c4-bce959c63042" ;
2726
+
2727
+ // Insert records using the `local_pref` column before it's renamed and its
2728
+ // database type is changed from INT8 to INT2. The receiving Rust type is u8
2729
+ // so 2 records are outside the u8 range, 2 records are at the edge of the u8
2730
+ // range, and 1 record is within the u8 range.
2731
+ fn before_165_0_0 < ' a > ( ctx : & ' a MigrationContext < ' a > ) -> BoxFuture < ' a , ( ) > {
2732
+ Box :: pin ( async move {
2733
+ ctx. client
2734
+ . batch_execute ( & format ! ( "
2735
+ INSERT INTO omicron.public.switch_port_settings_route_config
2736
+ (port_settings_id, interface_name, dst, gw, vid, local_pref)
2737
+ VALUES
2738
+ (
2739
+ '{ROUTE_CONFIG_PORT_SETTINGS_ID_0}', 'phy0', '0.0.0.0/0', '0.0.0.0', NULL, -1
2740
+ ),
2741
+ (
2742
+ '{ROUTE_CONFIG_PORT_SETTINGS_ID_1}', 'phy0', '0.0.0.0/0', '0.0.0.0', NULL, 0
2743
+ ),
2744
+ (
2745
+ '{ROUTE_CONFIG_PORT_SETTINGS_ID_2}', 'phy0', '0.0.0.0/0', '0.0.0.0', NULL, 128
2746
+ ),
2747
+ (
2748
+ '{ROUTE_CONFIG_PORT_SETTINGS_ID_3}', 'phy0', '0.0.0.0/0', '0.0.0.0', NULL, 255
2749
+ ),
2750
+ (
2751
+ '{ROUTE_CONFIG_PORT_SETTINGS_ID_4}', 'phy0', '0.0.0.0/0', '0.0.0.0', NULL, 256
2752
+ );
2753
+ " ) ,
2754
+ )
2755
+ . await
2756
+ . expect ( "failed to insert pre-migration rows for 165" ) ;
2757
+ } )
2758
+ }
2759
+
2760
+ // Query the records using the new `rib_priority` column and assert that the
2761
+ // values were correctly clamped within the u8 range.
2762
+ fn after_165_0_0 < ' a > ( ctx : & ' a MigrationContext < ' a > ) -> BoxFuture < ' a , ( ) > {
2763
+ Box :: pin ( async move {
2764
+ let rows = ctx
2765
+ . client
2766
+ . query (
2767
+ "SELECT * FROM omicron.public.switch_port_settings_route_config;" ,
2768
+ & [ ] ,
2769
+ )
2770
+ . await
2771
+ . expect ( "failed to query post-migration switch_port_settings_route_config table" ) ;
2772
+ assert_eq ! ( rows. len( ) , 5 ) ;
2773
+
2774
+ let records: HashMap < Uuid , i16 > = HashMap :: from ( [
2775
+ ( Uuid :: from_str ( ROUTE_CONFIG_PORT_SETTINGS_ID_0 ) . unwrap ( ) , 0 ) ,
2776
+ ( Uuid :: from_str ( ROUTE_CONFIG_PORT_SETTINGS_ID_1 ) . unwrap ( ) , 0 ) ,
2777
+ ( Uuid :: from_str ( ROUTE_CONFIG_PORT_SETTINGS_ID_2 ) . unwrap ( ) , 128 ) ,
2778
+ ( Uuid :: from_str ( ROUTE_CONFIG_PORT_SETTINGS_ID_3 ) . unwrap ( ) , 255 ) ,
2779
+ ( Uuid :: from_str ( ROUTE_CONFIG_PORT_SETTINGS_ID_4 ) . unwrap ( ) , 255 ) ,
2780
+ ] ) ;
2781
+
2782
+ for row in rows {
2783
+ let port_settings_id = row. get :: < & str , Uuid > ( "port_settings_id" ) ;
2784
+ let rib_priority_got = row. get :: < & str , i16 > ( "rib_priority" ) ;
2785
+
2786
+ let rib_priority_want = records
2787
+ . get ( & port_settings_id)
2788
+ . expect ( "unexpected port_settings_id value when querying switch_port_settings_route_config" ) ;
2789
+ assert_eq ! ( rib_priority_got, * rib_priority_want) ;
2790
+ }
2791
+ } )
2792
+ }
2793
+
2714
2794
// Lazily initializes all migration checks. The combination of Rust function
2715
2795
// pointers and async makes defining a static table fairly painful, so we're
2716
2796
// using lazy initialization instead.
@@ -2801,6 +2881,10 @@ fn get_migration_checks() -> BTreeMap<Version, DataMigrationFns> {
2801
2881
Version :: new ( 164 , 0 , 0 ) ,
2802
2882
DataMigrationFns :: new ( ) . before ( before_164_0_0) . after ( after_164_0_0) ,
2803
2883
) ;
2884
+ map. insert (
2885
+ Version :: new ( 165 , 0 , 0 ) ,
2886
+ DataMigrationFns :: new ( ) . before ( before_165_0_0) . after ( after_165_0_0) ,
2887
+ ) ;
2804
2888
2805
2889
map
2806
2890
}
0 commit comments