From d53372790435a003723a29cb15ac044b014a0e89 Mon Sep 17 00:00:00 2001 From: melanie witt Date: Wed, 1 Mar 2023 23:57:25 +0000 Subject: testing: Reset affinity support global variables Ran into this randomly today, if a test sets CONF.scheduler.enabled_filters to a non-default value, the affinity support global variables will be set to False which can affect subsequent test runs that expect the default configuration (affinity filter support enabled). Example error: WARNING [nova.scheduler.utils] Failed to compute_task_build_instances: ServerGroup policy is not supported: ServerGroupAffinityFilter not configured This resets the global variables during base test setup, similar to how other globals are reset. Change-Id: Icbc75b1001c0a609280241f99a780313b244aa9d --- nova/scheduler/utils.py | 11 +++++++++++ nova/test.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/nova/scheduler/utils.py b/nova/scheduler/utils.py index c7e6ffed97..02c44093bd 100644 --- a/nova/scheduler/utils.py +++ b/nova/scheduler/utils.py @@ -1080,6 +1080,17 @@ _SUPPORTS_SOFT_AFFINITY = None _SUPPORTS_SOFT_ANTI_AFFINITY = None +def reset_globals(): + global _SUPPORTS_AFFINITY + _SUPPORTS_AFFINITY = None + global _SUPPORTS_ANTI_AFFINITY + _SUPPORTS_ANTI_AFFINITY = None + global _SUPPORTS_SOFT_AFFINITY + _SUPPORTS_SOFT_AFFINITY = None + global _SUPPORTS_SOFT_ANTI_AFFINITY + _SUPPORTS_SOFT_ANTI_AFFINITY = None + + def _get_group_details(context, instance_uuid, user_group_hosts=None): """Provide group_hosts and group_policies sets related to instances if those instances are belonging to a group and if corresponding filters are diff --git a/nova/test.py b/nova/test.py index 0f7965ea33..e37967b06d 100644 --- a/nova/test.py +++ b/nova/test.py @@ -62,6 +62,7 @@ from nova import objects from nova.objects import base as objects_base from nova import quota from nova.scheduler.client import report +from nova.scheduler import utils as scheduler_utils from nova.tests import fixtures as nova_fixtures from nova.tests.unit import matchers from nova import utils @@ -310,6 +311,12 @@ class TestCase(base.BaseTestCase): if self.STUB_COMPUTE_ID: self.useFixture(nova_fixtures.ComputeNodeIdFixture()) + # Reset globals indicating affinity filter support. Some tests may set + # self.flags(enabled_filters=...) which could make the affinity filter + # support globals get set to a non-default configuration which affects + # all other tests. + scheduler_utils.reset_globals() + def _setup_cells(self): """Setup a normal cellsv2 environment. -- cgit v1.2.1