finnball pushed to branch master at BuildGrid / buildgrid
Commits:
-
fc0f7a96
by finn at 2018-07-26T13:45:02Z
4 changed files:
- app/commands/cmd_execute.py
- buildgrid/server/job.py
- tests/integration/execution_service.py
- tests/integration/operations_service.py
Changes:
... | ... | @@ -116,12 +116,10 @@ def list_operations(context): |
116 | 116 |
_log_operation(context, op)
|
117 | 117 |
|
118 | 118 |
def _log_operation(context, operation):
|
119 |
- op_any = any_pb2.Any()
|
|
120 | 119 |
op_meta = ExecuteOperationMetadata()
|
121 |
- op_any.CopyFrom(operation.metadata)
|
|
122 |
- op_any.Unpack(op_meta)
|
|
120 |
+ operation.metadata.Unpack(op_meta)
|
|
123 | 121 |
|
124 | 122 |
context.logger.info("Name : {}".format(operation.name))
|
125 | 123 |
context.logger.info("Done : {}".format(operation.done))
|
126 |
- context.logger.info("Stage : {}\n".format(ExecuteOperationMetadata.Stage.Name(op_meta.stage)))
|
|
127 |
- context.logger.info("Key : {}\n".format(operation.response))
|
|
124 |
+ context.logger.info("Stage : {}".format(ExecuteOperationMetadata.Stage.Name(op_meta.stage)))
|
|
125 |
+ context.logger.info("Key : {}".format(operation.response))
|
... | ... | @@ -66,9 +66,11 @@ class Job(): |
66 | 66 |
def get_operation(self):
|
67 | 67 |
self._operation.metadata.CopyFrom(self._pack_any(self.get_operation_meta()))
|
68 | 68 |
|
69 |
- if self.execute_stage == ExecuteStage.COMPLETED:
|
|
69 |
+ if self.result is not None:
|
|
70 | 70 |
self._operation.done = True
|
71 |
- self._operation.response.CopyFrom(self._pack_any(self.result))
|
|
71 |
+ response = ExecuteResponse()
|
|
72 |
+ self.result.Unpack(response.result)
|
|
73 |
+ self._operation.response.CopyFrom(self._pack_any(response))
|
|
72 | 74 |
|
73 | 75 |
return self._operation
|
74 | 76 |
|
... | ... | @@ -64,13 +64,7 @@ def test_execute(skip_cache_lookup, instance, context): |
64 | 64 |
context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED)
|
65 | 65 |
else:
|
66 | 66 |
metadata = remote_execution_pb2.ExecuteOperationMetadata()
|
67 |
- _unpack_any(result.metadata, metadata)
|
|
67 |
+ result.metadata.Unpack(metadata)
|
|
68 | 68 |
assert metadata.stage == job.ExecuteStage.QUEUED.value
|
69 | 69 |
assert uuid.UUID(result.name, version=4)
|
70 | 70 |
assert result.done is False
|
71 |
- |
|
72 |
-def _unpack_any(unpack_from, to):
|
|
73 |
- any = any_pb2.Any()
|
|
74 |
- any.CopyFrom(unpack_from)
|
|
75 |
- any.Unpack(to)
|
|
76 |
- return to
|
... | ... | @@ -24,9 +24,10 @@ from grpc._server import _Context |
24 | 24 |
from google.devtools.remoteexecution.v1test import remote_execution_pb2
|
25 | 25 |
from google.longrunning import operations_pb2
|
26 | 26 |
|
27 |
-from buildgrid.server import scheduler
|
|
27 |
+from buildgrid.server import scheduler, job
|
|
28 | 28 |
from buildgrid.server.execution._exceptions import InvalidArgumentError
|
29 | 29 |
from buildgrid.server.execution import execution_instance, operations_service
|
30 |
+from google.protobuf import any_pb2
|
|
30 | 31 |
|
31 | 32 |
# Can mock this
|
32 | 33 |
@pytest.fixture
|
... | ... | @@ -73,6 +74,39 @@ def test_get_operation_fail(instance, context): |
73 | 74 |
|
74 | 75 |
context.set_code.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT)
|
75 | 76 |
|
77 |
+def test_list_operations(instance, execute_request, context):
|
|
78 |
+ response_execute = instance._instance.execute(execute_request.action,
|
|
79 |
+ execute_request.skip_cache_lookup)
|
|
80 |
+ |
|
81 |
+ request = operations_pb2.ListOperationsRequest()
|
|
82 |
+ response = instance.ListOperations(request, context)
|
|
83 |
+ |
|
84 |
+ assert response.operations[0].name == response_execute.name
|
|
85 |
+ |
|
86 |
+def test_list_operations_with_result(instance, execute_request, context):
|
|
87 |
+ response_execute = instance._instance.execute(execute_request.action,
|
|
88 |
+ execute_request.skip_cache_lookup)
|
|
89 |
+ |
|
90 |
+ action_result = remote_execution_pb2.ActionResult()
|
|
91 |
+ output_file = remote_execution_pb2.OutputFile(path = 'unicorn')
|
|
92 |
+ action_result.output_files.extend([output_file])
|
|
93 |
+ instance._instance._scheduler.jobs[response_execute.name].result = _pack_any(action_result)
|
|
94 |
+ |
|
95 |
+ request = operations_pb2.ListOperationsRequest()
|
|
96 |
+ response = instance.ListOperations(request, context)
|
|
97 |
+ |
|
98 |
+ assert response.operations[0].name == response_execute.name
|
|
99 |
+ execute_response = remote_execution_pb2.ExecuteResponse()
|
|
100 |
+ response.operations[0].response.Unpack(execute_response)
|
|
101 |
+ assert execute_response.result == action_result
|
|
102 |
+ |
|
103 |
+def test_list_operations_empty(instance, context):
|
|
104 |
+ request = operations_pb2.ListOperationsRequest()
|
|
105 |
+ |
|
106 |
+ response = instance.ListOperations(request, context)
|
|
107 |
+ |
|
108 |
+ assert len(response.operations) is 0
|
|
109 |
+ |
|
76 | 110 |
# Send execution off, delete, try to find operation should fail
|
77 | 111 |
def test_delete_operation(instance, execute_request, context):
|
78 | 112 |
response_execute = instance._instance.execute(execute_request.action,
|
... | ... | @@ -97,3 +131,8 @@ def test_cancel_operation(instance, context): |
97 | 131 |
instance.CancelOperation(request, context)
|
98 | 132 |
|
99 | 133 |
context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED)
|
134 |
+ |
|
135 |
+def _pack_any(pack):
|
|
136 |
+ any = any_pb2.Any()
|
|
137 |
+ any.Pack(pack)
|
|
138 |
+ return any
|