From f9e18f725caae0e5c745a4a1a24d05a8a3df213d Mon Sep 17 00:00:00 2001 From: zhurong Date: Thu, 5 Jan 2017 20:33:47 +0800 Subject: [PATCH] Filter out the snapshot image type Create the snapshot will copy the image's metadata, so the snapshot image type will show in the Image table and configure application image field. This patch filter out the snapshot image type. Change-Id: I4a93b75730da9a0f3a9969687e684ee8dfeff815 Closes-Bug: #1650403 --- muranodashboard/dynamic_ui/fields.py | 3 +++ muranodashboard/images/forms.py | 7 +++++++ muranodashboard/tests/unit/images/test_forms.py | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/muranodashboard/dynamic_ui/fields.py b/muranodashboard/dynamic_ui/fields.py index 0347d5e69..6aa6f1f25 100644 --- a/muranodashboard/dynamic_ui/fields.py +++ b/muranodashboard/dynamic_ui/fields.py @@ -115,6 +115,9 @@ def get_murano_images(request): LOG.error("Error to request image list from glance ") exceptions.handle(request, _("Unable to retrieve public images.")) murano_images = [] + # filter out the snapshot image type + images = filter( + lambda x: x.properties.get("image_type", '') != 'snapshot', images) for image in images: murano_property = image.properties.get('murano_image_info') if murano_property: diff --git a/muranodashboard/images/forms.py b/muranodashboard/images/forms.py index e83a95273..5ca1bb278 100644 --- a/muranodashboard/images/forms.py +++ b/muranodashboard/images/forms.py @@ -27,6 +27,9 @@ LOG = logging.getLogger(__name__) def filter_murano_images(images, request=None): + # filter out the snapshot image type + images = filter( + lambda x: x.properties.get("image_type", '') != 'snapshot', images) marked_images = [] for image in images: metadata = image.properties.get('murano_image_info') @@ -92,6 +95,10 @@ class MarkImageForm(horizon_forms.SelfHandlingForm): images = filter( lambda x: x.container_format not in ('aki', 'ari'), images) + # filter out the snapshot image type + images = filter( + lambda x: x.properties.get("image_type", '') != 'snapshot', images) + self.fields['image'].choices = [(i.id, i.name) for i in images] self.fields['existing_titles'].initial = \ [image.title for image in filter_murano_images(images)] diff --git a/muranodashboard/tests/unit/images/test_forms.py b/muranodashboard/tests/unit/images/test_forms.py index fc287979f..9aac49a6c 100644 --- a/muranodashboard/tests/unit/images/test_forms.py +++ b/muranodashboard/tests/unit/images/test_forms.py @@ -40,6 +40,15 @@ class TestImagesForms(testtools.TestCase): images = [self.mock_img] self.assertEqual(images, forms.filter_murano_images(images)) + snapshot_meta = {'image_type': u'snapshot', + 'murano_image_info': '{"title": "title",\ + "type": "type"}'} + mock_snapshot_img = \ + mock.MagicMock(id=14, properties=snapshot_meta) + images = [mock_snapshot_img] + self.assertEqual([], + forms.filter_murano_images(images, self.mock_request)) + class TestMarkImageForm(testtools.TestCase): def setUp(self):