blob: c0b67305f57aafa7c185f39f5a45dfb45372621b [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'}
Attila Fazekas4629a232013-10-16 17:20:45 +020075 resp, body = self.client.create_image(self.server_id, name, meta)
Attila Fazekas46a1d922013-01-11 10:19:42 +010076 self.assertEqual(202, resp.status)
Masayuki Igawa259c1132013-10-31 17:48:44 +090077 image_id = data_utils.parse_image_id(resp['location'])
Attila Fazekas46a1d922013-01-11 10:19:42 +010078 self.client.wait_for_image_status(image_id, 'ACTIVE')
79
80 # Verify the image was created correctly
81 resp, image = self.client.get_image(image_id)
82 self.assertEqual(name, image['name'])
83 self.assertEqual('test', image['metadata']['image_type'])
84
Attila Fazekas46a1d922013-01-11 10:19:42 +010085 resp, original_image = self.client.get_image(self.image_ref)
Mate Lakatba417262013-07-05 18:03:11 +010086
87 # Verify minRAM is the same as the original image
88 self.assertEqual(image['minRam'], original_image['minRam'])
89
90 # Verify minDisk is the same as the original image or the flavor size
91 flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref)
92 self.assertIn(str(image['minDisk']),
93 (str(original_image['minDisk']), str(flavor_disk_size)))
Attila Fazekas46a1d922013-01-11 10:19:42 +010094
Prem Karat325ed282013-04-24 23:57:24 +053095 # Verify the image was deleted correctly
96 resp, body = self.client.delete_image(image_id)
97 self.assertEqual('204', resp['status'])
Matthew Treinish0d660492013-06-04 17:26:09 -040098 self.client.wait_for_resource_deletion(image_id)
Prem Karat325ed282013-04-24 23:57:24 +053099
ivan-zhued80f172014-02-10 12:50:59 +0800100 @test.attr(type=['gate'])
Sean Dague7eb10772013-12-14 12:50:02 +0000101 def test_create_image_specify_multibyte_character_image_name(self):
102 if self.__class__._interface == "xml":
103 # NOTE(sdague): not entirely accurage, but we'd need a ton of work
104 # in our XML client to make this good
105 raise self.skipException("Not testable in XML")
106 # prefix character is:
107 # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm
108 utf8_name = data_utils.rand_name(u'\xF0\x9F\x92\xA9')
109 resp, body = self.client.create_image(self.server_id, utf8_name)
110 image_id = data_utils.parse_image_id(resp['location'])
111 self.addCleanup(self.client.delete_image, image_id)
112 self.assertEqual('202', resp['status'])
113
Attila Fazekas46a1d922013-01-11 10:19:42 +0100114
Attila Fazekas19044d52013-02-16 07:35:06 +0100115class ImagesOneServerTestXML(ImagesOneServerTestJSON):
116 _interface = 'xml'