Merge "Fix the unit tests about policy and the DocumentedRule description"
This commit is contained in:
commit
055235a850
|
@ -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()
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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.'
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue