Merge "Use base.create_image_from_server to create server snapshot"
This commit is contained in:
commit
8e2f44f412
|
@ -295,20 +295,22 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
|
|||
@classmethod
|
||||
def create_image_from_server(cls, server_id, **kwargs):
|
||||
"""Wrapper utility that returns an image created from the server."""
|
||||
name = data_utils.rand_name(cls.__name__ + "-image")
|
||||
if 'name' in kwargs:
|
||||
name = kwargs.pop('name')
|
||||
name = kwargs.pop('name',
|
||||
data_utils.rand_name(cls.__name__ + "-image"))
|
||||
wait_until = kwargs.pop('wait_until', None)
|
||||
wait_for_server = kwargs.pop('wait_for_server', True)
|
||||
|
||||
image = cls.compute_images_client.create_image(server_id, name=name)
|
||||
image = cls.compute_images_client.create_image(server_id, name=name,
|
||||
**kwargs)
|
||||
image_id = data_utils.parse_image_id(image.response['location'])
|
||||
cls.images.append(image_id)
|
||||
|
||||
if 'wait_until' in kwargs:
|
||||
if wait_until is not None:
|
||||
try:
|
||||
waiters.wait_for_image_status(cls.compute_images_client,
|
||||
image_id, kwargs['wait_until'])
|
||||
image_id, wait_until)
|
||||
except lib_exc.NotFound:
|
||||
if kwargs['wait_until'].upper() == 'ACTIVE':
|
||||
if wait_until.upper() == 'ACTIVE':
|
||||
# If the image is not found after create_image returned
|
||||
# that means the snapshot failed in nova-compute and nova
|
||||
# deleted the image. There should be a compute fault
|
||||
|
@ -326,8 +328,8 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
|
|||
raise
|
||||
image = cls.compute_images_client.show_image(image_id)['image']
|
||||
|
||||
if kwargs['wait_until'] == 'ACTIVE':
|
||||
if kwargs.get('wait_for_server', True):
|
||||
if wait_until.upper() == 'ACTIVE':
|
||||
if wait_for_server:
|
||||
waiters.wait_for_server_status(cls.servers_client,
|
||||
server_id, 'ACTIVE')
|
||||
return image
|
||||
|
|
|
@ -54,7 +54,7 @@ class ImagesNegativeTestJSON(base.BaseV2ComputeTest):
|
|||
meta = {'image_type': 'test'}
|
||||
self.assertRaises(lib_exc.NotFound,
|
||||
self.create_image_from_server,
|
||||
server['id'], meta=meta)
|
||||
server['id'], metadata=meta)
|
||||
|
||||
@test.attr(type=['negative'])
|
||||
@decorators.idempotent_id('82c5b0c4-9dbd-463c-872b-20c4755aae7f')
|
||||
|
@ -63,7 +63,7 @@ class ImagesNegativeTestJSON(base.BaseV2ComputeTest):
|
|||
# Create a new image with invalid server id
|
||||
meta = {'image_type': 'test'}
|
||||
self.assertRaises(lib_exc.NotFound, self.create_image_from_server,
|
||||
data_utils.rand_name('invalid'), meta=meta)
|
||||
data_utils.rand_name('invalid'), metadata=meta)
|
||||
|
||||
@test.attr(type=['negative'])
|
||||
@decorators.idempotent_id('ec176029-73dc-4037-8d72-2e4ff60cf538')
|
||||
|
|
|
@ -14,10 +14,8 @@
|
|||
# under the License.
|
||||
|
||||
from tempest.api.compute import base
|
||||
from tempest.common import waiters
|
||||
from tempest import config
|
||||
from tempest.lib.common.utils import data_utils
|
||||
from tempest.lib.common.utils import test_utils
|
||||
from tempest.lib import decorators
|
||||
|
||||
CONF = config.CONF
|
||||
|
@ -53,15 +51,11 @@ class ImagesOneServerTestJSON(base.BaseV2ComputeTest):
|
|||
# Create a new image
|
||||
name = data_utils.rand_name('image')
|
||||
meta = {'image_type': 'test'}
|
||||
body = self.client.create_image(server_id, name=name,
|
||||
metadata=meta)
|
||||
image_id = data_utils.parse_image_id(body.response['location'])
|
||||
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
|
||||
self.client.delete_image, image_id)
|
||||
waiters.wait_for_image_status(self.client, image_id, 'ACTIVE')
|
||||
image = self.create_image_from_server(server_id, name=name,
|
||||
metadata=meta,
|
||||
wait_until='ACTIVE')
|
||||
|
||||
# Verify the image was created correctly
|
||||
image = self.client.show_image(image_id)['image']
|
||||
self.assertEqual(name, image['name'])
|
||||
self.assertEqual('test', image['metadata']['image_type'])
|
||||
|
||||
|
@ -76,8 +70,9 @@ class ImagesOneServerTestJSON(base.BaseV2ComputeTest):
|
|||
(str(original_image['minDisk']), str(flavor_disk_size)))
|
||||
|
||||
# Verify the image was deleted correctly
|
||||
self.client.delete_image(image_id)
|
||||
self.client.wait_for_resource_deletion(image_id)
|
||||
self.client.delete_image(image['id'])
|
||||
self.images.remove(image['id'])
|
||||
self.client.wait_for_resource_deletion(image['id'])
|
||||
|
||||
@decorators.idempotent_id('3b7c6fe4-dfe7-477c-9243-b06359db51e6')
|
||||
def test_create_image_specify_multibyte_character_image_name(self):
|
||||
|
|
|
@ -33,9 +33,6 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest):
|
|||
|
||||
def tearDown(self):
|
||||
"""Terminate test instances created after a test is executed."""
|
||||
for image_id in self.image_ids:
|
||||
self.client.delete_image(image_id)
|
||||
self.image_ids.remove(image_id)
|
||||
self.server_check_teardown()
|
||||
super(ImagesOneServerNegativeTestJSON, self).tearDown()
|
||||
|
||||
|
@ -80,25 +77,21 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest):
|
|||
server = cls.create_test_server(wait_until='ACTIVE')
|
||||
cls.server_id = server['id']
|
||||
|
||||
cls.image_ids = []
|
||||
|
||||
@test.attr(type=['negative'])
|
||||
@decorators.idempotent_id('55d1d38c-dd66-4933-9c8e-7d92aeb60ddc')
|
||||
def test_create_image_specify_invalid_metadata(self):
|
||||
# Return an error when creating image with invalid metadata
|
||||
snapshot_name = data_utils.rand_name('test-snap')
|
||||
meta = {'': ''}
|
||||
self.assertRaises(lib_exc.BadRequest, self.client.create_image,
|
||||
self.server_id, name=snapshot_name, metadata=meta)
|
||||
self.assertRaises(lib_exc.BadRequest, self.create_image_from_server,
|
||||
self.server_id, metadata=meta)
|
||||
|
||||
@test.attr(type=['negative'])
|
||||
@decorators.idempotent_id('3d24d11f-5366-4536-bd28-cff32b748eca')
|
||||
def test_create_image_specify_metadata_over_limits(self):
|
||||
# Return an error when creating image with meta data over 255 chars
|
||||
snapshot_name = data_utils.rand_name('test-snap')
|
||||
meta = {'a' * 256: 'b' * 256}
|
||||
self.assertRaises(lib_exc.BadRequest, self.client.create_image,
|
||||
self.server_id, name=snapshot_name, metadata=meta)
|
||||
self.assertRaises(lib_exc.BadRequest, self.create_image_from_server,
|
||||
self.server_id, metadata=meta)
|
||||
|
||||
@test.attr(type=['negative'])
|
||||
@decorators.idempotent_id('0460efcf-ee88-4f94-acef-1bf658695456')
|
||||
|
@ -106,16 +99,16 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest):
|
|||
# Disallow creating another image when first image is being saved
|
||||
|
||||
# Create first snapshot
|
||||
snapshot_name = data_utils.rand_name('test-snap')
|
||||
body = self.client.create_image(self.server_id, name=snapshot_name)
|
||||
image_id = data_utils.parse_image_id(body.response['location'])
|
||||
self.image_ids.append(image_id)
|
||||
image = self.create_image_from_server(self.server_id)
|
||||
self.addCleanup(self._reset_server)
|
||||
|
||||
# Create second snapshot
|
||||
alt_snapshot_name = data_utils.rand_name('test-snap')
|
||||
self.assertRaises(lib_exc.Conflict, self.client.create_image,
|
||||
self.server_id, name=alt_snapshot_name)
|
||||
self.assertRaises(lib_exc.Conflict, self.create_image_from_server,
|
||||
self.server_id)
|
||||
|
||||
image_id = data_utils.parse_image_id(image.response['location'])
|
||||
self.client.delete_image(image_id)
|
||||
self.images.remove(image_id)
|
||||
|
||||
@test.attr(type=['negative'])
|
||||
@decorators.idempotent_id('084f0cbc-500a-4963-8a4e-312905862581')
|
||||
|
@ -131,14 +124,13 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest):
|
|||
def test_delete_image_that_is_not_yet_active(self):
|
||||
# Return an error while trying to delete an image what is creating
|
||||
|
||||
snapshot_name = data_utils.rand_name('test-snap')
|
||||
body = self.client.create_image(self.server_id, name=snapshot_name)
|
||||
image_id = data_utils.parse_image_id(body.response['location'])
|
||||
self.image_ids.append(image_id)
|
||||
image = self.create_image_from_server(self.server_id)
|
||||
image_id = data_utils.parse_image_id(image.response['location'])
|
||||
|
||||
self.addCleanup(self._reset_server)
|
||||
|
||||
# Do not wait, attempt to delete the image, ensure it's successful
|
||||
self.client.delete_image(image_id)
|
||||
self.image_ids.remove(image_id)
|
||||
|
||||
self.assertRaises(lib_exc.NotFound, self.client.show_image, image_id)
|
||||
self.images.remove(image_id)
|
||||
self.assertRaises(lib_exc.NotFound,
|
||||
self.client.show_image, image_id)
|
||||
|
|
Loading…
Reference in New Issue