ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 16 | from tempest_lib import exceptions as lib_exc |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 17 | |
Masayuki Igawa | 911148b | 2014-02-17 15:00:54 +0900 | [diff] [blame] | 18 | from tempest.api.identity import base |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 19 | from tempest import clients |
Cyril Roelandt | c1482a2 | 2014-11-13 16:55:04 +0100 | [diff] [blame] | 20 | from tempest.common import credentials |
Daisuke Morita | 8e1f861 | 2013-11-26 15:43:21 +0900 | [diff] [blame] | 21 | from tempest.common import custom_matchers |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 22 | from tempest import config |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 23 | import tempest.test |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 24 | |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 25 | CONF = config.CONF |
| 26 | |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 27 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 28 | class BaseObjectTest(tempest.test.BaseTestCase): |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 29 | |
| 30 | @classmethod |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame^] | 31 | def skip_checks(cls): |
| 32 | super(BaseObjectTest, cls).skip_checks() |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 33 | if not CONF.service_available.swift: |
Matthew Treinish | 61e332b | 2013-07-19 16:42:31 -0400 | [diff] [blame] | 34 | skip_msg = ("%s skipped as swift is not available" % cls.__name__) |
| 35 | raise cls.skipException(skip_msg) |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame^] | 36 | |
| 37 | @classmethod |
| 38 | def setup_credentials(cls): |
| 39 | cls.set_network_resources() |
| 40 | super(BaseObjectTest, cls).setup_credentials() |
| 41 | |
Cyril Roelandt | c1482a2 | 2014-11-13 16:55:04 +0100 | [diff] [blame] | 42 | cls.isolated_creds = credentials.get_isolated_credentials( |
Matthew Treinish | 9f756a0 | 2014-01-15 10:26:07 -0500 | [diff] [blame] | 43 | cls.__name__, network_resources=cls.network_resources) |
Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 44 | # Get isolated creds for normal user |
| 45 | cls.os = clients.Manager(cls.isolated_creds.get_primary_creds()) |
| 46 | # Get isolated creds for admin user |
| 47 | cls.os_admin = clients.Manager(cls.isolated_creds.get_admin_creds()) |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame^] | 48 | cls.data = SwiftDataGenerator(cls.os_admin.identity_client) |
Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 49 | # Get isolated creds for alt user |
| 50 | cls.os_alt = clients.Manager(cls.isolated_creds.get_alt_creds()) |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 51 | |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame^] | 52 | @classmethod |
| 53 | def setup_clients(cls): |
| 54 | super(BaseObjectTest, cls).setup_clients() |
| 55 | |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 56 | cls.object_client = cls.os.object_client |
| 57 | cls.container_client = cls.os.container_client |
| 58 | cls.account_client = cls.os.account_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 59 | cls.token_client = cls.os_admin.token_client |
Attila Fazekas | 407b6db | 2013-01-19 12:48:36 +0100 | [diff] [blame] | 60 | cls.identity_admin_client = cls.os_admin.identity_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 61 | cls.object_client_alt = cls.os_alt.object_client |
| 62 | cls.container_client_alt = cls.os_alt.container_client |
Attila Fazekas | 407b6db | 2013-01-19 12:48:36 +0100 | [diff] [blame] | 63 | cls.identity_client_alt = cls.os_alt.identity_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 64 | |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame^] | 65 | @classmethod |
| 66 | def resource_setup(cls): |
| 67 | super(BaseObjectTest, cls).resource_setup() |
| 68 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 69 | # Make sure we get fresh auth data after assigning swift role |
| 70 | cls.object_client.auth_provider.clear_auth() |
| 71 | cls.container_client.auth_provider.clear_auth() |
| 72 | cls.account_client.auth_provider.clear_auth() |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 73 | cls.object_client_alt.auth_provider.clear_auth() |
| 74 | cls.container_client_alt.auth_provider.clear_auth() |
| 75 | |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 76 | @classmethod |
Andrea Frittoli | 5f13f71 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 77 | def resource_cleanup(cls): |
Daisuke Morita | 41a5cf4 | 2014-08-26 19:39:15 +0900 | [diff] [blame] | 78 | cls.data.teardown_all() |
Matthew Treinish | b7360f7 | 2013-09-13 15:40:11 +0000 | [diff] [blame] | 79 | cls.isolated_creds.clear_isolated_creds() |
Andrea Frittoli | 5f13f71 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 80 | super(BaseObjectTest, cls).resource_cleanup() |
Matthew Treinish | b7360f7 | 2013-09-13 15:40:11 +0000 | [diff] [blame] | 81 | |
| 82 | @classmethod |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 83 | def delete_containers(cls, containers, container_client=None, |
| 84 | object_client=None): |
| 85 | """Remove given containers and all objects in them. |
| 86 | |
| 87 | The containers should be visible from the container_client given. |
| 88 | Will not throw any error if the containers don't exist. |
Fabien Boucher | c3a9ba8 | 2014-01-03 13:17:05 +0100 | [diff] [blame] | 89 | Will not check that object and container deletions succeed. |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 90 | |
| 91 | :param containers: list of container names to remove |
| 92 | :param container_client: if None, use cls.container_client, this means |
| 93 | that the default testing user will be used (see 'username' in |
| 94 | 'etc/tempest.conf') |
| 95 | :param object_client: if None, use cls.object_client |
| 96 | """ |
| 97 | if container_client is None: |
| 98 | container_client = cls.container_client |
| 99 | if object_client is None: |
| 100 | object_client = cls.object_client |
| 101 | for cont in containers: |
| 102 | try: |
| 103 | objlist = container_client.list_all_container_objects(cont) |
| 104 | # delete every object in the container |
| 105 | for obj in objlist: |
Ala Rezmerita | a81af8c | 2014-02-18 16:01:48 +0100 | [diff] [blame] | 106 | try: |
| 107 | object_client.delete_object(cont, obj['name']) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 108 | except lib_exc.NotFound: |
Ala Rezmerita | a81af8c | 2014-02-18 16:01:48 +0100 | [diff] [blame] | 109 | pass |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 110 | container_client.delete_container(cont) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 111 | except lib_exc.NotFound: |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 112 | pass |
Daisuke Morita | 8e1f861 | 2013-11-26 15:43:21 +0900 | [diff] [blame] | 113 | |
| 114 | def assertHeaders(self, resp, target, method): |
| 115 | """ |
| 116 | Common method to check the existence and the format of common response |
| 117 | headers |
| 118 | """ |
| 119 | self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders( |
| 120 | target, method)) |
| 121 | self.assertThat(resp, custom_matchers.AreAllWellFormatted()) |
Daisuke Morita | 41a5cf4 | 2014-08-26 19:39:15 +0900 | [diff] [blame] | 122 | |
| 123 | |
| 124 | class SwiftDataGenerator(base.DataGenerator): |
| 125 | |
| 126 | def setup_test_user(self, reseller=False): |
| 127 | super(SwiftDataGenerator, self).setup_test_user() |
| 128 | if reseller: |
| 129 | role_name = CONF.object_storage.reseller_admin_role |
| 130 | else: |
| 131 | role_name = CONF.object_storage.operator_role |
| 132 | role_id = self._get_role_id(role_name) |
| 133 | self._assign_role(role_id) |
| 134 | |
| 135 | def _get_role_id(self, role_name): |
| 136 | try: |
David Kranz | b7afa92 | 2014-12-30 10:56:26 -0500 | [diff] [blame] | 137 | roles = self.client.list_roles() |
Daisuke Morita | 41a5cf4 | 2014-08-26 19:39:15 +0900 | [diff] [blame] | 138 | return next(r['id'] for r in roles if r['name'] == role_name) |
| 139 | except StopIteration: |
| 140 | msg = "Role name '%s' is not found" % role_name |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 141 | raise lib_exc.NotFound(msg) |
Daisuke Morita | 41a5cf4 | 2014-08-26 19:39:15 +0900 | [diff] [blame] | 142 | |
| 143 | def _assign_role(self, role_id): |
| 144 | self.client.assign_user_role(self.tenant['id'], |
| 145 | self.user['id'], |
| 146 | role_id) |