diff --git a/openstack_dashboard/dashboards/admin/networks/subnets/tests.py b/openstack_dashboard/dashboards/admin/networks/subnets/tests.py index 0e71f725ca..8b889f7228 100644 --- a/openstack_dashboard/dashboards/admin/networks/subnets/tests.py +++ b/openstack_dashboard/dashboards/admin/networks/subnets/tests.py @@ -126,9 +126,8 @@ class NetworkSubnetTests(test.BaseAdminViewTests): redir_url = reverse(NETWORKS_DETAIL_URL, args=[subnet.network_id]) self.assertRedirectsNoFollow(res, redir_url) - self.assert_mock_multiple_calls_with_same_arguments( - self.mock_network_get, 2, - mock.call(test.IsHttpRequest(), network.id)) + self.mock_network_get.assert_called_once_with(test.IsHttpRequest(), + network.id) self._check_is_extension_supported({'subnet_allocation': 1}) self.mock_subnetpool_list.assert_called_once_with(test.IsHttpRequest()) self.mock_subnet_create.assert_called_once_with( @@ -184,9 +183,8 @@ class NetworkSubnetTests(test.BaseAdminViewTests): redir_url = reverse(NETWORKS_DETAIL_URL, args=[subnet.network_id]) self.assertRedirectsNoFollow(res, redir_url) - self.assert_mock_multiple_calls_with_same_arguments( - self.mock_network_get, 2, - mock.call(test.IsHttpRequest(), network.id)) + self.mock_network_get.assert_called_once_with(test.IsHttpRequest(), + network.id) self._check_is_extension_supported({'subnet_allocation': 1}) self.mock_subnetpool_list.assert_called_once_with(test.IsHttpRequest()) self.mock_subnet_create.assert_called_once_with( diff --git a/openstack_dashboard/dashboards/admin/networks/subnets/workflows.py b/openstack_dashboard/dashboards/admin/networks/subnets/workflows.py index 72e2521058..cec55876a8 100644 --- a/openstack_dashboard/dashboards/admin/networks/subnets/workflows.py +++ b/openstack_dashboard/dashboards/admin/networks/subnets/workflows.py @@ -17,9 +17,6 @@ import logging from django.urls import reverse from django.utils.translation import ugettext_lazy as _ -from horizon import exceptions - -from openstack_dashboard import api from openstack_dashboard.dashboards.project.networks.subnets \ import workflows as project_workflows from openstack_dashboard.dashboards.project.networks import workflows \ @@ -52,27 +49,21 @@ class CreateSubnet(project_workflows.CreateSubnet): def get_success_url(self): return reverse("horizon:admin:networks:detail", - args=(self.context.get('network_id'),)) + args=(self.context['network'].id,)) def get_failure_url(self): return reverse("horizon:admin:networks:detail", - args=(self.context.get('network_id'),)) + args=(self.context['network'].id,)) def handle(self, request, data): - try: - # We must specify tenant_id of the network which a subnet is - # created for if admin user does not belong to the tenant. - network = api.neutron.network_get(request, - self.context['network_id']) - except Exception as e: - LOG.info('Failed to retrieve network %(id)s for a subnet: %(exc)s', - {'id': data['network_id'], 'exc': e}) - msg = (_('Failed to retrieve network %s for a subnet') % - data['network_id']) - redirect = self.get_failure_url() - exceptions.handle(request, msg, redirect=redirect) - subnet = self._create_subnet(request, data, - tenant_id=network.tenant_id) + network = self.context_seed['network'] + # NOTE: network argument is required to show error message correctly. + # NOTE: We must specify tenant_id of the network which a subnet is + # created for if admin user does not belong to the tenant. + subnet = self._create_subnet( + request, data, + network=network, + tenant_id=network.tenant_id) return True if subnet else False diff --git a/openstack_dashboard/dashboards/project/networks/subnets/tests.py b/openstack_dashboard/dashboards/project/networks/subnets/tests.py index 518a324007..598a3c091c 100644 --- a/openstack_dashboard/dashboards/project/networks/subnets/tests.py +++ b/openstack_dashboard/dashboards/project/networks/subnets/tests.py @@ -185,7 +185,7 @@ class NetworkSubnetTests(test.TestCase): def test_subnet_create_post_with_additional_attributes(self): network = self.networks.list()[1] subnet = self.subnets.list()[2] - self.mock_network_get.return_value = self.networks.first() + self.mock_network_get.return_value = network self.mock_is_extension_supported.return_value = True self.mock_subnetpool_list.return_value = self.subnetpools.list() self.mock_subnet_create.return_value = subnet diff --git a/openstack_dashboard/dashboards/project/networks/subnets/views.py b/openstack_dashboard/dashboards/project/networks/subnets/views.py index 0ab085da38..13e54c57eb 100644 --- a/openstack_dashboard/dashboards/project/networks/subnets/views.py +++ b/openstack_dashboard/dashboards/project/networks/subnets/views.py @@ -52,8 +52,7 @@ class CreateView(DefaultSubnetWorkflowMixin, workflows.WorkflowView): def get_initial(self): network = self.get_object() - return {"network_id": self.kwargs['network_id'], - "network_name": network.name_or_id, + return {"network": network, "dns_nameservers": self.get_default_dns_servers()} diff --git a/openstack_dashboard/dashboards/project/networks/subnets/workflows.py b/openstack_dashboard/dashboards/project/networks/subnets/workflows.py index ae7dd9cd5a..9e1ab9b3b4 100644 --- a/openstack_dashboard/dashboards/project/networks/subnets/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/subnets/workflows.py @@ -50,7 +50,7 @@ class CreateSubnetInfoAction(network_workflows.CreateSubnetInfoAction): class CreateSubnetInfo(network_workflows.CreateSubnetInfo): action_class = CreateSubnetInfoAction - depends_on = ("network_id",) + depends_on = ("network",) class CreateSubnet(network_workflows.CreateNetwork): @@ -68,14 +68,16 @@ class CreateSubnet(network_workflows.CreateNetwork): def get_success_url(self): return reverse("horizon:project:networks:detail", - args=(self.context.get('network_id'),)) + args=(self.context['network'].id,)) def get_failure_url(self): return reverse("horizon:project:networks:detail", - args=(self.context.get('network_id'),)) + args=(self.context['network'].id,)) def handle(self, request, data): - subnet = self._create_subnet(request, data) + network = self.context_seed['network'] + # network argument is required to show error message correctly. + subnet = self._create_subnet(request, data, network=network) return True if subnet else False