From 6dbf9f1b5488247002acda0bc64a7c581957cea6 Mon Sep 17 00:00:00 2001 From: Kelsey Tripp Date: Wed, 22 Aug 2012 11:57:16 -0700 Subject: [PATCH] Makes Launch Instance only show images that are "active" Fixes launchpad Bug #1040231 Change-Id: I3b9d760cf694f12be97998dd94debbd7b55d5ab8 --- horizon/dashboards/nova/instances/tests.py | 36 ++++++++++++------- .../dashboards/nova/instances/workflows.py | 8 +++-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/horizon/dashboards/nova/instances/tests.py b/horizon/dashboards/nova/instances/tests.py index 5cea20990..c248b51bf 100644 --- a/horizon/dashboards/nova/instances/tests.py +++ b/horizon/dashboards/nova/instances/tests.py @@ -600,10 +600,12 @@ class InstanceTests(test.TestCase): api.nova.volume_snapshot_list(IsA(http.HttpRequest)) \ .AndReturn(self.volumes.list()) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'is_public': True}) \ + filters={'is_public': True, + 'status': 'active'}) \ .AndReturn([self.images.list(), False]) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'property-owner_id': self.tenant.id}) \ + filters={'property-owner_id': self.tenant.id, + 'status': 'active'}) \ .AndReturn([[], False]) api.quantum.network_list(IsA(http.HttpRequest), tenant_id=self.tenant.id) \ @@ -668,10 +670,12 @@ class InstanceTests(test.TestCase): api.nova.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'is_public': True}) \ + filters={'is_public': True, + 'status': 'active'}) \ .AndReturn([self.images.list(), False]) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'property-owner_id': self.tenant.id}) \ + filters={'property-owner_id': self.tenant.id, + 'status': 'active'}) \ .AndReturn([[], False]) api.quantum.network_list(IsA(http.HttpRequest), tenant_id=self.tenant.id) \ @@ -735,10 +739,12 @@ class InstanceTests(test.TestCase): .AndReturn(self.flavors.list()) api.nova.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn({}) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'is_public': True}) \ + filters={'is_public': True, + 'status': 'active'}) \ .AndReturn([[], False]) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'property-owner_id': self.tenant.id}) \ + filters={'property-owner_id': self.tenant.id, + 'status': 'active'}) \ .AndReturn([[], False]) api.quantum.network_list(IsA(http.HttpRequest), tenant_id=self.tenant.id) \ @@ -791,10 +797,12 @@ class InstanceTests(test.TestCase): api.nova.volume_snapshot_list(IsA(http.HttpRequest)) \ .AndReturn(self.volumes.list()) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'is_public': True}) \ + filters={'is_public': True, + 'status': 'active'}) \ .AndReturn([self.images.list(), False]) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'property-owner_id': self.tenant.id}) \ + filters={'property-owner_id': self.tenant.id, + 'status': 'active'}) \ .AndReturn([[], False]) api.quantum.network_list(IsA(http.HttpRequest), tenant_id=self.tenant.id) \ @@ -842,10 +850,12 @@ class InstanceTests(test.TestCase): api.nova.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'is_public': True}) \ + filters={'is_public': True, + 'status': 'active'}) \ .AndReturn([self.images.list(), False]) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'property-owner_id': self.tenant.id}) \ + filters={'property-owner_id': self.tenant.id, + 'status': 'active'}) \ .AndReturn([[], False]) api.quantum.network_list(IsA(http.HttpRequest), tenant_id=self.tenant.id) \ @@ -908,10 +918,12 @@ class InstanceTests(test.TestCase): api.nova.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'is_public': True}) \ + filters={'is_public': True, + 'status': 'active'}) \ .AndReturn([self.images.list(), False]) api.glance.image_list_detailed(IsA(http.HttpRequest), - filters={'property-owner_id': self.tenant.id}) \ + filters={'property-owner_id': self.tenant.id, + 'status': 'active'}) \ .AndReturn([[], False]) api.quantum.network_list(IsA(http.HttpRequest), tenant_id=self.tenant.id) \ diff --git a/horizon/dashboards/nova/instances/workflows.py b/horizon/dashboards/nova/instances/workflows.py index 3453680e7..09308f774 100644 --- a/horizon/dashboards/nova/instances/workflows.py +++ b/horizon/dashboards/nova/instances/workflows.py @@ -217,7 +217,8 @@ class SetInstanceDetailsAction(workflows.Action): def _get_available_images(self, request, context): project_id = context.get('project_id', None) if not hasattr(self, "_public_images"): - public = {"is_public": True} + public = {"is_public": True, + "status": "active"} try: public_images, _more = api.glance.image_list_detailed(request, filters=public) @@ -232,7 +233,8 @@ class SetInstanceDetailsAction(workflows.Action): setattr(self, "_images_for_%s" % project_id, []) if not hasattr(self, "_images_for_%s" % project_id): - owner = {"property-owner_id": project_id} + owner = {"property-owner_id": project_id, + "status": "active"} try: owned_images, _more = api.glance.image_list_detailed(request, filters=owner) @@ -245,7 +247,7 @@ class SetInstanceDetailsAction(workflows.Action): owned_images = getattr(self, "_images_for_%s" % project_id) images = owned_images + self._public_images - # Remove duplicate images. + # Remove duplicate images image_ids = [] final_images = [] for image in images: