diff --git a/swh/objstorage/api/client.py b/swh/objstorage/api/client.py --- a/swh/objstorage/api/client.py +++ b/swh/objstorage/api/client.py @@ -32,7 +32,7 @@ reraise_exceptions = [ObjNotFoundError, Error] backend_class = ObjStorageInterface - def restore(self, content, obj_id=None): + def restore(self, content, obj_id): return self.add(content, obj_id, check_presence=False) def add_stream(self, content_iter, obj_id, check_presence=True): diff --git a/swh/objstorage/backends/azure.py b/swh/objstorage/backends/azure.py --- a/swh/objstorage/backends/azure.py +++ b/swh/objstorage/backends/azure.py @@ -229,12 +229,8 @@ return obj_id - def restore(self, content, obj_id=None): + def restore(self, content, obj_id): """Restore a content.""" - if obj_id is None: - # Checksum is missing, compute it on the fly. - obj_id = compute_hash(content) - if obj_id in self: self.delete(obj_id) diff --git a/swh/objstorage/backends/http.py b/swh/objstorage/backends/http.py --- a/swh/objstorage/backends/http.py +++ b/swh/objstorage/backends/http.py @@ -59,7 +59,7 @@ def delete(self, obj_id): raise exc.ReadOnlyObjStorage("delete") - def restore(self, content, obj_id=None): + def restore(self, content, obj_id): raise exc.ReadOnlyObjStorage("restore") def list_content(self, last_obj_id=None, limit=DEFAULT_LIMIT): diff --git a/swh/objstorage/backends/libcloud.py b/swh/objstorage/backends/libcloud.py --- a/swh/objstorage/backends/libcloud.py +++ b/swh/objstorage/backends/libcloud.py @@ -163,7 +163,7 @@ self._put_object(content, obj_id) return obj_id - def restore(self, content, obj_id=None): + def restore(self, content, obj_id): return self.add(content, obj_id, check_presence=False) def get(self, obj_id): diff --git a/swh/objstorage/backends/seaweedfs/objstorage.py b/swh/objstorage/backends/seaweedfs/objstorage.py --- a/swh/objstorage/backends/seaweedfs/objstorage.py +++ b/swh/objstorage/backends/seaweedfs/objstorage.py @@ -89,7 +89,7 @@ self.wf.put(io.BytesIO(b"".join(compressor(content))), self._path(obj_id)) return obj_id - def restore(self, content, obj_id=None): + def restore(self, content, obj_id): return self.add(content, obj_id, check_presence=False) def get(self, obj_id): diff --git a/swh/objstorage/interface.py b/swh/objstorage/interface.py --- a/swh/objstorage/interface.py +++ b/swh/objstorage/interface.py @@ -96,7 +96,7 @@ """ ... - def restore(self, content, obj_id=None): + def restore(self, content, obj_id): """Restore a content that have been corrupted. This function is identical to add but does not check if diff --git a/swh/objstorage/multiplexer/filter/filter.py b/swh/objstorage/multiplexer/filter/filter.py --- a/swh/objstorage/multiplexer/filter/filter.py +++ b/swh/objstorage/multiplexer/filter/filter.py @@ -61,7 +61,7 @@ def add(self, content, obj_id, check_presence=True, *args, **kwargs): return self.storage.add(content, obj_id, check_presence, *args, **kwargs) - def restore(self, content, obj_id=None, *args, **kwargs): + def restore(self, content, obj_id, *args, **kwargs): return self.storage.restore(content, obj_id, *args, **kwargs) def get(self, obj_id, *args, **kwargs): diff --git a/swh/objstorage/multiplexer/filter/id_filter.py b/swh/objstorage/multiplexer/filter/id_filter.py --- a/swh/objstorage/multiplexer/filter/id_filter.py +++ b/swh/objstorage/multiplexer/filter/id_filter.py @@ -9,7 +9,6 @@ from swh.model import hashutil from swh.objstorage.exc import ObjNotFoundError from swh.objstorage.multiplexer.filter.filter import ObjStorageFilter -from swh.objstorage.objstorage import compute_hash class IdObjStorageFilter(ObjStorageFilter, metaclass=abc.ABCMeta): @@ -41,9 +40,7 @@ if self.is_valid(obj_id): return self.storage.add(content, *args, obj_id=obj_id, **kwargs) - def restore(self, content, obj_id=None, *args, **kwargs): - if obj_id is None: - obj_id = compute_hash(content) + def restore(self, content, obj_id, *args, **kwargs): if self.is_valid(obj_id): return self.storage.restore(content, *args, obj_id=obj_id, **kwargs) diff --git a/swh/objstorage/multiplexer/multiplexer_objstorage.py b/swh/objstorage/multiplexer/multiplexer_objstorage.py --- a/swh/objstorage/multiplexer/multiplexer_objstorage.py +++ b/swh/objstorage/multiplexer/multiplexer_objstorage.py @@ -275,7 +275,7 @@ "object:add:bytes": summed["object:add:bytes"] // len(results), } - def restore(self, content, obj_id=None): + def restore(self, content, obj_id): return self.wrap_call( self.get_write_threads(obj_id), "restore", diff --git a/swh/objstorage/objstorage.py b/swh/objstorage/objstorage.py --- a/swh/objstorage/objstorage.py +++ b/swh/objstorage/objstorage.py @@ -112,7 +112,7 @@ summary["object:add:bytes"] += len(content) return summary - def restore(self, content, obj_id=None): + def restore(self, content, obj_id): # check_presence to false will erase the potential previous content. return self.add(content, obj_id, check_presence=False) diff --git a/swh/objstorage/tests/test_multiplexer_filter.py b/swh/objstorage/tests/test_multiplexer_filter.py --- a/swh/objstorage/tests/test_multiplexer_filter.py +++ b/swh/objstorage/tests/test_multiplexer_filter.py @@ -291,7 +291,7 @@ self.storage.check(corrupted_id) with self.assertRaises(Error): self.storage.check(valid_id) - self.storage.restore(valid_content) + self.storage.restore(valid_content, obj_id=valid_id) self.storage.check(valid_id) diff --git a/swh/objstorage/tests/test_objstorage_http.py b/swh/objstorage/tests/test_objstorage_http.py --- a/swh/objstorage/tests/test_objstorage_http.py +++ b/swh/objstorage/tests/test_objstorage_http.py @@ -100,7 +100,7 @@ with pytest.raises(exc.ReadOnlyObjStorage): sto_front.add(content, obj_id=obj_id) with pytest.raises(exc.ReadOnlyObjStorage): - sto_front.restore(b"") + sto_front.restore(b"", obj_id=compute_hash(b"")) with pytest.raises(exc.ReadOnlyObjStorage): sto_front.delete(b"\x00" * 20)