Skip to content

Commit

Permalink
Set specific backup name and check retain volume exists
Browse files Browse the repository at this point in the history
  • Loading branch information
TachunLin committed Aug 9, 2024
1 parent 1e6d8b8 commit b9ffaa1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions harvester_e2e_tests/integrations/test_4_vm_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,20 +648,20 @@ def test_connection(self, api_client, backup_config, config_backup_target):
@pytest.mark.dependency(depends=["TestBackupRestoreWithSnapshot::test_connection"], param=True)
def tests_backup_vm(self, api_client, wait_timeout, backup_config, base_vm_with_data):
unique_vm_name = base_vm_with_data['name']

unique_backup_name = f"{unique_vm_name}-backup-with-snapshot"
# Create backup with the name as VM's name
code, data = api_client.vms.backup(unique_vm_name, unique_vm_name)
code, data = api_client.vms.backup(unique_vm_name, unique_backup_name)
assert 204 == code, (code, data)
# Check backup is ready
endtime = datetime.now() + timedelta(seconds=wait_timeout)
while endtime > datetime.now():
code, backup = api_client.backups.get(unique_vm_name)
code, backup = api_client.backups.get(unique_backup_name)
if 200 == code and backup.get('status', {}).get('readyToUse'):
break
sleep(3)
else:
raise AssertionError(
f'Timed-out waiting for the backup \'{unique_vm_name}\' to be ready.'
f'Timed-out waiting for the backup \'{unique_backup_name}\' to be ready.'
)

@pytest.mark.dependency(depends=["TestBackupRestoreWithSnapshot::tests_backup_vm"], param=True)
Expand All @@ -673,6 +673,7 @@ def test_with_snapshot_restore_with_new_vm(
pub_key, pri_key = ssh_keypair

vm_snapshot_name = unique_vm_name + '-snapshot'
unique_backup_name = f"{unique_vm_name}-backup-with-snapshot"
# take vm snapshot
code, data = api_client.vm_snapshots.create(unique_vm_name, vm_snapshot_name)
assert 201 == code
Expand Down Expand Up @@ -700,9 +701,9 @@ def test_with_snapshot_restore_with_new_vm(
sh.exec_command('sync')

# Restore VM into new
restored_vm_name = f"{backup_config[0].lower()}-restore-{unique_vm_name}"
restored_vm_name = f"{backup_config[0].lower()}-restore-{unique_vm_name}-with-snapshot"
spec = api_client.backups.RestoreSpec.for_new(restored_vm_name)
code, data = api_client.backups.restore(unique_vm_name, spec)
code, data = api_client.backups.restore(unique_backup_name, spec)
assert 201 == code, (code, data)

# Check VM Started then get IPs (vm and host)
Expand Down Expand Up @@ -768,6 +769,7 @@ def test_with_snapshot_restore_replace_retain_vols(
pub_key, pri_key = ssh_keypair

vm_snapshot_name = unique_vm_name + '-snapshot-retain'
unique_backup_name = f"{unique_vm_name}-backup-with-snapshot"
# take vm snapshot
code, data = api_client.vm_snapshots.create(unique_vm_name, vm_snapshot_name)
assert 201 == code
Expand Down Expand Up @@ -802,7 +804,7 @@ def test_with_snapshot_restore_replace_retain_vols(
)

spec = api_client.backups.RestoreSpec.for_existing(delete_volumes=False)
code, data = api_client.backups.restore(unique_vm_name, spec)
code, data = api_client.backups.restore(unique_backup_name, spec)
assert 201 == code, f'Failed to restore backup with current VM replaced, {data}'

# Check VM Started then get IPs (vm and host)
Expand Down

0 comments on commit b9ffaa1

Please sign in to comment.