Fix server action resource call

Currently, action resource call of nova server doesn't work
correctly in case where action API doesn't have response body.
This patch fixes this issue.

Change-Id: I016f74507f7d5b5792c77879969bdc271c25f829
Closes-Bug: #1528145
This commit is contained in:
yanyanhu 2015-12-21 04:33:37 -05:00
parent 2574e9585a
commit b37bced0e7
2 changed files with 5 additions and 9 deletions

View File

@ -86,16 +86,12 @@ class Server(resource.Resource):
return body
def action(self, session, body, has_response=False):
def action(self, session, body):
"""Preform server actions given the message body."""
url = utils.urljoin(self.base_path, self.id, 'action')
if has_response:
resp = session.post(url, endpoint_filter=self.service, json=body)
else:
headers = {'Accept': ''}
resp = session.post(
url, endpoint_filter=self.service, json=body, headers=headers)
return resp.json()
headers = {'Accept': ''}
session.post(
url, endpoint_filter=self.service, json=body, headers=headers)
def change_password(self, session, new_password):
"""Change the administrator password to the given password."""

View File

@ -45,7 +45,7 @@ class TestServer(testtools.TestCase):
def setUp(self):
super(TestServer, self).setUp()
self.resp = mock.Mock()
self.resp.body = ''
self.resp.body = None
self.resp.json = mock.Mock(return_value=self.resp.body)
self.sess = mock.Mock()
self.sess.post = mock.Mock(return_value=self.resp)