blob: 6178a1c8892eeef29549da165d5fbd7a42c84d0c [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
Jérôme Gallard86551ce2013-03-08 11:41:26 +010028 def setUpClass(cls):
29 super(VolumeMultiBackendTest, cls).setUpClass()
Matthew Treinish4d352bc2014-01-29 18:29:18 +000030 if not CONF.volume_feature_enabled.multi_backend:
armando-migliaccio3e2a0282013-11-22 14:47:16 -080031 cls.tearDownClass()
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 = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010039 cls.volume_id_list = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010040 try:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020041 # Volume/Type creation (uses backend1_name)
Masayuki Igawa259c1132013-10-31 17:48:44 +090042 type1_name = data_utils.rand_name('Type-')
43 vol1_name = data_utils.rand_name('Volume-')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010044 extra_specs1 = {"volume_backend_name": cls.backend1_name}
Matthew Treinish4d2e5792014-02-07 22:24:19 +000045 resp, cls.type1 = cls.client.create_volume_type(
Giulio Fidentef4fa8942013-05-28 18:48:03 +020046 type1_name, extra_specs=extra_specs1)
47 cls.volume_type_id_list.append(cls.type1['id'])
Jérôme Gallard86551ce2013-03-08 11:41:26 +010048
Giulio Fidentef4fa8942013-05-28 18:48:03 +020049 resp, cls.volume1 = cls.volume_client.create_volume(
50 size=1, display_name=vol1_name, volume_type=type1_name)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010051 cls.volume_id_list.append(cls.volume1['id'])
Giulio Fidentef4fa8942013-05-28 18:48:03 +020052 cls.volume_client.wait_for_volume_status(cls.volume1['id'],
53 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010054
Giulio Fidentef4fa8942013-05-28 18:48:03 +020055 if cls.backend1_name != cls.backend2_name:
56 # Volume/Type creation (uses backend2_name)
Masayuki Igawa259c1132013-10-31 17:48:44 +090057 type2_name = data_utils.rand_name('Type-')
58 vol2_name = data_utils.rand_name('Volume-')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020059 extra_specs2 = {"volume_backend_name": cls.backend2_name}
Matthew Treinish4d2e5792014-02-07 22:24:19 +000060 resp, cls.type2 = cls.client.create_volume_type(
Giulio Fidentef4fa8942013-05-28 18:48:03 +020061 type2_name, extra_specs=extra_specs2)
62 cls.volume_type_id_list.append(cls.type2['id'])
63
64 resp, cls.volume2 = cls.volume_client.create_volume(
65 size=1, display_name=vol2_name, volume_type=type2_name)
66 cls.volume_id_list.append(cls.volume2['id'])
67 cls.volume_client.wait_for_volume_status(cls.volume2['id'],
68 'available')
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070069 except Exception as e:
70 LOG.exception("setup failed: %s" % e)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010071 cls.tearDownClass()
72 raise
73
74 @classmethod
75 def tearDownClass(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020076 # volumes deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080077 volume_id_list = getattr(cls, 'volume_id_list', [])
78 for volume_id in volume_id_list:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020079 cls.volume_client.delete_volume(volume_id)
80 cls.volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010081
Attila Fazekasf7f34f92013-08-01 17:01:44 +020082 # volume types deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080083 volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
84 for volume_type_id in volume_type_id_list:
Matthew Treinish4d2e5792014-02-07 22:24:19 +000085 cls.client.delete_volume_type(volume_type_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010086
Dolph Mathews6dbb27c2013-05-09 10:56:24 -050087 super(VolumeMultiBackendTest, cls).tearDownClass()
88
Masayuki Igawa1edf94f2014-03-04 18:34:16 +090089 @test.attr(type='smoke')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020090 def test_backend_name_reporting(self):
91 # this test checks if os-vol-attr:host is populated correctly after
92 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +010093 # if multi-backend is enabled: os-vol-attr:host should be like:
94 # host@backend_name
Giulio Fidentef4fa8942013-05-28 18:48:03 +020095 resp, volume = self.volume_client.get_volume(self.volume1['id'])
Jérôme Gallard86551ce2013-03-08 11:41:26 +010096 self.assertEqual(200, resp.status)
97
Giulio Fidentef4fa8942013-05-28 18:48:03 +020098 volume1_host = volume['os-vol-host-attr:host']
99 msg = ("multi-backend reporting incorrect values for volume %s" %
100 self.volume1['id'])
101 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100102
Masayuki Igawa1edf94f2014-03-04 18:34:16 +0900103 @test.attr(type='gate')
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100104 def test_backend_name_distinction(self):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200105 # this test checks that the two volumes created at setUp don't
106 # belong to the same backend (if they are, than the
107 # volume backend distinction is not working properly)
108 if self.backend1_name == self.backend2_name:
109 raise self.skipException("backends configured with same name")
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100110
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200111 resp, volume = self.volume_client.get_volume(self.volume1['id'])
112 volume1_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100113
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200114 resp, volume = self.volume_client.get_volume(self.volume2['id'])
115 volume2_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100116
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200117 msg = ("volumes %s and %s were created in the same backend" %
118 (self.volume1['id'], self.volume2['id']))
119 self.assertNotEqual(volume1_host, volume2_host, msg)