diff --git a/openstack_dashboard/dashboards/project/networks/tests.py b/openstack_dashboard/dashboards/project/networks/tests.py index 19038e77626..2771bc5017b 100644 --- a/openstack_dashboard/dashboards/project/networks/tests.py +++ b/openstack_dashboard/dashboards/project/networks/tests.py @@ -364,6 +364,21 @@ def test_network_create_post_with_subnet_nocidr(self): self.assertContains(res, escape('Specify "Network Address" or ' 'clear "Create Subnet" checkbox.')) + def test_network_create_post_with_subnet_cidr_without_mask(self): + network = self.networks.first() + subnet = self.subnets.first() + + form_data = {'net_name': network.name, + 'admin_state': network.admin_state_up, + 'with_subnet': True} + form_data.update(form_data_subnet(subnet, cidr='10.0.0.0', + allocation_pools=[])) + url = reverse('horizon:project:networks:create') + res = self.client.post(url, form_data) + + expected_msg = "The subnet in the Network Address is too small (/32)." + self.assertContains(res, expected_msg) + def test_network_create_post_with_subnet_cidr_inconsistent(self): network = self.networks.first() subnet = self.subnets.first() diff --git a/openstack_dashboard/dashboards/project/networks/workflows.py b/openstack_dashboard/dashboards/project/networks/workflows.py index 41283ece9a2..74b07e924cd 100644 --- a/openstack_dashboard/dashboards/project/networks/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/workflows.py @@ -104,9 +104,15 @@ def _check_subnet_data(self, cleaned_data, is_create=True): 'clear "Create Subnet" checkbox.') raise forms.ValidationError(msg) if cidr: - if netaddr.IPNetwork(cidr).version is not ip_version: + subnet = netaddr.IPNetwork(cidr) + if subnet.version != ip_version: msg = _('Network Address and IP version are inconsistent.') raise forms.ValidationError(msg) + if (ip_version == 4 and subnet.prefixlen == 32) or \ + (ip_version == 6 and subnet.prefixlen == 128): + msg = _("The subnet in the Network Address is too small (/%s)." + % subnet.prefixlen) + raise forms.ValidationError(msg) if not no_gateway and gateway_ip: if netaddr.IPAddress(gateway_ip).version is not ip_version: msg = _('Gateway IP and IP version are inconsistent.')