Skip to content

Commit e43f956

Browse files
committed
refactor: separate bind mount setup/clean
Move bind mount setup/clean up into separate functions. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent cb5c5c1 commit e43f956

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

tests/integration_tests/performance/test_jailer.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@
1414
from concurrent.futures import ProcessPoolExecutor
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+
subprocess.run(
28+
["mount", "--bind", f"{mount_path}", f"{mount_path}"], check=True
29+
)
30+
31+
32+
def clean_up_mounts(tmp_path):
33+
"""Cleanup mounts and jailer dirs"""
34+
mounts_paths = tmp_path / "mounts"
35+
for d in os.listdir(mounts_paths):
36+
subprocess.run(["umount", f"{mounts_paths}/{d}"], check=True)
37+
38+
1739
@pytest.mark.nonci
1840
@pytest.mark.parametrize("jailers", [1, 100, 300, 500])
1941
@pytest.mark.parametrize("mounts", [0, 100, 300, 500])
@@ -26,16 +48,7 @@ def test_jailer_startup(
2648

2749
jailer_binary = microvm_factory.jailer_binary_path
2850

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-
subprocess.run(
37-
["mount", "--bind", f"{mount_path}", f"{mount_path}"], check=True
38-
)
51+
setup_bind_mounts(tmp_path, mounts)
3952

4053
metrics.set_dimensions(
4154
{
@@ -81,9 +94,7 @@ def test_jailer_startup(
8194
unit="Microseconds",
8295
)
8396

84-
# Cleanup mounts and jailer dirs
85-
for d in os.listdir(mounts_paths):
86-
subprocess.run(["umount", f"{mounts_paths}/{d}"], check=True)
97+
clean_up_mounts(tmp_path)
8798
shutil.rmtree(DEFAULT_CHROOT_PATH)
8899

89100

@@ -114,16 +125,7 @@ def test_jailer_startup_parallel(
114125

115126
jailer_binary = microvm_factory.jailer_binary_path
116127

117-
# Create bind mount points. The exact location of them
118-
# does not matter, they just need to exist.
119-
mounts_paths = tmp_path / "mounts"
120-
os.makedirs(mounts_paths)
121-
for m in range(mounts):
122-
mount_path = f"{mounts_paths}/mount{m}"
123-
os.makedirs(mount_path)
124-
subprocess.run(
125-
["mount", "--bind", f"{mount_path}", f"{mount_path}"], check=True
126-
)
128+
setup_bind_mounts(tmp_path, mounts)
127129

128130
metrics.set_dimensions(
129131
{
@@ -161,7 +163,5 @@ def test_jailer_startup_parallel(
161163
unit="Microseconds",
162164
)
163165

164-
# Cleanup mounts and jailer dirs
165-
for d in os.listdir(mounts_paths):
166-
subprocess.run(["umount", f"{mounts_paths}/{d}"], check=True)
166+
clean_up_mounts(tmp_path)
167167
shutil.rmtree(DEFAULT_CHROOT_PATH)

0 commit comments

Comments
 (0)