Skip to content

Commit

Permalink
Add wait_status_running checker
Browse files Browse the repository at this point in the history
  • Loading branch information
albinsun authored and khushboo-rancher committed Aug 28, 2024
1 parent 5021574 commit ba771f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
12 changes: 12 additions & 0 deletions harvester_e2e_tests/fixtures/virtualmachines.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ def cb(ctx):
)
return self.wait_stopped(vm_name, endtime, cb, **kws)

def wait_status_running(self, vm_name, endtime=None, callback=default_cb, **kws):
endtime = endtime or self._endtime()
while endtime > datetime.now():
ctx = ResponseContext('vm.get', *self.vms.get(vm_name, **kws))
status = ctx.data.get('status', {}).get('printableStatus')
if 200 == ctx.code and "Running" == status and callback(ctx):
break
sleep(self.snooze)
else:
return False, ctx
return True, ctx

def wait_deleted(self, vm_name, endtime=None, callback=default_cb, **kws):
ctx = ResponseContext('vm.delete', *self.vms.delete(vm_name, **kws))
if 404 == ctx.code and callback(ctx):
Expand Down
16 changes: 5 additions & 11 deletions harvester_e2e_tests/integrations/test_4_vm_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,17 +481,11 @@ def test_restore_replace_with_delete_vols(
code, data = api_client.backups.restore(unique_vm_name, spec)
assert 201 == code, f'Failed to restore backup with current VM replaced, {data}'

endtime = datetime.now() + timedelta(seconds=wait_timeout)
while endtime > datetime.now():
code, data = api_client.vms.get(unique_vm_name)
if 200 == code and "Running" == data.get('status', {}).get('printableStatus'):
break
sleep(3)
else:
raise AssertionError(
f"Failed to restore VM({unique_vm_name}) with errors:\n"
f"Status({code}): {data}"
)
vm_running, (code, data) = vm_checker.wait_status_running(unique_vm_name)
assert vm_running, (
f"Failed to restore VM({unique_vm_name}) with errors:\n"
f"Status({code}): {data}"
)

# Check VM Started then get IPs (vm and host)
vm_got_ips, (code, data) = vm_checker.wait_ip_addresses(unique_vm_name, ['default'])
Expand Down

0 comments on commit ba771f7

Please sign in to comment.