~openstack-charmers-next/charms/wily/odl-controller/trunk

« back to all changes in this revision

Viewing changes to tests/charmhelpers/contrib/openstack/amulet/utils.py

  • Committer: Gerrit Code Review
  • Author(s): Jenkins
  • Date: 2016-03-18 16:10:08 UTC
  • mfrom: (21.1.1 trunk)
  • Revision ID: review@openstack.org-20160318161008-grzlrlzei667shdd
Merge "Add support for Ubuntu Xenial"

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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
 
33
 
30
34
import novaclient.v1_1.client as nova_client
31
35
import pika
32
36
import swiftclient
139
143
                return "role {} does not exist".format(e['name'])
140
144
        return ret
141
145
 
142
 
    def validate_user_data(self, expected, actual):
 
146
    def validate_user_data(self, expected, actual, api_version=None):
143
147
        """Validate user data.
144
148
 
145
149
           Validate a list of actual user data vs a list of expected user
150
154
        for e in expected:
151
155
            found = False
152
156
            for act in actual:
153
 
                a = {'enabled': act.enabled, 'name': act.name,
154
 
                     'email': act.email, 'tenantId': act.tenantId,
155
 
                     'id': act.id}
156
 
                if e['name'] == a['name']:
 
157
                if e['name'] == act.name:
 
158
                    a = {'enabled': act.enabled, 'name': act.name,
 
159
                         'email': act.email, 'id': act.id}
 
160
                    if api_version == 3:
 
161
                        a['default_project_id'] = getattr(act,
 
162
                                                          'default_project_id',
 
163
                                                          'none')
 
164
                    else:
 
165
                        a['tenantId'] = act.tenantId
157
166
                    found = True
158
167
                    ret = self._validate_dict_data(e, a)
159
168
                    if ret:
188
197
        return cinder_client.Client(username, password, tenant, ept)
189
198
 
190
199
    def authenticate_keystone_admin(self, keystone_sentry, user, password,
191
 
                                    tenant):
 
200
                                    tenant=None, api_version=None,
 
201
                                    keystone_ip=None):
192
202
        """Authenticates admin user with the keystone admin endpoint."""
193
203
        self.log.debug('Authenticating keystone admin...')
194
204
        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)
 
205
        if not keystone_ip:
 
206
            keystone_ip = unit.relation('shared-db',
 
207
                                        'mysql:shared-db')['private-address']
 
208
        base_ep = "http://{}:35357".format(keystone_ip.strip().decode('utf-8'))
 
209
        if not api_version or api_version == 2:
 
210
            ep = base_ep + "/v2.0"
 
211
            return keystone_client.Client(username=user, password=password,
 
212
                                          tenant_name=tenant, auth_url=ep)
 
213
        else:
 
214
            ep = base_ep + "/v3"
 
215
            auth = keystone_id_v3.Password(
 
216
                user_domain_name='admin_domain',
 
217
                username=user,
 
218
                password=password,
 
219
                domain_name='admin_domain',
 
220
                auth_url=ep,
 
221
            )
 
222
            sess = keystone_session.Session(auth=auth)
 
223
            return keystone_client_v3.Client(session=sess)
200
224
 
201
225
    def authenticate_keystone_user(self, keystone, user, password, tenant):
202
226
        """Authenticates a regular user with the keystone public endpoint."""