diff options
author | Michael Elkins <melkins@tislabs.com> | 2012-01-13 21:50:53 +0000 |
---|---|---|
committer | Michael Elkins <melkins@tislabs.com> | 2012-01-13 21:50:53 +0000 |
commit | d610af2370c1f8e4bf41766ffe045b269cc53c45 (patch) | |
tree | 16aa9718cadfb029aef3084d61b1647f3505969d /rpkid/tests/sql-cleaner.py | |
parent | 66a6246645eb12a4f968087662f42d1dd0417203 (diff) | |
parent | 49f26d19fcb2d9ef41cb1ed24415da16e7b5ecc2 (diff) |
merged with ^/branches/tk100
svn path=/branches/tk161/; revision=4154
Diffstat (limited to 'rpkid/tests/sql-cleaner.py')
-rw-r--r-- | rpkid/tests/sql-cleaner.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/rpkid/tests/sql-cleaner.py b/rpkid/tests/sql-cleaner.py index 5c772bc4..5db122e1 100644 --- a/rpkid/tests/sql-cleaner.py +++ b/rpkid/tests/sql-cleaner.py @@ -3,7 +3,7 @@ $Id$ -Copyright (C) 2009--2010 Internet Systems Consortium ("ISC") +Copyright (C) 2009--2011 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -18,7 +18,8 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import subprocess, rpki.config +import rpki.config, rpki.sql_schemas +from rpki.mysql_import import MySQLdb cfg = rpki.config.parser(None, "yamltest", allow_missing = True) @@ -26,8 +27,30 @@ for name in ("rpkid", "irdbd", "pubd"): username = cfg.get("%s_sql_username" % name, name[:4]) password = cfg.get("%s_sql_password" % name, "fnord") + + schema = [] + for line in getattr(rpki.sql_schemas, name, "").splitlines(): + schema.extend(line.partition("--")[0].split()) + schema = " ".join(schema).strip(";").split(";") + schema = [statement.strip() for statement in schema if statement and "DROP TABLE" not in statement] for i in xrange(12): - subprocess.check_call( - ("mysql", "-u", username, "-p" + password, "%s%d" % (name[:4], i)), - stdin = open("../%s.sql" % name)) + + database = "%s%d" % (name[:4], i) + + db = MySQLdb.connect(user = username, db = database, passwd = password) + cur = db.cursor() + + cur.execute("SHOW TABLES") + tables = [r[0] for r in cur.fetchall()] + + cur.execute("SET foreign_key_checks = 0") + for table in tables: + cur.execute("DROP TABLE %s" % table) + cur.execute("SET foreign_key_checks = 1") + + for statement in schema: + cur.execute(statement) + + cur.close() + db.close() |