ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 2 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 16 | from tempest.api.compute import base |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 17 | from tempest import config |
Ken'ichi Ohmichi | 757833a | 2017-03-10 10:30:30 -0800 | [diff] [blame] | 18 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 20 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 21 | CONF = config.CONF |
Attila Fazekas | 4629a23 | 2013-10-16 17:20:45 +0200 | [diff] [blame] | 22 | |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 23 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 24 | class ImagesOneServerTestJSON(base.BaseV2ComputeTest): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 25 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 26 | @classmethod |
zhufl | 4c79608 | 2017-04-28 12:16:17 +0800 | [diff] [blame] | 27 | 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 Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 32 | def skip_checks(cls): |
| 33 | super(ImagesOneServerTestJSON, cls).skip_checks() |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 34 | if not CONF.service_available.glance: |
Matthew Treinish | 853ae44 | 2013-07-19 16:36:07 -0400 | [diff] [blame] | 35 | skip_msg = ("%s skipped as glance is not available" % cls.__name__) |
| 36 | raise cls.skipException(skip_msg) |
ivan-zhu | bf88a63 | 2013-03-26 13:29:21 +0800 | [diff] [blame] | 37 | |
Adam Gandelman | fbc95ac | 2014-06-19 17:33:43 -0700 | [diff] [blame] | 38 | 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 Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 43 | @classmethod |
| 44 | def setup_clients(cls): |
| 45 | super(ImagesOneServerTestJSON, cls).setup_clients() |
Ghanshyam | ae76c12 | 2015-12-22 13:41:35 +0900 | [diff] [blame] | 46 | cls.client = cls.compute_images_client |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 47 | |
Mate Lakat | ba41726 | 2013-07-05 18:03:11 +0100 | [diff] [blame] | 48 | def _get_default_flavor_disk_size(self, flavor_id): |
ghanshyam | 19973be | 2015-08-18 15:46:42 +0900 | [diff] [blame] | 49 | flavor = self.flavors_client.show_flavor(flavor_id)['flavor'] |
Mate Lakat | ba41726 | 2013-07-05 18:03:11 +0100 | [diff] [blame] | 50 | return flavor['disk'] |
| 51 | |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 52 | @decorators.idempotent_id('3731d080-d4c5-4872-b41a-64d0d0021314') |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 53 | def test_create_delete_image(self): |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 54 | # Create a new image |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 55 | name = data_utils.rand_name('image') |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 56 | meta = {'image_type': 'test'} |
zhufl | 4c79608 | 2017-04-28 12:16:17 +0800 | [diff] [blame] | 57 | image = self.create_image_from_server(self.server_id, name=name, |
zhufl | 35a694b | 2017-02-14 17:10:53 +0800 | [diff] [blame] | 58 | metadata=meta, |
| 59 | wait_until='ACTIVE') |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 60 | |
| 61 | # Verify the image was created correctly |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 62 | self.assertEqual(name, image['name']) |
| 63 | self.assertEqual('test', image['metadata']['image_type']) |
| 64 | |
ghanshyam | 1756e0b | 2015-08-18 19:19:05 +0900 | [diff] [blame] | 65 | original_image = self.client.show_image(self.image_ref)['image'] |
Mate Lakat | ba41726 | 2013-07-05 18:03:11 +0100 | [diff] [blame] | 66 | |
| 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 Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 74 | |
Prem Karat | 325ed28 | 2013-04-24 23:57:24 +0530 | [diff] [blame] | 75 | # Verify the image was deleted correctly |
zhufl | 35a694b | 2017-02-14 17:10:53 +0800 | [diff] [blame] | 76 | self.client.delete_image(image['id']) |
zhufl | 35a694b | 2017-02-14 17:10:53 +0800 | [diff] [blame] | 77 | self.client.wait_for_resource_deletion(image['id']) |
Prem Karat | 325ed28 | 2013-04-24 23:57:24 +0530 | [diff] [blame] | 78 | |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 79 | @decorators.idempotent_id('3b7c6fe4-dfe7-477c-9243-b06359db51e6') |
Sean Dague | 7eb1077 | 2013-12-14 12:50:02 +0000 | [diff] [blame] | 80 | def test_create_image_specify_multibyte_character_image_name(self): |
Sean Dague | 7eb1077 | 2013-12-14 12:50:02 +0000 | [diff] [blame] | 81 | # prefix character is: |
Masayuki Igawa | 00c4487 | 2017-05-02 17:48:00 +0900 | [diff] [blame] | 82 | # http://unicode.org/cldr/utility/character.jsp?a=20A1 |
Chris Yeoh | 7a78cc8 | 2014-09-18 17:51:30 +0930 | [diff] [blame] | 83 | |
Masayuki Igawa | 00c4487 | 2017-05-02 17:48:00 +0900 | [diff] [blame] | 84 | # 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 Srinivas | 816607c | 2017-01-17 16:01:31 -0500 | [diff] [blame] | 87 | utf8_name = data_utils.rand_name(b'\xe2\x82\xa1'.decode('utf-8')) |
zhufl | 4c79608 | 2017-04-28 12:16:17 +0800 | [diff] [blame] | 88 | body = self.client.create_image(self.server_id, name=utf8_name) |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 89 | image_id = data_utils.parse_image_id(body.response['location']) |
Sean Dague | 7eb1077 | 2013-12-14 12:50:02 +0000 | [diff] [blame] | 90 | self.addCleanup(self.client.delete_image, image_id) |