diff options
author | Jürg Billeter <j@bitron.ch> | 2019-09-19 12:15:51 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2019-09-19 14:20:21 +0200 |
commit | 9453a0144fd6225fbc9f970ba7d68aa233bebb66 (patch) | |
tree | 94bfb4b406e5732686ee6cb63ee73cdd3173b127 | |
parent | e555cc249ee295d23e8093422db5f8ba2214d23b (diff) | |
download | buildstream-9453a0144fd6225fbc9f970ba7d68aa233bebb66.tar.gz |
_sourcecache.py: Move capabilities check to _check() and extend it
It's sufficient to check the capabilities once per bst session. This
avoids the extra round trip in remote.init().
This also adds a check for allow_updates for push remotes.
-rw-r--r-- | src/buildstream/_sourcecache.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/buildstream/_sourcecache.py b/src/buildstream/_sourcecache.py index 76a2e4f39..03ba9a74c 100644 --- a/src/buildstream/_sourcecache.py +++ b/src/buildstream/_sourcecache.py @@ -36,30 +36,42 @@ class SourceRemote(BaseRemote): self.source_service = None def _configure_protocols(self): + # set up source service + self.source_service = source_pb2_grpc.SourceServiceStub(self.channel) + + # _check(): + # + # Check if this remote provides everything required for the + # particular kind of remote. This is expected to be called as part + # of check(), and must be called in a non-main process. + # + # Returns: + # (str|None): An error message, or None if no error message. + # + def _check(self): capabilities_service = buildstream_pb2_grpc.CapabilitiesStub(self.channel) + # check that the service supports sources try: request = buildstream_pb2.GetCapabilitiesRequest() if self.instance_name: request.instance_name = self.instance_name - response = capabilities_service.GetCapabilities(request) except grpc.RpcError as e: # Check if this remote has the artifact service if e.code() == grpc.StatusCode.UNIMPLEMENTED: - raise SourceCacheError( - "Configured remote does not have the BuildStream " - "capabilities service. Please check remote configuration.") + return ("Configured remote does not have the BuildStream " + "capabilities service. Please check remote configuration.") # Else raise exception with details - raise SourceCacheError( - "Remote initialisation failed: {}".format(e.details())) + return "Remote initialisation failed: {}".format(e.details()) if not response.source_capabilities: - raise SourceCacheError( - "Configured remote does not support source service") + return "Configured remote does not support source service" - # set up source service - self.source_service = source_pb2_grpc.SourceServiceStub(self.channel) + if self.spec.push and not response.source_capabilities.allow_updates: + return 'Source server does not allow push' + + return None # get_source(): # |