diff options
author | Akihiro Motoki <amotoki@gmail.com> | 2021-02-26 03:44:15 +0900 |
---|---|---|
committer | Michal Nasiadka <mnasiadka@gmail.com> | 2021-10-18 09:55:55 +0000 |
commit | 432f77f887ca15ba8a37fa8a45e9987f4766a6b5 (patch) | |
tree | 109653ab72afb4a6b0f07e8044e26287e0a8fcaa | |
parent | 774800c1b6a974da99cf7def554e8a1ae52dd61e (diff) | |
download | horizon-432f77f887ca15ba8a37fa8a45e9987f4766a6b5.tar.gz |
Handle an attached volume without volume_image_metadata
There is a case where volume_image_metadata attribute does not exist.
It looks like it happens for example when a volume was created before
the volume_image_metadata feature was implemented.
Change-Id: I0b8e6b2e540a1782b9edd9921490a9371d31afc7
Closes-Bug: #1916891
(cherry picked from commit b841952906de33ff93c90cc04ea0509afeaab89f)
-rw-r--r-- | openstack_dashboard/dashboards/project/instances/tabs.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/openstack_dashboard/dashboards/project/instances/tabs.py b/openstack_dashboard/dashboards/project/instances/tabs.py index 686d03798..89d20b6fe 100644 --- a/openstack_dashboard/dashboards/project/instances/tabs.py +++ b/openstack_dashboard/dashboards/project/instances/tabs.py @@ -40,12 +40,19 @@ class OverviewTab(tabs.Tab): try: volume = api.cinder.volume_get( self.request, volume_id=instance.volumes[0].volumeId) - instance.image = { - 'id': volume.volume_image_metadata['image_id'], - 'name': volume.volume_image_metadata['image_name']} except Exception: exceptions.handle(self.request, _('Failed to get attached volume.')) + try: + instance.image = { + 'id': volume.volume_image_metadata['image_id'], + 'name': volume.volume_image_metadata['image_name'], + } + except (AttributeError, KeyError): + # AttributeError is raised when volume_image_metadata does not + # exist. KeyError is raised when volume_image_metadata exists + # but image_id or image_name is not included. + instance.image = None return {"instance": instance} |