blob: cd6d7a8a79b12f428e135511d2001d5a3048fd1b [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
30 def setUpClass(cls):
31 super(VolumesBackupsTest, cls).setUpClass()
32
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
45 resp, backup = create_backup(self.volume['id'],
46 name=backup_name)
47 self.assertEqual(202, resp.status)
48 self.addCleanup(self.backups_adm_client.delete_backup,
49 backup['id'])
raiesmh08f04da342014-02-28 17:14:43 +053050 self.assertEqual(backup_name, backup['name'])
Giulio Fidente74b08ad2014-01-18 04:02:51 +010051 self.volumes_adm_client.wait_for_volume_status(self.volume['id'],
52 'available')
53 self.backups_adm_client.wait_for_backup_status(backup['id'],
54 'available')
55
raiesmh08f04da342014-02-28 17:14:43 +053056 # Get a given backup
Giulio Fidente74b08ad2014-01-18 04:02:51 +010057 resp, backup = self.backups_adm_client.get_backup(backup['id'])
58 self.assertEqual(200, resp.status)
raiesmh08f04da342014-02-28 17:14:43 +053059 self.assertEqual(backup_name, backup['name'])
Giulio Fidente74b08ad2014-01-18 04:02:51 +010060
raiesmh08f04da342014-02-28 17:14:43 +053061 # Get all backups with detail
62 resp, backups = self.backups_adm_client.list_backups_with_detail()
63 self.assertEqual(200, resp.status)
64 self.assertIn((backup['name'], backup['id']),
65 [(m['name'], m['id']) for m in backups])
66
67 # Restore backup
Giulio Fidente74b08ad2014-01-18 04:02:51 +010068 resp, restore = self.backups_adm_client.restore_backup(backup['id'])
69 self.assertEqual(202, resp.status)
raiesmh08f04da342014-02-28 17:14:43 +053070
71 # Delete backup
Giulio Fidente74b08ad2014-01-18 04:02:51 +010072 self.addCleanup(self.volumes_adm_client.delete_volume,
73 restore['volume_id'])
raiesmh08f04da342014-02-28 17:14:43 +053074 self.assertEqual(backup['id'], restore['backup_id'])
Giulio Fidente74b08ad2014-01-18 04:02:51 +010075 self.backups_adm_client.wait_for_backup_status(backup['id'],
76 'available')
77 self.volumes_adm_client.wait_for_volume_status(restore['volume_id'],
78 'available')