blob: c5c70d2a715837000bc9898c8334c8f877e67db7 [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
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070023class VolumeMultiBackendTest(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):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070027 super(VolumeMultiBackendTest, cls).skip_checks()
Rohan Kanade05749152015-01-30 17:15:18 +053028
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
lkuchlan373f9852018-06-10 14:16:15 +030032 if len(set(CONF.volume.backend_names)) < 2:
33 raise cls.skipException("Requires at least two different "
34 "backend names")
35
Rohan Kanade05749152015-01-30 17:15:18 +053036 @classmethod
37 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070038 super(VolumeMultiBackendTest, cls).resource_setup()
bkopilov27905cc2016-04-12 14:29:13 +030039
40 # read backend name from a list .
zhufl7e0c9b62017-02-16 11:25:34 +080041 backend_names = set(CONF.volume.backend_names)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010042
Jerry Cai6e5eed22014-05-08 20:48:08 +080043 cls.volume_id_list_with_prefix = []
44 cls.volume_id_list_without_prefix = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010045
Jerry Cai6e5eed22014-05-08 20:48:08 +080046 # Volume/Type creation (uses volume_backend_name)
Benny Kopilovaf136a92015-11-10 07:37:23 +020047 # It is not allowed to create the same backend name twice
zhufl7e0c9b62017-02-16 11:25:34 +080048 for backend_name in backend_names:
Benny Kopilovaf136a92015-11-10 07:37:23 +020049 # Volume/Type creation (uses backend_name)
50 cls._create_type_and_volume(backend_name, False)
Jerry Cai6e5eed22014-05-08 20:48:08 +080051 # Volume/Type creation (uses capabilities:volume_backend_name)
Benny Kopilovaf136a92015-11-10 07:37:23 +020052 cls._create_type_and_volume(backend_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080053
Jerry Cai6e5eed22014-05-08 20:48:08 +080054 @classmethod
zhufle27c0e32016-08-17 14:45:30 +080055 def _create_type_and_volume(cls, backend_name_key, with_prefix):
Jerry Cai6e5eed22014-05-08 20:48:08 +080056 # Volume/Type creation
zhuflc6ce5392016-08-17 14:34:37 +080057 type_name = data_utils.rand_name(cls.__name__ + '-Type')
58 vol_name = data_utils.rand_name(cls.__name__ + '-Volume')
Jerry Cai6e5eed22014-05-08 20:48:08 +080059 spec_key_with_prefix = "capabilities:volume_backend_name"
60 spec_key_without_prefix = "volume_backend_name"
61 if with_prefix:
62 extra_specs = {spec_key_with_prefix: backend_name_key}
63 else:
64 extra_specs = {spec_key_without_prefix: backend_name_key}
zhufl8bd576f2017-02-16 11:37:38 +080065 cls.create_volume_type(name=type_name,
66 extra_specs=extra_specs)
Jerry Cai6e5eed22014-05-08 20:48:08 +080067
zhufla57530c2017-03-23 11:38:12 +080068 params = {'name': vol_name, 'volume_type': type_name,
Ken'ichi Ohmichiadb905e2016-08-26 15:16:23 -070069 'size': CONF.volume.volume_size}
lkuchlanb830fae1d2017-09-04 13:35:38 +030070 cls.volume = cls.create_volume(**params)
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
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080079 @decorators.idempotent_id('c1a41f3f-9dad-493e-9f09-3ff197d477cc')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020080 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +080081 # get volume id which created by type without prefix
Benny Kopilovaf136a92015-11-10 07:37:23 +020082 for volume_id in self.volume_id_list_without_prefix:
83 self._test_backend_name_reporting_by_volume_id(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +080084
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080085 @decorators.idempotent_id('f38e647f-ab42-4a31-a2e7-ca86a6485215')
Jerry Cai6e5eed22014-05-08 20:48:08 +080086 def test_backend_name_reporting_with_prefix(self):
87 # get volume id which created by type with prefix
Benny Kopilovaf136a92015-11-10 07:37:23 +020088 for volume_id in self.volume_id_list_with_prefix:
89 self._test_backend_name_reporting_by_volume_id(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +080090
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080091 @decorators.idempotent_id('46435ab1-a0af-4401-8373-f14e66b0dd58')
Jerry Cai6e5eed22014-05-08 20:48:08 +080092 def test_backend_name_distinction(self):
Benny Kopilovaf136a92015-11-10 07:37:23 +020093 # get volume ids which created by type without prefix
94 self._test_backend_name_distinction(self.volume_id_list_without_prefix)
Jerry Cai6e5eed22014-05-08 20:48:08 +080095
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080096 @decorators.idempotent_id('4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed')
Jerry Cai6e5eed22014-05-08 20:48:08 +080097 def test_backend_name_distinction_with_prefix(self):
Benny Kopilovaf136a92015-11-10 07:37:23 +020098 # get volume ids which created by type without prefix
99 self._test_backend_name_distinction(self.volume_id_list_with_prefix)
100
101 def _get_volume_host(self, volume_id):
102 return self.admin_volume_client.show_volume(
103 volume_id)['volume']['os-vol-host-attr:host']
Jerry Cai6e5eed22014-05-08 20:48:08 +0800104
105 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200106 # this test checks if os-vol-attr:host is populated correctly after
107 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100108 # if multi-backend is enabled: os-vol-attr:host should be like:
109 # host@backend_name
John Warren6177c9e2015-08-19 20:00:17 +0000110 volume = self.admin_volume_client.show_volume(volume_id)['volume']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100111
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200112 volume1_host = volume['os-vol-host-attr:host']
113 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800114 volume_id)
Béla Vancsics64862f72016-11-08 09:12:31 +0100115 self.assertGreater(len(volume1_host.split("@")), 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100116
Benny Kopilovaf136a92015-11-10 07:37:23 +0200117 def _test_backend_name_distinction(self, volume_id_list):
118 # this test checks that the volumes created at setUp don't
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200119 # belong to the same backend (if they are, than the
120 # volume backend distinction is not working properly)
Benny Kopilovaf136a92015-11-10 07:37:23 +0200121 volume_hosts = [self._get_volume_host(volume) for volume in
122 volume_id_list]
123 # assert that volumes are each created on separate hosts:
124 msg = ("volumes %s were created in the same backend" % ", "
125 .join(volume_hosts))
126 six.assertCountEqual(self, volume_hosts, set(volume_hosts), msg)