From 5cd1e5d216997c9d2b6e9fbcbea75c91984a2fed Mon Sep 17 00:00:00 2001 From: Tihomir Trifonov Date: Tue, 27 Mar 2012 10:13:05 +0300 Subject: [PATCH] Fix issue with not loading and showing tenant name in syspanel/instance view Fixes bug 964739 Patch2: Replaced API calls with _get(), added unit test The prefill of tenant_name was missing. The same code is present in AdminIndexView. Maybe it would be better to make UpdateRow as part of the TableView, because they share almost the same get_data() code... Change-Id: Ib74f7049625292644bba41ac0ab17279274a8ca3 --- .../instances_and_volumes/instances/tables.py | 9 ++++-- .../dashboards/syspanel/instances/tests.py | 31 +++++++++++++++++++ horizon/tests/test_data/nova_data.py | 1 + 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/tables.py b/horizon/dashboards/nova/instances_and_volumes/instances/tables.py index 7b13c0fc9..56f938f05 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/tables.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/tables.py @@ -181,9 +181,12 @@ class UpdateRow(tables.Row): def get_data(self, request, instance_id): instance = api.server_get(request, instance_id) - flavors = api.flavor_list(request) - keyed_flavors = [(str(flavor.id), flavor) for flavor in flavors] - instance.full_flavor = SortedDict(keyed_flavors)[instance.flavor["id"]] + instance.full_flavor = api.flavor_get(request, instance.flavor["id"]) + tenant = api.keystone.tenant_get(request, + instance.tenant_id, + admin=True) + instance.tenant_name = getattr(tenant, "name", None) + return instance diff --git a/horizon/dashboards/syspanel/instances/tests.py b/horizon/dashboards/syspanel/instances/tests.py index fc78d7e6f..506eb8298 100644 --- a/horizon/dashboards/syspanel/instances/tests.py +++ b/horizon/dashboards/syspanel/instances/tests.py @@ -55,3 +55,34 @@ class InstanceViewTest(test.BaseAdminViewTests): res = self.client.get(reverse('horizon:syspanel:instances:index')) self.assertTemplateUsed(res, 'syspanel/instances/index.html') self.assertEqual(len(res.context['instances_table'].data), 0) + + def test_ajax_loading_instances(self): + server = self.servers.first() + flavor = self.flavors.list()[0] + tenant = self.tenants.list()[0] + + self.mox.StubOutWithMock(api, 'server_get') + self.mox.StubOutWithMock(api, 'flavor_get') + self.mox.StubOutWithMock(api.keystone, 'tenant_get') + api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) + api.flavor_get(IsA(http.HttpRequest), + server.flavor['id']).AndReturn(flavor) + api.keystone.tenant_get(IsA(http.HttpRequest), + server.tenant_id, + admin=True).AndReturn(tenant) + self.mox.ReplayAll() + + url = reverse('horizon:syspanel:instances:index') + \ + "?action=row_update&table=instances&obj_id=" + server.id + + res = self.client.get(url, {}, + HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertTemplateUsed(res, "horizon/common/_data_table_row.html") + + self.assertContains(res, "test_tenant", 1, 200) + self.assertContains(res, "instance-host", 1, 200) + self.assertContains(res, "server_1", 1, 200) + self.assertContains(res, "10.0.0.1", 1, 200) + self.assertContains(res, "512MB RAM | 1 VCPU | 0 Disk", 1, 200) + self.assertContains(res, "Active", 1, 200) + self.assertContains(res, "Running", 1, 200) diff --git a/horizon/tests/test_data/nova_data.py b/horizon/tests/test_data/nova_data.py index 71b765e82..1ef48318b 100644 --- a/horizon/tests/test_data/nova_data.py +++ b/horizon/tests/test_data/nova_data.py @@ -27,6 +27,7 @@ SERVER_DATA = """ { "server": { "OS-EXT-SRV-ATTR:instance_name": "instance-00000005", + "OS-EXT-SRV-ATTR:host": "instance-host", "OS-EXT-STS:task_state": null, "addresses": { "private": [