Browse Source

Ignore error msg for gateway IP when gateway is disabled

Although the gateway is disabled,
it still checks the format of the gateway ip and
throws an error if there is a problem with the format.

Change-Id: I8d13819175701885412ab4813e19aba0ac63a3c3
Closes-Bug: #1799896
pengyuesheng 5 months ago
parent
commit
a8006b4441

+ 47
- 2
openstack_dashboard/dashboards/project/networks/tests.py View File

@@ -39,7 +39,8 @@ def form_data_subnet(subnet,
39 39
                      gateway_ip='', enable_dhcp=None,
40 40
                      allocation_pools=None,
41 41
                      dns_nameservers=None,
42
-                     host_routes=None):
42
+                     host_routes=None,
43
+                     no_gateway=None):
43 44
     def get_value(value, default):
44 45
         return default if value is None else value
45 46
 
@@ -50,7 +51,7 @@ def form_data_subnet(subnet,
50 51
 
51 52
     gateway_ip = subnet.gateway_ip if gateway_ip == '' else gateway_ip
52 53
     data['gateway_ip'] = gateway_ip or ''
53
-    data['no_gateway'] = (gateway_ip is None)
54
+    data['no_gateway'] = no_gateway or (gateway_ip is None)
54 55
 
55 56
     data['enable_dhcp'] = get_value(enable_dhcp, subnet.enable_dhcp)
56 57
     if data['ip_version'] == 6:
@@ -906,6 +907,50 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
906 907
         self.test_network_create_post_with_subnet_gw_inconsistent(
907 908
             test_with_subnetpool=True)
908 909
 
910
+    @test.create_mocks({api.neutron: ('network_create',
911
+                                      'subnet_create',
912
+                                      'is_extension_supported',
913
+                                      'subnetpool_list')})
914
+    def test_network_create_post_with_subnet_ignore_error_msg_for_gateway(
915
+            self):
916
+        network = self.networks.first()
917
+        subnet = self.subnets.first()
918
+        params = {'name': network.name,
919
+                  'admin_state_up': network.admin_state_up,
920
+                  'shared': False}
921
+
922
+        self._stub_is_extension_supported({'network_availability_zone': False,
923
+                                           'subnet_allocation': True})
924
+        self.mock_subnetpool_list.return_value = self.subnetpools.list()
925
+        self.mock_network_create.return_value = network
926
+        self.mock_subnet_create.return_value = subnet
927
+
928
+        form_data = {'net_name': network.name,
929
+                     'admin_state': network.admin_state_up,
930
+                     'shared': False,
931
+                     'with_subnet': True}
932
+        subnet_params = {'network_id': network.id,
933
+                         'name': subnet.name,
934
+                         'cidr': subnet.cidr,
935
+                         'ip_version': subnet.ip_version,
936
+                         'gateway_ip': None,
937
+                         'enable_dhcp': subnet.enable_dhcp}
938
+        form_data.update(form_data_subnet(subnet, allocation_pools=[],
939
+                                          no_gateway=True, gateway_ip="."))
940
+        url = reverse('horizon:project:networks:create')
941
+        res = self.client.post(url, form_data)
942
+        self.assertNoWorkflowErrors(res)
943
+        self.assertRedirectsNoFollow(res, INDEX_URL)
944
+
945
+        self.mock_subnetpool_list.assert_called_once_with(test.IsHttpRequest())
946
+        self.mock_network_create.assert_called_once_with(
947
+            test.IsHttpRequest(), **params)
948
+        self.mock_subnet_create.assert_called_once_with(
949
+            test.IsHttpRequest(),
950
+            **subnet_params)
951
+        self._check_is_extension_supported({'network_availability_zone': 1,
952
+                                            'subnet_allocation': 1})
953
+
909 954
     @test.create_mocks({api.neutron: ('network_get',)})
910 955
     def test_network_update_get(self):
911 956
         network = self.networks.first()

+ 2
- 0
openstack_dashboard/dashboards/project/networks/workflows.py View File

@@ -316,6 +316,8 @@ class CreateSubnetInfoAction(workflows.Action):
316 316
             msg = _('Specify IP address of gateway or '
317 317
                     'check "Disable Gateway" checkbox.')
318 318
             raise forms.ValidationError(msg)
319
+        if no_gateway and 'gateway_ip' in self._errors:
320
+            del self._errors['gateway_ip']
319 321
 
320 322
     def clean(self):
321 323
         cleaned_data = super(CreateSubnetInfoAction, self).clean()

+ 15
- 0
openstack_dashboard/test/helpers.py View File

@@ -385,6 +385,21 @@ class TestCase(horizon_helpers.TestCase):
385 385
         self.assertEqual(count, mocked_method.call_count)
386 386
         mocked_method.assert_has_calls([expected_call] * count)
387 387
 
388
+    def assertNoWorkflowErrors(self, response, context_name="workflow"):
389
+        """Checks for no workflow errors.
390
+
391
+        Asserts that the response either does not contain a workflow in its
392
+        context, or that if it does, that workflow has no errors.
393
+        """
394
+        context = getattr(response, "context", {})
395
+        if not context or context_name not in context:
396
+            return True
397
+        errors = [step.action._errors for step in
398
+                  response.context[context_name].steps]
399
+        self.assertEqual(
400
+            0, len(errors),
401
+            "Unexpected errors were found on the workflow: %s" % errors)
402
+
388 403
 
389 404
 class BaseAdminViewTests(TestCase):
390 405
     """Sets an active user with the "admin" role.

Loading…
Cancel
Save