[Notes] [Git][BuildGrid/buildgrid][finn/74-operation-cancelation] 2 commits: Added cancel command to app.



Title: GitLab

finn pushed to branch finn/74-operation-cancelation at BuildGrid / buildgrid

Commits:

2 changed files:

Changes:

  • buildgrid/_app/commands/cmd_operation.py
    ... ... @@ -153,6 +153,18 @@ def status(context, operation_name, json):
    153 153
             click.echo(json_format.MessageToJson(operation))
    
    154 154
     
    
    155 155
     
    
    156
    +@cli.command('cancel', short_help="Cancel an operation.")
    
    157
    +@click.argument('operation-name', nargs=1, type=click.STRING, required=True)
    
    158
    +@pass_context
    
    159
    +def cancel(context, operation_name):
    
    160
    +    click.echo("Cancelling an operation...")
    
    161
    +    stub = operations_pb2_grpc.OperationsStub(context.channel)
    
    162
    +    request = operations_pb2.CancelOperationRequest(name=operation_name)
    
    163
    +
    
    164
    +    stub.CancelOperation(request)
    
    165
    +    click.echo("Operation cancelled: [{}]".format(request))
    
    166
    +
    
    167
    +
    
    156 168
     @cli.command('list', short_help="List operations.")
    
    157 169
     @click.option('--json', is_flag=True, show_default=True,
    
    158 170
                   help="Print operations list in JSON format.")
    

  • tests/integration/operations_service.py
    ... ... @@ -24,6 +24,7 @@ import grpc
    24 24
     from grpc._server import _Context
    
    25 25
     import pytest
    
    26 26
     
    
    27
    +from buildgrid._enums import OperationStage
    
    27 28
     from buildgrid._exceptions import InvalidArgumentError
    
    28 29
     from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
    
    29 30
     from buildgrid._protos.google.longrunning import operations_pb2
    
    ... ... @@ -236,12 +237,24 @@ def test_delete_operation_fail(instance, context):
    236 237
         context.set_code.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT)
    
    237 238
     
    
    238 239
     
    
    239
    -def test_cancel_operation(instance, context):
    
    240
    +def test_cancel_operation(instance, controller, execute_request, context):
    
    241
    +    response_execute = controller.execution_instance.execute(execute_request.action_digest,
    
    242
    +                                                             execute_request.skip_cache_lookup)
    
    243
    +
    
    240 244
         request = operations_pb2.CancelOperationRequest()
    
    241
    -    request.name = "{}/{}".format(instance_name, "runner")
    
    245
    +    request.name = "{}/{}".format(instance_name, response_execute.name)
    
    246
    +
    
    242 247
         instance.CancelOperation(request, context)
    
    243 248
     
    
    244
    -    context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED)
    
    249
    +    request = operations_pb2.ListOperationsRequest(name=instance_name)
    
    250
    +    response = instance.ListOperations(request, context)
    
    251
    +
    
    252
    +    assert len(response.operations) is 1
    
    253
    +
    
    254
    +    for operation in response.operations:
    
    255
    +        operation_metadata = remote_execution_pb2.ExecuteOperationMetadata()
    
    256
    +        operation.metadata.Unpack(operation_metadata)
    
    257
    +        assert operation_metadata.stage == OperationStage.COMPLETED.value
    
    245 258
     
    
    246 259
     
    
    247 260
     def test_cancel_operation_blank(blank_instance, context):
    
    ... ... @@ -249,7 +262,7 @@ def test_cancel_operation_blank(blank_instance, context):
    249 262
         request.name = "runner"
    
    250 263
         blank_instance.CancelOperation(request, context)
    
    251 264
     
    
    252
    -    context.set_code.assert_called_once_with(grpc.StatusCode.UNIMPLEMENTED)
    
    265
    +    context.set_code.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT)
    
    253 266
     
    
    254 267
     
    
    255 268
     def test_cancel_operation_instance_fail(instance, context):
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]