Browse Source

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
Lin Hua Cheng 5 years ago
parent
commit
d3e8e29f1e

+ 39
- 0
openstack_dashboard/dashboards/project/instances/tests.py View File

@@ -181,6 +181,45 @@ class InstanceTests(test.TestCase):
181 181
         self.assertMessageCount(res, error=len(servers))
182 182
         self.assertItemsEqual(instances, self.servers.list())
183 183
 
184
+    @test.create_stubs({api.nova: ('flavor_list',
185
+                                   'server_list',
186
+                                   'tenant_absolute_limits',
187
+                                   'extension_supported',),
188
+                        api.glance: ('image_list_detailed',),
189
+                        api.network:
190
+                            ('floating_ip_simple_associate_supported',),
191
+                        })
192
+    def test_index_with_instance_booted_from_volume(self):
193
+        volume_server = self.servers.first()
194
+        volume_server.image = ""
195
+        volume_server.image_name = "(not found)"
196
+        servers = self.servers.list()
197
+        servers[0] = volume_server
198
+
199
+        api.nova.extension_supported('AdminActions',
200
+                                     IsA(http.HttpRequest)) \
201
+            .MultipleTimes().AndReturn(True)
202
+        api.nova.flavor_list(IsA(http.HttpRequest)) \
203
+            .AndReturn(self.flavors.list())
204
+        api.glance.image_list_detailed(IgnoreArg()) \
205
+            .AndReturn((self.images.list(), False))
206
+        search_opts = {'marker': None, 'paginate': True}
207
+        api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
208
+            .AndReturn([servers, False])
209
+        api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
210
+           .MultipleTimes().AndReturn(self.limits['absolute'])
211
+        api.network.floating_ip_simple_associate_supported(
212
+            IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
213
+
214
+        self.mox.ReplayAll()
215
+
216
+        res = self.client.get(INDEX_URL)
217
+
218
+        self.assertTemplateUsed(res, 'project/instances/index.html')
219
+        instances = res.context['instances_table'].data
220
+        self.assertEqual(len(instances), len(servers))
221
+        self.assertContains(res, "(not found)")
222
+
184 223
     @test.create_stubs({api.nova: ('server_list',
185 224
                                    'flavor_list',
186 225
                                    'server_delete',),

+ 9
- 3
openstack_dashboard/dashboards/project/instances/views.py View File

@@ -88,9 +88,15 @@ class IndexView(tables.DataTableView):
88 88
 
89 89
             # Loop through instances to get flavor info.
90 90
             for instance in instances:
91
-                if (hasattr(instance, 'image')
92
-                        and instance.image['id'] in image_map):
93
-                    instance.image = image_map[instance.image['id']]
91
+                if hasattr(instance, 'image'):
92
+                    # Instance from image returns dict
93
+                    if isinstance(instance.image, dict):
94
+                        if instance.image.get('id') in image_map:
95
+                            instance.image = image_map[instance.image['id']]
96
+                    else:
97
+                        # Instance from volume returns a string
98
+                        instance.image = {'name':
99
+                                instance.image if instance.image else _("-")}
94 100
 
95 101
                 try:
96 102
                     flavor_id = instance.flavor["id"]

Loading…
Cancel
Save