Optimize cinder mode backup in special cases

1. The backup may be in an infinite loop in the case that
   the volume copy is in error state.
2. When snapshot error, backup will be interrupted, but
   the wrong snapshot will never be deleted.

Change-Id: Ia29ae1d352930852c80ba776f5bf44173a42cadb
Closes-Bug: #1685261
This commit is contained in:
Pengju Jiao 2017-04-21 22:58:51 +08:00
parent e3456649b8
commit 9f0aef1266

View File

@ -211,11 +211,13 @@ class OSClientManager(object):
LOG.debug("Snapshot status: " + snapshot.status)
snapshot = self.get_cinder().volume_snapshots.get(snapshot.id)
if snapshot.status == "error":
raise Exception("snapshot has error state")
raise RuntimeError("snapshot has error state")
time.sleep(5)
except RuntimeError:
LOG.info("Delete snapshot in error state " + snapshot.id)
self.get_cinder().volume_snapshots.delete(snapshot)
raise
except Exception as e:
if str(e) == "snapshot has error state":
raise
LOG.exception(e)
return snapshot
@ -233,7 +235,13 @@ class OSClientManager(object):
try:
LOG.info("Volume copy status: " + volume.status)
volume = self.get_cinder().volumes.get(volume.id)
if volume.status == "error":
raise RuntimeError("Volume copy has error state")
time.sleep(5)
except RuntimeError:
LOG.info("Delete volume in error state " + volume.id)
self.get_cinder().volumes.delete(volume.id)
raise
except Exception as e:
LOG.exception(e)
LOG.warning("Exception getting volume status")