Add compute image format test
This adds tests to make sure that nova rejects invalid image formats and also rejects any format when the disk_format does not match the image content. Change-Id: I29b1af0a4034decad3d6ec0191460c251a745300
This commit is contained in:
@@ -17,9 +17,11 @@ import os
|
||||
import testscenarios
|
||||
import yaml
|
||||
|
||||
from tempest.api.compute import base as compute_base
|
||||
from tempest.api.image import base
|
||||
from tempest.common import waiters
|
||||
from tempest import config
|
||||
from tempest import exceptions
|
||||
from tempest.lib.common.utils import data_utils
|
||||
from tempest.lib import decorators
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
@@ -42,7 +44,8 @@ def load_tests(loader, suite, pattern):
|
||||
return result
|
||||
|
||||
|
||||
class ImagesFormatTest(base.BaseV2ImageTest):
|
||||
class ImagesFormatTest(base.BaseV2ImageTest,
|
||||
compute_base.BaseV2ComputeTest):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
if CONF.image.images_manifest_file is None:
|
||||
@@ -141,3 +144,43 @@ class ImagesFormatTest(base.BaseV2ImageTest):
|
||||
waiters.wait_for_image_status(self.client, image['id'],
|
||||
'queued')
|
||||
self.client.delete_image(image['id'])
|
||||
|
||||
def _create_server_with_image_def(self, image_def, **overrides):
|
||||
image_def = dict(image_def, **overrides)
|
||||
image = self._test_image(image_def)
|
||||
server = self.create_test_server(name='server-%s' % image['name'],
|
||||
image_id=image['id'],
|
||||
wait_until='ACTIVE')
|
||||
return server
|
||||
|
||||
@decorators.idempotent_id('f77394bc-81f4-4d54-9f5b-e48f3d6b5376')
|
||||
def test_compute_rejects_invalid(self):
|
||||
"""Make sure compute rejects invalid/insecure images."""
|
||||
if self.imgdef['format'] not in CONF.image.disk_formats:
|
||||
# if this format is not allowed by glance, we can not create
|
||||
# a properly-formatted image for it, so skip it.
|
||||
self.skipTest(
|
||||
'Format %s not allowed by config' % self.imgdef['format'])
|
||||
|
||||
# VMDK with footer is not supported by anyone yet until fixed:
|
||||
# https://bugs.launchpad.net/glance/+bug/2073262
|
||||
is_broken = 'footer' in self.imgdef['name']
|
||||
|
||||
if self.imgdef['usable'] and not is_broken:
|
||||
server = self._create_server_with_image_def(self.imgdef)
|
||||
self.delete_server(server['id'])
|
||||
else:
|
||||
self.assertRaises(exceptions.BuildErrorException,
|
||||
self._create_server_with_image_def,
|
||||
self.imgdef)
|
||||
|
||||
@decorators.idempotent_id('ffe21610-e801-4992-9b81-e2d646e2e2e9')
|
||||
def test_compute_rejects_format_mismatch(self):
|
||||
"""Make sure compute rejects any image with a format mismatch."""
|
||||
# Lying about the disk_format should always fail
|
||||
override_fmt = (
|
||||
self.imgdef['format'] in ('raw', 'gpt') and 'qcow2' or 'raw')
|
||||
self.assertRaises(exceptions.BuildErrorException,
|
||||
self._create_server_with_image_def,
|
||||
self.imgdef,
|
||||
format=override_fmt)
|
||||
|
||||
Reference in New Issue
Block a user