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 |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 16 | from tempest.common.utils.data_utils import rand_name |
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 | |
| 25 | class VolumeMultiBackendTest(base.BaseVolumeAdminTest): |
| 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() |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 31 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 36 | |
| 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 Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 42 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 52 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 53 | cls.volume_type_id_list = [] |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 54 | cls.volume_id_list = [] |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 55 | try: |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 56 | # Volume/Type creation (uses backend1_name) |
| 57 | type1_name = rand_name('Type-') |
| 58 | vol1_name = rand_name('Volume-') |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 59 | extra_specs1 = {"volume_backend_name": cls.backend1_name} |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 60 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 63 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 64 | resp, cls.volume1 = cls.volume_client.create_volume( |
| 65 | size=1, display_name=vol1_name, volume_type=type1_name) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 66 | cls.volume_id_list.append(cls.volume1['id']) |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 67 | cls.volume_client.wait_for_volume_status(cls.volume1['id'], |
| 68 | 'available') |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 69 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 70 | 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 Riedemann | bc8dbd3 | 2013-08-02 14:02:12 -0700 | [diff] [blame] | 84 | except Exception as e: |
| 85 | LOG.exception("setup failed: %s" % e) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 86 | cls.tearDownClass() |
| 87 | raise |
| 88 | |
| 89 | @classmethod |
| 90 | def tearDownClass(cls): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 91 | # volumes deletion |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 92 | for volume_id in cls.volume_id_list: |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 93 | cls.volume_client.delete_volume(volume_id) |
| 94 | cls.volume_client.wait_for_resource_deletion(volume_id) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 95 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 96 | # volume types deletion |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 97 | for volume_type_id in cls.volume_type_id_list: |
| 98 | cls.type_client.delete_volume_type(volume_type_id) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 99 | |
Dolph Mathews | 6dbb27c | 2013-05-09 10:56:24 -0500 | [diff] [blame] | 100 | super(VolumeMultiBackendTest, cls).tearDownClass() |
| 101 | |
Giulio Fidente | ba3985a | 2013-05-29 01:46:36 +0200 | [diff] [blame] | 102 | @attr(type='smoke') |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 103 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 106 | # if multi-backend is enabled: os-vol-attr:host should be like: |
| 107 | # host@backend_name |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 108 | resp, volume = self.volume_client.get_volume(self.volume1['id']) |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 109 | self.assertEqual(200, resp.status) |
| 110 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 111 | 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 115 | |
Giulio Fidente | 8b31190 | 2013-05-12 15:40:31 +0200 | [diff] [blame] | 116 | @attr(type='gate') |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 117 | def test_backend_name_distinction(self): |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 118 | # 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 Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 123 | |
Giulio Fidente | f4fa894 | 2013-05-28 18:48:03 +0200 | [diff] [blame] | 124 | resp, volume = self.volume_client.get_volume(self.volume1['id']) |
| 125 | volume1_host = volume['os-vol-host-attr:host'] |
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.volume2['id']) |
| 128 | volume2_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 | 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) |