blob: 5b65c84fc9362f6521b10815db7fb4f021d62201 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000013from oslo_log import log as logging
Matthew Treinish01472ff2015-02-20 17:26:52 -050014
Sean Dague1937d092013-05-17 16:36:38 -040015from tempest.api.volume import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120016from tempest.common.utils import data_utils
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 +010022LOG = logging.getLogger(__name__)
23
24
Chandan Kumar449e4c02014-09-12 07:26:19 -040025class VolumeMultiBackendV2Test(base.BaseVolumeAdminTest):
Jérôme Gallard86551ce2013-03-08 11:41:26 +010026
Jérôme Gallard86551ce2013-03-08 11:41:26 +010027 @classmethod
Rohan Kanade05749152015-01-30 17:15:18 +053028 def skip_checks(cls):
29 super(VolumeMultiBackendV2Test, cls).skip_checks()
30
Matthew Treinish4d352bc2014-01-29 18:29:18 +000031 if not CONF.volume_feature_enabled.multi_backend:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020032 raise cls.skipException("Cinder multi-backend feature disabled")
33
Rohan Kanade05749152015-01-30 17:15:18 +053034 @classmethod
35 def resource_setup(cls):
36 super(VolumeMultiBackendV2Test, cls).resource_setup()
37
Matthew Treinish4d352bc2014-01-29 18:29:18 +000038 cls.backend1_name = CONF.volume.backend1_name
39 cls.backend2_name = CONF.volume.backend2_name
Jérôme Gallard86551ce2013-03-08 11:41:26 +010040
Chandan Kumar449e4c02014-09-12 07:26:19 -040041 cls.name_field = cls.special_fields['name_field']
Giulio Fidentef4fa8942013-05-28 18:48:03 +020042 cls.volume_type_id_list = []
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)
47 cls._create_type_and_volume(cls.backend1_name, False)
48 # Volume/Type creation (uses capabilities:volume_backend_name)
49 cls._create_type_and_volume(cls.backend1_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080050
51 if cls.backend1_name != cls.backend2_name:
52 # Volume/Type creation (uses backend2_name)
Jerry Cai6e5eed22014-05-08 20:48:08 +080053 cls._create_type_and_volume(cls.backend2_name, False)
54 # Volume/Type creation (uses capabilities:volume_backend_name)
55 cls._create_type_and_volume(cls.backend2_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080056
Jerry Cai6e5eed22014-05-08 20:48:08 +080057 @classmethod
58 def _create_type_and_volume(self, backend_name_key, with_prefix):
59 # Volume/Type creation
60 type_name = data_utils.rand_name('Type')
61 vol_name = data_utils.rand_name('Volume')
62 spec_key_with_prefix = "capabilities:volume_backend_name"
63 spec_key_without_prefix = "volume_backend_name"
64 if with_prefix:
65 extra_specs = {spec_key_with_prefix: backend_name_key}
66 else:
67 extra_specs = {spec_key_without_prefix: backend_name_key}
Joseph Lanoux6809bab2014-12-18 14:57:18 +000068 self.type = self.volume_types_client.create_volume_type(
Jerry Cai6e5eed22014-05-08 20:48:08 +080069 type_name, extra_specs=extra_specs)
70 self.volume_type_id_list.append(self.type['id'])
71
Chandan Kumar449e4c02014-09-12 07:26:19 -040072 params = {self.name_field: vol_name, 'volume_type': type_name}
73
John Warren6177c9e2015-08-19 20:00:17 +000074 self.volume = self.admin_volume_client.create_volume(
75 **params)['volume']
Jerry Cai6e5eed22014-05-08 20:48:08 +080076 if with_prefix:
77 self.volume_id_list_with_prefix.append(self.volume['id'])
78 else:
79 self.volume_id_list_without_prefix.append(
80 self.volume['id'])
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053081 self.admin_volume_client.wait_for_volume_status(
git-harry9c9f6262014-09-11 15:26:23 +010082 self.volume['id'], 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010083
Jérôme Gallard86551ce2013-03-08 11:41:26 +010084 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010085 def resource_cleanup(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020086 # volumes deletion
Jerry Cai6e5eed22014-05-08 20:48:08 +080087 vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
88 for volume_id in vid_prefix:
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)
Jerry Cai6e5eed22014-05-08 20:48:08 +080091
92 vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
93 for volume_id in vid_no_pre:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053094 cls.admin_volume_client.delete_volume(volume_id)
95 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010096
Attila Fazekasf7f34f92013-08-01 17:01:44 +020097 # volume types deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080098 volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
99 for volume_type_id in volume_type_id_list:
ghanshyam1e0a9f82014-10-09 14:15:26 +0900100 cls.volume_types_client.delete_volume_type(volume_type_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100101
Chandan Kumar449e4c02014-09-12 07:26:19 -0400102 super(VolumeMultiBackendV2Test, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -0500103
Chris Hoge7579c1a2015-02-26 14:12:15 -0800104 @test.idempotent_id('c1a41f3f-9dad-493e-9f09-3ff197d477cc')
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200105 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +0800106 # get volume id which created by type without prefix
107 volume_id = self.volume_id_list_without_prefix[0]
108 self._test_backend_name_reporting_by_volume_id(volume_id)
109
Chris Hoge7579c1a2015-02-26 14:12:15 -0800110 @test.idempotent_id('f38e647f-ab42-4a31-a2e7-ca86a6485215')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800111 def test_backend_name_reporting_with_prefix(self):
112 # get volume id which created by type with prefix
113 volume_id = self.volume_id_list_with_prefix[0]
114 self._test_backend_name_reporting_by_volume_id(volume_id)
115
Chris Hoge7579c1a2015-02-26 14:12:15 -0800116 @test.idempotent_id('46435ab1-a0af-4401-8373-f14e66b0dd58')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800117 def test_backend_name_distinction(self):
118 if self.backend1_name == self.backend2_name:
119 raise self.skipException("backends configured with same name")
120 # get volume id which created by type without prefix
121 volume1_id = self.volume_id_list_without_prefix[0]
122 volume2_id = self.volume_id_list_without_prefix[1]
123 self._test_backend_name_distinction(volume1_id, volume2_id)
124
Chris Hoge7579c1a2015-02-26 14:12:15 -0800125 @test.idempotent_id('4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800126 def test_backend_name_distinction_with_prefix(self):
127 if self.backend1_name == self.backend2_name:
128 raise self.skipException("backends configured with same name")
129 # get volume id which created by type without prefix
130 volume1_id = self.volume_id_list_with_prefix[0]
131 volume2_id = self.volume_id_list_with_prefix[1]
132 self._test_backend_name_distinction(volume1_id, volume2_id)
133
134 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200135 # this test checks if os-vol-attr:host is populated correctly after
136 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100137 # if multi-backend is enabled: os-vol-attr:host should be like:
138 # host@backend_name
John Warren6177c9e2015-08-19 20:00:17 +0000139 volume = self.admin_volume_client.show_volume(volume_id)['volume']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100140
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200141 volume1_host = volume['os-vol-host-attr:host']
142 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800143 volume_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200144 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100145
Jerry Cai6e5eed22014-05-08 20:48:08 +0800146 def _test_backend_name_distinction(self, volume1_id, volume2_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200147 # this test checks that the two volumes created at setUp don't
148 # belong to the same backend (if they are, than the
149 # volume backend distinction is not working properly)
John Warren6177c9e2015-08-19 20:00:17 +0000150 volume = self.admin_volume_client.show_volume(volume1_id)['volume']
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200151 volume1_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100152
John Warren6177c9e2015-08-19 20:00:17 +0000153 volume = self.admin_volume_client.show_volume(volume2_id)['volume']
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200154 volume2_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100155
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200156 msg = ("volumes %s and %s were created in the same backend" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800157 (volume1_id, volume2_id))
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200158 self.assertNotEqual(volume1_host, volume2_host, msg)
Chandan Kumar449e4c02014-09-12 07:26:19 -0400159
160
161class VolumeMultiBackendV1Test(VolumeMultiBackendV2Test):
162 _api_version = 1