Merge "Add test cases for bugs 1869746 and 1873518"
Zuul authored 5 years ago
Gerrit Code Review committed 5 years ago
| 0 | # Copyright (C) 2020 Canonical Ltd. | |
| 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 tempest.common import waiters | |
| 16 | from tempest import config | |
| 17 | from tempest.lib import decorators | |
| 18 | from tempest.lib import exceptions | |
| 19 | ||
| 20 | from cinder_tempest_plugin.api.volume import base | |
| 21 | ||
| 22 | CONF = config.CONF | |
| 23 | ||
| 24 | ||
| 25 | class VolumesBackupsTest(base.BaseVolumeAdminTest): | |
| 26 | @classmethod | |
| 27 | def setup_clients(cls): | |
| 28 | super(VolumesBackupsTest, cls).setup_clients() | |
| 29 | cls.admin_volume_client = cls.os_admin.volumes_client_latest | |
| 30 | cls.backups_client = cls.os_primary.backups_client_latest | |
| 31 | cls.volumes_client = cls.os_primary.volumes_client_latest | |
| 32 | ||
| 33 | @classmethod | |
| 34 | def skip_checks(cls): | |
| 35 | super(VolumesBackupsTest, cls).skip_checks() | |
| 36 | if not CONF.volume_feature_enabled.backup: | |
| 37 | raise cls.skipException("Cinder backup feature disabled") | |
| 38 | ||
| 39 | @decorators.idempotent_id('2daadb2e-409a-4ede-a6ce-6002ec324372') | |
| 40 | def test_backup_crossproject_admin_negative(self): | |
| 41 | ||
| 42 | # create vol as user | |
| 43 | volume = self.volumes_client.create_volume( | |
| 44 | size=CONF.volume.volume_size)['volume'] | |
| 45 | waiters.wait_for_volume_resource_status( | |
| 46 | self.volumes_client, | |
| 47 | volume['id'], 'available') | |
| 48 | ||
| 49 | # create backup as user | |
| 50 | backup = self.backups_client.create_backup( | |
| 51 | volume_id=volume['id'])['backup'] | |
| 52 | waiters.wait_for_volume_resource_status( | |
| 53 | self.backups_client, | |
| 54 | backup['id'], 'available') | |
| 55 | ||
| 56 | # try to create incremental backup as admin | |
| 57 | self.assertRaises( | |
| 58 | exceptions.BadRequest, self.admin_backups_client.create_backup, | |
| 59 | volume_id=volume['id'], incremental=True) | |
| 60 | ||
| 61 | @decorators.idempotent_id('b9feb593-5809-4207-90d3-28e627730f13') | |
| 62 | def test_backup_crossproject_user_negative(self): | |
| 63 | ||
| 64 | # create vol as user | |
| 65 | volume = self.volumes_client.create_volume( | |
| 66 | size=CONF.volume.volume_size)['volume'] | |
| 67 | waiters.wait_for_volume_resource_status( | |
| 68 | self.volumes_client, | |
| 69 | volume['id'], 'available') | |
| 70 | ||
| 71 | # create backup as admin | |
| 72 | backup = self.admin_backups_client.create_backup( | |
| 73 | volume_id=volume['id'])['backup'] | |
| 74 | waiters.wait_for_volume_resource_status( | |
| 75 | self.admin_backups_client, | |
| 76 | backup['id'], 'available') | |
| 77 | ||
| 78 | # try to create incremental backup as user | |
| 79 | self.assertRaises( | |
| 80 | exceptions.BadRequest, self.backups_client.create_backup, | |
| 81 | volume_id=volume['id'], incremental=True) | |
| 82 | ||
| 83 | @decorators.idempotent_id('ce15f528-bfc1-492d-81db-b6168b631587') | |
| 84 | def test_incremental_backup_respective_parents(self): | |
| 85 | ||
| 86 | # create vol as user | |
| 87 | volume = self.volumes_client.create_volume( | |
| 88 | size=CONF.volume.volume_size)['volume'] | |
| 89 | waiters.wait_for_volume_resource_status( | |
| 90 | self.volumes_client, | |
| 91 | volume['id'], 'available') | |
| 92 | ||
| 93 | # create backup as admin | |
| 94 | backup_adm = self.admin_backups_client.create_backup( | |
| 95 | volume_id=volume['id'])['backup'] | |
| 96 | waiters.wait_for_volume_resource_status( | |
| 97 | self.admin_backups_client, | |
| 98 | backup_adm['id'], 'available') | |
| 99 | ||
| 100 | # create backup as user | |
| 101 | backup_usr = self.backups_client.create_backup( | |
| 102 | volume_id=volume['id'])['backup'] | |
| 103 | waiters.wait_for_volume_resource_status( | |
| 104 | self.backups_client, | |
| 105 | backup_usr['id'], 'available') | |
| 106 | ||
| 107 | # refresh admin backup and assert no child backups | |
| 108 | backup_adm = self.admin_backups_client.show_backup( | |
| 109 | backup_adm['id'])['backup'] | |
| 110 | self.assertFalse(backup_adm['has_dependent_backups']) | |
| 111 | ||
| 112 | # create incremental backup as admin | |
| 113 | backup_adm_inc = self.admin_backups_client.create_backup( | |
| 114 | volume_id=volume['id'], incremental=True)['backup'] | |
| 115 | waiters.wait_for_volume_resource_status( | |
| 116 | self.admin_backups_client, | |
| 117 | backup_adm_inc['id'], 'available') | |
| 118 | ||
| 119 | # refresh user backup and assert no child backups | |
| 120 | backup_usr = self.backups_client.show_backup( | |
| 121 | backup_usr['id'])['backup'] | |
| 122 | self.assertFalse(backup_usr['has_dependent_backups']) | |
| 123 | ||
| 124 | # refresh admin backup and assert it has childs | |
| 125 | backup_adm = self.admin_backups_client.show_backup( | |
| 126 | backup_adm['id'])['backup'] | |
| 127 | self.assertTrue(backup_adm['has_dependent_backups']) | |
| 128 | ||
| 129 | # create incremental backup as user | |
| 130 | backup_usr_inc = self.backups_client.create_backup( | |
| 131 | volume_id=volume['id'], incremental=True)['backup'] | |
| 132 | waiters.wait_for_volume_resource_status( | |
| 133 | self.backups_client, | |
| 134 | backup_usr_inc['id'], 'available') | |
| 135 | ||
| 136 | # refresh user backup and assert it has childs | |
| 137 | backup_usr = self.backups_client.show_backup( | |
| 138 | backup_usr['id'])['backup'] | |
| 139 | self.assertTrue(backup_usr['has_dependent_backups']) |