Cherrypick cl/217729965

Turn on serial log capturing but need to refactor logcat capturing
before turning it on.

Bug: 119614469
Test: acloud create --serial_log_file ./serial.tar.gz
acloud create_cf --{build_id,build_target,branch} ... --serial_log_file ./serial.tar.gz
atest acloud_test
Change-Id: I41463a4b72b0f2f86094c0b7d14879621280baca
diff --git a/internal/lib/utils_test.py b/internal/lib/utils_test.py
index d89cd03..9225ddd 100644
--- a/internal/lib/utils_test.py
+++ b/internal/lib/utils_test.py
@@ -29,6 +29,7 @@
 
 from acloud.internal.lib import driver_test_lib
 from acloud.internal.lib import utils
+from acloud.public import errors
 
 # Tkinter may not be supported so mock it out.
 try:
@@ -337,6 +338,43 @@
         self.assertEqual(expected_value, utils.AddUserGroupsToCmd(command,
                                                                   groups))
 
+    @staticmethod
+    def testScpPullFileSuccess():
+        """Test scp pull file successfully."""
+        subprocess.check_call = mock.MagicMock()
+        utils.ScpPullFile("/tmp/test", "/tmp/test_1.log", "192.168.0.1")
+        subprocess.check_call.assert_called_with(utils.SCP_CMD + [
+            "192.168.0.1:/tmp/test", "/tmp/test_1.log"])
+
+    @staticmethod
+    def testScpPullFileWithUserNameSuccess():
+        """Test scp pull file successfully."""
+        subprocess.check_call = mock.MagicMock()
+        utils.ScpPullFile("/tmp/test", "/tmp/test_1.log", "192.168.0.1",
+                          user_name="abc")
+        subprocess.check_call.assert_called_with(utils.SCP_CMD + [
+            "abc@192.168.0.1:/tmp/test", "/tmp/test_1.log"])
+
+    # pylint: disable=invalid-name
+    @staticmethod
+    def testScpPullFileWithUserNameWithRsaKeySuccess():
+        """Test scp pull file successfully."""
+        subprocess.check_call = mock.MagicMock()
+        utils.ScpPullFile("/tmp/test", "/tmp/test_1.log", "192.168.0.1",
+                          user_name="abc", rsa_key_file="/tmp/my_key")
+        subprocess.check_call.assert_called_with(utils.SCP_CMD + [
+            "-i", "/tmp/my_key", "abc@192.168.0.1:/tmp/test",
+            "/tmp/test_1.log"])
+
+    def testScpPullFileScpFailure(self):
+        """Test scp pull file failure."""
+        subprocess.check_call = mock.MagicMock(
+            side_effect=subprocess.CalledProcessError(123, "fake",
+                                                      "fake error"))
+        self.assertRaises(
+            errors.DeviceConnectionError,
+            utils.ScpPullFile, "/tmp/test", "/tmp/test_1.log", "192.168.0.1")
+
 
 if __name__ == "__main__":
     unittest.main()