Skip to content

Commit 2e8a813

Browse files
committed
tests: addressed feedback
will squash with the previous commits. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent d8ad616 commit 2e8a813

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/integration_tests/functional/test_drives.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import os
66
import platform
7-
from subprocess import run, CalledProcessError
7+
from subprocess import run, CalledProcessError, PIPE
88

99
import pytest
1010

@@ -92,14 +92,14 @@ def test_rescan_dev(test_microvm_with_ssh, network_config):
9292
size=512
9393
)
9494

95-
# "losetup --find" may slow down tests due to
96-
# https://github.com/firecracker-microvm/firecracker-containerd/issues/141
97-
loopback_device = f'/dev/loop{os.getpid()}'
98-
losetup = ['losetup', loopback_device, fs2.path]
95+
losetup = ['losetup', '--find', '--show', fs2.path]
96+
loopback_device = None
9997
try:
100-
run(losetup, check=True)
101-
except CalledProcessError:
102-
pytest.skip("the kernel doesn't have enough loopback devices")
98+
result = run(losetup, check=True, stdout=PIPE, stderr=PIPE)
99+
loopback_device = result.stdout.decode('utf-8').rstrip()
100+
except CalledProcessError as error:
101+
pytest.skip('failed to create a lookback device: ' +
102+
f'stdout={error.stdout}, stderr={error.stderr}')
103103

104104
try:
105105
response = test_microvm.drive.patch(
@@ -110,7 +110,8 @@ def test_rescan_dev(test_microvm_with_ssh, network_config):
110110

111111
_check_scratch_size(ssh_connection, fs2.size())
112112
finally:
113-
run(['losetup', '-d', loopback_device], check=True)
113+
if loopback_device:
114+
run(['losetup', '--detach', loopback_device], check=True)
114115

115116

116117
def test_non_partuuid_boot(test_microvm_with_ssh, network_config):

0 commit comments

Comments
 (0)