Python-SDK4: Check snapshot deletion result?

Hi, We're using ovirt-engine-sdk-python 4.1.6 on oVirt 4.1.9, currently we're trying to delete some snapshots via a script like this: sys_serv = conn.system_service() vms_service = sys_serv.vms_service() vm_service = vms_service.vm_service(vmid) snaps_service = vm_service.snapshots_service() snaps_service.service('SNAPSHOT-ID').remove() This works, mostly... however, sometimes the deletion fails: Failed to delete snapshot 'snapshot name' for VM 'vm'. Is it currently possible to know via Python-SDK that the deletion actually failed? I know I can check the state of a snapshot, but I'd like to check the result of the task. Is that possible somehow? Thanks.

On 07/11/2018 10:10 AM, nicolas@devels.es wrote:
Hi,
We're using ovirt-engine-sdk-python 4.1.6 on oVirt 4.1.9, currently we're trying to delete some snapshots via a script like this:
sys_serv = conn.system_service() vms_service = sys_serv.vms_service() vm_service = vms_service.vm_service(vmid) snaps_service = vm_service.snapshots_service() snaps_service.service('SNAPSHOT-ID').remove()
In case of failure this line should raise Error, so you should know it failed.
This works, mostly... however, sometimes the deletion fails:
Failed to delete snapshot 'snapshot name' for VM 'vm'.
Is it currently possible to know via Python-SDK that the deletion actually failed? I know I can check the state of a snapshot, but I'd like to check the result of the task. Is that possible somehow?
Thanks. _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/AFGSUUJ3RNWX6H...

Hi Ondra, El 2018-07-12 08:02, Ondra Machacek escribió:
On 07/11/2018 10:10 AM, nicolas@devels.es wrote:
Hi,
We're using ovirt-engine-sdk-python 4.1.6 on oVirt 4.1.9, currently we're trying to delete some snapshots via a script like this:
sys_serv = conn.system_service() vms_service = sys_serv.vms_service() vm_service = vms_service.vm_service(vmid) snaps_service = vm_service.snapshots_service() snaps_service.service('SNAPSHOT-ID').remove()
In case of failure this line should raise Error, so you should know it failed.
It doesn't, actually. This call is asynchronous, and the snapshot deletion seems to fail after about 10 seconds, so initially it seems to be correct but fails afterwards, that's why I need a way to check if the task ended correctly or not.
This works, mostly... however, sometimes the deletion fails:
Failed to delete snapshot 'snapshot name' for VM 'vm'.
Is it currently possible to know via Python-SDK that the deletion actually failed? I know I can check the state of a snapshot, but I'd like to check the result of the task. Is that possible somehow?
Thanks. _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/AFGSUUJ3RNWX6H...

Perhaps you can query the status of job using the correlation id (taking the examples from ovirt-system-tests): dead_snap1_params = types.Snapshot( description=SNAPSHOT_DESC_1, persist_memorystate=False, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=disk.id ) ) ] ) correlation_id = uuid.uuid4() vm1_snapshots_service.add(dead_snap1_params, query={'correlation_id': correlation_id}) testlib.assert_true_within_long( lambda: test_utils.all_jobs_finished(engine, correlation_id) ) All jobs finished checks that jobs with correlation_id have finished, it is implemented like this[2]: def all_jobs_finished(engine, correlation_id): try: jobs = engine.jobs_service().list( search='correlation_id=%s' % correlation_id ) except: jobs = engine.jobs_service().list() return all(job.status != types.JobStatus.STARTED for job in jobs) You can instead do something like this: jobs = engine.jobs_service().list( search='correlation_id=%s' % correlation_id ) return any(job.status == types.JobStatus.FAILED for job in jobs) [1] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... [2] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... On Thu, Jul 12, 2018 at 10:28 AM <nicolas@devels.es> wrote:
Hi Ondra,
El 2018-07-12 08:02, Ondra Machacek escribió:
On 07/11/2018 10:10 AM, nicolas@devels.es wrote:
Hi,
We're using ovirt-engine-sdk-python 4.1.6 on oVirt 4.1.9, currently we're trying to delete some snapshots via a script like this:
sys_serv = conn.system_service() vms_service = sys_serv.vms_service() vm_service = vms_service.vm_service(vmid) snaps_service = vm_service.snapshots_service() snaps_service.service('SNAPSHOT-ID').remove()
In case of failure this line should raise Error, so you should know it failed.
It doesn't, actually. This call is asynchronous, and the snapshot deletion seems to fail after about 10 seconds, so initially it seems to be correct but fails afterwards, that's why I need a way to check if the task ended correctly or not.
This works, mostly... however, sometimes the deletion fails:
Failed to delete snapshot 'snapshot name' for VM 'vm'.
Is it currently possible to know via Python-SDK that the deletion actually failed? I know I can check the state of a snapshot, but I'd like to check the result of the task. Is that possible somehow?
Thanks. _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives:
https://lists.ovirt.org/archives/list/users@ovirt.org/message/AFGSUUJ3RNWX6H...
Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/XFPROJO4XHL36S...

Hi Benny, El 2018-07-12 08:50, Benny Zlotnik escribió:
Perhaps you can query the status of job using the correlation id (taking the examples from ovirt-system-tests): dead_snap1_params = types.Snapshot(
description=SNAPSHOT_DESC_1, persist_memorystate=False, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=disk.id [5] ) ) ] ) correlation_id = uuid.uuid4()
vm1_snapshots_service.add(dead_snap1_params, query={'correlation_id': correlation_id})
testlib.assert_true_within_long( lambda: test_utils.all_jobs_finished(engine, correlation_id) )
I tried this approach but with the snapshot deletion task instead of creating one. customuuid = uuid4() snaps_service.service(newsnap.id).remove(query={'correlation_id': customuuid}) However, when this task is run, I see no task with this correlation_id. Moreover, I cannot find a correlation_id field in the job object. In [40]: job Out[40]: <ovirtsdk4.types.Job at 0x7f30c9312a10> In [41]: job. job.auto_cleared job.description job.external job.id job.name job.start_time job.steps job.comment job.end_time job.href job.last_updated job.owner job.status The 'id' field doesn't correspond to the correlation_id generated above.
All jobs finished checks that jobs with correlation_id have finished, it is implemented like this[2]:
def all_jobs_finished(engine, correlation_id): try: jobs = engine.jobs_service().list( search='correlation_id=%s' % correlation_id ) except: jobs = engine.jobs_service().list() return all(job.status != types.JobStatus.STARTED for job in jobs)
You can instead do something like this:
jobs = engine.jobs_service().list( search='correlation_id=%s' % correlation_id )
This won't work either, it returns an exception claiming this: TypeError: list() got an unexpected keyword argument 'search' Any further hints with this? Thanks
return any(job.status == types.JobStatus.FAILED for job in jobs)
[1] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... [6] [2] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... [7]
On Thu, Jul 12, 2018 at 10:28 AM <nicolas@devels.es> wrote:
Hi Ondra,
El 2018-07-12 08:02, Ondra Machacek escribió:
On 07/11/2018 10:10 AM, nicolas@devels.es wrote:
Hi,
We're using ovirt-engine-sdk-python 4.1.6 on oVirt 4.1.9, currently we're trying to delete some snapshots via a script like this:
sys_serv = conn.system_service() vms_service = sys_serv.vms_service() vm_service = vms_service.vm_service(vmid) snaps_service = vm_service.snapshots_service() snaps_service.service('SNAPSHOT-ID').remove()
In case of failure this line should raise Error, so you should know it failed.
It doesn't, actually. This call is asynchronous, and the snapshot deletion seems to fail after about 10 seconds, so initially it seems to be correct but fails afterwards, that's why I need a way to check if the task ended correctly or not.
This works, mostly... however, sometimes the deletion fails:
Failed to delete snapshot 'snapshot name' for VM 'vm'.
Is it currently possible to know via Python-SDK that the
deletion
actually failed? I know I can check the state of a snapshot, but I'd like to check the result of the task. Is that possible somehow?
Thanks. _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ [1] oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ [2] List Archives:
https://lists.ovirt.org/archives/list/users@ovirt.org/message/AFGSUUJ3RNWX6H...
[3] _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ [1] oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ [2] List Archives:
https://lists.ovirt.org/archives/list/users@ovirt.org/message/XFPROJO4XHL36S...
[4]
Links: ------ [1] https://www.ovirt.org/site/privacy-policy/ [2] https://www.ovirt.org/community/about/community-guidelines/ [3] https://lists.ovirt.org/archives/list/users@ovirt.org/message/AFGSUUJ3RNWX6H... [4] https://lists.ovirt.org/archives/list/users@ovirt.org/message/XFPROJO4XHL36S... [5] http://disk.id [6] https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... [7] https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t...

Ah, sorry, I missed the fact you're using 4.1, this was introduced in 4.2 [1] Regardless, correlation id will no appear in the job's fields, but it can be used to search (again, in 4.2) What you can probably do is just check the state of the system (i.e. the number of snapshots stayed the same after a period of time) You can also use the events in the audit log[2] The list of events can be found here: https://github.com/oVirt/ovirt-engine/blob/master/backend/manager/modules/co... But I haven't tried this and I'm not sure if it's reliable [1] - https://bugzilla.redhat.com/show_bug.cgi?id=1460701 [2] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... On Wed, Jul 18, 2018 at 1:39 PM <nicolas@devels.es> wrote:
Hi Benny,
El 2018-07-12 08:50, Benny Zlotnik escribió:
Perhaps you can query the status of job using the correlation id (taking the examples from ovirt-system-tests): dead_snap1_params = types.Snapshot(
description=SNAPSHOT_DESC_1, persist_memorystate=False, disk_attachments=[ types.DiskAttachment( disk=types.Disk( id=disk.id [5] ) ) ] ) correlation_id = uuid.uuid4()
vm1_snapshots_service.add(dead_snap1_params, query={'correlation_id': correlation_id})
testlib.assert_true_within_long( lambda: test_utils.all_jobs_finished(engine, correlation_id) )
I tried this approach but with the snapshot deletion task instead of creating one.
customuuid = uuid4() snaps_service.service(newsnap.id).remove(query={'correlation_id': customuuid})
However, when this task is run, I see no task with this correlation_id. Moreover, I cannot find a correlation_id field in the job object.
In [40]: job Out[40]: <ovirtsdk4.types.Job at 0x7f30c9312a10>
In [41]: job. job.auto_cleared job.description job.external job.id job.name job.start_time job.steps job.comment job.end_time job.href job.last_updated job.owner job.status
The 'id' field doesn't correspond to the correlation_id generated above.
All jobs finished checks that jobs with correlation_id have finished, it is implemented like this[2]:
def all_jobs_finished(engine, correlation_id): try: jobs = engine.jobs_service().list( search='correlation_id=%s' % correlation_id ) except: jobs = engine.jobs_service().list() return all(job.status != types.JobStatus.STARTED for job in jobs)
You can instead do something like this:
jobs = engine.jobs_service().list( search='correlation_id=%s' % correlation_id )
This won't work either, it returns an exception claiming this:
TypeError: list() got an unexpected keyword argument 'search'
Any further hints with this?
Thanks
return any(job.status == types.JobStatus.FAILED for job in jobs)
[1] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... [6] [2] - https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t... [7]
On Thu, Jul 12, 2018 at 10:28 AM <nicolas@devels.es> wrote:
Hi Ondra,
El 2018-07-12 08:02, Ondra Machacek escribió:
On 07/11/2018 10:10 AM, nicolas@devels.es wrote:
Hi,
We're using ovirt-engine-sdk-python 4.1.6 on oVirt 4.1.9, currently we're trying to delete some snapshots via a script like this:
sys_serv = conn.system_service() vms_service = sys_serv.vms_service() vm_service = vms_service.vm_service(vmid) snaps_service = vm_service.snapshots_service() snaps_service.service('SNAPSHOT-ID').remove()
In case of failure this line should raise Error, so you should know it failed.
It doesn't, actually. This call is asynchronous, and the snapshot deletion seems to fail after about 10 seconds, so initially it seems to be correct but fails afterwards, that's why I need a way to check if the task ended correctly or not.
This works, mostly... however, sometimes the deletion fails:
Failed to delete snapshot 'snapshot name' for VM 'vm'.
Is it currently possible to know via Python-SDK that the
deletion
actually failed? I know I can check the state of a snapshot, but I'd like to check the result of the task. Is that possible somehow?
Thanks. _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ [1] oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ [2] List Archives:
https://lists.ovirt.org/archives/list/users@ovirt.org/message/AFGSUUJ3RNWX6H...
[3] _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ [1] oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ [2] List Archives:
https://lists.ovirt.org/archives/list/users@ovirt.org/message/XFPROJO4XHL36S...
[4]
Links: ------ [1] https://www.ovirt.org/site/privacy-policy/ [2] https://www.ovirt.org/community/about/community-guidelines/ [3]
https://lists.ovirt.org/archives/list/users@ovirt.org/message/AFGSUUJ3RNWX6H...
[4]
https://lists.ovirt.org/archives/list/users@ovirt.org/message/XFPROJO4XHL36S...
[5] http://disk.id [6]
https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t...
[7]
https://github.com/oVirt/ovirt-system-tests/blob/master/basic-suite-master/t...
participants (3)
-
Benny Zlotnik
-
nicolas@devels.es
-
Ondra Machacek