blob: c56325988ea0a0d70437763599398091cb8ce327 [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
Masayuki Igawa259c1132013-10-31 17:48:44 +090016from tempest.common.utils import data_utils
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
Zhi Kun Liubb363a22013-11-28 18:47:39 +080025class VolumeMultiBackendTest(base.BaseVolumeV1AdminTest):
Jérôme Gallard86551ce2013-03-08 11:41:26 +010026 _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()
Matthew Treinishd5c96022013-10-17 21:51:23 +000031 if not cls.config.volume_feature_enabled.multi_backend:
armando-migliaccio3e2a0282013-11-22 14:47:16 -080032 cls.tearDownClass()
Giulio Fidentef4fa8942013-05-28 18:48:03 +020033 raise cls.skipException("Cinder multi-backend feature disabled")
34
35 cls.backend1_name = cls.config.volume.backend1_name
36 cls.backend2_name = cls.config.volume.backend2_name
Jérôme Gallard86551ce2013-03-08 11:41:26 +010037
38 adm_user = cls.config.identity.admin_username
39 adm_pass = cls.config.identity.admin_password
40 adm_tenant = cls.config.identity.admin_tenant_name
41 auth_url = cls.config.identity.uri
42
Giulio Fidentef4fa8942013-05-28 18:48:03 +020043 cls.volume_client = volumes_client.VolumesClientJSON(cls.config,
44 adm_user,
45 adm_pass,
46 auth_url,
47 adm_tenant)
48 cls.type_client = volume_types_client.VolumeTypesClientJSON(cls.config,
49 adm_user,
50 adm_pass,
51 auth_url,
52 adm_tenant)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010053
Giulio Fidentef4fa8942013-05-28 18:48:03 +020054 cls.volume_type_id_list = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010055 cls.volume_id_list = []
Jérôme Gallard86551ce2013-03-08 11:41:26 +010056 try:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020057 # Volume/Type creation (uses backend1_name)
Masayuki Igawa259c1132013-10-31 17:48:44 +090058 type1_name = data_utils.rand_name('Type-')
59 vol1_name = data_utils.rand_name('Volume-')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010060 extra_specs1 = {"volume_backend_name": cls.backend1_name}
Giulio Fidentef4fa8942013-05-28 18:48:03 +020061 resp, cls.type1 = cls.type_client.create_volume_type(
62 type1_name, extra_specs=extra_specs1)
63 cls.volume_type_id_list.append(cls.type1['id'])
Jérôme Gallard86551ce2013-03-08 11:41:26 +010064
Giulio Fidentef4fa8942013-05-28 18:48:03 +020065 resp, cls.volume1 = cls.volume_client.create_volume(
66 size=1, display_name=vol1_name, volume_type=type1_name)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010067 cls.volume_id_list.append(cls.volume1['id'])
Giulio Fidentef4fa8942013-05-28 18:48:03 +020068 cls.volume_client.wait_for_volume_status(cls.volume1['id'],
69 'available')
Jérôme Gallard86551ce2013-03-08 11:41:26 +010070
Giulio Fidentef4fa8942013-05-28 18:48:03 +020071 if cls.backend1_name != cls.backend2_name:
72 # Volume/Type creation (uses backend2_name)
Masayuki Igawa259c1132013-10-31 17:48:44 +090073 type2_name = data_utils.rand_name('Type-')
74 vol2_name = data_utils.rand_name('Volume-')
Giulio Fidentef4fa8942013-05-28 18:48:03 +020075 extra_specs2 = {"volume_backend_name": cls.backend2_name}
76 resp, cls.type2 = cls.type_client.create_volume_type(
77 type2_name, extra_specs=extra_specs2)
78 cls.volume_type_id_list.append(cls.type2['id'])
79
80 resp, cls.volume2 = cls.volume_client.create_volume(
81 size=1, display_name=vol2_name, volume_type=type2_name)
82 cls.volume_id_list.append(cls.volume2['id'])
83 cls.volume_client.wait_for_volume_status(cls.volume2['id'],
84 'available')
Matt Riedemannbc8dbd32013-08-02 14:02:12 -070085 except Exception as e:
86 LOG.exception("setup failed: %s" % e)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010087 cls.tearDownClass()
88 raise
89
90 @classmethod
91 def tearDownClass(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020092 # volumes deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080093 volume_id_list = getattr(cls, 'volume_id_list', [])
94 for volume_id in volume_id_list:
Giulio Fidentef4fa8942013-05-28 18:48:03 +020095 cls.volume_client.delete_volume(volume_id)
96 cls.volume_client.wait_for_resource_deletion(volume_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +010097
Attila Fazekasf7f34f92013-08-01 17:01:44 +020098 # volume types deletion
armando-migliaccio3e2a0282013-11-22 14:47:16 -080099 volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
100 for volume_type_id in volume_type_id_list:
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200101 cls.type_client.delete_volume_type(volume_type_id)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100102
Dolph Mathews6dbb27c2013-05-09 10:56:24 -0500103 super(VolumeMultiBackendTest, cls).tearDownClass()
104
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200105 @attr(type='smoke')
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200106 def test_backend_name_reporting(self):
107 # this test checks if os-vol-attr:host is populated correctly after
108 # the multi backend feature has been enabled
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100109 # if multi-backend is enabled: os-vol-attr:host should be like:
110 # host@backend_name
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200111 resp, volume = self.volume_client.get_volume(self.volume1['id'])
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100112 self.assertEqual(200, resp.status)
113
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200114 volume1_host = volume['os-vol-host-attr:host']
115 msg = ("multi-backend reporting incorrect values for volume %s" %
116 self.volume1['id'])
117 self.assertTrue(len(volume1_host.split("@")) > 1, msg)
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100118
Giulio Fidente8b311902013-05-12 15:40:31 +0200119 @attr(type='gate')
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100120 def test_backend_name_distinction(self):
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200121 # this test checks that the two volumes created at setUp don't
122 # belong to the same backend (if they are, than the
123 # volume backend distinction is not working properly)
124 if self.backend1_name == self.backend2_name:
125 raise self.skipException("backends configured with same name")
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.volume1['id'])
128 volume1_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 resp, volume = self.volume_client.get_volume(self.volume2['id'])
131 volume2_host = volume['os-vol-host-attr:host']
Jérôme Gallard86551ce2013-03-08 11:41:26 +0100132
Giulio Fidentef4fa8942013-05-28 18:48:03 +0200133 msg = ("volumes %s and %s were created in the same backend" %
134 (self.volume1['id'], self.volume2['id']))
135 self.assertNotEqual(volume1_host, volume2_host, msg)