Exemple #1
0
    def test_edit_rules_add_rule_exception(self):
        exception = novaclient_exceptions.ClientException(
            'ClientException', message='ClientException')

        RULE_ID = '1'
        FROM_PORT = '-1'
        TO_PORT = '-1'
        IP_PROTOCOL = 'icmp'
        CIDR = '0.0.0.0/0'

        formData = {
            'method': 'AddRule',
            'tenant_id': self.TEST_TENANT,
            'security_group_id': SECGROUP_ID,
            'from_port': FROM_PORT,
            'to_port': TO_PORT,
            'ip_protocol': IP_PROTOCOL,
            'cidr': CIDR
        }

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        api.security_group_rule_create(IsA(http.HttpRequest), SECGROUP_ID,
                                       IP_PROTOCOL, FROM_PORT, TO_PORT,
                                       CIDR).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.post(SG_EDIT_RULE_URL, formData)

        self.assertRedirectsNoFollow(res, SG_EDIT_RULE_URL)
Exemple #2
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()
        exc = novaclient_exceptions.ClientException('ClientException')

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        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(exc)
        self.mox.StubOutWithMock(api, 'security_group_list')
        api.security_group_list(
                        IsA(http.HttpRequest)).AndReturn(sec_group_list)
        self.mox.ReplayAll()

        formData = {'method': 'AddRule',
                    'tenant_id': self.tenant.id,
                    '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)
Exemple #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)
Exemple #4
0
    def test_edit_rules_add_rule(self):
        RULE_ID = '1'
        FROM_PORT = '-1'
        TO_PORT = '-1'
        IP_PROTOCOL = 'icmp'
        CIDR = '0.0.0.0/0'

        new_rule = self.mox.CreateMock(api.SecurityGroup)
        new_rule.from_port = FROM_PORT
        new_rule.to_port = TO_PORT
        new_rule.ip_protocol = IP_PROTOCOL
        new_rule.cidr = CIDR
        new_rule.security_group_id = SECGROUP_ID
        new_rule.id = RULE_ID

        formData = {
            'method': 'AddRule',
            'tenant_id': self.TEST_TENANT,
            'security_group_id': SECGROUP_ID,
            'from_port': FROM_PORT,
            'to_port': TO_PORT,
            'ip_protocol': IP_PROTOCOL,
            'cidr': CIDR
        }

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        api.security_group_rule_create(IsA(http.HttpRequest),
                           SECGROUP_ID, IP_PROTOCOL, FROM_PORT, TO_PORT, CIDR)\
                           .AndReturn(new_rule)

        self.mox.ReplayAll()

        res = self.client.post(SG_EDIT_RULE_URL, formData)

        self.assertRedirectsNoFollow(res, SG_EDIT_RULE_URL)
Exemple #5
0
    def test_edit_rules_add_rule_exception(self):
        exception = novaclient_exceptions.ClientException('ClientException',
                                                  message='ClientException')

        RULE_ID = '1'
        FROM_PORT = '-1'
        TO_PORT = '-1'
        IP_PROTOCOL = 'icmp'
        CIDR = '0.0.0.0/0'

        formData = {'method': 'AddRule',
                    'tenant_id': self.TEST_TENANT,
                    'security_group_id': SECGROUP_ID,
                    'from_port': FROM_PORT,
                    'to_port': TO_PORT,
                    'ip_protocol': IP_PROTOCOL,
                    'cidr': CIDR}

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        api.security_group_rule_create(IsA(http.HttpRequest),
                           SECGROUP_ID, IP_PROTOCOL, FROM_PORT,
                           TO_PORT, CIDR).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.post(SG_EDIT_RULE_URL, formData)

        self.assertRedirectsNoFollow(res, SG_EDIT_RULE_URL)
Exemple #6
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)
Exemple #7
0
    def test_edit_rules_add_rule(self):
        RULE_ID = '1'
        FROM_PORT = '-1'
        TO_PORT = '-1'
        IP_PROTOCOL = 'icmp'
        CIDR = '0.0.0.0/0'

        new_rule = self.mox.CreateMock(api.SecurityGroup)
        new_rule.from_port = FROM_PORT
        new_rule.to_port = TO_PORT
        new_rule.ip_protocol = IP_PROTOCOL
        new_rule.cidr = CIDR
        new_rule.security_group_id = SECGROUP_ID
        new_rule.id = RULE_ID

        formData = {'method': 'AddRule',
                    'tenant_id': self.TEST_TENANT,
                    'security_group_id': SECGROUP_ID,
                    'from_port': FROM_PORT,
                    'to_port': TO_PORT,
                    'ip_protocol': IP_PROTOCOL,
                    'cidr': CIDR}

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        api.security_group_rule_create(IsA(http.HttpRequest),
                           SECGROUP_ID, IP_PROTOCOL, FROM_PORT, TO_PORT, CIDR)\
                           .AndReturn(new_rule)

        self.mox.ReplayAll()

        res = self.client.post(SG_EDIT_RULE_URL, formData)

        self.assertRedirectsNoFollow(res, SG_EDIT_RULE_URL)
Exemple #8
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))
     except:
         exceptions.handle(request,
                           _('Unable to add rule to security group.'))
     return shortcuts.redirect("horizon:nova:access_and_security:index")
 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))
     except novaclient_exceptions.ClientException, e:
         LOG.exception("ClientException in AddRule")
         messages.error(
             request,
             _('Error adding rule security group: %s') % e.message)
Exemple #10
0
    def test_edit_rules_add_rule(self):
        sec_group = self.security_groups.first()
        rule = self.security_group_rules.first()

        self.mox.StubOutWithMock(api, 'security_group_rule_create')
        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']).AndReturn(rule)
        self.mox.ReplayAll()

        formData = {'method': 'AddRule',
                    'tenant_id': self.tenant.id,
                    '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']}
        res = self.client.post(self.edit_url, formData)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemple #11
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'])
         messages.success(request, _('Successfully added rule: %s') \
                                 % unicode(rule))
     except novaclient_exceptions.ClientException, e:
         LOG.exception("ClientException in AddRule")
         messages.error(request, _('Error adding rule security group: %s')
                                  % e.message)
Exemple #12
0
    def handle(self, request, data):
        tenant_id = data['tenant_id']
        try:
            LOG.info('Add security_group_rule: "%s"' % data)

            rule = api.security_group_rule_create(
                request, data['security_group_id'], data['ip_protocol'],
                data['from_port'], data['to_port'], data['cidr'])
            messages.success(request, _('Successfully added rule: %s') \
                                    % rule.id)
        except novaclient_exceptions.ClientException, e:
            LOG.exception("ClientException in AddRule")
            messages.error(
                request,
                _('Error adding rule security group: %s') % e.message)
Exemple #13
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))
     except:
         exceptions.handle(request,
                           _('Unable to add rule to security group.'))
     return shortcuts.redirect("horizon:nova:access_and_security:index")
Exemple #14
0
    def handle(self, request, data):
        try:
            LOG.info('Add security_group_rule: "%s"' % data)

            rule = api.security_group_rule_create(
                request,
                data["security_group_id"],
                data["ip_protocol"],
                data["from_port"],
                data["to_port"],
                data["cidr"],
            )
            messages.success(request, _("Successfully added rule: %s") % unicode(rule))
        except novaclient_exceptions.ClientException, e:
            LOG.exception("ClientException in AddRule")
            messages.error(request, _("Error adding rule security group: %s") % e.message)
Exemple #15
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)
Exemple #16
0
    def handle(self, request, data):
        tenant_id = data['tenant_id']
        try:
            LOG.info('Add security_group_rule: "%s"' % data)

            rule = 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') \
                                    % rule.id)
        except novaclient_exceptions.ClientException, e:
            LOG.exception("ClientException in AddRule")
            messages.error(request, _('Error adding rule security group: %s')
                                     % e.message)