blob: 09ec075c2b275047916cdd60f85812bb10ba16d7 [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050013from tempest_lib.common.utils import data_utils
14
Sean Dague1937d092013-05-17 16:36:38 -040015from tempest.api.volume import base
Matthew Treinish4d352bc2014-01-29 18:29:18 +000016from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040017from tempest.openstack.common import log as logging
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
Markus Zoeller3d2a21c2015-02-27 12:04:22 +010074 self.volume = self.admin_volume_client.create_volume(**params)
Jerry Cai6e5eed22014-05-08 20:48:08 +080075 if with_prefix:
76 self.volume_id_list_with_prefix.append(self.volume['id'])
77 else:
78 self.volume_id_list_without_prefix.append(
79 self.volume['id'])
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053080 self.admin_volume_client.wait_for_volume_status(
git-harry9c9f6262014-09-11 15:26:23 +010081 self.volume['id'], 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010082
Jérôme Gallard86551ce2013-03-08 11:41:26 +010083 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010084 def resource_cleanup(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020085 # volumes deletion
Jerry Cai6e5eed22014-05-08 20:48:08 +080086 vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
87 for volume_id in vid_prefix:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053088 cls.admin_volume_client.delete_volume(volume_id)
89 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +080090
91 vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
92 for volume_id in vid_no_pre:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053093 cls.admin_volume_client.delete_volume(volume_id)
94 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010095
Attila Fazekasf7f34f92013-08-01 17:01:44 +020096 # volume types deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080097 volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
98 for volume_type_id in volume_type_id_list:
ghanshyam1e0a9f82014-10-09 14:15:26 +090099 cls.volume_types_client.delete_volume_type(volume_type_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100100
Chandan Kumar449e4c02014-09-12 07:26:19 -0400101 super(VolumeMultiBackendV2Test, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -0500102
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900103 @test.attr(type='smoke')
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
110 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800111 @test.idempotent_id('f38e647f-ab42-4a31-a2e7-ca86a6485215')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800112 def test_backend_name_reporting_with_prefix(self):
113 # get volume id which created by type with prefix
114 volume_id = self.volume_id_list_with_prefix[0]
115 self._test_backend_name_reporting_by_volume_id(volume_id)
116
117 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800118 @test.idempotent_id('46435ab1-a0af-4401-8373-f14e66b0dd58')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800119 def test_backend_name_distinction(self):
120 if self.backend1_name == self.backend2_name:
121 raise self.skipException("backends configured with same name")
122 # get volume id which created by type without prefix
123 volume1_id = self.volume_id_list_without_prefix[0]
124 volume2_id = self.volume_id_list_without_prefix[1]
125 self._test_backend_name_distinction(volume1_id, volume2_id)
126
127 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800128 @test.idempotent_id('4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800129 def test_backend_name_distinction_with_prefix(self):
130 if self.backend1_name == self.backend2_name:
131 raise self.skipException("backends configured with same name")
132 # get volume id which created by type without prefix
133 volume1_id = self.volume_id_list_with_prefix[0]
134 volume2_id = self.volume_id_list_with_prefix[1]
135 self._test_backend_name_distinction(volume1_id, volume2_id)
136
137 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200138 # this test checks if os-vol-attr:host is populated correctly after
139 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100140 # if multi-backend is enabled: os-vol-attr:host should be like:
141 # host@backend_name
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000142 volume = self.admin_volume_client.get_volume(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100143
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200144 volume1_host = volume['os-vol-host-attr:host']
145 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800146 volume_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200147 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100148
Jerry Cai6e5eed22014-05-08 20:48:08 +0800149 def _test_backend_name_distinction(self, volume1_id, volume2_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200150 # this test checks that the two volumes created at setUp don't
151 # belong to the same backend (if they are, than the
152 # volume backend distinction is not working properly)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000153 volume = self.admin_volume_client.get_volume(volume1_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200154 volume1_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100155
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000156 volume = self.admin_volume_client.get_volume(volume2_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200157 volume2_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100158
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200159 msg = ("volumes %s and %s were created in the same backend" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800160 (volume1_id, volume2_id))
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200161 self.assertNotEqual(volume1_host, volume2_host, msg)
Chandan Kumar449e4c02014-09-12 07:26:19 -0400162
163
164class VolumeMultiBackendV1Test(VolumeMultiBackendV2Test):
165 _api_version = 1