blob: 6be569c5ce54cf3661f85a53b72202af23e1abfa [file] [log] [blame]
Attila Fazekas36b1fcf2013-01-31 16:41:04 +01001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
Sean Dague1937d092013-05-17 16:36:38 -040013from tempest.api.volume import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120014from tempest.common.utils import data_utils
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050015from tempest.common import waiters
Xiao Chen47fcbf42014-01-13 16:42:41 +080016from tempest import config
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090017from tempest import test
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010018
Xiao Chen47fcbf42014-01-13 16:42:41 +080019CONF = config.CONF
Giulio Fidente3a465e32013-05-07 13:38:18 +020020
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010021
Zhi Kun Liu38641c62014-07-10 20:12:48 +080022class VolumesV2SnapshotTestJSON(base.BaseVolumeTest):
Attila Fazekas36b1fcf2013-01-31 16:41:04 +010023
Giulio Fidente73332932013-05-03 18:04:09 +020024 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053025 def skip_checks(cls):
26 super(VolumesV2SnapshotTestJSON, cls).skip_checks()
27 if not CONF.volume_feature_enabled.snapshot:
28 raise cls.skipException("Cinder volume snapshots are disabled")
29
30 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010031 def resource_setup(cls):
32 super(VolumesV2SnapshotTestJSON, cls).resource_setup()
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080033 cls.volume_origin = cls.create_volume()
Zhi Kun Liu38641c62014-07-10 20:12:48 +080034 cls.name_field = cls.special_fields['name_field']
35 cls.descrip_field = cls.special_fields['descrip_field']
Giulio Fidente73332932013-05-03 18:04:09 +020036
Xiao Chen47fcbf42014-01-13 16:42:41 +080037 def _detach(self, volume_id):
38 """Detach volume."""
39 self.volumes_client.detach_volume(volume_id)
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050040 waiters.wait_for_volume_status(self.volumes_client,
41 volume_id, 'available')
Xiao Chen47fcbf42014-01-13 16:42:41 +080042
Chris Hoge7579c1a2015-02-26 14:12:15 -080043 @test.idempotent_id('b467b54c-07a4-446d-a1cf-651dedcc3ff1')
Matthew Treinish7ea69e62014-06-03 17:23:50 -040044 @test.services('compute')
Xiao Chen47fcbf42014-01-13 16:42:41 +080045 def test_snapshot_create_with_volume_in_use(self):
46 # Create a snapshot when volume status is in-use
47 # Create a test instance
zhuflc6ce5392016-08-17 14:34:37 +080048 server_name = data_utils.rand_name(
49 self.__class__.__name__ + '-instance')
Joseph Lanouxa074c012015-08-04 15:44:07 +000050 server = self.create_server(
51 name=server_name,
52 wait_until='ACTIVE')
David Kranz3ebc7212015-02-10 12:19:19 -050053 self.servers_client.attach_volume(
Ken'ichi Ohmichidfc88de2015-08-13 05:12:20 +000054 server['id'], volumeId=self.volume_origin['id'],
bkopilovbc830d02016-03-27 14:09:47 +030055 device='/dev/%s' % CONF.compute.volume_device_name)
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050056 waiters.wait_for_volume_status(self.volumes_client,
57 self.volume_origin['id'], 'in-use')
58 self.addCleanup(waiters.wait_for_volume_status, self.volumes_client,
Mitsuhiro Taninoab667962014-12-10 15:52:08 -050059 self.volume_origin['id'], 'available')
60 self.addCleanup(self.servers_client.detach_volume, server['id'],
61 self.volume_origin['id'])
Xiao Chen47fcbf42014-01-13 16:42:41 +080062 # Snapshot a volume even if it's attached to an instance
63 snapshot = self.create_snapshot(self.volume_origin['id'],
64 force=True)
65 # Delete the snapshot
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +030066 self.cleanup_snapshot(snapshot)
Xiao Chen47fcbf42014-01-13 16:42:41 +080067
Chris Hoge7579c1a2015-02-26 14:12:15 -080068 @test.idempotent_id('2a8abbe4-d871-46db-b049-c41f5af8216e')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070069 def test_snapshot_create_get_list_update_delete(self):
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020070 # Create a snapshot
zhuflc6ce5392016-08-17 14:34:37 +080071 s_name = data_utils.rand_name(self.__class__.__name__ + '-snap')
Zhi Kun Liu38641c62014-07-10 20:12:48 +080072 params = {self.name_field: s_name}
73 snapshot = self.create_snapshot(self.volume_origin['id'], **params)
Giulio Fidente73332932013-05-03 18:04:09 +020074
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020075 # Get the snap and check for some of its details
John Warrenff7faf62015-08-17 16:59:06 +000076 snap_get = self.snapshots_client.show_snapshot(
77 snapshot['id'])['snapshot']
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020078 self.assertEqual(self.volume_origin['id'],
79 snap_get['volume_id'],
80 "Referred volume origin mismatch")
81
82 # Compare also with the output from the list action
Zhi Kun Liu38641c62014-07-10 20:12:48 +080083 tracking_data = (snapshot['id'], snapshot[self.name_field])
John Warrenff7faf62015-08-17 16:59:06 +000084 snaps_list = self.snapshots_client.list_snapshots()['snapshots']
Zhi Kun Liu38641c62014-07-10 20:12:48 +080085 snaps_data = [(f['id'], f[self.name_field]) for f in snaps_list]
Giulio Fidentef41b8ee2013-05-21 11:07:21 +020086 self.assertIn(tracking_data, snaps_data)
87
QingXin Mengdc95f5e2013-09-16 19:06:44 -070088 # Updates snapshot with new values
zhuflc6ce5392016-08-17 14:34:37 +080089 new_s_name = data_utils.rand_name(
90 self.__class__.__name__ + '-new-snap')
QingXin Mengdc95f5e2013-09-16 19:06:44 -070091 new_desc = 'This is the new description of snapshot.'
Zhi Kun Liu38641c62014-07-10 20:12:48 +080092 params = {self.name_field: new_s_name,
93 self.descrip_field: new_desc}
John Warrenff7faf62015-08-17 16:59:06 +000094 update_snapshot = self.snapshots_client.update_snapshot(
95 snapshot['id'], **params)['snapshot']
QingXin Mengdc95f5e2013-09-16 19:06:44 -070096 # Assert response body for update_snapshot method
Zhi Kun Liu38641c62014-07-10 20:12:48 +080097 self.assertEqual(new_s_name, update_snapshot[self.name_field])
98 self.assertEqual(new_desc, update_snapshot[self.descrip_field])
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +000099 # Assert response body for show_snapshot method
John Warrenff7faf62015-08-17 16:59:06 +0000100 updated_snapshot = self.snapshots_client.show_snapshot(
101 snapshot['id'])['snapshot']
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800102 self.assertEqual(new_s_name, updated_snapshot[self.name_field])
103 self.assertEqual(new_desc, updated_snapshot[self.descrip_field])
QingXin Mengdc95f5e2013-09-16 19:06:44 -0700104
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200105 # Delete the snapshot
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300106 self.cleanup_snapshot(snapshot)
Giulio Fidentef41b8ee2013-05-21 11:07:21 +0200107
Chris Hoge7579c1a2015-02-26 14:12:15 -0800108 @test.idempotent_id('677863d1-3142-456d-b6ac-9924f667a7f4')
Giulio Fidente73332932013-05-03 18:04:09 +0200109 def test_volume_from_snapshot(self):
Erlon R. Cruz8dbbc292016-06-17 15:40:36 -0300110 # Creates a volume a snapshot passing a size different from the source
111 src_size = CONF.volume.volume_size
112
113 src_vol = self.create_volume(size=src_size)
114 src_snap = self.create_snapshot(src_vol['id'])
115 # Destination volume bigger than source snapshot
116 dst_vol = self.create_volume(snapshot_id=src_snap['id'],
117 size=src_size + 1)
118
119 volume = self.volumes_client.show_volume(dst_vol['id'])['volume']
120 # Should allow
121 self.assertEqual(volume['snapshot_id'], src_snap['id'])
122 self.assertEqual(int(volume['size']), src_size + 1)
Yuriy Nesenenko551e1a92015-09-11 18:26:05 +0300123
124 def cleanup_snapshot(self, snapshot):
125 # Delete the snapshot
126 self.snapshots_client.delete_snapshot(snapshot['id'])
127 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
128 self.snapshots.remove(snapshot)
Attila Fazekas36b1fcf2013-01-31 16:41:04 +0100129
130
Zhi Kun Liu38641c62014-07-10 20:12:48 +0800131class VolumesV1SnapshotTestJSON(VolumesV2SnapshotTestJSON):
132 _api_version = 1