Bug 1466424

Summary: Upgrading to EAP 7.0.5-3 breaks integration with CFME
Product: Red Hat Enterprise Virtualization Manager Reporter: Juan Hernández <juan.hernandez>
Component: ovirt-engineAssignee: Juan Hernández <juan.hernandez>
Status: CLOSED NOTABUG QA Contact: meital avital <mavital>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.0.7CC: bodnopoz, lsurette, masayag, oourfali, rbalakri, Rhev-m-bugs, srevivo, ykaul
Target Milestone: ---Keywords: Regression
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-07-03 12:02:16 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:
Embargoed:

Description Juan Hernández 2017-06-29 14:34:55 UTC
Description of problem:

The version of Resteasy included in EAP 7.0.5-3 does not support the 'xml' content type used by the 'ovirt' gem, which CFME uses to talk to RHV.


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

ovirt-engine-4.0.7.4-0.1.el7ev.noarch
eap7-wildfly-7.0.5-3.GA_redhat_2.1.ep7.el7.noarch
eap7-resteasy-jaxrs-3.0.19-3.SP1_redhat_1.1.ep7.el7.noarch

How reproducible:

Always.

Steps to Reproduce:

1. Send a request to create a virtual machine like the 'ovirt' gem does, using the 'xml' content type:

---8<---
url="https://.../ovirt-engine/api"
user="admin@internal"
password="..."

curl \
--verbose \
--cacert /etc/pki/ovirt-engine/ca.pem \
--user "${user}:${password}" \
--header "Version: 3" \
--header "Content-Type: xml" \
--request POST \
--data "
<vm>
  <name>myvm</name>
  <cluster>
    <name>mycluster</name>
  </cluster>
  <template>
    <name>mycluster</name>
  </template>
</vm>
" \
"${url}/vms"
--->8---

Actual results:

The server responds with a 400 HTTP error:

  HTTP/1.1 400 Bad Request

  <html><head><title>Error</title></head><body>Bad Request</body></html>

A message is written to /var/log/ovirt-engine/server.log indicating that 'xml' isn't a valid content type:

---8<---
2017-06-29 17:28:09,055 WARN  [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-31) RESTEASY002130: Failed to parse request.: java.lang.IllegalArgumentException: RESTEASY003340: Failure parsing MediaType string: xml
        at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse(MediaTypeHeaderDelegate.java:115) [resteasy-jaxrs.jar:3.0.19.SP1-redhat-1]
        at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.fromString(MediaTypeHeaderDelegate.java:20) [resteasy-jaxrs.jar:3.0.19.SP1-redhat-1]
        at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179) [jboss-jaxrs-api_2.0_spec.jar:1.0.0.Final-redhat-1]
--->8---

Expected results:

It is arguable if the server should accept the request, as 'xml' isn't really a valid content type. But the server used to accept it in previous versions, so it shouldn't reject it now.

Additional info:

The 'ovirt' gem should also be fixed to send 'application/xml' instead of just 'xml':

  https://github.com/ManageIQ/ovirt/blob/v0.17.0/lib/ovirt/service.rb#L295-L301

A workaround for the issue could be to configure the web server to replace the 'xml' with 'application/xml', something like this:

  # cat >> /etc/httpd/conf.d/fix-api-content-type.conf <<.
  <Location /ovirt-engine/api>
    RequestHeader edit ^xml$ application/xml
    RequestHeader edit ^xml$ application/xml
  </Location>

I haven't tested this workaround.

Comment 1 Juan Hernández 2017-06-29 14:35:47 UTC
The workaround should be for the 'Content-Type' and 'Accept' headers:

  RequestHeader Content-Type edit ...
  RequestHeader Accept edit ...

Comment 2 Juan Hernández 2017-07-03 08:51:19 UTC
Verified that the suggested workaround works correctly:

  # cat >> /etc/httpd/conf.d/fix-api-content-type.conf <<.
  <Location /ovirt-engine/api>
    RequestHeader edit Content-Type ^xml$ application/xml
    RequestHeader edit Accept ^xml$ application/xml
  </Location>
  .
  # systemctl restart httpd

Comment 3 Juan Hernández 2017-07-03 12:02:16 UTC
There is no change in behaviour in EAP 7, it has always rejected 'xml' as a valid content type. The change in behaviour is caused by the replacement in CFME of the 'mime-types' gem with 'mini_mime':

  Stub mini-mime in for mime-types
  https://github.com/ManageIQ/manageiq/pull/14525

The difference is that 'mime_types' doesn't convert 'xml' to 'application/xml', which is expected by 'rest-client' and also by the 'ovirt' gem:

  # Produces nil:
  require 'mini_mime'
  MiniMime.lookup_by_filename('xml')

  # Produces application/xml:
  MIME::Types.type_for('xml')[0]

This has been merged only to the CFME master branch, and not backported, so it won't affect released versions of CFME. I think that this can now be closed. We will still need to modify the 'ovirt' gem to explicitly use 'application/xml', but only for the master branch of CFME.