Bug 1167851 - [ovirt-sdk] export method clash in generate DS and RestApi
Summary: [ovirt-sdk] export method clash in generate DS and RestApi
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Virtualization Manager
Classification: Red Hat
Component: ovirt-engine-sdk-python
Version: 3.5.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ovirt-3.6.0-rc
: 3.6.0
Assignee: Juan Hernández
QA Contact: Kobi Hakimi
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-11-25 14:13 UTC by Kobi Hakimi
Modified: 2016-03-09 19:56 UTC (History)
8 users (show)

Fixed In Version: ovirt-engine-sdk-python-3.6.0.0-0.1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-03-09 19:56:07 UTC
oVirt Team: Infra
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2016:0403 0 normal SHIPPED_LIVE rhevm-sdk-python bug fix and enhancement update 2016-03-10 00:04:56 UTC
oVirt gerrit 35562 0 master MERGED codegen, sdk: Rename "export" to "export_" Never

Comment 1 Kobi Hakimi 2014-11-25 14:23:59 UTC
**
Expected results:
run without the above error

Comment 2 Juan Hernández 2014-11-25 16:49:41 UTC
I'm trying to reproduce this with the following script, which is the same that the failed job was trying to do:

#!/usr/bin/env python

import ovirtsdk.api
import ovirtsdk.xml

api = ovirtsdk.api.API(
  url="https://ovirt.example.com/ovirt-engine/api",
  username="admin@internal",
  password="******",
  ca_file="/etc/pki/ovirt-engine/ca.pem",
  debug=True,
)

user = api.users.get(name="myuser")
role = api.roles.get(name="UserRole")
vm = api.vms.get(name="myvm")

permission = ovirtsdk.xml.params.Permission(
  role=role,
  vm=vm
)
user.permissions.add(permission)

api.disconnect()

This should trigger the problem, because it is trying to generate XML for a Python object that contains references to brokers classes, in particular a reference to a brokers.VM class. But in fact the __setattr__ method of the base class of all parameter methods replaces (or tries to replace) brokers with the corresponding parameter classes, so the instance of brokers.VM will be replaced with the corresponding params.VM class. The result is that I can't reproduce the problem.

I'm still reasonably convinced that the problem is the clashing "export" methods, and that should be fixed, but I can't find a way to trigger the issue.

Can you prepare a simple script where the issue reproduces?

Comment 3 Kobi Hakimi 2014-11-26 12:42:00 UTC
maybe we can see the reason why its not reproduced cause in my commit https://gerrit.eng.lab.tlv.redhat.com/#/c/13984/22/art/core_api/ovirtsdk_utils.py I use : entity.__dict__[property_name] = property_value
which skip the __setattr__ 
it make sense to you??

Comment 4 Juan Hernández 2014-11-26 12:55:05 UTC
Yes, it makes all the sense. I can now reproduce the issue with this script:

---8<---
#!/usr/bin/env python

import ovirtsdk.api
import ovirtsdk.xml

api = ovirtsdk.api.API(
  url="https://ovirt.example.com/ovirt-engine/api",
  username="admin@internal",
  password="******",
  ca_file="/etc/pki/ovirt-engine/ca.pem",
  debug=False,
)

# Find the user:
user = api.users.get(name="admin")

# Find the role:
role = api.roles.get(name="UserRole")

# Find the VM:
vm = api.vms.get(name="myvm")

# Create the permission, and use the previously retrieved
# role and virtual machine to populate it accessing directly
# the attribute dictionary (this is bad practice):
permission = ovirtsdk.xml.params.Permission()
permission.__dict__["role"] = role
permission.__dict__["vm"] = vm

# Add the permission:
user.permissions.add(permission)

api.disconnect()
--->8---

Then the result is the following exception, same that in the description of the bug:

---8<---
Traceback (most recent call last):
  File "./modify-permission.py", line 33, in <module>
    user.permissions.add(permission)
  File "/usr/lib/python2.7/site-packages/ovirtsdk/infrastructure/brokers.py", line 21140, in add
    body=ParseHelper.toXml(permission),
  File "/usr/lib/python2.7/site-packages/ovirtsdk/utils/parsehelper.py", line 53, in toXml
    entity.export(output, 0, name_=entity_tag)
  File "/usr/lib/python2.7/site-packages/ovirtsdk/xml/params.py", line 13305, in export
    self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
  File "/usr/lib/python2.7/site-packages/ovirtsdk/xml/params.py", line 13333, in exportChildren
    self.vm.export(outfile, level, namespace_, name_='vm', pretty_print=pretty_print)
TypeError: export() takes at most 3 arguments (6 given)
--->8---

After the proposed fix it works correctly. Note however that using __dict__ in this way is bad practice, and it may produce other unexpected results. Refrain from using it.

Comment 5 Kobi Hakimi 2015-07-21 13:54:11 UTC
Verified on: 
ovirt-engine-3.6.0-0.0.master.20150627185750.git6f063c1.el6.noarch

with engine: https://10.35.161.178/ovirt-engine
run Juan script(above) without any errors

Comment 9 errata-xmlrpc 2016-03-09 19:56:07 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHEA-2016-0403.html


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