Merge "Modify the error message when creating subnet"

This commit is contained in:
Zuul 2019-01-23 14:32:56 +00:00 committed by Gerrit Code Review
commit 4cb09d1d7f
2 changed files with 10 additions and 5 deletions

View File

@ -41,7 +41,7 @@ class CreateSubnetInfoAction(network_workflows.CreateSubnetInfoAction):
def clean(self):
cleaned_data = workflows.Action.clean(self)
self._check_subnet_data(cleaned_data)
self._check_subnet_data(cleaned_data, with_network_form=False)
return cleaned_data
@ -114,7 +114,8 @@ class UpdateSubnetInfoAction(CreateSubnetInfoAction):
def clean(self):
cleaned_data = workflows.Action.clean(self)
self._check_subnet_data(cleaned_data, is_create=False)
self._check_subnet_data(cleaned_data, is_create=False,
with_network_form=False)
return cleaned_data

View File

@ -279,7 +279,8 @@ class CreateSubnetInfoAction(workflows.Action):
'allowed': range_str})
raise forms.ValidationError(msg)
def _check_subnet_data(self, cleaned_data, is_create=True):
def _check_subnet_data(self, cleaned_data, is_create=True,
with_network_form=True):
cidr = cleaned_data.get('cidr')
ip_version = int(cleaned_data.get('ip_version'))
gateway_ip = cleaned_data.get('gateway_ip')
@ -293,8 +294,11 @@ class CreateSubnetInfoAction(workflows.Action):
'"Network Address".')
raise forms.ValidationError(msg)
if not cidr and address_source != 'subnetpool':
msg = _('Specify "Network Address" or '
'clear "Create Subnet" checkbox in previous step.')
if with_network_form:
msg = _('Specify "Network Address" or '
'clear "Create Subnet" checkbox in previous step.')
else:
msg = _("Specify network address")
raise forms.ValidationError(msg)
if cidr:
subnet = netaddr.IPNetwork(cidr)