diff --git a/doc/api_samples/limits/v2.36/limit-get-resp.json b/doc/api_samples/limits/v2.36/limit-get-resp.json new file mode 100644 index 0000000000..4943f70edd --- /dev/null +++ b/doc/api_samples/limits/v2.36/limit-get-resp.json @@ -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": [] + } +} diff --git a/nova/api/openstack/compute/used_limits.py b/nova/api/openstack/compute/used_limits.py index 2c2449bfad..e24ae48c53 100644 --- a/nova/api/openstack/compute/used_limits.py +++ b/nova/api/openstack/compute/used_limits.py @@ -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: diff --git a/nova/tests/functional/api_sample_tests/api_samples/limits/v2.36/limit-get-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/limits/v2.36/limit-get-resp.json.tpl new file mode 100644 index 0000000000..4943f70edd --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/limits/v2.36/limit-get-resp.json.tpl @@ -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": [] + } +} diff --git a/nova/tests/functional/api_sample_tests/test_limits.py b/nova/tests/functional/api_sample_tests/test_limits.py index d946b574f6..ab20aa7bd8 100644 --- a/nova/tests/functional/api_sample_tests/test_limits.py +++ b/nova/tests/functional/api_sample_tests/test_limits.py @@ -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) diff --git a/nova/tests/unit/api/openstack/compute/test_used_limits.py b/nova/tests/unit/api/openstack/compute/test_used_limits.py index e7d8650986..90cbe836b1 100644 --- a/nova/tests/unit/api/openstack/compute/test_used_limits.py +++ b/nova/tests/unit/api/openstack/compute/test_used_limits.py @@ -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 {}