autotest: use get_headphone_node instead of hardcoded 'HEADPHONE'

BUG=b:146536456, b:142701772
TEST=Run tests on sarien and other boards.

Change-Id: Ib4157ed9850791fc8d444976ad6d867a3e4f965f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/1975256
Tested-by: En-Shuo Hsu <enshuo@chromium.org>
Commit-Queue: En-Shuo Hsu <enshuo@chromium.org>
Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Reviewed-by: Kalin Stoyanov <kalin@chromium.org>
Auto-Submit: En-Shuo Hsu <enshuo@chromium.org>
diff --git a/client/cros/chameleon/audio_test_utils.py b/client/cros/chameleon/audio_test_utils.py
index 85ffcb9..c53c428 100644
--- a/client/cros/chameleon/audio_test_utils.py
+++ b/client/cros/chameleon/audio_test_utils.py
@@ -830,7 +830,7 @@
 
     @returns: The name of the expected internal microphone nodes.
     """
-    board = host.get_board().split(':')[1]
+    board = get_board_name(host)
     model = host.get_platform()
     sku = host.host_info_store.get().device_sku
 
@@ -844,8 +844,17 @@
 
     @returns: A list of all the plugged internal microphone nodes.
     """
-    board = host.get_board().split(':')[1]
+    board = get_board_name(host)
     model = host.get_platform()
     sku = host.host_info_store.get().device_sku
 
     return audio_spec.get_plugged_internal_mics(board, model, sku)
+
+def get_headphone_node(host):
+    """Return the expected headphone node.
+
+    @param host: The CrosHost object.
+
+    @returns: The name of the expected headphone nodes.
+    """
+    return audio_spec.get_headphone_node(get_board_name(host))
diff --git a/server/site_tests/audio_AudioAfterReboot/control.external_mic b/server/site_tests/audio_AudioAfterReboot/control.external_mic
index 5530b5d..20dea07 100644
--- a/server/site_tests/audio_AudioAfterReboot/control.external_mic
+++ b/server/site_tests/audio_AudioAfterReboot/control.external_mic
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 from autotest_lib.client.cros.audio import audio_test_data
+from autotest_lib.client.cros.chameleon import audio_test_utils
 from autotest_lib.client.cros.chameleon import chameleon_audio_ids
 from autotest_lib.server import utils
 
@@ -31,6 +32,8 @@
                  golden_data=(audio_test_data.SIMPLE_FREQUENCY_TEST_FILE, 2000),
                  bind_from=chameleon_audio_ids.ChameleonIds.LINEOUT,
                  bind_to=chameleon_audio_ids.CrosIds.EXTERNAL_MIC,
-                 audio_nodes=(['HEADPHONE'], ['MIC']), tag = "external_mic")
+                 audio_nodes=([audio_test_utils.get_headphone_node(host)],
+                              ['MIC']),
+                 tag = "external_mic")
 
 parallel_simple(run, machines)
diff --git a/server/site_tests/audio_AudioAfterReboot/control.headphone b/server/site_tests/audio_AudioAfterReboot/control.headphone
index 996357f..fe06792 100644
--- a/server/site_tests/audio_AudioAfterReboot/control.headphone
+++ b/server/site_tests/audio_AudioAfterReboot/control.headphone
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 from autotest_lib.client.cros.audio import audio_test_data
+from autotest_lib.client.cros.chameleon import audio_test_utils
 from autotest_lib.client.cros.chameleon import chameleon_audio_ids
 from autotest_lib.server import utils
 
@@ -31,6 +32,8 @@
                  golden_data=(audio_test_data.FREQUENCY_TEST_FILE, 4000),
                  bind_from=chameleon_audio_ids.CrosIds.HEADPHONE,
                  bind_to=chameleon_audio_ids.ChameleonIds.LINEIN,
-                 audio_nodes=(['HEADPHONE'],[ 'MIC']), tag = "headphone")
+                 audio_nodes=([audio_test_utils.get_headphone_node(host)],
+                              [ 'MIC']),
+                 tag = "headphone")
 
 parallel_simple(run, machines)
diff --git a/server/site_tests/audio_AudioAfterSuspend/control.headphone b/server/site_tests/audio_AudioAfterSuspend/control.headphone
index 39e0809..a3a5dd0 100644
--- a/server/site_tests/audio_AudioAfterSuspend/control.headphone
+++ b/server/site_tests/audio_AudioAfterSuspend/control.headphone
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 from autotest_lib.client.cros.audio import audio_test_data
+from autotest_lib.client.cros.chameleon import audio_test_utils
 from autotest_lib.client.cros.chameleon import chameleon_audio_ids
 from autotest_lib.server import utils
 
@@ -36,7 +37,8 @@
                  golden_data=(audio_test_data.FREQUENCY_TEST_FILE, 4000),
                  bind_from=chameleon_audio_ids.CrosIds.HEADPHONE,
                  bind_to=chameleon_audio_ids.ChameleonIds.LINEIN,
-                 audio_nodes=(['HEADPHONE'], None),
+                 audio_nodes=([audio_test_utils.get_headphone_node(host)],
+                              None),
                  plug_status=plug_status, tag = "headphone")
 
 parallel_simple(run, machines)
diff --git a/server/site_tests/audio_AudioAfterSuspend/control.headphone.unplug b/server/site_tests/audio_AudioAfterSuspend/control.headphone.unplug
index 65b5aac..ca86174 100644
--- a/server/site_tests/audio_AudioAfterSuspend/control.headphone.unplug
+++ b/server/site_tests/audio_AudioAfterSuspend/control.headphone.unplug
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 from autotest_lib.client.cros.audio import audio_test_data
+from autotest_lib.client.cros.chameleon import audio_test_utils
 from autotest_lib.client.cros.chameleon import chameleon_audio_ids
 from autotest_lib.server import utils
 
@@ -39,7 +40,8 @@
                  golden_data=(audio_test_data.FREQUENCY_TEST_FILE, 4000),
                  bind_from=chameleon_audio_ids.CrosIds.HEADPHONE,
                  bind_to=chameleon_audio_ids.ChameleonIds.LINEIN,
-                 audio_nodes=(['HEADPHONE'], None),
+                 audio_nodes=([audio_test_utils.get_headphone_node(host)],
+                              None),
                  plug_status=plug_status, tag = "headphone.unplug")
 
 parallel_simple(run, machines)
diff --git a/server/site_tests/audio_AudioBasicHeadphone/audio_AudioBasicHeadphone.py b/server/site_tests/audio_AudioBasicHeadphone/audio_AudioBasicHeadphone.py
index 045708c..15f4d1a 100644
--- a/server/site_tests/audio_AudioBasicHeadphone/audio_AudioBasicHeadphone.py
+++ b/server/site_tests/audio_AudioBasicHeadphone/audio_AudioBasicHeadphone.py
@@ -55,7 +55,8 @@
 
             # Selects and checks the node selected by cras is correct.
             audio_test_utils.check_and_set_chrome_active_node_types(
-                    self.facade, 'HEADPHONE', None)
+                    self.facade, audio_test_utils.get_headphone_node(self.host),
+                    None)
 
             logging.info('Setting playback data on Cros device')
             source.set_playback_data(golden_file)
diff --git a/server/site_tests/audio_MediaBasicVerification/audio_MediaBasicVerification.py b/server/site_tests/audio_MediaBasicVerification/audio_MediaBasicVerification.py
index 0c0c276..3fd91f0 100644
--- a/server/site_tests/audio_MediaBasicVerification/audio_MediaBasicVerification.py
+++ b/server/site_tests/audio_MediaBasicVerification/audio_MediaBasicVerification.py
@@ -31,7 +31,7 @@
     UNSUPPORTED_BOARD_TYPES = ['CHROMEBIT']
 
     def run_once(self, host, audio_test_file):
-
+        """Runs MediaBasicVerification test."""
         if host.get_board_type() in self.UNSUPPORTED_BOARD_TYPES:
             raise error.TestNAError(
                     'DUT is not supported for this scenario. Skipping test.')
@@ -58,7 +58,9 @@
             audio_test_utils.dump_cros_audio_logs(
                     host, audio_facade, self.resultsdir, 'after_binding')
 
-            audio_test_utils.check_audio_nodes(audio_facade, (['HEADPHONE'], None))
+            audio_test_utils.check_audio_nodes(
+                    audio_facade,
+                    (audio_test_utils.get_headphone_node(host), None))
 
             # Starts playing, waits for some time, and then starts recording.
             # This is to avoid artifact caused by codec initialization.