diff --git a/openstack_dashboard/dashboards/admin/hypervisors/tables.py b/openstack_dashboard/dashboards/admin/hypervisors/tables.py index 28991021a5..ca99f46221 100644 --- a/openstack_dashboard/dashboards/admin/hypervisors/tables.py +++ b/openstack_dashboard/dashboards/admin/hypervisors/tables.py @@ -57,7 +57,8 @@ class AdminHypervisorsTable(tables.DataTable): verbose_name=_("Instances")) def get_object_id(self, hypervisor): - return hypervisor.hypervisor_hostname + return "%s_%s" % (hypervisor.id, + hypervisor.hypervisor_hostname) class Meta(object): name = "hypervisors" diff --git a/openstack_dashboard/dashboards/admin/hypervisors/tests.py b/openstack_dashboard/dashboards/admin/hypervisors/tests.py index 7553494e24..b03aa3af68 100644 --- a/openstack_dashboard/dashboards/admin/hypervisors/tests.py +++ b/openstack_dashboard/dashboards/admin/hypervisors/tests.py @@ -88,12 +88,17 @@ class HypervisorViewTest(test.BaseAdminViewTests): class HypervisorDetailViewTest(test.BaseAdminViewTests): @test.create_stubs({api.nova: ('hypervisor_search',)}) def test_index(self): - hypervisor = self.hypervisors.list().pop().hypervisor_hostname + hypervisor = self.hypervisors.first() api.nova.hypervisor_search( - IsA(http.HttpRequest), hypervisor).AndReturn([]) + IsA(http.HttpRequest), + hypervisor.hypervisor_hostname).AndReturn([ + hypervisor, + self.hypervisors.list()[1]]) self.mox.ReplayAll() - url = reverse('horizon:admin:hypervisors:detail', args=[hypervisor]) + url = reverse('horizon:admin:hypervisors:detail', + args=["%s_%s" % (hypervisor.id, + hypervisor.hypervisor_hostname)]) res = self.client.get(url) self.assertTemplateUsed(res, 'admin/hypervisors/detail.html') - self.assertItemsEqual(res.context['table'].data, []) + self.assertItemsEqual(res.context['table'].data, hypervisor.servers) diff --git a/openstack_dashboard/dashboards/admin/hypervisors/views.py b/openstack_dashboard/dashboards/admin/hypervisors/views.py index 07f6da6007..ff10e90855 100644 --- a/openstack_dashboard/dashboards/admin/hypervisors/views.py +++ b/openstack_dashboard/dashboards/admin/hypervisors/views.py @@ -61,13 +61,15 @@ class AdminDetailView(tables.DataTableView): def get_data(self): instances = [] try: + id, name = self.kwargs['hypervisor'].split('_', 1) result = api.nova.hypervisor_search(self.request, - self.kwargs['hypervisor']) + name) for hypervisor in result: - try: - instances += hypervisor.servers - except AttributeError: - pass + if str(hypervisor.id) == id: + try: + instances += hypervisor.servers + except AttributeError: + pass except Exception: exceptions.handle( self.request, diff --git a/openstack_dashboard/test/test_data/nova_data.py b/openstack_dashboard/test/test_data/nova_data.py index 53f46d9026..2861292b3b 100644 --- a/openstack_dashboard/test/test_data/nova_data.py +++ b/openstack_dashboard/test/test_data/nova_data.py @@ -634,7 +634,7 @@ def data(TEST): "vcpus_used": 1, "hypervisor_type": "QEMU", "local_gb_used": 20, - "hypervisor_hostname": "devstack002", + "hypervisor_hostname": "devstack001", "memory_mb_used": 1500, "memory_mb": 2000, "current_workload": 0, @@ -650,6 +650,7 @@ def data(TEST): "local_gb": 29, "free_ram_mb": 500, "id": 2, + "servers": [{"name": "test_name_2", "uuid": "test_uuid_2"}] }, ) hypervisor_3 = hypervisors.Hypervisor(