Coverage for /builds/BuildGrid/buildgrid/buildgrid/client/capabilities.py: 100.00%

14 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-06-11 15:37 +0000

1# Copyright (C) 2018 Bloomberg LP 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# <http://www.apache.org/licenses/LICENSE-2.0> 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15 

16import logging 

17 

18import grpc 

19 

20from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remote_execution_pb2_grpc 

21 

22LOGGER = logging.getLogger(__name__) 

23 

24 

25class CapabilitiesInterface: 

26 """Interface for calls the the Capabilities Service.""" 

27 

28 def __init__(self, channel: grpc.Channel) -> None: 

29 """Initialises an instance of the capabilities service. 

30 

31 Args: 

32 channel (grpc.Channel): A gRPC channel to the CAS endpoint. 

33 """ 

34 self.__stub = remote_execution_pb2_grpc.CapabilitiesStub(channel) 

35 

36 def get_capabilities(self, instance_name: str) -> remote_execution_pb2.ServerCapabilities: 

37 """Returns the capabilities or the server to the user. 

38 

39 Args: 

40 instance_name (str): The name of the instance.""" 

41 

42 request = remote_execution_pb2.GetCapabilitiesRequest(instance_name=instance_name) 

43 try: 

44 return self.__stub.GetCapabilities(request) 

45 

46 except grpc.RpcError as e: 

47 LOGGER.debug(e) 

48 raise ConnectionError(e.details())