27
27
import glanceclient.v1.client as glance_client
28
28
import heatclient.v1.client as heat_client
29
29
import keystoneclient.v2_0 as keystone_client
30
import novaclient.v1_1.client as nova_client
30
from keystoneclient.auth.identity import v3 as keystone_id_v3
31
from keystoneclient import session as keystone_session
32
from keystoneclient.v3 import client as keystone_client_v3
34
import novaclient.client as nova_client
139
145
return "role {} does not exist".format(e['name'])
142
def validate_user_data(self, expected, actual):
148
def validate_user_data(self, expected, actual, api_version=None):
143
149
"""Validate user data.
145
151
Validate a list of actual user data vs a list of expected user
150
156
for e in expected:
152
158
for act in actual:
153
a = {'enabled': act.enabled, 'name': act.name,
154
'email': act.email, 'tenantId': act.tenantId,
156
if e['name'] == a['name']:
159
if e['name'] == act.name:
160
a = {'enabled': act.enabled, 'name': act.name,
161
'email': act.email, 'id': act.id}
163
a['default_project_id'] = getattr(act,
164
'default_project_id',
167
a['tenantId'] = act.tenantId
158
169
ret = self._validate_dict_data(e, a)
188
199
return cinder_client.Client(username, password, tenant, ept)
190
201
def authenticate_keystone_admin(self, keystone_sentry, user, password,
202
tenant=None, api_version=None,
192
204
"""Authenticates admin user with the keystone admin endpoint."""
193
205
self.log.debug('Authenticating keystone admin...')
194
206
unit = keystone_sentry
195
service_ip = unit.relation('shared-db',
196
'mysql:shared-db')['private-address']
197
ep = "http://{}:35357/v2.0".format(service_ip.strip().decode('utf-8'))
198
return keystone_client.Client(username=user, password=password,
199
tenant_name=tenant, auth_url=ep)
208
keystone_ip = unit.relation('shared-db',
209
'mysql:shared-db')['private-address']
210
base_ep = "http://{}:35357".format(keystone_ip.strip().decode('utf-8'))
211
if not api_version or api_version == 2:
212
ep = base_ep + "/v2.0"
213
return keystone_client.Client(username=user, password=password,
214
tenant_name=tenant, auth_url=ep)
217
auth = keystone_id_v3.Password(
218
user_domain_name='admin_domain',
221
domain_name='admin_domain',
224
sess = keystone_session.Session(auth=auth)
225
return keystone_client_v3.Client(session=sess)
201
227
def authenticate_keystone_user(self, keystone, user, password, tenant):
202
228
"""Authenticates a regular user with the keystone public endpoint."""
225
251
self.log.debug('Authenticating nova user ({})...'.format(user))
226
252
ep = keystone.service_catalog.url_for(service_type='identity',
227
253
endpoint_type='publicURL')
228
return nova_client.Client(username=user, api_key=password,
254
return nova_client.Client(NOVA_CLIENT_VERSION,
255
username=user, api_key=password,
229
256
project_id=tenant, auth_url=ep)
231
258
def authenticate_swift_user(self, keystone, user, password, tenant):