storage: Handle mount error properly

Closes: #2343.

- The change is needed due to change in privileged exception handling.

Tests:

- In vagrant machine, while FreedomBox service is running, run unit tests are
root user. Observe that exception is not handled properly without the patch. But
a more reasonable error is printed with the patch.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2023-04-28 08:11:45 -07:00 committed by James Valleroy
parent e525d0ff72
commit 43a2734917
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -196,14 +196,14 @@ def _mount(object_path):
try:
privileged.mount(block_device.preferred_device, _log_error=False)
except Exception as exception:
parts = exception.args[2].split(':')
if parts[1].strip() != 'GDBus.Error':
stderr = exception.args[3].decode()
if 'GDBus.Error' not in stderr:
raise
if parts[2].strip() == _ERRORS['AlreadyMounted']:
if _ERRORS['AlreadyMounted'] in stderr:
logger.warning('Device is already mounted: %s %s', block_device.id,
block_device.preferred_device)
elif parts[2].strip() == _ERRORS['Failed']:
elif _ERRORS['Failed'] in stderr:
logger.warning('Mount operation failed: %s %s: %s',
block_device.id, block_device.preferred_device,
exception)