Chameleon: Support an usage of only testing the first connected video port

This change adds a new usage of only testing the first connected video
port and ensuring it being plugged.

It is used via a with statement, like the following:
    finder = ChameleonVideoInputFinder(chameleon_board, display_facade)
    with finder.use_first_port() as chameleon_port:
        # chameleon_port is automatically plugged before this line.
        do_some_test_on(chameleon_port)
        # chameleon_port is automatically unplugged after this line.

BUG=b:28885370
TEST=Pending

Change-Id: I657a4f9d9d204535b2c7690177101064205e243a
Reviewed-on: https://chromium-review.googlesource.com/348871
Commit-Ready: Tom Tam <waihong@google.com>
Tested-by: Tom Tam <waihong@google.com>
Reviewed-by: Tom Tam <waihong@google.com>
diff --git a/client/cros/chameleon/chameleon_port_finder.py b/client/cros/chameleon/chameleon_port_finder.py
index ec38f7f..703bc3c 100755
--- a/client/cros/chameleon/chameleon_port_finder.py
+++ b/client/cros/chameleon/chameleon_port_finder.py
@@ -5,6 +5,7 @@
 import logging
 import time
 from collections import namedtuple
+from contextlib import contextmanager
 
 from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import error
@@ -236,6 +237,30 @@
         return self._yield_all_ports(raise_error=True)
 
 
+    @contextmanager
+    def use_first_port(self):
+        """
+        Use the first connected video port and ensures it plugged.
+
+        It is used via a with statement, like the following:
+
+            finder = ChameleonVideoInputFinder(chameleon_board, display_facade)
+            with finder.use_first_port() as chameleon_port:
+                # chameleon_port is automatically plugged before this line.
+                do_some_test_on(chameleon_port)
+                # chameleon_port is automatically unplugged after this line.
+
+        @yields the first connected ChameleonVideoInput which is ensured plugged
+                before yeilding.
+
+        @raises TestFail if no connected video port.
+
+        """
+        for port in self._yield_all_ports(raise_error=True):
+            yield port
+            break
+
+
     def find_all_ports(self):
         """
         @returns a named tuple ChameleonPorts() containing a list of connected