Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 1 | # Copyright (c) 2014 Hewlett-Packard Development Company, L.P. |
| 2 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | # you may not use this file except in compliance with the License. |
| 4 | # You may obtain a copy of the License at |
| 5 | # |
| 6 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | # |
| 8 | # Unless required by applicable law or agreed to in writing, software |
| 9 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
| 13 | |
| 14 | from tempest.common import accounts |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 15 | from tempest.common import cred_provider |
Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 16 | from tempest.common import isolated_creds |
| 17 | from tempest import config |
| 18 | |
| 19 | CONF = config.CONF |
| 20 | |
| 21 | |
| 22 | # Return the right implementation of CredentialProvider based on config |
| 23 | # Dropping interface and password, as they are never used anyways |
| 24 | # TODO(andreaf) Drop them from the CredentialsProvider interface completely |
| 25 | def get_isolated_credentials(name, network_resources=None, |
| 26 | force_tenant_isolation=False): |
| 27 | # If a test requires a new account to work, it can have it via forcing |
| 28 | # tenant isolation. A new account will be produced only for that test. |
| 29 | # In case admin credentials are not available for the account creation, |
| 30 | # the test should be skipped else it would fail. |
| 31 | if CONF.auth.allow_tenant_isolation or force_tenant_isolation: |
| 32 | return isolated_creds.IsolatedCreds( |
| 33 | name=name, |
| 34 | network_resources=network_resources) |
| 35 | else: |
| 36 | if CONF.auth.locking_credentials_provider: |
| 37 | # Most params are not relevant for pre-created accounts |
| 38 | return accounts.Accounts(name=name) |
| 39 | else: |
| 40 | return accounts.NotLockingAccounts(name=name) |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 41 | |
| 42 | |
| 43 | # We want a helper function here to check and see if admin credentials |
| 44 | # are available so we can do a single call from skip_checks if admin |
| 45 | # creds area vailable. |
| 46 | def is_admin_available(): |
| 47 | is_admin = True |
| 48 | # In the case of a pre-provisioned account, if even if creds were |
| 49 | # configured, the admin credentials won't be available |
| 50 | if (CONF.auth.locking_credentials_provider and |
| 51 | not CONF.auth.allow_tenant_isolation): |
| 52 | is_admin = False |
| 53 | else: |
| 54 | try: |
| 55 | cred_provider.get_configured_credentials('identity_admin') |
| 56 | except NotImplementedError: |
| 57 | is_admin = False |
| 58 | |
| 59 | return is_admin |