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
This commit is contained in:
melanie witt 2017-12-07 01:54:18 +00:00
parent 82acee044e
commit 93ceb7fb5e
23 changed files with 477 additions and 0 deletions

View File

@ -0,0 +1,20 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"id": "fake_tenant",
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,80 @@
{
"quota_set": {
"cores": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"fixed_ips": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"floating_ips": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"id": "fake_tenant",
"injected_file_content_bytes": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"injected_file_path_bytes": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"injected_files": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"instances": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"key_pairs": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"metadata_items": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"networks": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"ram": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"security_group_rules": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"security_groups": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"server_group_members": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"server_groups": {
"in_use": -1,
"limit": -1,
"reserved": -1
}
}
}

View File

@ -0,0 +1,20 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"id": "fake_tenant",
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,6 @@
{
"quota_set": {
"force": "True",
"instances": 45
}
}

View File

@ -0,0 +1,19 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,5 @@
{
"quota_set": {
"security_groups": 45
}
}

View File

@ -0,0 +1,19 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,20 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"id": "fake_tenant",
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,6 @@
{
"quota_set": {
"force": "True",
"instances": 9
}
}

View File

@ -0,0 +1,19 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -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')

View File

@ -0,0 +1,20 @@
{
"quota_set": {
"cores": -1,
"floating_ips": -1,
"fixed_ips": -1,
"id": "fake_tenant",
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_groups": -1,
"server_group_members": -1,
"networks": -1
}
}

View File

@ -0,0 +1,80 @@
{
"quota_set": {
"cores": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"fixed_ips": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"floating_ips": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"id": "fake_tenant",
"injected_file_content_bytes": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"injected_file_path_bytes": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"injected_files": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"instances": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"key_pairs": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"metadata_items": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"networks": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"ram": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"security_group_rules": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"security_groups": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"server_group_members": {
"in_use": -1,
"limit": -1,
"reserved": -1
},
"server_groups": {
"in_use": -1,
"limit": -1,
"reserved": -1
}
}
}

View File

@ -0,0 +1,20 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"id": "fake_tenant",
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,6 @@
{
"quota_set": {
"force": "True",
"instances": 45
}
}

View File

@ -0,0 +1,19 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,5 @@
{
"quota_set": {
"security_groups": 45
}
}

View File

@ -0,0 +1,19 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,20 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"id": "fake_tenant",
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -0,0 +1,6 @@
{
"quota_set": {
"force": "True",
"instances": 9
}
}

View File

@ -0,0 +1,19 @@
{
"quota_set": {
"cores": -1,
"fixed_ips": -1,
"floating_ips": -1,
"injected_file_content_bytes": -1,
"injected_file_path_bytes": -1,
"injected_files": -1,
"instances": -1,
"key_pairs": -1,
"metadata_items": -1,
"networks": -1,
"ram": -1,
"security_group_rules": -1,
"security_groups": -1,
"server_group_members": -1,
"server_groups": -1
}
}

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.tests import fixtures as nova_fixtures
from nova.tests.functional.api_sample_tests import api_sample_base
@ -80,3 +81,14 @@ class QuotaSetsSampleJsonTests(api_sample_base.ApiSampleTestBaseV21):
class QuotaSetsSampleJsonTests2_36(QuotaSetsSampleJsonTests):
microversion = '2.36'
scenarios = [('v2_36', {'api_major_version': 'v2.1'})]
class NoopQuotaSetsSampleJsonTests(QuotaSetsSampleJsonTests):
sample_dir = "os-quota-sets-noop"
def setUp(self):
super(NoopQuotaSetsSampleJsonTests, self).setUp()
# NOTE(melwitt): We can't simply set self.flags to the NoopQuotaDriver
# here to use the driver because the QuotaEngine is global. See the
# fixture for details.
self.useFixture(nova_fixtures.NoopQuotaDriverFixture())

View File

@ -390,6 +390,20 @@ class ProjectCommandsTestCase(test.TestCase):
def test_quota_update_invalid_key(self):
self.assertEqual(2, self.commands.quota('admin', 'volumes1', '10'))
def test_quota_reserved(self):
self.commands.quota(project_id='admin')
result = self.output.getvalue()
print_format = "%-36s %-10s %-10s %-10s" % ('cores', '20', '0', '0')
self.assertIn(print_format, result)
def test_quota_reserved_noop_driver(self):
self.useFixture(nova_fixtures.NoopQuotaDriverFixture())
self.commands.quota(project_id='admin')
result = self.output.getvalue()
print_format = "%-36s %-10s %-10s %-10s" % ('cores', 'unlimited',
'-1', '-1')
self.assertIn(print_format, result)
class DBCommandsTestCase(test.NoDBTestCase):
USES_DB_SELF = True