blob: f75f4c843ac18aae75a6f638a25c1e0ed923b028 [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
Masayuki Igawabfa07602015-01-20 18:47:17 +090016from tempest_lib import exceptions as lib_exc
dwalleck5d734432012-10-04 01:11:47 -050017
Matthew Treinish481466b2012-12-20 17:16:01 -050018from tempest import clients
Cyril Roelandtc1482a22014-11-13 16:55:04 +010019from tempest.common import credentials
Daisuke Morita8e1f8612013-11-26 15:43:21 +090020from tempest.common import custom_matchers
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000021from tempest import config
Attila Fazekasdc216422013-01-29 15:12:14 +010022import tempest.test
dwalleck5d734432012-10-04 01:11:47 -050023
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000024CONF = config.CONF
25
dwalleck5d734432012-10-04 01:11:47 -050026
Attila Fazekasdc216422013-01-29 15:12:14 +010027class BaseObjectTest(tempest.test.BaseTestCase):
dwalleck5d734432012-10-04 01:11:47 -050028
29 @classmethod
Rohan Kanadef30a5692015-02-18 01:43:31 +053030 def skip_checks(cls):
31 super(BaseObjectTest, cls).skip_checks()
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000032 if not CONF.service_available.swift:
Matthew Treinish61e332b2013-07-19 16:42:31 -040033 skip_msg = ("%s skipped as swift is not available" % cls.__name__)
34 raise cls.skipException(skip_msg)
Rohan Kanadef30a5692015-02-18 01:43:31 +053035
36 @classmethod
37 def setup_credentials(cls):
38 cls.set_network_resources()
39 super(BaseObjectTest, cls).setup_credentials()
Cyril Roelandtc1482a22014-11-13 16:55:04 +010040 cls.isolated_creds = credentials.get_isolated_credentials(
Matthew Treinish9f756a02014-01-15 10:26:07 -050041 cls.__name__, network_resources=cls.network_resources)
Matthew Treinish4a596932015-03-06 20:37:01 -050042 operator_role = CONF.object_storage.operator_role
43 if not cls.isolated_creds.is_role_available(operator_role):
44 skip_msg = ("%s skipped because the configured credential provider"
45 " is not able to provide credentials with the %s role "
46 "assigned." % (cls.__name__, operator_role))
47 raise cls.skipException(skip_msg)
48 else:
49 # Get isolated creds for normal user
50 cls.os = clients.Manager(cls.isolated_creds.get_creds_by_roles(
51 [operator_role]))
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040052
Rohan Kanadef30a5692015-02-18 01:43:31 +053053 @classmethod
54 def setup_clients(cls):
55 super(BaseObjectTest, cls).setup_clients()
dwalleck5d734432012-10-04 01:11:47 -050056 cls.object_client = cls.os.object_client
57 cls.container_client = cls.os.container_client
58 cls.account_client = cls.os.account_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053059
Rohan Kanadef30a5692015-02-18 01:43:31 +053060 @classmethod
61 def resource_setup(cls):
62 super(BaseObjectTest, cls).resource_setup()
63
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000064 # Make sure we get fresh auth data after assigning swift role
65 cls.object_client.auth_provider.clear_auth()
66 cls.container_client.auth_provider.clear_auth()
67 cls.account_client.auth_provider.clear_auth()
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000068
Martina Kollarovafd850b92013-05-20 15:40:13 +020069 @classmethod
Andrea Frittoli5f13f712014-09-15 13:14:54 +010070 def resource_cleanup(cls):
Matthew Treinishb7360f72013-09-13 15:40:11 +000071 cls.isolated_creds.clear_isolated_creds()
Andrea Frittoli5f13f712014-09-15 13:14:54 +010072 super(BaseObjectTest, cls).resource_cleanup()
Matthew Treinishb7360f72013-09-13 15:40:11 +000073
74 @classmethod
Martina Kollarovafd850b92013-05-20 15:40:13 +020075 def delete_containers(cls, containers, container_client=None,
76 object_client=None):
77 """Remove given containers and all objects in them.
78
79 The containers should be visible from the container_client given.
80 Will not throw any error if the containers don't exist.
Fabien Boucherc3a9ba82014-01-03 13:17:05 +010081 Will not check that object and container deletions succeed.
Martina Kollarovafd850b92013-05-20 15:40:13 +020082
83 :param containers: list of container names to remove
84 :param container_client: if None, use cls.container_client, this means
85 that the default testing user will be used (see 'username' in
86 'etc/tempest.conf')
87 :param object_client: if None, use cls.object_client
88 """
89 if container_client is None:
90 container_client = cls.container_client
91 if object_client is None:
92 object_client = cls.object_client
93 for cont in containers:
94 try:
95 objlist = container_client.list_all_container_objects(cont)
96 # delete every object in the container
97 for obj in objlist:
Ala Rezmeritaa81af8c2014-02-18 16:01:48 +010098 try:
99 object_client.delete_object(cont, obj['name'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900100 except lib_exc.NotFound:
Ala Rezmeritaa81af8c2014-02-18 16:01:48 +0100101 pass
Martina Kollarovafd850b92013-05-20 15:40:13 +0200102 container_client.delete_container(cont)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900103 except lib_exc.NotFound:
Martina Kollarovafd850b92013-05-20 15:40:13 +0200104 pass
Daisuke Morita8e1f8612013-11-26 15:43:21 +0900105
106 def assertHeaders(self, resp, target, method):
107 """
108 Common method to check the existence and the format of common response
109 headers
110 """
111 self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders(
112 target, method))
113 self.assertThat(resp, custom_matchers.AreAllWellFormatted())