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 <[email protected]>

--- autotest/database/migrate.py        2010-01-11 13:14:38.000000000 -0800
+++ autotest/database/migrate.py        2010-01-14 16:17:25.000000000 -0800
@@ -70,6 +70,10 @@
     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 @@
             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 @@
         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 @@
         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
--- autotest/frontend/migrations/046_merge_databases.py 2010-01-14 
10:26:52.000000000 -0800
+++ autotest/frontend/migrations/046_merge_databases.py 2010-01-14 
16:17:25.000000000 -0800
@@ -16,6 +16,9 @@
         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. 
'
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to