summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshoward <showard@592f7852-d20e-0410-864c-8624ca9c26a4>2010-01-15 19:15:14 +0000
committershoward <showard@592f7852-d20e-0410-864c-8624ca9c26a4>2010-01-15 19:15:14 +0000
commit8809059a6b91871bf3aee221aa7a9c876f6d1545 (patch)
tree1d84aea97a8be75ce141bef0dca3e72873988ad1
parent85e538adb1d7cef842d3dac46177b4e449d2adcb (diff)
Fix interactions with db_utils when simulating. Anyone attempting to
simulate a migration through AUTOTEST_WEB version 46 before this change would actually drop the TKO database. Signed-off-by: James Ren <jamesren@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@4129 592f7852-d20e-0410-864c-8624ca9c26a4
-rwxr-xr-xdatabase/migrate.py24
-rw-r--r--frontend/migrations/046_merge_databases.py3
2 files changed, 21 insertions, 6 deletions
diff --git a/database/migrate.py b/database/migrate.py
index 07a286a4..3e054856 100755
--- a/database/migrate.py
+++ b/database/migrate.py
@@ -70,6 +70,10 @@ class MigrationManager(object):
def __init__(self, database_connection, migrations_dir=None, force=False):
self._database = database_connection
self.force = force
+ # A boolean, this will only be set to True if this migration should be
+ # simulated rather than actually taken. For use with migrations that
+ # may make destructive queries
+ self.simulate = False
self._set_migrations_dir(migrations_dir)
@@ -262,6 +266,16 @@ class MigrationManager(object):
print 'Skipping simulation, already at latest version'
return
# get existing data
+ self.initialize_and_fill_test_db()
+ try:
+ print 'Starting migration test on DB', self.get_db_name()
+ self.migrate_to_version_or_latest(version)
+ finally:
+ self.remove_test_db()
+ print 'Test finished successfully'
+
+
+ def initialize_and_fill_test_db(self):
print 'Dumping existing data'
dump_fd, dump_file = tempfile.mkstemp('.migrate_dump')
os.system('mysqldump %s >%s' %
@@ -272,12 +286,6 @@ class MigrationManager(object):
os.system('mysql %s <%s' % (self.get_mysql_args(), dump_file))
os.close(dump_fd)
os.remove(dump_file)
- try:
- print 'Starting migration test on DB', self.get_db_name()
- self.migrate_to_version_or_latest(version)
- finally:
- self.remove_test_db()
- print 'Test finished successfully'
USAGE = """\
@@ -311,13 +319,17 @@ def main():
if args[0] == 'sync':
manager.do_sync_db(version)
elif args[0] == 'test':
+ manager.simulate=True
manager.test_sync_db(version)
elif args[0] == 'simulate':
+ manager.simulate=True
manager.simulate_sync_db(version)
elif args[0] == 'safesync':
print 'Simluating migration'
+ manager.simulate=True
manager.simulate_sync_db(version)
print 'Performing real migration'
+ manager.simulate=False
manager.do_sync_db(version)
else:
print USAGE
diff --git a/frontend/migrations/046_merge_databases.py b/frontend/migrations/046_merge_databases.py
index 045ad1b8..f73dc748 100644
--- a/frontend/migrations/046_merge_databases.py
+++ b/frontend/migrations/046_merge_databases.py
@@ -16,6 +16,9 @@ def migrate_up(manager):
raise Exception('You must update the TKO database to at least version '
'31 before applying AUTOTEST_WEB migration 46')
+ if manager.simulate:
+ tko_manager.initialize_and_fill_test_db()
+
if not manager.force:
response = raw_input(
'This migration will merge the autotest_web and tko databases. '