server.action does not work

Bug #1509141 reported by Jared Berghold
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack SDK
Fix Committed
Undecided
Haifeng.Yan

Bug Description

Calling server.action results in a 404 error.

Looking at the OpenStack API documentation (http://developer.openstack.org/api-ref-compute-v2.1.html#os-server-actions-v2.1), calls to /v2.1/​{tenant_id}​/servers/​{server_id}​/action should use POST, however in /openstack/compute/v2/server.py, line 92, the action method uses a PUT request. See: https://github.com/openstack/python-openstacksdk/blob/master/openstack/compute/v2/server.py#L92

The issue can be resolved by replacing:
  resp = session.put(url, service=self.service, json=body).body
with:
  resp = session.post(url, service=self.service, json=body).body

However, then an exception is thrown on line 271 of /openstack/transport.py (https://github.com/openstack/python-openstacksdk/blob/master/openstack/transport.py#L271) whenever there is no JSON response. Many of the 'action' requests, such as the reboot action (see: http://developer.openstack.org/api-ref-compute-v2.1.html#rebootServer), don't return a response body.

To reproduce this, use code similar to the following:

from openstack import connection

conn = connection.Connection(auth_url='https://keystone.rc.nectar.org.au:5000/v2.0/',
                             project_name='my_project_name',
                             username='my_username',
                             password='my_password')

actionBody = {"reboot": {"type": "SOFT"}}
#actionBody = {"suspend": None}
#actionBody = {"resume": None}

servers = conn.compute.servers(details=False, name="my_vm")

for server in servers:
    server.action(session=conn.session,body=actionBody)

(Note: I'm fairly sure this is the incorrect usage of server.action in that I'm passing in a 'session' that has already been used in a previous request. I can't find documentation on the proper usage of server.action or how to generate a new session.)

Revision history for this message
Haifeng.Yan (yanheven) wrote :

I found that all of server actions get no response body, so we should make some change to this method.

Revision history for this message
Haifeng.Yan (yanheven) wrote :
Changed in python-openstacksdk:
status: New → In Progress
assignee: nobody → yan.haifeng (yanheven)
Revision history for this message
Jared Berghold (jared-9) wrote :

I think a few of the actions do return a response body. For example, "os-getVNCConsole" seems to. See : http://developer.openstack.org/api-ref-compute-v2.1.html#getVNCConsole

Changed in python-openstacksdk:
assignee: yan.haifeng (yanheven) → nobody
status: In Progress → Confirmed
Revision history for this message
Haifeng.Yan (yanheven) wrote :

maybe we can leave the specific action methods to decide whether would get a response body

Revision history for this message
Haifeng.Yan (yanheven) wrote :
Changed in python-openstacksdk:
assignee: nobody → yan.haifeng (yanheven)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-openstacksdk (master)

Reviewed: https://review.openstack.org/239253
Committed: https://git.openstack.org/cgit/openstack/python-openstacksdk/commit/?id=2700f034a1e19d6441a7ec3b6dffa33162e0f66d
Submitter: Jenkins
Branch: master

commit 2700f034a1e19d6441a7ec3b6dffa33162e0f66d
Author: yan.haifeng <email address hidden>
Date: Sun Oct 25 17:14:36 2015 +0800

    Fix server.action does not work

    As description in nova api document, server action request should use
    the post method, with no response body return.

    Fix this bug by modified request method from 'put' to 'post', and
    also add a boolean parameter 'has_response' in action method to avoid
    empty response body exception in response parsing.

    Change-Id: Ie37e9745b3c924049f7fd563e43e5de55c711af7
    Closes-Bug:#1509141

Changed in python-openstacksdk:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

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