blob: 65c4bd37e0ea5e837377365c13d612fa17bb83b4 [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
Sean Dague1937d092013-05-17 16:36:38 -040013from tempest.api.volume import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090014from tempest.common.utils import data_utils
Matthew Treinish4d352bc2014-01-29 18:29:18 +000015from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040016from tempest.openstack.common import log as logging
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090017from tempest import test
Jérôme Gallard86551ce2013-03-08 11:41:26 +010018
Matthew Treinish4d352bc2014-01-29 18:29:18 +000019CONF = config.CONF
20
Jérôme Gallard86551ce2013-03-08 11:41:26 +010021LOG = logging.getLogger(__name__)
22
23
Chandan Kumar449e4c02014-09-12 07:26:19 -040024class VolumeMultiBackendV2Test(base.BaseVolumeAdminTest):
Jérôme Gallard86551ce2013-03-08 11:41:26 +010025 _interface = "json"
26
Jérôme Gallard86551ce2013-03-08 11:41:26 +010027 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010028 def resource_setup(cls):
Chandan Kumar449e4c02014-09-12 07:26:19 -040029 super(VolumeMultiBackendV2Test, cls).resource_setup()
Matthew Treinish4d352bc2014-01-29 18:29:18 +000030 if not CONF.volume_feature_enabled.multi_backend:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020031 raise cls.skipException("Cinder multi-backend feature disabled")
32
Matthew Treinish4d352bc2014-01-29 18:29:18 +000033 cls.backend1_name = CONF.volume.backend1_name
34 cls.backend2_name = CONF.volume.backend2_name
Jérôme Gallard86551ce2013-03-08 11:41:26 +010035
Chandan Kumar449e4c02014-09-12 07:26:19 -040036 cls.name_field = cls.special_fields['name_field']
Giulio Fidentef4fa8942013-05-28 18:48:03 +020037 cls.volume_type_id_list = []
Jerry Cai6e5eed22014-05-08 20:48:08 +080038 cls.volume_id_list_with_prefix = []
39 cls.volume_id_list_without_prefix = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010040
Jerry Cai6e5eed22014-05-08 20:48:08 +080041 # Volume/Type creation (uses volume_backend_name)
42 cls._create_type_and_volume(cls.backend1_name, False)
43 # Volume/Type creation (uses capabilities:volume_backend_name)
44 cls._create_type_and_volume(cls.backend1_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080045
46 if cls.backend1_name != cls.backend2_name:
47 # Volume/Type creation (uses backend2_name)
Jerry Cai6e5eed22014-05-08 20:48:08 +080048 cls._create_type_and_volume(cls.backend2_name, False)
49 # Volume/Type creation (uses capabilities:volume_backend_name)
50 cls._create_type_and_volume(cls.backend2_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080051
Jerry Cai6e5eed22014-05-08 20:48:08 +080052 @classmethod
53 def _create_type_and_volume(self, backend_name_key, with_prefix):
54 # Volume/Type creation
55 type_name = data_utils.rand_name('Type')
56 vol_name = data_utils.rand_name('Volume')
57 spec_key_with_prefix = "capabilities:volume_backend_name"
58 spec_key_without_prefix = "volume_backend_name"
59 if with_prefix:
60 extra_specs = {spec_key_with_prefix: backend_name_key}
61 else:
62 extra_specs = {spec_key_without_prefix: backend_name_key}
Joseph Lanoux6809bab2014-12-18 14:57:18 +000063 self.type = self.volume_types_client.create_volume_type(
Jerry Cai6e5eed22014-05-08 20:48:08 +080064 type_name, extra_specs=extra_specs)
65 self.volume_type_id_list.append(self.type['id'])
66
Chandan Kumar449e4c02014-09-12 07:26:19 -040067 params = {self.name_field: vol_name, 'volume_type': type_name}
68
Joseph Lanoux6809bab2014-12-18 14:57:18 +000069 self.volume = self.admin_volume_client.create_volume(size=1,
70 **params)
Jerry Cai6e5eed22014-05-08 20:48:08 +080071 if with_prefix:
72 self.volume_id_list_with_prefix.append(self.volume['id'])
73 else:
74 self.volume_id_list_without_prefix.append(
75 self.volume['id'])
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053076 self.admin_volume_client.wait_for_volume_status(
git-harry9c9f6262014-09-11 15:26:23 +010077 self.volume['id'], 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010078
Jérôme Gallard86551ce2013-03-08 11:41:26 +010079 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010080 def resource_cleanup(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020081 # volumes deletion
Jerry Cai6e5eed22014-05-08 20:48:08 +080082 vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
83 for volume_id in vid_prefix:
Chandan Kumaree3f4bd2014-10-29 23:09:29 +053084 cls.admin_volume_client.delete_volume(volume_id)
85 cls.admin_volume_client.wait_for_resource_deletion(volume_id)
Jerry Cai6e5eed22014-05-08 20:48:08 +080086
87 vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
88 for volume_id in vid_no_pre:
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)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010091
Attila Fazekasf7f34f92013-08-01 17:01:44 +020092 # volume types deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080093 volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
94 for volume_type_id in volume_type_id_list:
ghanshyam1e0a9f82014-10-09 14:15:26 +090095 cls.volume_types_client.delete_volume_type(volume_type_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010096
Chandan Kumar449e4c02014-09-12 07:26:19 -040097 super(VolumeMultiBackendV2Test, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050098
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090099 @test.attr(type='smoke')
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200100 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +0800101 # get volume id which created by type without prefix
102 volume_id = self.volume_id_list_without_prefix[0]
103 self._test_backend_name_reporting_by_volume_id(volume_id)
104
105 @test.attr(type='smoke')
106 def test_backend_name_reporting_with_prefix(self):
107 # get volume id which created by type with prefix
108 volume_id = self.volume_id_list_with_prefix[0]
109 self._test_backend_name_reporting_by_volume_id(volume_id)
110
111 @test.attr(type='gate')
112 def test_backend_name_distinction(self):
113 if self.backend1_name == self.backend2_name:
114 raise self.skipException("backends configured with same name")
115 # get volume id which created by type without prefix
116 volume1_id = self.volume_id_list_without_prefix[0]
117 volume2_id = self.volume_id_list_without_prefix[1]
118 self._test_backend_name_distinction(volume1_id, volume2_id)
119
120 @test.attr(type='gate')
121 def test_backend_name_distinction_with_prefix(self):
122 if self.backend1_name == self.backend2_name:
123 raise self.skipException("backends configured with same name")
124 # get volume id which created by type without prefix
125 volume1_id = self.volume_id_list_with_prefix[0]
126 volume2_id = self.volume_id_list_with_prefix[1]
127 self._test_backend_name_distinction(volume1_id, volume2_id)
128
129 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200130 # this test checks if os-vol-attr:host is populated correctly after
131 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100132 # if multi-backend is enabled: os-vol-attr:host should be like:
133 # host@backend_name
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000134 volume = self.admin_volume_client.get_volume(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100135
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200136 volume1_host = volume['os-vol-host-attr:host']
137 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800138 volume_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200139 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100140
Jerry Cai6e5eed22014-05-08 20:48:08 +0800141 def _test_backend_name_distinction(self, volume1_id, volume2_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200142 # this test checks that the two volumes created at setUp don't
143 # belong to the same backend (if they are, than the
144 # volume backend distinction is not working properly)
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000145 volume = self.admin_volume_client.get_volume(volume1_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200146 volume1_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100147
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000148 volume = self.admin_volume_client.get_volume(volume2_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200149 volume2_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100150
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200151 msg = ("volumes %s and %s were created in the same backend" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800152 (volume1_id, volume2_id))
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200153 self.assertNotEqual(volume1_host, volume2_host, msg)
Chandan Kumar449e4c02014-09-12 07:26:19 -0400154
155
156class VolumeMultiBackendV1Test(VolumeMultiBackendV2Test):
157 _api_version = 1