Stop caching client to fix long-running test fails

If a node is really slow then a single test can take longer than an
hour. It will then fail as the client it has cached will now have an
expired token. To alleviate this, the caching of the clients was removed
(since the time saved on caching the clients is probably negligible
anyway).

Checking the client code was also cleaned up for a number of tests.

The cluster tests were modified, however the code was reverted as
there is no way to test it at present (they will not run as they
haven't been modified to work with the new neutron set up).  This
will be fixed in a separate changereq (since they are currently not
being tested in the gate, this should not hold up development).

Change-Id: I63d5b78084486b806bff38068260e42128c0d0ed
Closes-Bug: 1647002
This commit is contained in:
Peter Stachowski 2016-12-03 18:25:19 +00:00
parent 1d38d9ab9d
commit d558e5c2e0
16 changed files with 386 additions and 296 deletions

View File

@ -53,17 +53,19 @@ class BackupRunner(TestRunner):
self, expected_exception=exceptions.BadRequest,
expected_http_code=400):
invalid_inst_id = 'invalid-inst-id'
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.backups.create,
client, client.backups.create,
self.BACKUP_NAME, invalid_inst_id, self.BACKUP_DESC)
def run_backup_create_instance_not_found(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.backups.create,
client, client.backups.create,
self.BACKUP_NAME, generate_uuid(), self.BACKUP_DESC)
def run_add_data_for_backup(self):
@ -147,32 +149,37 @@ class BackupRunner(TestRunner):
def run_restore_instance_from_not_completed_backup(
self, expected_exception=exceptions.Conflict,
expected_http_code=409):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self._restore_from_backup, self.backup_info.id)
None, self._restore_from_backup, client, self.backup_info.id)
self.assert_client_code(client, expected_http_code)
def run_instance_action_right_after_backup_create(
self, expected_exception=exceptions.UnprocessableEntity,
expected_http_code=422):
client = self.auth_client
self.assert_raises(expected_exception, expected_http_code,
self.auth_client.instances.resize_instance,
client, client.instances.resize_instance,
self.instance_info.id, 1)
def run_backup_create_another_backup_running(
self, expected_exception=exceptions.UnprocessableEntity,
expected_http_code=422):
client = self.auth_client
self.assert_raises(expected_exception, expected_http_code,
self.auth_client.backups.create,
client, client.backups.create,
'backup_test2', self.instance_info.id,
'test description2')
def run_backup_delete_while_backup_running(
self, expected_exception=exceptions.UnprocessableEntity,
expected_http_code=422):
result = self.auth_client.backups.list()
client = self.auth_client
result = client.backups.list()
backup = result[0]
self.assert_raises(expected_exception, expected_http_code,
self.auth_client.backups.delete, backup.id)
client, client.backups.delete, backup.id)
def run_backup_create_completed(self):
self._verify_backup(self.backup_info.id)
@ -226,9 +233,10 @@ class BackupRunner(TestRunner):
def run_backup_list_filter_datastore_not_found(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.backups.list,
client, client.backups.list,
datastore='NOT_FOUND')
def run_backup_list_for_instance(self):
@ -255,12 +263,10 @@ class BackupRunner(TestRunner):
def run_backup_get_unauthorized_user(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.unauth_client
self.assert_raises(
expected_exception, None,
self.unauth_client.backups.get, self.backup_info.id)
# we're using a different client, so we'll check the return code
# on it explicitly, instead of depending on 'assert_raises'
self.assert_client_code(expected_http_code, client=self.unauth_client)
expected_exception, expected_http_code,
client, client.backups.get, self.backup_info.id)
def run_add_data_for_inc_backup_1(self):
self.backup_host = self.get_instance_host()
@ -302,15 +308,16 @@ class BackupRunner(TestRunner):
def assert_restore_from_backup(self, backup_ref, suffix='',
expected_http_code=200):
result = self._restore_from_backup(backup_ref, suffix=suffix)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
result = self._restore_from_backup(client, backup_ref, suffix=suffix)
self.assert_client_code(client, expected_http_code)
self.assert_equal('BUILD', result.status,
'Unexpected instance status')
return result.id
def _restore_from_backup(self, backup_ref, suffix=''):
def _restore_from_backup(self, client, backup_ref, suffix=''):
restore_point = {'backupRef': backup_ref}
result = self.auth_client.instances.create(
result = client.instances.create(
self.instance_info.name + '_restore' + suffix,
self.instance_info.dbaas_flavor_href,
self.instance_info.volume,
@ -372,8 +379,9 @@ class BackupRunner(TestRunner):
def assert_delete_restored_instance(
self, instance_id, expected_http_code):
self.auth_client.instances.delete(instance_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
client.instances.delete(instance_id)
self.assert_client_code(client, expected_http_code)
def run_delete_restored_inc_1_instance(self, expected_http_code=202):
self.assert_delete_restored_instance(
@ -398,20 +406,19 @@ class BackupRunner(TestRunner):
def run_delete_unknown_backup(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.backups.delete,
client, client.backups.delete,
'unknown_backup')
def run_delete_backup_unauthorized_user(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.unauth_client
self.assert_raises(
expected_exception, None,
self.unauth_client.backups.delete, self.backup_info.id)
# we're using a different client, so we'll check the return code
# on it explicitly, instead of depending on 'assert_raises'
self.assert_client_code(expected_http_code, client=self.unauth_client)
expected_exception, expected_http_code,
client, client.backups.delete, self.backup_info.id)
def run_delete_inc_2_backup(self, expected_http_code=202):
self.assert_delete_backup(
@ -420,14 +427,15 @@ class BackupRunner(TestRunner):
def assert_delete_backup(
self, backup_id, expected_http_code):
self.auth_client.backups.delete(backup_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
self._wait_until_backup_is_gone(backup_id)
client = self.auth_client
client.backups.delete(backup_id)
self.assert_client_code(client, expected_http_code)
self._wait_until_backup_is_gone(client, backup_id)
def _wait_until_backup_is_gone(self, backup_id):
def _wait_until_backup_is_gone(self, client, backup_id):
def _backup_is_gone():
try:
self.auth_client.backups.get(backup_id)
client.backups.get(backup_id)
return False
except exceptions.NotFound:
return True
@ -443,9 +451,10 @@ class BackupRunner(TestRunner):
expected_http_code=404):
if self.backup_inc_1_info is None:
raise SkipTest("Incremental Backup not created")
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.backups.get,
client, client.backups.get,
self.backup_inc_1_info.id)
self.backup_inc_1_info = None

View File

@ -49,9 +49,10 @@ class ConfigurationRunner(TestRunner):
def assert_action_on_conf_group_failure(
self, group_values, expected_exception, expected_http_code):
json_def = json.dumps(group_values)
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.configurations.create,
client, client.configurations.create,
'conf_group',
json_def,
'Group with Bad or Invalid entries',
@ -128,13 +129,14 @@ class ConfigurationRunner(TestRunner):
def assert_create_group(self, name, description, values,
expected_http_code):
json_def = json.dumps(values)
result = self.auth_client.configurations.create(
client = self.auth_client
result = client.configurations.create(
name,
json_def,
description,
datastore=self.instance_info.dbaas_datastore,
datastore_version=self.instance_info.dbaas_datastore_version)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
with TypeCheck('Configuration', result) as configuration:
configuration.has_field('name', basestring)
@ -269,12 +271,10 @@ class ConfigurationRunner(TestRunner):
def assert_conf_get_unauthorized_user(
self, config_id, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.unauth_client
self.assert_raises(
expected_exception, None,
self.unauth_client.configurations.get, config_id)
# we're using a different client, so we'll check the return code
# on it explicitly, instead of depending on 'assert_raises'
self.assert_client_code(expected_http_code, client=self.unauth_client)
expected_exception, expected_http_code,
client, client.configurations.get, config_id)
def run_non_dynamic_conf_get_unauthorized_user(
self, expected_exception=exceptions.NotFound,
@ -372,9 +372,10 @@ class ConfigurationRunner(TestRunner):
def assert_update_group(
self, instance_id, group_id, values,
expected_states, expected_http_code, restart_inst=False):
self.auth_client.configurations.update(group_id, values)
self.assert_instance_action(
instance_id, expected_states, expected_http_code)
client = self.auth_client
client.configurations.update(group_id, values)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(instance_id, expected_states)
if restart_inst:
self._restart_instance(instance_id)
@ -445,9 +446,10 @@ class ConfigurationRunner(TestRunner):
def assert_instance_modify(
self, instance_id, group_id, expected_states, expected_http_code,
restart_inst=False):
self.auth_client.instances.modify(instance_id, configuration=group_id)
self.assert_instance_action(
instance_id, expected_states, expected_http_code)
client = self.auth_client
client.instances.modify(instance_id, configuration=group_id)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(instance_id, expected_states)
# Verify the group has been attached.
instance = self.get_instance(instance_id)
@ -470,9 +472,10 @@ class ConfigurationRunner(TestRunner):
def assert_instance_modify_failure(
self, instance_id, group_id, expected_exception,
expected_http_code):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.instances.modify,
client, client.instances.modify,
instance_id, configuration=group_id)
def run_delete_dynamic_group(self, expected_http_code=202):
@ -481,8 +484,9 @@ class ConfigurationRunner(TestRunner):
expected_http_code)
def assert_group_delete(self, group_id, expected_http_code):
self.auth_client.configurations.delete(group_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
client.configurations.delete(group_id)
self.assert_client_code(client, expected_http_code)
def run_delete_non_dynamic_group(self, expected_http_code=202):
if self.non_dynamic_group_id:
@ -491,16 +495,18 @@ class ConfigurationRunner(TestRunner):
def assert_group_delete_failure(self, group_id, expected_exception,
expected_http_code):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.configurations.delete, group_id)
client, client.configurations.delete, group_id)
def _restart_instance(
self, instance_id, expected_states=['REBOOT', 'ACTIVE'],
expected_http_code=202):
self.auth_client.instances.restart(instance_id)
self.assert_instance_action(instance_id, expected_states,
expected_http_code)
client = self.auth_client
client.instances.restart(instance_id)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(instance_id, expected_states)
def run_create_instance_with_conf(self):
self.config_id_for_inst = (
@ -514,7 +520,8 @@ class ConfigurationRunner(TestRunner):
def assert_create_instance_with_conf(self, config_id):
# test that a new instance will apply the configuration on create
result = self.auth_client.instances.create(
client = self.auth_client
result = client.instances.create(
self.instance_info.name + "_config",
self.instance_info.dbaas_flavor_href,
self.instance_info.volume,
@ -524,7 +531,7 @@ class ConfigurationRunner(TestRunner):
nics=self.instance_info.nics,
availability_zone="nova",
configuration=config_id)
self.assert_client_code(200, client=self.auth_client)
self.assert_client_code(client, 200)
self.assert_equal("BUILD", result.status, 'Unexpected inst status')
return result.id
@ -554,8 +561,9 @@ class ConfigurationRunner(TestRunner):
raise SkipTest("No instance created with a configuration group.")
def assert_delete_conf_instance(self, instance_id, expected_http_code):
self.auth_client.instances.delete(instance_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
client.instances.delete(instance_id)
self.assert_client_code(client, expected_http_code)
def run_wait_for_delete_conf_instance(
self, expected_last_state=['SHUTDOWN']):

View File

@ -52,9 +52,11 @@ class DatabaseActionsRunner(TestRunner):
def assert_databases_create(self, instance_id, serial_databases_def,
expected_http_code):
self.auth_client.databases.create(instance_id, serial_databases_def)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.wait_for_database_create(instance_id, serial_databases_def)
client = self.auth_client
client.databases.create(instance_id, serial_databases_def)
self.assert_client_code(client, expected_http_code)
self.wait_for_database_create(client,
instance_id, serial_databases_def)
return serial_databases_def
def run_databases_list(self, expected_http_code=200):
@ -63,8 +65,9 @@ class DatabaseActionsRunner(TestRunner):
def assert_databases_list(self, instance_id, expected_database_defs,
expected_http_code, limit=2):
full_list = self.auth_client.databases.list(instance_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
full_list = client.databases.list(instance_id)
self.assert_client_code(client, expected_http_code)
listed_databases = {database.name: database for database in full_list}
self.assert_is_none(full_list.next,
"Unexpected pagination in the list.")
@ -85,8 +88,8 @@ class DatabaseActionsRunner(TestRunner):
"output.")
# Test list pagination.
list_page = self.auth_client.databases.list(instance_id, limit=limit)
self.assert_client_code(expected_http_code, client=self.auth_client)
list_page = client.databases.list(instance_id, limit=limit)
self.assert_client_code(client, expected_http_code)
self.assert_true(len(list_page) <= limit)
if len(full_list) > limit:
@ -102,10 +105,9 @@ class DatabaseActionsRunner(TestRunner):
self.assert_equal(expected_marker, marker,
"Pagination marker should be the last element "
"in the page.")
list_page = self.auth_client.databases.list(
list_page = client.databases.list(
instance_id, marker=marker)
self.assert_client_code(expected_http_code,
client=self.auth_client)
self.assert_client_code(client, expected_http_code)
self.assert_pagination_match(
list_page, full_list, limit, len(full_list))
@ -132,10 +134,11 @@ class DatabaseActionsRunner(TestRunner):
def assert_databases_create_failure(
self, instance_id, serial_databases_def,
expected_exception, expected_http_code):
client = self.auth_client
self.assert_raises(
expected_exception,
expected_http_code,
self.auth_client.databases.create,
client, client.databases.create,
instance_id,
serial_databases_def)
@ -163,16 +166,18 @@ class DatabaseActionsRunner(TestRunner):
instance_id,
database_name,
expected_http_code):
self.auth_client.databases.delete(instance_id, database_name)
self.assert_client_code(expected_http_code, client=self.auth_client)
self._wait_for_database_delete(instance_id, database_name)
client = self.auth_client
client.databases.delete(instance_id, database_name)
self.assert_client_code(client, expected_http_code)
self._wait_for_database_delete(client, instance_id, database_name)
def _wait_for_database_delete(self, instance_id, deleted_database_name):
def _wait_for_database_delete(self, client,
instance_id, deleted_database_name):
self.report.log("Waiting for deleted database to disappear from the "
"listing: %s" % deleted_database_name)
def _db_is_gone():
all_dbs = self.get_db_names(instance_id)
all_dbs = self.get_db_names(client, instance_id)
return deleted_database_name not in all_dbs
try:
@ -205,8 +210,9 @@ class DatabaseActionsRunner(TestRunner):
def assert_database_delete_failure(
self, instance_id, database_name,
expected_exception, expected_http_code):
client = self.auth_client
self.assert_raises(expected_exception, expected_http_code,
self.auth_client.databases.delete,
client, client.databases.delete,
instance_id, database_name)
def get_system_databases(self):

View File

@ -101,7 +101,7 @@ class GuestLogRunner(TestRunner):
self.report.log("Executing log_show for log '%s'" % log_name)
log_details = client.instances.log_show(
self.instance_info.id, log_name)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
self.assert_log_details(
log_details, log_name,
expected_type=expected_type,
@ -187,7 +187,7 @@ class GuestLogRunner(TestRunner):
self.report.log("Executing log_enable for log '%s'" % log_name)
log_details = client.instances.log_enable(
self.instance_info.id, log_name)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
self.assert_log_details(
log_details, log_name,
expected_type=expected_type,
@ -204,7 +204,7 @@ class GuestLogRunner(TestRunner):
(log_name, discard))
log_details = client.instances.log_disable(
self.instance_info.id, log_name, discard=discard)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
self.assert_log_details(
log_details, log_name,
expected_type=expected_type,
@ -222,7 +222,7 @@ class GuestLogRunner(TestRunner):
(log_name, disable, discard))
log_details = client.instances.log_publish(
self.instance_info.id, log_name, disable=disable, discard=discard)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
self.assert_log_details(
log_details, log_name,
expected_type=expected_type,
@ -238,7 +238,7 @@ class GuestLogRunner(TestRunner):
self.report.log("Executing log_discard for log '%s'" % log_name)
log_details = client.instances.log_discard(
self.instance_info.id, log_name)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
self.assert_log_details(
log_details, log_name,
expected_type=expected_type,
@ -303,10 +303,10 @@ class GuestLogRunner(TestRunner):
expected_exception, expected_http_code,
log_name):
self.assert_raises(expected_exception, None,
client.instances.log_enable,
client, client.instances.log_enable,
self.instance_info.id, log_name)
# we may not be using the main client, so check explicitly here
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
def run_test_log_disable_sys(self,
expected_exception=exceptions.BadRequest,
@ -320,11 +320,11 @@ class GuestLogRunner(TestRunner):
expected_exception, expected_http_code,
log_name, discard=None):
self.assert_raises(expected_exception, None,
client.instances.log_disable,
client, client.instances.log_disable,
self.instance_info.id, log_name,
discard=discard)
# we may not be using the main client, so check explicitly here
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
def run_test_log_show_unauth_user(self,
expected_exception=exceptions.NotFound,
@ -338,19 +338,18 @@ class GuestLogRunner(TestRunner):
expected_exception, expected_http_code,
log_name):
self.assert_raises(expected_exception, None,
client.instances.log_show,
client, client.instances.log_show,
self.instance_info.id, log_name)
# we may not be using the main client, so check explicitly here
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
def run_test_log_list_unauth_user(self,
expected_exception=exceptions.NotFound,
expected_http_code=404):
self.assert_raises(expected_exception, None,
self.unauth_client.instances.log_list,
client = self.unauth_client
self.assert_raises(expected_exception, expected_http_code,
client, client.instances.log_list,
self.instance_info.id)
# we're not using the main client, so check explicitly here
self.assert_client_code(expected_http_code, client=self.unauth_client)
def run_test_log_generator_unauth_user(self):
self.assert_log_generator_unauth_user(
@ -406,11 +405,11 @@ class GuestLogRunner(TestRunner):
log_name,
disable=None, discard=None):
self.assert_raises(expected_exception, None,
client.instances.log_publish,
client, client.instances.log_publish,
self.instance_info.id, log_name,
disable=disable, discard=discard)
# we may not be using the main client, so check explicitly here
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
def run_test_log_discard_unexposed_user(
self, expected_exception=exceptions.BadRequest,
@ -423,11 +422,9 @@ class GuestLogRunner(TestRunner):
def assert_log_discard_fails(self, client,
expected_exception, expected_http_code,
log_name):
self.assert_raises(expected_exception, None,
client.instances.log_discard,
self.assert_raises(expected_exception, expected_http_code,
client, client.instances.log_discard,
self.instance_info.id, log_name)
# we may not be using the main client, so check explicitly here
self.assert_client_code(expected_http_code, client=client)
def run_test_log_enable_user(self):
expected_status = guest_log.LogStatus.Ready.name
@ -470,15 +467,14 @@ class GuestLogRunner(TestRunner):
# we need to wait until the heartbeat flips the instance
# back into 'ACTIVE' before we issue the restart command
expected_states = ['RESTART_REQUIRED', 'ACTIVE']
self.assert_instance_action(instance_id, expected_states, None)
self.auth_client.instances.restart(instance_id)
self.assert_client_code(expected_http_code,
client=self.auth_client)
self.assert_instance_action(instance_id, expected_states)
client = self.auth_client
client.instances.restart(instance_id)
self.assert_client_code(client, expected_http_code)
def run_test_wait_for_restart(self, expected_states=['REBOOT', 'ACTIVE']):
if self.test_helper.log_enable_requires_restart():
self.assert_instance_action(self.instance_info.id,
expected_states, None)
self.assert_instance_action(self.instance_info.id, expected_states)
def run_test_log_publish_user(self):
for log_name in self._get_exposed_user_log_names():

View File

@ -59,9 +59,10 @@ class InstanceActionsRunner(TestRunner):
expected_http_code):
self.report.log("Testing restart on instance: %s" % instance_id)
self.auth_client.instances.restart(instance_id)
self.assert_instance_action(instance_id, expected_states,
expected_http_code)
client = self.auth_client
client.instances.restart(instance_id)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(instance_id, expected_states)
def run_instance_resize_volume(
self, resize_amount=1,
@ -83,9 +84,10 @@ class InstanceActionsRunner(TestRunner):
old_volume_size = int(instance.volume['size'])
new_volume_size = old_volume_size + resize_amount
self.auth_client.instances.resize_volume(instance_id, new_volume_size)
self.assert_instance_action(instance_id, expected_states,
expected_http_code)
client = self.auth_client
client.instances.resize_volume(instance_id, new_volume_size)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(instance_id, expected_states)
instance = self.get_instance(instance_id)
self.assert_equal(new_volume_size, instance.volume['size'],
@ -99,9 +101,9 @@ class InstanceActionsRunner(TestRunner):
expected_http_code):
self.report.log("Testing resize to '%s' on instance: %s" %
(resize_flavor_id, instance_id))
self.auth_client.instances.resize_instance(
instance_id, resize_flavor_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
client.instances.resize_instance(instance_id, resize_flavor_id)
self.assert_client_code(client, expected_http_code)
def run_wait_for_instance_resize_flavor(
self, expected_states=['RESIZE', 'ACTIVE']):

View File

@ -69,14 +69,14 @@ class InstanceCreateRunner(TestRunner):
values = dynamic_config or non_dynamic_config
if values:
json_def = json.dumps(values)
result = self.auth_client.configurations.create(
client = self.auth_client
result = client.configurations.create(
'initial_configuration_for_instance_create',
json_def,
"Configuration group used by instance create tests.",
datastore=self.instance_info.dbaas_datastore,
datastore_version=self.instance_info.dbaas_datastore_version)
self.assert_client_code(expected_http_code,
client=self.auth_client)
self.assert_client_code(client, expected_http_code)
self.config_group_id = result.id
else:
@ -184,7 +184,8 @@ class InstanceCreateRunner(TestRunner):
instance_info.name = instance.name
else:
self.report.log("Creating a new instance.")
instance = self.auth_client.instances.create(
client = self.auth_client
instance = client.instances.create(
instance_info.name,
instance_info.dbaas_flavor_href,
instance_info.volume,
@ -196,8 +197,8 @@ class InstanceCreateRunner(TestRunner):
datastore=instance_info.dbaas_datastore,
datastore_version=instance_info.dbaas_datastore_version,
locality=locality)
self.assert_instance_action(
instance.id, expected_states[0:1], expected_http_code)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(instance.id, expected_states[0:1])
instance_info.id = instance.id
@ -246,11 +247,12 @@ class InstanceCreateRunner(TestRunner):
def wait_for_test_helpers(self, inst_info):
self.report.log("Waiting for helper users and databases to be "
"created on instance: %s" % inst_info.id)
client = self.auth_client
if inst_info.helper_user:
self.wait_for_user_create(inst_info.id,
self.wait_for_user_create(client, inst_info.id,
[inst_info.helper_user])
if inst_info.helper_database:
self.wait_for_database_create(inst_info.id,
self.wait_for_database_create(client, inst_info.id,
[inst_info.helper_database])
self.report.log("Test helpers are ready.")
@ -299,13 +301,15 @@ class InstanceCreateRunner(TestRunner):
"No configuration group expected")
def assert_database_list(self, instance_id, expected_databases):
self.wait_for_database_create(instance_id, expected_databases)
self.wait_for_database_create(self.auth_client,
instance_id, expected_databases)
def _get_names(self, definitions):
return [item['name'] for item in definitions]
def assert_user_list(self, instance_id, expected_users):
self.wait_for_user_create(instance_id, expected_users)
self.wait_for_user_create(self.auth_client,
instance_id, expected_users)
# Verify that user definitions include only created databases.
all_databases = self._get_names(
self.test_helper.get_valid_database_definitions())
@ -318,9 +322,9 @@ class InstanceCreateRunner(TestRunner):
def run_initialized_instance_delete(self, expected_http_code=202):
if self.init_inst_info:
self.auth_client.instances.delete(self.init_inst_info.id)
self.assert_client_code(expected_http_code,
client=self.auth_client)
client = self.auth_client
client.instances.delete(self.init_inst_info.id)
self.assert_client_code(client, expected_http_code)
else:
raise SkipTest("Cleanup is not required.")
@ -341,9 +345,9 @@ class InstanceCreateRunner(TestRunner):
def run_initial_configuration_delete(self, expected_http_code=202):
if self.config_group_id:
self.auth_client.configurations.delete(self.config_group_id)
self.assert_client_code(expected_http_code,
client=self.auth_client)
client = self.auth_client
client.configurations.delete(self.config_group_id)
self.assert_client_code(client, expected_http_code)
else:
raise SkipTest("Cleanup is not required.")
self.config_group_id = None

View File

@ -35,8 +35,9 @@ class InstanceDeleteRunner(TestRunner):
def assert_instance_delete(self, instance_id, expected_http_code):
self.report.log("Testing delete on instance: %s" % instance_id)
self.auth_client.instances.delete(instance_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
client.instances.delete(instance_id)
self.assert_client_code(client, expected_http_code)
def run_instance_delete_wait(self, expected_states=['SHUTDOWN']):
if self.has_do_not_delete_instance:

View File

@ -33,14 +33,15 @@ class InstanceErrorCreateRunner(TestRunner):
name = self.instance_info.name + '_error'
flavor = self.get_instance_flavor(fault_num=1)
inst = self.auth_client.instances.create(
client = self.auth_client
inst = client.instances.create(
name,
self.get_flavor_href(flavor),
self.instance_info.volume,
nics=self.instance_info.nics,
datastore=self.instance_info.dbaas_datastore,
datastore_version=self.instance_info.dbaas_datastore_version)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
self.error_inst_id = inst.id
def run_create_error2_instance(self, expected_http_code=200):
@ -50,14 +51,15 @@ class InstanceErrorCreateRunner(TestRunner):
name = self.instance_info.name + '_error2'
flavor = self.get_instance_flavor(fault_num=2)
inst = self.auth_client.instances.create(
client = self.auth_client
inst = client.instances.create(
name,
self.get_flavor_href(flavor),
self.instance_info.volume,
nics=self.instance_info.nics,
datastore=self.instance_info.dbaas_datastore,
datastore_version=self.instance_info.dbaas_datastore_version)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
self.error2_inst_id = inst.id
def run_wait_for_error_instances(self, expected_states=['ERROR']):
@ -100,14 +102,13 @@ class InstanceErrorCreateRunner(TestRunner):
(instance.fault['message'], err_msg))
def run_delete_error_instances(self, expected_http_code=202):
client = self.auth_client
if self.error_inst_id:
self.auth_client.instances.delete(self.error_inst_id)
self.assert_client_code(expected_http_code,
client=self.auth_client)
client.instances.delete(self.error_inst_id)
self.assert_client_code(client, expected_http_code)
if self.error2_inst_id:
self.auth_client.instances.delete(self.error2_inst_id)
self.assert_client_code(expected_http_code,
client=self.auth_client)
client.instances.delete(self.error2_inst_id)
self.assert_client_code(client, expected_http_code)
def run_wait_for_error_delete(self, expected_states=['SHUTDOWN']):
delete_ids = []

View File

@ -33,22 +33,23 @@ class InstanceForceDeleteRunner(TestRunner):
name = self.instance_info.name + '_build'
flavor = self.get_instance_flavor()
inst = self.auth_client.instances.create(
client = self.auth_client
inst = client.instances.create(
name,
self.get_flavor_href(flavor),
self.instance_info.volume,
nics=self.instance_info.nics,
datastore=self.instance_info.dbaas_datastore,
datastore_version=self.instance_info.dbaas_datastore_version)
self.assert_instance_action([inst.id], expected_states,
expected_http_code)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action([inst.id], expected_states)
self.build_inst_id = inst.id
def run_delete_build_instance(self, expected_http_code=202):
if self.build_inst_id:
self.admin_client.instances.force_delete(self.build_inst_id)
self.assert_client_code(expected_http_code,
client=self.admin_client)
client = self.admin_client
client.instances.force_delete(self.build_inst_id)
self.assert_client_code(client, expected_http_code)
def run_wait_for_force_delete(self):
if self.build_inst_id:

View File

@ -41,6 +41,7 @@ class InstanceUpgradeRunner(TestRunner):
self.report.log("Testing upgrade on instance: %s" % instance_id)
target_version = self.instance_info.dbaas_datastore_version
self.auth_client.instances.upgrade(instance_id, target_version)
self.assert_instance_action(instance_id, expected_states,
expected_http_code)
client = self.auth_client
client.instances.upgrade(instance_id, target_version)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(instance_id, expected_states)

View File

@ -142,53 +142,59 @@ class ModuleRunner(TestRunner):
def run_module_create_bad_type(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.create,
client, client.modules.create,
self.MODULE_NAME, 'invalid-type', self.MODULE_NEG_CONTENTS)
def run_module_create_non_admin_auto(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.create,
client, client.modules.create,
self.MODULE_NAME, self.module_type, self.MODULE_NEG_CONTENTS,
auto_apply=True)
def run_module_create_non_admin_all_tenant(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.create,
client, client.modules.create,
self.MODULE_NAME, self.module_type, self.MODULE_NEG_CONTENTS,
all_tenants=True)
def run_module_create_non_admin_hidden(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.create,
client, client.modules.create,
self.MODULE_NAME, self.module_type, self.MODULE_NEG_CONTENTS,
visible=False)
def run_module_create_bad_datastore(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.create,
client, client.modules.create,
self.MODULE_NAME, self.module_type, self.MODULE_NEG_CONTENTS,
datastore='bad-datastore')
def run_module_create_bad_datastore_version(
self, expected_exception=exceptions.BadRequest,
expected_http_code=400):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.create,
client, client.modules.create,
self.MODULE_NAME, self.module_type, self.MODULE_NEG_CONTENTS,
datastore=self.instance_info.dbaas_datastore,
datastore_version='bad-datastore-version')
@ -196,9 +202,10 @@ class ModuleRunner(TestRunner):
def run_module_create_missing_datastore(
self, expected_exception=exceptions.BadRequest,
expected_http_code=400):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.create,
client, client.modules.create,
self.MODULE_NAME, self.module_type, self.MODULE_NEG_CONTENTS,
datastore_version=self.instance_info.dbaas_datastore_version)
@ -242,8 +249,9 @@ class ModuleRunner(TestRunner):
datastore=datastore, datastore_version=datastore_version,
auto_apply=auto_apply,
live_update=live_update, visible=visible)
if (client == self.auth_client or
(client == self.admin_client and visible)):
username = client.real_client.client.username
if (('alt' in username and 'admin' not in username) or
('admin' in username and visible)):
self.module_create_count += 1
if datastore:
self.module_ds_create_count += 1
@ -358,17 +366,19 @@ class ModuleRunner(TestRunner):
def run_module_create_dupe(
self, expected_exception=exceptions.BadRequest,
expected_http_code=400):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.create,
client, client.modules.create,
self.MODULE_NAME, self.module_type, self.MODULE_NEG_CONTENTS)
def run_module_update_missing_datastore(
self, expected_exception=exceptions.BadRequest,
expected_http_code=400):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update,
client, client.modules.update,
self.update_test_module.id,
datastore_version=self.instance_info.dbaas_datastore_version)
@ -414,12 +424,10 @@ class ModuleRunner(TestRunner):
def run_module_show_unauth_user(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.unauth_client
self.assert_raises(
expected_exception, None,
self.unauth_client.modules.get, self.main_test_module.id)
# we're using a different client, so we'll check the return code
# on it explicitly, instead of depending on 'assert_raises'
self.assert_client_code(expected_http_code, client=self.unauth_client)
expected_exception, expected_http_code,
client, client.modules.get, self.main_test_module.id)
def run_module_list(self):
self.assert_module_list(
@ -551,9 +559,10 @@ class ModuleRunner(TestRunner):
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
module = self._find_invisible_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.get, module.id)
client, client.modules.get, module.id)
def run_module_list_admin(self):
self.assert_module_list(
@ -632,82 +641,92 @@ class ModuleRunner(TestRunner):
def run_module_update_unauth(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.unauth_client
self.assert_raises(
expected_exception, expected_http_code,
self.unauth_client.modules.update,
client, client.modules.update,
self.main_test_module.id, description='Upd')
def run_module_update_non_admin_auto(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update,
client, client.modules.update,
self.main_test_module.id, visible=False)
def run_module_update_non_admin_auto_off(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
module = self._find_auto_apply_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update, module.id, auto_apply=False)
client, client.modules.update, module.id, auto_apply=False)
def run_module_update_non_admin_auto_any(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
module = self._find_auto_apply_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update, module.id, description='Upd')
client, client.modules.update, module.id, description='Upd')
def run_module_update_non_admin_all_tenant(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update,
client, client.modules.update,
self.main_test_module.id, all_tenants=True)
def run_module_update_non_admin_all_tenant_off(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
module = self._find_all_tenant_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update, module.id, all_tenants=False)
client, client.modules.update, module.id, all_tenants=False)
def run_module_update_non_admin_all_tenant_any(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
module = self._find_all_tenant_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update, module.id, description='Upd')
client, client.modules.update, module.id, description='Upd')
def run_module_update_non_admin_invisible(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update,
client, client.modules.update,
self.main_test_module.id, visible=False)
def run_module_update_non_admin_invisible_off(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
module = self._find_invisible_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update, module.id, visible=True)
client, client.modules.update, module.id, visible=True)
def run_module_update_non_admin_invisible_any(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
module = self._find_invisible_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.update, module.id, description='Upd')
client, client.modules.update, module.id, description='Upd')
# ModuleInstanceGroup methods
def run_module_list_instance_empty(self):
@ -718,7 +737,7 @@ class ModuleRunner(TestRunner):
def assert_module_list_instance(self, client, instance_id, expected_count,
expected_http_code=200):
module_list = client.instances.modules(instance_id)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
count = len(module_list)
self.assert_equal(expected_count, count,
"Wrong number of modules from list instance")
@ -733,7 +752,7 @@ class ModuleRunner(TestRunner):
def assert_module_instances(self, client, module_id, expected_count,
expected_http_code=200):
instance_list = client.modules.instances(module_id)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
count = len(instance_list)
self.assert_equal(expected_count, count,
"Wrong number of instances applied from module")
@ -751,7 +770,7 @@ class ModuleRunner(TestRunner):
def assert_module_query(self, client, instance_id, expected_count,
expected_http_code=200, expected_results=None):
modquery_list = client.instances.module_query(instance_id)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
count = len(modquery_list)
self.assert_equal(expected_count, count,
"Wrong number of modules from query")
@ -774,7 +793,7 @@ class ModuleRunner(TestRunner):
expected_http_code=200):
module_apply_list = client.instances.module_apply(
instance_id, [module.id])
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
admin_only = (not module.visible or module.auto_apply or
not module.tenant_id)
expected_status = expected_status or 'OK'
@ -919,7 +938,8 @@ class ModuleRunner(TestRunner):
def assert_inst_mod_create(self, module_id, name_suffix,
expected_http_code):
inst = self.auth_client.instances.create(
client = self.auth_client
inst = client.instances.create(
self.instance_info.name + name_suffix,
self.instance_info.dbaas_flavor_href,
self.instance_info.volume,
@ -928,15 +948,16 @@ class ModuleRunner(TestRunner):
nics=self.instance_info.nics,
modules=[module_id],
)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
return inst.id
def run_module_delete_applied(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.delete, self.main_test_module.id)
client, client.modules.delete, self.main_test_module.id)
def run_module_remove(self):
self.assert_module_remove(self.auth_client, self.instance_info.id,
@ -945,10 +966,10 @@ class ModuleRunner(TestRunner):
def assert_module_remove(self, client, instance_id, module_id,
expected_http_code=200):
client.instances.module_remove(instance_id, module_id)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
def run_wait_for_inst_with_mods(self, expected_states=['BUILD', 'ACTIVE']):
self.assert_instance_action(self.mod_inst_id, expected_states, None)
self.assert_instance_action(self.mod_inst_id, expected_states)
def run_module_query_after_inst_create(self):
auto_modules = self._find_all_auto_apply_modules(visible=True)
@ -975,7 +996,7 @@ class ModuleRunner(TestRunner):
prefix = 'contents'
modretrieve_list = client.instances.module_retrieve(
instance_id, directory=temp_dir, prefix=prefix)
self.assert_client_code(expected_http_code, client=client)
self.assert_client_code(client, expected_http_code)
count = len(modretrieve_list)
self.assert_equal(expected_count, count,
"Wrong number of modules from retrieve")
@ -1027,16 +1048,18 @@ class ModuleRunner(TestRunner):
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
module = self._find_auto_apply_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.delete, module.id)
client, client.modules.delete, module.id)
def run_delete_inst_with_mods(self, expected_http_code=202):
self.assert_delete_instance(self.mod_inst_id, expected_http_code)
def assert_delete_instance(self, instance_id, expected_http_code):
self.auth_client.instances.delete(instance_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
client.instances.delete(instance_id)
self.assert_client_code(client, expected_http_code)
def run_wait_for_delete_inst_with_mods(
self, expected_last_state=['SHUTDOWN']):
@ -1046,40 +1069,45 @@ class ModuleRunner(TestRunner):
def run_module_delete_non_existent(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.delete, 'bad_id')
client, client.modules.delete, 'bad_id')
def run_module_delete_unauth_user(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
client = self.unauth_client
self.assert_raises(
expected_exception, expected_http_code,
self.unauth_client.modules.delete, self.main_test_module.id)
client, client.modules.delete, self.main_test_module.id)
def run_module_delete_hidden_by_non_admin(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
module = self._find_invisible_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.delete, module.id)
client, client.modules.delete, module.id)
def run_module_delete_all_tenant_by_non_admin(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
module = self._find_all_tenant_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.delete, module.id)
client, client.modules.delete, module.id)
def run_module_delete_auto_by_non_admin(
self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
module = self._find_auto_apply_module()
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.modules.delete, module.id)
client, client.modules.delete, module.id)
def run_module_delete(self):
expected_count = len(self.auth_client.modules.list()) - 1

View File

@ -60,8 +60,9 @@ class NegativeClusterActionsRunner(TestRunner):
def _assert_cluster_create_raises(self, cluster_name, instances_def,
expected_http_code):
client = self.auth_client
self.assert_raises(exceptions.BadRequest, expected_http_code,
self.auth_client.clusters.create,
client, client.clusters.create,
cluster_name,
self.instance_info.dbaas_datastore,
self.instance_info.dbaas_datastore_version,

View File

@ -62,7 +62,8 @@ class ReplicationRunner(TestRunner):
self.test_helper.verify_data(data_type, host)
def run_create_non_affinity_master(self, expected_http_code=200):
self.non_affinity_master_id = self.auth_client.instances.create(
client = self.auth_client
self.non_affinity_master_id = client.instances.create(
self.instance_info.name + '_non-affinity',
self.instance_info.dbaas_flavor_href,
self.instance_info.volume,
@ -70,7 +71,7 @@ class ReplicationRunner(TestRunner):
datastore_version=self.instance_info.dbaas_datastore_version,
nics=self.instance_info.nics,
locality='anti-affinity').id
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
def run_create_single_replica(self, expected_http_code=200):
self.master_backup_count = len(
@ -80,7 +81,8 @@ class ReplicationRunner(TestRunner):
def assert_replica_create(
self, master_id, replica_name, replica_count, expected_http_code):
replica = self.auth_client.instances.create(
client = self.auth_client
replica = client.instances.create(
self.instance_info.name + '_' + replica_name,
self.instance_info.dbaas_flavor_href,
self.instance_info.volume, replica_of=master_id,
@ -88,7 +90,7 @@ class ReplicationRunner(TestRunner):
datastore_version=self.instance_info.dbaas_datastore_version,
nics=self.instance_info.nics,
replica_count=replica_count)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
return replica.id
def run_wait_for_single_replica(self, expected_states=['BUILD', 'ACTIVE']):
@ -99,8 +101,9 @@ class ReplicationRunner(TestRunner):
self.replica_1_host = self.get_instance_host(self.replica_1_id)
def _assert_is_master(self, instance_id, replica_ids):
instance = self.get_instance(instance_id, client=self.admin_client)
self.assert_client_code(200, client=self.admin_client)
client = self.admin_client
instance = self.get_instance(instance_id, client=client)
self.assert_client_code(client, 200)
CheckInstance(instance._info).slaves()
self.assert_true(
set(replica_ids).issubset(self._get_replica_set(instance_id)))
@ -111,8 +114,9 @@ class ReplicationRunner(TestRunner):
return set([replica['id'] for replica in instance._info['replicas']])
def _assert_is_replica(self, instance_id, master_id):
instance = self.get_instance(instance_id, client=self.admin_client)
self.assert_client_code(200, client=self.admin_client)
client = self.admin_client
instance = self.get_instance(instance_id, client=client)
self.assert_client_code(client, 200)
CheckInstance(instance._info).replica_of()
self.assert_equal(master_id, instance._info['replica_of']['id'],
'Unexpected replication master ID')
@ -138,7 +142,8 @@ class ReplicationRunner(TestRunner):
self.non_affinity_master_id)
def run_create_non_affinity_replica(self, expected_http_code=200):
self.non_affinity_repl_id = self.auth_client.instances.create(
client = self.auth_client
self.non_affinity_repl_id = client.instances.create(
self.instance_info.name + '_non-affinity-repl',
self.instance_info.dbaas_flavor_href,
self.instance_info.volume,
@ -147,7 +152,7 @@ class ReplicationRunner(TestRunner):
nics=self.instance_info.nics,
replica_of=self.non_affinity_master_id,
replica_count=1).id
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
def run_create_multiple_replicas(self, expected_http_code=200):
self.replica_2_id = self.assert_replica_create(
@ -176,10 +181,10 @@ class ReplicationRunner(TestRunner):
def assert_delete_instances(self, instance_ids, expected_http_code):
instance_ids = (instance_ids if utils.is_collection(instance_ids)
else [instance_ids])
client = self.auth_client
for instance_id in instance_ids:
self.auth_client.instances.delete(instance_id)
self.assert_client_code(expected_http_code,
client=self.auth_client)
client.instances.delete(instance_id)
self.assert_client_code(client, expected_http_code)
def run_wait_for_delete_non_affinity_repl(
self, expected_last_status=['SHUTDOWN']):
@ -220,32 +225,36 @@ class ReplicationRunner(TestRunner):
def run_promote_master(self, expected_exception=exceptions.BadRequest,
expected_http_code=400):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.instances.promote_to_replica_source,
client, client.instances.promote_to_replica_source,
self.instance_info.id)
def run_eject_replica(self, expected_exception=exceptions.BadRequest,
expected_http_code=400):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.instances.eject_replica_source,
client, client.instances.eject_replica_source,
self.replica_1_id)
def run_eject_valid_master(self, expected_exception=exceptions.BadRequest,
expected_http_code=400):
# client = self.auth_client
# self.assert_raises(
# expected_exception, expected_http_code,
# self.auth_client.instances.eject_replica_source,
# client, client.instances.eject_replica_source,
# self.instance_info.id)
# Uncomment once BUG_EJECT_VALID_MASTER is fixed
raise SkipKnownBug(runners.BUG_EJECT_VALID_MASTER)
def run_delete_valid_master(self, expected_exception=exceptions.Forbidden,
expected_http_code=403):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.instances.delete,
client, client.instances.delete,
self.instance_info.id)
def run_promote_to_replica_source(self,
@ -272,9 +281,10 @@ class ReplicationRunner(TestRunner):
def assert_replica_promote(
self, new_master_id, expected_states, expected_http_code):
self.auth_client.instances.promote_to_replica_source(new_master_id)
self.assert_instance_action(new_master_id, expected_states,
expected_http_code)
client = self.auth_client
client.instances.promote_to_replica_source(new_master_id)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(new_master_id, expected_states)
def run_verify_replica_data_new_master(self):
self.assert_verify_replication_data(
@ -340,14 +350,15 @@ class ReplicationRunner(TestRunner):
def assert_detach_replica(
self, replica_id, expected_states, expected_http_code):
self.auth_client.instances.edit(replica_id,
detach_replica_source=True)
self.assert_instance_action(
replica_id, expected_states, expected_http_code)
client = self.auth_client
client.instances.edit(replica_id, detach_replica_source=True)
self.assert_client_code(client, expected_http_code)
self.assert_instance_action(replica_id, expected_states)
def _assert_is_not_replica(self, instance_id):
instance = self.get_instance(instance_id, client=self.admin_client)
self.assert_client_code(200, client=self.admin_client)
client = self.admin_client
instance = self.get_instance(instance_id, client=client)
self.assert_client_code(client, 200)
if 'replica_of' not in instance._info:
try:

View File

@ -41,8 +41,9 @@ class RootActionsRunner(TestRunner):
def _assert_root_state(self, instance_id, expected_state,
expected_http_code, message):
# The call returns a nameless user object with 'rootEnabled' attribute.
response = self.auth_client.root.is_root_enabled(instance_id)
self.assert_instance_action(instance_id, None, expected_http_code)
client = self.auth_client
response = client.root.is_root_enabled(instance_id)
self.assert_client_code(client, expected_http_code)
actual_state = getattr(response, 'rootEnabled', None)
self.assert_equal(expected_state, actual_state, message)
@ -54,8 +55,9 @@ class RootActionsRunner(TestRunner):
def assert_root_disable_failure(self, instance_id, expected_exception,
expected_http_code):
client = self.auth_client
self.assert_raises(expected_exception, expected_http_code,
self.auth_client.root.delete, instance_id)
client, client.root.delete, instance_id)
def run_enable_root_no_password(self, expected_http_code=200):
root_credentials = self.test_helper.get_helper_credentials_root()
@ -66,17 +68,18 @@ class RootActionsRunner(TestRunner):
def assert_root_create(self, instance_id, root_password,
expected_root_name, expected_http_code):
client = self.auth_client
if root_password is not None:
root_creds = self.auth_client.root.create_instance_root(
root_creds = client.root.create_instance_root(
instance_id, root_password)
self.assert_equal(root_password, root_creds[1])
else:
root_creds = self.auth_client.root.create(instance_id)
root_creds = client.root.create(instance_id)
self.assert_client_code(client, expected_http_code)
if expected_root_name is not None:
self.assert_equal(expected_root_name, root_creds[0])
self.assert_instance_action(instance_id, None, expected_http_code)
self.assert_can_connect(instance_id, root_creds)
return root_creds
@ -122,8 +125,9 @@ class RootActionsRunner(TestRunner):
self.assert_root_disable(self.instance_info.id, expected_http_code)
def assert_root_disable(self, instance_id, expected_http_code):
self.auth_client.root.delete(instance_id)
self.assert_instance_action(instance_id, None, expected_http_code)
client = self.auth_client
client.root.delete(instance_id)
self.assert_client_code(client, expected_http_code)
self.assert_cannot_connect(self.instance_info.id,
self.current_root_creds)
@ -142,8 +146,9 @@ class RootActionsRunner(TestRunner):
def assert_root_delete_failure(self, instance_id, expected_exception,
expected_http_code):
root_user_name = self.current_root_creds[0]
client = self.auth_client
self.assert_raises(expected_exception, expected_http_code,
self.auth_client.users.delete,
client, client.users.delete,
instance_id, root_user_name)
def run_check_root_enabled_after_restore(

View File

@ -14,6 +14,7 @@
# under the License.
import datetime
import inspect
import netaddr
import os
import proboscis
@ -321,9 +322,7 @@ class TestRunner(object):
@property
def auth_client(self):
if not self._auth_client:
self._auth_client = self._create_authorized_client()
return self._auth_client
return self._create_authorized_client()
def _create_authorized_client(self):
"""Create a client from the normal 'authorized' user."""
@ -331,9 +330,7 @@ class TestRunner(object):
@property
def unauth_client(self):
if not self._unauth_client:
self._unauth_client = self._create_unauthorized_client()
return self._unauth_client
return self._create_unauthorized_client()
def _create_unauthorized_client(self):
"""Create a client from a different 'unauthorized' user
@ -346,9 +343,7 @@ class TestRunner(object):
@property
def admin_client(self):
if not self._admin_client:
self._admin_client = self._create_admin_client()
return self._admin_client
return self._create_admin_client()
def _create_admin_client(self):
"""Create a client from an admin user."""
@ -358,9 +353,7 @@ class TestRunner(object):
@property
def swift_client(self):
if not self._swift_client:
self._swift_client = self._create_swift_client()
return self._swift_client
return self._create_swift_client()
def _create_swift_client(self):
"""Create a swift client from the admin user details."""
@ -377,9 +370,7 @@ class TestRunner(object):
@property
def nova_client(self):
if not self._nova_client:
self._nova_client = create_nova_client(self.instance_info.user)
return self._nova_client
return create_nova_client(self.instance_info.user)
def get_client_tenant(self, client):
tenant_name = client.real_client.client.tenant
@ -389,11 +380,26 @@ class TestRunner(object):
return tenant_name, tenant_id
def assert_raises(self, expected_exception, expected_http_code,
client_cmd, *cmd_args, **cmd_kwargs):
client, client_cmd, *cmd_args, **cmd_kwargs):
if client:
# Make sure that the client_cmd comes from the same client that
# was passed in, otherwise asserting the client code may fail.
cmd_clz = client_cmd.im_self
cmd_clz_name = cmd_clz.__class__.__name__
client_attrs = [attr[0] for attr in inspect.getmembers(
client.real_client)
if '__' not in attr[0]]
match = [getattr(client, a) for a in client_attrs
if getattr(client, a).__class__.__name__ == cmd_clz_name]
self.assert_true(any(match),
"Could not find method class in client: %s" %
client_attrs)
self.assert_equal(
match[0], cmd_clz,
"Test error: client_cmd must be from client obj")
asserts.assert_raises(expected_exception, client_cmd,
*cmd_args, **cmd_kwargs)
self.assert_client_code(expected_http_code)
self.assert_client_code(client, expected_http_code)
def get_datastore_config_property(self, name, datastore=None):
"""Get a Trove configuration property for a given datastore.
@ -429,17 +435,14 @@ class TestRunner(object):
def has_do_not_delete_instance(self):
return self.has_env_flag(self.DO_NOT_DELETE_INSTANCE_FLAG)
def assert_instance_action(
self, instance_ids, expected_states, expected_http_code=None):
self.assert_client_code(expected_http_code)
def assert_instance_action(self, instance_ids, expected_states):
if expected_states:
self.assert_all_instance_states(
instance_ids if utils.is_collection(instance_ids)
else [instance_ids], expected_states)
def assert_client_code(self, expected_http_code, client=None):
if expected_http_code is not None:
client = client or self.auth_client
def assert_client_code(self, client, expected_http_code):
if client and expected_http_code is not None:
self.assert_equal(expected_http_code, client.last_http_code,
"Unexpected client status code")
@ -691,19 +694,20 @@ class TestRunner(object):
not be changed by individual test-cases.
"""
database_def, user_def, root_def = self.build_helper_defs()
client = self.auth_client
if database_def:
self.report.log(
"Creating a helper database '%s' on instance: %s"
% (database_def['name'], instance_id))
self.auth_client.databases.create(instance_id, [database_def])
self.wait_for_database_create(instance_id, [database_def])
client.databases.create(instance_id, [database_def])
self.wait_for_database_create(client, instance_id, [database_def])
if user_def:
self.report.log(
"Creating a helper user '%s:%s' on instance: %s"
% (user_def['name'], user_def['password'], instance_id))
self.auth_client.users.create(instance_id, [user_def])
self.wait_for_user_create(instance_id, [user_def])
client.users.create(instance_id, [user_def])
self.wait_for_user_create(client, instance_id, [user_def])
if root_def:
# Not enabling root on a single instance of the cluster here
@ -736,14 +740,14 @@ class TestRunner(object):
_get_credentials(credentials),
_get_credentials(credentials_root))
def wait_for_user_create(self, instance_id, expected_user_defs):
def wait_for_user_create(self, client, instance_id, expected_user_defs):
expected_user_names = {user_def['name']
for user_def in expected_user_defs}
self.report.log("Waiting for all created users to appear in the "
"listing: %s" % expected_user_names)
def _all_exist():
all_users = self.get_user_names(instance_id)
all_users = self.get_user_names(client, instance_id)
return all(usr in all_users for usr in expected_user_names)
try:
@ -753,18 +757,19 @@ class TestRunner(object):
self.fail("Some users were not created within the poll "
"timeout: %ds" % self.GUEST_CAST_WAIT_TIMEOUT_SEC)
def get_user_names(self, instance_id):
full_list = self.auth_client.users.list(instance_id)
def get_user_names(self, client, instance_id):
full_list = client.users.list(instance_id)
return {user.name: user for user in full_list}
def wait_for_database_create(self, instance_id, expected_database_defs):
def wait_for_database_create(self, client,
instance_id, expected_database_defs):
expected_db_names = {db_def['name']
for db_def in expected_database_defs}
self.report.log("Waiting for all created databases to appear in the "
"listing: %s" % expected_db_names)
def _all_exist():
all_dbs = self.get_db_names(instance_id)
all_dbs = self.get_db_names(client, instance_id)
return all(db in all_dbs for db in expected_db_names)
try:
@ -774,8 +779,8 @@ class TestRunner(object):
self.fail("Some databases were not created within the poll "
"timeout: %ds" % self.GUEST_CAST_WAIT_TIMEOUT_SEC)
def get_db_names(self, instance_id):
full_list = self.auth_client.databases.list(instance_id)
def get_db_names(self, client, instance_id):
full_list = client.databases.list(instance_id)
return {database.name: database for database in full_list}

View File

@ -65,9 +65,10 @@ class UserActionsRunner(TestRunner):
def assert_users_create(self, instance_id, serial_users_def,
expected_http_code):
self.auth_client.users.create(instance_id, serial_users_def)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.wait_for_user_create(instance_id, serial_users_def)
client = self.auth_client
client.users.create(instance_id, serial_users_def)
self.assert_client_code(client, expected_http_code)
self.wait_for_user_create(client, instance_id, serial_users_def)
return serial_users_def
def run_user_show(self, expected_http_code=200):
@ -80,9 +81,10 @@ class UserActionsRunner(TestRunner):
user_name = expected_user_def['name']
user_host = expected_user_def.get('host')
queried_user = self.auth_client.users.get(
client = self.auth_client
queried_user = client.users.get(
instance_id, user_name, user_host)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
self._assert_user_matches(queried_user, expected_user_def)
def _assert_user_matches(self, user, expected_user_def):
@ -99,8 +101,9 @@ class UserActionsRunner(TestRunner):
def assert_users_list(self, instance_id, expected_user_defs,
expected_http_code, limit=2):
full_list = self.auth_client.users.list(instance_id)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
full_list = client.users.list(instance_id)
self.assert_client_code(client, expected_http_code)
listed_users = {user.name: user for user in full_list}
self.assert_is_none(full_list.next,
"Unexpected pagination in the list.")
@ -120,8 +123,8 @@ class UserActionsRunner(TestRunner):
"System users should not be included in the 'user-list' output.")
# Test list pagination.
list_page = self.auth_client.users.list(instance_id, limit=limit)
self.assert_client_code(expected_http_code, client=self.auth_client)
list_page = client.users.list(instance_id, limit=limit)
self.assert_client_code(client, expected_http_code)
self.assert_true(len(list_page) <= limit)
if len(full_list) > limit:
@ -137,9 +140,8 @@ class UserActionsRunner(TestRunner):
self.assert_equal(expected_marker, marker,
"Pagination marker should be the last element "
"in the page.")
list_page = self.auth_client.users.list(instance_id, marker=marker)
self.assert_client_code(expected_http_code,
client=self.auth_client)
list_page = client.users.list(instance_id, marker=marker)
self.assert_client_code(client, expected_http_code)
self.assert_pagination_match(
list_page, full_list, limit, len(full_list))
@ -154,9 +156,10 @@ class UserActionsRunner(TestRunner):
def assert_user_access_show(self, instance_id, user_def,
expected_http_code):
user_name, user_host = self._get_user_name_host_pair(user_def)
user_dbs = self.auth_client.users.list_access(instance_id, user_name,
hostname=user_host)
self.assert_client_code(expected_http_code, client=self.auth_client)
client = self.auth_client
user_dbs = client.users.list_access(
instance_id, user_name, hostname=user_host)
self.assert_client_code(client, expected_http_code)
expected_dbs = {db_def['name'] for db_def in user_def['databases']}
listed_dbs = [db.name for db in user_dbs]
@ -189,10 +192,11 @@ class UserActionsRunner(TestRunner):
def assert_user_access_revoke(self, instance_id, user_name, user_host,
database, expected_http_code):
self.auth_client.users.revoke(
client = self.auth_client
client.users.revoke(
instance_id, user_name, database, hostname=user_host)
self.assert_client_code(expected_http_code, client=self.auth_client)
user_dbs = self.auth_client.users.list_access(
self.assert_client_code(client, expected_http_code)
user_dbs = client.users.list_access(
instance_id, user_name, hostname=user_host)
self.assert_false(any(db.name == database for db in user_dbs),
"Database should no longer be included in the user "
@ -205,10 +209,11 @@ class UserActionsRunner(TestRunner):
def assert_user_access_grant(self, instance_id, user_name, user_host,
database, expected_http_code):
self.auth_client.users.grant(
client = self.auth_client
client.users.grant(
instance_id, user_name, [database], hostname=user_host)
self.assert_client_code(expected_http_code, client=self.auth_client)
user_dbs = self.auth_client.users.list_access(
self.assert_client_code(client, expected_http_code)
user_dbs = client.users.list_access(
instance_id, user_name, hostname=user_host)
self.assert_true(any(db.name == database for db in user_dbs),
"Database should be included in the user "
@ -278,9 +283,10 @@ class UserActionsRunner(TestRunner):
def assert_users_create_failure(
self, instance_id, serial_users_def,
expected_exception, expected_http_code):
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.users.create, instance_id, serial_users_def)
client, client.users.create, instance_id, serial_users_def)
def run_user_update_with_blank_name(
self, expected_exception=exceptions.BadRequest,
@ -302,9 +308,10 @@ class UserActionsRunner(TestRunner):
expected_exception, expected_http_code):
user_name, user_host = self._get_user_name_host_pair(user_def)
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.users.update_attributes, instance_id,
client, client.users.update_attributes, instance_id,
user_name, update_attribites, user_host)
def _get_user_name_host_pair(self, user_def):
@ -338,9 +345,10 @@ class UserActionsRunner(TestRunner):
update_attribites, expected_http_code):
user_name, user_host = self._get_user_name_host_pair(user_def)
self.auth_client.users.update_attributes(
client = self.auth_client
client.users.update_attributes(
instance_id, user_name, update_attribites, user_host)
self.assert_client_code(expected_http_code, client=self.auth_client)
self.assert_client_code(client, expected_http_code)
# Update the stored definitions with the new value.
expected_def = None
@ -350,7 +358,7 @@ class UserActionsRunner(TestRunner):
user_def.update(update_attribites)
expected_def = user_def
self.wait_for_user_create(instance_id, self.user_defs)
self.wait_for_user_create(client, instance_id, self.user_defs)
# Verify using 'user-show' and 'user-list'.
self.assert_user_show(instance_id, expected_def, 200)
@ -388,16 +396,17 @@ class UserActionsRunner(TestRunner):
def assert_user_delete(self, instance_id, user_def, expected_http_code):
user_name, user_host = self._get_user_name_host_pair(user_def)
self.auth_client.users.delete(instance_id, user_name, user_host)
self.assert_client_code(expected_http_code, client=self.auth_client)
self._wait_for_user_delete(instance_id, user_name)
client = self.auth_client
client.users.delete(instance_id, user_name, user_host)
self.assert_client_code(client, expected_http_code)
self._wait_for_user_delete(client, instance_id, user_name)
def _wait_for_user_delete(self, instance_id, deleted_user_name):
def _wait_for_user_delete(self, client, instance_id, deleted_user_name):
self.report.log("Waiting for deleted user to disappear from the "
"listing: %s" % deleted_user_name)
def _db_is_gone():
all_users = self.get_user_names(instance_id)
all_users = self.get_user_names(client, instance_id)
return deleted_user_name not in all_users
try:
@ -419,9 +428,10 @@ class UserActionsRunner(TestRunner):
expected_exception, expected_http_code):
user_name, user_host = self._get_user_name_host_pair(user_def)
client = self.auth_client
self.assert_raises(
expected_exception, expected_http_code,
self.auth_client.users.get, instance_id, user_name, user_host)
client, client.users.get, instance_id, user_name, user_host)
def run_system_user_show(
self, expected_exception=exceptions.BadRequest,
@ -456,8 +466,9 @@ class UserActionsRunner(TestRunner):
expected_exception, expected_http_code):
user_name, user_host = self._get_user_name_host_pair(user_def)
client = self.auth_client
self.assert_raises(expected_exception, expected_http_code,
self.auth_client.users.delete,
client, client.users.delete,
instance_id, user_name, user_host)
def run_system_user_delete(