| Summary: | Python-SDK: dc.set_quota_mode('whatever') works - the mode is ignored. | ||
|---|---|---|---|
| Product: | [oVirt] ovirt-engine-sdk-python | Reporter: | Yaniv Kaul <ykaul> |
| Component: | Core | Assignee: | Juan Hernández <juan.hernandez> |
| Status: | CLOSED CURRENTRELEASE | QA Contact: | movciari |
| Severity: | low | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 3.6.3.0 | CC: | bugs, sbonazzo, ykaul |
| Target Milestone: | ovirt-4.0.0-alpha | Flags: | rule-engine:
ovirt-4.0.0+
rule-engine: planning_ack+ juan.hernandez: devel_ack+ pstehlik: testing_ack+ |
| Target Release: | 4.0.0a | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | ovirt 4.0.0 alpha1 | Doc Type: | Bug Fix |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2016-08-12 14:04:56 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: | |
Are you calling dc.update() after dc.set_quota_mode()? (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). 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, ), ) |
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: