Umpire: migrate: Avoid re-importing modules.

Currently will fork a process and have the child-process run
'python -r MIGRATION_ID' to run migration scripts each time.
This is very slow because indirectly imports many unused
modules. In this change we re-use the spawned python child-process, this
avoids re-importing those previously imported modules and makes the
migration much faster.

TEST=manually && ~/ umpire test

Change-Id: I931650317d088bc7ab1071dde66c0d125509d9d3
Commit-Ready: Youcheng Syu <>
Tested-by: Youcheng Syu <>
Reviewed-by: Ting Shen <>
diff --git a/py/umpire/server/ b/py/umpire/server/
index fefa727..bce173e 100755
--- a/py/umpire/server/
+++ b/py/umpire/server/
@@ -11,11 +11,11 @@
 import logging
 import os
 import re
+import sys
 import factory_common  # pylint: disable=unused-import
 from cros.factory.umpire.server import umpire_env
 from cros.factory.utils import json_utils
-from cros.factory.utils import process_utils
 _ENV_DIR = os.path.join('/', umpire_env.DEFAULT_BASE_DIR)
@@ -104,8 +104,11 @@
     raise RuntimeError('Cannot downgrade Umpire version.')
   while version < latest:
     version += 1
-    process_utils.Spawn(
-        [__file__, '-r', str(version)], log=True, check_call=True)
+    if os.fork() == 0:
+      _RunMigration(version)
+      sys.exit()
+    if os.wait()[1] != 0:
+      raise RuntimeError('Stop running migrations.')
 def main():