Only show image name as a link when the image exists

Updated the nova api to return None when the image name
is not available, for example, when it's deleted.

Added a check for the image name before showing it as
a link.

Change-Id: I342b23dfd8352182f50c41054d2dbb3eae854839
Closes-bug:1668783
This commit is contained in:
Ying Zuo 2017-03-01 13:21:41 -08:00
parent a3e28c1b6c
commit a35cf2da28
3 changed files with 10 additions and 4 deletions

View File

@ -118,7 +118,7 @@ class Server(base.APIResourceWrapper):
from openstack_dashboard.api import glance
if not self.image:
return _("-")
return None
if hasattr(self.image, 'name'):
return self.image.name
if 'name' in self.image:
@ -129,7 +129,7 @@ class Server(base.APIResourceWrapper):
return image.name
except (glance_exceptions.ClientException,
horizon_exceptions.ServiceCatalogException):
return _("-")
return None
@property
def internal_name(self):

View File

@ -101,7 +101,13 @@
{% endwith %}
{% if instance.image %}
<dt>{% trans "Image Name" %}</dt>
<dd><a href="{{ instance.image_url }}">{{ instance.image_name }}</a></dd>
<dd>
{% if instance.image_name %}
<a href="{{ instance.image_url }}">{{ instance.image_name }}</a>
{% else %}
{% trans "-" %}
{% endif %}
</dd>
<dt>{% trans "Image ID" %}</dt>
<dd>{{ instance.image.id }}</dd>
{% else %}

View File

@ -59,7 +59,7 @@ class ServerWrapperTests(test.TestCase):
self.mox.ReplayAll()
server = api.nova.Server(server, self.request)
self.assertEqual('-', server.image_name)
self.assertEqual(None, server.image_name)
class ComputeApiTests(test.APITestCase):