4
4
5
5
import os
6
6
import platform
7
- from subprocess import run , CalledProcessError
7
+ from subprocess import run , CalledProcessError , PIPE
8
8
9
9
import pytest
10
10
@@ -92,14 +92,14 @@ def test_rescan_dev(test_microvm_with_ssh, network_config):
92
92
size = 512
93
93
)
94
94
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
99
97
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 } ' )
103
103
104
104
try :
105
105
response = test_microvm .drive .patch (
@@ -110,7 +110,8 @@ def test_rescan_dev(test_microvm_with_ssh, network_config):
110
110
111
111
_check_scratch_size (ssh_connection , fs2 .size ())
112
112
finally :
113
- run (['losetup' , '-d' , loopback_device ], check = True )
113
+ if loopback_device :
114
+ run (['losetup' , '--detach' , loopback_device ], check = True )
114
115
115
116
116
117
def test_non_partuuid_boot (test_microvm_with_ssh , network_config ):
0 commit comments