Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1488729

Summary: Failed to create affinity group via REST API
Product: [oVirt] ovirt-engine Reporter: Artyom <alukiano>
Component: RestAPIAssignee: Juan Hernández <juan.hernandez>
Status: CLOSED CURRENTRELEASE QA Contact: Petr Matyáš <pmatyas>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.2.0CC: bugs, msivak, pmatyas
Target Milestone: ovirt-4.2.0Keywords: Automation, Regression
Target Release: ---Flags: rule-engine: ovirt-4.2+
rule-engine: blocker+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-12-20 10:45:19 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: SLA RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
server log none

Description Artyom 2017-09-06 06:40:37 UTC
Created attachment 1322497 [details]
server log

Description of problem:
Failed to create affinity host to VM group

Version-Release number of selected component (if applicable):
ovirt-engine-4.2.0-0.0.master.20170904111624.git842d79b.el7.centos.noarch

How reproducible:
Always

Steps to Reproduce:
1. Try to create host to VM affinity group via REST API
<affinity_group>
    <name>affinity_enforcement_01</name>
    <hosts_rule>
        <enforcing>true</enforcing>
        <positive>true</positive>
    </hosts_rule>
    <vms_rule>
        <enabled>false</enabled>
    </vms_rule>
    <hosts>
        <host id="091db1f9-7c7a-408d-9abe-3f549b4da5b9"/>
    </hosts>
    <vms>
        <vm id="06fefa09-a213-410c-ae12-149b0de90f42"/>
    </vms>
</affinity_group>
2.
3.

Actual results:
Internal Server Error
2017-09-06 09:35:21,835+03 ERROR [io.undertow.request] (default task-36) UT005023: Exception handling request to /ovirt-engine/api/v4/clusters/753d7ede-61f6-4fc3-9d8d-263d01374745/affinitygroups: java.lang.RuntimeException: org.jboss.resteasy.spi.UnhandledException: org.ovirt.api.metamodel.server.ValidationException: Parameter 'group.enforcing' is mandatory but was not provided.
        at io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:245) [undertow-servlet-1.4.18.Final.jar:1.4.18.Final]
        at io.undertow.servlet.spec.RequestDispatcherImpl.forwardImplSetup(RequestDispatcherImpl.java:147) [undertow-servlet-1.4.18.Final.jar:1.4.18.Final]
        at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:111) [undertow-servlet-1.4.18.Final.jar:1.4.18.Final]
        at org.ovirt.engine.api.restapi.invocation.VersionFilter.doFilter(VersionFilter.java:180) [restapi-jaxrs.jar:]
        at org.ovirt.engine.api.restapi.invocation.VersionFilter.doFilter(VersionFilter.java:98) [restapi-jaxrs.jar:]
        at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) [undertow-servlet-1.4.18.Final.jar:1.4.18.Final]

Expected results:
Affinity group creation succeeds

Additional info:
Via UI all works fine

Comment 1 Juan Hernández 2017-09-06 07:58:19 UTC
The reason for this is that the 'enforcing' and 'positive' attributes where deprecated in version 4.1 of the engine, but we didn't update the specification of the API correctly, so they are still marked as mandatory. In addition now the API server is more strict, and enforces the restrictions declared in the specification of the API, so it rejects the request.

This will need to be fixed in the specification of the API, with the suggested patch, then the engine will need to be updated to use the fixed version of the specification.

Comment 2 Red Hat Bugzilla Rules Engine 2017-09-06 07:59:03 UTC
This bug report has Keywords: Regression or TestBlocker.
Since no regressions or test blockers are allowed between releases, it is also being identified as a blocker for this release. Please resolve ASAP.

Comment 3 Petr Matyáš 2017-09-12 11:42:58 UTC
[root@pm-rh40 ~]# curl -v -u "admin@internal:$pass" -H "Content-type: application/xml" --insecure -X POST https://$engine/ovirt-engine/api/clusters/$cluster_id/affinitygroups -d "<affinity_group><name>affinity_enforcement_01</name><hosts_rule><enforcing>true</enforcing><positive>true</positive></hosts_rule><vms_rule><enabled>false</enabled></vms_rule><hosts><host id="7c14d704-66b0-462b-8e6d-5619736e6ce6"/></hosts><vms><vm id="54fff86b-f4b2-4a6d-acf9-70d7f17977f0"/></vms></affinity_group>"

^ this results in 400 Request syntactically incorrect and in engine log is:
Message: Open quote is expected for attribute "id" associated with an  element type  "host".
Although I can clearly see that id attribute has all the necessary quotes

Comment 5 Petr Matyáš 2017-09-12 12:34:26 UTC
Sorry, I forgot to mention I'm using ovirt-engine-4.2.0-0.0.master.20170911195522.git5ddba50.el7.centos.noarch

Comment 6 Juan Hernández 2017-09-12 12:39:54 UTC
In order to send that request using curl and the command line you need to use shell quoting carefully. Currently you are putting all the XML document between double quotes, and then there are double quotes inside the XML document itself. Try to use single quotes for the XML document:

  -d '<affinity_group>...</affinity_group>'

Or else use the back slash to escape the double quotes inside the XML document:

  -d "<affinity_group>...id=\"..."

Comment 7 Petr Matyáš 2017-09-12 13:29:00 UTC
You are right, my quotes were wrong, this request works correctly.

Comment 8 Sandro Bonazzola 2017-12-20 10:45:19 UTC
This bugzilla is included in oVirt 4.2.0 release, published on Dec 20th 2017.

Since the problem described in this bug report should be
resolved in oVirt 4.2.0 release, published on Dec 20th 2017, it has been closed with a resolution of CURRENT RELEASE.

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