blob: 8b90b0712099eac4e365d7f9b7b0025fcc87b312 [file] [log] [blame]
Giulio Fidente74b08ad2014-01-18 04:02:51 +01001# Copyright 2014 OpenStack Foundation
2# 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
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090016from tempest.api.volume import base
Giulio Fidente74b08ad2014-01-18 04:02:51 +010017from tempest.common.utils import data_utils
18from tempest import config
19from tempest.openstack.common import log as logging
20from tempest import test
21
22CONF = config.CONF
23LOG = logging.getLogger(__name__)
24
25
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090026class VolumesBackupsTest(base.BaseVolumeV1AdminTest):
Giulio Fidente74b08ad2014-01-18 04:02:51 +010027 _interface = "json"
28
29 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010030 def resource_setup(cls):
31 super(VolumesBackupsTest, cls).resource_setup()
Giulio Fidente74b08ad2014-01-18 04:02:51 +010032
33 if not CONF.volume_feature_enabled.backup:
34 raise cls.skipException("Cinder backup feature disabled")
35
36 cls.volumes_adm_client = cls.os_adm.volumes_client
37 cls.backups_adm_client = cls.os_adm.backups_client
38 cls.volume = cls.create_volume()
39
40 @test.attr(type='smoke')
raiesmh08f04da342014-02-28 17:14:43 +053041 def test_volume_backup_create_get_detailed_list_restore_delete(self):
42 # Create backup
Giulio Fidente74b08ad2014-01-18 04:02:51 +010043 backup_name = data_utils.rand_name('Backup')
44 create_backup = self.backups_adm_client.create_backup
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000045 _, backup = create_backup(self.volume['id'],
46 name=backup_name)
Giulio Fidente74b08ad2014-01-18 04:02:51 +010047 self.addCleanup(self.backups_adm_client.delete_backup,
48 backup['id'])
raiesmh08f04da342014-02-28 17:14:43 +053049 self.assertEqual(backup_name, backup['name'])
Giulio Fidente74b08ad2014-01-18 04:02:51 +010050 self.volumes_adm_client.wait_for_volume_status(self.volume['id'],
51 'available')
52 self.backups_adm_client.wait_for_backup_status(backup['id'],
53 'available')
54
raiesmh08f04da342014-02-28 17:14:43 +053055 # Get a given backup
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000056 _, backup = self.backups_adm_client.get_backup(backup['id'])
raiesmh08f04da342014-02-28 17:14:43 +053057 self.assertEqual(backup_name, backup['name'])
Giulio Fidente74b08ad2014-01-18 04:02:51 +010058
raiesmh08f04da342014-02-28 17:14:43 +053059 # Get all backups with detail
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000060 _, backups = self.backups_adm_client.list_backups_with_detail()
raiesmh08f04da342014-02-28 17:14:43 +053061 self.assertIn((backup['name'], backup['id']),
62 [(m['name'], m['id']) for m in backups])
63
64 # Restore backup
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000065 _, restore = self.backups_adm_client.restore_backup(backup['id'])
raiesmh08f04da342014-02-28 17:14:43 +053066
67 # Delete backup
Giulio Fidente74b08ad2014-01-18 04:02:51 +010068 self.addCleanup(self.volumes_adm_client.delete_volume,
69 restore['volume_id'])
raiesmh08f04da342014-02-28 17:14:43 +053070 self.assertEqual(backup['id'], restore['backup_id'])
Giulio Fidente74b08ad2014-01-18 04:02:51 +010071 self.backups_adm_client.wait_for_backup_status(backup['id'],
72 'available')
73 self.volumes_adm_client.wait_for_volume_status(restore['volume_id'],
74 'available')