@@ -7,6 +7,7 @@ use grpc::{
77 } ,
88} ;
99use itertools:: Itertools ;
10+ use regex:: Regex ;
1011use std:: { collections:: HashMap , convert:: TryFrom , thread:: sleep, time:: Duration } ;
1112use stor_port:: types:: v0:: store:: pool:: { Encryption , EncryptionSecret } ;
1213use stor_port:: types:: v0:: transport:: { GetBlockDevices , NodeStatus } ;
@@ -1347,3 +1348,34 @@ async fn reject_devlink_reuse() {
13471348 }
13481349 }
13491350}
1351+
1352+ #[ tokio:: test]
1353+ async fn persistent_devlink_regex ( ) {
1354+ fn is_persistent_devlink ( pattern : & str ) -> bool {
1355+ let re = Regex :: new ( utils:: DEVLINK_REGEX ) . expect ( "DEVLINK_REGEX should be valid" ) ;
1356+ re. is_match ( pattern)
1357+ }
1358+
1359+ let test_suite = [
1360+ ( "/dev/some/path" , false ) ,
1361+ ( "/dev/mapper/some/path" , false ) ,
1362+ ( "/dev/disk/some/path" , false ) ,
1363+ ( "/dev/disk/by-something/path" , false ) ,
1364+ ( "/devil/disk/by-something/path" , false ) ,
1365+ ( "/dev/diskxyz/by-something/path" , false ) ,
1366+ ( "/dev/disk/something-by/path" , false ) ,
1367+ ( "/dev/disk/by-/path" , false ) ,
1368+ ( "something" , false ) ,
1369+ ( "/dev/somevg/lv0" , false ) , // LVM Paths are to be used via the /dev/mapper or by /dev/disk/by-id
1370+ ( "/dev/disk/by-id/somepath" , true ) ,
1371+ ( "/dev/disk/by-path/somepath" , true ) ,
1372+ ( "/dev/disk/by-label/somepath" , true ) ,
1373+ ( "/dev/disk/by-partuuid/somepath" , true ) ,
1374+ ( "/dev/disk/by-partlabel/somepath" , true ) ,
1375+ ( "/dev/mapper/dm0" , true ) ,
1376+ ] ;
1377+
1378+ for test in test_suite {
1379+ assert_eq ! ( is_persistent_devlink( test. 0 ) , test. 1 ) ;
1380+ }
1381+ }
0 commit comments