"heat stack-create" is getting failed with HTTP error code 415 due to missing HTTP header

Bug #1638451 reported by adithya
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
python-heatclient
New
Undecided
Unassigned

Bug Description

The latest openstack heat client (1.5.0) has a bug which will not allow the user to create the stack. After examining the source code of it, it is basically creating a HTTP POST request but with a missing HTTP header.
I have added it to the source code of heat client and verified that heat create is working fine.

Issue:

"Content-Type: application/json" header is missing in the curl request header and results in HTTP 415 response code.

$ heat --debug stack-create networks -f network_create.yml
DEBUG (connectionpool) "POST /v1/f8672940d897401dae2e174e9dbcd62d/stacks HTTP/1.1" 415 0
DEBUG (session) RESP: [415] Date: Wed, 02 Nov 2016 02:06:45 GMT Via: 1.1 Repose (Repose/7.1.4.0) x-trans-id: 48ce78c7-62db-425e-91cb-43aa09f80786 Content-Length: 0 Server: Jetty(9.2.z-SNAPSHOT)
Traceback (most recent call last):
  File "/usr/local/bin/heat", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/heatclient/shell.py", line 612, in main
    HeatShell().main(args)
  File "/usr/local/lib/python2.7/site-packages/heatclient/shell.py", line 562, in main
    args.func(client, args)
  File "/usr/local/lib/python2.7/site-packages/heatclient/v1/shell.py", line 139, in do_stack_create
    hc.stacks.create(**fields)
  File "/usr/local/lib/python2.7/site-packages/heatclient/v1/stacks.py", line 172, in create
    data=kwargs, headers=headers)
  File "/usr/local/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 222, in post
    return self.request(url, 'POST', **kwargs)
  File "/usr/local/lib/python2.7/site-packages/heatclient/common/http.py", line 318, in request
    raise exc.from_response(resp)
heatclient.exc.HTTPUnsupported: ERROR: None

Proposed Fix:

Add "Content-Type: application/json" in adapter.py script of keystoneauth1 module.

#!/usr/bin/env python

import sys
try:
    import keystoneauth1
except ImportError:
    print "Please run this script after installing openstack clients"
    sys.exit(2)
import fileinput
import os

def main():
    path = os.path.join(os.path.dirname(keystoneauth1.__file__), 'adapter.py')
    check = False
    for line in fileinput.input(path, inplace=True):
        if line.find('Content-Type') != -1:
            check = True
        else:
            if line.find('Accept') != -1 and not check:
                print line.replace('Accept', 'Content-Type'),
        print line,

if __name__ == '__main__':
    main()

adithya (adithya-kiran)
description: updated
Zane Bitter (zaneb)
affects: heat-templates → python-heatclient
Revision history for this message
Gaëtan Trellu (goldyfruit) wrote :

Please find the diff:

--- a/usr/local/lib/python2.7/dist-packages/keystoneauth1/adapter.py 2017-05-17 09:09:44.531448269 -0400
+++ b/usr/local/lib/python2.7/dist-packages/keystoneauth1/adapter.py 2017-05-17 09:07:22.038628580 -0400
@@ -372,6 +372,7 @@

     def request(self, *args, **kwargs):
         headers = kwargs.setdefault('headers', {})
+ headers.setdefault('Content-Type', 'application/json')
         headers.setdefault('Accept', 'application/json')

         try:

Revision history for this message
Gaëtan Trellu (goldyfruit) wrote :

Another output.
POST call to orchestration for https://ilove.myopenstack.com:8004/v1/76fb727e666b4a8f9207f3b74b512690/stacks used request id req-7686675d-011e-4c23-adf9-59d0b32811dd
ERROR: The server could not comply with the request since it is either malformed or otherwise incorrect.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/cliff/app.py", line 400, in run_subcommand
    result = cmd.run(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/osc_lib/command/command.py", line 41, in run
    return super(Command, self).run(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/cliff/display.py", line 112, in run
    column_names, data = self.take_action(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/heatclient/osc/v1/stack.py", line 183, in take_action
    stack = client.stacks.create(**fields)['stack']
  File "/usr/local/lib/python2.7/dist-packages/heatclient/v1/stacks.py", line 172, in create
    data=kwargs, headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/keystoneauth1/adapter.py", line 229, in post
    return self.request(url, 'POST', **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/heatclient/common/http.py", line 317, in request
    raise exc.from_response(resp)
HTTPBadRequest: ERROR: The server could not comply with the request since it is either malformed or otherwise incorrect.
clean_up CreateStack: ERROR: The server could not comply with the request since it is either malformed or otherwise incorrect.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/osc_lib/shell.py", line 135, in run
    ret_val = super(OpenStackShell, self).run(argv)
  File "/usr/local/lib/python2.7/dist-packages/cliff/app.py", line 279, in run
    result = self.run_subcommand(remainder)
  File "/usr/local/lib/python2.7/dist-packages/osc_lib/shell.py", line 180, in run_subcommand
    ret_value = super(OpenStackShell, self).run_subcommand(argv)
  File "/usr/local/lib/python2.7/dist-packages/cliff/app.py", line 400, in run_subcommand
    result = cmd.run(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/osc_lib/command/command.py", line 41, in run
    return super(Command, self).run(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/cliff/display.py", line 112, in run
    column_names, data = self.take_action(parsed_args)
  File "/usr/local/lib/python2.7/dist-packages/heatclient/osc/v1/stack.py", line 183, in take_action
    stack = client.stacks.create(**fields)['stack']
  File "/usr/local/lib/python2.7/dist-packages/heatclient/v1/stacks.py", line 172, in create
    data=kwargs, headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/keystoneauth1/adapter.py", line 229, in post
    return self.request(url, 'POST', **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/heatclient/common/http.py", line 317, in request
    raise exc.from_response(resp)
HTTPBadRequest: ERROR: The server could not comply with the request since it is either malformed or otherwise incorrect.

END return value: 1

Revision history for this message
Gaëtan Trellu (goldyfruit) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.