blob: b7c42365ab788567822c42c7bb9cb5608bf87d22 [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
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090018from tempest import test
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']
Giulio Fidentef4fa8942013-05-28 18:48:03 +020040 cls.volume_type_id_list = []
Jerry Cai6e5eed22014-05-08 20:48:08 +080041 cls.volume_id_list_with_prefix = []
42 cls.volume_id_list_without_prefix = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010043
Jerry Cai6e5eed22014-05-08 20:48:08 +080044 # Volume/Type creation (uses volume_backend_name)
Benny Kopilovaf136a92015-11-10 07:37:23 +020045 # It is not allowed to create the same backend name twice
46 if len(cls.backend_names) < 2:
47 raise cls.skipException("Requires at least two different "
48 "backend names")
49 for backend_name in cls.backend_names:
50 # Volume/Type creation (uses backend_name)
51 cls._create_type_and_volume(backend_name, False)
Jerry Cai6e5eed22014-05-08 20:48:08 +080052 # Volume/Type creation (uses capabilities:volume_backend_name)
Benny Kopilovaf136a92015-11-10 07:37:23 +020053 cls._create_type_and_volume(backend_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080054
Jerry Cai6e5eed22014-05-08 20:48:08 +080055 @classmethod
zhufle27c0e32016-08-17 14:45:30 +080056 def _create_type_and_volume(cls, backend_name_key, with_prefix):
Jerry Cai6e5eed22014-05-08 20:48:08 +080057 # Volume/Type creation
58 type_name = data_utils.rand_name('Type')
59 vol_name = data_utils.rand_name('Volume')
60 spec_key_with_prefix = "capabilities:volume_backend_name"
61 spec_key_without_prefix = "volume_backend_name"
62 if with_prefix:
63 extra_specs = {spec_key_with_prefix: backend_name_key}
64 else:
65 extra_specs = {spec_key_without_prefix: backend_name_key}
zhufle27c0e32016-08-17 14:45:30 +080066 cls.type = cls.create_volume_type(name=type_name,
67 extra_specs=extra_specs)
Jerry Cai6e5eed22014-05-08 20:48:08 +080068
zhufle27c0e32016-08-17 14:45:30 +080069 params = {cls.name_field: vol_name, 'volume_type': type_name}
Chandan Kumar449e4c02014-09-12 07:26:19 -040070
zhufle27c0e32016-08-17 14:45:30 +080071 cls.volume = cls.admin_volume_client.create_volume(
John Warren6177c9e2015-08-19 20:00:17 +000072 **params)['volume']
Jerry Cai6e5eed22014-05-08 20:48:08 +080073 if with_prefix:
zhufle27c0e32016-08-17 14:45:30 +080074 cls.volume_id_list_with_prefix.append(cls.volume['id'])
Jerry Cai6e5eed22014-05-08 20:48:08 +080075 else:
zhufle27c0e32016-08-17 14:45:30 +080076 cls.volume_id_list_without_prefix.append(
77 cls.volume['id'])
78 waiters.wait_for_volume_status(cls.admin_volume_client,
79 cls.volume['id'], 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010080
Jérôme Gallard86551ce2013-03-08 11:41:26 +010081 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010082 def resource_cleanup(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020083 # volumes deletion
Jerry Cai6e5eed22014-05-08 20:48:08 +080084 vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
85 for volume_id in vid_prefix:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053086 cls.admin_volume_client.delete_volume(volume_id)
87 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +080088
89 vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
90 for volume_id in vid_no_pre:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053091 cls.admin_volume_client.delete_volume(volume_id)
92 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010093
Chandan Kumar449e4c02014-09-12 07:26:19 -040094 super(VolumeMultiBackendV2Test, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050095
Chris Hoge7579c1a2015-02-26 14:12:15 -080096 @test.idempotent_id('c1a41f3f-9dad-493e-9f09-3ff197d477cc')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020097 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +080098 # get volume id which created by type without prefix
Benny Kopilovaf136a92015-11-10 07:37:23 +020099 for volume_id in self.volume_id_list_without_prefix:
100 self._test_backend_name_reporting_by_volume_id(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800101
Chris Hoge7579c1a2015-02-26 14:12:15 -0800102 @test.idempotent_id('f38e647f-ab42-4a31-a2e7-ca86a6485215')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800103 def test_backend_name_reporting_with_prefix(self):
104 # get volume id which created by type with prefix
Benny Kopilovaf136a92015-11-10 07:37:23 +0200105 for volume_id in self.volume_id_list_with_prefix:
106 self._test_backend_name_reporting_by_volume_id(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800107
Chris Hoge7579c1a2015-02-26 14:12:15 -0800108 @test.idempotent_id('46435ab1-a0af-4401-8373-f14e66b0dd58')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800109 def test_backend_name_distinction(self):
Benny Kopilovaf136a92015-11-10 07:37:23 +0200110 # get volume ids which created by type without prefix
111 self._test_backend_name_distinction(self.volume_id_list_without_prefix)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800112
Chris Hoge7579c1a2015-02-26 14:12:15 -0800113 @test.idempotent_id('4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800114 def test_backend_name_distinction_with_prefix(self):
Benny Kopilovaf136a92015-11-10 07:37:23 +0200115 # get volume ids which created by type without prefix
116 self._test_backend_name_distinction(self.volume_id_list_with_prefix)
117
118 def _get_volume_host(self, volume_id):
119 return self.admin_volume_client.show_volume(
120 volume_id)['volume']['os-vol-host-attr:host']
Jerry Cai6e5eed22014-05-08 20:48:08 +0800121
122 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200123 # this test checks if os-vol-attr:host is populated correctly after
124 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100125 # if multi-backend is enabled: os-vol-attr:host should be like:
126 # host@backend_name
John Warren6177c9e2015-08-19 20:00:17 +0000127 volume = self.admin_volume_client.show_volume(volume_id)['volume']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100128
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200129 volume1_host = volume['os-vol-host-attr:host']
130 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800131 volume_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200132 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100133
Benny Kopilovaf136a92015-11-10 07:37:23 +0200134 def _test_backend_name_distinction(self, volume_id_list):
135 # this test checks that the volumes created at setUp don't
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200136 # belong to the same backend (if they are, than the
137 # volume backend distinction is not working properly)
Benny Kopilovaf136a92015-11-10 07:37:23 +0200138 volume_hosts = [self._get_volume_host(volume) for volume in
139 volume_id_list]
140 # assert that volumes are each created on separate hosts:
141 msg = ("volumes %s were created in the same backend" % ", "
142 .join(volume_hosts))
143 six.assertCountEqual(self, volume_hosts, set(volume_hosts), msg)
Chandan Kumar449e4c02014-09-12 07:26:19 -0400144
145
146class VolumeMultiBackendV1Test(VolumeMultiBackendV2Test):
147 _api_version = 1