blob: f68f19a9f1cd09f6cd0f51d57bbe88ee98e979d8 [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120015from tempest.common.utils import data_utils
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050016from tempest.common import waiters
Matthew Treinish4d352bc2014-01-29 18:29:18 +000017from tempest import config
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 .
37 cls.backend_names = set(CONF.volume.backend_names)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010038
Chandan Kumar449e4c02014-09-12 07:26:19 -040039 cls.name_field = cls.special_fields['name_field']
Jerry Cai6e5eed22014-05-08 20:48:08 +080040 cls.volume_id_list_with_prefix = []
41 cls.volume_id_list_without_prefix = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010042
Jerry Cai6e5eed22014-05-08 20:48:08 +080043 # Volume/Type creation (uses volume_backend_name)
Benny Kopilovaf136a92015-11-10 07:37:23 +020044 # It is not allowed to create the same backend name twice
45 if len(cls.backend_names) < 2:
46 raise cls.skipException("Requires at least two different "
47 "backend names")
48 for backend_name in cls.backend_names:
49 # 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
Ken'ichi Ohmichiadb905e2016-08-26 15:16:23 -070068 params = {cls.name_field: vol_name, 'volume_type': type_name,
69 'size': CONF.volume.volume_size}
zhufle27c0e32016-08-17 14:45:30 +080070 cls.volume = cls.admin_volume_client.create_volume(
John Warren6177c9e2015-08-19 20:00:17 +000071 **params)['volume']
Jerry Cai6e5eed22014-05-08 20:48:08 +080072 if with_prefix:
zhufle27c0e32016-08-17 14:45:30 +080073 cls.volume_id_list_with_prefix.append(cls.volume['id'])
Jerry Cai6e5eed22014-05-08 20:48:08 +080074 else:
zhufle27c0e32016-08-17 14:45:30 +080075 cls.volume_id_list_without_prefix.append(
76 cls.volume['id'])
77 waiters.wait_for_volume_status(cls.admin_volume_client,
78 cls.volume['id'], 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010079
Jérôme Gallard86551ce2013-03-08 11:41:26 +010080 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010081 def resource_cleanup(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020082 # volumes deletion
Jerry Cai6e5eed22014-05-08 20:48:08 +080083 vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
84 for volume_id in vid_prefix:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053085 cls.admin_volume_client.delete_volume(volume_id)
86 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +080087
88 vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
89 for volume_id in vid_no_pre:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053090 cls.admin_volume_client.delete_volume(volume_id)
91 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010092
Chandan Kumar449e4c02014-09-12 07:26:19 -040093 super(VolumeMultiBackendV2Test, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050094
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080095 @decorators.idempotent_id('c1a41f3f-9dad-493e-9f09-3ff197d477cc')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020096 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +080097 # get volume id which created by type without prefix
Benny Kopilovaf136a92015-11-10 07:37:23 +020098 for volume_id in self.volume_id_list_without_prefix:
99 self._test_backend_name_reporting_by_volume_id(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800100
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800101 @decorators.idempotent_id('f38e647f-ab42-4a31-a2e7-ca86a6485215')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800102 def test_backend_name_reporting_with_prefix(self):
103 # get volume id which created by type with prefix
Benny Kopilovaf136a92015-11-10 07:37:23 +0200104 for volume_id in self.volume_id_list_with_prefix:
105 self._test_backend_name_reporting_by_volume_id(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800106
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800107 @decorators.idempotent_id('46435ab1-a0af-4401-8373-f14e66b0dd58')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800108 def test_backend_name_distinction(self):
Benny Kopilovaf136a92015-11-10 07:37:23 +0200109 # get volume ids which created by type without prefix
110 self._test_backend_name_distinction(self.volume_id_list_without_prefix)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800111
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800112 @decorators.idempotent_id('4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800113 def test_backend_name_distinction_with_prefix(self):
Benny Kopilovaf136a92015-11-10 07:37:23 +0200114 # get volume ids which created by type without prefix
115 self._test_backend_name_distinction(self.volume_id_list_with_prefix)
116
117 def _get_volume_host(self, volume_id):
118 return self.admin_volume_client.show_volume(
119 volume_id)['volume']['os-vol-host-attr:host']
Jerry Cai6e5eed22014-05-08 20:48:08 +0800120
121 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200122 # this test checks if os-vol-attr:host is populated correctly after
123 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100124 # if multi-backend is enabled: os-vol-attr:host should be like:
125 # host@backend_name
John Warren6177c9e2015-08-19 20:00:17 +0000126 volume = self.admin_volume_client.show_volume(volume_id)['volume']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100127
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200128 volume1_host = volume['os-vol-host-attr:host']
129 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800130 volume_id)
Béla Vancsics64862f72016-11-08 09:12:31 +0100131 self.assertGreater(len(volume1_host.split("@")), 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100132
Benny Kopilovaf136a92015-11-10 07:37:23 +0200133 def _test_backend_name_distinction(self, volume_id_list):
134 # this test checks that the volumes created at setUp don't
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200135 # belong to the same backend (if they are, than the
136 # volume backend distinction is not working properly)
Benny Kopilovaf136a92015-11-10 07:37:23 +0200137 volume_hosts = [self._get_volume_host(volume) for volume in
138 volume_id_list]
139 # assert that volumes are each created on separate hosts:
140 msg = ("volumes %s were created in the same backend" % ", "
141 .join(volume_hosts))
142 six.assertCountEqual(self, volume_hosts, set(volume_hosts), msg)
Chandan Kumar449e4c02014-09-12 07:26:19 -0400143
144
145class VolumeMultiBackendV1Test(VolumeMultiBackendV2Test):
146 _api_version = 1