Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 3 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 15 | from tempest.api.volume import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 17 | from tempest.openstack.common import log as logging |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 18 | from tempest.services.volume.json.admin import volume_types_client |
| 19 | from tempest.services.volume.json import volumes_client |
Giulio Fidente | 8b31190 | 2013-05-12 15:40:31 +0200 | [diff] [blame] | 20 | from tempest.test import attr |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 21 | |
| 22 | LOG = logging.getLogger(__name__) |
| 23 | |
| 24 | |
Zhi Kun Liu | bb363a2 | 2013-11-28 18:47:39 +0800 | [diff] [blame] | 25 | class VolumeMultiBackendTest(base.BaseVolumeV1AdminTest): |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 26 | _interface = "json" |
| 27 | |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 28 | @classmethod |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 29 | def setUpClass(cls): |
| 30 | super(VolumeMultiBackendTest, cls).setUpClass() |
Matthew Treinish | d5c9602 | 2013-10-17 21:51:23 +0000 | [diff] [blame] | 31 | if not cls.config.volume_feature_enabled.multi_backend: |
armando-migliaccio | 3e2a028 | 2013-11-22 14:47:16 -0800 | [diff] [blame] | 32 | cls.tearDownClass() |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 33 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 37 | |
| 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 Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 43 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 53 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 54 | cls.volume_type_id_list = [] |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 55 | cls.volume_id_list = [] |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 56 | try: |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 57 | # Volume/Type creation (uses backend1_name) |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 58 | type1_name = data_utils.rand_name('Type-') |
| 59 | vol1_name = data_utils.rand_name('Volume-') |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 60 | extra_specs1 = {"volume_backend_name": cls.backend1_name} |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 61 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 64 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 65 | resp, cls.volume1 = cls.volume_client.create_volume( |
| 66 | size=1, display_name=vol1_name, volume_type=type1_name) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 67 | cls.volume_id_list.append(cls.volume1['id']) |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 68 | cls.volume_client.wait_for_volume_status(cls.volume1['id'], |
| 69 | 'available') |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 70 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 71 | if cls.backend1_name != cls.backend2_name: |
| 72 | # Volume/Type creation (uses backend2_name) |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 73 | type2_name = data_utils.rand_name('Type-') |
| 74 | vol2_name = data_utils.rand_name('Volume-') |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 75 | 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 Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 85 | except Exception as e: |
| 86 | LOG.exception("setup failed: %s" % e) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 87 | cls.tearDownClass() |
| 88 | raise |
| 89 | |
| 90 | @classmethod |
| 91 | def tearDownClass(cls): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 92 | # volumes deletion |
armando-migliaccio | 3e2a028 | 2013-11-22 14:47:16 -0800 | [diff] [blame] | 93 | volume_id_list = getattr(cls, 'volume_id_list', []) |
| 94 | for volume_id in volume_id_list: |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 95 | cls.volume_client.delete_volume(volume_id) |
| 96 | cls.volume_client.wait_for_resource_deletion(volume_id) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 97 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 98 | # volume types deletion |
armando-migliaccio | 3e2a028 | 2013-11-22 14:47:16 -0800 | [diff] [blame] | 99 | volume_type_id_list = getattr(cls, 'volume_type_id_list', []) |
| 100 | for volume_type_id in volume_type_id_list: |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 101 | cls.type_client.delete_volume_type(volume_type_id) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 102 | |
Dolph Mathews | 6dbb27c | 2013-05-09 10:56:24 -0500 | [diff] [blame] | 103 | super(VolumeMultiBackendTest, cls).tearDownClass() |
| 104 | |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 105 | @attr(type='smoke') |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 106 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 109 | # if multi-backend is enabled: os-vol-attr:host should be like: |
| 110 | # host@backend_name |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 111 | resp, volume = self.volume_client.get_volume(self.volume1['id']) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 112 | self.assertEqual(200, resp.status) |
| 113 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 114 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 118 | |
Giulio Fidente | 8b31190 | 2013-05-12 15:40:31 +0200 | [diff] [blame] | 119 | @attr(type='gate') |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 120 | def test_backend_name_distinction(self): |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 121 | # 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 126 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 127 | resp, volume = self.volume_client.get_volume(self.volume1['id']) |
| 128 | volume1_host = volume['os-vol-host-attr:host'] |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 129 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 130 | resp, volume = self.volume_client.get_volume(self.volume2['id']) |
| 131 | volume2_host = volume['os-vol-host-attr:host'] |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 132 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 133 | 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) |