Example #1
0
    def test_update_firewall_post(self):
        firewall_group = self.firewall_groups_v2.first()
        tenant_id = self.tenant.id
        api_fwaas_v2.firewall_get(IsA(http.HttpRequest),
                                  firewall_group.id).AndReturn(firewall_group)

        data = {
            'name': 'new name',
            'description': 'new desc',
            'ingress_firewall_policy_id':
            firewall_group.ingress_firewall_policy_id,
            'admin_state_up': False
        }

        policies = self.fw_policies_v2.list()
        api_fwaas_v2.policy_list_for_tenant(IsA(http.HttpRequest),
                                            tenant_id).AndReturn(policies)

        api_fwaas_v2.firewall_update(
            IsA(http.HttpRequest), firewall_group.id, **data)\
            .AndReturn(firewall_group)

        self.mox.ReplayAll()

        res = self.client.post(
            reverse(self.UPDATEFIREWALLGROUP_PATH, args=(firewall_group.id, )),
            data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
Example #2
0
    def test_firewall_update(self):
        firewall = self.firewall_groups_v2.first()
        firewall_dict = self.api_firewall_groups_v2.first()

        firewall.name = 'new name'
        firewall.description = 'new desc'
        firewall.admin_state_up = False

        firewall_dict['name'] = 'new name'
        firewall_dict['description'] = 'new desc'
        firewall_dict['admin_state_up'] = False

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

        form_dict = {'firewall_group': form_data}
        ret_dict = {'firewall_group': firewall_dict}

        self.mock_update_fwaas_firewall_group.return_value = ret_dict

        ret_val = api_fwaas_v2.firewall_update(self.request, firewall.id,
                                               **form_data)
        self.assertIsInstance(ret_val, api_fwaas_v2.FirewallGroup)
        self.assertEqual(firewall.name, ret_val.name)
        self.assertTrue(ret_val.id)

        self.mock_update_fwaas_firewall_group.assert_called_once_with(
            firewall.id, form_dict)
Example #3
0
    def test_firewall_update(self):
        firewall = self.firewall_groups_v2.first()
        firewall_dict = self.api_firewall_groups_v2.first()

        firewall.name = 'new name'
        firewall.description = 'new desc'
        firewall.admin_state_up = False

        firewall_dict['name'] = 'new name'
        firewall_dict['description'] = 'new desc'
        firewall_dict['admin_state_up'] = False

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

        form_dict = {'firewall_group': form_data}
        ret_dict = {'firewall_group': firewall_dict}

        neutronclient.update_fwaas_firewall_group(
            firewall.id, form_dict).AndReturn(ret_dict)
        self.mox.ReplayAll()

        ret_val = api_fwaas_v2.firewall_update(self.request, firewall.id,
                                               **form_data)
        self.assertIsInstance(ret_val, api_fwaas_v2.FirewallGroup)
        self.assertEqual(firewall.name, ret_val.name)
        self.assertTrue(ret_val.id)
 def handle(self, request, context):
     firewallgroup_id = self.initial['firewallgroup_id']
     name_or_id = context.get('name') or firewallgroup_id
     body = self._convert_req_body(_get_request_body(context, self.initial))
     try:
         firewall = api_fwaas_v2.firewall_update(request, firewallgroup_id,
                                                 **body)
         msg = _('Firewall %s was successfully updated.') % name_or_id
         messages.success(request, msg)
         return firewall
     except Exception as e:
         msg = (_('Failed to update firewall %(name)s: %(reason)s') %
                {'name': name_or_id, 'reason': e})
         redirect = reverse(self.failure_url)
         exceptions.handle(request, msg, redirect=redirect)
 def handle(self, request, context):
     firewallgroup_id = self.initial['firewallgroup_id']
     name_or_id = context.get('name') or firewallgroup_id
     body = _get_request_body(context, self.initial)
     remove_port = context['port_id']
     if remove_port:
         ports = self.initial['ports']
         ports.remove(remove_port)
         body['ports'] = ports
     try:
         firewallgroup = api_fwaas_v2.firewall_update(
             request, firewallgroup_id, **body)
         msg = _('FirewallGroup %s was successfully updated.') % name_or_id
         messages.success(request, msg)
         return firewallgroup
     except Exception as e:
         msg = (_('Failed to update firewallgroup %(name)s: %(reason)s') %
                {'name': name_or_id, 'reason': e})
         redirect = reverse(self.failure_url)
         exceptions.handle(request, msg, redirect=redirect)