Bug 1450986

Summary: [RFE] Could the ovirtsdk4.Error improved ?
Product: [oVirt] ovirt-engine-sdk-python Reporter: Fabrice Bacchella <fabrice.bacchella>
Component: RFEsAssignee: Ondra Machacek <omachace>
Status: CLOSED CURRENTRELEASE QA Contact: Petr Kubica <pkubica>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.1.3CC: bugs, juan.hernandez, lsvaty, mgoldboi, mperina, oourfali, stirabos
Target Milestone: ovirt-4.1.3Keywords: FutureFeature
Target Release: 4.1.4Flags: rule-engine: ovirt-4.1+
lsvaty: testing_plan_complete-
mgoldboi: planning_ack+
mperina: devel_ack+
lsvaty: testing_ack+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-ovirt-engine-sdk4-4.1.4 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-07-06 13:19:09 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Fabrice Bacchella 2017-05-15 13:57:32 UTC
The ovirtsdk4.Error is a basic wrapping around an generic python exception. I did try introspection of it's content and sees nothing else than a raw string argument. For example:
args ('Fault reason is "Operation Failed". Fault detail is "[Cannot switch the following Hosts to Maintenance mode: XXX.\nOne or more running VMs are indicated as non-migratable. The non-migratable VMs are: XXX , XXX.]". HTTP response code is 409.',)

As I used the sdk in a bigger application I would like to have in this case 3 variables:
The fault reasons: "Operation Failed"
The fault detail: "[Cannot switch the following Hosts to Maintenance mode: XXX.\nOne or more running VMs are indicated as non-migratable. The non-migratable VMs are: XXX , XXX.]"
The error code : 409.

That should be easy, they are all part of the returned message:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<action>
    <async>true</async>
    <fault>
        <detail>[Cannot switch the following Hosts to Maintenance mode: XXX.
One or more running VMs are indicated as non-migratable. The non-migratable VMs are: XXX , XXX.]</detail>
        <reason>Operation Failed</reason>
    </fault>
    <reason>For upgrade</reason>
    <status>failed</status>
</action>

I can then build a custom message with the details I need. For example, I don't think the HTTP response code is generally useful, unless in debug mode.

What do you think of that ?

Comment 1 Fabrice Bacchella 2017-05-15 14:30:40 UTC
Another use case where a smart exception would be useful:

ovirtsdk4.Error: Error during SSO revoke server_error : UT000021: Session already invalidated

I can catch this exception and transform it as a warning or a notice if details can be used, instead of having to use a brittle regex.

Comment 2 Juan Hernández 2017-05-16 08:02:12 UTC
Yes, that can be useful. I'd suggest to add two properties: 'code' and 'fault'. The first should be an integer containing the HTTP response code. The second should be an instance of the 'Fault' type, containing the detail and reason. Both should be optional, as certain errors won't have an HTTP error code or a fault (timeout, for example).

Comment 3 Petr Kubica 2017-06-07 11:11:55 UTC
Verified in python-ovirt-engine-sdk4-4.1.4-1.el7ev.x86_64