don't report network limits after 2.35

We correctly stopped reporting the limits for things like security
groups and floating ips after mv 2.35. We completely missed that
limits are modified by the used_limits extension, and hilarity
ensued. We were reporting no maxSecurityGroups over the wire, but we
were reporting totalSecurityGroups through the magic of extensions.

Change-Id: I85b2b41d919ed6987d4c9288905ccce49c10c81f
Closes-Bug: #1614133
This commit is contained in:
Sean Dague 2016-08-17 16:20:45 -04:00 committed by He Jie Xu
parent 33a50eace0
commit 4461cdf4c4
5 changed files with 85 additions and 8 deletions

View File

@ -0,0 +1,21 @@
{
"limits": {
"absolute": {
"maxImageMeta": 128,
"maxPersonality": 5,
"maxPersonalitySize": 10240,
"maxServerMeta": 128,
"maxTotalCores": 20,
"maxTotalInstances": 10,
"maxTotalKeypairs": 100,
"maxTotalRAMSize": 51200,
"maxServerGroups": 10,
"maxServerGroupMembers": 10,
"totalCoresUsed": 0,
"totalInstancesUsed": 0,
"totalRAMUsed": 0,
"totalServerGroupsUsed": 0
},
"rate": []
}
}

View File

@ -14,6 +14,9 @@
import six
from nova.api.openstack import api_version_request
from nova.api.openstack.api_version_request \
import MIN_WITHOUT_PROXY_API_SUPPORT_VERSION
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.policies import used_limits as ul_policies
@ -41,14 +44,24 @@ class UsedLimitsController(wsgi.Controller):
context = req.environ['nova.context']
project_id = self._project_id(context, req)
quotas = QUOTAS.get_project_quotas(context, project_id, usages=True)
quota_map = {
'totalRAMUsed': 'ram',
'totalCoresUsed': 'cores',
'totalInstancesUsed': 'instances',
'totalFloatingIpsUsed': 'floating_ips',
'totalSecurityGroupsUsed': 'security_groups',
'totalServerGroupsUsed': 'server_groups',
}
if api_version_request.is_supported(
req, min_version=MIN_WITHOUT_PROXY_API_SUPPORT_VERSION):
quota_map = {
'totalRAMUsed': 'ram',
'totalCoresUsed': 'cores',
'totalInstancesUsed': 'instances',
'totalServerGroupsUsed': 'server_groups',
}
else:
quota_map = {
'totalRAMUsed': 'ram',
'totalCoresUsed': 'cores',
'totalInstancesUsed': 'instances',
'totalFloatingIpsUsed': 'floating_ips',
'totalSecurityGroupsUsed': 'security_groups',
'totalServerGroupsUsed': 'server_groups',
}
used_limits = {}
for display_name, key in six.iteritems(quota_map):
if key in quotas:

View File

@ -0,0 +1,21 @@
{
"limits": {
"absolute": {
"maxImageMeta": 128,
"maxPersonality": 5,
"maxPersonalitySize": 10240,
"maxServerMeta": 128,
"maxTotalCores": 20,
"maxTotalInstances": 10,
"maxTotalKeypairs": 100,
"maxTotalRAMSize": 51200,
"maxServerGroups": 10,
"maxServerGroupMembers": 10,
"totalCoresUsed": 0,
"totalInstancesUsed": 0,
"totalRAMUsed": 0,
"totalServerGroupsUsed": 0
},
"rate": []
}
}

View File

@ -29,3 +29,22 @@ class LimitsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
def test_limits_get(self):
response = self._do_get('limits')
self._verify_response(self.template, {}, response, 200)
class LimitsV236Test(api_sample_base.ApiSampleTestBaseV21):
"""Test limits don't return network resources after 2.36.
We dropped the network API in 2.36, which also means that we
shouldn't be returning any limits related to network resources
either. This tests a different limits template after that point
which does not have these.
"""
sample_dir = "limits"
microversion = '2.36'
scenarios = [('v2_36', {'api_major_version': 'v2.1'})]
def test_limits_get(self):
self.api.microversion = self.microversion
response = self._do_get('limits')
self._verify_response('limit-get-resp', {}, response, 200)

View File

@ -16,6 +16,7 @@
import mock
import six
from nova.api.openstack import api_version_request
from nova.api.openstack.compute import used_limits \
as used_limits_v21
from nova.api.openstack import wsgi
@ -30,6 +31,8 @@ class FakeRequest(object):
def __init__(self, context, reserved=False):
self.environ = {'nova.context': context}
self.reserved = reserved
self.api_version_request = api_version_request.min_api_version()
self.GET = {'reserved': 1} if reserved else {}