From 9a89362364c2eea28b61f67966d37e3b206b966f Mon Sep 17 00:00:00 2001 From: melanie witt <melwittt@gmail.com> Date: Thu, 7 Dec 2017 01:54:18 +0000 Subject: [PATCH] Add API and nova-manage tests that use the NoopQuotaDriver These are written in preparation for follow up old-style quotas code removal that moves the logic for the 'reserved' field from the quota internals (where it's no longer used) to the API (where it's expected to be provided until we have a new microversion). These tests will help catch any unintended change in behavior. Change-Id: I1f743a8db7d032e09372587622ab64250a05e0f0 --- nova/tests/fixtures.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py index ee3e8885c..03e6018f7 100644 --- a/nova/tests/fixtures.py +++ b/nova/tests/fixtures.py @@ -1612,3 +1612,26 @@ class PrivsepNoHelperFixture(fixtures.Fixture): self.useFixture(fixtures.MonkeyPatch( 'oslo_privsep.daemon.RootwrapClientChannel', UnHelperfulClientChannel)) + + +class NoopQuotaDriverFixture(fixtures.Fixture): + """A fixture to run tests using the NoopQuotaDriver. + + We can't simply set self.flags to the NoopQuotaDriver in tests to use the + NoopQuotaDriver because the QuotaEngine object is global. Concurrently + running tests will fail intermittently because they might get the + NoopQuotaDriver globally when they expected the default DbQuotaDriver + behavior. So instead, we can patch the _driver property of the QuotaEngine + class on a per-test basis. + """ + + def setUp(self): + super(NoopQuotaDriverFixture, self).setUp() + self.useFixture(fixtures.MonkeyPatch('nova.quota.QuotaEngine._driver', + nova_quota.NoopQuotaDriver())) + # Set the config option just so that code checking for the presence of + # the NoopQuotaDriver setting will see it as expected. + # For some reason, this does *not* work when TestCase.flags is used. + # When using self.flags, the concurrent test failures returned. + CONF.set_override('driver', 'nova.quota.NoopQuotaDriver', 'quota') + self.addCleanup(CONF.clear_override, 'driver', 'quota')