Build API: Automatic copying of files into the chroot.

Implemented in the VM test endpoint for the vm image itself.

BUG=chromium:966903
TEST=run_tests

Change-Id: Iab179101a933373ca1bdca5b4046b8f561a538a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1639598
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Evan Hernandez <evanhernandez@chromium.org>
diff --git a/api/controller/test.py b/api/controller/test.py
index 196d818..43f4e41 100644
--- a/api/controller/test.py
+++ b/api/controller/test.py
@@ -156,15 +156,18 @@
     cros_build_lib.Die('build_target is required')
   build_target = input_proto.build_target
 
+  vm_path = input_proto.vm_path
   vm_image = input_proto.vm_image
   test_vm_image = input_proto.test_vm_image
-  if not vm_image.path and not test_vm_image.path:
-    cros_build_lib.Die('vm_image or test_vm_image is required.')
+  if not vm_image.path and not test_vm_image.path and not vm_path.path:
+    cros_build_lib.Die('A VM path must be provided.')
   if test_vm_image.path:
     if test_vm_image.type != common_pb2.TEST_VM:
       cros_build_lib.Die('Must provide a test VM image.')
     vm_image = test_vm_image
 
+  vm_image_path = vm_path.path or vm_image.path
+
   test_harness = input_proto.test_harness
   if test_harness == test_pb2.VmTestRequest.UNSPECIFIED:
     cros_build_lib.Die('test_harness is required')
@@ -174,7 +177,7 @@
     cros_build_lib.Die('vm_tests must contain at least one element')
 
   cmd = ['cros_run_test', '--debug', '--no-display', '--copy-on-write',
-         '--board', build_target.name, '--image-path', vm_image.path,
+         '--board', build_target.name, '--image-path', vm_image_path,
          '--%s' % test_pb2.VmTestRequest.TestHarness.Name(test_harness).lower()]
   cmd.extend(vm_test.pattern for vm_test in vm_tests)