blob: 7350222a89b6fc7690085ea965b71f2fb43e5fa7 [file] [log] [blame]
Matthew Treinishc791ac42014-07-16 09:15:23 -04001# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import hashlib
16import os
Matthew Treinish96e9e882014-06-09 18:37:19 -040017
Doug Hellmann583ce2c2015-03-11 14:55:46 +000018from oslo_concurrency import lockutils
19from oslo_log import log as logging
Matthew Treinish1c517a22015-04-23 11:39:44 -040020import six
Matthew Treinishc791ac42014-07-16 09:15:23 -040021import yaml
22
Matthew Treinishf83f35c2015-04-10 11:59:11 -040023from tempest import clients
Matthew Treinishc791ac42014-07-16 09:15:23 -040024from tempest.common import cred_provider
Matthew Treinishf83f35c2015-04-10 11:59:11 -040025from tempest.common import fixed_network
Matthew Treinishc791ac42014-07-16 09:15:23 -040026from tempest import exceptions
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050027from tempest.lib import auth
28from tempest.lib import exceptions as lib_exc
Matthew Treinishc791ac42014-07-16 09:15:23 -040029
Matthew Treinishc791ac42014-07-16 09:15:23 -040030LOG = logging.getLogger(__name__)
31
32
33def read_accounts_yaml(path):
Matthew Treinishd89db1b2015-12-16 17:29:14 -050034 try:
35 with open(path, 'r') as yaml_file:
36 accounts = yaml.load(yaml_file)
37 except IOError:
38 raise exceptions.InvalidConfiguration(
39 'The path for the test accounts file: %s '
40 'could not be found' % path)
Matthew Treinishc791ac42014-07-16 09:15:23 -040041 return accounts
42
43
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070044class PreProvisionedCredentialProvider(cred_provider.CredentialProvider):
Matthew Treinishc791ac42014-07-16 09:15:23 -040045
Andrea Frittoli (andreaf)52deb8b2016-05-18 19:14:22 +010046 # Exclude from the hash fields specific to v2 or v3 identity API
47 # i.e. only include user*, project*, tenant* and password
48 HASH_CRED_FIELDS = (set(auth.KeystoneV2Credentials.ATTRIBUTES) &
49 set(auth.KeystoneV3Credentials.ATTRIBUTES))
50
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010051 def __init__(self, identity_version, test_accounts_file,
52 accounts_lock_dir, name=None, credentials_domain=None,
53 admin_role=None, object_storage_operator_role=None,
54 object_storage_reseller_admin_role=None):
55 """Credentials provider using pre-provisioned accounts
56
57 This credentials provider loads the details of pre-provisioned
58 accounts from a YAML file, in the format specified by
59 `etc/accounts.yaml.sample`. It locks accounts while in use, using the
60 external locking mechanism, allowing for multiple python processes
61 to share a single account file, and thus running tests in parallel.
62
63 The accounts_lock_dir must be generated using `lockutils.get_lock_path`
64 from the oslo.concurrency library. For instance:
65
66 accounts_lock_dir = os.path.join(lockutils.get_lock_path(CONF),
67 'test_accounts')
68
69 Role names for object storage are optional as long as the
70 `operator` and `reseller_admin` credential types are not used in the
71 accounts file.
72
73 :param identity_version: identity version of the credentials
74 :param admin_role: name of the admin role
75 :param test_accounts_file: path to the accounts YAML file
76 :param accounts_lock_dir: the directory for external locking
77 :param name: name of the hash file (optional)
78 :param credentials_domain: name of the domain credentials belong to
79 (if no domain is configured)
80 :param object_storage_operator_role: name of the role
81 :param object_storage_reseller_admin_role: name of the role
82 """
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070083 super(PreProvisionedCredentialProvider, self).__init__(
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010084 identity_version=identity_version, name=name,
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010085 admin_role=admin_role, credentials_domain=credentials_domain)
86 self.test_accounts_file = test_accounts_file
Matthew Treinishd89db1b2015-12-16 17:29:14 -050087 if test_accounts_file:
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010088 accounts = read_accounts_yaml(self.test_accounts_file)
Matthew Treinishb19eeb82014-09-04 09:57:46 -040089 self.use_default_creds = False
90 else:
91 accounts = {}
92 self.use_default_creds = True
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010093 self.hash_dict = self.get_hash_dict(
94 accounts, admin_role, object_storage_operator_role,
95 object_storage_reseller_admin_role)
96 self.accounts_dir = accounts_lock_dir
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -070097 self._creds = {}
Matthew Treinishc791ac42014-07-16 09:15:23 -040098
99 @classmethod
Matthew Treinish976e8df2014-12-19 14:21:54 -0500100 def _append_role(cls, role, account_hash, hash_dict):
101 if role in hash_dict['roles']:
102 hash_dict['roles'][role].append(account_hash)
103 else:
104 hash_dict['roles'][role] = [account_hash]
105 return hash_dict
106
107 @classmethod
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100108 def get_hash_dict(cls, accounts, admin_role,
109 object_storage_operator_role=None,
110 object_storage_reseller_admin_role=None):
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400111 hash_dict = {'roles': {}, 'creds': {}, 'networks': {}}
Andrea Frittoli (andreaf)52deb8b2016-05-18 19:14:22 +0100112
Matthew Treinish976e8df2014-12-19 14:21:54 -0500113 # Loop over the accounts read from the yaml file
Matthew Treinishc791ac42014-07-16 09:15:23 -0400114 for account in accounts:
Matthew Treinish976e8df2014-12-19 14:21:54 -0500115 roles = []
116 types = []
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400117 resources = []
Matthew Treinish976e8df2014-12-19 14:21:54 -0500118 if 'roles' in account:
119 roles = account.pop('roles')
120 if 'types' in account:
121 types = account.pop('types')
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400122 if 'resources' in account:
123 resources = account.pop('resources')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400124 temp_hash = hashlib.md5()
Andrea Frittoli (andreaf)52deb8b2016-05-18 19:14:22 +0100125 account_for_hash = dict((k, v) for (k, v) in six.iteritems(account)
126 if k in cls.HASH_CRED_FIELDS)
127 temp_hash.update(six.text_type(account_for_hash).encode('utf-8'))
Matthew Treinish976e8df2014-12-19 14:21:54 -0500128 temp_hash_key = temp_hash.hexdigest()
129 hash_dict['creds'][temp_hash_key] = account
130 for role in roles:
131 hash_dict = cls._append_role(role, temp_hash_key,
132 hash_dict)
133 # If types are set for the account append the matching role
134 # subdict with the hash
135 for type in types:
136 if type == 'admin':
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100137 hash_dict = cls._append_role(admin_role, temp_hash_key,
138 hash_dict)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500139 elif type == 'operator':
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100140 if object_storage_operator_role:
141 hash_dict = cls._append_role(
142 object_storage_operator_role, temp_hash_key,
143 hash_dict)
144 else:
145 msg = ("Type 'operator' configured, but no "
146 "object_storage_operator_role specified")
147 raise lib_exc.InvalidCredentials(msg)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500148 elif type == 'reseller_admin':
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100149 if object_storage_reseller_admin_role:
150 hash_dict = cls._append_role(
151 object_storage_reseller_admin_role,
152 temp_hash_key,
153 hash_dict)
154 else:
155 msg = ("Type 'reseller_admin' configured, but no "
156 "object_storage_reseller_admin_role specified")
157 raise lib_exc.InvalidCredentials(msg)
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400158 # Populate the network subdict
159 for resource in resources:
160 if resource == 'network':
161 hash_dict['networks'][temp_hash_key] = resources[resource]
162 else:
Zhao Lei647cc182015-09-24 17:47:02 +0800163 LOG.warning('Unknown resource type %s, ignoring this field'
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400164 % resource)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400165 return hash_dict
166
Matthew Treinish09f17832014-08-15 15:22:50 -0400167 def is_multi_user(self):
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100168 # Default credentials is not a valid option with locking Account
169 if self.use_default_creds:
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100170 raise lib_exc.InvalidCredentials(
171 "Account file %s doesn't exist" % self.test_accounts_file)
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100172 else:
Matthew Treinish976e8df2014-12-19 14:21:54 -0500173 return len(self.hash_dict['creds']) > 1
Matthew Treinish09f17832014-08-15 15:22:50 -0400174
Yair Fried76488d72014-10-21 10:13:19 +0300175 def is_multi_tenant(self):
176 return self.is_multi_user()
177
Matthew Treinish09f17832014-08-15 15:22:50 -0400178 def _create_hash_file(self, hash_string):
179 path = os.path.join(os.path.join(self.accounts_dir, hash_string))
Matthew Treinishc791ac42014-07-16 09:15:23 -0400180 if not os.path.isfile(path):
Matthew Treinish4041b262015-02-27 11:18:54 -0500181 with open(path, 'w') as fd:
182 fd.write(self.name)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400183 return True
184 return False
185
186 @lockutils.synchronized('test_accounts_io', external=True)
187 def _get_free_hash(self, hashes):
Matthew Treinish976e8df2014-12-19 14:21:54 -0500188 # Cast as a list because in some edge cases a set will be passed in
189 hashes = list(hashes)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400190 if not os.path.isdir(self.accounts_dir):
191 os.mkdir(self.accounts_dir)
192 # Create File from first hash (since none are in use)
193 self._create_hash_file(hashes[0])
194 return hashes[0]
Matthew Treinish4041b262015-02-27 11:18:54 -0500195 names = []
Matthew Treinish09f17832014-08-15 15:22:50 -0400196 for _hash in hashes:
197 res = self._create_hash_file(_hash)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400198 if res:
Matthew Treinish09f17832014-08-15 15:22:50 -0400199 return _hash
Matthew Treinish4041b262015-02-27 11:18:54 -0500200 else:
201 path = os.path.join(os.path.join(self.accounts_dir,
202 _hash))
203 with open(path, 'r') as fd:
204 names.append(fd.read())
205 msg = ('Insufficient number of users provided. %s have allocated all '
206 'the credentials for this allocation request' % ','.join(names))
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100207 raise lib_exc.InvalidCredentials(msg)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400208
Matthew Treinish976e8df2014-12-19 14:21:54 -0500209 def _get_match_hash_list(self, roles=None):
210 hashes = []
211 if roles:
212 # Loop over all the creds for each role in the subdict and generate
213 # a list of cred lists for each role
214 for role in roles:
215 temp_hashes = self.hash_dict['roles'].get(role, None)
216 if not temp_hashes:
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100217 raise lib_exc.InvalidCredentials(
Matthew Treinish976e8df2014-12-19 14:21:54 -0500218 "No credentials with role: %s specified in the "
219 "accounts ""file" % role)
220 hashes.append(temp_hashes)
221 # Take the list of lists and do a boolean and between each list to
222 # find the creds which fall under all the specified roles
223 temp_list = set(hashes[0])
224 for hash_list in hashes[1:]:
225 temp_list = temp_list & set(hash_list)
226 hashes = temp_list
227 else:
228 hashes = self.hash_dict['creds'].keys()
229 # NOTE(mtreinish): admin is a special case because of the increased
zhufl0892cb22016-05-06 14:46:00 +0800230 # privilege set which could potentially cause issues on tests where
231 # that is not expected. So unless the admin role isn't specified do
232 # not allocate admin.
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100233 admin_hashes = self.hash_dict['roles'].get(self.admin_role,
Matthew Treinish976e8df2014-12-19 14:21:54 -0500234 None)
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100235 if ((not roles or self.admin_role not in roles) and
Matthew Treinish976e8df2014-12-19 14:21:54 -0500236 admin_hashes):
237 useable_hashes = [x for x in hashes if x not in admin_hashes]
238 else:
239 useable_hashes = hashes
240 return useable_hashes
241
Matthew Treinishfd683e82015-04-13 20:30:06 -0400242 def _sanitize_creds(self, creds):
243 temp_creds = creds.copy()
244 temp_creds.pop('password')
245 return temp_creds
246
Matthew Treinish976e8df2014-12-19 14:21:54 -0500247 def _get_creds(self, roles=None):
Matthew Treinishb19eeb82014-09-04 09:57:46 -0400248 if self.use_default_creds:
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100249 raise lib_exc.InvalidCredentials(
250 "Account file %s doesn't exist" % self.test_accounts_file)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500251 useable_hashes = self._get_match_hash_list(roles)
252 free_hash = self._get_free_hash(useable_hashes)
Matthew Treinishfd683e82015-04-13 20:30:06 -0400253 clean_creds = self._sanitize_creds(
254 self.hash_dict['creds'][free_hash])
255 LOG.info('%s allocated creds:\n%s' % (self.name, clean_creds))
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400256 return self._wrap_creds_with_network(free_hash)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400257
258 @lockutils.synchronized('test_accounts_io', external=True)
Matthew Treinish09f17832014-08-15 15:22:50 -0400259 def remove_hash(self, hash_string):
260 hash_path = os.path.join(self.accounts_dir, hash_string)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400261 if not os.path.isfile(hash_path):
262 LOG.warning('Expected an account lock file %s to remove, but '
Matthew Treinish53a2b4b2015-02-24 23:32:07 -0500263 'one did not exist' % hash_path)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400264 else:
265 os.remove(hash_path)
266 if not os.listdir(self.accounts_dir):
267 os.rmdir(self.accounts_dir)
268
269 def get_hash(self, creds):
Matthew Treinish976e8df2014-12-19 14:21:54 -0500270 for _hash in self.hash_dict['creds']:
271 # Comparing on the attributes that are expected in the YAML
Andrea Frittoli (andreaf)f39f9f32015-04-13 20:55:31 +0100272 init_attributes = creds.get_init_attributes()
Andrea Frittoli (andreaf)52deb8b2016-05-18 19:14:22 +0100273 # Only use the attributes initially used to calculate the hash
274 init_attributes = [x for x in init_attributes if
275 x in self.HASH_CRED_FIELDS]
Andrea Frittoli (andreaf)f39f9f32015-04-13 20:55:31 +0100276 hash_attributes = self.hash_dict['creds'][_hash].copy()
Andrea Frittoli (andreaf)52deb8b2016-05-18 19:14:22 +0100277 # NOTE(andreaf) Not all fields may be available on all credentials
278 # so defaulting to None for that case.
279 if all([getattr(creds, k, None) == hash_attributes.get(k, None) for
Andrea Frittoli (andreaf)f39f9f32015-04-13 20:55:31 +0100280 k in init_attributes]):
Matthew Treinish09f17832014-08-15 15:22:50 -0400281 return _hash
Matthew Treinishc791ac42014-07-16 09:15:23 -0400282 raise AttributeError('Invalid credentials %s' % creds)
283
284 def remove_credentials(self, creds):
Matthew Treinish09f17832014-08-15 15:22:50 -0400285 _hash = self.get_hash(creds)
Matthew Treinishfd683e82015-04-13 20:30:06 -0400286 clean_creds = self._sanitize_creds(self.hash_dict['creds'][_hash])
Matthew Treinish09f17832014-08-15 15:22:50 -0400287 self.remove_hash(_hash)
Matthew Treinishfd683e82015-04-13 20:30:06 -0400288 LOG.info("%s returned allocated creds:\n%s" % (self.name, clean_creds))
Matthew Treinishc791ac42014-07-16 09:15:23 -0400289
290 def get_primary_creds(self):
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700291 if self._creds.get('primary'):
292 return self._creds.get('primary')
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400293 net_creds = self._get_creds()
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700294 self._creds['primary'] = net_creds
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400295 return net_creds
Matthew Treinishc791ac42014-07-16 09:15:23 -0400296
297 def get_alt_creds(self):
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700298 if self._creds.get('alt'):
299 return self._creds.get('alt')
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400300 net_creds = self._get_creds()
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700301 self._creds['alt'] = net_creds
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400302 return net_creds
Matthew Treinishc791ac42014-07-16 09:15:23 -0400303
Matthew Treinish976e8df2014-12-19 14:21:54 -0500304 def get_creds_by_roles(self, roles, force_new=False):
305 roles = list(set(roles))
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700306 exist_creds = self._creds.get(six.text_type(roles).encode(
Matthew Treinish1c517a22015-04-23 11:39:44 -0400307 'utf-8'), None)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500308 # The force kwarg is used to allocate an additional set of creds with
309 # the same role list. The index used for the previously allocation
Ken'ichi Ohmichiedff8862015-10-13 01:10:53 +0000310 # in the _creds dict will be moved.
Matthew Treinish976e8df2014-12-19 14:21:54 -0500311 if exist_creds and not force_new:
312 return exist_creds
313 elif exist_creds and force_new:
Matthew Treinish1c517a22015-04-23 11:39:44 -0400314 new_index = six.text_type(roles).encode('utf-8') + '-' + \
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700315 six.text_type(len(self._creds)).encode('utf-8')
316 self._creds[new_index] = exist_creds
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400317 net_creds = self._get_creds(roles=roles)
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700318 self._creds[six.text_type(roles).encode('utf-8')] = net_creds
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400319 return net_creds
Matthew Treinish976e8df2014-12-19 14:21:54 -0500320
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700321 def clear_creds(self):
322 for creds in self._creds.values():
Matthew Treinishc791ac42014-07-16 09:15:23 -0400323 self.remove_credentials(creds)
324
325 def get_admin_creds(self):
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100326 return self.get_creds_by_roles([self.admin_role])
Matthew Treinish976e8df2014-12-19 14:21:54 -0500327
Matthew Treinish4a596932015-03-06 20:37:01 -0500328 def is_role_available(self, role):
329 if self.use_default_creds:
Matthew Treinish976e8df2014-12-19 14:21:54 -0500330 return False
Matthew Treinish4a596932015-03-06 20:37:01 -0500331 else:
332 if self.hash_dict['roles'].get(role):
333 return True
334 return False
335
336 def admin_available(self):
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100337 return self.is_role_available(self.admin_role)
Andrea Frittolib1c23fc2014-09-03 13:40:08 +0100338
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400339 def _wrap_creds_with_network(self, hash):
340 creds_dict = self.hash_dict['creds'][hash]
Andrea Frittoli (andreaf)c625bcf2015-10-09 12:09:05 +0100341 # Make sure a domain scope if defined for users in case of V3
Sean Dagueed6e5862016-04-04 10:49:13 -0400342 # Make sure a tenant is available in case of V2
Andrea Frittoli (andreaf)c625bcf2015-10-09 12:09:05 +0100343 creds_dict = self._extend_credentials(creds_dict)
344 # This just builds a Credentials object, it does not validate
345 # nor fill with missing fields.
346 credential = auth.get_credentials(
347 auth_url=None, fill_in=False,
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400348 identity_version=self.identity_version, **creds_dict)
349 net_creds = cred_provider.TestResources(credential)
350 net_clients = clients.Manager(credentials=credential)
John Warren9487a182015-09-14 18:12:56 -0400351 compute_network_client = net_clients.compute_networks_client
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400352 net_name = self.hash_dict['networks'].get(hash, None)
Matthew Treinishbe855fd2015-04-16 13:10:49 -0400353 try:
354 network = fixed_network.get_network_from_name(
355 net_name, compute_network_client)
Andrea Frittoli (andreaf)940f8c62015-10-30 16:39:24 +0900356 except exceptions.InvalidTestResource:
Matthew Treinishbe855fd2015-04-16 13:10:49 -0400357 network = {}
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400358 net_creds.set_resources(network=network)
359 return net_creds
360
Andrea Frittoli (andreaf)c625bcf2015-10-09 12:09:05 +0100361 def _extend_credentials(self, creds_dict):
Andrea Frittoli (andreaf)52deb8b2016-05-18 19:14:22 +0100362 # Add or remove credential domain fields to fit the identity version
363 domain_fields = set(x for x in auth.KeystoneV3Credentials.ATTRIBUTES
364 if 'domain' in x)
365 msg = 'Assuming they are valid in the default domain.'
Andrea Frittoli (andreaf)c625bcf2015-10-09 12:09:05 +0100366 if self.identity_version == 'v3':
Andrea Frittoli (andreaf)52deb8b2016-05-18 19:14:22 +0100367 if not domain_fields.intersection(set(creds_dict.keys())):
368 msg = 'Using credentials %s for v3 API calls. ' + msg
369 LOG.warning(msg, self._sanitize_creds(creds_dict))
370 creds_dict['domain_name'] = self.credentials_domain
Sean Dagueed6e5862016-04-04 10:49:13 -0400371 if self.identity_version == 'v2':
Andrea Frittoli (andreaf)52deb8b2016-05-18 19:14:22 +0100372 if domain_fields.intersection(set(creds_dict.keys())):
373 msg = 'Using credentials %s for v2 API calls. ' + msg
374 LOG.warning(msg, self._sanitize_creds(creds_dict))
375 # Remove all valid domain attributes
376 for attr in domain_fields.intersection(set(creds_dict.keys())):
377 creds_dict.pop(attr)
Andrea Frittoli (andreaf)c625bcf2015-10-09 12:09:05 +0100378 return creds_dict