Add list resource provider usage

Add a method to return the current resource usage for a specific
resource provider. Given a specific rp_uuid return the resource
providers current generation as well as its assoicated resource class
usage at that time. Example output below:

(Pdb) self.resource_providers_client.list_resource_provider_usages('90234521-0f4f-4777-98d8-731db8e61a0d')
{'resource_provider_generation': 52, 'usages': {'VGPU': 1}}

More details of the api can be referenced here [1]

[1] https://docs.openstack.org/api-ref/placement/#resource-provider-usages

Change-Id: I13ca77f1cd8fbf74cd716b2d8eae772f5328a4d4
This commit is contained in:
James Parker 2021-03-25 22:33:14 -04:00
parent c0a408b803
commit 92005532d6
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,8 @@
---
features:
- |
Add ``placement`` API usage method for evaluating resource class
utilization of the resource provider. The following API call is available
for tempest from now in the resource_providers_client:
* GET /resource_providers/{uuid}/usages

View File

@ -26,6 +26,7 @@ class ResourceProvidersClient(base_placement_client.BasePlacementClient):
* resource providers
* resource provider inventories
* resource provider aggregates
* resource provider usages
"""
def list_resource_providers(self, **params):
@ -69,6 +70,19 @@ class ResourceProvidersClient(base_placement_client.BasePlacementClient):
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def list_resource_provider_usages(self, rp_uuid):
"""List resource provider usages.
For full list of available parameters, please refer to the official
API reference:
https://docs.openstack.org/api-ref/placement/#list-resource-provider-usages
"""
url = '/resource_providers/%s/usages' % rp_uuid
resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def list_resource_provider_aggregates(self, rp_uuid):
"""List resource provider aggregates.

View File

@ -85,6 +85,14 @@ class TestResourceProvidersClient(base.BaseServiceTest):
},
"resource_provider_generation": 1
}
FAKE_RESOURCE_PROVIDER_USAGES = {
"usages": {
"VCPU": 2,
"MEMORY_MB": 1024,
"DISK_GB": 10
},
"resource_provider_generation": 3
}
def setUp(self):
super(TestResourceProvidersClient, self).setUp()
@ -180,3 +188,19 @@ class TestResourceProvidersClient(base.BaseServiceTest):
def test_list_resource_provider_aggregates_with_bytes_body(self):
self._test_list_resource_provider_aggregates(bytes_body=True)
def _test_list_resource_provider_usages(self, bytes_body=False):
self.check_service_client_function(
self.client.list_resource_provider_usages,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_RESOURCE_PROVIDER_USAGES,
to_utf=bytes_body,
status=200,
rp_uuid=self.FAKE_RESOURCE_PROVIDER_UUID
)
def test_show_resource_provider_usages_with_str_body(self):
self._test_list_resource_provider_inventories()
def test_show_resource_provider_usages_with_with_bytes_body(self):
self._test_list_resource_provider_inventories(bytes_body=True)