Add show default quotas API to network quotas_client library

This patch adds show default quotas API to network quotas_client
library and also adds test cases for this feature.

Change-Id: Icadc4a522681ab042ca6e07908bdc16f08330add
This commit is contained in:
jeremy.zhang 2017-12-21 23:52:48 +08:00 committed by Jeremy Zhang
parent b4db359d1a
commit 6e695c9626
4 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,6 @@
---
features:
- |
Add show default quotas API to network quotas_client library.
This feature enables the possibility to show default network quotas for
a specified project.

View File

@ -80,6 +80,10 @@ class QuotasTest(base.BaseAdminNetworkTest):
non_default_quotas = self.admin_quotas_client.list_quotas()
for q in non_default_quotas['quotas']:
self.assertNotEqual(project_id, q['tenant_id'])
quota_set = self.admin_quotas_client.show_quotas(project_id)['quota']
default_quotas = self.admin_quotas_client.show_default_quotas(
project_id)['quota']
self.assertEqual(default_quotas, quota_set)
@decorators.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb')
def test_quotas(self):

View File

@ -41,3 +41,8 @@ class QuotasClient(base.BaseNetworkClient):
def list_quotas(self, **filters):
uri = '/quotas'
return self.list_resources(uri, **filters)
def show_default_quotas(self, tenant_id):
"""List default quotas for a project."""
uri = '/quotas/%s/default' % tenant_id
return self.show_resource(uri)

View File

@ -38,6 +38,20 @@ class TestQuotasClient(base.BaseServiceTest):
]
}
FAKE_PROJECT_QUOTAS = {
"quota": {
"floatingip": 50,
"network": 10,
"port": 50,
"rbac_policy": -1,
"router": 10,
"security_group": 10,
"security_group_rule": 100,
"subnet": 10,
"subnetpool": -1
}
}
FAKE_QUOTA_TENANT_ID = "bab7d5c60cd041a0a36f7c4b6e1dd978"
def setUp(self):
@ -58,7 +72,16 @@ class TestQuotasClient(base.BaseServiceTest):
self.check_service_client_function(
self.quotas_client.show_quotas,
"tempest.lib.common.rest_client.RestClient.get",
{"quota": self.FAKE_QUOTAS["quotas"][0]},
self.FAKE_PROJECT_QUOTAS,
bytes_body,
200,
tenant_id=self.FAKE_QUOTA_TENANT_ID)
def _test_show_default_quotas(self, bytes_body=False):
self.check_service_client_function(
self.quotas_client.show_default_quotas,
"tempest.lib.common.rest_client.RestClient.get",
self.FAKE_PROJECT_QUOTAS,
bytes_body,
200,
tenant_id=self.FAKE_QUOTA_TENANT_ID)
@ -67,7 +90,7 @@ class TestQuotasClient(base.BaseServiceTest):
self.check_service_client_function(
self.quotas_client.update_quotas,
"tempest.lib.common.rest_client.RestClient.put",
{"quota": self.FAKE_QUOTAS["quotas"][0]},
self.FAKE_PROJECT_QUOTAS,
bytes_body,
200,
tenant_id=self.FAKE_QUOTA_TENANT_ID)
@ -92,6 +115,12 @@ class TestQuotasClient(base.BaseServiceTest):
def test_show_quotas_with_bytes_body(self):
self._test_show_quotas(bytes_body=True)
def test_show_default_quotas_with_str_body(self):
self._test_show_default_quotas()
def test_show_default_quotas_with_bytes_body(self):
self._test_show_default_quotas(bytes_body=True)
def test_update_quotas_with_str_body(self):
self._test_update_quotas()