Ken'ichi Ohmichi | 6ea3f98 | 2015-11-09 12:41:13 +0000 | [diff] [blame] | 1 | # 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) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame^] | 16 | from tempest.lib import exceptions as lib_exc |
Ken'ichi Ohmichi | 6ea3f98 | 2015-11-09 12:41:13 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | def 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 Ohmichi | d9fed31 | 2015-11-09 13:05:32 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def 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)) |