Fix bug in dockerloadformat and make sure we handle exceptions properly in the verb call
This commit is contained in:
parent
c34a8b6727
commit
d16fdde528
4 changed files with 35 additions and 7 deletions
|
@ -1232,6 +1232,18 @@ def find_or_create_derived_storage(source, transformation_name, preferred_locati
|
||||||
return new_storage
|
return new_storage
|
||||||
|
|
||||||
|
|
||||||
|
def delete_derived_storage_by_uuid(storage_uuid):
|
||||||
|
try:
|
||||||
|
image_storage = get_storage_by_uuid(storage_uuid)
|
||||||
|
derived_storage = DerivedImageStorage.get(derivative=image_storage)
|
||||||
|
except InvalidImageException:
|
||||||
|
return
|
||||||
|
except DerivedImageStorage.DoesNotExist:
|
||||||
|
return
|
||||||
|
|
||||||
|
image_storage.delete_instance(recursive=True)
|
||||||
|
|
||||||
|
|
||||||
def get_storage_by_uuid(storage_uuid):
|
def get_storage_by_uuid(storage_uuid):
|
||||||
placements = list(ImageStoragePlacement
|
placements = list(ImageStoragePlacement
|
||||||
.select(ImageStoragePlacement, ImageStorage, ImageStorageLocation)
|
.select(ImageStoragePlacement, ImageStorage, ImageStorageLocation)
|
||||||
|
|
|
@ -43,14 +43,21 @@ def _open_stream(namespace, repository, tag, synthetic_image_id, image_json, ima
|
||||||
|
|
||||||
|
|
||||||
def _write_synthetic_image_to_storage(linked_storage_uuid, linked_locations, queue_file):
|
def _write_synthetic_image_to_storage(linked_storage_uuid, linked_locations, queue_file):
|
||||||
|
database.configure(app.config)
|
||||||
|
|
||||||
|
def handle_exception(ex):
|
||||||
|
model.delete_derived_storage_by_uuid(linked_storage_uuid)
|
||||||
|
|
||||||
|
queue_file.add_exception_handler(handle_exception)
|
||||||
|
|
||||||
image_path = store.image_layer_path(linked_storage_uuid)
|
image_path = store.image_layer_path(linked_storage_uuid)
|
||||||
store.stream_write(linked_locations, image_path, queue_file)
|
store.stream_write(linked_locations, image_path, queue_file)
|
||||||
queue_file.close()
|
queue_file.close()
|
||||||
|
|
||||||
database.configure(app.config)
|
if not queue_file.raised_exception:
|
||||||
done_uploading = model.get_storage_by_uuid(linked_storage_uuid)
|
done_uploading = model.get_storage_by_uuid(linked_storage_uuid)
|
||||||
done_uploading.uploading = False
|
done_uploading.uploading = False
|
||||||
done_uploading.save()
|
done_uploading.save()
|
||||||
|
|
||||||
|
|
||||||
@verbs.route('/squash/<namespace>/<repository>/<tag>', methods=['GET'])
|
@verbs.route('/squash/<namespace>/<repository>/<tag>', methods=['GET'])
|
||||||
|
|
|
@ -26,7 +26,6 @@ def build_docker_load_stream(namespace, repository, tag, synthetic_image_id,
|
||||||
|
|
||||||
def _import_format_generator(namespace, repository, tag, synthetic_image_id,
|
def _import_format_generator(namespace, repository, tag, synthetic_image_id,
|
||||||
layer_json, get_image_iterator, get_layer_iterator):
|
layer_json, get_image_iterator, get_layer_iterator):
|
||||||
|
|
||||||
# Docker import V1 Format (.tar):
|
# Docker import V1 Format (.tar):
|
||||||
# repositories - JSON file containing a repo -> tag -> image map
|
# repositories - JSON file containing a repo -> tag -> image map
|
||||||
# {image ID folder}:
|
# {image ID folder}:
|
||||||
|
@ -114,6 +113,7 @@ def _tar_file_padding(length):
|
||||||
if length % 512 != 0:
|
if length % 512 != 0:
|
||||||
return '\0' * (512 - (length % 512))
|
return '\0' * (512 - (length % 512))
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
def _tar_file_header(name, file_size):
|
def _tar_file_header(name, file_size):
|
||||||
info = tarfile.TarInfo(name=name)
|
info = tarfile.TarInfo(name=name)
|
||||||
|
|
|
@ -12,6 +12,11 @@ class QueueFile(object):
|
||||||
self._buffer = ''
|
self._buffer = ''
|
||||||
self._total_size = 0
|
self._total_size = 0
|
||||||
self._name = name
|
self._name = name
|
||||||
|
self.raised_exception = False
|
||||||
|
self._exception_handlers = []
|
||||||
|
|
||||||
|
def add_exception_handler(self, handler):
|
||||||
|
self._exception_handlers.append(handler)
|
||||||
|
|
||||||
def read(self, size=8192):
|
def read(self, size=8192):
|
||||||
if self._closed or self._done:
|
if self._closed or self._done:
|
||||||
|
@ -25,7 +30,11 @@ class QueueFile(object):
|
||||||
|
|
||||||
if isinstance(result, Exception):
|
if isinstance(result, Exception):
|
||||||
self._closed = True
|
self._closed = True
|
||||||
raise result
|
self.raised_exception = True
|
||||||
|
for handler in self._exception_handlers:
|
||||||
|
handler(result)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
self._buffer += result
|
self._buffer += result
|
||||||
self._total_size += len(result)
|
self._total_size += len(result)
|
||||||
|
|
Reference in a new issue