api: Add response body schemas for quota class sets API
We replace the use of 'test_class' in a variety of places with 'default', since nova only supports the 'default' quota class set. We also start using the quota fixture in the policy tests to ensure we return "valid" responses. Change-Id: I6df0ec741f355e71c359c4e94bb32caacf9b1fab Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"cores": 20,
|
||||
"fixed_ips": -1,
|
||||
"floating_ips": -1,
|
||||
"id": "test_class",
|
||||
"id": "default",
|
||||
"injected_file_content_bytes": 10240,
|
||||
"injected_file_path_bytes": 255,
|
||||
"injected_files": 5,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"quota_class_set": {
|
||||
"cores": 20,
|
||||
"id": "test_class",
|
||||
"id": "default",
|
||||
"injected_file_content_bytes": 10240,
|
||||
"injected_file_path_bytes": 255,
|
||||
"injected_files": 5,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"quota_class_set": {
|
||||
"cores": 20,
|
||||
"id": "test_class",
|
||||
"id": "default",
|
||||
"instances": 10,
|
||||
"key_pairs": 100,
|
||||
"metadata_items": 128,
|
||||
|
||||
@@ -17,7 +17,7 @@ import copy
|
||||
import webob
|
||||
|
||||
from nova.api.openstack import api_version_request
|
||||
from nova.api.openstack.compute.schemas import quota_classes
|
||||
from nova.api.openstack.compute.schemas import quota_classes as schema
|
||||
from nova.api.openstack import wsgi
|
||||
from nova.api import validation
|
||||
from nova import exception
|
||||
@@ -36,21 +36,22 @@ EXTENDED_QUOTAS = ['server_groups', 'server_group_members']
|
||||
|
||||
# NOTE(gmann): Network related quotas are filter out in
|
||||
# microversion 2.50. Bug#1701211.
|
||||
FILTERED_QUOTAS_2_50 = ["fixed_ips", "floating_ips",
|
||||
FILTERED_QUOTAS_v250 = ["fixed_ips", "floating_ips",
|
||||
"security_group_rules", "security_groups"]
|
||||
|
||||
# Microversion 2.57 removes personality (injected) files from the API.
|
||||
FILTERED_QUOTAS_2_57 = list(FILTERED_QUOTAS_2_50)
|
||||
FILTERED_QUOTAS_2_57.extend(['injected_files', 'injected_file_content_bytes',
|
||||
FILTERED_QUOTAS_v257 = list(FILTERED_QUOTAS_v250)
|
||||
FILTERED_QUOTAS_v257.extend(['injected_files', 'injected_file_content_bytes',
|
||||
'injected_file_path_bytes'])
|
||||
|
||||
|
||||
@validation.validated
|
||||
class QuotaClassSetsController(wsgi.Controller):
|
||||
|
||||
supported_quotas = []
|
||||
|
||||
def __init__(self):
|
||||
super(QuotaClassSetsController, self).__init__()
|
||||
super().__init__()
|
||||
self.supported_quotas = QUOTAS.resources
|
||||
|
||||
def _format_quota_set(self, quota_class, quota_set, filtered_quotas=None,
|
||||
@@ -58,7 +59,7 @@ class QuotaClassSetsController(wsgi.Controller):
|
||||
"""Convert the quota object to a result dict."""
|
||||
|
||||
if quota_class:
|
||||
result = dict(id=str(quota_class))
|
||||
result = {'id': str(quota_class)}
|
||||
else:
|
||||
result = {}
|
||||
original_quotas = copy.deepcopy(self.supported_quotas)
|
||||
@@ -79,14 +80,17 @@ class QuotaClassSetsController(wsgi.Controller):
|
||||
|
||||
def _get_filtered_quotas(self, req):
|
||||
if api_version_request.is_supported(req, '2.57'):
|
||||
return FILTERED_QUOTAS_2_57
|
||||
return FILTERED_QUOTAS_v257
|
||||
elif api_version_request.is_supported(req, '2.50'):
|
||||
return FILTERED_QUOTAS_2_50
|
||||
return FILTERED_QUOTAS_v250
|
||||
else:
|
||||
return []
|
||||
|
||||
@wsgi.expected_errors(())
|
||||
@validation.query_schema(quota_classes.show_query)
|
||||
@validation.query_schema(schema.show_query)
|
||||
@validation.response_body_schema(schema.show_response, '2.1', '2.49')
|
||||
@validation.response_body_schema(schema.show_response_v250, '2.50', '2.56') # noqa: E501
|
||||
@validation.response_body_schema(schema.show_response_v257, '2.57')
|
||||
def show(self, req, id):
|
||||
filtered_quotas = self._get_filtered_quotas(req)
|
||||
|
||||
@@ -94,23 +98,20 @@ class QuotaClassSetsController(wsgi.Controller):
|
||||
if api_version_request.is_supported(req, '2.50'):
|
||||
exclude_server_groups = False
|
||||
|
||||
return self._show(
|
||||
req, id, filtered_quotas=filtered_quotas,
|
||||
exclude_server_groups=exclude_server_groups,
|
||||
)
|
||||
|
||||
def _show(self, req, id, filtered_quotas=None,
|
||||
exclude_server_groups=False):
|
||||
context = req.environ['nova.context']
|
||||
context.can(qcs_policies.POLICY_ROOT % 'show', target={})
|
||||
values = QUOTAS.get_class_quotas(context, id)
|
||||
return self._format_quota_set(id, values, filtered_quotas,
|
||||
exclude_server_groups)
|
||||
return self._format_quota_set(
|
||||
id, values, filtered_quotas, exclude_server_groups
|
||||
)
|
||||
|
||||
@wsgi.expected_errors(400)
|
||||
@validation.schema(quota_classes.update, '2.1', '2.49')
|
||||
@validation.schema(quota_classes.update_v250, '2.50', '2.56')
|
||||
@validation.schema(quota_classes.update_v257, '2.57')
|
||||
@validation.schema(schema.update, '2.1', '2.49')
|
||||
@validation.schema(schema.update_v250, '2.50', '2.56')
|
||||
@validation.schema(schema.update_v257, '2.57')
|
||||
@validation.response_body_schema(schema.update_response, '2.1', '2.49')
|
||||
@validation.response_body_schema(schema.update_response_v250, '2.50', '2.56') # noqa: E501
|
||||
@validation.response_body_schema(schema.update_response_v257, '2.57')
|
||||
def update(self, req, id, body):
|
||||
filtered_quotas = self._get_filtered_quotas(req)
|
||||
|
||||
@@ -118,15 +119,9 @@ class QuotaClassSetsController(wsgi.Controller):
|
||||
if api_version_request.is_supported(req, '2.50'):
|
||||
exclude_server_groups = False
|
||||
|
||||
return self._update(
|
||||
req, id, body, filtered_quotas=filtered_quotas,
|
||||
exclude_server_groups=exclude_server_groups,
|
||||
)
|
||||
|
||||
def _update(self, req, id, body, filtered_quotas=None,
|
||||
exclude_server_groups=False):
|
||||
context = req.environ['nova.context']
|
||||
context.can(qcs_policies.POLICY_ROOT % 'update', target={})
|
||||
|
||||
try:
|
||||
utils.check_string_length(id, 'quota_class_name',
|
||||
min_length=1, max_length=255)
|
||||
|
||||
@@ -52,3 +52,109 @@ show_query = {
|
||||
'properties': {},
|
||||
'additionalProperties': True,
|
||||
}
|
||||
|
||||
_quota_response = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'cores': {'type': 'integer', 'minimum': -1},
|
||||
'fixed_ips': {'type': 'integer', 'minimum': -1},
|
||||
'floating_ips': {'type': 'integer', 'minimum': -1},
|
||||
'injected_file_content_bytes': {'type': 'integer', 'minimum': -1},
|
||||
'injected_file_path_bytes': {'type': 'integer', 'minimum': -1},
|
||||
'injected_files': {'type': 'integer', 'minimum': -1},
|
||||
'instances': {'type': 'integer', 'minimum': -1},
|
||||
'key_pairs': {'type': 'integer', 'minimum': -1},
|
||||
'metadata_items': {'type': 'integer', 'minimum': -1},
|
||||
'networks': {'type': 'integer', 'minimum': -1},
|
||||
'ram': {'type': 'integer', 'minimum': -1},
|
||||
'security_groups': {'type': 'integer', 'minimum': -1},
|
||||
'security_group_rules': {'type': 'integer', 'minimum': -1},
|
||||
},
|
||||
'required': [
|
||||
# only networks is optional (it only appears under nova-network)
|
||||
'cores',
|
||||
'fixed_ips',
|
||||
'floating_ips',
|
||||
'injected_file_content_bytes',
|
||||
'injected_file_path_bytes',
|
||||
'injected_files',
|
||||
'instances',
|
||||
'key_pairs',
|
||||
'metadata_items',
|
||||
'ram',
|
||||
'security_groups',
|
||||
'security_group_rules',
|
||||
],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
_quota_response_v250 = copy.deepcopy(_quota_response)
|
||||
for field in {
|
||||
'fixed_ips', 'floating_ips', 'security_group_rules', 'security_groups'
|
||||
}:
|
||||
del _quota_response_v250['properties'][field]
|
||||
_quota_response_v250['required'].pop(
|
||||
_quota_response_v250['required'].index(field)
|
||||
)
|
||||
_quota_response_v250['properties'].update({
|
||||
'server_groups': {'type': 'integer', 'minimum': -1},
|
||||
'server_group_members': {'type': 'integer', 'minimum': -1},
|
||||
})
|
||||
_quota_response_v250['required'].extend(
|
||||
['server_groups', 'server_group_members']
|
||||
)
|
||||
|
||||
_quota_response_v257 = copy.deepcopy(_quota_response_v250)
|
||||
for field in {
|
||||
'injected_files', 'injected_file_content_bytes', 'injected_file_path_bytes'
|
||||
}:
|
||||
del _quota_response_v257['properties'][field]
|
||||
_quota_response_v257['required'].pop(
|
||||
_quota_response_v257['required'].index(field)
|
||||
)
|
||||
|
||||
show_response = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'quota_class_set': copy.deepcopy(_quota_response),
|
||||
},
|
||||
'required': ['quota_class_set'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
show_response['properties']['quota_class_set']['properties'].update({
|
||||
'id': {'type': 'string', 'const': 'default'},
|
||||
})
|
||||
show_response['properties']['quota_class_set']['required'].append('id')
|
||||
|
||||
show_response_v250 = copy.deepcopy(show_response)
|
||||
show_response_v250['properties']['quota_class_set'] = copy.deepcopy(
|
||||
_quota_response_v250
|
||||
)
|
||||
show_response_v250['properties']['quota_class_set']['properties'].update({
|
||||
'id': {'type': 'string', 'const': 'default'},
|
||||
})
|
||||
show_response_v250['properties']['quota_class_set']['required'].append('id')
|
||||
|
||||
show_response_v257 = copy.deepcopy(show_response_v250)
|
||||
show_response_v257['properties']['quota_class_set'] = copy.deepcopy(
|
||||
_quota_response_v257
|
||||
)
|
||||
show_response_v257['properties']['quota_class_set']['properties'].update({
|
||||
'id': {'type': 'string', 'const': 'default'},
|
||||
})
|
||||
show_response_v257['properties']['quota_class_set']['required'].append('id')
|
||||
|
||||
update_response = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'quota_class_set': _quota_response,
|
||||
},
|
||||
'required': ['quota_class_set'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
update_response_v250 = copy.deepcopy(update_response)
|
||||
update_response_v250['properties']['quota_class_set'] = _quota_response_v250
|
||||
|
||||
update_response_v257 = copy.deepcopy(update_response_v250)
|
||||
update_response_v257['properties']['quota_class_set'] = _quota_response_v257
|
||||
|
||||
@@ -19,7 +19,7 @@ from nova.tests.functional.api_sample_tests import api_sample_base
|
||||
class QuotaClassesSampleJsonTests(api_sample_base.ApiSampleTestBaseV21):
|
||||
ADMIN_API = True
|
||||
sample_dir = "os-quota-class-sets"
|
||||
set_id = 'test_class'
|
||||
set_id = 'default'
|
||||
|
||||
def test_show_quota_classes(self):
|
||||
# Get api sample to show quota classes.
|
||||
|
||||
@@ -64,12 +64,12 @@ class QuotaClassSetsTestV21(test.TestCase):
|
||||
self.assertEqual(-1, quota_set['security_group_rules'])
|
||||
|
||||
def test_format_quota_set(self):
|
||||
quota_set = self.controller._format_quota_set('test_class',
|
||||
quota_set = self.controller._format_quota_set('default',
|
||||
self.quota_resources,
|
||||
self.filtered_quotas)
|
||||
qs = quota_set['quota_class_set']
|
||||
|
||||
self.assertEqual(qs['id'], 'test_class')
|
||||
self.assertEqual(qs['id'], 'default')
|
||||
for resource, value in self.quota_resources.items():
|
||||
self.assertEqual(value, qs[resource])
|
||||
if self.filtered_quotas:
|
||||
@@ -78,9 +78,9 @@ class QuotaClassSetsTestV21(test.TestCase):
|
||||
self._check_filtered_extended_quota(qs)
|
||||
|
||||
def test_quotas_show(self):
|
||||
res_dict = self.controller.show(self.req, 'test_class')
|
||||
res_dict = self.controller.show(self.req, 'default')
|
||||
|
||||
self.assertEqual(res_dict, self.quota_set('test_class'))
|
||||
self.assertEqual(res_dict, self.quota_set('default'))
|
||||
|
||||
def test_quotas_update(self):
|
||||
expected_body = {'quota_class_set': self.quota_resources}
|
||||
@@ -88,7 +88,7 @@ class QuotaClassSetsTestV21(test.TestCase):
|
||||
request_quota_resources['server_groups'] = 10
|
||||
request_quota_resources['server_group_members'] = 10
|
||||
request_body = {'quota_class_set': request_quota_resources}
|
||||
res_dict = self.controller.update(self.req, 'test_class',
|
||||
res_dict = self.controller.update(self.req, 'default',
|
||||
body=request_body)
|
||||
|
||||
self.assertEqual(res_dict, expected_body)
|
||||
@@ -96,12 +96,12 @@ class QuotaClassSetsTestV21(test.TestCase):
|
||||
def test_quotas_update_with_empty_body(self):
|
||||
body = {}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req, 'test_class', body=body)
|
||||
self.req, 'default', body=body)
|
||||
|
||||
def test_quotas_update_with_invalid_integer(self):
|
||||
body = {'quota_class_set': {'instances': 2 ** 31 + 1}}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req, 'test_class', body=body)
|
||||
self.req, 'default', body=body)
|
||||
|
||||
def test_quotas_update_with_long_quota_class_name(self):
|
||||
name = 'a' * 256
|
||||
@@ -112,22 +112,22 @@ class QuotaClassSetsTestV21(test.TestCase):
|
||||
def test_quotas_update_with_non_integer(self):
|
||||
body = {'quota_class_set': {'instances': "abc"}}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req, 'test_class', body=body)
|
||||
self.req, 'default', body=body)
|
||||
|
||||
body = {'quota_class_set': {'instances': 50.5}}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req, 'test_class', body=body)
|
||||
self.req, 'default', body=body)
|
||||
|
||||
body = {'quota_class_set': {
|
||||
'instances': u'\u30aa\u30fc\u30d7\u30f3'}}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req, 'test_class', body=body)
|
||||
self.req, 'default', body=body)
|
||||
|
||||
def test_quotas_update_with_unsupported_quota_class(self):
|
||||
body = {'quota_class_set': {'instances': 50, 'cores': 50,
|
||||
'ram': 51200, 'unsupported': 12}}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req, 'test_class', body=body)
|
||||
self.req, 'default', body=body)
|
||||
|
||||
|
||||
class QuotaClassSetsTestV250(QuotaClassSetsTestV21):
|
||||
@@ -140,7 +140,7 @@ class QuotaClassSetsTestV250(QuotaClassSetsTestV21):
|
||||
'injected_file_path_bytes': 255,
|
||||
'server_groups': 10,
|
||||
'server_group_members': 10}
|
||||
filtered_quotas = quota_classes_v21.FILTERED_QUOTAS_2_50
|
||||
filtered_quotas = quota_classes_v21.FILTERED_QUOTAS_v250
|
||||
|
||||
def _check_filtered_extended_quota(self, quota_set):
|
||||
self.assertEqual(10, quota_set['server_groups'])
|
||||
@@ -152,7 +152,7 @@ class QuotaClassSetsTestV250(QuotaClassSetsTestV21):
|
||||
for resource in self.filtered_quotas:
|
||||
body = {'quota_class_set': {resource: 10}}
|
||||
self.assertRaises(self.validation_error, self.controller.update,
|
||||
self.req, 'test_class', body=body)
|
||||
self.req, 'default', body=body)
|
||||
|
||||
|
||||
class QuotaClassSetsTestV257(QuotaClassSetsTestV250):
|
||||
@@ -160,9 +160,9 @@ class QuotaClassSetsTestV257(QuotaClassSetsTestV250):
|
||||
|
||||
def setUp(self):
|
||||
super(QuotaClassSetsTestV257, self).setUp()
|
||||
for resource in quota_classes_v21.FILTERED_QUOTAS_2_57:
|
||||
for resource in quota_classes_v21.FILTERED_QUOTAS_v257:
|
||||
self.quota_resources.pop(resource, None)
|
||||
self.filtered_quotas.extend(quota_classes_v21.FILTERED_QUOTAS_2_57)
|
||||
self.filtered_quotas.extend(quota_classes_v21.FILTERED_QUOTAS_v257)
|
||||
|
||||
|
||||
class NoopQuotaClassesTest(test.NoDBTestCase):
|
||||
@@ -175,10 +175,10 @@ class NoopQuotaClassesTest(test.NoDBTestCase):
|
||||
|
||||
def test_show_v21(self):
|
||||
req = fakes.HTTPRequest.blank("")
|
||||
response = self.controller.show(req, "test_class")
|
||||
response = self.controller.show(req, "default")
|
||||
expected_response = {
|
||||
'quota_class_set': {
|
||||
'id': 'test_class',
|
||||
'id': 'default',
|
||||
'cores': -1,
|
||||
'fixed_ips': -1,
|
||||
'floating_ips': -1,
|
||||
@@ -217,7 +217,7 @@ class NoopQuotaClassesTest(test.NoDBTestCase):
|
||||
body = {'quota_class_set': {'instances': 50, 'cores': 50,
|
||||
'ram': 51200, 'unsupported': 12}}
|
||||
self.assertRaises(exception.ValidationError, self.controller.update,
|
||||
req, 'test_class', body=body)
|
||||
req, 'default', body=body)
|
||||
|
||||
@mock.patch.object(objects.Quotas, "update_class")
|
||||
def test_update_v21(self, mock_update):
|
||||
@@ -286,10 +286,10 @@ class UnifiedLimitsQuotaClassesTest(NoopQuotaClassesTest):
|
||||
def test_show_v21(self, mock_default):
|
||||
mock_default.return_value = {"instances": 1, "cores": 2, "ram": 3}
|
||||
req = fakes.HTTPRequest.blank("")
|
||||
response = self.controller.show(req, "test_class")
|
||||
response = self.controller.show(req, "default")
|
||||
expected_response = {
|
||||
'quota_class_set': {
|
||||
'id': 'test_class',
|
||||
'id': 'default',
|
||||
'cores': 2,
|
||||
'fixed_ips': -1,
|
||||
'floating_ips': -1,
|
||||
@@ -330,7 +330,7 @@ class UnifiedLimitsQuotaClassesTest(NoopQuotaClassesTest):
|
||||
body = {'quota_class_set': {'instances': 50, 'cores': 50,
|
||||
'ram': 51200, 'unsupported': 12}}
|
||||
self.assertRaises(exception.ValidationError, self.controller.update,
|
||||
req, 'test_class', body=body)
|
||||
req, 'default', body=body)
|
||||
|
||||
@mock.patch.object(placement_limit, "get_legacy_default_limits")
|
||||
@mock.patch.object(objects.Quotas, "update_class")
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from nova.api.openstack.compute import quota_classes
|
||||
from nova.policies import quota_class_sets as policies
|
||||
from nova.tests import fixtures as nova_fixtures
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests.unit.policies import base
|
||||
|
||||
@@ -31,6 +30,8 @@ class QuotaClassSetsPolicyTest(base.BasePolicyTest):
|
||||
self.controller = quota_classes.QuotaClassSetsController()
|
||||
self.req = fakes.HTTPRequest.blank('')
|
||||
|
||||
self.useFixture(nova_fixtures.NoopQuotaDriverFixture())
|
||||
|
||||
# With legacy rule and scope check disabled by default, system admin,
|
||||
# legacy admin, and project admin will be able to get, update quota
|
||||
# class.
|
||||
@@ -38,27 +39,31 @@ class QuotaClassSetsPolicyTest(base.BasePolicyTest):
|
||||
self.legacy_admin_context, self.system_admin_context,
|
||||
self.project_admin_context]
|
||||
|
||||
@mock.patch('nova.objects.Quotas.update_class')
|
||||
def test_update_quota_class_sets_policy(self, mock_update):
|
||||
def test_update_quota_class_sets_policy(self):
|
||||
rule_name = policies.POLICY_ROOT % 'update'
|
||||
body = {'quota_class_set':
|
||||
{'metadata_items': 128,
|
||||
'ram': 51200, 'floating_ips': -1,
|
||||
'fixed_ips': -1, 'instances': 10,
|
||||
'injected_files': 5, 'cores': 20}}
|
||||
body = {
|
||||
'quota_class_set': {
|
||||
'cores': 20,
|
||||
'fixed_ips': -1,
|
||||
'floating_ips': -1,
|
||||
'injected_files': 5,
|
||||
'instances': 10,
|
||||
'metadata_items': 128,
|
||||
'ram': 51200,
|
||||
}
|
||||
}
|
||||
self.common_policy_auth(self.project_admin_authorized_contexts,
|
||||
rule_name,
|
||||
self.controller.update,
|
||||
self.req, 'test_class',
|
||||
self.req, 'default',
|
||||
body=body)
|
||||
|
||||
@mock.patch('nova.quota.QUOTAS.get_class_quotas')
|
||||
def test_show_quota_class_sets_policy(self, mock_get):
|
||||
def test_show_quota_class_sets_policy(self):
|
||||
rule_name = policies.POLICY_ROOT % 'show'
|
||||
self.common_policy_auth(self.project_admin_authorized_contexts,
|
||||
rule_name,
|
||||
self.controller.show,
|
||||
self.req, 'test_class')
|
||||
self.req, 'default')
|
||||
|
||||
|
||||
class QuotaClassSetsNoLegacyNoScopePolicyTest(QuotaClassSetsPolicyTest):
|
||||
|
||||
@@ -469,11 +469,11 @@ class QuotaEngineTestCase(test.TestCase):
|
||||
context = FakeContext(None, None)
|
||||
driver = FakeDriver()
|
||||
quota_obj = self._get_quota_engine(driver)
|
||||
result1 = quota_obj.get_class_quotas(context, 'test_class')
|
||||
result1 = quota_obj.get_class_quotas(context, 'default')
|
||||
|
||||
self.assertEqual(driver.called, [
|
||||
('get_class_quotas', context, quota_obj._resources,
|
||||
'test_class'),
|
||||
'default'),
|
||||
])
|
||||
self.assertEqual(result1, quota_obj._resources)
|
||||
|
||||
@@ -485,14 +485,14 @@ class QuotaEngineTestCase(test.TestCase):
|
||||
'fake_user')
|
||||
result2 = quota_obj.get_user_quotas(context, 'test_project',
|
||||
'fake_user',
|
||||
quota_class='test_class',
|
||||
quota_class='default',
|
||||
usages=False)
|
||||
|
||||
self.assertEqual(driver.called, [
|
||||
('get_user_quotas', context, quota_obj._resources,
|
||||
'test_project', 'fake_user', None, True),
|
||||
('get_user_quotas', context, quota_obj._resources,
|
||||
'test_project', 'fake_user', 'test_class', False),
|
||||
'test_project', 'fake_user', 'default', False),
|
||||
])
|
||||
self.assertEqual(result1, quota_obj._resources)
|
||||
self.assertEqual(result2, quota_obj._resources)
|
||||
@@ -503,14 +503,14 @@ class QuotaEngineTestCase(test.TestCase):
|
||||
quota_obj = self._get_quota_engine(driver)
|
||||
result1 = quota_obj.get_project_quotas(context, 'test_project')
|
||||
result2 = quota_obj.get_project_quotas(context, 'test_project',
|
||||
quota_class='test_class',
|
||||
quota_class='default',
|
||||
usages=False)
|
||||
|
||||
self.assertEqual(driver.called, [
|
||||
('get_project_quotas', context, quota_obj._resources,
|
||||
'test_project', None, True, False),
|
||||
('get_project_quotas', context, quota_obj._resources,
|
||||
'test_project', 'test_class', False, False),
|
||||
'test_project', 'default', False, False),
|
||||
])
|
||||
self.assertEqual(result1, quota_obj._resources)
|
||||
self.assertEqual(result2, quota_obj._resources)
|
||||
@@ -649,7 +649,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
# Stub out quota_class_get_all_by_name
|
||||
def fake_qcgabn(cls, context, quota_class):
|
||||
self.calls.append('quota_class_get_all_by_name')
|
||||
self.assertEqual(quota_class, 'test_class')
|
||||
self.assertEqual(quota_class, 'default')
|
||||
return dict(
|
||||
instances=5,
|
||||
ram=25 * 1024,
|
||||
@@ -661,7 +661,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_class_quotas(self):
|
||||
self._stub_quota_class_get_all_by_name()
|
||||
result = self.driver.get_class_quotas(None, quota.QUOTAS._resources,
|
||||
'test_class')
|
||||
'default')
|
||||
|
||||
self.assertEqual(self.calls, ['quota_class_get_all_by_name'])
|
||||
self.assertEqual(result, dict(
|
||||
@@ -744,7 +744,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_usages_for_project(self):
|
||||
resources = self._get_fake_countable_resources()
|
||||
actual = self.driver._get_usages(
|
||||
FakeContext('test_project', 'test_class'), resources,
|
||||
FakeContext('test_project', 'default'), resources,
|
||||
'test_project')
|
||||
# key_pairs, server_group_members, and security_group_rules are never
|
||||
# counted as a usage. Their counts are only for quota limit checking.
|
||||
@@ -759,7 +759,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_usages_for_user(self):
|
||||
resources = self._get_fake_countable_resources()
|
||||
actual = self.driver._get_usages(
|
||||
FakeContext('test_project', 'test_class'), resources,
|
||||
FakeContext('test_project', 'default'), resources,
|
||||
'test_project', user_id='fake_user')
|
||||
# key_pairs, server_group_members, and security_group_rules are never
|
||||
# counted as a usage. Their counts are only for quota limit checking.
|
||||
@@ -776,7 +776,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_user_quotas(self, mock_get_usages):
|
||||
self.maxDiff = None
|
||||
self._stub_get_by_project_and_user()
|
||||
ctxt = FakeContext('test_project', 'test_class')
|
||||
ctxt = FakeContext('test_project', 'default')
|
||||
result = self.driver.get_user_quotas(
|
||||
ctxt, quota.QUOTAS._resources, 'test_project', 'fake_user')
|
||||
|
||||
@@ -887,7 +887,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_project_quotas(self, mock_get_usages):
|
||||
self.maxDiff = None
|
||||
self._stub_get_by_project()
|
||||
ctxt = FakeContext('test_project', 'test_class')
|
||||
ctxt = FakeContext('test_project', 'default')
|
||||
result = self.driver.get_project_quotas(
|
||||
ctxt, quota.QUOTAS._resources, 'test_project')
|
||||
|
||||
@@ -962,7 +962,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_project_quotas_with_remains(self, mock_get_usages):
|
||||
self.maxDiff = None
|
||||
self._stub_get_by_project()
|
||||
ctxt = FakeContext('test_project', 'test_class')
|
||||
ctxt = FakeContext('test_project', 'default')
|
||||
result = self.driver.get_project_quotas(
|
||||
ctxt, quota.QUOTAS._resources, 'test_project', remains=True)
|
||||
|
||||
@@ -1204,7 +1204,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
ctxt = FakeContext('other_project', 'other_class')
|
||||
result = self.driver.get_user_quotas(
|
||||
ctxt, quota.QUOTAS._resources, 'test_project', 'fake_user',
|
||||
quota_class='test_class')
|
||||
quota_class='default')
|
||||
|
||||
self.assertEqual(self.calls, [
|
||||
'quota_get_all_by_project_and_user',
|
||||
@@ -1281,7 +1281,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
ctxt = FakeContext('other_project', 'other_class')
|
||||
result = self.driver.get_project_quotas(
|
||||
ctxt, quota.QUOTAS._resources, 'test_project',
|
||||
quota_class='test_class')
|
||||
quota_class='default')
|
||||
|
||||
self.assertEqual(self.calls, [
|
||||
'quota_get_all_by_project',
|
||||
@@ -1352,7 +1352,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_user_quotas_no_usages(self):
|
||||
self._stub_get_by_project_and_user()
|
||||
result = self.driver.get_user_quotas(
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources, 'test_project', 'fake_user', usages=False)
|
||||
|
||||
self.assertEqual(self.calls, [
|
||||
@@ -1408,7 +1408,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_project_quotas_no_usages(self):
|
||||
self._stub_get_by_project()
|
||||
result = self.driver.get_project_quotas(
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources, 'test_project', usages=False)
|
||||
|
||||
self.assertEqual(self.calls, [
|
||||
@@ -1527,7 +1527,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_settable_quotas_with_user(self):
|
||||
self._stub_get_settable_quotas()
|
||||
result = self.driver.get_settable_quotas(
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources, 'test_project', user_id='test_user')
|
||||
|
||||
self.assertEqual(self.calls, [
|
||||
@@ -1598,7 +1598,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_settable_quotas_without_user(self):
|
||||
self._stub_get_settable_quotas()
|
||||
result = self.driver.get_settable_quotas(
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources, 'test_project')
|
||||
|
||||
self.assertEqual(self.calls, [
|
||||
@@ -1667,7 +1667,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_settable_quotas_by_user_with_unlimited_value(self):
|
||||
self._stub_get_settable_quotas()
|
||||
result = self.driver.get_settable_quotas(
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources, 'test_project', user_id='test_user')
|
||||
|
||||
self.assertEqual(self.calls, [
|
||||
@@ -1758,7 +1758,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
self._stub_get_project_quotas()
|
||||
self.assertRaises(exception.InvalidQuotaValue,
|
||||
self.driver.limit_check,
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources,
|
||||
dict(metadata_items=-1))
|
||||
|
||||
@@ -1766,7 +1766,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
self._stub_get_project_quotas()
|
||||
self.assertRaises(exception.OverQuota,
|
||||
self.driver.limit_check,
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources,
|
||||
dict(metadata_items=129))
|
||||
|
||||
@@ -1774,7 +1774,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
self._stub_get_project_quotas()
|
||||
self.assertRaises(exception.OverQuota,
|
||||
self.driver.limit_check,
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources,
|
||||
dict(injected_file_content_bytes=10241,
|
||||
injected_file_path_bytes=256))
|
||||
@@ -1782,25 +1782,25 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
def test_limit_check_unlimited(self):
|
||||
self.flags(metadata_items=-1, group='quota')
|
||||
self._stub_get_project_quotas()
|
||||
self.driver.limit_check(FakeContext('test_project', 'test_class'),
|
||||
self.driver.limit_check(FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources,
|
||||
dict(metadata_items=32767))
|
||||
|
||||
def test_limit_check(self):
|
||||
self._stub_get_project_quotas()
|
||||
self.driver.limit_check(FakeContext('test_project', 'test_class'),
|
||||
self.driver.limit_check(FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources,
|
||||
dict(metadata_items=128))
|
||||
|
||||
def test_limit_check_project_and_user_no_values(self):
|
||||
self.assertRaises(exception.Invalid,
|
||||
self.driver.limit_check_project_and_user,
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
quota.QUOTAS._resources)
|
||||
|
||||
def test_limit_check_project_and_user_under(self):
|
||||
self._stub_get_project_quotas()
|
||||
ctxt = FakeContext('test_project', 'test_class')
|
||||
ctxt = FakeContext('test_project', 'default')
|
||||
resources = self._get_fake_countable_resources()
|
||||
# Check: only project_values, only user_values, and then both.
|
||||
kwargs = [{'project_values': {'fixed_ips': -1}},
|
||||
@@ -1820,7 +1820,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
resources = self._get_fake_countable_resources()
|
||||
self.assertRaises(exception.OverQuota,
|
||||
self.driver.limit_check_project_and_user,
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
resources,
|
||||
project_values=dict(instances=6),
|
||||
user_values=dict(instances=5))
|
||||
@@ -1834,14 +1834,14 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
# pass project quota but user_values exceed user quota.
|
||||
self.assertRaises(exception.OverQuota,
|
||||
self.driver.limit_check_project_and_user,
|
||||
FakeContext('test_project', 'test_class'),
|
||||
FakeContext('test_project', 'default'),
|
||||
resources,
|
||||
project_values=dict(instances=5),
|
||||
user_values=dict(instances=6))
|
||||
|
||||
def test_limit_check_project_and_user_overs(self):
|
||||
self._stub_get_project_quotas()
|
||||
ctxt = FakeContext('test_project', 'test_class')
|
||||
ctxt = FakeContext('test_project', 'default')
|
||||
resources = self._get_fake_countable_resources()
|
||||
# Check: only project_values, only user_values, and then both.
|
||||
kwargs = [{'project_values': {'instances': 512}},
|
||||
@@ -1857,7 +1857,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
self.flags(key_pairs=-1, group='quota')
|
||||
self.flags(instances=-1, group='quota')
|
||||
self._stub_get_project_quotas()
|
||||
ctxt = FakeContext('test_project', 'test_class')
|
||||
ctxt = FakeContext('test_project', 'default')
|
||||
resources = self._get_fake_countable_resources()
|
||||
# Check: only project_values, only user_values, and then both.
|
||||
kwargs = [{'project_values': {'fixed_ips': 32767}},
|
||||
@@ -1869,7 +1869,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
|
||||
def test_limit_check_project_and_user(self):
|
||||
self._stub_get_project_quotas()
|
||||
ctxt = FakeContext('test_project', 'test_class')
|
||||
ctxt = FakeContext('test_project', 'default')
|
||||
resources = self._get_fake_countable_resources()
|
||||
# Check: only project_values, only user_values, and then both.
|
||||
kwargs = [{'project_values': {'fixed_ips': 5}},
|
||||
@@ -1885,7 +1885,7 @@ class DbQuotaDriverTestCase(test.TestCase):
|
||||
project_values and user_values.
|
||||
"""
|
||||
self._stub_get_project_quotas()
|
||||
ctxt = FakeContext('test_project', 'test_class')
|
||||
ctxt = FakeContext('test_project', 'default')
|
||||
resources = self._get_fake_countable_resources()
|
||||
# Check: only project_values, only user_values, and then both.
|
||||
kwargs = [{'project_values': {'fixed_ips': 0}},
|
||||
@@ -1931,7 +1931,7 @@ class NoopQuotaDriverTestCase(test.TestCase):
|
||||
def test_get_class_quotas(self):
|
||||
result = self.driver.get_class_quotas(None,
|
||||
quota.QUOTAS._resources,
|
||||
'test_class')
|
||||
'default')
|
||||
self.assertEqual(self.expected_without_dict, result)
|
||||
|
||||
def test_get_project_quotas(self):
|
||||
@@ -2052,7 +2052,7 @@ class UnifiedLimitsDriverTestCase(NoopQuotaDriverTestCase):
|
||||
def test_get_class_quotas(self, mock_default):
|
||||
mock_default.return_value = {"instances": 1, "cores": 2, "ram": 0}
|
||||
result = self.driver.get_class_quotas(
|
||||
None, quota.QUOTAS._resources, 'test_class')
|
||||
None, quota.QUOTAS._resources, 'default')
|
||||
self.assertEqual(self.expected_without_dict, result)
|
||||
mock_default.assert_called_once_with()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user