blob: 4b352e0c5197ae6eab1e6221127f68762ae740eb [file] [log] [blame]
jeremy.zhangf4fbf302017-03-22 11:25:53 +08001# 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
16from tempest.api.volume import base
17from tempest.common import waiters
18from tempest import config
19from tempest.lib.common.utils import data_utils
20from tempest.lib import decorators
jeremy.zhangaa8c9312017-06-21 12:32:47 +080021from tempest.lib import exceptions
jeremy.zhangf4fbf302017-03-22 11:25:53 +080022
23CONF = config.CONF
24
25
Ken'ichi Ohmichi9fff0202017-04-03 13:32:15 -070026class VolumeManageAdminTest(base.BaseVolumeAdminTest):
jeremy.zhangf4fbf302017-03-22 11:25:53 +080027
28 @classmethod
29 def skip_checks(cls):
Ken'ichi Ohmichi9fff0202017-04-03 13:32:15 -070030 super(VolumeManageAdminTest, cls).skip_checks()
jeremy.zhangf4fbf302017-03-22 11:25:53 +080031
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.zhangaa8c9312017-06-21 12:32:47 +080036 msg = ("Manage volume ref is not correctly configured, "
37 "it should be a list of two elements")
38 raise exceptions.InvalidConfiguration(msg)
jeremy.zhangf4fbf302017-03-22 11:25:53 +080039
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])