Add acloud test build target.

Bug: 110430047
Test: m acloud_test && acloud_test
./run_tests.sh
Change-Id: I1d18db2a4363271a1422e3516ee603547b8942e0
diff --git a/internal/lib/gcompute_client_test.py b/internal/lib/gcompute_client_test.py
index 2ce4c90..2f8aa03 100644
--- a/internal/lib/gcompute_client_test.py
+++ b/internal/lib/gcompute_client_test.py
@@ -23,8 +23,8 @@
 import mock
 
 # pylint: disable=import-error
-import apiclient.http
 from absl.testing import parameterized
+import apiclient.http
 
 from acloud.internal.lib import driver_test_lib
 from acloud.internal.lib import gcompute_client
@@ -937,7 +937,6 @@
 
         self.Patch(os.path, "exists", return_value=True)
         m = mock.mock_open(read_data=sshkey)
-        self.Patch(__builtins__, "open", m, create=True)
         self.Patch(gcompute_client.ComputeClient, "WaitOnOperation")
         self.Patch(
             gcompute_client.ComputeClient, "GetProject", return_value=project)
@@ -946,9 +945,10 @@
             return_value=resource_mock)
         resource_mock.setCommonInstanceMetadata = mock.MagicMock()
 
-        self.compute_client.AddSshRsa(fake_user, "/path/to/test_rsa.pub")
-        resource_mock.setCommonInstanceMetadata.assert_called_with(
-            project=PROJECT, body=expected)
+        with mock.patch("__builtin__.open", m):
+            self.compute_client.AddSshRsa(fake_user, "/path/to/test_rsa.pub")
+            resource_mock.setCommonInstanceMetadata.assert_called_with(
+                project=PROJECT, body=expected)
 
     def testAddSshRsaInvalidKey(self):
         """Test AddSshRsa.."""
@@ -968,13 +968,13 @@
         }
         self.Patch(os.path, "exists", return_value=True)
         m = mock.mock_open(read_data=sshkey)
-        self.Patch(__builtins__, "open", m, create=True)
         self.Patch(gcompute_client.ComputeClient, "WaitOnOperation")
         self.Patch(
             gcompute_client.ComputeClient, "GetProject", return_value=project)
-        self.assertRaisesRegexp(errors.DriverError, "rsa key is invalid:*",
-                                self.compute_client.AddSshRsa, fake_user,
-                                "/path/to/test_rsa.pub")
+        with mock.patch("__builtin__.open", m):
+            self.assertRaisesRegexp(errors.DriverError, "rsa key is invalid:*",
+                                    self.compute_client.AddSshRsa, fake_user,
+                                    "/path/to/test_rsa.pub")
 
     @mock.patch.object(gcompute_client.ComputeClient, "WaitOnOperation")
     def testDeleteDisks(self, mock_wait):
diff --git a/internal/lib/utils_test.py b/internal/lib/utils_test.py
index 02cf8aa..aad23c1 100644
--- a/internal/lib/utils_test.py
+++ b/internal/lib/utils_test.py
@@ -153,10 +153,10 @@
         self.Patch(os.path, "exists", side_effect=[False, True, True])
         self.Patch(os, "makedirs", return_value=True)
         mock_open = mock.mock_open(read_data=public_key)
-        self.Patch(__builtins__, "open", mock_open, create=True)
         self.Patch(subprocess, "check_output")
         self.Patch(os, "rename")
-        utils.CreateSshKeyPairIfNotExist(private_key, public_key)
+        with mock.patch("__builtin__.open", mock_open):
+            utils.CreateSshKeyPairIfNotExist(private_key, public_key)
         self.assertEqual(subprocess.check_output.call_count, 1)  #pylint: disable=no-member
         subprocess.check_output.assert_called_with(  #pylint: disable=no-member
             utils.SSH_KEYGEN_PUB_CMD +["-f", private_key])