Ondra Machacek has submitted this change and it was merged.
Change subject: Improve type checking
......................................................................
Improve type checking
Currently the types of the parameters passed to service methods aren't
checked. As a result when there are errors they are detected too late,
and the error messages aren't clear. To avoid that this patch changes
the SDK so that the types of these parameters are checked inmediately,
and so that the error messages are explicit. For example, if the user
tries to start a virtual machine with wrong parameters like this:
vm_service.start(
use_cloud_init='true',
vm=types.Disk(
...
)
)
The SDK will inmediately raise a 'TypeError' exception with the
following error message:
The 'use_cloud_init' parameter should be of type 'bool',
but it is of type 'str'. The 'vm' parameter should be of
type 'Vm', but it is of type 'Disk'.
The type check is performed by the new 'Service._check_types' function. The
calls to this function are added to the beginning of each service method. For
example, for the 'VmService.start' method:
# Check the types of the parameters:
Service._check_types([
('async', async, bool),
('filter', filter, bool),
('pause', pause, bool),
('use_cloud_init', use_cloud_init, bool),
('use_sysprep', use_sysprep, bool),
('vm', vm, types.Vm),
])
Change-Id: Icb77aa4327dfff0ee0ea9bf8d2a1cf0b70c1ec90
Signed-off-by: Juan Hernandez <juan.hernandez(a)redhat.com>
(cherry picked from commit ca085e490a59eb469c54299a5e3ff0561e6a96db)
---
M generator/src/main/java/org/ovirt/sdk/python/PythonBuffer.java
M generator/src/main/java/org/ovirt/sdk/python/PythonNames.java
A generator/src/main/java/org/ovirt/sdk/python/PythonTypeReference.java
M generator/src/main/java/org/ovirt/sdk/python/ReadersGenerator.java
M generator/src/main/java/org/ovirt/sdk/python/ServicesGenerator.java
M generator/src/main/java/org/ovirt/sdk/python/TypesGenerator.java
M generator/src/main/java/org/ovirt/sdk/python/WritersGenerator.java
M sdk/lib/ovirtsdk4/service.py
A sdk/tests/test_check_types.py
9 files changed, 379 insertions(+), 88 deletions(-)
Approvals:
Ondra Machacek: Verified; Looks good to me, approved
Jenkins CI: Passed CI tests
--
To view, visit
https://gerrit.ovirt.org/63411
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icb77aa4327dfff0ee0ea9bf8d2a1cf0b70c1ec90
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: sdk_4.0
Gerrit-Owner: Ondra Machacek <omachace(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Juan Hernandez <juan.hernandez(a)redhat.com>
Gerrit-Reviewer: Ondra Machacek <omachace(a)redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>