blob: 8ce443469229b79d4de955fe956019a4683eec08 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Soniya Vyasfaa16342020-01-15 19:34:57 +053015import testtools
16
Sean Dague1937d092013-05-17 16:36:38 -040017from tempest.api.compute import base
Joe H. Rahme66793a32015-10-09 18:36:26 +020018from tempest.common import waiters
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000019from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080020from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080021from tempest.lib import decorators
Soniya Vyasfaa16342020-01-15 19:34:57 +053022from tempest.lib import exceptions as lib_exceptions
Jay Pipes7f757632011-12-02 15:53:32 -050023
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000024CONF = config.CONF
25
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060026
ivan-zhuf2b00502013-10-18 10:06:52 +080027class ImagesTestJSON(base.BaseV2ComputeTest):
zhuflb5603bc2020-05-27 09:18:24 +080028 """Test server images"""
29
Ghanshyam Mann7d91b692020-03-03 10:21:50 -060030 create_default_network = True
Attila Fazekas19044d52013-02-16 07:35:06 +010031
32 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053033 def skip_checks(cls):
34 super(ImagesTestJSON, cls).skip_checks()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000035 if not CONF.service_available.glance:
Matthew Treinish853ae442013-07-19 16:36:07 -040036 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
37 raise cls.skipException(skip_msg)
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070038 if not CONF.compute_feature_enabled.snapshot:
39 skip_msg = ("%s skipped as instance snapshotting is not supported"
40 % cls.__name__)
41 raise cls.skipException(skip_msg)
42
Rohan Kanade60b73092015-02-04 17:58:19 +053043 @classmethod
44 def setup_clients(cls):
45 super(ImagesTestJSON, cls).setup_clients()
zhufl66275c22018-03-28 15:32:14 +080046 if cls.is_requested_microversion_compatible('2.35'):
47 cls.client = cls.compute_images_client
48 else:
49 cls.client = cls.images_client
Attila Fazekas19044d52013-02-16 07:35:06 +010050
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080051 @decorators.idempotent_id('aa06b52b-2db5-4807-b218-9441f75d74e3')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080052 def test_delete_saving_image(self):
zhuflb5603bc2020-05-27 09:18:24 +080053 """Test deleting server image while it is in 'SAVING' state"""
David Kranz0fb14292015-02-11 15:55:20 -050054 server = self.create_test_server(wait_until='ACTIVE')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080055 self.addCleanup(self.servers_client.delete_server, server['id'])
zhuflc3cd87a2019-08-06 11:26:57 +080056 # wait for server active to avoid conflict when deleting server
57 # in task_state image_snapshot
58 self.addCleanup(waiters.wait_for_server_status, self.servers_client,
59 server['id'], 'ACTIVE')
Martin Kopec213d0a42023-11-30 10:28:14 +010060 snapshot_name = data_utils.rand_name(
61 prefix=CONF.resource_name_prefix, name='test-snap')
Soniya Vyasfaa16342020-01-15 19:34:57 +053062 try:
63 image = self.create_image_from_server(server['id'],
64 name=snapshot_name,
65 wait_until='SAVING')
66 self.client.delete_image(image['id'])
67 msg = ('The image with ID {image_id} failed to be deleted'
68 .format(image_id=image['id']))
69 self.assertTrue(self.client.is_resource_deleted(image['id']),
70 msg)
71 self.assertEqual(snapshot_name, image['name'])
72 except lib_exceptions.TimeoutException as ex:
73 # If timeout is reached, we don't need to check state,
Rajesh Tailora85bdb42024-04-02 12:01:53 +053074 # since, it wouldn't be a 'SAVING' state at least and apart from
Soniya Vyasfaa16342020-01-15 19:34:57 +053075 # it, this testcase doesn't have scope for other state transition
76 # Hence, skip the test.
77 raise self.skipException("This test is skipped because " + str(ex))
Joe H. Rahme66793a32015-10-09 18:36:26 +020078
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080079 @decorators.idempotent_id('aaacd1d0-55a2-4ce8-818a-b5439df8adc9')
Joe H. Rahme66793a32015-10-09 18:36:26 +020080 def test_create_image_from_stopped_server(self):
zhuflb5603bc2020-05-27 09:18:24 +080081 """Test creating server image from stopped server"""
Joe H. Rahme66793a32015-10-09 18:36:26 +020082 server = self.create_test_server(wait_until='ACTIVE')
83 self.servers_client.stop_server(server['id'])
84 waiters.wait_for_server_status(self.servers_client,
85 server['id'], 'SHUTOFF')
86 self.addCleanup(self.servers_client.delete_server, server['id'])
Martin Kopec213d0a42023-11-30 10:28:14 +010087 snapshot_name = data_utils.rand_name(
88 prefix=CONF.resource_name_prefix, name='test-snap')
Joe H. Rahme66793a32015-10-09 18:36:26 +020089 image = self.create_image_from_server(server['id'],
90 name=snapshot_name,
Bob Ball5fe62392017-02-20 09:51:00 +000091 wait_until='ACTIVE',
92 wait_for_server=False)
Pranali Deore57183792024-08-30 08:32:44 +000093 # This is required due to ceph issue:
94 # https://bugs.launchpad.net/glance/+bug/2045769.
95 # New location APIs are async so we need to wait for the location
96 # import task to complete.
97 # This should work with old location API since we don't fail if there
98 # are no tasks for the image
99 waiters.wait_for_image_tasks_status(self.images_client,
100 image['id'], 'success')
Joe H. Rahme66793a32015-10-09 18:36:26 +0200101 self.addCleanup(self.client.delete_image, image['id'])
102 self.assertEqual(snapshot_name, image['name'])
lianghaoc0807862017-03-06 20:02:15 +0800103
104 @decorators.idempotent_id('71bcb732-0261-11e7-9086-fa163e4fa634')
Eric Berglunddde9de42017-03-22 15:19:48 -0500105 @testtools.skipUnless(CONF.compute_feature_enabled.pause,
106 'Pause is not available.')
lianghaoc0807862017-03-06 20:02:15 +0800107 def test_create_image_from_paused_server(self):
zhuflb5603bc2020-05-27 09:18:24 +0800108 """Test creating server image from paused server"""
lianghaoc0807862017-03-06 20:02:15 +0800109 server = self.create_test_server(wait_until='ACTIVE')
110 self.servers_client.pause_server(server['id'])
111 waiters.wait_for_server_status(self.servers_client,
112 server['id'], 'PAUSED')
113 self.addCleanup(self.servers_client.delete_server, server['id'])
114
Martin Kopec213d0a42023-11-30 10:28:14 +0100115 snapshot_name = data_utils.rand_name(
116 prefix=CONF.resource_name_prefix, name='test-snap')
lianghaoc0807862017-03-06 20:02:15 +0800117 image = self.create_image_from_server(server['id'],
118 name=snapshot_name,
119 wait_until='ACTIVE',
120 wait_for_server=False)
Pranali Deore57183792024-08-30 08:32:44 +0000121 # This is required due to ceph issue:
122 # https://bugs.launchpad.net/glance/+bug/2045769.
123 # New location APIs are async so we need to wait for the location
124 # import task to complete.
125 # This should work with old location API since we don't fail if there
126 # are no tasks for the image
127 waiters.wait_for_image_tasks_status(self.images_client,
128 image['id'], 'success')
lianghaoc0807862017-03-06 20:02:15 +0800129 self.addCleanup(self.client.delete_image, image['id'])
130 self.assertEqual(snapshot_name, image['name'])
131
132 @decorators.idempotent_id('8ca07fec-0262-11e7-907e-fa163e4fa634')
Eric Berglunddde9de42017-03-22 15:19:48 -0500133 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
134 'Suspend is not available.')
lianghaoc0807862017-03-06 20:02:15 +0800135 def test_create_image_from_suspended_server(self):
zhuflb5603bc2020-05-27 09:18:24 +0800136 """Test creating server image from suspended server"""
lianghaoc0807862017-03-06 20:02:15 +0800137 server = self.create_test_server(wait_until='ACTIVE')
138 self.servers_client.suspend_server(server['id'])
139 waiters.wait_for_server_status(self.servers_client,
140 server['id'], 'SUSPENDED')
141 self.addCleanup(self.servers_client.delete_server, server['id'])
142
Martin Kopec213d0a42023-11-30 10:28:14 +0100143 snapshot_name = data_utils.rand_name(
144 prefix=CONF.resource_name_prefix, name='test-snap')
lianghaoc0807862017-03-06 20:02:15 +0800145 image = self.create_image_from_server(server['id'],
146 name=snapshot_name,
147 wait_until='ACTIVE',
148 wait_for_server=False)
Pranali Deore57183792024-08-30 08:32:44 +0000149 # This is required due to ceph issue:
150 # https://bugs.launchpad.net/glance/+bug/2045769.
151 # New location APIs are async so we need to wait for the location
152 # import task to complete.
153 # This should work with old location API since we don't fail if there
154 # are no tasks for the image
155 waiters.wait_for_image_tasks_status(self.images_client,
156 image['id'], 'success')
lianghaoc0807862017-03-06 20:02:15 +0800157 self.addCleanup(self.client.delete_image, image['id'])
158 self.assertEqual(snapshot_name, image['name'])
Dan Smith6714b652022-10-05 15:05:31 -0700159
Pavlo Shchelokovskyyb86898a2023-11-21 11:16:39 +0000160 @testtools.skipIf(
161 CONF.compute_feature_enabled.barbican_integration_enabled,
162 "Not supported when barbican integration enabled.")
Dan Smith6714b652022-10-05 15:05:31 -0700163 @decorators.idempotent_id('f3cac456-e3fe-4183-a7a7-a59f7f017088')
164 def test_create_server_from_snapshot(self):
165 # Create one server normally
166 server = self.create_test_server(wait_until='ACTIVE')
167 self.addCleanup(self.servers_client.delete_server, server['id'])
168
169 # Snapshot it
Martin Kopec213d0a42023-11-30 10:28:14 +0100170 snapshot_name = data_utils.rand_name(
171 prefix=CONF.resource_name_prefix, name='test-snap')
Dan Smith6714b652022-10-05 15:05:31 -0700172 image = self.create_image_from_server(server['id'],
173 name=snapshot_name,
174 wait_until='ACTIVE',
175 wait_for_server=False)
176 self.addCleanup(self.client.delete_image, image['id'])
177
178 # Try to create another server from that snapshot
179 server2 = self.create_test_server(wait_until='ACTIVE',
180 image_id=image['id'])
181
182 # Delete server 2 before we finish otherwise we'll race with
183 # the cleanup which tries to delete the image before the
184 # server is gone.
185 self.servers_client.delete_server(server2['id'])
186 waiters.wait_for_server_termination(self.servers_client, server2['id'])