blob: 1d26a00c8cef6e6f914a18bf096c21a69ddcde28 [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050017from tempest_lib.common.utils import data_utils
Attila Fazekas46a1d922013-01-11 10:19:42 +010018
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.compute import base
Sean Dague86bd8422013-12-20 09:56:44 -050020from tempest import config
ivan-zhued80f172014-02-10 12:50:59 +080021from tempest import test
Attila Fazekas46a1d922013-01-11 10:19:42 +010022
Sean Dague86bd8422013-12-20 09:56:44 -050023CONF = config.CONF
Attila Fazekas4629a232013-10-16 17:20:45 +020024LOG = logging.getLogger(__name__)
25
Attila Fazekas46a1d922013-01-11 10:19:42 +010026
ivan-zhuf2b00502013-10-18 10:06:52 +080027class ImagesOneServerTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010028
Attila Fazekas305e65b2013-10-29 13:23:07 +010029 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 Fazekas4629a232013-10-16 17:20:45 +020034 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 Yerrapragada62c1d9c2013-10-21 14:14:43 -070040 self.servers_client.wait_for_server_status(self.server_id,
41 'ACTIVE')
Yair Frieda039f872014-01-02 12:11:10 +020042 except Exception:
43 LOG.exception('server %s timed out to become ACTIVE. rebuilding'
44 % self.server_id)
Attila Fazekas4629a232013-10-16 17:20:45 +020045 # Rebuild server if cannot reach the ACTIVE state
Yair Frieda039f872014-01-02 12:11:10 +020046 # Usually it means the server had a serious accident
Ken'ichi Ohmichi122cdf52013-12-11 21:32:25 +090047 self.__class__.server_id = self.rebuild_server(self.server_id)
Attila Fazekas4629a232013-10-16 17:20:45 +020048
Attila Fazekas19044d52013-02-16 07:35:06 +010049 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053050 def skip_checks(cls):
51 super(ImagesOneServerTestJSON, cls).skip_checks()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000052 if not CONF.service_available.glance:
Matthew Treinish853ae442013-07-19 16:36:07 -040053 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
54 raise cls.skipException(skip_msg)
ivan-zhubf88a632013-03-26 13:29:21 +080055
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070056 if not CONF.compute_feature_enabled.snapshot:
57 skip_msg = ("%s skipped as instance snapshotting is not supported"
58 % cls.__name__)
59 raise cls.skipException(skip_msg)
60
Rohan Kanade60b73092015-02-04 17:58:19 +053061 @classmethod
62 def setup_clients(cls):
63 super(ImagesOneServerTestJSON, cls).setup_clients()
64 cls.client = cls.images_client
65
66 @classmethod
67 def resource_setup(cls):
68 super(ImagesOneServerTestJSON, cls).resource_setup()
David Kranz0fb14292015-02-11 15:55:20 -050069 server = cls.create_test_server(wait_until='ACTIVE')
Ghanshyame6aea8e2014-07-31 12:41:44 +090070 cls.server_id = server['id']
Attila Fazekas19044d52013-02-16 07:35:06 +010071
Mate Lakatba417262013-07-05 18:03:11 +010072 def _get_default_flavor_disk_size(self, flavor_id):
David Kranz2fa77b22015-02-09 11:39:50 -050073 flavor = self.flavors_client.get_flavor_details(flavor_id)
Mate Lakatba417262013-07-05 18:03:11 +010074 return flavor['disk']
75
ivan-zhued80f172014-02-10 12:50:59 +080076 @test.attr(type='smoke')
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'}
David Kranza5299eb2015-01-15 17:24:05 -050083 body = self.client.create_image(self.server_id, name, meta)
84 image_id = data_utils.parse_image_id(body.response['location'])
Attila Fazekas46a1d922013-01-11 10:19:42 +010085 self.client.wait_for_image_status(image_id, 'ACTIVE')
86
87 # Verify the image was created correctly
David Kranza5299eb2015-01-15 17:24:05 -050088 image = self.client.get_image(image_id)
Attila Fazekas46a1d922013-01-11 10:19:42 +010089 self.assertEqual(name, image['name'])
90 self.assertEqual('test', image['metadata']['image_type'])
91
David Kranza5299eb2015-01-15 17:24:05 -050092 original_image = self.client.get_image(self.image_ref)
Mate Lakatba417262013-07-05 18:03:11 +010093
94 # Verify minRAM is the same as the original image
95 self.assertEqual(image['minRam'], original_image['minRam'])
96
97 # Verify minDisk is the same as the original image or the flavor size
98 flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref)
99 self.assertIn(str(image['minDisk']),
100 (str(original_image['minDisk']), str(flavor_disk_size)))
Attila Fazekas46a1d922013-01-11 10:19:42 +0100101
Prem Karat325ed282013-04-24 23:57:24 +0530102 # Verify the image was deleted correctly
David Kranza5299eb2015-01-15 17:24:05 -0500103 self.client.delete_image(image_id)
Matthew Treinish0d660492013-06-04 17:26:09 -0400104 self.client.wait_for_resource_deletion(image_id)
Prem Karat325ed282013-04-24 23:57:24 +0530105
ivan-zhued80f172014-02-10 12:50:59 +0800106 @test.attr(type=['gate'])
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')
David Kranza5299eb2015-01-15 17:24:05 -0500116 body = self.client.create_image(self.server_id, utf8_name)
117 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)