@@ -28,7 +28,11 @@ async fn read_ldev_config() -> Result<String, ImlAgentError> {
28
28
}
29
29
30
30
fn parse_entries ( ldev_config : String ) -> BTreeSet < LdevEntry > {
31
- ldev_config. lines ( ) . map ( LdevEntry :: from) . collect ( )
31
+ ldev_config
32
+ . lines ( )
33
+ . filter ( |x| !x. trim_start ( ) . starts_with ( "#" ) )
34
+ . map ( LdevEntry :: from)
35
+ . collect ( )
32
36
}
33
37
34
38
fn convert ( entries : & [ LdevEntry ] ) -> String {
@@ -44,6 +48,7 @@ pub async fn create(entries: Vec<LdevEntry>) -> Result<(), ImlAgentError> {
44
48
let ldev_config = read_ldev_config ( ) . await ?;
45
49
let existing_entries = parse_entries ( ldev_config) ;
46
50
let entries_set = entries. iter ( ) . cloned ( ) . collect :: < BTreeSet < LdevEntry > > ( ) ;
51
+
47
52
if existing_entries != entries_set {
48
53
let data = convert ( & entries) ;
49
54
write_to_file ( data) . await ?;
@@ -63,7 +68,69 @@ mod tests {
63
68
use iml_wire_types:: FsType ;
64
69
65
70
#[ test]
66
- fn test_create ( ) -> Result < ( ) , ImlAgentError > {
71
+ fn test_ldiskfs_create ( ) -> Result < ( ) , ImlAgentError > {
72
+ let entries = vec ! [
73
+ LdevEntry {
74
+ primary: "mds1" . into( ) ,
75
+ failover: Some ( "mds2" . into( ) ) ,
76
+ label: "MGS" . into( ) ,
77
+ device: "/mnt/mgt" . into( ) ,
78
+ fs_type: Some ( FsType :: Ldiskfs ) ,
79
+ } ,
80
+ LdevEntry {
81
+ primary: "mds1" . into( ) ,
82
+ failover: Some ( "mds2" . into( ) ) ,
83
+ label: "fs-MDT0000" . into( ) ,
84
+ device: "/mnt/mdt0" . into( ) ,
85
+ fs_type: Some ( FsType :: Ldiskfs ) ,
86
+ } ,
87
+ LdevEntry {
88
+ primary: "mds2" . into( ) ,
89
+ failover: Some ( "mds1" . into( ) ) ,
90
+ label: "fs-MDT0001" . into( ) ,
91
+ device: "/mnt/mdt1" . into( ) ,
92
+ fs_type: Some ( FsType :: Ldiskfs ) ,
93
+ } ,
94
+ LdevEntry {
95
+ primary: "oss1" . into( ) ,
96
+ failover: Some ( "oss2" . into( ) ) ,
97
+ label: "fs-OST0000" . into( ) ,
98
+ device: "/mnt/ost0" . into( ) ,
99
+ fs_type: Some ( FsType :: Ldiskfs ) ,
100
+ } ,
101
+ LdevEntry {
102
+ primary: "oss2" . into( ) ,
103
+ failover: Some ( "oss1" . into( ) ) ,
104
+ label: "fs-OST0001" . into( ) ,
105
+ device: "/mnt/ost1" . into( ) ,
106
+ fs_type: Some ( FsType :: Ldiskfs ) ,
107
+ } ,
108
+ LdevEntry {
109
+ primary: "oss1" . into( ) ,
110
+ failover: Some ( "oss2" . into( ) ) ,
111
+ label: "fs-OST0002" . into( ) ,
112
+ device: "/mnt/ost2" . into( ) ,
113
+ fs_type: Some ( FsType :: Ldiskfs ) ,
114
+ } ,
115
+ LdevEntry {
116
+ primary: "oss2" . into( ) ,
117
+ failover: Some ( "oss1" . into( ) ) ,
118
+ label: "fs-OST0003" . into( ) ,
119
+ device: "/mnt/ost3" . into( ) ,
120
+ fs_type: Some ( FsType :: Ldiskfs ) ,
121
+ } ,
122
+ ]
123
+ . into_iter ( )
124
+ . collect :: < Vec < LdevEntry > > ( ) ;
125
+
126
+ let data = convert ( & entries) ;
127
+ insta:: assert_snapshot!( data) ;
128
+
129
+ Ok ( ( ) )
130
+ }
131
+
132
+ #[ test]
133
+ fn test_zfs_create ( ) -> Result < ( ) , ImlAgentError > {
67
134
let entries = vec ! [
68
135
LdevEntry {
69
136
primary: "mds1" . into( ) ,
@@ -208,21 +275,21 @@ mod tests {
208
275
LdevEntry {
209
276
primary: "oss2" . into( ) ,
210
277
failover: Some ( "oss1" . into( ) ) ,
211
- label: "zfsmo-OST00011 " . into( ) ,
278
+ label: "zfsmo-OST0011 " . into( ) ,
212
279
device: "zfs:ost17/ost17" . into( ) ,
213
280
fs_type: Some ( FsType :: Zfs ) ,
214
281
} ,
215
282
LdevEntry {
216
283
primary: "oss2" . into( ) ,
217
284
failover: Some ( "oss1" . into( ) ) ,
218
- label: "zfsmo-OST00012 " . into( ) ,
285
+ label: "zfsmo-OST0012 " . into( ) ,
219
286
device: "zfs:ost18/ost18" . into( ) ,
220
287
fs_type: Some ( FsType :: Zfs ) ,
221
288
} ,
222
289
LdevEntry {
223
290
primary: "oss2" . into( ) ,
224
291
failover: Some ( "oss1" . into( ) ) ,
225
- label: "zfsmo-OST00013 " . into( ) ,
292
+ label: "zfsmo-OST0013 " . into( ) ,
226
293
device: "zfs:ost19/ost19" . into( ) ,
227
294
fs_type: Some ( FsType :: Zfs ) ,
228
295
} ,
@@ -262,4 +329,50 @@ mod tests {
262
329
263
330
Ok ( ( ) )
264
331
}
332
+
333
+ #[ test]
334
+ fn test_parsing_commented_data ( ) -> Result < ( ) , ImlAgentError > {
335
+ let content: String = r#"# example /etc/ldev.conf
336
+ #
337
+ #local foreign/- label [md|zfs:]device-path [journal-path]/- [raidtab]
338
+ #
339
+ #zeno-mds1 - zeno-MDT0000 zfs:lustre-zeno-mds1/mdt1
340
+ #
341
+ #zeno1 zeno5 zeno-OST0000 zfs:lustre-zeno1/ost1
342
+ #zeno2 zeno6 zeno-OST0001 zfs:lustre-zeno2/ost1
343
+ #zeno3 zeno7 zeno-OST0002 zfs:lustre-zeno3/ost1
344
+ #zeno4 zeno8 zeno-OST0003 zfs:lustre-zeno4/ost1
345
+ #zeno5 zeno1 zeno-OST0004 zfs:lustre-zeno5/ost1
346
+ #zeno6 zeno2 zeno-OST0005 zfs:lustre-zeno6/ost1
347
+ #zeno7 zeno3 zeno-OST0006 zfs:lus tre-zeno7/ost1
348
+ #zeno8 zeno4 zeno-OST0007 zfs:lustre-zeno8/ost1"#
349
+ . into ( ) ;
350
+
351
+ let data: BTreeSet < LdevEntry > = parse_entries ( content) ;
352
+
353
+ assert ! ( data. is_empty( ) ) ;
354
+
355
+ Ok ( ( ) )
356
+ }
357
+
358
+ #[ test]
359
+ fn test_parsing_data ( ) -> Result < ( ) , ImlAgentError > {
360
+ let content: String = r#"#zeno-mds1 - zeno-MDT0000 zfs:lustre-zeno-mds1/mdt1
361
+ # Random comment
362
+ zeno1 zeno5 zeno-OST0000 zfs:lustre-zeno1/ost1
363
+ zeno2 - zeno-OST0001 zfs:lustre-zeno2/ost1
364
+ zeno3 zeno7 zeno-OST0002 zfs:lustre-zeno3/ost1
365
+ zeno4 zeno8 zeno-OST0003 zfs:lustre-zeno4/ost1
366
+ zeno5 zeno1 zeno-OST0004 zfs:lustre-zeno5/ost1
367
+ zeno6 - zeno-OST0005 zfs:lustre-zeno6/ost1
368
+ zeno7 zeno3 zeno-OST0006 zfs:lustre-zeno7/ost1
369
+ zeno8 zeno4 zeno-OST0007 zfs:lustre-zeno8/ost1"#
370
+ . into ( ) ;
371
+
372
+ let data: BTreeSet < LdevEntry > = parse_entries ( content) ;
373
+
374
+ insta:: assert_debug_snapshot!( data) ;
375
+
376
+ Ok ( ( ) )
377
+ }
265
378
}
0 commit comments