Bug 1408839 - Importing a VM using the SDK fails
Summary: Importing a VM using the SDK fails
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine-sdk-python
Classification: oVirt
Component: Core
Version: 4.1.0a
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ovirt-4.1.0-rc
: 4.1.0
Assignee: Juan Hernández
QA Contact: Aleksei Slaikovskii
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-12-27 16:13 UTC by Benny Zlotnik
Modified: 2017-02-01 14:56 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-02-01 14:56:03 UTC
oVirt Team: Infra
Embargoed:
rule-engine: ovirt-4.1+


Attachments (Terms of Use)
logs (26.47 KB, application/zip)
2016-12-27 16:13 UTC, Benny Zlotnik
no flags Details
snippet (1.44 KB, text/plain)
2016-12-27 16:18 UTC, Benny Zlotnik
no flags Details


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 69266 0 master MERGED Fix writing 'id' attribute for enum values 2017-01-02 08:51:05 UTC
oVirt gerrit 69267 0 sdk_4.1 MERGED Fix writing 'id' attribute for enum values 2017-01-02 08:36:37 UTC
oVirt gerrit 69269 0 master MERGED Fix reading XML attributes of enum types 2017-01-03 08:46:11 UTC
oVirt gerrit 69406 0 sdk_4.1 MERGED Fix writing 'id' attribute for enum values 2017-01-02 09:02:36 UTC
oVirt gerrit 69408 0 sdk_4.1 MERGED Fix writing 'id' attribute for enum values 2017-01-02 09:42:15 UTC
oVirt gerrit 69409 0 sdk_4.0 MERGED Fix writing 'id' attribute for enum values 2017-01-02 09:09:21 UTC
oVirt gerrit 69411 0 sdk_4.0 MERGED Fix writing 'id' attribute for enum values 2017-01-03 08:41:46 UTC
oVirt gerrit 69456 0 metamodel_1.1 MERGED Fix reading XML attributes of enum types 2017-01-03 08:51:30 UTC
oVirt gerrit 69458 0 metamodel_1.0 MERGED Fix reading XML attributes of enum types 2017-01-04 11:36:59 UTC
oVirt gerrit 69598 0 master MERGED restapi: Update to model 4.2.1 and metamodel 1.2.0 2017-01-04 14:22:58 UTC
oVirt gerrit 69617 0 ovirt-engine-4.1 MERGED restapi: Update to model 4.1.26 and metamodel 1.1.10 2017-01-04 18:00:13 UTC
oVirt gerrit 69640 0 ovirt-engine-4.0 MERGED restapi: Update to model 4.0.40 and metamodel 1.0.23 2017-01-05 13:34:19 UTC
oVirt gerrit 71440 0 sdk_4.1 MERGED Update to model 4.1.29 and metamodel 1.1.10 2017-01-31 10:48:42 UTC

Description Benny Zlotnik 2016-12-27 16:13:14 UTC
Created attachment 1235529 [details]
logs

Description of problem:
When trying to import a VM from an export domain, the attached snippet[1] failes with following stacktrace:
Traceback (most recent call last):
  File "engine.py", line 38, in <module>
    cluster=import_cluster)
  File "build/bdist.linux-x86_64/egg/ovirtsdk4/services.py", line 21143, in import_
  File "build/bdist.linux-x86_64/egg/ovirtsdk4/service.py", line 118, in _check_action
  File "build/bdist.linux-x86_64/egg/ovirtsdk4/reader.py", line 283, in read
KeyError: u'html'
shell returned 1


Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. Export a VM 
2. Remove the VM
3. Attempt to import it using the attached snippet[1]

Please note that the snippet will use the first export domain returned and first VM exported to it, the snippet also attempts to import the VM to an SD named 'slow_domain'

Actual results:
Fails with the following stacktrace:
Traceback (most recent call last):
  File "engine.py", line 38, in <module>
    cluster=import_cluster)
  File "build/bdist.linux-x86_64/egg/ovirtsdk4/services.py", line 21143, in import_
  File "build/bdist.linux-x86_64/egg/ovirtsdk4/service.py", line 118, in _check_action
  File "build/bdist.linux-x86_64/egg/ovirtsdk4/reader.py", line 283, in read
KeyError: u'html'
shell returned 1

Expected results:
VM should be imported

Additional info:
[1] - the attached import_vm.py

Comment 1 Benny Zlotnik 2016-12-27 16:18:05 UTC
Created attachment 1235530 [details]
snippet

Comment 2 Ondra Machacek 2016-12-28 18:50:01 UTC
Adding relevant exceptions from log:

Server.log:

2016-12-27 16:57:30,191+02 ERROR [io.undertow.request] (default task-30) UT005023: Exception handling request to /ovirt-engine/api/v4/storagedomains/448c56e0-486d-45b8-be5d-55170c2281fd/vms/b3b6add4-c331-4e5f-a145-47609c3bd24b/import: java.lang.RuntimeException: javax.ws.rs.WebApplicationException: HTTP 500 Internal Server Error
	at io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:245) [undertow-servlet-1.4.0.Final.jar:1.4.0.Final]
...
Caused by: java.lang.NullPointerException
	at org.ovirt.engine.api.restapi.resource.validation.UsageFinder.processNodeName(UsageFinder.java:82) [restapi-jaxrs.jar:]
	at org.ovirt.engine.api.restapi.resource.validation.UsageFinder.getLinkPrefix(UsageFinder.java:77) [restapi-jaxrs.jar:]


engine.log:
2016-12-27 17:01:24,905+02 ERROR [org.ovirt.engine.api.restapi.resource.validation.IOExceptionMapper] (default task-62) [] Exception: java.io.IOException: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"id"). Expected elements are (none)
	at org.ovirt.engine.api.restapi.xml.JAXBProvider.readFrom(JAXBProvider.java:199) [restapi-jaxrs.jar:]
	at org.ovirt.engine.api.restapi.xml.JAXBProvider.readFrom(JAXBProvider.java:161) [restapi-jaxrs.jar:]
..
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"id"). Expected elements are (none)
	at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:740)

Comment 3 Juan Hernández 2016-12-28 19:18:23 UTC
Note that this can be avoided using a slightly different script. Currently this is what the script is doing:

  vm_service.import_(storage_domain=slow_domain,
                   vm=export_vm,
                   cluster=import_cluster)

The 'slow_domain', 'export_vm' and 'import_cluster' variables contain the complete representation of the storage domain, the virtual machine and the cluster. That means that the SDK will send to the server the complete representations of those objects. But the server only needs the identifier of the storage domain, the name of the virtual machine, and the identifier of the cluster. So it would be better, for performance, to send only what it is required:

  vm_service.import_(
    storage_domain=types.StorageDomain(
      id=slow_domain.id
    ),
    vm=types.Vm(
      name=export_vm.name
    ),
    cluster=types.Cluster(
      id=import_cluster.id
    )
  )

That results in a simplified request:

  POST /ovirt-engine/api/storagedomains/122/import

  <action>
    <storage_domain id="..."/>
    <cluster id="..."/>
    <vm>
      <name>myvm</name>
    </vm>
  </action>

That is 173 bytes, versus the approx 8 KiB that the current approach.

Benny already tried this alternative. It works correctly. Anyhow, the server shouldn't fail to parse that request, so this needs to be fixed anyhow.

Comment 4 Juan Hernández 2016-12-28 19:35:34 UTC
Benny, what version of the engine were you using for this test exactly? I guess it was a development environment. What git commit?

Comment 5 Benny Zlotnik 2016-12-28 19:45:43 UTC
(In reply to Juan Hernández from comment #4)
> Benny, what version of the engine were you using for this test exactly? I
> guess it was a development environment. What git commit?

I believe it was this commit: 818841777e4547a1b0a4c7771a192b843bf282df

Comment 6 Juan Hernández 2016-12-28 20:50:53 UTC
The problem is related to the representation of the 'sso' attribute of the virtual machine. The SDK sends it as follows:

  <sso>
    <methods>
      <method>
        <id>guest_agent</id>
      </method>
    </methods>
  </sso>

But the engine expects it as follows:

  <sso>
    <methods>
      <method id="guest_agent"/>
    </methods>
  </sso>

I am not sure yet if this is a problem in the SDK or in the engine, I am checking it.

Comment 7 Juan Hernández 2016-12-28 21:36:37 UTC
The bug is in the SDK, the right syntax is the one accepted by the server. I am moving the bug to the SDK product.

Comment 8 Sandro Bonazzola 2017-01-25 07:57:19 UTC
4.0.6 has been the last oVirt 4.0 release, please re-target this bug.

Comment 9 Aleksei Slaikovskii 2017-01-31 17:54:39 UTC
Verified on ovirt-engine-sdk-python (4.1.0)


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