diff --git a/karbor/api/v1/plans.py b/karbor/api/v1/plans.py index 14a32763..fe1f72cc 100644 --- a/karbor/api/v1/plans.py +++ b/karbor/api/v1/plans.py @@ -329,7 +329,7 @@ class PlansController(wsgi.Controller): plan = self._plan_get(context, id) except exception.PlanNotFound as error: raise exc.HTTPNotFound(explanation=error.msg) - context.can(plan_policy.UPDATE_POLICY, target_obj=plan) + self._plan_update(context, plan, update_dict) plan.update(update_dict) @@ -360,6 +360,7 @@ class PlansController(wsgi.Controller): raise exception.InvalidPlan(reason=msg) # TODO(chenying) replication scene: need call rpc API when # the status of the plan is changed. + context.can(plan_policy.UPDATE_POLICY, target_obj=plan) if isinstance(plan, objects_base.KarborObject): plan.update(fields) plan.save() diff --git a/karbor/policies/plans.py b/karbor/policies/plans.py index bba7c795..eda3b787 100644 --- a/karbor/policies/plans.py +++ b/karbor/policies/plans.py @@ -28,7 +28,7 @@ plans_policies = [ policy.DocumentedRuleDefault( name=CREATE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Create a plan.""", + description='Create a plan.', operations=[ { 'method': 'POST', @@ -38,7 +38,7 @@ plans_policies = [ policy.DocumentedRuleDefault( name=UPDATE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Update a plan.""", + description='Update a plan.', operations=[ { 'method': 'PUT', @@ -48,7 +48,7 @@ plans_policies = [ policy.DocumentedRuleDefault( name=DELETE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Delete a plan.""", + description='Delete a plan.', operations=[ { 'method': 'DELETE', @@ -58,7 +58,7 @@ plans_policies = [ policy.DocumentedRuleDefault( name=GET_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Get a plan.""", + description='Get a plan.', operations=[ { 'method': 'GET', @@ -68,7 +68,7 @@ plans_policies = [ policy.DocumentedRuleDefault( name=GET_ALL_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Get plans.""", + description='Get plans.', operations=[ { 'method': 'GET', diff --git a/karbor/policies/protectables.py b/karbor/policies/protectables.py index 4ef3729c..6ad40da9 100644 --- a/karbor/policies/protectables.py +++ b/karbor/policies/protectables.py @@ -27,7 +27,7 @@ protectables_policies = [ policy.DocumentedRuleDefault( name=GET_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Show a protectable type.""", + description='Show a protectable type.', operations=[ { 'method': 'GET', @@ -37,7 +37,7 @@ protectables_policies = [ policy.DocumentedRuleDefault( name=GET_ALL_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""List protectable types.""", + description='List protectable types.', operations=[ { 'method': 'GET', @@ -47,7 +47,7 @@ protectables_policies = [ policy.DocumentedRuleDefault( name=INSTANCES_GET_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Show a protectable instance.""", + description='Show a protectable instance.', operations=[ { 'method': 'GET', @@ -58,7 +58,7 @@ protectables_policies = [ policy.DocumentedRuleDefault( name=INSTANCES_GET_ALL_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""List protectable instances.""", + description='List protectable instances.', operations=[ { 'method': 'GET', diff --git a/karbor/policies/providers.py b/karbor/policies/providers.py index 85396bec..a3f4865c 100644 --- a/karbor/policies/providers.py +++ b/karbor/policies/providers.py @@ -30,7 +30,7 @@ providers_policies = [ policy.DocumentedRuleDefault( name=GET_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Show a protection provider.""", + description='Show a protection provider.', operations=[ { 'method': 'GET', @@ -40,7 +40,7 @@ providers_policies = [ policy.DocumentedRuleDefault( name=GET_ALL_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""List protection providers.""", + description='List protection providers.', operations=[ { 'method': 'GET', @@ -50,7 +50,7 @@ providers_policies = [ policy.DocumentedRuleDefault( name=CHECKPOINT_GET_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Show a checkpoint.""", + description='Show a checkpoint.', operations=[ { 'method': 'GET', @@ -60,7 +60,7 @@ providers_policies = [ policy.DocumentedRuleDefault( name=CHECKPOINT_GET_ALL_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""List checkpoints.""", + description='List checkpoints.', operations=[ { 'method': 'GET', @@ -70,7 +70,7 @@ providers_policies = [ policy.DocumentedRuleDefault( name=CHECKPOINT_CREATE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Create checkpoint.""", + description='Create checkpoint.', operations=[ { 'method': 'POST', @@ -80,7 +80,7 @@ providers_policies = [ policy.DocumentedRuleDefault( name=CHECKPOINT_DELETE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Delete checkpoint.""", + description='Delete checkpoint.', operations=[ { 'method': 'DELETE', diff --git a/karbor/policies/restores.py b/karbor/policies/restores.py index 47ff56af..1d9ec571 100644 --- a/karbor/policies/restores.py +++ b/karbor/policies/restores.py @@ -27,7 +27,7 @@ restores_policies = [ policy.DocumentedRuleDefault( name=CREATE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Create a restore.""", + description='Create a restore.', operations=[ { 'method': 'POST', @@ -37,7 +37,7 @@ restores_policies = [ policy.DocumentedRuleDefault( name=UPDATE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Update a restore.""", + description='Update a restore.', operations=[ { 'method': 'PUT', @@ -47,7 +47,7 @@ restores_policies = [ policy.DocumentedRuleDefault( name=GET_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Get a restore.""", + description='Get a restore.', operations=[ { 'method': 'GET', @@ -57,7 +57,7 @@ restores_policies = [ policy.DocumentedRuleDefault( name=GET_ALL_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Get restores.""", + description='Get restores.', operations=[ { 'method': 'GET', diff --git a/karbor/policies/scheduled_operations.py b/karbor/policies/scheduled_operations.py index 5984d164..8574f94f 100644 --- a/karbor/policies/scheduled_operations.py +++ b/karbor/policies/scheduled_operations.py @@ -27,7 +27,7 @@ scheduled_operations_policies = [ policy.DocumentedRuleDefault( name=CREATE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Create a scheduled_operation.""", + description='Create a scheduled_operation.', operations=[ { 'method': 'POST', @@ -37,7 +37,7 @@ scheduled_operations_policies = [ policy.DocumentedRuleDefault( name=DELETE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Delete a scheduled_operation.""", + description='Delete a scheduled_operation.', operations=[ { 'method': 'DELETE', @@ -47,7 +47,7 @@ scheduled_operations_policies = [ policy.DocumentedRuleDefault( name=GET_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Get a scheduled_operation.""", + description='Get a scheduled_operation.', operations=[ { 'method': 'GET', @@ -57,7 +57,7 @@ scheduled_operations_policies = [ policy.DocumentedRuleDefault( name=GET_ALL_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Get scheduled_operations.""", + description='Get scheduled_operations.', operations=[ { 'method': 'GET', diff --git a/karbor/policies/triggers.py b/karbor/policies/triggers.py index eeffe736..8e1ae0c6 100644 --- a/karbor/policies/triggers.py +++ b/karbor/policies/triggers.py @@ -28,7 +28,7 @@ triggers_policies = [ policy.DocumentedRuleDefault( name=CREATE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Create a trigger.""", + description='Create a trigger.', operations=[ { 'method': 'POST', @@ -38,7 +38,7 @@ triggers_policies = [ policy.DocumentedRuleDefault( name=UPDATE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Update a trigger.""", + description='Update a trigger.', operations=[ { 'method': 'PUT', @@ -48,7 +48,7 @@ triggers_policies = [ policy.DocumentedRuleDefault( name=DELETE_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Delete a trigger.""", + description='Delete a trigger.', operations=[ { 'method': 'DELETE', @@ -58,7 +58,7 @@ triggers_policies = [ policy.DocumentedRuleDefault( name=GET_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Get a trigger.""", + description='Get a trigger.', operations=[ { 'method': 'GET', @@ -68,7 +68,7 @@ triggers_policies = [ policy.DocumentedRuleDefault( name=GET_ALL_POLICY, check_str=base.RULE_ADMIN_OR_OWNER, - description="""Get triggerss.""", + description='Get triggerss.', operations=[ { 'method': 'GET', diff --git a/karbor/tests/unit/api/v1/test_operation_logs.py b/karbor/tests/unit/api/v1/test_operation_logs.py index 611ed770..69bace82 100644 --- a/karbor/tests/unit/api/v1/test_operation_logs.py +++ b/karbor/tests/unit/api/v1/test_operation_logs.py @@ -28,8 +28,6 @@ class OperationLogTest(base.TestCase): super(OperationLogTest, self).setUp() self.controller = operation_logs.OperationLogsController() self.ctxt = context.RequestContext('demo', 'fakeproject', True) - self.mock_policy_check = self.mock_object( - context.RequestContext, 'can') @mock.patch( 'karbor.api.v1.operation_logs.' diff --git a/karbor/tests/unit/api/v1/test_plans.py b/karbor/tests/unit/api/v1/test_plans.py index d0eefc3d..36e57b3d 100644 --- a/karbor/tests/unit/api/v1/test_plans.py +++ b/karbor/tests/unit/api/v1/test_plans.py @@ -37,9 +37,8 @@ class PlanApiTest(base.TestCase): def setUp(self): super(PlanApiTest, self).setUp() self.controller = plans.PlansController() - self.ctxt = context.RequestContext('demo', 'fakeproject', True) - self.mock_policy_check = self.mock_object( - context.RequestContext, 'can') + self.ctxt = context.RequestContext('demo', + DEFAULT_PROJECT_ID, True) @mock.patch( 'karbor.services.protection.rpcapi.ProtectionAPI.show_provider') @@ -52,7 +51,6 @@ class PlanApiTest(base.TestCase): mock_provider.return_value = fakes.PROVIDER_OS self.controller.create(req, body) self.assertTrue(mock_plan_create.called) - self.assertTrue(self.mock_policy_check.called) def test_plan_create_InvalidBody(self): plan = self._plan_in_request_body() diff --git a/karbor/tests/unit/api/v1/test_protectables.py b/karbor/tests/unit/api/v1/test_protectables.py index e6d73941..494fdcae 100644 --- a/karbor/tests/unit/api/v1/test_protectables.py +++ b/karbor/tests/unit/api/v1/test_protectables.py @@ -28,8 +28,6 @@ class ProtectablesApiTest(base.TestCase): super(ProtectablesApiTest, self).setUp() self.controller = protectables.ProtectablesController() self.ctxt = context.RequestContext('demo', 'fakeproject', True) - self.mock_policy_check = self.mock_object( - context.RequestContext, 'can') @mock.patch( 'karbor.api.v1.protectables.ProtectablesController._get_all') diff --git a/karbor/tests/unit/api/v1/test_providers.py b/karbor/tests/unit/api/v1/test_providers.py index cb0642b8..5cf02cc7 100644 --- a/karbor/tests/unit/api/v1/test_providers.py +++ b/karbor/tests/unit/api/v1/test_providers.py @@ -29,8 +29,6 @@ class ProvidersApiTest(base.TestCase): super(ProvidersApiTest, self).setUp() self.controller = providers.ProvidersController() self.ctxt = context.RequestContext('demo', 'fakeproject', True) - self.mock_policy_check = self.mock_object( - context.RequestContext, 'can') @mock.patch( 'karbor.api.v1.providers.ProvidersController._get_all') diff --git a/karbor/tests/unit/api/v1/test_restores.py b/karbor/tests/unit/api/v1/test_restores.py index 6ec30f6a..6ef673ea 100644 --- a/karbor/tests/unit/api/v1/test_restores.py +++ b/karbor/tests/unit/api/v1/test_restores.py @@ -42,8 +42,6 @@ class RestoreApiTest(base.TestCase): super(RestoreApiTest, self).setUp() self.controller = restores.RestoresController() self.ctxt = context.RequestContext('demo', 'fakeproject', True) - self.mock_policy_check = self.mock_object( - context.RequestContext, 'can') @mock.patch( 'karbor.services.protection.api.API.restore') diff --git a/karbor/tests/unit/api/v1/test_scheduled_operation.py b/karbor/tests/unit/api/v1/test_scheduled_operation.py index 66eb66b2..70744c6e 100644 --- a/karbor/tests/unit/api/v1/test_scheduled_operation.py +++ b/karbor/tests/unit/api/v1/test_scheduled_operation.py @@ -63,8 +63,6 @@ class ScheduledOperationApiTest(base.TestCase): "provider_id": self._plan['provider_id'] }, } - self.mock_policy_check = self.mock_object( - context.RequestContext, 'can') def test_create_operation_InvalidBody(self): self.assertRaises(exc.HTTPUnprocessableEntity, diff --git a/karbor/tests/unit/api/v1/test_triggers.py b/karbor/tests/unit/api/v1/test_triggers.py index 4a499218..30e62836 100644 --- a/karbor/tests/unit/api/v1/test_triggers.py +++ b/karbor/tests/unit/api/v1/test_triggers.py @@ -54,8 +54,6 @@ class TriggerApiTest(base.TestCase): "pattern": "* * * * *" }, } - self.mock_policy_check = self.mock_object( - context.RequestContext, 'can') def test_create_trigger_InvalidBody(self): self.assertRaises(exc.HTTPUnprocessableEntity,