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
This commit is contained in:
zhurong 2017-01-05 20:33:47 +08:00
parent e96b4c98e2
commit f9e18f725c
3 changed files with 19 additions and 0 deletions

View File

@ -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:

View File

@ -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)]

View File

@ -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):