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 | |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 16 | |
Masayuki Igawa | 911148b | 2014-02-17 15:00:54 +0900 | [diff] [blame^] | 17 | from tempest.api.identity import base |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 18 | from tempest import clients |
Daisuke Morita | 8e1f861 | 2013-11-26 15:43:21 +0900 | [diff] [blame] | 19 | from tempest.common import custom_matchers |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 20 | from tempest.common import isolated_creds |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 21 | from tempest import config |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 22 | from tempest import exceptions |
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 |
| 31 | def setUpClass(cls): |
Sylvain Afchain | 11b99d0 | 2014-01-16 00:42:33 +0100 | [diff] [blame] | 32 | cls.set_network_resources() |
Attila Fazekas | f86fa31 | 2013-07-30 19:56:39 +0200 | [diff] [blame] | 33 | super(BaseObjectTest, cls).setUpClass() |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 34 | if not CONF.service_available.swift: |
Matthew Treinish | 61e332b | 2013-07-19 16:42:31 -0400 | [diff] [blame] | 35 | skip_msg = ("%s skipped as swift is not available" % cls.__name__) |
| 36 | raise cls.skipException(skip_msg) |
Matthew Treinish | 9f756a0 | 2014-01-15 10:26:07 -0500 | [diff] [blame] | 37 | cls.isolated_creds = isolated_creds.IsolatedCreds( |
| 38 | cls.__name__, network_resources=cls.network_resources) |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 39 | if CONF.compute.allow_tenant_isolation: |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 40 | # Get isolated creds for normal user |
| 41 | creds = cls.isolated_creds.get_primary_creds() |
| 42 | username, tenant_name, password = creds |
| 43 | cls.os = clients.Manager(username=username, |
| 44 | password=password, |
| 45 | tenant_name=tenant_name) |
| 46 | # Get isolated creds for admin user |
| 47 | admin_creds = cls.isolated_creds.get_admin_creds() |
| 48 | admin_username, admin_tenant_name, admin_password = admin_creds |
| 49 | cls.os_admin = clients.Manager(username=admin_username, |
| 50 | password=admin_password, |
| 51 | tenant_name=admin_tenant_name) |
| 52 | # Get isolated creds for alt user |
| 53 | alt_creds = cls.isolated_creds.get_alt_creds() |
| 54 | alt_username, alt_tenant, alt_password = alt_creds |
| 55 | cls.os_alt = clients.Manager(username=alt_username, |
| 56 | password=alt_password, |
| 57 | tenant_name=alt_tenant) |
| 58 | # Add isolated users to operator role so that they can create a |
| 59 | # container in swift. |
| 60 | cls._assign_member_role() |
| 61 | else: |
| 62 | cls.os = clients.Manager() |
| 63 | cls.os_admin = clients.AdminManager() |
| 64 | cls.os_alt = clients.AltManager() |
| 65 | |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 66 | cls.object_client = cls.os.object_client |
| 67 | cls.container_client = cls.os.container_client |
| 68 | cls.account_client = cls.os.account_client |
harika-vakadi | 1a9ad61 | 2012-12-14 19:12:08 +0530 | [diff] [blame] | 69 | cls.custom_object_client = cls.os.custom_object_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 70 | cls.token_client = cls.os_admin.token_client |
Attila Fazekas | 407b6db | 2013-01-19 12:48:36 +0100 | [diff] [blame] | 71 | cls.identity_admin_client = cls.os_admin.identity_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 72 | cls.custom_account_client = cls.os.custom_account_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 73 | cls.object_client_alt = cls.os_alt.object_client |
| 74 | cls.container_client_alt = cls.os_alt.container_client |
Attila Fazekas | 407b6db | 2013-01-19 12:48:36 +0100 | [diff] [blame] | 75 | cls.identity_client_alt = cls.os_alt.identity_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 76 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 77 | # Make sure we get fresh auth data after assigning swift role |
| 78 | cls.object_client.auth_provider.clear_auth() |
| 79 | cls.container_client.auth_provider.clear_auth() |
| 80 | cls.account_client.auth_provider.clear_auth() |
| 81 | cls.custom_object_client.auth_provider.clear_auth() |
| 82 | cls.custom_account_client.auth_provider.clear_auth() |
| 83 | cls.object_client_alt.auth_provider.clear_auth() |
| 84 | cls.container_client_alt.auth_provider.clear_auth() |
| 85 | |
Masayuki Igawa | 911148b | 2014-02-17 15:00:54 +0900 | [diff] [blame^] | 86 | cls.data = base.DataGenerator(cls.identity_admin_client) |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 87 | |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 88 | @classmethod |
Matthew Treinish | b7360f7 | 2013-09-13 15:40:11 +0000 | [diff] [blame] | 89 | def tearDownClass(cls): |
| 90 | cls.isolated_creds.clear_isolated_creds() |
| 91 | super(BaseObjectTest, cls).tearDownClass() |
| 92 | |
| 93 | @classmethod |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 94 | def _assign_member_role(cls): |
| 95 | primary_user = cls.isolated_creds.get_primary_user() |
| 96 | alt_user = cls.isolated_creds.get_alt_user() |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 97 | swift_role = CONF.object_storage.operator_role |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 98 | try: |
| 99 | resp, roles = cls.os_admin.identity_client.list_roles() |
| 100 | role = next(r for r in roles if r['name'] == swift_role) |
| 101 | except StopIteration: |
| 102 | msg = "No role named %s found" % swift_role |
| 103 | raise exceptions.NotFound(msg) |
| 104 | for user in [primary_user, alt_user]: |
| 105 | cls.os_admin.identity_client.assign_user_role(user['tenantId'], |
| 106 | user['id'], |
| 107 | role['id']) |
| 108 | |
| 109 | @classmethod |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 110 | def delete_containers(cls, containers, container_client=None, |
| 111 | object_client=None): |
| 112 | """Remove given containers and all objects in them. |
| 113 | |
| 114 | The containers should be visible from the container_client given. |
| 115 | Will not throw any error if the containers don't exist. |
Fabien Boucher | c3a9ba8 | 2014-01-03 13:17:05 +0100 | [diff] [blame] | 116 | Will not check that object and container deletions succeed. |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 117 | |
| 118 | :param containers: list of container names to remove |
| 119 | :param container_client: if None, use cls.container_client, this means |
| 120 | that the default testing user will be used (see 'username' in |
| 121 | 'etc/tempest.conf') |
| 122 | :param object_client: if None, use cls.object_client |
| 123 | """ |
| 124 | if container_client is None: |
| 125 | container_client = cls.container_client |
| 126 | if object_client is None: |
| 127 | object_client = cls.object_client |
| 128 | for cont in containers: |
| 129 | try: |
| 130 | objlist = container_client.list_all_container_objects(cont) |
| 131 | # delete every object in the container |
| 132 | for obj in objlist: |
| 133 | object_client.delete_object(cont, obj['name']) |
| 134 | container_client.delete_container(cont) |
| 135 | except exceptions.NotFound: |
| 136 | pass |
Daisuke Morita | 8e1f861 | 2013-11-26 15:43:21 +0900 | [diff] [blame] | 137 | |
| 138 | def assertHeaders(self, resp, target, method): |
| 139 | """ |
| 140 | Common method to check the existence and the format of common response |
| 141 | headers |
| 142 | """ |
| 143 | self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders( |
| 144 | target, method)) |
| 145 | self.assertThat(resp, custom_matchers.AreAllWellFormatted()) |