Skip to content

Commit d533727

Browse files
committed
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
1 parent 6b0b009 commit d533727

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

nova/scheduler/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,17 @@ def validate_weigher(weigher):
10801080
_SUPPORTS_SOFT_ANTI_AFFINITY = None
10811081

10821082

1083+
def reset_globals():
1084+
global _SUPPORTS_AFFINITY
1085+
_SUPPORTS_AFFINITY = None
1086+
global _SUPPORTS_ANTI_AFFINITY
1087+
_SUPPORTS_ANTI_AFFINITY = None
1088+
global _SUPPORTS_SOFT_AFFINITY
1089+
_SUPPORTS_SOFT_AFFINITY = None
1090+
global _SUPPORTS_SOFT_ANTI_AFFINITY
1091+
_SUPPORTS_SOFT_ANTI_AFFINITY = None
1092+
1093+
10831094
def _get_group_details(context, instance_uuid, user_group_hosts=None):
10841095
"""Provide group_hosts and group_policies sets related to instances if
10851096
those instances are belonging to a group and if corresponding filters are

nova/test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from nova.objects import base as objects_base
6363
from nova import quota
6464
from nova.scheduler.client import report
65+
from nova.scheduler import utils as scheduler_utils
6566
from nova.tests import fixtures as nova_fixtures
6667
from nova.tests.unit import matchers
6768
from nova import utils
@@ -310,6 +311,12 @@ def setUp(self):
310311
if self.STUB_COMPUTE_ID:
311312
self.useFixture(nova_fixtures.ComputeNodeIdFixture())
312313

314+
# Reset globals indicating affinity filter support. Some tests may set
315+
# self.flags(enabled_filters=...) which could make the affinity filter
316+
# support globals get set to a non-default configuration which affects
317+
# all other tests.
318+
scheduler_utils.reset_globals()
319+
313320
def _setup_cells(self):
314321
"""Setup a normal cellsv2 environment.
315322

0 commit comments

Comments
 (0)