jeremy.zhang | f4fbf30 | 2017-03-22 11:25:53 +0800 | [diff] [blame] | 1 | # Copyright 2017 FiberHome Telecommunication Technologies CO.,LTD |
| 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 | |
| 16 | from tempest.api.volume import base |
| 17 | from tempest.common import waiters |
| 18 | from tempest import config |
| 19 | from tempest.lib.common.utils import data_utils |
| 20 | from tempest.lib import decorators |
jeremy.zhang | aa8c931 | 2017-06-21 12:32:47 +0800 | [diff] [blame] | 21 | from tempest.lib import exceptions |
jeremy.zhang | f4fbf30 | 2017-03-22 11:25:53 +0800 | [diff] [blame] | 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | |
Ken'ichi Ohmichi | 9fff020 | 2017-04-03 13:32:15 -0700 | [diff] [blame] | 26 | class VolumeManageAdminTest(base.BaseVolumeAdminTest): |
jeremy.zhang | f4fbf30 | 2017-03-22 11:25:53 +0800 | [diff] [blame] | 27 | |
| 28 | @classmethod |
| 29 | def skip_checks(cls): |
Ken'ichi Ohmichi | 9fff020 | 2017-04-03 13:32:15 -0700 | [diff] [blame] | 30 | super(VolumeManageAdminTest, cls).skip_checks() |
jeremy.zhang | f4fbf30 | 2017-03-22 11:25:53 +0800 | [diff] [blame] | 31 | |
| 32 | if not CONF.volume_feature_enabled.manage_volume: |
| 33 | raise cls.skipException("Manage volume tests are disabled") |
| 34 | |
| 35 | if len(CONF.volume.manage_volume_ref) != 2: |
jeremy.zhang | aa8c931 | 2017-06-21 12:32:47 +0800 | [diff] [blame] | 36 | msg = ("Manage volume ref is not correctly configured, " |
| 37 | "it should be a list of two elements") |
| 38 | raise exceptions.InvalidConfiguration(msg) |
jeremy.zhang | f4fbf30 | 2017-03-22 11:25:53 +0800 | [diff] [blame] | 39 | |
| 40 | @decorators.idempotent_id('70076c71-0ce1-4208-a8ff-36a66e65cc1e') |
| 41 | def test_unmanage_manage_volume(self): |
| 42 | # Create original volume |
| 43 | org_vol_id = self.create_volume()['id'] |
| 44 | org_vol_info = self.admin_volume_client.show_volume( |
| 45 | org_vol_id)['volume'] |
| 46 | |
| 47 | # Unmanage the original volume |
| 48 | self.admin_volume_client.unmanage_volume(org_vol_id) |
| 49 | self.admin_volume_client.wait_for_resource_deletion(org_vol_id) |
| 50 | |
| 51 | # Verify the original volume does not exist in volume list |
| 52 | params = {'all_tenants': 1} |
| 53 | all_tenants_volumes = self.admin_volume_client.list_volumes( |
| 54 | detail=True, params=params)['volumes'] |
| 55 | self.assertNotIn(org_vol_id, [v['id'] for v in all_tenants_volumes]) |
| 56 | |
| 57 | # Manage volume |
| 58 | new_vol_name = data_utils.rand_name( |
| 59 | self.__class__.__name__ + '-volume') |
| 60 | new_vol_ref = { |
| 61 | 'name': new_vol_name, |
| 62 | 'host': org_vol_info['os-vol-host-attr:host'], |
| 63 | 'ref': {CONF.volume.manage_volume_ref[0]: |
| 64 | CONF.volume.manage_volume_ref[1] % org_vol_id}, |
| 65 | 'volume_type': org_vol_info['volume_type'], |
| 66 | 'availability_zone': org_vol_info['availability_zone']} |
| 67 | new_vol_id = self.admin_volume_manage_client.manage_volume( |
| 68 | **new_vol_ref)['volume']['id'] |
| 69 | self.addCleanup(self.delete_volume, |
| 70 | self.admin_volume_client, new_vol_id) |
| 71 | waiters.wait_for_volume_resource_status(self.admin_volume_client, |
| 72 | new_vol_id, 'available') |
| 73 | |
| 74 | # Compare the managed volume with the original |
| 75 | new_vol_info = self.admin_volume_client.show_volume( |
| 76 | new_vol_id)['volume'] |
| 77 | self.assertNotIn(new_vol_id, [org_vol_id]) |
| 78 | self.assertEqual(new_vol_info['name'], new_vol_name) |
| 79 | for key in ['size', |
| 80 | 'volume_type', |
| 81 | 'availability_zone', |
| 82 | 'os-vol-host-attr:host']: |
| 83 | self.assertEqual(new_vol_info[key], org_vol_info[key]) |