Check only the active pool for storage qual check setup

Updating the hardware_StorageQualCheckSetup test to only validate the active pool actually running the suite has correct setup. Partners would often fail this test by having extra DUTs plugged into their moblab, even though the pool they are running the
suite with was correctly set up.

BUG=b:122616405
TEST=Run hardware_StorageQualCheckSetup with correct and incorrect configurations

Change-Id: Ib0cf7ba35fc2cd9cf57d1030d7f7f51c8757c768
Reviewed-on: https://chromium-review.googlesource.com/1600465
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Matt Mallett <mattmallett@chromium.org>
Reviewed-by: Matt Mallett <mattmallett@chromium.org>
Reviewed-by: Keith Haddow <haddowk@chromium.org>
(cherry picked from commit 672cc83d61f78187bd7dfe9c84f50c905d649f48)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/1951863
Tested-by: Keith Haddow <haddowk@chromium.org>
Commit-Queue: Keith Haddow <haddowk@chromium.org>
diff --git a/server/site_tests/hardware_StorageQualCheckSetup/hardware_StorageQualCheckSetup.py b/server/site_tests/hardware_StorageQualCheckSetup/hardware_StorageQualCheckSetup.py
index 6854058..27f82c9 100644
--- a/server/site_tests/hardware_StorageQualCheckSetup/hardware_StorageQualCheckSetup.py
+++ b/server/site_tests/hardware_StorageQualCheckSetup/hardware_StorageQualCheckSetup.py
@@ -1,12 +1,10 @@
-# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+# Copyright (c) 2019 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
 import logging
-import subprocess
 
 from autotest_lib.client.common_lib import error
-from autotest_lib.client.common_lib import utils
 from autotest_lib.server import test
 from autotest_lib.server import frontend
 
@@ -20,11 +18,10 @@
         No duplication of the labels, all labels are applied exactly once
             per pool
 
-    The test will verify this set up. If any pool isn't configured correctly,
-    the test will fail. To pass the test, every DUT must be a part of a
-    correctly configured pool. This gives us confidence that the partners
-    will have a correct setup for storage qual no matter which pool they select
-    on RunSuite page.
+    The test will verify this set up, for the pool that is selected on the
+    RunSuite page (by getting the pool of the DUT running the test). If this
+    test passes, we have confidence that this individual pool is a valid setup
+    for storage qual.
     """
 
     version = 1
@@ -51,12 +48,20 @@
 
         return pools
 
+    def _get_running_host_pool(self):
+        host = list(self.job.hosts)[0]
+        pools = host.host_info_store.get().pools
+        return list(pools)[0] if len(pools) > 0 else 'none'
 
     def run_once(self):
         """ Tests the moblab's connected DUTs to see if the current
         configuration is valid for storage qual
         """
 
+        # get the pool of the host this test is running on
+        pool_name = self._get_running_host_pool()
+        logging.info('Test is running on pool %s', pool_name)
+
         afe = frontend.AFE(server='localhost', user='moblab')
 
         # get autotest statuses that indicate a live host
@@ -66,52 +71,48 @@
         hosts = []
         for host in afe.get_hosts():
             if host.status in live_statuses:
-                logging.info('Host %s is live, status %s' %
-                        (host.hostname, host.status))
+                logging.info('Host %s is live, status %s',
+                        host.hostname, host.status)
                 hosts.append(host)
             else:
-                logging.info('Host %s is not live, status %s' %
-                        (host.hostname, host.status))
+                logging.info('Host %s is not live, status %s',
+                        host.hostname, host.status)
 
         pools = self._group_hosts_into_pools(hosts)
 
-        # verify that each pool is set up to run storage qual
-        # err on the side of caution by requiring all pools to have the correct
-        # setup, so it is clear to partners that they could run storage qual
-        # with any configuration on RunSuite page
+        # verify that the pool is set up to run storage qual, with correct
+        # number of DUTs and correct labels
         required_set = set(self.REQUIRED_LABELS)
-        for pool_name, pool_hosts in pools.iteritems():
-            provided_set = set()
-            logging.info('Pool %s' % pool_name)
-            for host in pool_hosts:
-                host_provided_labels = set(host['labels']) & required_set
-                # check that each DUT has at most 1 storage qual label
-                if len(host_provided_labels) > 1:
-                    raise error.TestFail(
-                        ('Host %s is assigned more than '
-                            'one storage qual label %s') %
-                            (host['host'], str(host_provided_labels)))
-                if len(host_provided_labels) == 0:
-                    continue
-
-                # check that each label is only on one DUT in the pool
-                provided_label = host_provided_labels.pop()
-                if provided_label in provided_set:
-                    raise error.TestFail(
-                        ('Host %s is assigned label %s, which is already '
-                         'assigned to another DUT in pool %s') %
-                            (host['host'], provided_label, pool_name)
-                    )
-
-                provided_set.add(provided_label)
-                logging.info(' - %s %s' % (host['host'], provided_label))
-
-            # check that all storage qual labels are accounted for in the pool
-            missing_labels = required_set - provided_set
-            if len(missing_labels) > 0:
+        provided_set = set()
+        for host in pools[pool_name]:
+            host_provided_labels = set(host['labels']) & required_set
+            # check that each DUT has at most 1 storage qual label
+            if len(host_provided_labels) > 1:
                 raise error.TestFail(
-                    'Pool %s is missing required labels %s' %
-                        (pool_name, str(missing_labels))
+                    ('Host %s is assigned more than '
+                        'one storage qual label %s') %
+                        (host['host'], str(host_provided_labels)))
+            if len(host_provided_labels) == 0:
+                continue
+
+            # check that each label is only on one DUT in the pool
+            provided_label = host_provided_labels.pop()
+            if provided_label in provided_set:
+                raise error.TestFail(
+                    ('Host %s is assigned label %s, which is already '
+                      'assigned to another DUT in pool %s') %
+                        (host['host'], provided_label, pool_name)
+                )
+
+            provided_set.add(provided_label)
+            logging.info(' - %s %s', host['host'], provided_label)
+
+        # check that all storage qual labels are accounted for in the pool
+        missing_labels = required_set - provided_set
+        if len(missing_labels) > 0:
+            raise error.TestFail(
+                'Pool %s is missing required labels %s' %
+                    (pool_name, str(missing_labels))
                 )
 
         return