blob: 7b978ab12966f5afd281764ead3499947a66c939 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
Attila Fazekas46a1d922013-01-11 10:19:42 +010017
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Ken'ichi Ohmichi8b9c7802015-07-08 05:57:37 +000020from tempest.common import waiters
Sean Dague86bd8422013-12-20 09:56:44 -050021from tempest import config
ivan-zhued80f172014-02-10 12:50:59 +080022from tempest import test
Attila Fazekas46a1d922013-01-11 10:19:42 +010023
Sean Dague86bd8422013-12-20 09:56:44 -050024CONF = config.CONF
Attila Fazekas4629a232013-10-16 17:20:45 +020025LOG = logging.getLogger(__name__)
26
Attila Fazekas46a1d922013-01-11 10:19:42 +010027
ivan-zhuf2b00502013-10-18 10:06:52 +080028class ImagesOneServerTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010029
Attila Fazekas305e65b2013-10-29 13:23:07 +010030 def tearDown(self):
31 """Terminate test instances created after a test is executed."""
32 self.server_check_teardown()
33 super(ImagesOneServerTestJSON, self).tearDown()
34
Attila Fazekas4629a232013-10-16 17:20:45 +020035 def setUp(self):
36 # NOTE(afazekas): Normally we use the same server with all test cases,
37 # but if it has an issue, we build a new one
38 super(ImagesOneServerTestJSON, self).setUp()
39 # Check if the server is in a clean state after test
40 try:
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000041 waiters.wait_for_server_status(self.servers_client,
42 self.server_id, 'ACTIVE')
Yair Frieda039f872014-01-02 12:11:10 +020043 except Exception:
44 LOG.exception('server %s timed out to become ACTIVE. rebuilding'
45 % self.server_id)
Attila Fazekas4629a232013-10-16 17:20:45 +020046 # Rebuild server if cannot reach the ACTIVE state
Yair Frieda039f872014-01-02 12:11:10 +020047 # Usually it means the server had a serious accident
Ken'ichi Ohmichi122cdf52013-12-11 21:32:25 +090048 self.__class__.server_id = self.rebuild_server(self.server_id)
Attila Fazekas4629a232013-10-16 17:20:45 +020049
Attila Fazekas19044d52013-02-16 07:35:06 +010050 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053051 def skip_checks(cls):
52 super(ImagesOneServerTestJSON, cls).skip_checks()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000053 if not CONF.service_available.glance:
Matthew Treinish853ae442013-07-19 16:36:07 -040054 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
55 raise cls.skipException(skip_msg)
ivan-zhubf88a632013-03-26 13:29:21 +080056
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070057 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
Rohan Kanade60b73092015-02-04 17:58:19 +053062 @classmethod
63 def setup_clients(cls):
64 super(ImagesOneServerTestJSON, cls).setup_clients()
Ghanshyamae76c122015-12-22 13:41:35 +090065 cls.client = cls.compute_images_client
Rohan Kanade60b73092015-02-04 17:58:19 +053066
67 @classmethod
68 def resource_setup(cls):
69 super(ImagesOneServerTestJSON, cls).resource_setup()
David Kranz0fb14292015-02-11 15:55:20 -050070 server = cls.create_test_server(wait_until='ACTIVE')
Ghanshyame6aea8e2014-07-31 12:41:44 +090071 cls.server_id = server['id']
Attila Fazekas19044d52013-02-16 07:35:06 +010072
Mate Lakatba417262013-07-05 18:03:11 +010073 def _get_default_flavor_disk_size(self, flavor_id):
ghanshyam19973be2015-08-18 15:46:42 +090074 flavor = self.flavors_client.show_flavor(flavor_id)['flavor']
Mate Lakatba417262013-07-05 18:03:11 +010075 return flavor['disk']
76
Chris Hoge7579c1a2015-02-26 14:12:15 -080077 @test.idempotent_id('3731d080-d4c5-4872-b41a-64d0d0021314')
Attila Fazekas46a1d922013-01-11 10:19:42 +010078 def test_create_delete_image(self):
79
80 # Create a new image
Masayuki Igawa259c1132013-10-31 17:48:44 +090081 name = data_utils.rand_name('image')
Attila Fazekas46a1d922013-01-11 10:19:42 +010082 meta = {'image_type': 'test'}
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +000083 body = self.client.create_image(self.server_id, name=name,
84 metadata=meta)
David Kranza5299eb2015-01-15 17:24:05 -050085 image_id = data_utils.parse_image_id(body.response['location'])
Ken'ichi Ohmichi8b9c7802015-07-08 05:57:37 +000086 waiters.wait_for_image_status(self.client, image_id, 'ACTIVE')
Attila Fazekas46a1d922013-01-11 10:19:42 +010087
88 # Verify the image was created correctly
ghanshyam1756e0b2015-08-18 19:19:05 +090089 image = self.client.show_image(image_id)['image']
Attila Fazekas46a1d922013-01-11 10:19:42 +010090 self.assertEqual(name, image['name'])
91 self.assertEqual('test', image['metadata']['image_type'])
92
ghanshyam1756e0b2015-08-18 19:19:05 +090093 original_image = self.client.show_image(self.image_ref)['image']
Mate Lakatba417262013-07-05 18:03:11 +010094
95 # Verify minRAM is the same as the original image
96 self.assertEqual(image['minRam'], original_image['minRam'])
97
98 # Verify minDisk is the same as the original image or the flavor size
99 flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref)
100 self.assertIn(str(image['minDisk']),
101 (str(original_image['minDisk']), str(flavor_disk_size)))
Attila Fazekas46a1d922013-01-11 10:19:42 +0100102
Prem Karat325ed282013-04-24 23:57:24 +0530103 # Verify the image was deleted correctly
David Kranza5299eb2015-01-15 17:24:05 -0500104 self.client.delete_image(image_id)
Matthew Treinish0d660492013-06-04 17:26:09 -0400105 self.client.wait_for_resource_deletion(image_id)
Prem Karat325ed282013-04-24 23:57:24 +0530106
Chris Hoge7579c1a2015-02-26 14:12:15 -0800107 @test.idempotent_id('3b7c6fe4-dfe7-477c-9243-b06359db51e6')
Sean Dague7eb10772013-12-14 12:50:02 +0000108 def test_create_image_specify_multibyte_character_image_name(self):
Sean Dague7eb10772013-12-14 12:50:02 +0000109 # prefix character is:
110 # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm
Chris Yeoh7a78cc82014-09-18 17:51:30 +0930111
112 # We use a string with 3 byte utf-8 character due to bug
113 # #1370954 in glance which will 500 if mysql is used as the
114 # backend and it attempts to store a 4 byte utf-8 character
115 utf8_name = data_utils.rand_name('\xe2\x82\xa1')
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +0000116 body = self.client.create_image(self.server_id, name=utf8_name)
David Kranza5299eb2015-01-15 17:24:05 -0500117 image_id = data_utils.parse_image_id(body.response['location'])
Sean Dague7eb10772013-12-14 12:50:02 +0000118 self.addCleanup(self.client.delete_image, image_id)