blob: 29bd6dae11e1a8473683e90f2cf52869c022d3f7 [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
Sean Dague1937d092013-05-17 16:36:38 -040015from tempest.api.compute import base
Joe H. Rahme66793a32015-10-09 18:36:26 +020016from tempest.common import waiters
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000017from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080018from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080019from tempest.lib import decorators
Eric Berglunddde9de42017-03-22 15:19:48 -050020import testtools
Jay Pipes7f757632011-12-02 15:53:32 -050021
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000022CONF = config.CONF
23
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060024
ivan-zhuf2b00502013-10-18 10:06:52 +080025class ImagesTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010026
27 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053028 def skip_checks(cls):
29 super(ImagesTestJSON, cls).skip_checks()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000030 if not CONF.service_available.glance:
Matthew Treinish853ae442013-07-19 16:36:07 -040031 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
32 raise cls.skipException(skip_msg)
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070033 if not CONF.compute_feature_enabled.snapshot:
34 skip_msg = ("%s skipped as instance snapshotting is not supported"
35 % cls.__name__)
36 raise cls.skipException(skip_msg)
37
Rohan Kanade60b73092015-02-04 17:58:19 +053038 @classmethod
39 def setup_clients(cls):
40 super(ImagesTestJSON, cls).setup_clients()
Ghanshyamae76c122015-12-22 13:41:35 +090041 cls.client = cls.compute_images_client
Attila Fazekas19044d52013-02-16 07:35:06 +010042
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080043 @decorators.idempotent_id('aa06b52b-2db5-4807-b218-9441f75d74e3')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080044 def test_delete_saving_image(self):
David Kranz0fb14292015-02-11 15:55:20 -050045 server = self.create_test_server(wait_until='ACTIVE')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080046 self.addCleanup(self.servers_client.delete_server, server['id'])
David Kranza5299eb2015-01-15 17:24:05 -050047 image = self.create_image_from_server(server['id'],
David Kranza5299eb2015-01-15 17:24:05 -050048 wait_until='SAVING')
49 self.client.delete_image(image['id'])
Castulo J. Martinez43147c62016-07-08 12:04:45 -070050 msg = ('The image with ID {image_id} failed to be deleted'
51 .format(image_id=image['id']))
52 self.assertTrue(self.client.is_resource_deleted(image['id']), msg)
Joe H. Rahme66793a32015-10-09 18:36:26 +020053
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080054 @decorators.idempotent_id('aaacd1d0-55a2-4ce8-818a-b5439df8adc9')
Joe H. Rahme66793a32015-10-09 18:36:26 +020055 def test_create_image_from_stopped_server(self):
56 server = self.create_test_server(wait_until='ACTIVE')
57 self.servers_client.stop_server(server['id'])
58 waiters.wait_for_server_status(self.servers_client,
59 server['id'], 'SHUTOFF')
60 self.addCleanup(self.servers_client.delete_server, server['id'])
61 snapshot_name = data_utils.rand_name('test-snap')
62 image = self.create_image_from_server(server['id'],
63 name=snapshot_name,
Bob Ball5fe62392017-02-20 09:51:00 +000064 wait_until='ACTIVE',
65 wait_for_server=False)
Joe H. Rahme66793a32015-10-09 18:36:26 +020066 self.addCleanup(self.client.delete_image, image['id'])
67 self.assertEqual(snapshot_name, image['name'])
lianghaoc0807862017-03-06 20:02:15 +080068
69 @decorators.idempotent_id('71bcb732-0261-11e7-9086-fa163e4fa634')
Eric Berglunddde9de42017-03-22 15:19:48 -050070 @testtools.skipUnless(CONF.compute_feature_enabled.pause,
71 'Pause is not available.')
lianghaoc0807862017-03-06 20:02:15 +080072 def test_create_image_from_paused_server(self):
73 server = self.create_test_server(wait_until='ACTIVE')
74 self.servers_client.pause_server(server['id'])
75 waiters.wait_for_server_status(self.servers_client,
76 server['id'], 'PAUSED')
77 self.addCleanup(self.servers_client.delete_server, server['id'])
78
79 snapshot_name = data_utils.rand_name('test-snap')
80 image = self.create_image_from_server(server['id'],
81 name=snapshot_name,
82 wait_until='ACTIVE',
83 wait_for_server=False)
84 self.addCleanup(self.client.delete_image, image['id'])
85 self.assertEqual(snapshot_name, image['name'])
86
87 @decorators.idempotent_id('8ca07fec-0262-11e7-907e-fa163e4fa634')
Eric Berglunddde9de42017-03-22 15:19:48 -050088 @testtools.skipUnless(CONF.compute_feature_enabled.suspend,
89 'Suspend is not available.')
lianghaoc0807862017-03-06 20:02:15 +080090 def test_create_image_from_suspended_server(self):
91 server = self.create_test_server(wait_until='ACTIVE')
92 self.servers_client.suspend_server(server['id'])
93 waiters.wait_for_server_status(self.servers_client,
94 server['id'], 'SUSPENDED')
95 self.addCleanup(self.servers_client.delete_server, server['id'])
96
97 snapshot_name = data_utils.rand_name('test-snap')
98 image = self.create_image_from_server(server['id'],
99 name=snapshot_name,
100 wait_until='ACTIVE',
101 wait_for_server=False)
102 self.addCleanup(self.client.delete_image, image['id'])
103 self.assertEqual(snapshot_name, image['name'])