Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 OpenStack Foundation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | import logging |
| 19 | import testtools |
| 20 | |
| 21 | from tempest.common.utils.data_utils import rand_name |
| 22 | from tempest import config |
| 23 | from tempest.services.volume.json.admin import volume_types_client |
| 24 | from tempest.services.volume.json import volumes_client |
| 25 | from tempest.tests.volume import base |
| 26 | |
| 27 | LOG = logging.getLogger(__name__) |
| 28 | |
| 29 | |
| 30 | class VolumeMultiBackendTest(base.BaseVolumeAdminTest): |
| 31 | _interface = "json" |
| 32 | |
| 33 | multi_backend_enabled = config.TempestConfig().volume.multi_backend_enabled |
| 34 | backend1_name = config.TempestConfig().volume.backend1_name |
| 35 | backend2_name = config.TempestConfig().volume.backend2_name |
| 36 | backend_names_equal = False |
| 37 | if (backend1_name == backend2_name): |
| 38 | backend_names_equal = True |
| 39 | |
| 40 | @classmethod |
| 41 | @testtools.skipIf(not multi_backend_enabled, |
| 42 | "Cinder multi-backend feature is not available") |
| 43 | def setUpClass(cls): |
| 44 | super(VolumeMultiBackendTest, cls).setUpClass() |
| 45 | |
| 46 | adm_user = cls.config.identity.admin_username |
| 47 | adm_pass = cls.config.identity.admin_password |
| 48 | adm_tenant = cls.config.identity.admin_tenant_name |
| 49 | auth_url = cls.config.identity.uri |
| 50 | |
| 51 | cls.client = volumes_client.VolumesClientJSON(cls.config, |
| 52 | adm_user, |
| 53 | adm_pass, |
| 54 | auth_url, |
| 55 | adm_tenant) |
| 56 | cls.client2 = volume_types_client.VolumeTypesClientJSON(cls.config, |
| 57 | adm_user, |
| 58 | adm_pass, |
| 59 | auth_url, |
| 60 | adm_tenant) |
| 61 | |
| 62 | ## variables initialization |
| 63 | type_name1 = rand_name('type-') |
| 64 | type_name2 = rand_name('type-') |
| 65 | cls.volume_type_list = [] |
| 66 | |
| 67 | vol_name1 = rand_name('Volume-') |
| 68 | vol_name2 = rand_name('Volume-') |
| 69 | cls.volume_id_list = [] |
| 70 | |
| 71 | try: |
| 72 | ## Volume types creation |
| 73 | extra_specs1 = {"volume_backend_name": cls.backend1_name} |
| 74 | resp, cls.body1 = cls.client2.create_volume_type( |
| 75 | type_name1, extra_specs=extra_specs1) |
| 76 | cls.volume_type_list.append(cls.body1) |
| 77 | |
| 78 | extra_specs2 = {"volume_backend_name": cls.backend2_name} |
| 79 | resp, cls.body2 = cls.client2.create_volume_type( |
| 80 | type_name2, extra_specs=extra_specs2) |
| 81 | cls.volume_type_list.append(cls.body2) |
| 82 | |
| 83 | ## Volumes creation |
| 84 | resp, cls.volume1 = cls.client.create_volume( |
| 85 | size=1, display_name=vol_name1, volume_type=type_name1) |
| 86 | cls.client.wait_for_volume_status(cls.volume1['id'], 'available') |
| 87 | cls.volume_id_list.append(cls.volume1['id']) |
| 88 | |
| 89 | resp, cls.volume2 = cls.client.create_volume( |
| 90 | size=1, display_name=vol_name2, volume_type=type_name2) |
| 91 | cls.client.wait_for_volume_status(cls.volume2['id'], 'available') |
| 92 | cls.volume_id_list.append(cls.volume2['id']) |
| 93 | except Exception: |
| 94 | LOG.exception("setup failed") |
| 95 | cls.tearDownClass() |
| 96 | raise |
| 97 | |
| 98 | @classmethod |
| 99 | def tearDownClass(cls): |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 100 | ## volumes deletion |
| 101 | for volume_id in cls.volume_id_list: |
| 102 | cls.client.delete_volume(volume_id) |
| 103 | cls.client.wait_for_resource_deletion(volume_id) |
| 104 | |
| 105 | ## volume types deletion |
| 106 | for volume_type in cls.volume_type_list: |
| 107 | cls.client2.delete_volume_type(volume_type) |
| 108 | |
Dolph Mathews | 6dbb27c | 2013-05-09 10:56:24 -0500 | [diff] [blame^] | 109 | super(VolumeMultiBackendTest, cls).tearDownClass() |
| 110 | |
Jérôme Gallard | 86551ce | 2013-03-08 11:41:26 +0100 | [diff] [blame] | 111 | def test_multi_backend_enabled(self): |
| 112 | # this test checks that multi backend is enabled for at least the |
| 113 | # computes where the volumes created in setUp were made |
| 114 | # if multi-backend is enabled: os-vol-attr:host should be like: |
| 115 | # host@backend_name |
| 116 | # this test fails if: |
| 117 | # - multi backend is not enabled |
| 118 | resp, fetched_volume = self.client.get_volume(self.volume1['id']) |
| 119 | self.assertEqual(200, resp.status) |
| 120 | |
| 121 | volume_host1 = fetched_volume['os-vol-host-attr:host'] |
| 122 | msg = ("Multi-backend is not available for at least host " |
| 123 | "%(volume_host1)s") % locals() |
| 124 | self.assertTrue(len(volume_host1.split("@")) > 1, msg) |
| 125 | |
| 126 | resp, fetched_volume = self.client.get_volume(self.volume2['id']) |
| 127 | self.assertEqual(200, resp.status) |
| 128 | |
| 129 | volume_host2 = fetched_volume['os-vol-host-attr:host'] |
| 130 | msg = ("Multi-backend is not available for at least host " |
| 131 | "%(volume_host2)s") % locals() |
| 132 | self.assertTrue(len(volume_host2.split("@")) > 1, msg) |
| 133 | |
| 134 | def test_backend_name_distinction(self): |
| 135 | # this test checks that the two volumes created at setUp doesn't |
| 136 | # belong to the same backend (if they are in the same backend, that |
| 137 | # means, volume_backend_name distinction is not working properly) |
| 138 | # this test fails if: |
| 139 | # - tempest.conf is not well configured |
| 140 | # - the two volumes belongs to the same backend |
| 141 | |
| 142 | # checks tempest.conf |
| 143 | msg = ("tempest.conf is not well configured, " |
| 144 | "backend1_name and backend2_name are equal") |
| 145 | self.assertEqual(self.backend_names_equal, False, msg) |
| 146 | |
| 147 | # checks the two volumes belongs to different backend |
| 148 | resp, fetched_volume = self.client.get_volume(self.volume1['id']) |
| 149 | volume_host1 = fetched_volume['os-vol-host-attr:host'] |
| 150 | |
| 151 | resp, fetched_volume = self.client.get_volume(self.volume2['id']) |
| 152 | volume_host2 = fetched_volume['os-vol-host-attr:host'] |
| 153 | |
| 154 | msg = ("volume2 was created in the same backend as volume1: " |
| 155 | "%(volume_host2)s.") % locals() |
| 156 | self.assertNotEqual(volume_host2, volume_host1, msg) |