blob: 1ca0128e96a405a86cf86fafcea5a7c49f5b89f8 [file] [log] [blame]
Andrea Frittoli8283b4e2014-07-17 13:28:58 +01001# 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
Matthew Treinish976e8df2014-12-19 14:21:54 -050014import os
15
Andrea Frittoli8283b4e2014-07-17 13:28:58 +010016from tempest.common import accounts
Emily Hugenbruche7991d92014-12-12 16:53:36 +000017from tempest.common import cred_provider
Andrea Frittoli8283b4e2014-07-17 13:28:58 +010018from tempest.common import isolated_creds
19from tempest import config
Matthew Treinishfda37652015-02-20 15:14:53 -050020from tempest import exceptions
Andrea Frittoli8283b4e2014-07-17 13:28:58 +010021
22CONF = config.CONF
23
24
25# Return the right implementation of CredentialProvider based on config
26# Dropping interface and password, as they are never used anyways
27# TODO(andreaf) Drop them from the CredentialsProvider interface completely
28def get_isolated_credentials(name, network_resources=None,
Andrea Frittoli (andreaf)345c7fa2015-03-25 10:10:42 -040029 force_tenant_isolation=False,
30 identity_version=None):
Andrea Frittoli8283b4e2014-07-17 13:28:58 +010031 # If a test requires a new account to work, it can have it via forcing
32 # tenant isolation. A new account will be produced only for that test.
33 # In case admin credentials are not available for the account creation,
34 # the test should be skipped else it would fail.
35 if CONF.auth.allow_tenant_isolation or force_tenant_isolation:
36 return isolated_creds.IsolatedCreds(
37 name=name,
Andrea Frittoli (andreaf)345c7fa2015-03-25 10:10:42 -040038 network_resources=network_resources,
39 identity_version=identity_version)
Andrea Frittoli8283b4e2014-07-17 13:28:58 +010040 else:
41 if CONF.auth.locking_credentials_provider:
42 # Most params are not relevant for pre-created accounts
Andrea Frittoli (andreaf)345c7fa2015-03-25 10:10:42 -040043 return accounts.Accounts(name=name,
44 identity_version=identity_version)
Andrea Frittoli8283b4e2014-07-17 13:28:58 +010045 else:
Andrea Frittoli (andreaf)345c7fa2015-03-25 10:10:42 -040046 return accounts.NotLockingAccounts(
47 name=name, identity_version=identity_version)
Emily Hugenbruche7991d92014-12-12 16:53:36 +000048
49
50# We want a helper function here to check and see if admin credentials
51# are available so we can do a single call from skip_checks if admin
52# creds area vailable.
53def is_admin_available():
54 is_admin = True
Matthew Treinish976e8df2014-12-19 14:21:54 -050055 # If tenant isolation is enabled admin will be available
56 if CONF.auth.allow_tenant_isolation:
57 return is_admin
58 # Check whether test accounts file has the admin specified or not
59 elif os.path.isfile(CONF.auth.test_accounts_file):
60 check_accounts = accounts.Accounts(name='check_admin')
61 if not check_accounts.admin_available():
62 is_admin = False
Emily Hugenbruche7991d92014-12-12 16:53:36 +000063 else:
64 try:
David Kranz8d557c72015-03-11 11:51:07 -040065 cred_provider.get_configured_credentials('identity_admin',
66 fill_in=False)
Matthew Treinishfda37652015-02-20 15:14:53 -050067 except exceptions.InvalidConfiguration:
68 is_admin = False
Emily Hugenbruche7991d92014-12-12 16:53:36 +000069 return is_admin