Ejemplo n.º 1
0
    def _test_add_firewall_post(self, router_extension=False):
        firewall = self.firewalls.first()
        policies = self.fw_policies.list()
        tenant_id = self.tenant.id
        if router_extension:
            routers = self.routers.list()
            firewalls = self.firewalls.list()

        form_data = {'name': firewall.name,
                     'description': firewall.description,
                     'firewall_policy_id': firewall.firewall_policy_id,
                     'admin_state_up': firewall.admin_state_up
                     }
        if router_extension:
            form_data['router_ids'] = firewall.router_ids
            api.neutron.router_list(
                IsA(http.HttpRequest), tenant_id=tenant_id).AndReturn(routers)
            api_fwaas.firewall_list_for_tenant(
                IsA(http.HttpRequest),
                tenant_id=tenant_id).AndReturn(firewalls)

        api.neutron.is_extension_supported(
            IsA(http.HttpRequest),
            'fwaasrouterinsertion').AndReturn(router_extension)
        api_fwaas.policy_list_for_tenant(
            IsA(http.HttpRequest), tenant_id).AndReturn(policies)
        api_fwaas.firewall_create(
            IsA(http.HttpRequest), **form_data).AndReturn(firewall)

        self.mox.ReplayAll()

        res = self.client.post(reverse(self.ADDFIREWALL_PATH), form_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
Ejemplo n.º 2
0
 def handle(self, request, context):
     try:
         api_fwaas.firewall_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
    def test_firewall_create(self):
        firewall = self.firewalls.first()
        firewall_dict = self.api_firewalls.first()

        form_data = {'name': firewall.name,
                     'description': firewall.description,
                     'firewall_policy_id': firewall.firewall_policy_id,
                     'admin_state_up': firewall.admin_state_up
                     }

        form_dict = {'firewall': form_data}
        ret_dict = {'firewall': firewall_dict}
        self.mock_create_firewall.return_value = ret_dict

        ret_val = api_fwaas.firewall_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api_fwaas.Firewall)
        self.assertEqual(firewall.name, ret_val.name)
        self.assertTrue(ret_val.id)
        self.mock_create_firewall.assert_called_once_with(form_dict)
Ejemplo n.º 4
0
    def test_firewall_create(self):
        firewall = self.firewalls.first()
        firewall_dict = self.api_firewalls.first()

        form_data = {
            'name': firewall.name,
            'description': firewall.description,
            'firewall_policy_id': firewall.firewall_policy_id,
            'admin_state_up': firewall.admin_state_up
        }

        form_dict = {'firewall': form_data}
        ret_dict = {'firewall': firewall_dict}
        neutronclient.create_firewall(form_dict).AndReturn(ret_dict)
        self.mox.ReplayAll()

        ret_val = api_fwaas.firewall_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api_fwaas.Firewall)
        self.assertEqual(firewall.name, ret_val.name)
        self.assertTrue(ret_val.id)