Loading app/commands/cmd_execute.py +3 −5 Original line number Diff line number Diff line Loading @@ -116,12 +116,10 @@ def list_operations(context): _log_operation(context, op) def _log_operation(context, operation): op_any = any_pb2.Any() op_meta = ExecuteOperationMetadata() op_any.CopyFrom(operation.metadata) op_any.Unpack(op_meta) operation.metadata.Unpack(op_meta) context.logger.info("Name : {}".format(operation.name)) context.logger.info("Done : {}".format(operation.done)) context.logger.info("Stage : {}\n".format(ExecuteOperationMetadata.Stage.Name(op_meta.stage))) context.logger.info("Key : {}\n".format(operation.response)) context.logger.info("Stage : {}".format(ExecuteOperationMetadata.Stage.Name(op_meta.stage))) context.logger.info("Key : {}".format(operation.response)) buildgrid/server/job.py +4 −2 Original line number Diff line number Diff line Loading @@ -66,9 +66,11 @@ class Job(): def get_operation(self): self._operation.metadata.CopyFrom(self._pack_any(self.get_operation_meta())) if self.execute_stage == ExecuteStage.COMPLETED: if self.result is not None: self._operation.done = True self._operation.response.CopyFrom(self._pack_any(self.result)) response = ExecuteResponse() self.result.Unpack(response.result) self._operation.response.CopyFrom(self._pack_any(response)) return self._operation Loading tests/integration/execution_service.py +1 −7 Original line number Diff line number Diff line Loading @@ -64,13 +64,7 @@ def test_execute(skip_cache_lookup, instance, context): context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED) else: metadata = remote_execution_pb2.ExecuteOperationMetadata() _unpack_any(result.metadata, metadata) result.metadata.Unpack(metadata) assert metadata.stage == job.ExecuteStage.QUEUED.value assert uuid.UUID(result.name, version=4) assert result.done is False def _unpack_any(unpack_from, to): any = any_pb2.Any() any.CopyFrom(unpack_from) any.Unpack(to) return to tests/integration/operations_service.py +40 −1 Original line number Diff line number Diff line Loading @@ -24,9 +24,10 @@ from grpc._server import _Context from google.devtools.remoteexecution.v1test import remote_execution_pb2 from google.longrunning import operations_pb2 from buildgrid.server import scheduler from buildgrid.server import scheduler, job from buildgrid.server.execution._exceptions import InvalidArgumentError from buildgrid.server.execution import execution_instance, operations_service from google.protobuf import any_pb2 # Can mock this @pytest.fixture Loading Loading @@ -73,6 +74,39 @@ def test_get_operation_fail(instance, context): context.set_code.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT) def test_list_operations(instance, execute_request, context): response_execute = instance._instance.execute(execute_request.action, execute_request.skip_cache_lookup) request = operations_pb2.ListOperationsRequest() response = instance.ListOperations(request, context) assert response.operations[0].name == response_execute.name def test_list_operations_with_result(instance, execute_request, context): response_execute = instance._instance.execute(execute_request.action, execute_request.skip_cache_lookup) action_result = remote_execution_pb2.ActionResult() output_file = remote_execution_pb2.OutputFile(path = 'unicorn') action_result.output_files.extend([output_file]) instance._instance._scheduler.jobs[response_execute.name].result = _pack_any(action_result) request = operations_pb2.ListOperationsRequest() response = instance.ListOperations(request, context) assert response.operations[0].name == response_execute.name execute_response = remote_execution_pb2.ExecuteResponse() response.operations[0].response.Unpack(execute_response) assert execute_response.result == action_result def test_list_operations_empty(instance, context): request = operations_pb2.ListOperationsRequest() response = instance.ListOperations(request, context) assert len(response.operations) is 0 # Send execution off, delete, try to find operation should fail def test_delete_operation(instance, execute_request, context): response_execute = instance._instance.execute(execute_request.action, Loading @@ -97,3 +131,8 @@ def test_cancel_operation(instance, context): instance.CancelOperation(request, context) context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED) def _pack_any(pack): any = any_pb2.Any() any.Pack(pack) return any Loading
app/commands/cmd_execute.py +3 −5 Original line number Diff line number Diff line Loading @@ -116,12 +116,10 @@ def list_operations(context): _log_operation(context, op) def _log_operation(context, operation): op_any = any_pb2.Any() op_meta = ExecuteOperationMetadata() op_any.CopyFrom(operation.metadata) op_any.Unpack(op_meta) operation.metadata.Unpack(op_meta) context.logger.info("Name : {}".format(operation.name)) context.logger.info("Done : {}".format(operation.done)) context.logger.info("Stage : {}\n".format(ExecuteOperationMetadata.Stage.Name(op_meta.stage))) context.logger.info("Key : {}\n".format(operation.response)) context.logger.info("Stage : {}".format(ExecuteOperationMetadata.Stage.Name(op_meta.stage))) context.logger.info("Key : {}".format(operation.response))
buildgrid/server/job.py +4 −2 Original line number Diff line number Diff line Loading @@ -66,9 +66,11 @@ class Job(): def get_operation(self): self._operation.metadata.CopyFrom(self._pack_any(self.get_operation_meta())) if self.execute_stage == ExecuteStage.COMPLETED: if self.result is not None: self._operation.done = True self._operation.response.CopyFrom(self._pack_any(self.result)) response = ExecuteResponse() self.result.Unpack(response.result) self._operation.response.CopyFrom(self._pack_any(response)) return self._operation Loading
tests/integration/execution_service.py +1 −7 Original line number Diff line number Diff line Loading @@ -64,13 +64,7 @@ def test_execute(skip_cache_lookup, instance, context): context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED) else: metadata = remote_execution_pb2.ExecuteOperationMetadata() _unpack_any(result.metadata, metadata) result.metadata.Unpack(metadata) assert metadata.stage == job.ExecuteStage.QUEUED.value assert uuid.UUID(result.name, version=4) assert result.done is False def _unpack_any(unpack_from, to): any = any_pb2.Any() any.CopyFrom(unpack_from) any.Unpack(to) return to
tests/integration/operations_service.py +40 −1 Original line number Diff line number Diff line Loading @@ -24,9 +24,10 @@ from grpc._server import _Context from google.devtools.remoteexecution.v1test import remote_execution_pb2 from google.longrunning import operations_pb2 from buildgrid.server import scheduler from buildgrid.server import scheduler, job from buildgrid.server.execution._exceptions import InvalidArgumentError from buildgrid.server.execution import execution_instance, operations_service from google.protobuf import any_pb2 # Can mock this @pytest.fixture Loading Loading @@ -73,6 +74,39 @@ def test_get_operation_fail(instance, context): context.set_code.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT) def test_list_operations(instance, execute_request, context): response_execute = instance._instance.execute(execute_request.action, execute_request.skip_cache_lookup) request = operations_pb2.ListOperationsRequest() response = instance.ListOperations(request, context) assert response.operations[0].name == response_execute.name def test_list_operations_with_result(instance, execute_request, context): response_execute = instance._instance.execute(execute_request.action, execute_request.skip_cache_lookup) action_result = remote_execution_pb2.ActionResult() output_file = remote_execution_pb2.OutputFile(path = 'unicorn') action_result.output_files.extend([output_file]) instance._instance._scheduler.jobs[response_execute.name].result = _pack_any(action_result) request = operations_pb2.ListOperationsRequest() response = instance.ListOperations(request, context) assert response.operations[0].name == response_execute.name execute_response = remote_execution_pb2.ExecuteResponse() response.operations[0].response.Unpack(execute_response) assert execute_response.result == action_result def test_list_operations_empty(instance, context): request = operations_pb2.ListOperationsRequest() response = instance.ListOperations(request, context) assert len(response.operations) is 0 # Send execution off, delete, try to find operation should fail def test_delete_operation(instance, execute_request, context): response_execute = instance._instance.execute(execute_request.action, Loading @@ -97,3 +131,8 @@ def test_cancel_operation(instance, context): instance.CancelOperation(request, context) context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED) def _pack_any(pack): any = any_pb2.Any() any.Pack(pack) return any