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 2020-06-28 17:22:21 -07:00 committed by James Valleroy
parent 86829a29c1
commit 618501f8e6
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

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)