Merge "Corrects list_database query for MySQL"

This commit is contained in:
Jenkins 2015-04-02 19:00:03 +00:00 committed by Gerrit Code Review
commit bbdecfd835
3 changed files with 17 additions and 21 deletions

View File

@ -128,7 +128,8 @@ common_opts = [
cfg.ListOpt('ignore_users', default=['os_admin', 'root'],
help='Users to exclude when listing users.'),
cfg.ListOpt('ignore_dbs',
default=['lost+found', 'mysql', 'information_schema'],
default=['lost+found', '#mysql50#lost+found', 'mysql',
'information_schema'],
help='Databases to exclude when listing databases.'),
cfg.IntOpt('agent_call_low_timeout', default=5,
help="Maximum time (in seconds) to wait for Guest Agent 'quick'"

View File

@ -422,6 +422,9 @@ class MySqlAdmin(object):
def list_databases(self, limit=None, marker=None, include_marker=False):
"""List databases the user created on this mysql instance."""
LOG.debug("---Listing Databases---")
ignored_database_names = "'%s'" % "', '".join(CONF.ignore_dbs)
LOG.debug("The following database names are on ignore list and will "
"be omitted from the listing: %s" % ignored_database_names)
databases = []
with LocalSqlClient(get_engine()) as client:
# If you have an external volume mounted at /var/lib/mysql
@ -435,10 +438,7 @@ class MySqlAdmin(object):
'default_collation_name as collation',
]
q.tables = ['information_schema.schemata']
q.where = ["schema_name NOT IN ("
"'mysql', 'information_schema', "
"'lost+found', '#mysql50#lost+found'"
")"]
q.where = ["schema_name NOT IN (" + ignored_database_names + ")"]
q.order = ['schema_name ASC']
if limit:
q.limit = limit + 1

View File

@ -27,6 +27,7 @@ import testtools
from testtools.matchers import Is
from testtools.matchers import Equals
from testtools.matchers import Not
from trove.common import cfg
from trove.common.exception import ProcessExecutionError
from trove.common.exception import GuestError
from trove.common import utils
@ -71,6 +72,8 @@ from trove.guestagent.volume import VolumeDevice
from trove.instance.models import InstanceServiceStatus
from trove.tests.unittests.util import util
CONF = cfg.CONF
"""
Unit tests for the classes and functions in dbaas.py.
@ -348,10 +351,8 @@ class MySqlAdminTest(testtools.TestCase):
"default_character_set_name as charset,",
"default_collation_name as collation",
"FROM information_schema.schemata",
("schema_name NOT IN ("
"'mysql', 'information_schema', "
"'lost+found', '#mysql50#lost+found'"
")"),
("schema_name NOT IN ('" + "', '".join(CONF.ignore_dbs) +
"')"),
"ORDER BY schema_name ASC",
]
for text in expected:
@ -366,10 +367,8 @@ class MySqlAdminTest(testtools.TestCase):
"default_character_set_name as charset,",
"default_collation_name as collation",
"FROM information_schema.schemata",
("schema_name NOT IN ("
"'mysql', 'information_schema', "
"'lost+found', '#mysql50#lost+found'"
")"),
("schema_name NOT IN ('" + "', '".join(CONF.ignore_dbs) +
"')"),
"ORDER BY schema_name ASC",
]
for text in expected:
@ -385,10 +384,8 @@ class MySqlAdminTest(testtools.TestCase):
"default_character_set_name as charset,",
"default_collation_name as collation",
"FROM information_schema.schemata",
("schema_name NOT IN ("
"'mysql', 'information_schema', "
"'lost+found', '#mysql50#lost+found'"
")"),
("schema_name NOT IN ('" + "', '".join(CONF.ignore_dbs) +
"')"),
"ORDER BY schema_name ASC",
]
@ -407,10 +404,8 @@ class MySqlAdminTest(testtools.TestCase):
"default_character_set_name as charset,",
"default_collation_name as collation",
"FROM information_schema.schemata",
("schema_name NOT IN ("
"'mysql', 'information_schema', "
"'lost+found', '#mysql50#lost+found'"
")"),
("schema_name NOT IN ('" + "', '".join(CONF.ignore_dbs) +
"')"),
"ORDER BY schema_name ASC",
]
for text in expected: