Skip to content

Commit

Permalink
proxmox_snap: fix bug in error handling on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
h3po authored and Daniel Rocholz committed Dec 16, 2024
1 parent f6dae1f commit 299e30f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions plugins/modules/proxmox_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,20 @@ def snapshot_create(self, vm, vmid, timeout, snapname, description, vmstate, unb
while timeout:
if self.api_task_ok(vm['node'], taskid):
break
if timeout == 0:
self.module.fail_json(msg='Reached timeout while waiting for creating VM snapshot. Last line in task before timeout: %s' %
self.proxmox_api.nodes(vm['node']).tasks(taskid).log.get()[:1])

time.sleep(1)
timeout -= 1

if vm['type'] == 'lxc' and unbind is True and mountpoints:
self._container_mp_restore(vm, vmid, timeout, unbind, mountpoints, vmstatus)

if timeout == 0:
self.module.fail_json(msg='Reached timeout while waiting for creating VM snapshot. Last line in task before timeout: %s' %
self.proxmox_api.nodes(vm['node']).tasks(taskid).log.get()[:1])
return False

self.snapshot_retention(vm, vmid, retention)
return timeout > 0
return True

def snapshot_remove(self, vm, vmid, timeout, snapname, force):
if self.module.check_mode:
Expand All @@ -268,12 +271,13 @@ def snapshot_remove(self, vm, vmid, timeout, snapname, force):
while timeout:
if self.api_task_ok(vm['node'], taskid):
return True
if timeout == 0:
self.module.fail_json(msg='Reached timeout while waiting for removing VM snapshot. Last line in task before timeout: %s' %
self.proxmox_api.nodes(vm['node']).tasks(taskid).log.get()[:1])

time.sleep(1)
timeout -= 1

self.module.fail_json(msg='Reached timeout while waiting for removing VM snapshot. Last line in task before timeout: %s' %
self.proxmox_api.nodes(vm['node']).tasks(taskid).log.get()[:1])

return False

def snapshot_rollback(self, vm, vmid, timeout, snapname):
Expand All @@ -284,14 +288,14 @@ def snapshot_rollback(self, vm, vmid, timeout, snapname):
while timeout:
if self.api_task_ok(vm['node'], taskid):
return True
if timeout == 0:
self.module.fail_json(msg='Reached timeout while waiting for rolling back VM snapshot. Last line in task before timeout: %s' %
self.proxmox_api.nodes(vm['node']).tasks(taskid).log.get()[:1])

time.sleep(1)
timeout -= 1
return False

self.module.fail_json(msg='Reached timeout while waiting for rolling back VM snapshot. Last line in task before timeout: %s' %
self.proxmox_api.nodes(vm['node']).tasks(taskid).log.get()[:1])

return False

def main():
module_args = proxmox_auth_argument_spec()
Expand Down

0 comments on commit 299e30f

Please sign in to comment.