Merge lp:~gnuoy/charm-helpers/amulet-ksv3 into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 542
Proposed branch: lp:~gnuoy/charm-helpers/amulet-ksv3
Merge into: lp:charm-helpers
Diff against target: 80 lines (+35/-11)
1 file modified
charmhelpers/contrib/openstack/amulet/utils.py (+35/-11)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/amulet-ksv3
Reviewer Review Type Date Requested Status
David Ames (community) Approve
charmers Pending
Review via email: mp+288236@code.launchpad.net
To post a comment you must log in.
Revision history for this message
David Ames (thedac) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/amulet/utils.py'
2--- charmhelpers/contrib/openstack/amulet/utils.py 2015-10-21 02:59:41 +0000
3+++ charmhelpers/contrib/openstack/amulet/utils.py 2016-03-07 07:15:18 +0000
4@@ -27,6 +27,10 @@
5 import glanceclient.v1.client as glance_client
6 import heatclient.v1.client as heat_client
7 import keystoneclient.v2_0 as keystone_client
8+from keystoneclient.auth.identity import v3 as keystone_id_v3
9+from keystoneclient import session as keystone_session
10+from keystoneclient.v3 import client as keystone_client_v3
11+
12 import novaclient.v1_1.client as nova_client
13 import pika
14 import swiftclient
15@@ -139,7 +143,7 @@
16 return "role {} does not exist".format(e['name'])
17 return ret
18
19- def validate_user_data(self, expected, actual):
20+ def validate_user_data(self, expected, actual, api_version=None):
21 """Validate user data.
22
23 Validate a list of actual user data vs a list of expected user
24@@ -150,10 +154,15 @@
25 for e in expected:
26 found = False
27 for act in actual:
28- a = {'enabled': act.enabled, 'name': act.name,
29- 'email': act.email, 'tenantId': act.tenantId,
30- 'id': act.id}
31- if e['name'] == a['name']:
32+ if e['name'] == act.name:
33+ a = {'enabled': act.enabled, 'name': act.name,
34+ 'email': act.email, 'id': act.id}
35+ if api_version == 2:
36+ a['tenantId'] = act.tenantId
37+ else:
38+ a['default_project_id'] = getattr(act,
39+ 'default_project_id',
40+ 'none')
41 found = True
42 ret = self._validate_dict_data(e, a)
43 if ret:
44@@ -188,15 +197,30 @@
45 return cinder_client.Client(username, password, tenant, ept)
46
47 def authenticate_keystone_admin(self, keystone_sentry, user, password,
48- tenant):
49+ tenant=None, api_version=None,
50+ keystone_ip=None):
51 """Authenticates admin user with the keystone admin endpoint."""
52 self.log.debug('Authenticating keystone admin...')
53 unit = keystone_sentry
54- service_ip = unit.relation('shared-db',
55- 'mysql:shared-db')['private-address']
56- ep = "http://{}:35357/v2.0".format(service_ip.strip().decode('utf-8'))
57- return keystone_client.Client(username=user, password=password,
58- tenant_name=tenant, auth_url=ep)
59+ if not keystone_ip:
60+ keystone_ip = unit.relation('shared-db',
61+ 'mysql:shared-db')['private-address']
62+ base_ep = "http://{}:35357".format(keystone_ip.strip().decode('utf-8'))
63+ if not api_version or api_version == 2:
64+ ep = base_ep + "/v2.0"
65+ return keystone_client.Client(username=user, password=password,
66+ tenant_name=tenant, auth_url=ep)
67+ else:
68+ ep = base_ep + "/v3"
69+ auth = keystone_id_v3.Password(
70+ user_domain_name='admin_domain',
71+ username=user,
72+ password=password,
73+ domain_name='admin_domain',
74+ auth_url=ep,
75+ )
76+ sess = keystone_session.Session(auth=auth)
77+ return keystone_client_v3.Client(session=sess)
78
79 def authenticate_keystone_user(self, keystone, user, password, tenant):
80 """Authenticates a regular user with the keystone public endpoint."""

Subscribers

People subscribed via source and target branches