Raise error if resource provider is not found

On reservation provider creation, dict key error occurred if the host
resource provider is not found, which is difficult to debug. This
patch changes it to raise a more understandable one,
ResourceProviderNotFound error.

Change-Id: Id9a23a3fd92597c87dcdfba7b8e73e720b0ab656
Related-Bug: #1814594
This commit is contained in:
Tetsuro Nakamura 2019-02-05 10:27:58 +00:00
parent 1418b29a44
commit 41efc33338
2 changed files with 13 additions and 0 deletions

View File

@ -269,6 +269,16 @@ class TestPlacementClient(tests.TestCase):
headers={'accept': 'application/json'},
microversion=PLACEMENT_MICROVERSION, raise_exc=False)
@mock.patch('keystoneauth1.session.Session.request')
def test_create_reservation_provider_fail(self, kss_req):
host_name = "compute-1"
get_json_mock = {'resource_providers': []}
kss_req.return_value = fake_requests.FakeResponse(
200, content=json.dumps(get_json_mock))
self.assertRaises(
exceptions.ResourceProviderNotFound,
self.client.create_reservation_provider, host_name)
@mock.patch('keystoneauth1.session.Session.request')
def test_delete_reservation_provider(self, kss_req):
host_uuid = uuidutils.generate_uuid()

View File

@ -185,6 +185,9 @@ class BlazarPlacementClient(object):
def create_reservation_provider(self, host_name):
"""Create a reservation provider as a child of the given host"""
host_rp = self.get_resource_provider(host_name)
if host_rp is None:
raise exceptions.ResourceProviderNotFound(
resource_provider=host_name)
host_uuid = host_rp['uuid']
rp_name = "blazar_" + host_name