Remove redundant body validation for createBackup

The body validation is redundant for createBackup, should remove it. In
fact that this extension is registered as WSGI action implies that the
body must contain a key with the same name as action.

Change-Id: I327688b2df50782bc38b97a4750f83a607623ce4
Closes-Bug: #1254988
This commit is contained in:
zhangyanzi 2013-11-26 15:40:29 +08:00
parent eced10cf41
commit 3001bc67ed
4 changed files with 24 additions and 10 deletions

View File

@ -219,11 +219,7 @@ class AdminActionsController(wsgi.Controller):
""" """
context = req.environ["nova.context"] context = req.environ["nova.context"]
authorize(context, 'createBackup') authorize(context, 'createBackup')
entity = body["createBackup"]
try:
entity = body["createBackup"]
except (KeyError, TypeError):
raise exc.HTTPBadRequest(_("Malformed request body"))
try: try:
image_name = entity["name"] image_name = entity["name"]

View File

@ -210,11 +210,7 @@ class AdminActionsController(wsgi.Controller):
""" """
context = req.environ["nova.context"] context = req.environ["nova.context"]
authorize(context, 'create_backup') authorize(context, 'create_backup')
entity = body["create_backup"]
try:
entity = body["create_backup"]
except (KeyError, TypeError):
raise exc.HTTPBadRequest(_("Malformed request body"))
try: try:
image_name = entity["name"] image_name = entity["name"]

View File

@ -433,6 +433,17 @@ class CreateBackupTests(CommonMixin, test.NoDBTestCase):
self._test_non_existing_instance('createBackup', self._test_non_existing_instance('createBackup',
body_map=body_map) body_map=body_map)
def test_create_backup_with_invalid_createBackup(self):
body = {
'createBackupup': {
'name': 'Backup 1',
'backup_type': 'daily',
'rotation': 1,
},
}
res = self._make_request(self._make_url('fake'), body)
self.assertEqual(400, res.status_int)
class ResetStateTests(test.NoDBTestCase): class ResetStateTests(test.NoDBTestCase):
def setUp(self): def setUp(self):

View File

@ -490,6 +490,17 @@ class CreateBackupTests(CommonMixin, test.NoDBTestCase):
self._test_non_existing_instance('create_backup', self._test_non_existing_instance('create_backup',
body_map=body_map) body_map=body_map)
def test_create_backup_with_invalid_create_backup(self):
body = {
'create_backupup': {
'name': 'Backup 1',
'backup_type': 'daily',
'rotation': 1,
},
}
res = self._make_request(self._make_url('fake'), body)
self.assertEqual(400, res.status_int)
class ResetStateTests(test.NoDBTestCase): class ResetStateTests(test.NoDBTestCase):
def setUp(self): def setUp(self):