From 95b4e8f41dbc56911369733a264a20c4affc1173 Mon Sep 17 00:00:00 2001 From: yatinkarel Date: Mon, 20 Nov 2023 12:29:33 +0530 Subject: [PATCH] Make unit tests compatible with neutron-lib-3.9.0 A new flag was added with [1], adapt unit tests with it. Also drop an older compatibility check which is no longer needed as neutron-lib>=3.8.0 already. [1] https://review.opendev.org/c/openstack/neutron-lib/+/895940 Needed-By: https://review.opendev.org/c/openstack/requirements/+/901231 Closes-Bug: #2043959 Change-Id: I3b48b418d2d1293cdcf8fefb1b9ff7005bbebb29 --- neutron/tests/tools.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/neutron/tests/tools.py b/neutron/tests/tools.py index aca89a216b3..d419ebe8f5a 100644 --- a/neutron/tests/tools.py +++ b/neutron/tests/tools.py @@ -19,6 +19,7 @@ import unittest import fixtures import netaddr +from neutron_lib.callbacks import priority_group from neutron_lib import constants from neutron_lib.services.logapi import constants as log_const from neutron_lib.utils import helpers @@ -27,15 +28,15 @@ from oslo_utils import netutils from oslo_utils import timeutils -# NOTE(yamahata): from neutron-lib 1.9.1, callback priority was added and -# priority_group module was added for constants of priority. -# test the existence of the module of priority_group to check if -# callback priority is supported or not. -_CALLBACK_PRIORITY_SUPPORTED = True +# NOTE(ykarel): from neutron-lib 3.9.0, cancellable flag was added +# test the existence of the is_cancellable_event function to check if +# cancellable flag is supported or not. This compatibility check can +# be removed once neutron-lib >= 3.9.0 in requirements.txt. +_CANCELLABLE_FLAG_SUPPORTED = True try: - from neutron_lib.callbacks import priority_group # noqa + from neutron_lib.callbacks.events import is_cancellable_event # noqa except ImportError: - _CALLBACK_PRIORITY_SUPPORTED = False + _CANCELLABLE_FLAG_SUPPORTED = False LAST_RANDOM_PORT_RANGE_GENERATED = 1 @@ -146,12 +147,14 @@ def make_mock_plugin_json_encodable(plugin_instance_mock): def get_subscribe_args(*args): - # NOTE(yamahata): from neutron-lib 1.9.1, callback priority was added. - # old signature: (callback, resource, event) - # new signature: (callback, resource, event, priority=PRIORITY_DEFAULT) - if len(args) == 3 and _CALLBACK_PRIORITY_SUPPORTED: - args = list(args) # don't modify original list - args.append(priority_group.PRIORITY_DEFAULT) + args = list(args) # don't modify original list + args.append(priority_group.PRIORITY_DEFAULT) + # NOTE(ykarel): from neutron-lib 3.9.0, cancellable flag was added. + # old signature: (callback, resource, event, priority=PRIORITY_DEFAULT) + # new signature: (callback, resource, event, priority=PRIORITY_DEFAULT, + # cancellable=False) + if len(args) == 4 and _CANCELLABLE_FLAG_SUPPORTED: + args.append(False) return args