faft: Swap servo v4 role to SNK for recovery USB boot

In recovery boot, the locked EC RO doesn't support PD for most
of the CrOS devices. The default servo v4 power role is a SRC.
The DUT becomes a SNK. Lack of PD makes CrOS unable to do the
data role swap from UFP to DFP; as a result, DUT can't see the
USB disk and the Ethernet dongle on servo v4.

This is a workaround to set servo v4 as a SNK, for every FAFT
test which boots into the USB disk in the recovery mode.

A test should define the argument used_for_recovery=True in
the setup_usbkey().

BUG=b:123719781
TEST=Only use a single-USB-port on a locked Snappy device,
which connects to servo v4 with servo micro, and servo v4
connects to Ethernet, USB disk, and power supply.
 * Run the FAFT test firmware_RecoveryButton.ec_wp which locks
   EC through WP and boots into the servo v4 USB disk.
 * Run the firmware_PDProtocol not broken.

Change-Id: Id92f6fa8a87405880c17f2853b40dfb2568fce63
Reviewed-on: https://chromium-review.googlesource.com/943832
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index ba5ccf9..fe564bc 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -913,6 +913,24 @@
         return self._usb_state
 
 
+    def set_servo_v4_role(self, role):
+        """Set the power role of servo v4, either 'src' or 'snk'.
+
+        It does nothing if not a servo v4.
+
+        @param role: Power role for DUT port on servo v4, either 'src' or 'snk'.
+        """
+        servo_version = self.get_servo_version()
+        if servo_version.startswith('servo_v4'):
+            value = self.get('servo_v4_role')
+            if value != role:
+                self.set_nocheck('servo_v4_role', role)
+            else:
+                logging.debug('Already in the role: %s.', role)
+        else:
+            logging.debug('Not a servo v4, unable to set role to %s.', role)
+
+
     def dump_uart_streams(self, output_dir):
         """Get buffered UART streams and append to log files.