servo_LabstationVerification: Store stable_version in static config file

Since we no longer pass stable_version info for tests, the original logic
to copy labstation's stable_version to DUT's stable_version has been
broken. This fix will store and read stable_version from the existing
DUT info config.

BUG=None
TEST=Run test locally

Change-Id: I8938b07a3cd6fe36437e44788cf7de324003410a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2481970
Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Commit-Queue: Garry Wang <xianuowang@chromium.org>
Tested-by: Garry Wang <xianuowang@chromium.org>
diff --git a/server/site_tests/servo_LabstationVerification/labstation_to_dut_map.json b/server/site_tests/servo_LabstationVerification/labstation_to_dut_map.json
index 6c6c3e3..52825dc 100644
--- a/server/site_tests/servo_LabstationVerification/labstation_to_dut_map.json
+++ b/server/site_tests/servo_LabstationVerification/labstation_to_dut_map.json
@@ -6,7 +6,8 @@
       "model": "soraka",
       "servo_serial": "C1903142451",
       "servo_port": "9999",
-      "mac_address": "F4:F5:E8:50:DD:01"
+      "mac_address": "F4:F5:E8:50:DD:01",
+      "stable_version": "R86-13421.17.0"
     },
     {
       "hostname": "chromeos1-row4-rack7-host2",
@@ -14,7 +15,8 @@
       "model": "aleena",
       "servo_serial": "C1706310086",
       "servo_port": "9998",
-      "mac_address": "08:9E:08:E4:A0:5C"
+      "mac_address": "08:9E:08:E4:A0:5C",
+      "stable_version": "R86-13421.32.0"
     },
     {
       "hostname": "chromeos1-row4-rack7-host3",
@@ -22,7 +24,8 @@
       "model": "kevin",
       "servo_serial": "C1903145143",
       "servo_port": "9997",
-      "mac_address": "F4:F5:E8:50:E7:85"
+      "mac_address": "F4:F5:E8:50:E7:85",
+      "stable_version": "R86-13421.32.0"
     },
     {
       "hostname": "chromeos1-row4-rack7-host5",
@@ -30,7 +33,8 @@
       "model": "nocturne",
       "servo_serial": "C1706310022",
       "servo_port": "9995",
-      "mac_address": "08:9E:08:E4:A0:1C"
+      "mac_address": "08:9E:08:E4:A0:1C",
+      "stable_version": "R86-13421.32.0"
     },
     {
       "hostname": "chromeos1-row4-rack7-host6",
@@ -38,7 +42,8 @@
       "model": "bard",
       "servo_serial": "C1903142681",
       "servo_port": "9994",
-      "mac_address": "F4:F5:E8:50:DD:E7"
+      "mac_address": "F4:F5:E8:50:DD:E7",
+      "stable_version": "R86-13421.32.0"
     }
   ],
   "chromeos1-row4-rack9-labstation3": [
@@ -48,7 +53,8 @@
       "model": "atlas",
       "servo_serial": "C1804022991",
       "servo_port": "9997",
-      "mac_address": "F4:F5:E8:50:D1:D5"
+      "mac_address": "F4:F5:E8:50:D1:D5",
+      "stable_version": "R86-13421.32.0"
     },
     {
       "hostname": "chromeos1-row4-rack9-host4",
@@ -56,7 +62,8 @@
       "model": "atlas",
       "servo_serial": "C1706310083",
       "servo_port": "9996",
-      "mac_address": "08:9E:08:E4:A0:59"
+      "mac_address": "08:9E:08:E4:A0:59",
+      "stable_version": "R86-13421.32.0"
     },
     {
       "hostname": "chromeos1-row4-rack9-host5",
@@ -64,7 +71,8 @@
       "model": "wukong",
       "servo_serial": "C1903143985",
       "servo_port": "9995",
-      "mac_address": "F4:F5:E8:50:E2:FF"
+      "mac_address": "F4:F5:E8:50:E2:FF",
+      "stable_version": "R86-13421.32.0"
     },
     {
       "hostname": "chromeos1-row4-rack9-host6",
@@ -72,7 +80,8 @@
       "model": "sarien",
       "servo_serial": "C1903143516",
       "servo_port": "9994",
-      "mac_address": "F4:F5:E8:50:E1:2A"
+      "mac_address": "F4:F5:E8:50:E1:2A",
+      "stable_version": "R86-13421.32.0"
     }
   ]
 }
diff --git a/server/site_tests/servo_LabstationVerification/servo_LabstationVerification.py b/server/site_tests/servo_LabstationVerification/servo_LabstationVerification.py
index 207ca7f..e2a3495 100644
--- a/server/site_tests/servo_LabstationVerification/servo_LabstationVerification.py
+++ b/server/site_tests/servo_LabstationVerification/servo_LabstationVerification.py
@@ -60,7 +60,7 @@
             if 'No control named' in e:
                 serial = servo_proxy.get('serialname')
             else:
-              raise e
+                raise e
         ctrl_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  'serial_to_mac_map.json')
         with open(ctrl_path, 'r') as f:
@@ -275,13 +275,15 @@
                                            'autoserv')
         return dut_ipv4
 
-    def _set_dut_stable_version(self, dut_host):
+    def _set_dut_stable_version(self, dut_host, stable_version=None):
         """Helper method to set stable_version in DUT host.
 
         @param dut_host: CrosHost object representing the DUT.
         """
-        logging.info('Setting stable_version to %s for DUT host.',
-                     self.cros_version)
+        if not stable_version:
+            stable_version = self.cros_version
+        logging.info('Setting stable_version to %s for DUT %s.',
+                     stable_version, dut_host.hostname)
         host_info = dut_host.host_info_store.get()
         host_info.stable_versions['cros'] = self.cros_version
         dut_host.host_info_store.commit(host_info)
@@ -369,7 +371,8 @@
             # consume.
             # TODO(xianuowang@): remove this logic once we figured out how to
             # propagate DUT's stable_version to the test.
-            self._set_dut_stable_version(dut_host)
+            stable_version_from_config = dut_info.get('stable_version')
+            self._set_dut_stable_version(dut_host, stable_version_from_config)
             # Store |dut_host| in |machine_dict| so that parallel running can
             # find the host.
             self.machine_dict[dut_host.hostname] = dut_host
@@ -454,6 +457,8 @@
         # debugging failures is cleaner given multiple setups.
 
     def cleanup(self):
-        """Clean up by stopping the servod instance again."""
-        for servo_host in self.servo_hosts:
-            servo_host.close()
+        """Clean up by calling close for dut host, which will also take care
+        of servo cleanup.
+        """
+        for _, dut in self.machine_dict.items():
+            dut.close()