Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve display of instance image information
When instance is booted from volume image it returns a string,
while for instance from image returns a dict. Fix is made to
handle both cases.

Change-Id: I23aeccd21f88a353222d3fc7dc4b5c337c2bfecb
Closes-Bug: #1239896
  • Loading branch information
lin-hua-cheng authored and dklyle committed Oct 16, 2013
1 parent d716bfc commit d3e8e29
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
39 changes: 39 additions & 0 deletions openstack_dashboard/dashboards/project/instances/tests.py
Expand Up @@ -181,6 +181,45 @@ def test_index_flavor_get_exception(self):
self.assertMessageCount(res, error=len(servers))
self.assertItemsEqual(instances, self.servers.list())

@test.create_stubs({api.nova: ('flavor_list',
'server_list',
'tenant_absolute_limits',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network:
('floating_ip_simple_associate_supported',),
})
def test_index_with_instance_booted_from_volume(self):
volume_server = self.servers.first()
volume_server.image = ""
volume_server.image_name = "(not found)"
servers = self.servers.list()
servers[0] = volume_server

api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(self.limits['absolute'])
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)

self.mox.ReplayAll()

res = self.client.get(INDEX_URL)

self.assertTemplateUsed(res, 'project/instances/index.html')
instances = res.context['instances_table'].data
self.assertEqual(len(instances), len(servers))
self.assertContains(res, "(not found)")

@test.create_stubs({api.nova: ('server_list',
'flavor_list',
'server_delete',),
Expand Down
12 changes: 9 additions & 3 deletions openstack_dashboard/dashboards/project/instances/views.py
Expand Up @@ -88,9 +88,15 @@ def get_data(self):

# Loop through instances to get flavor info.
for instance in instances:
if (hasattr(instance, 'image')
and instance.image['id'] in image_map):
instance.image = image_map[instance.image['id']]
if hasattr(instance, 'image'):
# Instance from image returns dict
if isinstance(instance.image, dict):
if instance.image.get('id') in image_map:
instance.image = image_map[instance.image['id']]
else:
# Instance from volume returns a string
instance.image = {'name':
instance.image if instance.image else _("-")}

try:
flavor_id = instance.flavor["id"]
Expand Down

0 comments on commit d3e8e29

Please sign in to comment.