Codebase list cinder-tempest-plugin / 9d9a091
Merge "Add volume backup tempest tests" Jenkins authored 9 years ago Gerrit Code Review committed 9 years ago
1 changed file(s) with 142 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 # Copyright (c) 2016 Mirantis Inc.
1 # All Rights Reserved.
2 #
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
15 from oslo_config import cfg
16 import testtools
17
18 from tempest.api.volume import base as volume_base
19 from tempest.common import waiters
20 from tempest import config
21 from tempest.lib.common.utils import data_utils
22 from tempest import test
23
24 # TODO(obutenko): Remove this when liberty-eol happens.
25 snapshot_backup_opt = cfg.BoolOpt('snapshot_backup',
26 default=False,
27 help='Creating backup from snapshot not '
28 'implemented in Liberty.')
29
30 CONF = config.CONF
31 CONF.register_opt(snapshot_backup_opt, group='volume-feature-enabled')
32
33
34 class VolumesBackupsTest(volume_base.BaseVolumeTest):
35
36 @classmethod
37 def skip_checks(cls):
38 super(VolumesBackupsTest, cls).skip_checks()
39 if not CONF.volume_feature_enabled.backup:
40 raise cls.skipException("Cinder backup feature disabled")
41
42 @testtools.skipUnless(CONF.volume_feature_enabled.snapshot_backup,
43 "Skip. Not implemented in Liberty.")
44 @test.idempotent_id('885410c6-cd1d-452c-a409-7c32b7e0be15')
45 def test_volume_snapshot_backup(self):
46 """Create backup from snapshot."""
47 volume = self.create_volume()
48 # Create snapshot
49 snapshot = self.create_snapshot(volume['id'])
50 # Create backup
51 backup = self.create_backup(
52 volume_id=volume['id'],
53 snapshot_id=snapshot['id'])
54 # Get a given backup
55 backup = self.backups_client.show_backup(
56 backup['id'])['backup']
57 waiters.wait_for_backup_status(
58 self.backups_client,
59 backup['id'], 'available')
60 self.assertEqual(volume['id'], backup['volume_id'])
61 self.assertEqual(snapshot['id'], backup['snapshot_id'])
62
63 self.snapshots_client.delete_snapshot(snapshot['id'])
64 self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
65
66 self.volumes_client.delete_volume(volume['id'])
67 self.volumes_client.wait_for_resource_deletion(volume['id'])
68
69 @test.idempotent_id('b5d837b0-7066-455d-88fc-4a721a899306')
70 def test_backup_create_and_restore_to_an_existing_volume(self):
71 """Test backup create and restore to an existing volume."""
72 # Create volume
73 src_vol = self.create_volume()
74 self.addCleanup(self.volumes_client.delete_volume,
75 src_vol['id'])
76 # Create backup
77 backup = self.backups_client.create_backup(
78 volume_id=src_vol['id'])['backup']
79 self.addCleanup(self.backups_client.delete_backup, backup['id'])
80 waiters.wait_for_backup_status(
81 self.backups_client,
82 backup['id'], 'available')
83 # Restore to existing volume
84 restore = self.backups_client.restore_backup(
85 backup_id=backup['id'],
86 volume_id=src_vol['id'])['restore']
87 waiters.wait_for_backup_status(
88 self.backups_client,
89 backup['id'], 'available')
90 waiters.wait_for_volume_status(
91 self.volumes_client,
92 src_vol['id'], 'available')
93 self.assertEqual(src_vol['id'], restore['volume_id'])
94 self.assertEqual(backup['id'], restore['backup_id'])
95
96 @test.idempotent_id('c810fe2c-cb40-43ab-96aa-471b74516a98')
97 def test_incremental_backup(self):
98 """Test create incremental backup."""
99 # Create volume from image
100 volume = self.create_volume(size=CONF.volume.volume_size,
101 imageRef=CONF.compute.image_ref)
102 self.addCleanup(self.volumes_client.delete_volume,
103 volume['id'])
104
105 # Create backup
106 backup = self.backups_client.create_backup(
107 volume_id=volume['id'])['backup']
108 waiters.wait_for_backup_status(self.backups_client,
109 backup['id'],
110 'available')
111 # Create a server
112 bd_map = [{'volume_id': volume['id'],
113 'delete_on_termination': '0'}]
114
115 server_name = data_utils.rand_name('instance')
116 server = self.create_server(
117 name=server_name,
118 block_device_mapping=bd_map,
119 wait_until='ACTIVE')
120
121 # Delete VM
122 self.servers_client.delete_server(server['id'])
123 # Create incremental backup
124 waiters.wait_for_volume_status(self.volumes_client, volume['id'],
125 'available')
126 backup_incr = self.backups_client.create_backup(
127 volume_id=volume['id'],
128 incremental=True)['backup']
129
130 waiters.wait_for_backup_status(self.backups_client,
131 backup_incr['id'],
132 'available')
133
134 is_incremental = self.backups_client.show_backup(
135 backup_incr['id'])['backup']['is_incremental']
136 self.assertTrue(is_incremental)
137
138 self.backups_client.delete_backup(backup_incr['id'])
139 self.backups_client.wait_for_resource_deletion(backup_incr['id'])
140 self.backups_client.delete_backup(backup['id'])
141 self.backups_client.wait_for_resource_deletion(backup['id'])