misc.get_scratch_devices(): Split up checks
For better logging.
@@ -808,27 +808,21 @@ def get_scratch_devices(remote):
retval = []
for dev in devs:
- try:
- # FIXME: Split this into multiple calls.
- remote.run(
- args=[
- # node exists
- 'stat',
- dev,
- run.Raw('&&'),
- # readable
- 'sudo', 'dd', 'if=%s' % dev, 'of=/dev/null', 'count=1',
- run.Raw('&&'),
- # not mounted
- run.Raw('!'),
- 'mount',
- run.Raw('|'),
- 'grep', '-q', dev,
+ dev_checks = [
+ [['stat', dev], "does not exist"],
+ [['sudo', 'dd', 'if=%s' % dev, 'of=/dev/null', 'count=1'], "is not readable"],
+ [[run.Raw('!'), 'mount', run.Raw('|'), 'grep', '-q', dev], "is in use"],
]
- )
- retval.append(dev)
+ for args, msg in dev_checks:
+ try:
+ remote.run(args=args)
except CommandFailedError:
- log.debug("get_scratch_devices: %s is in use" % dev)
+ log.debug(f"get_scratch_devices: {dev} {msg}")
+ break
+ else:
+ retval.append(dev)
+ continue
+ break
return retval
