blob: 6156c5a556d53bbfa5f4653a4c44acee36668d5b [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
Attila Fazekas46a1d922013-01-11 10:19:42 +010016
Sean Dague1937d092013-05-17 16:36:38 -040017from tempest.api.compute import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090018from tempest.common.utils import data_utils
Sean Dague86bd8422013-12-20 09:56:44 -050019from tempest import config
Attila Fazekas4629a232013-10-16 17:20:45 +020020from tempest.openstack.common import log as logging
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
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010050 def resource_setup(cls):
51 super(ImagesOneServerTestJSON, cls).resource_setup()
Attila Fazekas19044d52013-02-16 07:35:06 +010052 cls.client = cls.images_client
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
Ghanshyame6aea8e2014-07-31 12:41:44 +090062 resp, server = cls.create_test_server(wait_until='ACTIVE')
63 cls.server_id = server['id']
Attila Fazekas19044d52013-02-16 07:35:06 +010064
Mate Lakatba417262013-07-05 18:03:11 +010065 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-zhued80f172014-02-10 12:50:59 +080069 @test.attr(type='smoke')
Attila Fazekas46a1d922013-01-11 10:19:42 +010070 def test_create_delete_image(self):
71
72 # Create a new image
Masayuki Igawa259c1132013-10-31 17:48:44 +090073 name = data_utils.rand_name('image')
Attila Fazekas46a1d922013-01-11 10:19:42 +010074 meta = {'image_type': 'test'}
David Kranza5299eb2015-01-15 17:24:05 -050075 body = self.client.create_image(self.server_id, name, meta)
76 image_id = data_utils.parse_image_id(body.response['location'])
Attila Fazekas46a1d922013-01-11 10:19:42 +010077 self.client.wait_for_image_status(image_id, 'ACTIVE')
78
79 # Verify the image was created correctly
David Kranza5299eb2015-01-15 17:24:05 -050080 image = self.client.get_image(image_id)
Attila Fazekas46a1d922013-01-11 10:19:42 +010081 self.assertEqual(name, image['name'])
82 self.assertEqual('test', image['metadata']['image_type'])
83
David Kranza5299eb2015-01-15 17:24:05 -050084 original_image = self.client.get_image(self.image_ref)
Mate Lakatba417262013-07-05 18:03:11 +010085
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 Fazekas46a1d922013-01-11 10:19:42 +010093
Prem Karat325ed282013-04-24 23:57:24 +053094 # Verify the image was deleted correctly
David Kranza5299eb2015-01-15 17:24:05 -050095 self.client.delete_image(image_id)
Matthew Treinish0d660492013-06-04 17:26:09 -040096 self.client.wait_for_resource_deletion(image_id)
Prem Karat325ed282013-04-24 23:57:24 +053097
ivan-zhued80f172014-02-10 12:50:59 +080098 @test.attr(type=['gate'])
Sean Dague7eb10772013-12-14 12:50:02 +000099 def test_create_image_specify_multibyte_character_image_name(self):
Sean Dague7eb10772013-12-14 12:50:02 +0000100 # prefix character is:
101 # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm
Chris Yeoh7a78cc82014-09-18 17:51:30 +0930102
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 Kranza5299eb2015-01-15 17:24:05 -0500107 body = self.client.create_image(self.server_id, utf8_name)
108 image_id = data_utils.parse_image_id(body.response['location'])
Sean Dague7eb10772013-12-14 12:50:02 +0000109 self.addCleanup(self.client.delete_image, image_id)