1414from framework .properties import global_props
1515
1616
17+ def setup_bind_mounts (tmp_path , n ):
18+ """
19+ Create bind mount points. The exact location of them
20+ does not matter, they just need to exist.
21+ """
22+ mounts_paths = tmp_path / "mounts"
23+ os .makedirs (mounts_paths )
24+ for m in range (n ):
25+ mount_path = f"{ mounts_paths } /mount{ m } "
26+ os .makedirs (mount_path )
27+ utils .check_output (f"mount --bind { mount_path } { mount_path } " )
28+
29+
30+ def clean_up_mounts (tmp_path ):
31+ """Cleanup mounts and jailer dirs"""
32+ mounts_paths = tmp_path / "mounts"
33+ for d in os .listdir (mounts_paths ):
34+ utils .check_output (f"umount { mounts_paths } /{ d } " )
35+
36+
1737@pytest .mark .nonci
1838@pytest .mark .parametrize ("jailers" , [1 , 100 , 300 , 500 ])
1939@pytest .mark .parametrize ("mounts" , [0 , 100 , 300 , 500 ])
@@ -26,14 +46,7 @@ def test_jailer_startup(
2646
2747 jailer_binary = microvm_factory .jailer_binary_path
2848
29- # Create bind mount points. The exact location of them
30- # does not matter, they just need to exist.
31- mounts_paths = tmp_path / "mounts"
32- os .makedirs (mounts_paths )
33- for m in range (mounts ):
34- mount_path = f"{ mounts_paths } /mount{ m } "
35- os .makedirs (mount_path )
36- utils .check_output (f"mount --bind { mount_path } { mount_path } " )
49+ setup_bind_mounts (tmp_path , mounts )
3750
3851 metrics .set_dimensions (
3952 {
@@ -79,9 +92,7 @@ def test_jailer_startup(
7992 unit = "Microseconds" ,
8093 )
8194
82- # Cleanup mounts and jailer dirs
83- for d in os .listdir (mounts_paths ):
84- utils .check_output (f"umount { mounts_paths } /{ d } " )
95+ clean_up_mounts (tmp_path )
8596 shutil .rmtree (DEFAULT_CHROOT_PATH )
8697
8798
@@ -112,13 +123,7 @@ def test_jailer_startup_parallel(
112123
113124 jailer_binary = microvm_factory .jailer_binary_path
114125
115- # Create bind mount points. The exact location of them
116- # does not matter, they just need to exist.
117- mounts_paths = tmp_path / "mounts"
118- for m in range (mounts ):
119- mount_path = f"{ mounts_paths } /mount{ m } "
120- os .makedirs (mount_path )
121- utils .check_output (f"mount --bind { mount_path } { mount_path } " )
126+ setup_bind_mounts (tmp_path , mounts )
122127
123128 metrics .set_dimensions (
124129 {
@@ -156,7 +161,5 @@ def test_jailer_startup_parallel(
156161 unit = "Microseconds" ,
157162 )
158163
159- # Cleanup mounts and jailer dirs
160- for d in os .listdir (mounts_paths ):
161- utils .check_output (f"umount { mounts_paths } /{ d } " )
164+ clean_up_mounts (tmp_path )
162165 shutil .rmtree (DEFAULT_CHROOT_PATH )
0 commit comments