dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame^] | 3 | # Copyright 2012 OpenStack Foundation |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 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 | |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 18 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 19 | from tempest.api.identity.base import DataGenerator |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 20 | from tempest import clients |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 21 | from tempest.common import isolated_creds |
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 | |
| 25 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 26 | class BaseObjectTest(tempest.test.BaseTestCase): |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 27 | |
| 28 | @classmethod |
| 29 | def setUpClass(cls): |
Attila Fazekas | f86fa31 | 2013-07-30 19:56:39 +0200 | [diff] [blame] | 30 | super(BaseObjectTest, cls).setUpClass() |
Matthew Treinish | 61e332b | 2013-07-19 16:42:31 -0400 | [diff] [blame] | 31 | if not cls.config.service_available.swift: |
| 32 | skip_msg = ("%s skipped as swift is not available" % cls.__name__) |
| 33 | raise cls.skipException(skip_msg) |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 34 | cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__) |
| 35 | if cls.config.compute.allow_tenant_isolation: |
| 36 | # Get isolated creds for normal user |
| 37 | creds = cls.isolated_creds.get_primary_creds() |
| 38 | username, tenant_name, password = creds |
| 39 | cls.os = clients.Manager(username=username, |
| 40 | password=password, |
| 41 | tenant_name=tenant_name) |
| 42 | # Get isolated creds for admin user |
| 43 | admin_creds = cls.isolated_creds.get_admin_creds() |
| 44 | admin_username, admin_tenant_name, admin_password = admin_creds |
| 45 | cls.os_admin = clients.Manager(username=admin_username, |
| 46 | password=admin_password, |
| 47 | tenant_name=admin_tenant_name) |
| 48 | # Get isolated creds for alt user |
| 49 | alt_creds = cls.isolated_creds.get_alt_creds() |
| 50 | alt_username, alt_tenant, alt_password = alt_creds |
| 51 | cls.os_alt = clients.Manager(username=alt_username, |
| 52 | password=alt_password, |
| 53 | tenant_name=alt_tenant) |
| 54 | # Add isolated users to operator role so that they can create a |
| 55 | # container in swift. |
| 56 | cls._assign_member_role() |
| 57 | else: |
| 58 | cls.os = clients.Manager() |
| 59 | cls.os_admin = clients.AdminManager() |
| 60 | cls.os_alt = clients.AltManager() |
| 61 | |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 62 | cls.object_client = cls.os.object_client |
| 63 | cls.container_client = cls.os.container_client |
| 64 | cls.account_client = cls.os.account_client |
harika-vakadi | 1a9ad61 | 2012-12-14 19:12:08 +0530 | [diff] [blame] | 65 | cls.custom_object_client = cls.os.custom_object_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 66 | cls.token_client = cls.os_admin.token_client |
Attila Fazekas | 407b6db | 2013-01-19 12:48:36 +0100 | [diff] [blame] | 67 | cls.identity_admin_client = cls.os_admin.identity_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 68 | cls.custom_account_client = cls.os.custom_account_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 69 | cls.object_client_alt = cls.os_alt.object_client |
| 70 | cls.container_client_alt = cls.os_alt.container_client |
Attila Fazekas | 407b6db | 2013-01-19 12:48:36 +0100 | [diff] [blame] | 71 | cls.identity_client_alt = cls.os_alt.identity_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 72 | |
Attila Fazekas | 407b6db | 2013-01-19 12:48:36 +0100 | [diff] [blame] | 73 | cls.data = DataGenerator(cls.identity_admin_client) |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 74 | |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 75 | @classmethod |
Matthew Treinish | b7360f7 | 2013-09-13 15:40:11 +0000 | [diff] [blame] | 76 | def tearDownClass(cls): |
| 77 | cls.isolated_creds.clear_isolated_creds() |
| 78 | super(BaseObjectTest, cls).tearDownClass() |
| 79 | |
| 80 | @classmethod |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 81 | def _assign_member_role(cls): |
| 82 | primary_user = cls.isolated_creds.get_primary_user() |
| 83 | alt_user = cls.isolated_creds.get_alt_user() |
| 84 | swift_role = cls.config.object_storage.operator_role |
| 85 | try: |
| 86 | resp, roles = cls.os_admin.identity_client.list_roles() |
| 87 | role = next(r for r in roles if r['name'] == swift_role) |
| 88 | except StopIteration: |
| 89 | msg = "No role named %s found" % swift_role |
| 90 | raise exceptions.NotFound(msg) |
| 91 | for user in [primary_user, alt_user]: |
| 92 | cls.os_admin.identity_client.assign_user_role(user['tenantId'], |
| 93 | user['id'], |
| 94 | role['id']) |
| 95 | |
| 96 | @classmethod |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 97 | def delete_containers(cls, containers, container_client=None, |
| 98 | object_client=None): |
| 99 | """Remove given containers and all objects in them. |
| 100 | |
| 101 | The containers should be visible from the container_client given. |
| 102 | Will not throw any error if the containers don't exist. |
| 103 | |
| 104 | :param containers: list of container names to remove |
| 105 | :param container_client: if None, use cls.container_client, this means |
| 106 | that the default testing user will be used (see 'username' in |
| 107 | 'etc/tempest.conf') |
| 108 | :param object_client: if None, use cls.object_client |
| 109 | """ |
| 110 | if container_client is None: |
| 111 | container_client = cls.container_client |
| 112 | if object_client is None: |
| 113 | object_client = cls.object_client |
| 114 | for cont in containers: |
| 115 | try: |
| 116 | objlist = container_client.list_all_container_objects(cont) |
| 117 | # delete every object in the container |
| 118 | for obj in objlist: |
| 119 | object_client.delete_object(cont, obj['name']) |
| 120 | container_client.delete_container(cont) |
| 121 | except exceptions.NotFound: |
| 122 | pass |