Beispiel #1
0
    def test_policy_remove_rule(self):
        policy = self.fw_policies.first()
        tenant_id = self.tenant.id
        rules = self.fw_rules.list()

        remove_rule_id = policy.firewall_rules[0]
        left_rule_id = policy.firewall_rules[1]

        data = {'firewall_rule_id': remove_rule_id}

        after_remove_policy_dict = {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                                    'tenant_id': '1',
                                    'name': 'policy1',
                                    'description': 'policy description',
                                    'firewall_rules': [left_rule_id],
                                    'audited': True,
                                    'shared': True}
        after_remove_policy = api_fwaas.Policy(after_remove_policy_dict)

        api_fwaas.policy_get(IsA(http.HttpRequest),
                             policy.id).AndReturn(policy)
        api_fwaas.rule_list_for_tenant(
            IsA(http.HttpRequest), tenant_id).AndReturn(rules)
        api_fwaas.rule_get(
            IsA(http.HttpRequest), remove_rule_id).AndReturn(rules[0])
        api_fwaas.policy_remove_rule(IsA(http.HttpRequest), policy.id, **data)\
            .AndReturn(after_remove_policy)

        self.mox.ReplayAll()

        res = self.client.post(
            reverse(self.REMOVERULE_PATH, args=(policy.id,)), data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
 def handle(self, request, context):
     policy_id = self.initial['policy_id']
     policy_name_or_id = self.initial['name'] or policy_id
     try:
         remove_rule_id = context['firewall_rule_id']
         remove_rule = api_fwaas.rule_get(request, remove_rule_id)
         body = {'firewall_rule_id': remove_rule_id}
         policy = api_fwaas.policy_remove_rule(request, policy_id, **body)
         msg = _('Rule %(rule)s was successfully removed from policy '
                 '%(policy)s.') % {
                     'rule': remove_rule.name or remove_rule.id,
                     'policy': policy_name_or_id
                 }
         messages.success(request, msg)
         return policy
     except Exception as e:
         LOG.error('Failed to remove rule from policy %(id)s: %(reason)s', {
             'id': policy_id,
             'reason': e
         })
         msg = (
             _('Failed to remove rule from policy %(name)s: %(reason)s') % {
                 'name': self.initial['name'],
                 'reason': e
             })
         redirect = reverse(self.failure_url)
         exceptions.handle(request, msg, redirect=redirect)
    def test_policy_remove_rule(self):
        policy = self.fw_policies.first()
        policy_dict = self.api_fw_policies.first()

        remove_rule_id = policy.firewall_rules[0]
        policy_dict['firewall_rules'].remove(remove_rule_id)

        body = {'firewall_rule_id': remove_rule_id}

        neutronclient.firewall_policy_remove_rule(policy.id,
                                                  body).AndReturn(policy_dict)
        self.mox.ReplayAll()

        ret_val = api_fwaas.policy_remove_rule(self.request, policy.id, **body)
        self.assertNotIn(remove_rule_id, ret_val.firewall_rules)
    def test_policy_remove_rule(self):
        policy = self.fw_policies.first()
        policy_dict = self.api_fw_policies.first()

        remove_rule_id = policy.firewall_rules[0]
        policy_dict['firewall_rules'].remove(remove_rule_id)

        body = {'firewall_rule_id': remove_rule_id}

        self.mock_firewall_policy_remove_rule.return_value = policy_dict

        ret_val = api_fwaas.policy_remove_rule(self.request,
                                               policy.id, **body)
        self.assertNotIn(remove_rule_id, ret_val.firewall_rules)
        self.mock_firewall_policy_remove_rule.assert_called_once_with(
            policy.id, body)