Rescue API handle NotImplementedError

There are several nova virt drivers that don't implement the rescue API,
but the os compute API doesn't handle NotImplementedError,
it returns a 400 instead of a 501.

The patch add the proper logic to return a 501 instead.

Change-Id: Ia649c4dadd50985efed631ce8f3e4b212646766e
Closes-Bug: #1287367
This commit is contained in:
Leandro I. Costantino
2014-03-03 21:09:52 -03:00
parent 80e8555e10
commit f3f46b532c
4 changed files with 84 additions and 2 deletions

View File

@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo.config import cfg
import webob
@@ -128,3 +129,35 @@ class RescueTest(test.NoDBTestCase):
resp = req.get_response(self.app)
self.assertEqual(resp.status_int, 400)
@mock.patch('nova.compute.api.API.rescue')
def test_rescue_raises_not_implemented(self, rescue_mock):
body = dict(rescue=None)
def fake_rescue(*args, **kwargs):
raise NotImplementedError('not implemented')
rescue_mock.side_effect = fake_rescue
req = webob.Request.blank('/v2/fake/servers/test_inst/action')
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(self.app)
self.assertEqual(resp.status_int, 501)
@mock.patch('nova.compute.api.API.unrescue')
def test_unrescue_raises_not_implemented(self, unrescue_mock):
body = dict(unrescue=None)
def fake_unrescue(*args, **kwargs):
raise NotImplementedError('not implemented')
unrescue_mock.side_effect = fake_unrescue
req = webob.Request.blank('/v2/fake/servers/test_inst/action')
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(self.app)
self.assertEqual(resp.status_int, 501)

View File

@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo.config import cfg
import webob
@@ -168,3 +169,35 @@ class RescueTest(test.NoDBTestCase):
resp = req.get_response(self.app)
self.assertEqual(400, resp.status_int)
@mock.patch('nova.compute.api.API.rescue')
def test_rescue_raises_not_implemented(self, rescue_mock):
body = dict(rescue=None)
def fake_rescue(*args, **kwargs):
raise NotImplementedError('fake message')
rescue_mock.side_effect = fake_rescue
req = webob.Request.blank('/v3/servers/test_inst/action')
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(self.app)
self.assertEqual(resp.status_int, 501)
@mock.patch('nova.compute.api.API.unrescue')
def test_unrescue_raises_not_implemented(self, unrescue_mock):
body = dict(unrescue=None)
def fake_unrescue(*args, **kwargs):
raise NotImplementedError('fake message')
unrescue_mock.side_effect = fake_unrescue
req = webob.Request.blank('/v3/servers/test_inst/action')
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
resp = req.get_response(self.app)
self.assertEqual(resp.status_int, 501)