blob: e62e25e9bf625d94f24eee741d8078d4cfdbe7d0 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Attila Fazekas46a1d922013-01-11 10:19:42 +01002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.compute import base
Sean Dague86bd8422013-12-20 09:56:44 -050017from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080018from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080019from tempest.lib import decorators
Attila Fazekas46a1d922013-01-11 10:19:42 +010020
Sean Dague86bd8422013-12-20 09:56:44 -050021CONF = config.CONF
Attila Fazekas4629a232013-10-16 17:20:45 +020022
Attila Fazekas46a1d922013-01-11 10:19:42 +010023
ivan-zhuf2b00502013-10-18 10:06:52 +080024class ImagesOneServerTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010025
Attila Fazekas19044d52013-02-16 07:35:06 +010026 @classmethod
zhufl4c796082017-04-28 12:16:17 +080027 def resource_setup(cls):
28 super(ImagesOneServerTestJSON, cls).resource_setup()
29 cls.server_id = cls.create_test_server(wait_until='ACTIVE')['id']
30
31 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053032 def skip_checks(cls):
33 super(ImagesOneServerTestJSON, cls).skip_checks()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000034 if not CONF.service_available.glance:
Matthew Treinish853ae442013-07-19 16:36:07 -040035 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
36 raise cls.skipException(skip_msg)
ivan-zhubf88a632013-03-26 13:29:21 +080037
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070038 if not CONF.compute_feature_enabled.snapshot:
39 skip_msg = ("%s skipped as instance snapshotting is not supported"
40 % cls.__name__)
41 raise cls.skipException(skip_msg)
42
Rohan Kanade60b73092015-02-04 17:58:19 +053043 @classmethod
44 def setup_clients(cls):
45 super(ImagesOneServerTestJSON, cls).setup_clients()
Ghanshyamae76c122015-12-22 13:41:35 +090046 cls.client = cls.compute_images_client
Rohan Kanade60b73092015-02-04 17:58:19 +053047
Mate Lakatba417262013-07-05 18:03:11 +010048 def _get_default_flavor_disk_size(self, flavor_id):
ghanshyam19973be2015-08-18 15:46:42 +090049 flavor = self.flavors_client.show_flavor(flavor_id)['flavor']
Mate Lakatba417262013-07-05 18:03:11 +010050 return flavor['disk']
51
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080052 @decorators.idempotent_id('3731d080-d4c5-4872-b41a-64d0d0021314')
Attila Fazekas46a1d922013-01-11 10:19:42 +010053 def test_create_delete_image(self):
Attila Fazekas46a1d922013-01-11 10:19:42 +010054 # Create a new image
Masayuki Igawa259c1132013-10-31 17:48:44 +090055 name = data_utils.rand_name('image')
Attila Fazekas46a1d922013-01-11 10:19:42 +010056 meta = {'image_type': 'test'}
zhufl4c796082017-04-28 12:16:17 +080057 image = self.create_image_from_server(self.server_id, name=name,
zhufl35a694b2017-02-14 17:10:53 +080058 metadata=meta,
59 wait_until='ACTIVE')
Attila Fazekas46a1d922013-01-11 10:19:42 +010060
61 # Verify the image was created correctly
Attila Fazekas46a1d922013-01-11 10:19:42 +010062 self.assertEqual(name, image['name'])
63 self.assertEqual('test', image['metadata']['image_type'])
64
ghanshyam1756e0b2015-08-18 19:19:05 +090065 original_image = self.client.show_image(self.image_ref)['image']
Mate Lakatba417262013-07-05 18:03:11 +010066
67 # Verify minRAM is the same as the original image
68 self.assertEqual(image['minRam'], original_image['minRam'])
69
70 # Verify minDisk is the same as the original image or the flavor size
71 flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref)
72 self.assertIn(str(image['minDisk']),
73 (str(original_image['minDisk']), str(flavor_disk_size)))
Attila Fazekas46a1d922013-01-11 10:19:42 +010074
Prem Karat325ed282013-04-24 23:57:24 +053075 # Verify the image was deleted correctly
zhufl35a694b2017-02-14 17:10:53 +080076 self.client.delete_image(image['id'])
zhufl35a694b2017-02-14 17:10:53 +080077 self.client.wait_for_resource_deletion(image['id'])
Prem Karat325ed282013-04-24 23:57:24 +053078
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080079 @decorators.idempotent_id('3b7c6fe4-dfe7-477c-9243-b06359db51e6')
Sean Dague7eb10772013-12-14 12:50:02 +000080 def test_create_image_specify_multibyte_character_image_name(self):
Sean Dague7eb10772013-12-14 12:50:02 +000081 # prefix character is:
Masayuki Igawa00c44872017-05-02 17:48:00 +090082 # http://unicode.org/cldr/utility/character.jsp?a=20A1
Chris Yeoh7a78cc82014-09-18 17:51:30 +093083
Masayuki Igawa00c44872017-05-02 17:48:00 +090084 # We use a string with 3 byte utf-8 character due to nova/glance which
85 # will return 400(Bad Request) if we attempt to send a name which has
86 # 4 byte utf-8 character.
Davanum Srinivas816607c2017-01-17 16:01:31 -050087 utf8_name = data_utils.rand_name(b'\xe2\x82\xa1'.decode('utf-8'))
zhufl4c796082017-04-28 12:16:17 +080088 body = self.client.create_image(self.server_id, name=utf8_name)
David Kranza5299eb2015-01-15 17:24:05 -050089 image_id = data_utils.parse_image_id(body.response['location'])
Sean Dague7eb10772013-12-14 12:50:02 +000090 self.addCleanup(self.client.delete_image, image_id)