Adds placement trait api calls

Change-Id: I0c4523c6916821781c3a67b01ed2e0091407734e
This commit is contained in:
Amit Uniyal 2024-06-20 05:48:44 -04:00
parent 3619d297d5
commit 3c3985c2ec
3 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
features:
- |
Adds API calls for traits in PlacementClient.

View File

@ -49,3 +49,39 @@ class PlacementClient(base_placement_client.BasePlacementClient):
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def list_traits(self, **params):
"""API ref https://docs.openstack.org/api-ref/placement/#traits
"""
url = "/traits"
if params:
url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def show_trait(self, name, **params):
url = "/traits"
if params:
url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url)
body = json.loads(body)
self.expected_success(200, resp.status)
return rest_client.ResponseBody(resp, body)
url = f"{url}/{name}"
resp, _ = self.get(url)
self.expected_success(204, resp.status)
return resp.status
def create_trait(self, name, **params):
url = f"/traits/{name}"
json_body = json.dumps(params)
resp, _ = self.put(url, body=json_body)
return resp.status
def delete_trait(self, name):
url = f"/traits/{name}"
resp, _ = self.delete(url)
self.expected_success(204, resp.status)
return resp.status

View File

@ -87,3 +87,77 @@ class TestPlacementClient(base.BaseServiceTest):
def test_list_allocations_with_bytes_body(self):
self._test_list_allocations(bytes_body=True)
FAKE_ALL_TRAITS = {
"traits": [
"CUSTOM_HW_FPGA_CLASS1",
"CUSTOM_HW_FPGA_CLASS2",
"CUSTOM_HW_FPGA_CLASS3"
]
}
FAKE_ASSOCIATED_TRAITS = {
"traits": [
"CUSTOM_HW_FPGA_CLASS1",
"CUSTOM_HW_FPGA_CLASS2"
]
}
def test_list_traits(self):
self.check_service_client_function(
self.client.list_traits,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_ALL_TRAITS)
self.check_service_client_function(
self.client.list_traits,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_ASSOCIATED_TRAITS,
**{
"associated": "true"
})
self.check_service_client_function(
self.client.list_traits,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_ALL_TRAITS,
**{
"associated": "true",
"name": "startswith:CUSTOM_HW_FPGPA"
})
def test_show_traits(self):
self.check_service_client_function(
self.client.show_trait,
'tempest.lib.common.rest_client.RestClient.get',
204, status=204,
name="CUSTOM_HW_FPGA_CLASS1")
self.check_service_client_function(
self.client.show_trait,
'tempest.lib.common.rest_client.RestClient.get',
404, status=404,
# trait with this name does not exists
name="CUSTOM_HW_FPGA_CLASS4")
def test_create_traits(self):
self.check_service_client_function(
self.client.create_trait,
'tempest.lib.common.rest_client.RestClient.put',
204, status=204,
# try to create trait with existing name
name="CUSTOM_HW_FPGA_CLASS1")
self.check_service_client_function(
self.client.create_trait,
'tempest.lib.common.rest_client.RestClient.put',
201, status=201,
# create new trait
name="CUSTOM_HW_FPGA_CLASS4")
def test_delete_traits(self):
self.check_service_client_function(
self.client.delete_trait,
'tempest.lib.common.rest_client.RestClient.delete',
204, status=204,
name="CUSTOM_HW_FPGA_CLASS1")