blob: bbdf4a85483851dba6b259852ca6a7014b297412 [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(
John Warrend053ded2015-08-13 15:22:48 +000069 type_name, extra_specs=extra_specs)['volume_type']
Jerry Cai6e5eed22014-05-08 20:48:08 +080070 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
Chris Hoge7579c1a2015-02-26 14:12:15 -0800103 @test.idempotent_id('c1a41f3f-9dad-493e-9f09-3ff197d477cc')
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200104 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +0800105 # get volume id which created by type without prefix
106 volume_id = self.volume_id_list_without_prefix[0]
107 self._test_backend_name_reporting_by_volume_id(volume_id)
108
Chris Hoge7579c1a2015-02-26 14:12:15 -0800109 @test.idempotent_id('f38e647f-ab42-4a31-a2e7-ca86a6485215')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800110 def test_backend_name_reporting_with_prefix(self):
111 # get volume id which created by type with prefix
112 volume_id = self.volume_id_list_with_prefix[0]
113 self._test_backend_name_reporting_by_volume_id(volume_id)
114
Chris Hoge7579c1a2015-02-26 14:12:15 -0800115 @test.idempotent_id('46435ab1-a0af-4401-8373-f14e66b0dd58')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800116 def test_backend_name_distinction(self):
117 if self.backend1_name == self.backend2_name:
118 raise self.skipException("backends configured with same name")
119 # get volume id which created by type without prefix
120 volume1_id = self.volume_id_list_without_prefix[0]
121 volume2_id = self.volume_id_list_without_prefix[1]
122 self._test_backend_name_distinction(volume1_id, volume2_id)
123
Chris Hoge7579c1a2015-02-26 14:12:15 -0800124 @test.idempotent_id('4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed')
Jerry Cai6e5eed22014-05-08 20:48:08 +0800125 def test_backend_name_distinction_with_prefix(self):
126 if self.backend1_name == self.backend2_name:
127 raise self.skipException("backends configured with same name")
128 # get volume id which created by type without prefix
129 volume1_id = self.volume_id_list_with_prefix[0]
130 volume2_id = self.volume_id_list_with_prefix[1]
131 self._test_backend_name_distinction(volume1_id, volume2_id)
132
133 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200134 # this test checks if os-vol-attr:host is populated correctly after
135 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100136 # if multi-backend is enabled: os-vol-attr:host should be like:
137 # host@backend_name
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000138 volume = self.admin_volume_client.show_volume(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100139
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200140 volume1_host = volume['os-vol-host-attr:host']
141 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800142 volume_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200143 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100144
Jerry Cai6e5eed22014-05-08 20:48:08 +0800145 def _test_backend_name_distinction(self, volume1_id, volume2_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200146 # this test checks that the two volumes created at setUp don't
147 # belong to the same backend (if they are, than the
148 # volume backend distinction is not working properly)
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000149 volume = self.admin_volume_client.show_volume(volume1_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200150 volume1_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100151
Ken'ichi Ohmichi35798fb2015-04-06 01:22:41 +0000152 volume = self.admin_volume_client.show_volume(volume2_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200153 volume2_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100154
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200155 msg = ("volumes %s and %s were created in the same backend" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800156 (volume1_id, volume2_id))
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200157 self.assertNotEqual(volume1_host, volume2_host, msg)
Chandan Kumar449e4c02014-09-12 07:26:19 -0400158
159
160class VolumeMultiBackendV1Test(VolumeMultiBackendV2Test):
161 _api_version = 1