aboutsummaryrefslogtreecommitdiff
path: root/rpkid/tests
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2012-08-27 15:28:44 +0000
committerRob Austein <sra@hactrn.net>2012-08-27 15:28:44 +0000
commit7c6e23bff8d0b27a3b42f201b2a294671c7b464f (patch)
treecb93e8a8eb1bad184df8572edb62378b5a050c91 /rpkid/tests
parente4c190ad3ef54bd21dfc3adbfe817674beeb0944 (diff)
Use SHOW DATABASES and pattern matching to determine which databases
need cleaning, rather than wiring in a fixed set of database names. svn path=/branches/tk274/; revision=4663
Diffstat (limited to 'rpkid/tests')
-rw-r--r--rpkid/tests/sql-cleaner.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/rpkid/tests/sql-cleaner.py b/rpkid/tests/sql-cleaner.py
index 5db122e1..24a1f588 100644
--- a/rpkid/tests/sql-cleaner.py
+++ b/rpkid/tests/sql-cleaner.py
@@ -3,7 +3,7 @@
$Id$
-Copyright (C) 2009--2011 Internet Systems Consortium ("ISC")
+Copyright (C) 2009--2012 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
@@ -34,12 +34,16 @@ for name in ("rpkid", "irdbd", "pubd"):
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):
+ db = MySQLdb.connect(user = username, passwd = password)
+ cur = db.cursor()
- database = "%s%d" % (name[:4], i)
+ cur.execute("SHOW DATABASES")
- db = MySQLdb.connect(user = username, db = database, passwd = password)
- cur = db.cursor()
+ databases = [r[0] for r in cur.fetchall() if r[0][:4] == name[:4] and r[0][4:].isdigit()]
+
+ for database in databases:
+
+ cur.execute("USE " + database)
cur.execute("SHOW TABLES")
tables = [r[0] for r in cur.fetchall()]
@@ -52,5 +56,5 @@ for name in ("rpkid", "irdbd", "pubd"):
for statement in schema:
cur.execute(statement)
- cur.close()
- db.close()
+ cur.close()
+ db.close()