示例#1
0
文件: tests.py 项目: redondos/horizon
    def test_edit_rules_add_rule_exception(self):
        sec_group = self.security_groups.first()
        sec_group_list = self.security_groups.list()
        rule = self.security_group_rules.first()

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_rule_create(IsA(http.HttpRequest), sec_group.id,
                                       rule.ip_protocol, int(rule.from_port),
                                       int(rule.to_port),
                                       rule.ip_range['cidr'],
                                       None).AndRaise(self.exceptions.nova)
        api.security_group_list(IsA(
            http.HttpRequest)).AndReturn(sec_group_list)
        self.mox.ReplayAll()

        formData = {
            'method': 'AddRule',
            'security_group_id': sec_group.id,
            'from_port': rule.from_port,
            'to_port': rule.to_port,
            'ip_protocol': rule.ip_protocol,
            'cidr': rule.ip_range['cidr'],
            'source_group': ''
        }
        res = self.client.post(self.edit_url, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
示例#2
0
文件: tests.py 项目: redondos/horizon
    def test_edit_rules_add_rule_self_as_source_group(self):
        sec_group = self.security_groups.first()
        sec_group_list = self.security_groups.list()
        rule = self.security_group_rules.get(id=3)

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_rule_create(IsA(http.HttpRequest), sec_group.id,
                                       rule.ip_protocol, int(rule.from_port),
                                       int(rule.to_port), None,
                                       u'%s' % sec_group.id).AndReturn(rule)
        api.security_group_list(IsA(
            http.HttpRequest)).AndReturn(sec_group_list)
        self.mox.ReplayAll()

        formData = {
            'method': 'AddRule',
            'security_group_id': sec_group.id,
            'from_port': rule.from_port,
            'to_port': rule.to_port,
            'ip_protocol': rule.ip_protocol,
            'cidr': '0.0.0.0/0',
            'source_group': sec_group.id
        }
        res = self.client.post(self.edit_url, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
示例#3
0
    def test_edit_rules_add_rule_exception(self):
        sec_group = self.security_groups.first()
        sec_group_list = self.security_groups.list()
        rule = self.security_group_rules.first()

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_rule_create(IsA(http.HttpRequest),
                                       sec_group.id,
                                       rule.ip_protocol,
                                       int(rule.from_port),
                                       int(rule.to_port),
                                       rule.ip_range['cidr'],
                                       None).AndRaise(self.exceptions.nova)
        api.security_group_list(
                        IsA(http.HttpRequest)).AndReturn(sec_group_list)
        self.mox.ReplayAll()

        formData = {'method': 'AddRule',
                    'security_group_id': sec_group.id,
                    'from_port': rule.from_port,
                    'to_port': rule.to_port,
                    'ip_protocol': rule.ip_protocol,
                    'cidr': rule.ip_range['cidr'],
                    'source_group': ''}
        res = self.client.post(self.edit_url, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
示例#4
0
    def test_edit_rules_add_rule_self_as_source_group(self):
        sec_group = self.security_groups.first()
        sec_group_list = self.security_groups.list()
        rule = self.security_group_rules.get(id=3)

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_rule_create(IsA(http.HttpRequest),
                                       sec_group.id,
                                       rule.ip_protocol,
                                       int(rule.from_port),
                                       int(rule.to_port),
                                       None,
                                       u'%s' % sec_group.id).AndReturn(rule)
        api.security_group_list(
                        IsA(http.HttpRequest)).AndReturn(sec_group_list)
        self.mox.ReplayAll()

        formData = {'method': 'AddRule',
                    'security_group_id': sec_group.id,
                    'from_port': rule.from_port,
                    'to_port': rule.to_port,
                    'ip_protocol': rule.ip_protocol,
                    'cidr': '0.0.0.0/0',
                    'source_group': sec_group.id}
        res = self.client.post(self.edit_url, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
示例#5
0
 def handle(self, request, data):
     try:
         rule = api.security_group_rule_create(
             request, data['security_group_id'], data['ip_protocol'],
             data['from_port'], data['to_port'], data['cidr'],
             data['source_group'])
         messages.success(request,
                          _('Successfully added rule: %s') % unicode(rule))
         return rule
     except:
         redirect = reverse("horizon:project:access_and_security:index")
         exceptions.handle(request,
                           _('Unable to add rule to security group.'),
                           redirect=redirect)
    def handle(self, request, data):
        tenant_id = data['tenant_id']
        try:
            LOG.info('Add security_group_rule: "%s"' % data)

            security_group = api.security_group_rule_create(request,
                                                     data['security_group_id'],
                                                     data['ip_protocol'],
                                                     data['from_port'],
                                                     data['to_port'],
                                                     data['cidr'])
            messages.info(request, 'Successfully added rule: %s' \
                                    % security_group.id)
        except api_exceptions.ApiException, e:
            LOG.error("ApiException in AddRule", exc_info=True)
            messages.error(request, 'Error adding rule security group: %s' % e.message)
示例#7
0
 def handle(self, request, data):
     try:
         rule = api.security_group_rule_create(request,
                                               data['security_group_id'],
                                               data['ip_protocol'],
                                               data['from_port'],
                                               data['to_port'],
                                               data['cidr'],
                                               data['source_group'])
         messages.success(request,
                          _('Successfully added rule: %s') % unicode(rule))
         return rule
     except:
         redirect = reverse("horizon:project:access_and_security:index")
         exceptions.handle(request,
                           _('Unable to add rule to security group.'),
                           redirect=redirect)