blob: fd973c63198de17c85d6ebc26bcb993f7bdfd94c [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
Cindy Lu6bdc3ed2016-05-31 16:07:43 -070018from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010019from tempest.lib.common.utils import test_utils
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050020from tempest.lib import exceptions as lib_exc
Attila Fazekasdc216422013-01-29 15:12:14 +010021import tempest.test
dwalleck5d734432012-10-04 01:11:47 -050022
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000023CONF = config.CONF
24
dwalleck5d734432012-10-04 01:11:47 -050025
Attila Fazekasdc216422013-01-29 15:12:14 +010026class BaseObjectTest(tempest.test.BaseTestCase):
dwalleck5d734432012-10-04 01:11:47 -050027
Andrea Frittoli (andreaf)825b2d32015-04-08 20:58:01 +010028 credentials = [['operator', CONF.object_storage.operator_role]]
29
dwalleck5d734432012-10-04 01:11:47 -050030 @classmethod
Rohan Kanadef30a5692015-02-18 01:43:31 +053031 def skip_checks(cls):
32 super(BaseObjectTest, cls).skip_checks()
Matthew Treinishcb09bbb2014-01-29 18:20:25 +000033 if not CONF.service_available.swift:
Matthew Treinish61e332b2013-07-19 16:42:31 -040034 skip_msg = ("%s skipped as swift is not available" % cls.__name__)
35 raise cls.skipException(skip_msg)
Rohan Kanadef30a5692015-02-18 01:43:31 +053036
37 @classmethod
38 def setup_credentials(cls):
39 cls.set_network_resources()
40 super(BaseObjectTest, cls).setup_credentials()
Andrea Frittoli (andreaf)825b2d32015-04-08 20:58:01 +010041 # credentials may be overwritten by children classes
42 if hasattr(cls, 'os_roles_operator'):
43 cls.os = cls.os_roles_operator
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040044
Rohan Kanadef30a5692015-02-18 01:43:31 +053045 @classmethod
46 def setup_clients(cls):
47 super(BaseObjectTest, cls).setup_clients()
dwalleck5d734432012-10-04 01:11:47 -050048 cls.object_client = cls.os.object_client
49 cls.container_client = cls.os.container_client
50 cls.account_client = cls.os.account_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053051
Rohan Kanadef30a5692015-02-18 01:43:31 +053052 @classmethod
53 def resource_setup(cls):
54 super(BaseObjectTest, cls).resource_setup()
55
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000056 # Make sure we get fresh auth data after assigning swift role
57 cls.object_client.auth_provider.clear_auth()
58 cls.container_client.auth_provider.clear_auth()
59 cls.account_client.auth_provider.clear_auth()
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000060
Brian Obera212c4a2016-04-16 18:30:12 -050061 # make sure that discoverability is enabled and that the sections
62 # have not been disallowed by Swift
63 cls.policies = None
64
65 if CONF.object_storage_feature_enabled.discoverability:
66 _, body = cls.account_client.list_extensions()
67
68 if 'swift' in body and 'policies' in body['swift']:
69 cls.policies = body['swift']['policies']
70
Cindy Lu6bdc3ed2016-05-31 16:07:43 -070071 cls.containers = []
72
Martina Kollarovafd850b92013-05-20 15:40:13 +020073 @classmethod
Cindy Lu6bdc3ed2016-05-31 16:07:43 -070074 def create_container(cls):
75 # wrapper that returns a test container
76 container_name = data_utils.rand_name(name='TestContainer')
77 cls.container_client.create_container(container_name)
78 cls.containers.append(container_name)
79
80 return container_name
81
82 @classmethod
83 def create_object(cls, container_name, object_name=None,
84 data=None, metadata=None):
85 # wrapper that returns a test object
86 if object_name is None:
87 object_name = data_utils.rand_name(name='TestObject')
88 if data is None:
89 data = data_utils.arbitrary_string()
90 cls.object_client.create_object(container_name,
91 object_name,
92 data,
93 metadata=metadata)
94
95 return object_name, data
96
97 @classmethod
98 def delete_containers(cls, container_client=None,
Martina Kollarovafd850b92013-05-20 15:40:13 +020099 object_client=None):
Cindy Lu6bdc3ed2016-05-31 16:07:43 -0700100 """Remove containers and all objects in them.
Martina Kollarovafd850b92013-05-20 15:40:13 +0200101
102 The containers should be visible from the container_client given.
103 Will not throw any error if the containers don't exist.
Fabien Boucherc3a9ba82014-01-03 13:17:05 +0100104 Will not check that object and container deletions succeed.
Martina Kollarovafd850b92013-05-20 15:40:13 +0200105
Martina Kollarovafd850b92013-05-20 15:40:13 +0200106 :param container_client: if None, use cls.container_client, this means
107 that the default testing user will be used (see 'username' in
108 'etc/tempest.conf')
109 :param object_client: if None, use cls.object_client
110 """
111 if container_client is None:
112 container_client = cls.container_client
113 if object_client is None:
114 object_client = cls.object_client
Cindy Lu6bdc3ed2016-05-31 16:07:43 -0700115 for cont in cls.containers:
Martina Kollarovafd850b92013-05-20 15:40:13 +0200116 try:
117 objlist = container_client.list_all_container_objects(cont)
118 # delete every object in the container
119 for obj in objlist:
Jordan Pittier9e227c52016-02-09 14:35:18 +0100120 test_utils.call_and_ignore_notfound_exc(
121 object_client.delete_object, cont, obj['name'])
Martina Kollarovafd850b92013-05-20 15:40:13 +0200122 container_client.delete_container(cont)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900123 except lib_exc.NotFound:
Martina Kollarovafd850b92013-05-20 15:40:13 +0200124 pass
Daisuke Morita8e1f8612013-11-26 15:43:21 +0900125
126 def assertHeaders(self, resp, target, method):
Ken'ichi Ohmichi9e3dac02015-11-19 07:01:07 +0000127 """Check the existence and the format of response headers"""
128
Daisuke Morita8e1f8612013-11-26 15:43:21 +0900129 self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders(
Brian Obera212c4a2016-04-16 18:30:12 -0500130 target, method, self.policies))
Daisuke Morita8e1f8612013-11-26 15:43:21 +0900131 self.assertThat(resp, custom_matchers.AreAllWellFormatted())