blob: 044e8c1e2ce5dfd8553cc0925b103c138488e453 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
dwalleck5d734432012-10-04 01:11:47 -05002# 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
Daisuke Morita8e1f8612013-11-26 15:43:21 +090016from tempest.common import custom_matchers
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000017from tempest import config
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050018from tempest.lib import exceptions as lib_exc
Attila Fazekasdc216422013-01-29 15:12:14 +010019import tempest.test
dwalleck5d734432012-10-04 01:11:47 -050020
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000021CONF = config.CONF
22
dwalleck5d734432012-10-04 01:11:47 -050023
Attila Fazekasdc216422013-01-29 15:12:14 +010024class BaseObjectTest(tempest.test.BaseTestCase):
dwalleck5d734432012-10-04 01:11:47 -050025
Andrea Frittoli (andreaf)825b2d32015-04-08 20:58:01 +010026 credentials = [['operator', CONF.object_storage.operator_role]]
27
dwalleck5d734432012-10-04 01:11:47 -050028 @classmethod
Rohan Kanadef30a5692015-02-18 01:43:31 +053029 def skip_checks(cls):
30 super(BaseObjectTest, cls).skip_checks()
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000031 if not CONF.service_available.swift:
Matthew Treinish61e332b2013-07-19 16:42:31 -040032 skip_msg = ("%s skipped as swift is not available" % cls.__name__)
33 raise cls.skipException(skip_msg)
Rohan Kanadef30a5692015-02-18 01:43:31 +053034
35 @classmethod
36 def setup_credentials(cls):
37 cls.set_network_resources()
38 super(BaseObjectTest, cls).setup_credentials()
Andrea Frittoli (andreaf)825b2d32015-04-08 20:58:01 +010039 # credentials may be overwritten by children classes
40 if hasattr(cls, 'os_roles_operator'):
41 cls.os = cls.os_roles_operator
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040042
Rohan Kanadef30a5692015-02-18 01:43:31 +053043 @classmethod
44 def setup_clients(cls):
45 super(BaseObjectTest, cls).setup_clients()
dwalleck5d734432012-10-04 01:11:47 -050046 cls.object_client = cls.os.object_client
47 cls.container_client = cls.os.container_client
48 cls.account_client = cls.os.account_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053049
Rohan Kanadef30a5692015-02-18 01:43:31 +053050 @classmethod
51 def resource_setup(cls):
52 super(BaseObjectTest, cls).resource_setup()
53
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000054 # Make sure we get fresh auth data after assigning swift role
55 cls.object_client.auth_provider.clear_auth()
56 cls.container_client.auth_provider.clear_auth()
57 cls.account_client.auth_provider.clear_auth()
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000058
Martina Kollarovafd850b92013-05-20 15:40:13 +020059 @classmethod
60 def delete_containers(cls, containers, container_client=None,
61 object_client=None):
62 """Remove given containers and all objects in them.
63
64 The containers should be visible from the container_client given.
65 Will not throw any error if the containers don't exist.
Fabien Boucherc3a9ba82014-01-03 13:17:05 +010066 Will not check that object and container deletions succeed.
Martina Kollarovafd850b92013-05-20 15:40:13 +020067
68 :param containers: list of container names to remove
69 :param container_client: if None, use cls.container_client, this means
70 that the default testing user will be used (see 'username' in
71 'etc/tempest.conf')
72 :param object_client: if None, use cls.object_client
73 """
74 if container_client is None:
75 container_client = cls.container_client
76 if object_client is None:
77 object_client = cls.object_client
78 for cont in containers:
79 try:
80 objlist = container_client.list_all_container_objects(cont)
81 # delete every object in the container
82 for obj in objlist:
Ala Rezmeritaa81af8c2014-02-18 16:01:48 +010083 try:
84 object_client.delete_object(cont, obj['name'])
Masayuki Igawabfa07602015-01-20 18:47:17 +090085 except lib_exc.NotFound:
Ala Rezmeritaa81af8c2014-02-18 16:01:48 +010086 pass
Martina Kollarovafd850b92013-05-20 15:40:13 +020087 container_client.delete_container(cont)
Masayuki Igawabfa07602015-01-20 18:47:17 +090088 except lib_exc.NotFound:
Martina Kollarovafd850b92013-05-20 15:40:13 +020089 pass
Daisuke Morita8e1f8612013-11-26 15:43:21 +090090
91 def assertHeaders(self, resp, target, method):
Ken'ichi Ohmichi9e3dac02015-11-19 07:01:07 +000092 """Check the existence and the format of response headers"""
93
Daisuke Morita8e1f8612013-11-26 15:43:21 +090094 self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders(
95 target, method))
96 self.assertThat(resp, custom_matchers.AreAllWellFormatted())