Merge "Fail on deleting non-existing database"

This commit is contained in:
Jenkins 2016-11-21 11:03:20 +00:00 committed by Gerrit Code Review
commit ad51c7dc82
4 changed files with 19 additions and 7 deletions

View File

@ -261,3 +261,13 @@ class Schemas(object):
mysql_schema.collate,
mysql_schema.character_set))
return model_schemas, next_marker
@classmethod
def find(cls, context, instance_id, schema_id):
load_and_verify(context, instance_id)
client = create_guest_client(context, instance_id)
model_schemas, _ = cls.load_with_client(client, 1, schema_id, True)
if model_schemas and model_schemas[0].name == schema_id:
return model_schemas[0]
return None

View File

@ -340,6 +340,8 @@ class SchemaController(wsgi.Controller):
try:
schema = guest_models.MySQLSchema(name=id)
schema.check_delete()
if not models.Schemas.find(context, instance_id, id):
raise exception.DatabaseNotFound(uuid=id)
models.Schema.delete(context, instance_id, schema.serialize())
except (ValueError, AttributeError) as e:
raise exception.BadRequest(_("Database delete error: %(e)s")

View File

@ -454,7 +454,7 @@ class BaseMySqlAdmin(object):
next_marker = None
LOG.debug("database_names = %r." % database_names)
for count, database in enumerate(database_names):
if count >= limit:
if limit is not None and count >= limit:
break
LOG.debug("database = %s." % str(database))
mysql_db = models.MySQLSchema(name=database[0],
@ -517,7 +517,7 @@ class BaseMySqlAdmin(object):
next_marker = None
LOG.debug("result = " + str(result))
for count, row in enumerate(result):
if count >= limit:
if limit is not None and count >= limit:
break
LOG.debug("user = " + str(row))
mysql_user = models.MySQLUser(name=row['User'],

View File

@ -182,12 +182,12 @@ class DatabaseActionsRunner(TestRunner):
self.fail("Database still listed after the poll timeout: %ds" %
self.GUEST_CAST_WAIT_TIMEOUT_SEC)
def run_nonexisting_database_delete(self, expected_http_code=202):
# Deleting a non-existing database is expected to succeed as if the
# database was deleted.
self.assert_database_delete(
def run_nonexisting_database_delete(
self, expected_exception=exceptions.NotFound,
expected_http_code=404):
self.assert_database_delete_failure(
self.instance_info.id, self.non_existing_db_def['name'],
expected_http_code)
expected_exception, expected_http_code)
def run_system_database_delete(
self, expected_exception=exceptions.BadRequest,