diff options
author | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2019-05-29 16:35:57 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-06-05 14:41:48 +0000 |
commit | 216e17384575e67ee1c70209d97f666672eb31bd (patch) | |
tree | b8ca84b006e4ff8c06080fb28419ca22b9a005ec /src/buildstream/_artifactcache.py | |
parent | eda3d28249a2a21bf09bcc7340d324888ba6584d (diff) | |
download | buildstream-216e17384575e67ee1c70209d97f666672eb31bd.tar.gz |
Improve legacy artifact remote handling
This creates a new ArtifactRemote class, derived from CASRemote that
extends initialisation to check for an artifact service. This drops the
remote early rather than raising an error on method not found each time
it tries to use it.
Fixes #1025
Diffstat (limited to 'src/buildstream/_artifactcache.py')
-rw-r--r-- | src/buildstream/_artifactcache.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/buildstream/_artifactcache.py b/src/buildstream/_artifactcache.py index 91ff762c7..de17ea7ac 100644 --- a/src/buildstream/_artifactcache.py +++ b/src/buildstream/_artifactcache.py @@ -25,7 +25,7 @@ from .types import _KeyStrength from ._exceptions import ArtifactError, CASError, CASCacheError from ._protos.buildstream.v2 import artifact_pb2, artifact_pb2_grpc -from ._cas import CASRemoteSpec +from ._cas import CASRemoteSpec, CASRemote from .storage._casbaseddirectory import CasBasedDirectory from ._artifact import Artifact from . import utils @@ -43,6 +43,38 @@ class ArtifactCacheSpec(CASRemoteSpec): pass +# ArtifactRemote extends CASRemote to check during initialisation that there is +# an artifact service +class ArtifactRemote(CASRemote): + def __init__(self, *args): + super().__init__(*args) + self.artifact_service = None + + def init(self): + if not self._initialized: + # do default initialisation + super().init() + + # Add artifact stub + self.artifact_service = artifact_pb2_grpc.ArtifactServiceStub(self.channel) + + # Check whether the server supports newer proto based artifact. + try: + request = artifact_pb2.ArtifactStatusRequest() + if self.instance_name: + request.instance_name = self.instance_name + self.artifact_service.ArtifactStatus(request) + except grpc.RpcError as e: + # Check if this remote has the artifact service + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise ArtifactError( + "Configured remote does not have the BuildStream " + "ArtifactService. Please check remote configuration.") + # Else raise exception with details + raise ArtifactError( + "Remote initialisation failed: {}".format(e.details())) + + # An ArtifactCache manages artifacts. # # Args: @@ -54,6 +86,7 @@ class ArtifactCache(BaseCache): spec_name = "artifact_cache_specs" spec_error = ArtifactError config_node_name = "artifacts" + remote_class = ArtifactRemote def __init__(self, context): super().__init__(context) |