Improve logic for volume snapshots tab

This makes the logic around retrieving volume data in the volume
snapshot page slightly safer. Previously, if the snapshots loaded but
volume didn't a NameError could occur, and the error message would have
been incorrect. This patch fixes both of those issues.

Change-Id: I53df72005b343a9836ed96af045a1f0eb0b3c31d
Related-Bug: 1323644
This commit is contained in:
Rob Cresswell 2017-07-27 16:53:50 +01:00
parent 9e9ee5c145
commit 6be47ced8e

View File

@ -42,15 +42,23 @@ class SnapshotTab(tabs.TableTab):
try:
snapshots = cinder.volume_snapshot_list(
self.request, search_opts={'volume_id': volume_id})
volume = cinder.volume_get(self.request, volume_id)
except Exception:
snapshots = []
exceptions.handle(self.request,
_("Unable to retrieve volume snapshots for "
"volume %s.") % volume_id)
for snapshot in snapshots:
snapshot._volume = volume
try:
volume = cinder.volume_get(self.request, volume_id)
except Exception:
volume = None
exceptions.handle(self.request,
_("Unable to retrieve volume details for "
"volume %s.") % volume_id)
if volume is not None:
for snapshot in snapshots:
snapshot._volume = volume
return snapshots