blob: 469defed352ac3c613e4d78b072fbc1e375f2f75 [file] [log] [blame]
Ken'ichi Ohmichi6ea3f982015-11-09 12:41:13 +00001# Copyright 2015 NEC Corporation
2# 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
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050016from tempest.lib import exceptions as lib_exc
Ken'ichi Ohmichi6ea3f982015-11-09 12:41:13 +000017
18
19def get_tenant_by_name(client, tenant_name):
20 tenants = client.list_tenants()['tenants']
21 for tenant in tenants:
22 if tenant['name'] == tenant_name:
23 return tenant
24 raise lib_exc.NotFound('No such tenant(%s) in %s' % (tenant_name, tenants))
Ken'ichi Ohmichid9fed312015-11-09 13:05:32 +000025
26
27def get_user_by_username(client, tenant_id, username):
28 users = client.list_tenant_users(tenant_id)['users']
29 for user in users:
30 if user['name'] == username:
31 return user
32 raise lib_exc.NotFound('No such user(%s) in %s' % (username, users))