From 5c35a5905e03f7d45c3d99ceccdfffc67a171bd7 Mon Sep 17 00:00:00 2001 From: Sylvain Bauza Date: Fri, 19 Feb 2021 18:51:10 +0100 Subject: [PATCH] FUP: Catch and reraise routed nets exception Based on review feedback, we prefer to have the exception for routed networks to not be prefilter-specific and just reraise with the right exception type in the prefilter. Change-Id: I9ccbbf3be8efc65fe7f480ad545fb5fc70767988 --- nova/exception.py | 2 +- nova/scheduler/request_filter.py | 18 ++++++++++++++---- nova/tests/functional/test_routed_networks.py | 7 ++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/nova/exception.py b/nova/exception.py index e48b7bcfb21d..d5696690f37f 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -1195,7 +1195,7 @@ class RequestFilterFailed(NovaException): msg_fmt = _("Scheduling failed: %(reason)s") -class InvalidRoutedNetworkConfiguration(RequestFilterFailed): +class InvalidRoutedNetworkConfiguration(NovaException): msg_fmt = _("Neutron routed networks configuration is invalid: " "%(reason)s.") diff --git a/nova/scheduler/request_filter.py b/nova/scheduler/request_filter.py index 9095bec33817..f837efe65339 100644 --- a/nova/scheduler/request_filter.py +++ b/nova/scheduler/request_filter.py @@ -326,8 +326,13 @@ def routed_networks_filter( # subnets than only one but given they would be for the same # port, just looking at the first subnet is needed. subnet_id = port['fixed_ips'][0]['subnet_id'] - aggregates = utils.get_aggregates_for_routed_subnet( - ctxt, network_api, report_api, subnet_id) + try: + aggregates = utils.get_aggregates_for_routed_subnet( + ctxt, network_api, report_api, subnet_id) + except exception.InvalidRoutedNetworkConfiguration as e: + raise exception.RequestFilterFailed( + reason=_('Aggregates not found for the subnet %s' + ) % subnet_id) from e else: # The port was just created without a subnet. network_id = port["network_id"] @@ -339,8 +344,13 @@ def routed_networks_filter( if network_id: # As the user only requested a network or a port unbound to a # segment, we are free to choose any segment from the network. - aggregates = utils.get_aggregates_for_routed_network( - ctxt, network_api, report_api, network_id) + try: + aggregates = utils.get_aggregates_for_routed_network( + ctxt, network_api, report_api, network_id) + except exception.InvalidRoutedNetworkConfiguration as e: + raise exception.RequestFilterFailed( + reason=_('Aggregates not found for the network %s' + ) % network_id) from e if aggregates: LOG.debug( diff --git a/nova/tests/functional/test_routed_networks.py b/nova/tests/functional/test_routed_networks.py index a958b89e4cce..19c5d3c59f2b 100644 --- a/nova/tests/functional/test_routed_networks.py +++ b/nova/tests/functional/test_routed_networks.py @@ -518,11 +518,12 @@ class RoutedNetworkTests(integrated_helpers._IntegratedTestBase): # Make sure we correctly looked up at which aggregates were related to # the segment ID #2 - exp_segment_id = self.neutron.segment_id_2['id'] + expected_subnet_id = self.neutron.subnet_for_segment_id_2['id'] + expected_segment_id = self.neutron.segment_id_2['id'] mock_get_aggregates.assert_called_once_with( - mock.ANY, exp_segment_id) + mock.ANY, expected_segment_id) self.assertIn('No valid host', server['fault']['message']) self.assertIn( - 'Failed to find aggregate related to segment %s' % exp_segment_id, + 'Aggregates not found for the subnet %s' % expected_subnet_id, server['fault']['message'])