Exemple #1
0
 def handle(self, request, context):
     try:
         api_fwaas.policy_create(request, **context)
         return True
     except Exception as e:
         msg = self.format_status_message(self.failure_message) + str(e)
         exceptions.handle(request, msg)
         return False
Exemple #2
0
    def test_add_policy_post(self):
        policy = self.fw_policies.first()
        rules = self.fw_rules.list()
        tenant_id = self.tenant.id
        form_data = {
            'name': policy.name,
            'description': policy.description,
            'firewall_rules': policy.firewall_rules,
            'shared': policy.shared,
            'audited': policy.audited
        }
        post_data = {
            'name': policy.name,
            'description': policy.description,
            'rule': policy.firewall_rules,
            'shared': policy.shared,
            'audited': policy.audited
        }

        # NOTE: SelectRulesAction.populate_rule_choices() lists rule not
        # associated with any policy. We need to ensure that rules specified
        # in policy.firewall_rules in post_data (above) are not associated
        # with any policy. Test data in neutron_data is data in a stable state,
        # so we need to modify here.
        for rule in rules:
            if rule.id in policy.firewall_rules:
                rule.firewall_policy_id = rule.policy = None
        api_fwaas.rule_list_for_tenant(IsA(http.HttpRequest),
                                       tenant_id).AndReturn(rules)
        api_fwaas.policy_create(IsA(http.HttpRequest),
                                **form_data).AndReturn(policy)

        self.mox.ReplayAll()

        res = self.client.post(reverse(self.ADDPOLICY_PATH), post_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
    def test_policy_create(self):
        policy1 = self.fw_policies.first()
        policy1_dict = self.api_fw_policies.first()

        form_data = {'name': policy1.name,
                     'description': policy1.description,
                     'firewall_rules': policy1.firewall_rules,
                     'shared': policy1.shared,
                     'audited': policy1.audited
                     }
        form_dict = {'firewall_policy': form_data}
        ret_dict = {'firewall_policy': policy1_dict}

        self.mock_create_firewall_policy.return_value = ret_dict

        ret_val = api_fwaas.policy_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api_fwaas.Policy)
        self.assertEqual(policy1.name, ret_val.name)
        self.assertTrue(ret_val.id)
        self.mock_create_firewall_policy.assert_called_once_with(form_dict)
    def test_policy_create(self):
        policy1 = self.fw_policies.first()
        policy1_dict = self.api_fw_policies.first()

        form_data = {
            'name': policy1.name,
            'description': policy1.description,
            'firewall_rules': policy1.firewall_rules,
            'shared': policy1.shared,
            'audited': policy1.audited
        }
        form_dict = {'firewall_policy': form_data}
        ret_dict = {'firewall_policy': policy1_dict}

        neutronclient.create_firewall_policy(form_dict).AndReturn(ret_dict)
        self.mox.ReplayAll()

        ret_val = api_fwaas.policy_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api_fwaas.Policy)
        self.assertEqual(policy1.name, ret_val.name)
        self.assertTrue(ret_val.id)