storage: tests: Ignore cases needing loop devices when not available

- In containers, loopback devices may not be available. Skip tests in this case
by looking at the output of losetup setup utility.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2020-06-28 21:02:14 -04:00
1 parent 86829a29c1
commit 618501f8e6
1 file changed
+7 -1
+7 -1
View File
@@ -48,7 +48,13 @@ class Disk():
command = 'losetup --show --find {file}'.format(
file=self.disk_file.name)
process = subprocess.run(command.split(), stdout=subprocess.PIPE,
check=True)
stderr=subprocess.PIPE)
if process.returncode:
if b'cannot find an unused loop device' in process.stderr:
pytest.skip('Loopback devices not available')
else:
raise Exception(process.stderr)
device = process.stdout.decode().strip()
subprocess.run(['partprobe', device], check=True)