Skip to content

Commit 867621f

Browse files
committed
refactor: separate bind mount setup/clean
Move bind mount setup/clean up into separate functions. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 4c1a8f7 commit 867621f

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
@@ -13,6 +13,28 @@
1313
from framework.properties import global_props
1414

1515

16+
def setup_bind_mounts(tmp_path, n):
17+
"""
18+
Create bind mount points. The exact location of them
19+
does not matter, they just need to exist.
20+
"""
21+
mounts_paths = tmp_path / "mounts"
22+
os.makedirs(mounts_paths)
23+
for m in range(n):
24+
mount_path = f"{mounts_paths}/mount{m}"
25+
os.makedirs(mount_path)
26+
subprocess.run(
27+
["mount", "--bind", f"{mount_path}", f"{mount_path}"], check=True
28+
)
29+
30+
31+
def clean_up_mounts(tmp_path):
32+
"""Cleanup mounts and jailer dirs"""
33+
mounts_paths = tmp_path / "mounts"
34+
for d in os.listdir(mounts_paths):
35+
subprocess.run(["umount", f"{mounts_paths}/{d}"], check=True)
36+
37+
1638
@pytest.mark.nonci
1739
@pytest.mark.parametrize("jailers", [1, 100, 300, 500])
1840
@pytest.mark.parametrize("mounts", [0, 100, 300, 500])
@@ -25,16 +47,7 @@ def test_jailer_startup(
2547

2648
jailer_binary = microvm_factory.jailer_binary_path
2749

28-
# Create bind mount points. The exact location of them
29-
# does not matter, they just need to exist.
30-
mounts_paths = tmp_path / "mounts"
31-
os.makedirs(mounts_paths)
32-
for m in range(mounts):
33-
mount_path = f"{mounts_paths}/mount{m}"
34-
os.makedirs(mount_path)
35-
subprocess.run(
36-
["mount", "--bind", f"{mount_path}", f"{mount_path}"], check=True
37-
)
50+
setup_bind_mounts(tmp_path, mounts)
3851

3952
metrics.set_dimensions(
4053
{
@@ -80,9 +93,7 @@ def test_jailer_startup(
8093
unit="Microseconds",
8194
)
8295

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

8899

@@ -113,16 +124,7 @@ def test_jailer_startup_parallel(
113124

114125
jailer_binary = microvm_factory.jailer_binary_path
115126

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

127129
metrics.set_dimensions(
128130
{
@@ -160,7 +162,5 @@ def test_jailer_startup_parallel(
160162
unit="Microseconds",
161163
)
162164

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

0 commit comments

Comments
 (0)