RBD driver: clean up _trash_purge exception handling

This is cleaner if we catch OSError specifically, and
also alleviates the need for pylint/type checking skips.

Change-Id: Ief59eea8ccdd8d263e262ba04d209829321ac6d1
This commit is contained in:
Eric Harney 2021-11-22 16:17:00 -05:00
parent f6cb333c13
commit 1075d1d304
1 changed files with 15 additions and 10 deletions

View File

@ -374,14 +374,17 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD,
def _trash_purge(self):
LOG.info("Purging trash for backend '%s'", self._backend_name)
def _err(vol_name: str, backend_name: str) -> None:
LOG.exception("Error deleting %s from trash backend '%s'",
vol_name,
backend_name)
with RADOSClient(self) as client:
for vol in self.RBDProxy().trash_list(client.ioctx):
try:
self.RBDProxy().trash_remove(client.ioctx, vol.get('id'))
LOG.info("Deleted %s from trash for backend '%s'",
vol.get('name'),
self._backend_name)
except Exception as e:
except OSError as e:
# NOTE(arne_wiebalck): trash_remove raises EPERM in case
# the volume's deferral time has not expired yet, so we
# want to explicitly handle this "normal" situation.
@ -389,16 +392,18 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD,
# so that the periodic purge retries on the next iteration
# and leaves ERRORs in the logs in case the deletion fails
# repeatedly.
# pylint: disable=E1101
if (e is OSError) and (e.errno == errno.EPERM):
if (e.errno == errno.EPERM):
LOG.debug("%s has not expired yet on backend '%s'",
vol.get('name'),
self._backend_name)
else:
LOG.exception("Error deleting %s from trash "
"backend '%s'",
vol.get('name'),
self._backend_name)
_err(vol.get('name'), self._backend_name)
except Exception:
_err(vol.get('name'), self._backend_name)
else:
LOG.info("Deleted %s from trash for backend '%s'",
vol.get('name'),
self._backend_name)
def _start_periodic_tasks(self):
if self.configuration.enable_deferred_deletion: