diff options
author | Jürg Billeter <j@bitron.ch> | 2018-08-14 16:12:32 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-08-15 15:02:32 +0200 |
commit | 8b84a51a82181d4dacf9e8342f8927903f917454 (patch) | |
tree | a5a1401b73f58d11e995c389570a6c164aa40c5f | |
parent | 76f34a633e43790eab6592c5f1385f00c5ba2e83 (diff) | |
download | buildstream-8b84a51a82181d4dacf9e8342f8927903f917454.tar.gz |
_artifactcache/casserver.py: Fix resource_name format for blobs
Continue to accept requests from non-conforming BuildStream clients for
the time being to ease migration.
-rw-r--r-- | buildstream/_artifactcache/casserver.py | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/buildstream/_artifactcache/casserver.py b/buildstream/_artifactcache/casserver.py index 73e1ac67a..3cb8944ad 100644 --- a/buildstream/_artifactcache/casserver.py +++ b/buildstream/_artifactcache/casserver.py @@ -23,6 +23,7 @@ import os import signal import sys import tempfile +import uuid import click import grpc @@ -130,7 +131,7 @@ class _ByteStreamServicer(bytestream_pb2_grpc.ByteStreamServicer): def Read(self, request, context): resource_name = request.resource_name - client_digest = _digest_from_resource_name(resource_name) + client_digest = _digest_from_download_resource_name(resource_name) assert request.read_offset <= client_digest.size_bytes try: @@ -168,7 +169,7 @@ class _ByteStreamServicer(bytestream_pb2_grpc.ByteStreamServicer): if resource_name is None: # First request resource_name = request.resource_name - client_digest = _digest_from_resource_name(resource_name) + client_digest = _digest_from_upload_resource_name(resource_name) try: _clean_up_cache(self.cas, client_digest.size_bytes) except ArtifactTooLargeException as e: @@ -247,12 +248,35 @@ class _ReferenceStorageServicer(buildstream_pb2_grpc.ReferenceStorageServicer): return response -def _digest_from_resource_name(resource_name): +def _digest_from_download_resource_name(resource_name): parts = resource_name.split('/') - assert len(parts) == 2 + + # Accept requests from non-conforming BuildStream 1.1.x clients + if len(parts) == 2: + parts.insert(0, 'blobs') + + assert len(parts) == 3 and parts[0] == 'blobs' + digest = remote_execution_pb2.Digest() + digest.hash = parts[1] + digest.size_bytes = int(parts[2]) + return digest + + +def _digest_from_upload_resource_name(resource_name): + parts = resource_name.split('/') + + # Accept requests from non-conforming BuildStream 1.1.x clients + if len(parts) == 2: + parts.insert(0, 'uploads') + parts.insert(1, str(uuid.uuid4())) + parts.insert(2, 'blobs') + + assert len(parts) >= 5 and parts[0] == 'uploads' and parts[2] == 'blobs' + uuid_ = uuid.UUID(hex=parts[1]) + assert uuid_.version == 4 digest = remote_execution_pb2.Digest() - digest.hash = parts[0] - digest.size_bytes = int(parts[1]) + digest.hash = parts[3] + digest.size_bytes = int(parts[4]) return digest |