Check unspecified flavor in user defined driver

In order to decide whether to process a router related
request, the user defined router flavor OVN driver needs to
check the flavor_id specified in the request. This change adds
the code to test the case when the API passed the flavor_id as
unspecified.

Change-Id: I4d7d9d5582b97246cad63ef7f5511b159d6c6791
Closes-Bug: #2059051
(cherry picked from commit 9d729bda20)
This commit is contained in:
Miguel Lavalle 2024-03-25 17:30:01 -05:00 committed by Rodolfo Alonso Hernandez
parent 0eccc52f82
commit d683804dfa
2 changed files with 11 additions and 1 deletions

View File

@ -16,6 +16,7 @@
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import constants as const
from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory
from oslo_log import log as logging
@ -44,7 +45,7 @@ class UserDefined(base.L3ServiceProvider):
def _is_user_defined_provider(self, context, router):
flavor_id = router.get('flavor_id')
if flavor_id is None:
if flavor_id is None or flavor_id is const.ATTR_NOT_SPECIFIED:
return False
flavor = self._flavor_plugin.get_flavor(context, flavor_id)
provider = self._flavor_plugin.get_flavor_next_provider(

View File

@ -14,6 +14,7 @@
from unittest import mock
from neutron_lib.callbacks import events
from neutron_lib import constants as const
from neutron.db.models import l3
@ -56,6 +57,14 @@ class TestUserDefined(testlib_api.SqlTestCase):
self.assertFalse(self.provider._is_user_defined_provider(
self.context, self.router))
# test flavor_id request not specified
self.router.flavor_id = None
self.assertFalse(self.provider._is_user_defined_provider(
self.context, self.router))
self.router.flavor_id = const.ATTR_NOT_SPECIFIED
self.assertFalse(self.provider._is_user_defined_provider(
self.context, self.router))
def test_router_processing(self):
with mock.patch.object(user_defined.LOG, 'debug') as log:
payload = events.DBEventPayload(