Skip to content

Commit

Permalink
Fix cancle backup return and remove list
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkkul committed Sep 16, 2024
1 parent 1ed127a commit d85e6bb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
28 changes: 15 additions & 13 deletions integration_v3/test_backup_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from weaviate.exceptions import (
WeaviateUnsupportedFeatureError,
UnexpectedStatusCodeException,
BackupFailedException, UnexpectedStatusCodeError,
BackupFailedException,
UnexpectedStatusCodeError,
)

BACKEND = BackupStorage.FILESYSTEM
Expand Down Expand Up @@ -452,17 +453,18 @@ def test_backup_and_restore_with_collection_and_config_1_23_x(
)


def test_list_backup(client: weaviate.WeaviateClient) -> None:
"""Create and restore backup without waiting."""
backup_id = _create_backup_id()
if client._connection._weaviate_version.is_lower_than(1, 27, 0):
pytest.skip("List backups is only supported from 1.27.0")

resp = client.backup.create(backup_id=backup_id, backend=BACKEND)
assert resp.status == BackupStatus.STARTED

backups = client.backup.list_backups(backend=BACKEND)
assert backup_id in [b.backup_id for b in backups]
# did not make it into 1.27, will come later
# def test_list_backup(client: weaviate.WeaviateClient) -> None:
# """Create and restore backup without waiting."""
# backup_id = _create_backup_id()
# if client._connection._weaviate_version.is_lower_than(1, 27, 0):
# pytest.skip("List backups is only supported from 1.27.0")
#
# resp = client.backup.create(backup_id=backup_id, backend=BACKEND)
# assert resp.status == BackupStatus.STARTED
#
# backups = client.backup.list_backups(backend=BACKEND)
# assert backup_id in [b.backup_id for b in backups]


def test_cancel_backup(client: weaviate.WeaviateClient) -> None:
Expand All @@ -476,7 +478,7 @@ def test_cancel_backup(client: weaviate.WeaviateClient) -> None:

with pytest.raises(UnexpectedStatusCodeError):
assert client.backup.cancel_backup(backup_id=backup_id, backend=BACKEND)

status_resp = client.backup.get_create_status(backup_id=backup_id, backend=BACKEND)
assert status_resp.status == BackupStatus.CANCELED
_ = client.backup.list_backups(backend=BACKEND)
Expand Down
40 changes: 22 additions & 18 deletions weaviate/backup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from requests.exceptions import ConnectionError as RequestsConnectionError

from weaviate.connect import Connection, ConnectionV4
from weaviate.connect.v4 import _ExpectedStatusCodes
from weaviate.exceptions import (
WeaviateInvalidInputError,
WeaviateUnsupportedFeatureError,
Expand Down Expand Up @@ -373,15 +374,17 @@ async def __cancel_backup(self, backup_id: str, backend: BackupStorage) -> bool:
path = f"/backups/{backend.value}/{backup_id}"

response = await self._connection.delete(
path=path, error_msg="Backup delete failed due to connection error."
path=path,
error_msg="Backup delete failed due to connection error.",
status_codes=_ExpectedStatusCodes(ok_in=[204, 404], error="delete object"),
)
typed_response = _decode_json_response_dict(response, "Backup restore status check")
if typed_response is None:
raise EmptyResponseException()

if response.status_code == 204:
return True # Successfully deleted
else:
typed_response = _decode_json_response_dict(response, "Backup restore status check")
if typed_response is None:
raise EmptyResponseException()
return False # did not exist

async def cancel_backup(self, backup_id: str, backend: BackupStorage) -> bool:
Expand Down Expand Up @@ -419,20 +422,21 @@ async def __list_backups(self, backend: BackupStorage) -> List[BackupReturn]:
raise EmptyResponseException()
return [BackupReturn(**entry) for entry in typed_response]

async def list_backups(self, backend: BackupStorage) -> List[BackupReturn]:
"""
List all backups that are currently in progress.
Parameters
----------
backend : BackupStorage
The backend storage where to create the backup.
Returns
-------
A list of `BackupStatusReturn` objects that contain the backup restore status responses.
"""
return await self.__list_backups(backend)
# did not make it into 1.27, will come later
# async def list_backups(self, backend: BackupStorage) -> List[BackupReturn]:
# """
# List all backups that are currently in progress.
#
# Parameters
# ----------
# backend : BackupStorage
# The backend storage where to create the backup.
#
# Returns
# -------
# A list of `BackupStatusReturn` objects that contain the backup restore status responses.
# """
# return await self.__list_backups(backend)


class Backup:
Expand Down

0 comments on commit d85e6bb

Please sign in to comment.