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)}
|
if not objects.Snapshot.exists(self.ctxt, snap_id)}
|
||||||
self._exclude_running_backups(backups)
|
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
|
# Now clean
|
||||||
for filenames in itertools.chain(volumes.values(),
|
for filenames in itertools.chain(volumes.values(),
|
||||||
snapshots.values(),
|
snapshots.values(),
|
||||||
|
@ -973,11 +977,11 @@ class UtilCommands(object):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
try:
|
try:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
except OSError as exc:
|
||||||
|
if (exc.errno != errno.ENOENT):
|
||||||
|
_err(filename, exc)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
if not (isinstance(exc, OSError) and
|
_err(filename, exc)
|
||||||
exc.errno == errno.ENOENT):
|
|
||||||
print('Failed to cleanup lock %(name)s: %(exc)s',
|
|
||||||
{'name': filename, 'exc': exc})
|
|
||||||
|
|
||||||
|
|
||||||
CATEGORIES = {
|
CATEGORIES = {
|
||||||
|
|
|
@ -110,16 +110,21 @@ class Coordinator(object):
|
||||||
def remove_lock(self, glob_name):
|
def remove_lock(self, glob_name):
|
||||||
# Most locks clean up on release, but not the file lock, so we manually
|
# Most locks clean up on release, but not the file lock, so we manually
|
||||||
# clean them.
|
# 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:
|
if self._file_path:
|
||||||
files = glob.glob(self._file_path + glob_name)
|
files = glob.glob(self._file_path + glob_name)
|
||||||
for file_name in files:
|
for file_name in files:
|
||||||
try:
|
try:
|
||||||
os.remove(file_name)
|
os.remove(file_name)
|
||||||
|
except OSError as exc:
|
||||||
|
if (exc.errno != errno.ENOENT):
|
||||||
|
_err(file_name, exc)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
if not (isinstance(exc, OSError) and
|
_err(file_name, exc)
|
||||||
exc.errno == errno.ENOENT):
|
|
||||||
LOG.warning('Failed to cleanup lock %(name)s: %(exc)s',
|
|
||||||
{'name': file_name, 'exc': exc})
|
|
||||||
|
|
||||||
|
|
||||||
COORDINATOR = Coordinator(prefix='cinder-')
|
COORDINATOR = Coordinator(prefix='cinder-')
|
||||||
|
|
Loading…
Reference in New Issue