Bug 1321571 - Python-SDK: dc.set_quota_mode('whatever') works - the mode is ignored.
Summary: Python-SDK: dc.set_quota_mode('whatever') works - the mode is ignored.
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine-sdk-python
Classification: oVirt
Component: Core
Version: 3.6.3.0
Hardware: Unspecified
OS: Unspecified
unspecified
low vote
Target Milestone: ovirt-4.0.0-alpha
: 4.0.0a
Assignee: Juan Hernández
QA Contact: movciari
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-03-28 12:34 UTC by Yaniv Kaul
Modified: 2016-08-12 14:04 UTC (History)
3 users (show)

Fixed In Version: ovirt 4.0.0 alpha1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-08-12 14:04:56 UTC
oVirt Team: Infra
rule-engine: ovirt-4.0.0+
rule-engine: planning_ack+
juan.hernandez: devel_ack+
pstehlik: testing_ack+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 55405 0 None None None 2016-03-29 12:28:50 UTC

Description Yaniv Kaul 2016-03-28 12:34:34 UTC
Description of problem:
According to Doron's testing, via REST API it works. Via the Python SDK, the value seems to be ignored.
Code:
dc = api.datacenters.get(name=DC_NAME)
dc.set_quota_mode('whatever')

(also tried 'audit' and 'SOFT_ENFORCEMENT' ...)

Version-Release number of selected component (if applicable):
ovirt-engine-sdk-python-3.6.3.0-1.fc23.noarch

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Juan Hernández 2016-03-28 12:47:25 UTC
Are you calling dc.update() after dc.set_quota_mode()?

Comment 2 Yaniv Kaul 2016-03-29 08:07:02 UTC
(In reply to Juan Hernández from comment #1)
> Are you calling dc.update() after dc.set_quota_mode()?

It gets updated when calling dc.update() - was surprised there's no validation (and that there's no implicit updated after a 'set' call).

Comment 3 Juan Hernández 2016-03-29 12:28:51 UTC
This is a good example of some of the problems that we have with the SDKs.

First is that we try to hide to the user the fact that the API isn't object oriented, but REST oriented. That fact means, for example, that when you retrieve a data center what you get is a copy of the representation of that data center. It isn't a reference to the object, and it doesn't have any "methods". Methods, like "update", are part of services, not part of entities. In the current version of the SDK this separation isn't clear, and it induces misunderstandings like this one. Version 4 of the SDK makes this separation crystal clear, and we explicitly document (in the examples) what is the recommended way to do an update:

  https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/examples/update_data_center.py#L41

The way to update used in the description of the bug is a bad practice, and it is dis-encouraged:

  https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/examples/update_data_center.py#L54

But in the current version of the SDK there is no alternative.

Second problem that this issue uncovers is that we don't have validation (or documentation) of enum values, like the quota mode. This is one of the side effects of how we use XML schema in the engine and how we parse XML in the SDK. In the XML schema enums are strings, and we parse XML in the SDK using generateDS.py. This means that we can't do validation of values. We can't change that in version 3 of the API, as it would break backwards compatibility.

In version 4 of the API enums are specified:

  https://github.com/oVirt/ovirt-engine-api-model/blob/master/src/main/java/types/QuotaModeType.java

And documented:

  http://jenkins.ovirt.org/job/ovirt-engine-api-model_master_check-patch-el7-x86_64/106/artifact/exported-artifacts/model.html#types/quota-mode-type

In addition in version 4 of the SDK the XML parsing code is generated directly from the specification of the API (not from the XML schema) so that we can and will validate values of enums:

  Use type safe enums
  https://gerrit.ovirt.org/55405

When this is eventually merged, if you try to set a quota mode that isn't valid:

  dc = dc_service.update(
    types.DataCenter(
        quota_mode='junk',
    ),
  )

You will get the following exception:

  Traceback (most recent call last):
  File ".../update_data_center.py", line 47, in <module>
    quota_mode='junk',
  File ".../types.py", line 11747, in __init__
    self.quota_mode = quota_mode
  File ".../types.py", line 11795, in quota_mode
    Struct._check_type('quota_mode', value, QuotaModeType)
  File ".../struct.py", line 64, in _check_type
    expected=expected.__name__,
TypeError: The type 'str' isn't valid for attribute 'quota_mode', it must be 'QuotaModeType'

The right way to do it is this:

  dc = dc_service.update(
    types.DataCenter(
        quota_mode=types.QuotaModeType.DISABLED,
    ),
  )


Note You need to log in before you can comment on or make changes to this bug.