servo: enable main device during initialize_dut

We are going to start changing the active_device during faft. This
change modifies initialize_dut to ensure the main device is active at
the start of tests just in case cleanup fails to cleanup the active
device.

BUG=b:35579416
BRANCH=none
TEST=run on a device with dual_v4

Change-Id: Ia1c6e3529c39cc8f56286cf21665ca572ce23ce7
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1850711
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Namyoon Woo <namyoon@chromium.org>
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index e9bb022..067c552 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -335,7 +335,7 @@
         return self._power_state
 
 
-    def initialize_dut(self, cold_reset=False):
+    def initialize_dut(self, cold_reset=False, enable_main=True):
         """Initializes a dut for testing purposes.
 
         This sets various servo signals back to default values
@@ -354,7 +354,13 @@
 
         @param cold_reset If True, cold reset the device after
                           initialization.
+        @param enable_main If True, make sure the main servo device has
+                           control of the dut.
+
         """
+        if enable_main:
+            self.enable_main_servo_device()
+
         try:
             self._server.hwinit()
         except socket.error as e:
@@ -958,6 +964,19 @@
         return servo_type
 
 
+    def get_main_servo_device(self):
+        """Return the main servo device"""
+        servo_type = self.get_servo_version()
+        return servo_type.split('_with_')[-1].split('_and_')[0]
+
+
+    def enable_main_servo_device(self):
+        """Make sure the main device has control of the dut."""
+        if not self.has_control('active_v4_device'):
+            return
+        self.set('active_v4_device', self.get_main_servo_device())
+
+
     def running_through_ccd(self):
         """Returns True if the setup is using ccd to run."""
         servo = self._server.get_version()