Browse Source

Fix raise error in create plan process

Change-Id: Ied5885670b0a9e401865d47e5f1ba598403b1351
liushuai 5 months ago
parent
commit
2be6e2a496
2 changed files with 11 additions and 1 deletions
  1. 1
    1
      karbor/api/v1/plans.py
  2. 10
    0
      karbor/tests/unit/api/v1/test_plans.py

+ 1
- 1
karbor/api/v1/plans.py View File

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

+ 10
- 0
karbor/tests/unit/api/v1/test_plans.py View File

@@ -96,6 +96,16 @@ class PlanApiTest(base.TestCase):
96 96
         self.assertRaises(exc.HTTPBadRequest, self.controller.create,
97 97
                           req, body=body)
98 98
 
99
+    @mock.patch(
100
+        'karbor.services.protection.rpcapi.ProtectionAPI.show_provider')
101
+    def test_plan_create_InvalidProvider(self, mock_provider):
102
+        plan = self._plan_in_request_body()
103
+        body = {"plan": plan}
104
+        req = fakes.HTTPRequest.blank('/v1/plans')
105
+        mock_provider.side_effect = exception.NotFound()
106
+        self.assertRaises(exc.HTTPBadRequest, self.controller.create,
107
+                          req, body=body)
108
+
99 109
     @mock.patch(
100 110
         'karbor.api.v1.plans.PlansController._plan_get')
101 111
     @mock.patch(

Loading…
Cancel
Save