I can refer again to what we do in the ovirt-system-tests:
testlib.assert_true_within_long(
lambda:
vm1_snapshots_service.list()[-1].snapshot_status ==
types.SnapshotStatus.OK
)
Which tests whether the status change to desirable one within a given
period of time (I think ten minutes in case of assert_true_within_long),
the assert code itself is in ovirtlago:
So instead of just asserting you can modify it to do whatever you need
On Thu, Jun 21, 2018 at 4:06 PM Gianluca Cecchi <gianluca.cecchi(a)gmail.com>
wrote:
On Thu, Jun 21, 2018 at 2:00 PM, Benny Zlotnik
<bzlotnik(a)redhat.com>
wrote:
> You could something like this (IIUC):
> dead_snap1_params = types.Snapshot(
> description=SNAPSHOT_DESC_1,
> persist_memorystate=False,
> disk_attachments=[
> types.DiskAttachment(
> disk=types.Disk(
> id=disk.id
> )
> )
> ]
> )
>
> Taken from ovirt-system-tests[1]
>
> [1] -
>
https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-maste...
>
>
>
Hi, thanks for your input!
It seems I was able to reach my target
What I've done
# Locate the service that manages the disk attachments of the virtual
# machine:
disk_attachments_service = vm_service.disk_attachments_service()
# Retrieve the list of disk attachments and then the bootable disk
disk_attachments = disk_attachments_service.list()
bootdisk = None
for disk_attachment in disk_attachments:
disk = connection.follow_link(disk_attachment.disk)
if disk_attachment.bootable == True:
bootdisk = connection.follow_link(disk_attachment.disk)
break
snaps_service = vm_service.snapshots_service()
snap = snaps_service.add(
snapshot=types.Snapshot(
description=snap_description,
persist_memorystate=False,
disk_attachments=[
types.DiskAttachment(
disk=types.Disk(
id=bootdisk.id
)
)
]
),
)
logging.info(
'Sent request to create snapshot \'%s\', the id is \'%s\'.',
snap.description, snap.id,
)
It seems also the monitor function already present in backup.py of the sdk
examples linked in my previous message is working ok,
# Poll and wait till the status of the snapshot is 'ok', which means
# that it is completely created:
snap_service = snaps_service.snapshot_service(snap.id)
while snap.snapshot_status != types.SnapshotStatus.OK:
logging.info(
'Waiting till the snapshot is created, the status is now
\'%s\'.',
snap.snapshot_status,
)
time.sleep(1)
snap = snap_service.get()
logging.info('The snapshot is now complete.')
In fact in the log file I have
INFO:root:Sent request to create snapshot
'padnpro_imp-backup-0e0c7064-bec5-429b-9ad7-cd8d1e5b25be', the id is
'4135e8cb-87e8-4f09-82f5-b9ad0ed2f5be'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:Waiting till the snapshot is created, the status is now 'locked'.
INFO:root:The snapshot is now complete.
What if I would like to emit an event if for any reason the creation of
the snapshot doesn't complete in a predefined elapsed time and manage it?
I think I have also to manage the case when for any reason no disk is
marked as bootable inside the VM I'm backing up...
Gianluca