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 | |
Daisuke Morita | 8e1f861 | 2013-11-26 15:43:21 +0900 | [diff] [blame] | 18 | from tempest.common import custom_matchers |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 19 | from tempest import config |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 20 | import tempest.test |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 21 | |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 22 | CONF = config.CONF |
| 23 | |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 24 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 25 | class BaseObjectTest(tempest.test.BaseTestCase): |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 26 | |
Andrea Frittoli (andreaf) | 825b2d3 | 2015-04-08 20:58:01 +0100 | [diff] [blame] | 27 | credentials = [['operator', CONF.object_storage.operator_role]] |
| 28 | |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 29 | @classmethod |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame] | 30 | def skip_checks(cls): |
| 31 | super(BaseObjectTest, cls).skip_checks() |
Matthew Treinish | cb09bbb | 2014-01-29 18:20:25 +0000 | [diff] [blame] | 32 | if not CONF.service_available.swift: |
Matthew Treinish | 61e332b | 2013-07-19 16:42:31 -0400 | [diff] [blame] | 33 | skip_msg = ("%s skipped as swift is not available" % cls.__name__) |
| 34 | raise cls.skipException(skip_msg) |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame] | 35 | |
| 36 | @classmethod |
| 37 | def setup_credentials(cls): |
| 38 | cls.set_network_resources() |
| 39 | super(BaseObjectTest, cls).setup_credentials() |
Andrea Frittoli (andreaf) | 825b2d3 | 2015-04-08 20:58:01 +0100 | [diff] [blame] | 40 | # credentials may be overwritten by children classes |
| 41 | if hasattr(cls, 'os_roles_operator'): |
| 42 | cls.os = cls.os_roles_operator |
Matthew Treinish | 3fdb80c | 2013-08-15 11:13:19 -0400 | [diff] [blame] | 43 | |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame] | 44 | @classmethod |
| 45 | def setup_clients(cls): |
| 46 | super(BaseObjectTest, cls).setup_clients() |
dwalleck | 5d73443 | 2012-10-04 01:11:47 -0500 | [diff] [blame] | 47 | cls.object_client = cls.os.object_client |
| 48 | cls.container_client = cls.os.container_client |
| 49 | cls.account_client = cls.os.account_client |
harika-vakadi | 2daed0a | 2013-01-01 20:51:39 +0530 | [diff] [blame] | 50 | |
Rohan Kanade | f30a569 | 2015-02-18 01:43:31 +0530 | [diff] [blame] | 51 | @classmethod |
| 52 | def resource_setup(cls): |
| 53 | super(BaseObjectTest, cls).resource_setup() |
| 54 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 55 | # Make sure we get fresh auth data after assigning swift role |
| 56 | cls.object_client.auth_provider.clear_auth() |
| 57 | cls.container_client.auth_provider.clear_auth() |
| 58 | cls.account_client.auth_provider.clear_auth() |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 59 | |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 60 | @classmethod |
| 61 | def delete_containers(cls, containers, container_client=None, |
| 62 | object_client=None): |
| 63 | """Remove given containers and all objects in them. |
| 64 | |
| 65 | The containers should be visible from the container_client given. |
| 66 | Will not throw any error if the containers don't exist. |
Fabien Boucher | c3a9ba8 | 2014-01-03 13:17:05 +0100 | [diff] [blame] | 67 | Will not check that object and container deletions succeed. |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 68 | |
| 69 | :param containers: list of container names to remove |
| 70 | :param container_client: if None, use cls.container_client, this means |
| 71 | that the default testing user will be used (see 'username' in |
| 72 | 'etc/tempest.conf') |
| 73 | :param object_client: if None, use cls.object_client |
| 74 | """ |
| 75 | if container_client is None: |
| 76 | container_client = cls.container_client |
| 77 | if object_client is None: |
| 78 | object_client = cls.object_client |
| 79 | for cont in containers: |
| 80 | try: |
| 81 | objlist = container_client.list_all_container_objects(cont) |
| 82 | # delete every object in the container |
| 83 | for obj in objlist: |
Ala Rezmerita | a81af8c | 2014-02-18 16:01:48 +0100 | [diff] [blame] | 84 | try: |
| 85 | object_client.delete_object(cont, obj['name']) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 86 | except lib_exc.NotFound: |
Ala Rezmerita | a81af8c | 2014-02-18 16:01:48 +0100 | [diff] [blame] | 87 | pass |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 88 | container_client.delete_container(cont) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 89 | except lib_exc.NotFound: |
Martina Kollarova | fd850b9 | 2013-05-20 15:40:13 +0200 | [diff] [blame] | 90 | pass |
Daisuke Morita | 8e1f861 | 2013-11-26 15:43:21 +0900 | [diff] [blame] | 91 | |
| 92 | def assertHeaders(self, resp, target, method): |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 93 | """Check the existence and the format of response headers""" |
| 94 | |
Daisuke Morita | 8e1f861 | 2013-11-26 15:43:21 +0900 | [diff] [blame] | 95 | self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders( |
| 96 | target, method)) |
| 97 | self.assertThat(resp, custom_matchers.AreAllWellFormatted()) |