blob: 797aa71d68682bfe049e920effe07e93e459c3e3 [file] [log] [blame]
Jérôme Gallard86551ce2013-03-08 11:41:26 +01001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
Jérôme Gallard86551ce2013-03-08 11:41:26 +01003# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Sean Dague1937d092013-05-17 16:36:38 -040015from tempest.api.volume import base
Jérôme Gallard86551ce2013-03-08 11:41:26 +010016from tempest.common.utils.data_utils import rand_name
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040017from tempest.openstack.common import log as logging
Jérôme Gallard86551ce2013-03-08 11:41:26 +010018from tempest.services.volume.json.admin import volume_types_client
19from tempest.services.volume.json import volumes_client
Giulio Fidente8b311902013-05-12 15:40:31 +020020from tempest.test import attr
Jérôme Gallard86551ce2013-03-08 11:41:26 +010021
22LOG = logging.getLogger(__name__)
23
24
25class VolumeMultiBackendTest(base.BaseVolumeAdminTest):
26 _interface = "json"
27
Jérôme Gallard86551ce2013-03-08 11:41:26 +010028 @classmethod
Jérôme Gallard86551ce2013-03-08 11:41:26 +010029 def setUpClass(cls):
30 super(VolumeMultiBackendTest, cls).setUpClass()
Giulio Fidentef4fa8942013-05-28 18:48:03 +020031 if not cls.config.volume.multi_backend_enabled:
32 raise cls.skipException("Cinder multi-backend feature disabled")
33
34 cls.backend1_name = cls.config.volume.backend1_name
35 cls.backend2_name = cls.config.volume.backend2_name
Jérôme Gallard86551ce2013-03-08 11:41:26 +010036
37 adm_user = cls.config.identity.admin_username
38 adm_pass = cls.config.identity.admin_password
39 adm_tenant = cls.config.identity.admin_tenant_name
40 auth_url = cls.config.identity.uri
41
Giulio Fidentef4fa8942013-05-28 18:48:03 +020042 cls.volume_client = volumes_client.VolumesClientJSON(cls.config,
43 adm_user,
44 adm_pass,
45 auth_url,
46 adm_tenant)
47 cls.type_client = volume_types_client.VolumeTypesClientJSON(cls.config,
48 adm_user,
49 adm_pass,
50 auth_url,
51 adm_tenant)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010052
Giulio Fidentef4fa8942013-05-28 18:48:03 +020053 cls.volume_type_id_list = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010054 cls.volume_id_list = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010055 try:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020056 # Volume/Type creation (uses backend1_name)
57 type1_name = rand_name('Type-')
58 vol1_name = rand_name('Volume-')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010059 extra_specs1 = {"volume_backend_name": cls.backend1_name}
Giulio Fidentef4fa8942013-05-28 18:48:03 +020060 resp, cls.type1 = cls.type_client.create_volume_type(
61 type1_name, extra_specs=extra_specs1)
62 cls.volume_type_id_list.append(cls.type1['id'])
Jérôme Gallard86551ce2013-03-08 11:41:26 +010063
Giulio Fidentef4fa8942013-05-28 18:48:03 +020064 resp, cls.volume1 = cls.volume_client.create_volume(
65 size=1, display_name=vol1_name, volume_type=type1_name)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010066 cls.volume_id_list.append(cls.volume1['id'])
Giulio Fidentef4fa8942013-05-28 18:48:03 +020067 cls.volume_client.wait_for_volume_status(cls.volume1['id'],
68 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010069
Giulio Fidentef4fa8942013-05-28 18:48:03 +020070 if cls.backend1_name != cls.backend2_name:
71 # Volume/Type creation (uses backend2_name)
72 type2_name = rand_name('Type-')
73 vol2_name = rand_name('Volume-')
74 extra_specs2 = {"volume_backend_name": cls.backend2_name}
75 resp, cls.type2 = cls.type_client.create_volume_type(
76 type2_name, extra_specs=extra_specs2)
77 cls.volume_type_id_list.append(cls.type2['id'])
78
79 resp, cls.volume2 = cls.volume_client.create_volume(
80 size=1, display_name=vol2_name, volume_type=type2_name)
81 cls.volume_id_list.append(cls.volume2['id'])
82 cls.volume_client.wait_for_volume_status(cls.volume2['id'],
83 'available')
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070084 except Exception as e:
85 LOG.exception("setup failed: %s" % e)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010086 cls.tearDownClass()
87 raise
88
89 @classmethod
90 def tearDownClass(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020091 # volumes deletion
Jérôme Gallard86551ce2013-03-08 11:41:26 +010092 for volume_id in cls.volume_id_list:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020093 cls.volume_client.delete_volume(volume_id)
94 cls.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
Giulio Fidentef4fa8942013-05-28 18:48:03 +020097 for volume_type_id in cls.volume_type_id_list:
98 cls.type_client.delete_volume_type(volume_type_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010099
Dolph Mathews6dbb27c2013-05-09 10:56:24 -0500100 super(VolumeMultiBackendTest, cls).tearDownClass()
101
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200102 @attr(type='smoke')
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200103 def test_backend_name_reporting(self):
104 # this test checks if os-vol-attr:host is populated correctly after
105 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100106 # if multi-backend is enabled: os-vol-attr:host should be like:
107 # host@backend_name
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200108 resp, volume = self.volume_client.get_volume(self.volume1['id'])
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100109 self.assertEqual(200, resp.status)
110
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200111 volume1_host = volume['os-vol-host-attr:host']
112 msg = ("multi-backend reporting incorrect values for volume %s" %
113 self.volume1['id'])
114 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100115
Giulio Fidente8b311902013-05-12 15:40:31 +0200116 @attr(type='gate')
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100117 def test_backend_name_distinction(self):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200118 # this test checks that the two volumes created at setUp don't
119 # belong to the same backend (if they are, than the
120 # volume backend distinction is not working properly)
121 if self.backend1_name == self.backend2_name:
122 raise self.skipException("backends configured with same name")
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100123
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200124 resp, volume = self.volume_client.get_volume(self.volume1['id'])
125 volume1_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100126
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200127 resp, volume = self.volume_client.get_volume(self.volume2['id'])
128 volume2_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100129
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200130 msg = ("volumes %s and %s were created in the same backend" %
131 (self.volume1['id'], self.volume2['id']))
132 self.assertNotEqual(volume1_host, volume2_host, msg)