Skip to content

Commit

Permalink
fix(backup lock): fix test case to follow the test purpose
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 8296

Signed-off-by: Jack Lin <[email protected]>
  • Loading branch information
ChanYiLin authored and innobead committed Mar 28, 2024
1 parent fff5fe8 commit 25b00ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
18 changes: 18 additions & 0 deletions manager/integration/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,24 @@ def wait_for_backup_completion(client, volume_name, snapshot_name=None,
return v


def wait_for_backup_failed(client, volume_name, snapshot_name=None,
retry_count=RETRY_BACKUP_COUNTS):
failed = False
for _ in range(retry_count):
v = client.by_id_volume(volume_name)
for b in v.backupStatus:
if b.state == "Error":
assert b.progress == 0
assert b.error != ""
failed = True
break
if failed:
break
time.sleep(RETRY_BACKUP_INTERVAL)
assert failed is True
return v


def wait_pod_attach_after_first_backup_completion(
client, core_api, volume_name, label_name):
completed = False
Expand Down
39 changes: 22 additions & 17 deletions manager/integration/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from common import VOLUME_RWTEST_SIZE
from common import write_pod_volume_data
from common import find_backup, find_replica_for_backup
from common import wait_for_backup_completion
from common import wait_for_backup_completion, wait_for_backup_failed
from common import create_storage_class
from common import wait_for_backup_restore_completed
from common import wait_for_volume_restoration_completed
Expand Down Expand Up @@ -3337,46 +3337,51 @@ def test_backup_lock_creation_during_deletion(set_random_backupstore, client, co
steps:
1. Create a volume, then create the corresponding PV, PVC and Pod.
2. Wait for the pod running and the volume healthy.
3. Write data (DATA_SIZE_IN_MB_2) to the pod volume and get the md5sum.
3. Write data (DATA_SIZE_IN_MB_4) to the pod volume and get the md5sum.
4. Take a backup.
5. Wait for the backup to be completed.
6. Delete the backup.
7. Create another backup of the same volume.
8. Wait for the delete backup to be completed.
8. Wait for the backup to be completed.
9. Assert there is 1 backup in the backup store.
8. The newly created backup should failed because there is a deletion lock.
9. Wait for the first backup to be Deleted
10. Create another backup of the same volume.
11. Wait for the backup to be completed.
"""
backupstore_cleanup(client)
std_volume_name = volume_name + "-std"

std_pod_name, _, _, std_md5sum1 = \
prepare_pod_with_data_in_mb(
client, core_api, csi_pv, pvc, pod_make, std_volume_name,
data_size_in_mb=DATA_SIZE_IN_MB_1)
data_size_in_mb=common.DATA_SIZE_IN_MB_4)
std_volume = client.by_id_volume(std_volume_name)

# create first snapshot and backup
snap1 = create_snapshot(client, std_volume_name)
std_volume.snapshotBackup(name=snap1.name)
wait_for_backup_completion(client, std_volume_name, snap1.name)
_, b1 = common.find_backup(client, std_volume_name, snap1.name)

write_pod_volume_random_data(core_api, std_pod_name,
"/data/test2", DATA_SIZE_IN_MB_1)
# create second snapshot
snap2 = create_snapshot(client, std_volume_name)

# delete first backup
backup_volume = client.by_id_backupVolume(std_volume_name)
backup_volume.backupDelete(name=b1.name)

snap2 = create_snapshot(client, std_volume_name)
# create second backup immediately
std_volume.snapshotBackup(name=snap2.name)
# the second backup should be failed because of the lock
wait_for_backup_failed(client, std_volume_name, snap2.name)

wait_for_backup_delete(client, volume_name, b1.name)
wait_for_backup_completion(client, std_volume_name, snap2.name)
# wait for first backup to be deleted
wait_for_backup_delete(client, std_volume_name, b1.name)

try:
_, b1 = common.find_backup(client, std_volume_name, snap1.name)
except AssertionError:
b1 = None
assert b1 is None
_, b2 = common.find_backup(client, std_volume_name, snap2.name)
# create third snapshot and do the backup
snap3 = create_snapshot(client, std_volume_name)
std_volume.snapshotBackup(name=snap3.name)
# the third backup should be completed
wait_for_backup_completion(client, std_volume_name, snap3.name)


@pytest.mark.skip(reason="This test takes more than 20 mins to run") # NOQA
Expand Down

0 comments on commit 25b00ed

Please sign in to comment.