finn pushed to branch finn/84-bot-errors at BuildGrid / buildgrid
Commits:
-
4011db7a
by finnball at 2018-09-20T08:18:24Z
-
84b4085c
by finnball at 2018-09-20T08:21:35Z
-
63964835
by finnball at 2018-09-20T08:29:12Z
3 changed files:
Changes:
... | ... | @@ -19,6 +19,7 @@ import tempfile |
19 | 19 |
|
20 | 20 |
from google.protobuf import any_pb2
|
21 | 21 |
|
22 |
+from buildgrid.settings import HASH_LENGTH
|
|
22 | 23 |
from buildgrid.client.cas import upload
|
23 | 24 |
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
|
24 | 25 |
from buildgrid._protos.google.bytestream import bytestream_pb2_grpc
|
... | ... | @@ -87,17 +88,35 @@ def work_buildbox(context, lease): |
87 | 88 |
|
88 | 89 |
command_line = subprocess.Popen(command_line,
|
89 | 90 |
stdin=subprocess.PIPE,
|
90 |
- stdout=subprocess.PIPE)
|
|
91 |
- # TODO: Should return the stdout and stderr to the user.
|
|
92 |
- command_line.communicate()
|
|
91 |
+ stdout=subprocess.PIPE,
|
|
92 |
+ stderr=subprocess.PIPE)
|
|
93 |
+ stdout, stderr = command_line.communicate()
|
|
94 |
+ action_result = remote_execution_pb2.ActionResult()
|
|
95 |
+ # TODO: Have a decision if to upload to CAS
|
|
96 |
+ # or output raw
|
|
97 |
+ action_result.stdout_raw = stdout
|
|
98 |
+ |
|
99 |
+ def __error(msg):
|
|
100 |
+ # TODO: Have a decision if to upload to CAS
|
|
101 |
+ # or output raw
|
|
102 |
+ logger.error("BuildBox returned an error: [{}]".format(stderr))
|
|
103 |
+ action_result.stderr_raw = msg
|
|
104 |
+ action_result_any = any_pb2.Any()
|
|
105 |
+ action_result_any.Pack(action_result)
|
|
106 |
+ lease.result.CopyFrom(action_result_any)
|
|
107 |
+ return lease
|
|
108 |
+ |
|
109 |
+ if stderr:
|
|
110 |
+ return __error(stderr)
|
|
93 | 111 |
|
94 | 112 |
output_digest = remote_execution_pb2.Digest()
|
95 | 113 |
output_digest.ParseFromString(read_file(output_digest_file.name))
|
96 | 114 |
|
97 | 115 |
logger.debug("Output root digest: {}".format(output_digest))
|
98 | 116 |
|
99 |
- if len(output_digest.hash) < 64:
|
|
100 |
- logger.warning("Buildbox command failed - no output root digest present.")
|
|
117 |
+ if len(output_digest.hash) < HASH_LENGTH:
|
|
118 |
+ msg = "Buildbox command failed - no output root digest present."
|
|
119 |
+ return __error(msg)
|
|
101 | 120 |
|
102 | 121 |
# TODO: Have BuildBox helping us creating the Tree instance here
|
103 | 122 |
# See https://gitlab.com/BuildStream/buildbox/issues/7 for details
|
... | ... | @@ -110,7 +129,6 @@ def work_buildbox(context, lease): |
110 | 129 |
output_directory.tree_digest.CopyFrom(output_tree_digest)
|
111 | 130 |
output_directory.path = os.path.relpath(working_directory, start='/')
|
112 | 131 |
|
113 |
- action_result = remote_execution_pb2.ActionResult()
|
|
114 | 132 |
action_result.output_directories.extend([output_directory])
|
115 | 133 |
|
116 | 134 |
action_result_any = any_pb2.Any()
|
... | ... | @@ -21,6 +21,7 @@ from enum import Enum |
21 | 21 |
|
22 | 22 |
from google.protobuf import any_pb2
|
23 | 23 |
|
24 |
+from buildgrid._protos.google.rpc import code_pb2, status_pb2
|
|
24 | 25 |
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
|
25 | 26 |
from buildgrid._protos.google.devtools.remoteworkers.v1test2 import bots_pb2
|
26 | 27 |
from buildgrid._protos.google.longrunning import operations_pb2
|
... | ... | @@ -121,10 +122,14 @@ class Job: |
121 | 122 |
self._operation.metadata.CopyFrom(self._pack_any(self.get_operation_meta()))
|
122 | 123 |
if self.result is not None:
|
123 | 124 |
self._operation.done = True
|
124 |
- action_result = remote_execution_pb2.ActionResult()
|
|
125 |
- self.result.Unpack(action_result)
|
|
126 |
- response = remote_execution_pb2.ExecuteResponse(result=action_result,
|
|
127 |
- cached_result=self.result_cached)
|
|
125 |
+ status = status_pb2.Status()
|
|
126 |
+ status.code = code_pb2.OK
|
|
127 |
+ if self.result.stderr_raw or self.result.stderr_digest:
|
|
128 |
+ status.code = code_pb2.INTERNAL
|
|
129 |
+ |
|
130 |
+ response = remote_execution_pb2.ExecuteResponse(result=self.result,
|
|
131 |
+ cached_result=self.result_cached,
|
|
132 |
+ status=status)
|
|
128 | 133 |
self._operation.response.CopyFrom(self._pack_any(response))
|
129 | 134 |
|
130 | 135 |
return self._operation
|
... | ... | @@ -27,6 +27,7 @@ from google.protobuf import any_pb2 |
27 | 27 |
|
28 | 28 |
|
29 | 29 |
from buildgrid.server._exceptions import NotFoundError
|
30 |
+from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
|
|
30 | 31 |
from buildgrid._protos.google.longrunning import operations_pb2
|
31 | 32 |
|
32 | 33 |
from .job import ExecuteStage, LeaseState
|
... | ... | @@ -84,10 +85,13 @@ class Scheduler: |
84 | 85 |
|
85 | 86 |
def job_complete(self, name, result):
|
86 | 87 |
job = self.jobs[name]
|
87 |
- job.result = result
|
|
88 |
- job.update_execute_stage(ExecuteStage.COMPLETED)
|
|
88 |
+ action_result = remote_execution_pb2.ActionResult()
|
|
89 |
+ result.Unpack(action_result)
|
|
90 |
+ job.result = action_result
|
|
89 | 91 |
if not job.do_not_cache and self._action_cache is not None:
|
90 |
- self._action_cache.update_action_result(job.action_digest, result)
|
|
92 |
+ if not (action_result.stderr_raw or action_result.stderr_digest):
|
|
93 |
+ self._action_cache.update_action_result(job.action_digest, result)
|
|
94 |
+ job.update_execute_stage(ExecuteStage.COMPLETED)
|
|
91 | 95 |
|
92 | 96 |
def get_operations(self):
|
93 | 97 |
response = operations_pb2.ListOperationsResponse()
|