summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpengyuesheng <pengyuesheng@gohighsec.com>2018-10-25 15:54:13 +0800
committerpengyuesheng <pengyuesheng@gohighsec.com>2018-11-13 16:18:45 +0800
commita8006b44411577a856b0144bb3da57492dd56d0a (patch)
treee31978a7220a6e88ee603b056db44543fdc30f43
parent51869de19d45f66df9f1373900ba41401bd1ba3f (diff)
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
Notes
Notes (review): Code-Review+2: Radomir Dopieralski <openstack@sheep.art.pl> Code-Review+2: Akihiro Motoki <amotoki@gmail.com> Workflow+1: Akihiro Motoki <amotoki@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 13 Nov 2018 16:24:55 +0000 Reviewed-on: https://review.openstack.org/613237 Project: openstack/horizon Branch: refs/heads/master
-rw-r--r--openstack_dashboard/dashboards/project/networks/tests.py49
-rw-r--r--openstack_dashboard/dashboards/project/networks/workflows.py2
-rw-r--r--openstack_dashboard/test/helpers.py15
3 files changed, 64 insertions, 2 deletions
diff --git a/openstack_dashboard/dashboards/project/networks/tests.py b/openstack_dashboard/dashboards/project/networks/tests.py
index 049e5d4..afc878a 100644
--- a/openstack_dashboard/dashboards/project/networks/tests.py
+++ b/openstack_dashboard/dashboards/project/networks/tests.py
@@ -39,7 +39,8 @@ def form_data_subnet(subnet,
39 gateway_ip='', enable_dhcp=None, 39 gateway_ip='', enable_dhcp=None,
40 allocation_pools=None, 40 allocation_pools=None,
41 dns_nameservers=None, 41 dns_nameservers=None,
42 host_routes=None): 42 host_routes=None,
43 no_gateway=None):
43 def get_value(value, default): 44 def get_value(value, default):
44 return default if value is None else value 45 return default if value is None else value
45 46
@@ -50,7 +51,7 @@ def form_data_subnet(subnet,
50 51
51 gateway_ip = subnet.gateway_ip if gateway_ip == '' else gateway_ip 52 gateway_ip = subnet.gateway_ip if gateway_ip == '' else gateway_ip
52 data['gateway_ip'] = gateway_ip or '' 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 data['enable_dhcp'] = get_value(enable_dhcp, subnet.enable_dhcp) 56 data['enable_dhcp'] = get_value(enable_dhcp, subnet.enable_dhcp)
56 if data['ip_version'] == 6: 57 if data['ip_version'] == 6:
@@ -906,6 +907,50 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
906 self.test_network_create_post_with_subnet_gw_inconsistent( 907 self.test_network_create_post_with_subnet_gw_inconsistent(
907 test_with_subnetpool=True) 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 @test.create_mocks({api.neutron: ('network_get',)}) 954 @test.create_mocks({api.neutron: ('network_get',)})
910 def test_network_update_get(self): 955 def test_network_update_get(self):
911 network = self.networks.first() 956 network = self.networks.first()
diff --git a/openstack_dashboard/dashboards/project/networks/workflows.py b/openstack_dashboard/dashboards/project/networks/workflows.py
index 8106778..391d4ce 100644
--- a/openstack_dashboard/dashboards/project/networks/workflows.py
+++ b/openstack_dashboard/dashboards/project/networks/workflows.py
@@ -316,6 +316,8 @@ class CreateSubnetInfoAction(workflows.Action):
316 msg = _('Specify IP address of gateway or ' 316 msg = _('Specify IP address of gateway or '
317 'check "Disable Gateway" checkbox.') 317 'check "Disable Gateway" checkbox.')
318 raise forms.ValidationError(msg) 318 raise forms.ValidationError(msg)
319 if no_gateway and 'gateway_ip' in self._errors:
320 del self._errors['gateway_ip']
319 321
320 def clean(self): 322 def clean(self):
321 cleaned_data = super(CreateSubnetInfoAction, self).clean() 323 cleaned_data = super(CreateSubnetInfoAction, self).clean()
diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py
index 83ba308..d1c7eea 100644
--- a/openstack_dashboard/test/helpers.py
+++ b/openstack_dashboard/test/helpers.py
@@ -385,6 +385,21 @@ class TestCase(horizon_helpers.TestCase):
385 self.assertEqual(count, mocked_method.call_count) 385 self.assertEqual(count, mocked_method.call_count)
386 mocked_method.assert_has_calls([expected_call] * count) 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
389class BaseAdminViewTests(TestCase): 404class BaseAdminViewTests(TestCase):
390 """Sets an active user with the "admin" role. 405 """Sets an active user with the "admin" role.