Add show quota details to network quotas_client library

This patch adds show quota details API to network quotas_client library
and also adds test cases for this new feature.

Change-Id: I1d229d7903db719369fd8ec0eb0bd2ce4d15978f
This commit is contained in:
jeremy.zhang 2018-02-09 15:17:21 +08:00
parent 70ebe69cc2
commit 1ac13b274a
4 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,7 @@
---
features:
- |
Add extension API show quota details to network quotas_client library.
This feature enables the possibility to show a quota set for a specified
project that includes the quotas used, limit and reserved counts for per
resource

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import testtools
from tempest.api.network import base
from tempest.common import identity
from tempest.common import utils
@ -89,3 +91,15 @@ class QuotasTest(base.BaseAdminNetworkTest):
def test_quotas(self):
new_quotas = {'network': 0, 'port': 0}
self._check_quotas(new_quotas)
@testtools.skipUnless(utils.is_extension_enabled(
'quota_details', 'network'), 'Quota details extension not enabled.')
@decorators.idempotent_id('7b05ec5f-bf44-43cb-b28f-ddd72a824288')
def test_show_quota_details(self):
# Show quota details for an existing project
quota_details = self.admin_quotas_client.show_quota_details(
self.admin_quotas_client.tenant_id)['quota']
expected_keys = ['used', 'limit', 'reserved']
for resource_type in quota_details:
for key in expected_keys:
self.assertIn(key, quota_details[resource_type])

View File

@ -46,3 +46,8 @@ class QuotasClient(base.BaseNetworkClient):
"""List default quotas for a project."""
uri = '/quotas/%s/default' % tenant_id
return self.show_resource(uri)
def show_quota_details(self, tenant_id):
"""Show quota details for a project."""
uri = '/quotas/%s/details.json' % tenant_id
return self.show_resource(uri)

View File

@ -54,6 +54,46 @@ class TestQuotasClient(base.BaseServiceTest):
FAKE_QUOTA_TENANT_ID = "bab7d5c60cd041a0a36f7c4b6e1dd978"
FAKE_QUOTA_DETAILS = {
"quota": {
"rbac_policy": {
"used": 4,
"limit": 10,
"reserved": 0
},
"subnetpool": {
"used": 2,
"limit": -1,
"reserved": 0
},
"security_group_rule": {
"used": 10,
"limit": 100,
"reserved": 1
},
"security_group": {
"used": 3,
"limit": 10,
"reserved": 0
},
"subnet": {
"used": 3,
"limit": 100,
"reserved": 0
},
"port": {
"used": 21,
"limit": 500,
"reserved": 3
},
"network": {
"used": 9,
"limit": 100,
"reserved": 2
}
}
}
def setUp(self):
super(TestQuotasClient, self).setUp()
fake_auth = fake_auth_provider.FakeAuthProvider()
@ -95,6 +135,15 @@ class TestQuotasClient(base.BaseServiceTest):
200,
tenant_id=self.FAKE_QUOTA_TENANT_ID)
def _test_show_quota_details(self, bytes_body=False):
self.check_service_client_function(
self.quotas_client.show_quota_details,
"tempest.lib.common.rest_client.RestClient.get",
self.FAKE_QUOTA_DETAILS,
bytes_body,
200,
tenant_id=self.FAKE_QUOTA_TENANT_ID)
def test_reset_quotas(self):
self.check_service_client_function(
self.quotas_client.reset_quotas,
@ -126,3 +175,9 @@ class TestQuotasClient(base.BaseServiceTest):
def test_update_quotas_with_bytes_body(self):
self._test_update_quotas(bytes_body=True)
def test_show_quota_details_with_str_body(self):
self._test_show_quota_details()
def test_show_quota_details_with_bytes_body(self):
self._test_show_quota_details(bytes_body=True)