From 9f0aef12660ebda483daec7818fbd15cc71a8f4e Mon Sep 17 00:00:00 2001 From: Pengju Jiao Date: Fri, 21 Apr 2017 22:58:51 +0800 Subject: [PATCH] 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 --- freezer/openstack/osclients.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/freezer/openstack/osclients.py b/freezer/openstack/osclients.py index a68d6460..4d23877e 100644 --- a/freezer/openstack/osclients.py +++ b/freezer/openstack/osclients.py @@ -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")