blob: d451517d8e67e4006d91a417c40a8ce03cb2dc83 [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
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080028 @test.safe_setup
Jérôme Gallard86551ce2013-03-08 11:41:26 +010029 def setUpClass(cls):
30 super(VolumeMultiBackendTest, cls).setUpClass()
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
Matthew Treinish4d352bc2014-01-29 18:29:18 +000034 cls.backend1_name = CONF.volume.backend1_name
35 cls.backend2_name = CONF.volume.backend2_name
Jérôme Gallard86551ce2013-03-08 11:41:26 +010036
Matthew Treinish4d2e5792014-02-07 22:24:19 +000037 cls.volume_client = cls.os_adm.volumes_client
Giulio Fidentef4fa8942013-05-28 18:48:03 +020038 cls.volume_type_id_list = []
Jerry Cai6e5eed22014-05-08 20:48:08 +080039 cls.volume_id_list_with_prefix = []
40 cls.volume_id_list_without_prefix = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010041
Jerry Cai6e5eed22014-05-08 20:48:08 +080042 # Volume/Type creation (uses volume_backend_name)
43 cls._create_type_and_volume(cls.backend1_name, False)
44 # Volume/Type creation (uses capabilities:volume_backend_name)
45 cls._create_type_and_volume(cls.backend1_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080046
47 if cls.backend1_name != cls.backend2_name:
48 # Volume/Type creation (uses backend2_name)
Jerry Cai6e5eed22014-05-08 20:48:08 +080049 cls._create_type_and_volume(cls.backend2_name, False)
50 # Volume/Type creation (uses capabilities:volume_backend_name)
51 cls._create_type_and_volume(cls.backend2_name, True)
Zhi Kun Liu43f9af12014-03-19 21:01:35 +080052
Jerry Cai6e5eed22014-05-08 20:48:08 +080053 @classmethod
54 def _create_type_and_volume(self, backend_name_key, with_prefix):
55 # Volume/Type creation
56 type_name = data_utils.rand_name('Type')
57 vol_name = data_utils.rand_name('Volume')
58 spec_key_with_prefix = "capabilities:volume_backend_name"
59 spec_key_without_prefix = "volume_backend_name"
60 if with_prefix:
61 extra_specs = {spec_key_with_prefix: backend_name_key}
62 else:
63 extra_specs = {spec_key_without_prefix: backend_name_key}
64 resp, self.type = self.client.create_volume_type(
65 type_name, extra_specs=extra_specs)
66 self.volume_type_id_list.append(self.type['id'])
67
68 resp, self.volume = self.volume_client.create_volume(
69 size=1, display_name=vol_name, volume_type=type_name)
70 self.volume_client.wait_for_volume_status(
71 self.volume['id'], 'available')
72 if with_prefix:
73 self.volume_id_list_with_prefix.append(self.volume['id'])
74 else:
75 self.volume_id_list_without_prefix.append(
76 self.volume['id'])
Jérôme Gallard86551ce2013-03-08 11:41:26 +010077
Jérôme Gallard86551ce2013-03-08 11:41:26 +010078 @classmethod
79 def tearDownClass(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020080 # volumes deletion
Jerry Cai6e5eed22014-05-08 20:48:08 +080081 vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
82 for volume_id in vid_prefix:
83 cls.volume_client.delete_volume(volume_id)
84 cls.volume_client.wait_for_resource_deletion(volume_id)
85
86 vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
87 for volume_id in vid_no_pre:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020088 cls.volume_client.delete_volume(volume_id)
89 cls.volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010090
Attila Fazekasf7f34f92013-08-01 17:01:44 +020091 # volume types deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080092 volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
93 for volume_type_id in volume_type_id_list:
Matthew Treinish4d2e5792014-02-07 22:24:19 +000094 cls.client.delete_volume_type(volume_type_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010095
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050096 super(VolumeMultiBackendTest, cls).tearDownClass()
97
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090098 @test.attr(type='smoke')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020099 def test_backend_name_reporting(self):
Jerry Cai6e5eed22014-05-08 20:48:08 +0800100 # get volume id which created by type without prefix
101 volume_id = self.volume_id_list_without_prefix[0]
102 self._test_backend_name_reporting_by_volume_id(volume_id)
103
104 @test.attr(type='smoke')
105 def test_backend_name_reporting_with_prefix(self):
106 # get volume id which created by type with prefix
107 volume_id = self.volume_id_list_with_prefix[0]
108 self._test_backend_name_reporting_by_volume_id(volume_id)
109
110 @test.attr(type='gate')
111 def test_backend_name_distinction(self):
112 if self.backend1_name == self.backend2_name:
113 raise self.skipException("backends configured with same name")
114 # get volume id which created by type without prefix
115 volume1_id = self.volume_id_list_without_prefix[0]
116 volume2_id = self.volume_id_list_without_prefix[1]
117 self._test_backend_name_distinction(volume1_id, volume2_id)
118
119 @test.attr(type='gate')
120 def test_backend_name_distinction_with_prefix(self):
121 if self.backend1_name == self.backend2_name:
122 raise self.skipException("backends configured with same name")
123 # get volume id which created by type without prefix
124 volume1_id = self.volume_id_list_with_prefix[0]
125 volume2_id = self.volume_id_list_with_prefix[1]
126 self._test_backend_name_distinction(volume1_id, volume2_id)
127
128 def _test_backend_name_reporting_by_volume_id(self, volume_id):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200129 # this test checks if os-vol-attr:host is populated correctly after
130 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100131 # if multi-backend is enabled: os-vol-attr:host should be like:
132 # host@backend_name
Jerry Cai6e5eed22014-05-08 20:48:08 +0800133 resp, volume = self.volume_client.get_volume(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100134 self.assertEqual(200, resp.status)
135
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)
Jerry Cai6e5eed22014-05-08 20:48:08 +0800145 resp, volume = self.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
Jerry Cai6e5eed22014-05-08 20:48:08 +0800148 resp, volume = self.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)