blob: bf014a8f33a95353aa56c3e35225e929a96e221f [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
Giulio Fidente74b08ad2014-01-18 04:02:51 +010036 cls.backups_adm_client = cls.os_adm.backups_client
37 cls.volume = cls.create_volume()
38
39 @test.attr(type='smoke')
raiesmh08f04da342014-02-28 17:14:43 +053040 def test_volume_backup_create_get_detailed_list_restore_delete(self):
41 # Create backup
Giulio Fidente74b08ad2014-01-18 04:02:51 +010042 backup_name = data_utils.rand_name('Backup')
43 create_backup = self.backups_adm_client.create_backup
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000044 _, backup = create_backup(self.volume['id'],
45 name=backup_name)
Giulio Fidente74b08ad2014-01-18 04:02:51 +010046 self.addCleanup(self.backups_adm_client.delete_backup,
47 backup['id'])
raiesmh08f04da342014-02-28 17:14:43 +053048 self.assertEqual(backup_name, backup['name'])
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053049 self.admin_volume_client.wait_for_volume_status(
50 self.volume['id'], 'available')
Giulio Fidente74b08ad2014-01-18 04:02:51 +010051 self.backups_adm_client.wait_for_backup_status(backup['id'],
52 'available')
53
raiesmh08f04da342014-02-28 17:14:43 +053054 # Get a given backup
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000055 _, backup = self.backups_adm_client.get_backup(backup['id'])
raiesmh08f04da342014-02-28 17:14:43 +053056 self.assertEqual(backup_name, backup['name'])
Giulio Fidente74b08ad2014-01-18 04:02:51 +010057
raiesmh08f04da342014-02-28 17:14:43 +053058 # Get all backups with detail
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000059 _, backups = self.backups_adm_client.list_backups_with_detail()
raiesmh08f04da342014-02-28 17:14:43 +053060 self.assertIn((backup['name'], backup['id']),
61 [(m['name'], m['id']) for m in backups])
62
63 # Restore backup
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000064 _, restore = self.backups_adm_client.restore_backup(backup['id'])
raiesmh08f04da342014-02-28 17:14:43 +053065
66 # Delete backup
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053067 self.addCleanup(self.admin_volume_client.delete_volume,
Giulio Fidente74b08ad2014-01-18 04:02:51 +010068 restore['volume_id'])
raiesmh08f04da342014-02-28 17:14:43 +053069 self.assertEqual(backup['id'], restore['backup_id'])
Giulio Fidente74b08ad2014-01-18 04:02:51 +010070 self.backups_adm_client.wait_for_backup_status(backup['id'],
71 'available')
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053072 self.admin_volume_client.wait_for_volume_status(
73 restore['volume_id'], 'available')