Change in ovirt-engine-sdk[master]: Improve type checking

omachace at redhat.com omachace at redhat.com
Tue Sep 6 12:44:02 UTC 2016


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 at redhat.com>
---
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: Looks good to me, approved
  Juan Hernandez: Verified
  Jenkins CI: Passed CI tests



-- 
To view, visit https://gerrit.ovirt.org/63222
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Icb77aa4327dfff0ee0ea9bf8d2a1cf0b70c1ec90
Gerrit-PatchSet: 3
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernandez at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Juan Hernandez <juan.hernandez at redhat.com>
Gerrit-Reviewer: Ondra Machacek <omachace at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>



More information about the Engine-commits mailing list