Fix raise error in create plan process

Change-Id: Ied5885670b0a9e401865d47e5f1ba598403b1351
This commit is contained in:
liushuai 2018-11-26 23:53:36 +08:00
parent d2655031ae
commit 2be6e2a496
2 changed files with 11 additions and 1 deletions

View File

@ -403,7 +403,7 @@ class PlansController(wsgi.Controller):
try: try:
provider = self.protection_api.show_provider( provider = self.protection_api.show_provider(
context, plan["provider_id"]) context, plan["provider_id"])
except exception: except Exception:
msg = _("The provider could not be found.") msg = _("The provider could not be found.")
raise exc.HTTPBadRequest(explanation=msg) raise exc.HTTPBadRequest(explanation=msg)
options_schema = provider.get( options_schema = provider.get(

View File

@ -96,6 +96,16 @@ class PlanApiTest(base.TestCase):
self.assertRaises(exc.HTTPBadRequest, self.controller.create, self.assertRaises(exc.HTTPBadRequest, self.controller.create,
req, body=body) req, body=body)
@mock.patch(
'karbor.services.protection.rpcapi.ProtectionAPI.show_provider')
def test_plan_create_InvalidProvider(self, mock_provider):
plan = self._plan_in_request_body()
body = {"plan": plan}
req = fakes.HTTPRequest.blank('/v1/plans')
mock_provider.side_effect = exception.NotFound()
self.assertRaises(exc.HTTPBadRequest, self.controller.create,
req, body=body)
@mock.patch( @mock.patch(
'karbor.api.v1.plans.PlansController._plan_get') 'karbor.api.v1.plans.PlansController._plan_get')
@mock.patch( @mock.patch(