Return proper error message when adding security group with no params

* fixes bug 944469

Change-Id: I03ba89de135a2d7e2e9f6359ec652b069e55d089
This commit is contained in:
Andy Chong 2012-03-02 18:47:16 +08:00
parent eb724878fa
commit 9edcc59af4
3 changed files with 21 additions and 3 deletions

View File

@ -1,5 +1,6 @@
aababilov <aababilov@griddynamics.com>
Andrews Medina <andrewsmedina@gmail.com>
Andy Chong <andycjw@gmail.com>
Anthony Young <sleepsonthefloor@gmail.com>
Arvind Somya <asomya@cisco.com>
Carlo Truijllo <truijllo@crs4.it>

View File

@ -31,6 +31,7 @@ from horizon import api
from horizon import exceptions
from horizon import forms
from horizon.utils.validators import validate_ipv4_cidr
from horizon.utils.validators import validate_port_range
LOG = logging.getLogger(__name__)
@ -68,7 +69,8 @@ class AddRule(forms.SelfHandlingForm):
"in the range (-1: 255)"),
widget=forms.TextInput(
attrs={'data': _('From port'),
'data-icmp': _('Type')}))
'data-icmp': _('Type')}),
validators=[validate_port_range])
to_port = forms.IntegerField(label=_("To port"),
help_text=_("TCP/UDP: Enter integer value "
"between 1 and 65535. ICMP: "
@ -76,7 +78,8 @@ class AddRule(forms.SelfHandlingForm):
"in the range (-1: 255)"),
widget=forms.TextInput(
attrs={'data': _('To port'),
'data-icmp': _('Code')}))
'data-icmp': _('Code')}),
validators=[validate_port_range])
cidr = forms.CharField(label=_("CIDR"),
help_text=_("Classless Inter-Domain Routing "
"(i.e. 192.168.0.0/24"),
@ -89,7 +92,15 @@ class AddRule(forms.SelfHandlingForm):
def clean(self):
cleaned_data = super(AddRule, self).clean()
if cleaned_data["to_port"] < cleaned_data["from_port"]:
to_port = cleaned_data.get("to_port", None)
from_port = cleaned_data.get("from_port", None)
if to_port == None:
msg = _('The "to" port number must not be empty.')
raise ValidationError(msg)
if from_port == None:
msg = _('The "from" port number must not be empty.')
raise ValidationError(msg)
if to_port < from_port:
msg = _('The "to" port number must be greater than or equal to '
'the "from" port number.')
raise ValidationError(msg)

View File

@ -17,6 +17,7 @@
import re
from django.core import validators
from django.core.exceptions import ValidationError
ipv4_cidr_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)' # 0-255
@ -25,3 +26,8 @@ ipv4_cidr_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)' # 0-255
validate_ipv4_cidr = validators.RegexValidator(ipv4_cidr_re)
def validate_port_range(port):
if port not in range(-1, 65535):
raise ValidationError(u'%d is not a valid port number' % port)