blob: ef336851a139f1a7ff10e71cc091f3abadbdf13c [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):
Ghanshyam Mann7d91b692020-03-03 10:21:50 -060028 create_default_network = True
Attila Fazekas19044d52013-02-16 07:35:06 +010029
30 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053031 def skip_checks(cls):
32 super(ImagesTestJSON, cls).skip_checks()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000033 if not CONF.service_available.glance:
Matthew Treinish853ae442013-07-19 16:36:07 -040034 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
35 raise cls.skipException(skip_msg)
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070036 if not CONF.compute_feature_enabled.snapshot:
37 skip_msg = ("%s skipped as instance snapshotting is not supported"
38 % cls.__name__)
39 raise cls.skipException(skip_msg)
40
Rohan Kanade60b73092015-02-04 17:58:19 +053041 @classmethod
42 def setup_clients(cls):
43 super(ImagesTestJSON, cls).setup_clients()
zhufl66275c22018-03-28 15:32:14 +080044 if cls.is_requested_microversion_compatible('2.35'):
45 cls.client = cls.compute_images_client
46 else:
47 cls.client = cls.images_client
Attila Fazekas19044d52013-02-16 07:35:06 +010048
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080049 @decorators.idempotent_id('aa06b52b-2db5-4807-b218-9441f75d74e3')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080050 def test_delete_saving_image(self):
David Kranz0fb14292015-02-11 15:55:20 -050051 server = self.create_test_server(wait_until='ACTIVE')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080052 self.addCleanup(self.servers_client.delete_server, server['id'])
zhuflc3cd87a2019-08-06 11:26:57 +080053 # wait for server active to avoid conflict when deleting server
54 # in task_state image_snapshot
55 self.addCleanup(waiters.wait_for_server_status, self.servers_client,
56 server['id'], 'ACTIVE')
Soniya Vyasfaa16342020-01-15 19:34:57 +053057 snapshot_name = data_utils.rand_name('test-snap')
58 try:
59 image = self.create_image_from_server(server['id'],
60 name=snapshot_name,
61 wait_until='SAVING')
62 self.client.delete_image(image['id'])
63 msg = ('The image with ID {image_id} failed to be deleted'
64 .format(image_id=image['id']))
65 self.assertTrue(self.client.is_resource_deleted(image['id']),
66 msg)
67 self.assertEqual(snapshot_name, image['name'])
68 except lib_exceptions.TimeoutException as ex:
69 # If timeout is reached, we don't need to check state,
70 # since, it wouldn't be a 'SAVING' state atleast and apart from
71 # it, this testcase doesn't have scope for other state transition
72 # Hence, skip the test.
73 raise self.skipException("This test is skipped because " + str(ex))
Joe H. Rahme66793a32015-10-09 18:36:26 +020074
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080075 @decorators.idempotent_id('aaacd1d0-55a2-4ce8-818a-b5439df8adc9')
Joe H. Rahme66793a32015-10-09 18:36:26 +020076 def test_create_image_from_stopped_server(self):
77 server = self.create_test_server(wait_until='ACTIVE')
78 self.servers_client.stop_server(server['id'])
79 waiters.wait_for_server_status(self.servers_client,
80 server['id'], 'SHUTOFF')
81 self.addCleanup(self.servers_client.delete_server, server['id'])
82 snapshot_name = data_utils.rand_name('test-snap')
83 image = self.create_image_from_server(server['id'],
84 name=snapshot_name,
Bob Ball5fe62392017-02-20 09:51:00 +000085 wait_until='ACTIVE',
86 wait_for_server=False)
Joe H. Rahme66793a32015-10-09 18:36:26 +020087 self.addCleanup(self.client.delete_image, image['id'])
88 self.assertEqual(snapshot_name, image['name'])
lianghaoc0807862017-03-06 20:02:15 +080089
90 @decorators.idempotent_id('71bcb732-0261-11e7-9086-fa163e4fa634')
Eric Berglunddde9de42017-03-22 15:19:48 -050091 @testtools.skipUnless(CONF.compute_feature_enabled.pause,
92 'Pause is not available.')
lianghaoc0807862017-03-06 20:02:15 +080093 def test_create_image_from_paused_server(self):
94 server = self.create_test_server(wait_until='ACTIVE')
95 self.servers_client.pause_server(server['id'])
96 waiters.wait_for_server_status(self.servers_client,
97 server['id'], 'PAUSED')
98 self.addCleanup(self.servers_client.delete_server, server['id'])
99
100 snapshot_name = data_utils.rand_name('test-snap')
101 image = self.create_image_from_server(server['id'],
102 name=snapshot_name,
103 wait_until='ACTIVE',
104 wait_for_server=False)
105 self.addCleanup(self.client.delete_image, image['id'])
106 self.assertEqual(snapshot_name, image['name'])
107
108 @decorators.idempotent_id('8ca07fec-0262-11e7-907e-fa163e4fa634')
Eric Berglunddde9de42017-03-22 15:19:48 -0500109 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
110 'Suspend is not available.')
lianghaoc0807862017-03-06 20:02:15 +0800111 def test_create_image_from_suspended_server(self):
112 server = self.create_test_server(wait_until='ACTIVE')
113 self.servers_client.suspend_server(server['id'])
114 waiters.wait_for_server_status(self.servers_client,
115 server['id'], 'SUSPENDED')
116 self.addCleanup(self.servers_client.delete_server, server['id'])
117
118 snapshot_name = data_utils.rand_name('test-snap')
119 image = self.create_image_from_server(server['id'],
120 name=snapshot_name,
121 wait_until='ACTIVE',
122 wait_for_server=False)
123 self.addCleanup(self.client.delete_image, image['id'])
124 self.assertEqual(snapshot_name, image['name'])