blob: bf013ec3d3fa7c0a4d77761b26741a1f7e1d5386 [file] [log] [blame]
dwalleck5d734432012-10-04 01:11:47 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
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
dwalleck5d734432012-10-04 01:11:47 -050018
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.identity.base import DataGenerator
Matthew Treinish481466b2012-12-20 17:16:01 -050020from tempest import clients
dwalleck5d734432012-10-04 01:11:47 -050021from tempest import exceptions
Attila Fazekasdc216422013-01-29 15:12:14 +010022import tempest.test
dwalleck5d734432012-10-04 01:11:47 -050023
24
Attila Fazekasdc216422013-01-29 15:12:14 +010025class BaseObjectTest(tempest.test.BaseTestCase):
dwalleck5d734432012-10-04 01:11:47 -050026
27 @classmethod
28 def setUpClass(cls):
Matthew Treinish481466b2012-12-20 17:16:01 -050029 cls.os = clients.Manager()
dwalleck5d734432012-10-04 01:11:47 -050030 cls.object_client = cls.os.object_client
31 cls.container_client = cls.os.container_client
32 cls.account_client = cls.os.account_client
harika-vakadi1a9ad612012-12-14 19:12:08 +053033 cls.custom_object_client = cls.os.custom_object_client
Attila Fazekas407b6db2013-01-19 12:48:36 +010034 cls.os_admin = clients.AdminManager()
harika-vakadi2daed0a2013-01-01 20:51:39 +053035 cls.token_client = cls.os_admin.token_client
Attila Fazekas407b6db2013-01-19 12:48:36 +010036 cls.identity_admin_client = cls.os_admin.identity_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053037 cls.custom_account_client = cls.os.custom_account_client
38 cls.os_alt = clients.AltManager()
39 cls.object_client_alt = cls.os_alt.object_client
40 cls.container_client_alt = cls.os_alt.container_client
Attila Fazekas407b6db2013-01-19 12:48:36 +010041 cls.identity_client_alt = cls.os_alt.identity_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053042
Attila Fazekas407b6db2013-01-19 12:48:36 +010043 cls.data = DataGenerator(cls.identity_admin_client)
dwalleck5d734432012-10-04 01:11:47 -050044
45 try:
46 cls.account_client.list_account_containers()
47 except exceptions.EndpointNotFound:
dwalleck5d734432012-10-04 01:11:47 -050048 skip_msg = "No OpenStack Object Storage API endpoint"
ivan-zhu1feeb382013-01-24 10:14:39 +080049 raise cls.skipException(skip_msg)
Martina Kollarovafd850b92013-05-20 15:40:13 +020050
51 @classmethod
52 def delete_containers(cls, containers, container_client=None,
53 object_client=None):
54 """Remove given containers and all objects in them.
55
56 The containers should be visible from the container_client given.
57 Will not throw any error if the containers don't exist.
58
59 :param containers: list of container names to remove
60 :param container_client: if None, use cls.container_client, this means
61 that the default testing user will be used (see 'username' in
62 'etc/tempest.conf')
63 :param object_client: if None, use cls.object_client
64 """
65 if container_client is None:
66 container_client = cls.container_client
67 if object_client is None:
68 object_client = cls.object_client
69 for cont in containers:
70 try:
71 objlist = container_client.list_all_container_objects(cont)
72 # delete every object in the container
73 for obj in objlist:
74 object_client.delete_object(cont, obj['name'])
75 container_client.delete_container(cont)
76 except exceptions.NotFound:
77 pass