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 | |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 16 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 17 | from tempest.api.compute import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 18 | from tempest.common.utils import data_utils |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 19 | from tempest import config |
Attila Fazekas | 4629a23 | 2013-10-16 17:20:45 +0200 | [diff] [blame] | 20 | from tempest.openstack.common import log as logging |
ivan-zhu | ed80f17 | 2014-02-10 12:50:59 +0800 | [diff] [blame] | 21 | from tempest import test |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 22 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 23 | CONF = config.CONF |
Attila Fazekas | 4629a23 | 2013-10-16 17:20:45 +0200 | [diff] [blame] | 24 | LOG = logging.getLogger(__name__) |
| 25 | |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 26 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 27 | class ImagesOneServerTestJSON(base.BaseV2ComputeTest): |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 28 | |
Attila Fazekas | 305e65b | 2013-10-29 13:23:07 +0100 | [diff] [blame] | 29 | def tearDown(self): |
| 30 | """Terminate test instances created after a test is executed.""" |
| 31 | self.server_check_teardown() |
| 32 | super(ImagesOneServerTestJSON, self).tearDown() |
| 33 | |
Attila Fazekas | 4629a23 | 2013-10-16 17:20:45 +0200 | [diff] [blame] | 34 | def setUp(self): |
| 35 | # NOTE(afazekas): Normally we use the same server with all test cases, |
| 36 | # but if it has an issue, we build a new one |
| 37 | super(ImagesOneServerTestJSON, self).setUp() |
| 38 | # Check if the server is in a clean state after test |
| 39 | try: |
Sreeram Yerrapragada | 62c1d9c | 2013-10-21 14:14:43 -0700 | [diff] [blame] | 40 | self.servers_client.wait_for_server_status(self.server_id, |
| 41 | 'ACTIVE') |
Yair Fried | a039f87 | 2014-01-02 12:11:10 +0200 | [diff] [blame] | 42 | except Exception: |
| 43 | LOG.exception('server %s timed out to become ACTIVE. rebuilding' |
| 44 | % self.server_id) |
Attila Fazekas | 4629a23 | 2013-10-16 17:20:45 +0200 | [diff] [blame] | 45 | # Rebuild server if cannot reach the ACTIVE state |
Yair Fried | a039f87 | 2014-01-02 12:11:10 +0200 | [diff] [blame] | 46 | # Usually it means the server had a serious accident |
Ken'ichi Ohmichi | 122cdf5 | 2013-12-11 21:32:25 +0900 | [diff] [blame] | 47 | self.__class__.server_id = self.rebuild_server(self.server_id) |
Attila Fazekas | 4629a23 | 2013-10-16 17:20:45 +0200 | [diff] [blame] | 48 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 49 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 50 | def resource_setup(cls): |
| 51 | super(ImagesOneServerTestJSON, cls).resource_setup() |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 52 | cls.client = cls.images_client |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 53 | if not CONF.service_available.glance: |
Matthew Treinish | 853ae44 | 2013-07-19 16:36:07 -0400 | [diff] [blame] | 54 | skip_msg = ("%s skipped as glance is not available" % cls.__name__) |
| 55 | raise cls.skipException(skip_msg) |
ivan-zhu | bf88a63 | 2013-03-26 13:29:21 +0800 | [diff] [blame] | 56 | |
Adam Gandelman | fbc95ac | 2014-06-19 17:33:43 -0700 | [diff] [blame] | 57 | if not CONF.compute_feature_enabled.snapshot: |
| 58 | skip_msg = ("%s skipped as instance snapshotting is not supported" |
| 59 | % cls.__name__) |
| 60 | raise cls.skipException(skip_msg) |
| 61 | |
Ghanshyam | e6aea8e | 2014-07-31 12:41:44 +0900 | [diff] [blame] | 62 | resp, server = cls.create_test_server(wait_until='ACTIVE') |
| 63 | cls.server_id = server['id'] |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 64 | |
Mate Lakat | ba41726 | 2013-07-05 18:03:11 +0100 | [diff] [blame] | 65 | def _get_default_flavor_disk_size(self, flavor_id): |
| 66 | resp, flavor = self.flavors_client.get_flavor_details(flavor_id) |
| 67 | return flavor['disk'] |
| 68 | |
ivan-zhu | ed80f17 | 2014-02-10 12:50:59 +0800 | [diff] [blame] | 69 | @test.attr(type='smoke') |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 70 | def test_create_delete_image(self): |
| 71 | |
| 72 | # Create a new image |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 73 | name = data_utils.rand_name('image') |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 74 | meta = {'image_type': 'test'} |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 75 | body = self.client.create_image(self.server_id, name, meta) |
| 76 | image_id = data_utils.parse_image_id(body.response['location']) |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 77 | self.client.wait_for_image_status(image_id, 'ACTIVE') |
| 78 | |
| 79 | # Verify the image was created correctly |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 80 | image = self.client.get_image(image_id) |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 81 | self.assertEqual(name, image['name']) |
| 82 | self.assertEqual('test', image['metadata']['image_type']) |
| 83 | |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 84 | original_image = self.client.get_image(self.image_ref) |
Mate Lakat | ba41726 | 2013-07-05 18:03:11 +0100 | [diff] [blame] | 85 | |
| 86 | # Verify minRAM is the same as the original image |
| 87 | self.assertEqual(image['minRam'], original_image['minRam']) |
| 88 | |
| 89 | # Verify minDisk is the same as the original image or the flavor size |
| 90 | flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref) |
| 91 | self.assertIn(str(image['minDisk']), |
| 92 | (str(original_image['minDisk']), str(flavor_disk_size))) |
Attila Fazekas | 46a1d92 | 2013-01-11 10:19:42 +0100 | [diff] [blame] | 93 | |
Prem Karat | 325ed28 | 2013-04-24 23:57:24 +0530 | [diff] [blame] | 94 | # Verify the image was deleted correctly |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 95 | self.client.delete_image(image_id) |
Matthew Treinish | 0d66049 | 2013-06-04 17:26:09 -0400 | [diff] [blame] | 96 | self.client.wait_for_resource_deletion(image_id) |
Prem Karat | 325ed28 | 2013-04-24 23:57:24 +0530 | [diff] [blame] | 97 | |
ivan-zhu | ed80f17 | 2014-02-10 12:50:59 +0800 | [diff] [blame] | 98 | @test.attr(type=['gate']) |
Sean Dague | 7eb1077 | 2013-12-14 12:50:02 +0000 | [diff] [blame] | 99 | def test_create_image_specify_multibyte_character_image_name(self): |
Sean Dague | 7eb1077 | 2013-12-14 12:50:02 +0000 | [diff] [blame] | 100 | # prefix character is: |
| 101 | # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm |
Chris Yeoh | 7a78cc8 | 2014-09-18 17:51:30 +0930 | [diff] [blame] | 102 | |
| 103 | # We use a string with 3 byte utf-8 character due to bug |
| 104 | # #1370954 in glance which will 500 if mysql is used as the |
| 105 | # backend and it attempts to store a 4 byte utf-8 character |
| 106 | utf8_name = data_utils.rand_name('\xe2\x82\xa1') |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 107 | body = self.client.create_image(self.server_id, utf8_name) |
| 108 | image_id = data_utils.parse_image_id(body.response['location']) |
Sean Dague | 7eb1077 | 2013-12-14 12:50:02 +0000 | [diff] [blame] | 109 | self.addCleanup(self.client.delete_image, image_id) |