Merge "cmd/manage and coordination: Clean up exception handling"

This commit is contained in:
Zuul 2022-06-14 16:58:34 +00:00 committed by Gerrit Code Review
commit a1d6d3e4e8
2 changed files with 17 additions and 8 deletions

View File

@ -966,6 +966,10 @@ class UtilCommands(object):
if not objects.Snapshot.exists(self.ctxt, snap_id)}
self._exclude_running_backups(backups)
def _err(filename: str, exc: Exception) -> None:
print('Failed to cleanup lock %(name)s: %(exc)s',
{'name': filename, 'exc': exc})
# Now clean
for filenames in itertools.chain(volumes.values(),
snapshots.values(),
@ -973,11 +977,11 @@ class UtilCommands(object):
for filename in filenames:
try:
os.remove(filename)
except OSError as exc:
if (exc.errno != errno.ENOENT):
_err(filename, exc)
except Exception as exc:
if not (isinstance(exc, OSError) and
exc.errno == errno.ENOENT):
print('Failed to cleanup lock %(name)s: %(exc)s',
{'name': filename, 'exc': exc})
_err(filename, exc)
CATEGORIES = {

View File

@ -110,16 +110,21 @@ class Coordinator(object):
def remove_lock(self, glob_name):
# Most locks clean up on release, but not the file lock, so we manually
# clean them.
def _err(file_name: str, exc: Exception) -> None:
LOG.warning('Failed to cleanup lock %(name)s: %(exc)s',
{'name': file_name, 'exc': exc})
if self._file_path:
files = glob.glob(self._file_path + glob_name)
for file_name in files:
try:
os.remove(file_name)
except OSError as exc:
if (exc.errno != errno.ENOENT):
_err(file_name, exc)
except Exception as exc:
if not (isinstance(exc, OSError) and
exc.errno == errno.ENOENT):
LOG.warning('Failed to cleanup lock %(name)s: %(exc)s',
{'name': file_name, 'exc': exc})
_err(file_name, exc)
COORDINATOR = Coordinator(prefix='cinder-')