156
162
Validate a list of actual flavors vs a list of expected flavors.
164
self.log.debug('Validating flavor data...')
158
165
self.log.debug('actual: {}'.format(repr(actual)))
159
166
act = [a.name for a in actual]
160
167
return self._validate_list_data(expected, act)
162
169
def tenant_exists(self, keystone, tenant):
163
170
"""Return True if tenant exists."""
171
self.log.debug('Checking if tenant exists ({})...'.format(tenant))
164
172
return tenant in [t.name for t in keystone.tenants.list()]
166
174
def authenticate_keystone_admin(self, keystone_sentry, user, password,
168
176
"""Authenticates admin user with the keystone admin endpoint."""
177
self.log.debug('Authenticating keystone admin...')
169
178
unit = keystone_sentry
170
179
service_ip = unit.relation('shared-db',
171
180
'mysql:shared-db')['private-address']
183
193
def authenticate_glance_admin(self, keystone):
184
194
"""Authenticates admin user with glance."""
195
self.log.debug('Authenticating glance admin...')
185
196
ep = keystone.service_catalog.url_for(service_type='image',
186
197
endpoint_type='adminURL')
187
198
return glance_client.Client(ep, token=keystone.auth_token)
200
def authenticate_heat_admin(self, keystone):
201
"""Authenticates the admin user with heat."""
202
self.log.debug('Authenticating heat admin...')
203
ep = keystone.service_catalog.url_for(service_type='orchestration',
204
endpoint_type='publicURL')
205
return heat_client.Client(endpoint=ep, token=keystone.auth_token)
189
207
def authenticate_nova_user(self, keystone, user, password, tenant):
190
208
"""Authenticates a regular user with nova-api."""
209
self.log.debug('Authenticating nova user ({})...'.format(user))
191
210
ep = keystone.service_catalog.url_for(service_type='identity',
192
211
endpoint_type='publicURL')
193
212
return nova_client.Client(username=user, api_key=password,
328
def create_or_get_keypair(self, nova, keypair_name="testkey"):
329
"""Create a new keypair, or return pointer if it already exists."""
331
_keypair = nova.keypairs.get(keypair_name)
332
self.log.debug('Keypair ({}) already exists, '
333
'using it.'.format(keypair_name))
336
self.log.debug('Keypair ({}) does not exist, '
337
'creating it.'.format(keypair_name))
339
_keypair = nova.keypairs.create(name=keypair_name)
342
def delete_resource(self, resource, resource_id,
343
msg="resource", max_wait=120):
344
"""Delete one openstack resource, such as one instance, keypair,
345
image, volume, stack, etc., and confirm deletion within max wait time.
347
:param resource: pointer to os resource type, ex:glance_client.images
348
:param resource_id: unique name or id for the openstack resource
349
:param msg: text to identify purpose in logging
350
:param max_wait: maximum wait time in seconds
351
:returns: True if successful, otherwise False
353
num_before = len(list(resource.list()))
354
resource.delete(resource_id)
357
num_after = len(list(resource.list()))
358
while num_after != (num_before - 1) and tries < (max_wait / 4):
359
self.log.debug('{} delete check: '
360
'{} [{}:{}] {}'.format(msg, tries,
365
num_after = len(list(resource.list()))
368
self.log.debug('{}: expected, actual count = {}, '
369
'{}'.format(msg, num_before - 1, num_after))
371
if num_after == (num_before - 1):
374
self.log.error('{} delete timed out'.format(msg))
377
def resource_reaches_status(self, resource, resource_id,
378
expected_stat='available',
379
msg='resource', max_wait=120):
380
"""Wait for an openstack resources status to reach an
381
expected status within a specified time. Useful to confirm that
382
nova instances, cinder vols, snapshots, glance images, heat stacks
383
and other resources eventually reach the expected status.
385
:param resource: pointer to os resource type, ex: heat_client.stacks
386
:param resource_id: unique id for the openstack resource
387
:param expected_stat: status to expect resource to reach
388
:param msg: text to identify purpose in logging
389
:param max_wait: maximum wait time in seconds
390
:returns: True if successful, False if status is not reached
394
resource_stat = resource.get(resource_id).status
395
while resource_stat != expected_stat and tries < (max_wait / 4):
396
self.log.debug('{} status check: '
397
'{} [{}:{}] {}'.format(msg, tries,
402
resource_stat = resource.get(resource_id).status
405
self.log.debug('{}: expected, actual status = {}, '
406
'{}'.format(msg, resource_stat, expected_stat))
408
if resource_stat == expected_stat:
411
self.log.debug('{} never reached expected status: '
412
'{}'.format(resource_id, expected_stat))