Safer to sync and wait until the cgpt status written to the disk.

We found that firmware_CorruptKernelB test on Alex may fail due to this reason.

BUG=chromium-os:19710
TEST=run_remote_tests.sh --remote=$REMOTE_IP -a "xml_config=$OVERLAY_XML \
        servo_vid=0x18d1 servo_pid=0x5001" CorruptKernelB/control.both

Change-Id: I03df8569d4187a9396a7a2088207da602e6d620b
Reviewed-on: https://gerrit.chromium.org/gerrit/12612
Commit-Ready: Tom Wai-Hong Tam <waihong@chromium.org>
Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org>
Tested-by: Tom Wai-Hong Tam <waihong@chromium.org>
diff --git a/server/cros/faftsequence.py b/server/cros/faftsequence.py
index 9cc0a8f..c30cf75 100644
--- a/server/cros/faftsequence.py
+++ b/server/cros/faftsequence.py
@@ -74,6 +74,7 @@
     FIRMWARE_SCREEN_DELAY = 10
     TEXT_SCREEN_DELAY = 20
     USB_PLUG_DELAY = 10
+    SYNC_DELAY = 5
 
     _faft_template = None
     _faft_sequence = ()
@@ -214,8 +215,12 @@
         Returns:
           True if the currect root  partition number matched; otherwise, False.
         """
-        part = self.faft_client.get_root_part()
-        return self.ROOTFS_MAP[expected_part] == part[-1]
+        part = self.faft_client.get_root_part()[-1]
+        if self.ROOTFS_MAP[expected_part] != part:
+            logging.info("Expected root part %s but got %s" %
+                         (self.ROOTFS_MAP[expected_part], part))
+            return False
+        return True
 
 
     def _join_part(self, dev, part):
@@ -389,6 +394,9 @@
         # Set kernel part highest priority.
         self.faft_client.run_shell_command('cgpt prioritize -i%s %s' %
                 (self.KERNEL_MAP[part], root_dev))
+        # Safer to sync and wait until the cgpt status written to the disk.
+        self.faft_client.run_shell_command('sync')
+        time.sleep(self.SYNC_DELAY)
 
 
     def sync_and_hw_reboot(self):
@@ -397,7 +405,7 @@
         This is the default reboot action on FAFT.
         """
         self.faft_client.run_shell_command('sync')
-        time.sleep(5)
+        time.sleep(self.SYNC_DELAY)
         self.servo.warm_reset()