Fix ValueError when running with zed cinder

When using the stable/zed cinder branch and zed upper-constraints,
we're getting a bunch of "ValueError: Backend named fake_backend
already exists with a different configuration" in unit tests.  The
backend name is set in the test setUp(), but it looks like isolation
isn't being respected, maybe because the Backend instantiation uses
a singleton pattern.  (Which doesn't, however, explain why this was
working previously.)  Address this by giving each test backend a
unique name.

Change-Id: I469b4b9dd9966be8477f3cefbd6284bdaf17ca17
This commit is contained in:
Brian Rosmaita 2022-12-07 13:13:00 -05:00
parent e4da0146a5
commit b1db48c6ed
2 changed files with 2 additions and 2 deletions

View File

@ -45,7 +45,7 @@ class BaseTest(unittest.TestCase):
if not self.PERSISTENCE_CFG:
cfg = {'storage': utils.get_mock_persistence()}
cinderlib.Backend.set_persistence(cfg)
self.backend_name = 'fake_backend'
self.backend_name = 'fake_backend_%s' % id(self)
self.backend = utils.FakeBackend(volume_backend_name=self.backend_name)
self.persistence = self.backend.persistence
cinderlib.Backend._volumes_inflight = {}

View File

@ -398,7 +398,7 @@ class TestCinderlib(base.BaseTest):
def test_stats_single(self):
stat_value = {'driver_version': 'v1', 'key': 'value'}
expect = {'driver_version': 'v1', 'key': 'value',
'pools': [{'key': 'value', 'pool_name': 'fake_backend'}]}
'pools': [{'key': 'value', 'pool_name': self.backend_name}]}
with mock.patch.object(self.backend.driver, 'get_volume_stats',
return_value=stat_value) as mock_stat:
res = self.backend.stats(mock.sentinel.refresh)