@@ -20,57 +20,48 @@ use tempfile::TempDir;
2020
2121use crate :: { get_test_image, run_bcvk, INTEGRATION_TEST_LABEL } ;
2222
23- /// Create a systemd unit that verifies a mount exists and contains expected content
23+ /// Create a systemd unit that verifies a mount exists and tests writability
2424fn create_mount_verify_unit (
2525 unit_dir : & Utf8Path ,
2626 mount_name : & str ,
2727 expected_file : & str ,
28- expected_content : & str ,
28+ expected_content : Option < & str > ,
29+ readonly : bool ,
2930) -> std:: io:: Result < ( ) > {
30- let unit_content = format ! (
31- r#"[Unit]
32- Description=Verify mount {mount_name} and poweroff
33- RequiresMountsFor=/run/virtiofs-mnt-{mount_name}
31+ let ( description, content_check, write_check, unit_prefix) = if readonly {
32+ (
33+ format ! ( "Verify read-only mount {mount_name} and poweroff" ) ,
34+ format ! ( "ExecStart=test -f /run/virtiofs-mnt-{mount_name}/{expected_file}" ) ,
35+ format ! ( "ExecStart=/bin/sh -c '! echo test-write > /run/virtiofs-mnt-{mount_name}/write-test.txt 2>/dev/null'" ) ,
36+ "verify-ro-mount" ,
37+ )
38+ } else {
39+ let content = expected_content. expect ( "expected_content required for writable mounts" ) ;
40+ (
41+ format ! ( "Verify mount {mount_name} and poweroff" ) ,
42+ format ! ( "ExecStart=grep -qF \" {content}\" /run/virtiofs-mnt-{mount_name}/{expected_file}" ) ,
43+ format ! ( "ExecStart=/bin/sh -c 'echo test-write > /run/virtiofs-mnt-{mount_name}/write-test.txt'" ) ,
44+ "verify-mount" ,
45+ )
46+ } ;
3447
35- [Service]
36- Type=oneshot
37- ExecStart=grep -qF "{expected_content}" /run/virtiofs-mnt-{mount_name}/{expected_file}
38- ExecStart=test -w /run/virtiofs-mnt-{mount_name}/{expected_file}
39- ExecStart=echo ok mount verify {mount_name}
40- ExecStart=systemctl poweroff
41- StandardOutput=journal+console
42- StandardError=journal+console
43- "#
44- ) ;
45-
46- let unit_path = unit_dir. join ( format ! ( "verify-mount-{}.service" , mount_name) ) ;
47- fs:: write ( & unit_path, unit_content) ?;
48- Ok ( ( ) )
49- }
50-
51- /// Create a systemd unit that tries to write to a mount to verify read-only status
52- fn create_ro_mount_verify_unit (
53- unit_dir : & Utf8Path ,
54- mount_name : & str ,
55- expected_file : & str ,
56- ) -> std:: io:: Result < ( ) > {
5748 let unit_content = format ! (
5849 r#"[Unit]
59- Description=Verify read-only mount {mount_name} and poweroff
50+ Description={description}
6051RequiresMountsFor=/run/virtiofs-mnt-{mount_name}
6152
6253[Service]
6354Type=oneshot
64- ExecStart=test -f /run/virtiofs-mnt-{mount_name}/{expected_file }
65- ExecStart=test '!' -w /run/virtiofs-mnt-{mount_name}/{expected_file }
55+ {content_check }
56+ {write_check }
6657ExecStart=echo ok mount verify {mount_name}
6758ExecStart=systemctl poweroff
6859StandardOutput=journal+console
6960StandardError=journal+console
7061"#
7162 ) ;
7263
73- let unit_path = unit_dir. join ( format ! ( "verify-ro-mount-{ }.service" , mount_name ) ) ;
64+ let unit_path = unit_dir. join ( format ! ( "{unit_prefix}-{mount_name }.service" ) ) ;
7465 fs:: write ( & unit_path, unit_content) ?;
7566 Ok ( ( ) )
7667}
@@ -90,8 +81,14 @@ pub fn test_mount_feature_bind() {
9081 fs:: create_dir ( & system_dir) . expect ( "Failed to create system directory" ) ;
9182
9283 // Create verification unit
93- create_mount_verify_unit ( & system_dir, "testmount" , "test.txt" , test_content)
94- . expect ( "Failed to create verify unit" ) ;
84+ create_mount_verify_unit (
85+ & system_dir,
86+ "testmount" ,
87+ "test.txt" ,
88+ Some ( test_content) ,
89+ false ,
90+ )
91+ . expect ( "Failed to create verify unit" ) ;
9592
9693 println ! ( "Testing bind mount with temp directory: {}" , temp_dir_path) ;
9794
@@ -135,7 +132,7 @@ pub fn test_mount_feature_ro_bind() {
135132 fs:: create_dir ( & system_dir) . expect ( "Failed to create system directory" ) ;
136133
137134 // Create verification unit for read-only mount
138- create_ro_mount_verify_unit ( & system_dir, "romount" , "readonly.txt" )
135+ create_mount_verify_unit ( & system_dir, "romount" , "readonly.txt" , None , true )
139136 . expect ( "Failed to create verify unit" ) ;
140137
141138 println ! (
0 commit comments