From 142c1a8a05e23c26e139dd1f42934dd516e4f025 Mon Sep 17 00:00:00 2001 From: Tihomir Trifonov Date: Wed, 23 May 2012 16:53:58 +0300 Subject: [PATCH] Ordering the attached volumes for an instance by device name instead of order by id Fixed bug 980332. Change-Id: Iad292ea01ce31f1ed07b1b48117ef64ea7207ac8 --- .../instances_and_volumes/instances/tests.py | 31 +++++++++++++++++++ .../instances_and_volumes/instances/views.py | 2 ++ 2 files changed, 33 insertions(+) diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/tests.py b/horizon/dashboards/nova/instances_and_volumes/instances/tests.py index 0e552e7d7..e34af39e0 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/tests.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/tests.py @@ -243,6 +243,37 @@ class InstanceViewTests(test.TestCase): res = self.client.post(INDEX_URL, formData) self.assertRedirectsNoFollow(res, INDEX_URL) + @test.create_stubs({api: ("server_get", "volume_instance_list", + "flavor_get", "server_security_groups")}) + def test_instance_details_volumes(self): + server = self.servers.first() + volumes = deepcopy(self.volumes.list()) + volumes[0].device = "/dev/hdk" + second_vol = deepcopy(volumes[0]) + second_vol.id = 2 + second_vol.device = "/dev/hdb" + volumes.append(second_vol) + + api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) + api.volume_instance_list(IsA(http.HttpRequest), + server.id).AndReturn(volumes) + api.flavor_get(IsA(http.HttpRequest), + server.flavor['id']).AndReturn(self.flavors.first()) + api.server_security_groups(IsA(http.HttpRequest), + server.id).AndReturn(self.security_groups.first()) + + self.mox.ReplayAll() + + url = reverse('horizon:nova:instances_and_volumes:instances:detail', + args=[server.id]) + res = self.client.get(url) + self.assertItemsEqual(res.context['instance'].volumes, volumes) + # Test device ordering + self.assertEquals(res.context['instance'].volumes[0].device, + "/dev/hdb") + self.assertEquals(res.context['instance'].volumes[1].device, + "/dev/hdk") + def test_instance_log(self): server = self.servers.first() CONSOLE_OUTPUT = 'output' diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/views.py b/horizon/dashboards/nova/instances_and_volumes/instances/views.py index e6c7ece5f..6dfa08f22 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/views.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/views.py @@ -118,6 +118,8 @@ class DetailView(tabs.TabView): instance = api.server_get(self.request, instance_id) instance.volumes = api.volume_instance_list(self.request, instance_id) + # Sort by device name + instance.volumes.sort(key=lambda vol: vol.device) instance.full_flavor = api.flavor_get(self.request, instance.flavor["id"]) instance.security_groups = api.server_security_groups(