Skip to content

Commit

Permalink
feat(system-backup): add system backup backingimage test
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 5085

Signed-off-by: Jack Lin <[email protected]>
  • Loading branch information
ChanYiLin authored and yangchiu committed May 2, 2024
1 parent f012eb0 commit 4c5e902
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions manager/integration/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@

BACKING_IMAGE_SOURCE_TYPE_DOWNLOAD = "download"
BACKING_IMAGE_SOURCE_TYPE_FROM_VOLUME = "export-from-volume"
BACKING_IMAGE_SOURCE_TYPE_RESTORE = "restore"

JOB_LABEL = "recurring-job.longhorn.io"

Expand Down
69 changes: 69 additions & 0 deletions manager/integration/tests/test_system_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
from common import wait_for_volume_detached
from common import wait_for_volume_healthy
from common import wait_for_volume_restoration_completed
from common import cleanup_all_backing_images
from common import create_backing_image_with_matching_url
from common import BACKING_IMAGE_NAME
from common import BACKING_IMAGE_RAW_URL
from common import BACKING_IMAGE_SOURCE_TYPE_RESTORE

from common import SETTING_BACKUPSTORE_POLL_INTERVAL

Expand Down Expand Up @@ -112,6 +117,70 @@ def test_system_backup_and_restore_volume_with_data(client, volume_name, set_ran

check_volume_data(restored_volume, data)

@pytest.mark.system_backup_restore # NOQA
def test_system_backup_and_restore_volume_with_backingimage(client, volume_name, set_random_backupstore): # NOQA
"""
Scenario: test system backup and restore volume with backingimage
Noted that for volume data integrity check, we have
"test_system_backup_and_restore_volume_with_data" to cover it.
BackingImage uses checksum to verified the data during backup/restore.
If it is inconsistent, BackingImage will be failed and so is the test.
Thus, we don't need to do data integrity check in this test.
Issue: https://github.com/longhorn/longhorn/issues/5085
Given a backingimage
And a volume created with the backingimage
When system backup created
Then system backup in state Ready
When volume deleted
And backingimage deleted
And restore system backup
Then system restore should be in state Completed
And wait for backingimage restoration to complete
And wait for volume restoration to complete
And volume should be detached
When attach volume
Then volume should be healthy
"""

host_id = get_self_host_id()

create_backing_image_with_matching_url(
client, BACKING_IMAGE_NAME, BACKING_IMAGE_RAW_URL)

volume = create_and_check_volume(
client, volume_name, backing_image=BACKING_IMAGE_NAME)
volume.attach(hostId=host_id)
volume = wait_for_volume_healthy(client, volume_name)

system_backup_name = system_backup_random_name()
client.create_system_backup(Name=system_backup_name)

system_backup_wait_for_state("Ready", system_backup_name, client)

cleanup_volume(client, volume)
cleanup_all_backing_images(client)

system_restore_name = system_restore_random_name()
client.create_system_restore(Name=system_restore_name,
SystemBackup=system_backup_name)

system_restore_wait_for_state("Completed", system_restore_name, client)

backing_image = client.by_id_backing_image(BACKING_IMAGE_NAME)
assert backing_image.sourceType == BACKING_IMAGE_SOURCE_TYPE_RESTORE

restored_volume = client.by_id_volume(volume_name)
wait_for_volume_restoration_completed(client, volume_name)
wait_for_volume_detached(client, volume_name)

restored_volume.attach(hostId=host_id)
restored_volume = wait_for_volume_healthy(client, volume_name)


@pytest.mark.system_backup_restore # NOQA
def test_system_backup_with_volume_backup_policy_if_not_present(client, volume_name, set_random_backupstore): # NOQA
Expand Down

0 comments on commit 4c5e902

Please sign in to comment.