Bug 1093755 - [BUG] can't boot vm with cloud-init data submitted as json via REST api
Summary: [BUG] can't boot vm with cloud-init data submitted as json via REST api
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: oVirt
Classification: Retired
Component: ovirt-engine-api
Version: 3.4
Hardware: x86_64
OS: Linux
unspecified
urgent
Target Milestone: ---
: 3.4.1
Assignee: Juan Hernández
QA Contact: Pavel Stehlik
URL:
Whiteboard: infra
Depends On:
Blocks: 1080483
TreeView+ depends on / blocked
 
Reported: 2014-05-02 14:48 UTC by Sven Kieske
Modified: 2014-05-08 13:37 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-05-08 13:37:33 UTC
oVirt Team: ---
Embargoed:


Attachments (Terms of Use)
jboss exception log (13.84 KB, text/plain)
2014-05-02 14:49 UTC, Sven Kieske
no flags Details
Example script to create a VM using JSON (1.59 KB, application/x-shellscript)
2014-05-05 10:35 UTC, Juan Hernández
no flags Details


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 27380 0 master MERGED restapi: Don't use inner classes in LinkBuilder Never
oVirt gerrit 27420 0 ovirt-engine-3.4 MERGED restapi: Don't use inner classes in LinkBuilder Never
oVirt gerrit 27426 0 ovirt-engine-3.4.1 MERGED restapi: Don't use inner classes in LinkBuilder Never

Description Sven Kieske 2014-05-02 14:48:14 UTC
Description of problem:
when starting a vm with cloud-init data via api (json)


Version-Release number of selected component (if applicable):
3.4.1[RC]

How reproducible:
always

Steps to Reproduce:
1. start a vm with cloud-init data via json
2.
3.

Actual results:
unhandled excepetion in jboss

Expected results:
vm starts

Additional info:
see the attached log

Comment 1 Sven Kieske 2014-05-02 14:49:02 UTC
Created attachment 891906 [details]
jboss exception log

Comment 2 Sven Kieske 2014-05-02 14:50:21 UTC
this looks like a regression. it did work in 3.3.3.
I therefore add this as a blocker for 3.4.1 release.

Comment 3 Sven Kieske 2014-05-02 14:56:13 UTC
Here is the json used to start the vm:

{"vm":{"initialization":{"cloud_init":{"host":{"address":"test"},"network_configuration":{"nics":{"nics":[{"name":"eth0","boot_protocol":"STATIC","network":{"ip":{"address":"10.211.0.236","netmask":"255.255.255.248","gateway":"10.211.0.233"}},"on_boot":true}]},"dns":{"servers":{"hosts":[{"address":"46.30.62.99"},{"address":"46.30.62.98"},{"address":"46.30.62.97"}]}}},"users":{"users":[{"name":"root","password":"#9Dh2--3xz-h95Zy"}]},"files":{"files":[{"name":"\/foo\/test","content":"test","type":"PLAINTEXT"}]}}}}}

Comment 4 Sandro Bonazzola 2014-05-05 07:12:44 UTC
Removing from 3.4.1 blockers since this has been re-targeted to 3.4.2.

Comment 5 Sandro Bonazzola 2014-05-05 07:42:01 UTC
Re-targeted to 3.4.1 and re-added to blockers for 3.4.1 since it fails Release Criteria test:
 MUST: No regressions from 3.3 Release 

Please check if this is a real regression or an error in the JSON.
If it's not a regression, please remove Regression keyword, remove this from blockers for 3.4.1 and re-tartget.
Otherwise please fix this ASAP since without this bug fixed we can't release 3.4.1.

Comment 6 Juan Hernández 2014-05-05 10:33:01 UTC
There are some issues with the JSON document that you are sending, and there is also a bug in the engine that prevents returning a proper error response.

The issues with the document are the following:

1. You shouldn't send a "vm" element. Instead of this:

  { "vm": { ... } }

Send this:

  { ... }

2. You need to specify a name, a cluster and a template (by id or name) in order to create a VM:

  {
    "name": "myvm",
    "cluster": {
      "id": "..."
    },
    "template": {
      "id": "..."
    },
    ...
  }

3. Arrays are named in singular, not in plural. In your case this applies to "nics", "hosts", "users" and "files". You are currently sending this:

  "network_configuration": {
    "nics": {
      "nics": [
        ...
      ]
    },
  }

But you should send this:

  "network_configuration": {
    "nics": {
      "nic": [
        ...
      ]
    },
  }

Note that the name of the dictionary is "nics", in plural, but the name of the array is "nic", in singular. Same for the other arrays.

If you fix this in your client then the VM should be created correctly. However, if you make any mistake, the bug will trigger and the error message will be useless.

I will attach a complete example of how to create the VM using JSON.

Comment 7 Juan Hernández 2014-05-05 10:35:01 UTC
Created attachment 892489 [details]
Example script to create a VM using JSON

Comment 8 Juan Hernández 2014-05-05 11:00:00 UTC
The proposed patch fixes the issue with the error messages. That is a regression.

Comment 9 Sven Kieske 2014-05-06 06:59:38 UTC
I can confirm that the following json works
to run-once a vm via rest, notice there are
some differences to the json submitted by juan.

I don't use this to create and start the vm
in one step, the vm is already created:

{"vm":{"initialization":{"cloud_init":{"host":{"address":"test"},"network_configuration":{"nics":{"nic":[{"name":"eth0","boot_protocol":"STATIC","network":{"ip":{"address":"10.211.0.244","netmask":"255.255.255.248","gateway":"10.211.0.241"}},"on_boot":true}]},"dns":{"servers":{"host":[{"address":"46.30.62.99"},{"address":"46.30.62.98"},{"address":"46.30.62.97"}]}}},"users":{"user":[{"name":"root","password":"#9Dh2--3xz-h95Zy"}]},"files":{"file":[{"name":"\/foo\/test","content":"test","type":"PLAINTEXT"}]}}}}}

specifically, in order to "run-once" a vm
you need the  { "vm": { ... } } element
opposing to what juan said.

I hope this is by design, and not a bug?

Comment 10 Juan Hernández 2014-05-06 08:40:57 UTC
Yes, it is by design. The operation to create a VM receives a VM entity as parameter. In XML this is represented as follows:

  <vm>
    <name>blah</name>
    ...
  </vm>

In JSON the outer "vm" element isn't needed:

  {
    "name": "blah",
    ...
  }

But the the operation to start a VM doesn't receive a VM entity as parameter, it receives an Action entity, which contains a VM, and maybe other things. In XML this is represented as follows:

  <action>
    <vm>
      <name>blah</name>
      ...
    </vm>
    ...
  </action>

As always the outer element isn't used in JSON, so the representation of the action is the following:

  {
    "vm": {
      "name": "blah",
      ...
    }
    ...
  }

Comment 11 Sandro Bonazzola 2014-05-08 13:37:33 UTC
This is an automated message

oVirt 3.4.1 has been released:
 * should fix your issue
 * should be available at your local mirror within two days.

If problems still persist, please make note of it in this bug report.


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