blob: e7cb806608a9422e190f49f346a74e99f10f46bd [file] [log] [blame]
dwalleck5d734432012-10-04 01:11:47 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
dwalleck5d734432012-10-04 01:11:47 -05004# 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
Daisuke Morita8e1f8612013-11-26 15:43:21 +090021from tempest.common import custom_matchers
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040022from tempest.common import isolated_creds
dwalleck5d734432012-10-04 01:11:47 -050023from tempest import exceptions
Attila Fazekasdc216422013-01-29 15:12:14 +010024import tempest.test
dwalleck5d734432012-10-04 01:11:47 -050025
26
Attila Fazekasdc216422013-01-29 15:12:14 +010027class BaseObjectTest(tempest.test.BaseTestCase):
dwalleck5d734432012-10-04 01:11:47 -050028
29 @classmethod
30 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020031 super(BaseObjectTest, cls).setUpClass()
Matthew Treinish61e332b2013-07-19 16:42:31 -040032 if not cls.config.service_available.swift:
33 skip_msg = ("%s skipped as swift is not available" % cls.__name__)
34 raise cls.skipException(skip_msg)
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040035 cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
36 if cls.config.compute.allow_tenant_isolation:
37 # Get isolated creds for normal user
38 creds = cls.isolated_creds.get_primary_creds()
39 username, tenant_name, password = creds
40 cls.os = clients.Manager(username=username,
41 password=password,
42 tenant_name=tenant_name)
43 # Get isolated creds for admin user
44 admin_creds = cls.isolated_creds.get_admin_creds()
45 admin_username, admin_tenant_name, admin_password = admin_creds
46 cls.os_admin = clients.Manager(username=admin_username,
47 password=admin_password,
48 tenant_name=admin_tenant_name)
49 # Get isolated creds for alt user
50 alt_creds = cls.isolated_creds.get_alt_creds()
51 alt_username, alt_tenant, alt_password = alt_creds
52 cls.os_alt = clients.Manager(username=alt_username,
53 password=alt_password,
54 tenant_name=alt_tenant)
55 # Add isolated users to operator role so that they can create a
56 # container in swift.
57 cls._assign_member_role()
58 else:
59 cls.os = clients.Manager()
60 cls.os_admin = clients.AdminManager()
61 cls.os_alt = clients.AltManager()
62
dwalleck5d734432012-10-04 01:11:47 -050063 cls.object_client = cls.os.object_client
64 cls.container_client = cls.os.container_client
65 cls.account_client = cls.os.account_client
harika-vakadi1a9ad612012-12-14 19:12:08 +053066 cls.custom_object_client = cls.os.custom_object_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053067 cls.token_client = cls.os_admin.token_client
Attila Fazekas407b6db2013-01-19 12:48:36 +010068 cls.identity_admin_client = cls.os_admin.identity_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053069 cls.custom_account_client = cls.os.custom_account_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053070 cls.object_client_alt = cls.os_alt.object_client
71 cls.container_client_alt = cls.os_alt.container_client
Attila Fazekas407b6db2013-01-19 12:48:36 +010072 cls.identity_client_alt = cls.os_alt.identity_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053073
Attila Fazekas407b6db2013-01-19 12:48:36 +010074 cls.data = DataGenerator(cls.identity_admin_client)
dwalleck5d734432012-10-04 01:11:47 -050075
Martina Kollarovafd850b92013-05-20 15:40:13 +020076 @classmethod
Matthew Treinishb7360f72013-09-13 15:40:11 +000077 def tearDownClass(cls):
78 cls.isolated_creds.clear_isolated_creds()
79 super(BaseObjectTest, cls).tearDownClass()
80
81 @classmethod
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040082 def _assign_member_role(cls):
83 primary_user = cls.isolated_creds.get_primary_user()
84 alt_user = cls.isolated_creds.get_alt_user()
85 swift_role = cls.config.object_storage.operator_role
86 try:
87 resp, roles = cls.os_admin.identity_client.list_roles()
88 role = next(r for r in roles if r['name'] == swift_role)
89 except StopIteration:
90 msg = "No role named %s found" % swift_role
91 raise exceptions.NotFound(msg)
92 for user in [primary_user, alt_user]:
93 cls.os_admin.identity_client.assign_user_role(user['tenantId'],
94 user['id'],
95 role['id'])
96
97 @classmethod
Martina Kollarovafd850b92013-05-20 15:40:13 +020098 def delete_containers(cls, containers, container_client=None,
99 object_client=None):
100 """Remove given containers and all objects in them.
101
102 The containers should be visible from the container_client given.
103 Will not throw any error if the containers don't exist.
104
105 :param containers: list of container names to remove
106 :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
115 for cont in containers:
116 try:
117 objlist = container_client.list_all_container_objects(cont)
118 # delete every object in the container
119 for obj in objlist:
120 object_client.delete_object(cont, obj['name'])
121 container_client.delete_container(cont)
122 except exceptions.NotFound:
123 pass
Daisuke Morita8e1f8612013-11-26 15:43:21 +0900124
125 def assertHeaders(self, resp, target, method):
126 """
127 Common method to check the existence and the format of common response
128 headers
129 """
130 self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders(
131 target, method))
132 self.assertThat(resp, custom_matchers.AreAllWellFormatted())