Merge "cmd/manage and coordination: Clean up exception handling"
This commit is contained in:
commit
a1d6d3e4e8
|
@ -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 = {
|
||||
|
|
|
@ -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-')
|
||||
|
|
Loading…
Reference in New Issue