blob: c6639c22162c849d862f82cdbf7ed59319989579 [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
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040021from tempest.common import isolated_creds
dwalleck5d734432012-10-04 01:11:47 -050022from tempest import exceptions
Attila Fazekasdc216422013-01-29 15:12:14 +010023import tempest.test
dwalleck5d734432012-10-04 01:11:47 -050024
25
Attila Fazekasdc216422013-01-29 15:12:14 +010026class BaseObjectTest(tempest.test.BaseTestCase):
dwalleck5d734432012-10-04 01:11:47 -050027
28 @classmethod
29 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020030 super(BaseObjectTest, cls).setUpClass()
Matthew Treinish61e332b2013-07-19 16:42:31 -040031 if not cls.config.service_available.swift:
32 skip_msg = ("%s skipped as swift is not available" % cls.__name__)
33 raise cls.skipException(skip_msg)
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040034 cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
35 if cls.config.compute.allow_tenant_isolation:
36 # Get isolated creds for normal user
37 creds = cls.isolated_creds.get_primary_creds()
38 username, tenant_name, password = creds
39 cls.os = clients.Manager(username=username,
40 password=password,
41 tenant_name=tenant_name)
42 # Get isolated creds for admin user
43 admin_creds = cls.isolated_creds.get_admin_creds()
44 admin_username, admin_tenant_name, admin_password = admin_creds
45 cls.os_admin = clients.Manager(username=admin_username,
46 password=admin_password,
47 tenant_name=admin_tenant_name)
48 # Get isolated creds for alt user
49 alt_creds = cls.isolated_creds.get_alt_creds()
50 alt_username, alt_tenant, alt_password = alt_creds
51 cls.os_alt = clients.Manager(username=alt_username,
52 password=alt_password,
53 tenant_name=alt_tenant)
54 # Add isolated users to operator role so that they can create a
55 # container in swift.
56 cls._assign_member_role()
57 else:
58 cls.os = clients.Manager()
59 cls.os_admin = clients.AdminManager()
60 cls.os_alt = clients.AltManager()
61
dwalleck5d734432012-10-04 01:11:47 -050062 cls.object_client = cls.os.object_client
63 cls.container_client = cls.os.container_client
64 cls.account_client = cls.os.account_client
harika-vakadi1a9ad612012-12-14 19:12:08 +053065 cls.custom_object_client = cls.os.custom_object_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053066 cls.token_client = cls.os_admin.token_client
Attila Fazekas407b6db2013-01-19 12:48:36 +010067 cls.identity_admin_client = cls.os_admin.identity_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053068 cls.custom_account_client = cls.os.custom_account_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053069 cls.object_client_alt = cls.os_alt.object_client
70 cls.container_client_alt = cls.os_alt.container_client
Attila Fazekas407b6db2013-01-19 12:48:36 +010071 cls.identity_client_alt = cls.os_alt.identity_client
harika-vakadi2daed0a2013-01-01 20:51:39 +053072
Attila Fazekas407b6db2013-01-19 12:48:36 +010073 cls.data = DataGenerator(cls.identity_admin_client)
dwalleck5d734432012-10-04 01:11:47 -050074
Martina Kollarovafd850b92013-05-20 15:40:13 +020075 @classmethod
Matthew Treinishb7360f72013-09-13 15:40:11 +000076 def tearDownClass(cls):
77 cls.isolated_creds.clear_isolated_creds()
78 super(BaseObjectTest, cls).tearDownClass()
79
80 @classmethod
Matthew Treinish3fdb80c2013-08-15 11:13:19 -040081 def _assign_member_role(cls):
82 primary_user = cls.isolated_creds.get_primary_user()
83 alt_user = cls.isolated_creds.get_alt_user()
84 swift_role = cls.config.object_storage.operator_role
85 try:
86 resp, roles = cls.os_admin.identity_client.list_roles()
87 role = next(r for r in roles if r['name'] == swift_role)
88 except StopIteration:
89 msg = "No role named %s found" % swift_role
90 raise exceptions.NotFound(msg)
91 for user in [primary_user, alt_user]:
92 cls.os_admin.identity_client.assign_user_role(user['tenantId'],
93 user['id'],
94 role['id'])
95
96 @classmethod
Martina Kollarovafd850b92013-05-20 15:40:13 +020097 def delete_containers(cls, containers, container_client=None,
98 object_client=None):
99 """Remove given containers and all objects in them.
100
101 The containers should be visible from the container_client given.
102 Will not throw any error if the containers don't exist.
103
104 :param containers: list of container names to remove
105 :param container_client: if None, use cls.container_client, this means
106 that the default testing user will be used (see 'username' in
107 'etc/tempest.conf')
108 :param object_client: if None, use cls.object_client
109 """
110 if container_client is None:
111 container_client = cls.container_client
112 if object_client is None:
113 object_client = cls.object_client
114 for cont in containers:
115 try:
116 objlist = container_client.list_all_container_objects(cont)
117 # delete every object in the container
118 for obj in objlist:
119 object_client.delete_object(cont, obj['name'])
120 container_client.delete_container(cont)
121 except exceptions.NotFound:
122 pass