blob: 6f2ee06608e2068272e05c827182ad8fd5a59806 [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
Zhi Kun Liubb363a22013-11-28 18:47:39 +080024class VolumeMultiBackendTest(base.BaseVolumeV1AdminTest):
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):
29 super(VolumeMultiBackendTest, 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
Matthew Treinish4d2e5792014-02-07 22:24:19 +000036 cls.volume_client = cls.os_adm.volumes_client
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}
ghanshyam1e0a9f82014-10-09 14:15:26 +090063 _, 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
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +000067 _, self.volume = self.volume_client.create_volume(
Jerry Cai6e5eed22014-05-08 20:48:08 +080068 size=1, display_name=vol_name, volume_type=type_name)
Jerry Cai6e5eed22014-05-08 20:48:08 +080069 if with_prefix:
70 self.volume_id_list_with_prefix.append(self.volume['id'])
71 else:
72 self.volume_id_list_without_prefix.append(
73 self.volume['id'])
git-harry9c9f6262014-09-11 15:26:23 +010074 self.volume_client.wait_for_volume_status(
75 self.volume['id'], 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010076
Jérôme Gallard86551ce2013-03-08 11:41:26 +010077 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010078 def resource_cleanup(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020079 # volumes deletion
Jerry Cai6e5eed22014-05-08 20:48:08 +080080 vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
81 for volume_id in vid_prefix:
82 cls.volume_client.delete_volume(volume_id)
83 cls.volume_client.wait_for_resource_deletion(volume_id)
84
85 vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
86 for volume_id in vid_no_pre:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020087 cls.volume_client.delete_volume(volume_id)
88 cls.volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010089
Attila Fazekasf7f34f92013-08-01 17:01:44 +020090 # volume types deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080091 volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
92 for volume_type_id in volume_type_id_list:
ghanshyam1e0a9f82014-10-09 14:15:26 +090093 cls.volume_types_client.delete_volume_type(volume_type_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010094
Andrea Frittoli61a12e22014-09-15 13:14:54 +010095 super(VolumeMultiBackendTest, cls).resource_cleanup()
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050096
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090097 @test.attr(type='smoke')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020098 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +080099 # get volume id which created by type without prefix
100 volume_id = self.volume_id_list_without_prefix[0]
101 self._test_backend_name_reporting_by_volume_id(volume_id)
102
103 @test.attr(type='smoke')
104 def test_backend_name_reporting_with_prefix(self):
105 # get volume id which created by type with prefix
106 volume_id = self.volume_id_list_with_prefix[0]
107 self._test_backend_name_reporting_by_volume_id(volume_id)
108
109 @test.attr(type='gate')
110 def test_backend_name_distinction(self):
111 if self.backend1_name == self.backend2_name:
112 raise self.skipException("backends configured with same name")
113 # get volume id which created by type without prefix
114 volume1_id = self.volume_id_list_without_prefix[0]
115 volume2_id = self.volume_id_list_without_prefix[1]
116 self._test_backend_name_distinction(volume1_id, volume2_id)
117
118 @test.attr(type='gate')
119 def test_backend_name_distinction_with_prefix(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_with_prefix[0]
124 volume2_id = self.volume_id_list_with_prefix[1]
125 self._test_backend_name_distinction(volume1_id, volume2_id)
126
127 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200128 # this test checks if os-vol-attr:host is populated correctly after
129 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100130 # if multi-backend is enabled: os-vol-attr:host should be like:
131 # host@backend_name
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000132 _, volume = self.volume_client.get_volume(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100133
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200134 volume1_host = volume['os-vol-host-attr:host']
135 msg = ("multi-backend reporting incorrect values for volume %s" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800136 volume_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200137 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100138
Jerry Cai6e5eed22014-05-08 20:48:08 +0800139 def _test_backend_name_distinction(self, volume1_id, volume2_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200140 # this test checks that the two volumes created at setUp don't
141 # belong to the same backend (if they are, than the
142 # volume backend distinction is not working properly)
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000143 _, volume = self.volume_client.get_volume(volume1_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200144 volume1_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100145
Swapnil Kulkarnid9df38c2014-08-16 18:06:52 +0000146 _, volume = self.volume_client.get_volume(volume2_id)
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200147 volume2_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100148
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200149 msg = ("volumes %s and %s were created in the same backend" %
Jerry Cai6e5eed22014-05-08 20:48:08 +0800150 (volume1_id, volume2_id))
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200151 self.assertNotEqual(volume1_host, volume2_host, msg)