Merge "Fix raise error in create plan process"

This commit is contained in:
Zuul 2018-11-27 07:15:38 +00:00 committed by Gerrit Code Review
commit 6d9cecd0d2
2 changed files with 11 additions and 1 deletions

View File

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

View File

@ -96,6 +96,16 @@ class PlanApiTest(base.TestCase):
self.assertRaises(exc.HTTPBadRequest, self.controller.create,
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(
'karbor.api.v1.plans.PlansController._plan_get')
@mock.patch(