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

        new_rule_id = rules[2].id

        data = {'firewall_rule_id': new_rule_id,
                'insert_before': rules[1].id,
                'insert_after': rules[0].id}

        api_fwaas.policy_get(IsA(http.HttpRequest),
                             policy.id).AndReturn(policy)

        policy.firewall_rules = [rules[0].id,
                                 new_rule_id,
                                 rules[1].id]

        api_fwaas.rule_list_for_tenant(
            IsA(http.HttpRequest), tenant_id).AndReturn(rules)
        api_fwaas.rule_get(
            IsA(http.HttpRequest), new_rule_id).AndReturn(rules[2])
        api_fwaas.policy_insert_rule(IsA(http.HttpRequest), policy.id, **data)\
            .AndReturn(policy)

        self.mox.ReplayAll()

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

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
Example #2
0
 def handle(self, request, context):
     policy_id = self.initial['policy_id']
     policy_name_or_id = self.initial['name'] or policy_id
     try:
         insert_rule_id = context['firewall_rule_id']
         insert_rule = api_fwaas.rule_get(request, insert_rule_id)
         body = {
             'firewall_rule_id': insert_rule_id,
             'insert_before': context['insert_before'],
             'insert_after': context['insert_after']
         }
         policy = api_fwaas.policy_insert_rule(request, policy_id, **body)
         msg = _('Rule %(rule)s was successfully inserted to policy '
                 '%(policy)s.') % {
                     'rule': insert_rule.name or insert_rule.id,
                     'policy': policy_name_or_id
                 }
         messages.success(request, msg)
         return policy
     except Exception as e:
         LOG.error('Failed to insert rule to policy %(id)s: %(reason)s', {
             'id': policy_id,
             'reason': e
         })
         msg = (_('Failed to insert rule to policy %(name)s: %(reason)s') %
                {
                    'name': policy_id,
                    'reason': e
                })
         redirect = reverse(self.failure_url)
         exceptions.handle(request, msg, redirect=redirect)
    def test_policy_insert_rule(self):
        policy = self.fw_policies.first()
        policy_dict = self.api_fw_policies.first()

        new_rule_id = 'h0881d38-c3eb-4fee-9763-12de3338041d'
        policy.firewall_rules.append(new_rule_id)
        policy_dict['firewall_rules'].append(new_rule_id)

        body = {'firewall_rule_id': new_rule_id,
                'insert_before': policy.firewall_rules[1],
                'insert_after': policy.firewall_rules[0]}

        self.mock_firewall_policy_insert_rule.return_value = policy_dict

        ret_val = api_fwaas.policy_insert_rule(self.request,
                                               policy.id, **body)
        self.assertIn(new_rule_id, ret_val.firewall_rules)
        self.mock_firewall_policy_insert_rule.assert_called_once_with(
            policy.id, body)
    def test_policy_insert_rule(self):
        policy = self.fw_policies.first()
        policy_dict = self.api_fw_policies.first()

        new_rule_id = 'h0881d38-c3eb-4fee-9763-12de3338041d'
        policy.firewall_rules.append(new_rule_id)
        policy_dict['firewall_rules'].append(new_rule_id)

        body = {
            'firewall_rule_id': new_rule_id,
            'insert_before': policy.firewall_rules[1],
            'insert_after': policy.firewall_rules[0]
        }

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

        ret_val = api_fwaas.policy_insert_rule(self.request, policy.id, **body)
        self.assertIn(new_rule_id, ret_val.firewall_rules)