blob: eea918a08c10a96e22db68c0083b1ab89a08db1d [file] [log] [blame]
Jérôme Gallard86551ce2013-03-08 11:41:26 +01001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
Benny Kopilovaf136a92015-11-10 07:37:23 +020013import six
Sean Dague1937d092013-05-17 16:36:38 -040014from tempest.api.volume import base
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050015from tempest.common import waiters
Matthew Treinish4d352bc2014-01-29 18:29:18 +000016from tempest import config
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080017from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080018from tempest.lib import decorators
Jérôme Gallard86551ce2013-03-08 11:41:26 +010019
Matthew Treinish4d352bc2014-01-29 18:29:18 +000020CONF = config.CONF
21
Jérôme Gallard86551ce2013-03-08 11:41:26 +010022
Chandan Kumar449e4c02014-09-12 07:26:19 -040023class VolumeMultiBackendV2Test(base.BaseVolumeAdminTest):
Jérôme Gallard86551ce2013-03-08 11:41:26 +010024
Jérôme Gallard86551ce2013-03-08 11:41:26 +010025 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053026 def skip_checks(cls):
27 super(VolumeMultiBackendV2Test, cls).skip_checks()
28
Matthew Treinish4d352bc2014-01-29 18:29:18 +000029 if not CONF.volume_feature_enabled.multi_backend:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020030 raise cls.skipException("Cinder multi-backend feature disabled")
31
Rohan Kanade05749152015-01-30 17:15:18 +053032 @classmethod
33 def resource_setup(cls):
34 super(VolumeMultiBackendV2Test, cls).resource_setup()
bkopilov27905cc2016-04-12 14:29:13 +030035
36 # read backend name from a list .
zhufl7e0c9b62017-02-16 11:25:34 +080037 backend_names = set(CONF.volume.backend_names)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010038
Jerry Cai6e5eed22014-05-08 20:48:08 +080039 cls.volume_id_list_with_prefix = []
40 cls.volume_id_list_without_prefix = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010041
Jerry Cai6e5eed22014-05-08 20:48:08 +080042 # Volume/Type creation (uses volume_backend_name)
Benny Kopilovaf136a92015-11-10 07:37:23 +020043 # It is not allowed to create the same backend name twice
zhufl7e0c9b62017-02-16 11:25:34 +080044 if len(backend_names) < 2:
Benny Kopilovaf136a92015-11-10 07:37:23 +020045 raise cls.skipException("Requires at least two different "
46 "backend names")
zhufl7e0c9b62017-02-16 11:25:34 +080047 for backend_name in backend_names:
Benny Kopilovaf136a92015-11-10 07:37:23 +020048 # Volume/Type creation (uses backend_name)
49 cls._create_type_and_volume(backend_name, False)
Jerry Cai6e5eed22014-05-08 20:48:08 +080050 # Volume/Type creation (uses capabilities:volume_backend_name)
Benny Kopilovaf136a92015-11-10 07:37:23 +020051 cls._create_type_and_volume(backend_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080052
Jerry Cai6e5eed22014-05-08 20:48:08 +080053 @classmethod
zhufle27c0e32016-08-17 14:45:30 +080054 def _create_type_and_volume(cls, backend_name_key, with_prefix):
Jerry Cai6e5eed22014-05-08 20:48:08 +080055 # Volume/Type creation
zhuflc6ce5392016-08-17 14:34:37 +080056 type_name = data_utils.rand_name(cls.__name__ + '-Type')
57 vol_name = data_utils.rand_name(cls.__name__ + '-Volume')
Jerry Cai6e5eed22014-05-08 20:48:08 +080058 spec_key_with_prefix = "capabilities:volume_backend_name"
59 spec_key_without_prefix = "volume_backend_name"
60 if with_prefix:
61 extra_specs = {spec_key_with_prefix: backend_name_key}
62 else:
63 extra_specs = {spec_key_without_prefix: backend_name_key}
zhufl8bd576f2017-02-16 11:37:38 +080064 cls.create_volume_type(name=type_name,
65 extra_specs=extra_specs)
Jerry Cai6e5eed22014-05-08 20:48:08 +080066
zhufla57530c2017-03-23 11:38:12 +080067 params = {'name': vol_name, 'volume_type': type_name,
Ken'ichi Ohmichiadb905e2016-08-26 15:16:23 -070068 'size': CONF.volume.volume_size}
zhufle27c0e32016-08-17 14:45:30 +080069 cls.volume = cls.admin_volume_client.create_volume(
John Warren6177c9e2015-08-19 20:00:17 +000070 **params)['volume']
Jerry Cai6e5eed22014-05-08 20:48:08 +080071 if with_prefix:
zhufle27c0e32016-08-17 14:45:30 +080072 cls.volume_id_list_with_prefix.append(cls.volume['id'])
Jerry Cai6e5eed22014-05-08 20:48:08 +080073 else:
zhufle27c0e32016-08-17 14:45:30 +080074 cls.volume_id_list_without_prefix.append(
75 cls.volume['id'])
lkuchlan52d7b0d2016-11-07 20:53:19 +020076 waiters.wait_for_volume_resource_status(cls.admin_volume_client,
77 cls.volume['id'], 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010078
Jérôme Gallard86551ce2013-03-08 11:41:26 +010079 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010080 def resource_cleanup(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020081 # volumes deletion
Jerry Cai6e5eed22014-05-08 20:48:08 +080082 vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
83 for volume_id in vid_prefix:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053084 cls.admin_volume_client.delete_volume(volume_id)
85 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +080086
87 vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
88 for volume_id in vid_no_pre:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053089 cls.admin_volume_client.delete_volume(volume_id)
90 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010091
Chandan Kumar449e4c02014-09-12 07:26:19 -040092 super(VolumeMultiBackendV2Test, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050093
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080094 @decorators.idempotent_id('c1a41f3f-9dad-493e-9f09-3ff197d477cc')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020095 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +080096 # get volume id which created by type without prefix
Benny Kopilovaf136a92015-11-10 07:37:23 +020097 for volume_id in self.volume_id_list_without_prefix:
98 self._test_backend_name_reporting_by_volume_id(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +080099
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800100 @decorators.idempotent_id('f38e647f-ab42-4a31-a2e7-ca86a6485215')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800101 def test_backend_name_reporting_with_prefix(self):
102 # get volume id which created by type with prefix
Benny Kopilovaf136a92015-11-10 07:37:23 +0200103 for volume_id in self.volume_id_list_with_prefix:
104 self._test_backend_name_reporting_by_volume_id(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800105
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800106 @decorators.idempotent_id('46435ab1-a0af-4401-8373-f14e66b0dd58')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800107 def test_backend_name_distinction(self):
Benny Kopilovaf136a92015-11-10 07:37:23 +0200108 # get volume ids which created by type without prefix
109 self._test_backend_name_distinction(self.volume_id_list_without_prefix)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800110
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800111 @decorators.idempotent_id('4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800112 def test_backend_name_distinction_with_prefix(self):
Benny Kopilovaf136a92015-11-10 07:37:23 +0200113 # get volume ids which created by type without prefix
114 self._test_backend_name_distinction(self.volume_id_list_with_prefix)
115
116 def _get_volume_host(self, volume_id):
117 return self.admin_volume_client.show_volume(
118 volume_id)['volume']['os-vol-host-attr:host']
Jerry Cai6e5eed22014-05-08 20:48:08 +0800119
120 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200121 # this test checks if os-vol-attr:host is populated correctly after
122 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100123 # if multi-backend is enabled: os-vol-attr:host should be like:
124 # host@backend_name
John Warren6177c9e2015-08-19 20:00:17 +0000125 volume = self.admin_volume_client.show_volume(volume_id)['volume']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100126
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200127 volume1_host = volume['os-vol-host-attr:host']
128 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800129 volume_id)
Béla Vancsics64862f72016-11-08 09:12:31 +0100130 self.assertGreater(len(volume1_host.split("@")), 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100131
Benny Kopilovaf136a92015-11-10 07:37:23 +0200132 def _test_backend_name_distinction(self, volume_id_list):
133 # this test checks that the volumes created at setUp don't
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200134 # belong to the same backend (if they are, than the
135 # volume backend distinction is not working properly)
Benny Kopilovaf136a92015-11-10 07:37:23 +0200136 volume_hosts = [self._get_volume_host(volume) for volume in
137 volume_id_list]
138 # assert that volumes are each created on separate hosts:
139 msg = ("volumes %s were created in the same backend" % ", "
140 .join(volume_hosts))
141 six.assertCountEqual(self, volume_hosts, set(volume_hosts), msg)