Merge "Adds subnormal path for placement client (2)"

This commit is contained in:
Zuul 2018-11-06 06:36:26 +00:00 committed by Gerrit Code Review
commit bc588e36b6
2 changed files with 40 additions and 8 deletions

View File

@ -375,12 +375,11 @@ class TestPlacementClient(tests.TestCase):
@mock.patch('keystoneauth1.session.Session.request')
def test_delete_reservation_class_fail(self, kss_req):
rc_name = 'CUSTOM_RESERVATION_abc-def'
kss_req.return_value = fake_requests.FakeResponse(400)
self.assertRaises(
exceptions.ResourceClassDeletionFailed,
self.client.delete_reservation_class, rc_name)
rc_name = 'abc-def'
# If no reservation class found, the placement API returns 404 error.
kss_req.return_value = fake_requests.FakeResponse(404)
# Ensure that no error is raised
self.client.delete_reservation_class(rc_name)
@mock.patch('blazar.utils.openstack.placement.'
'BlazarPlacementClient.get_resource_provider')
@ -594,3 +593,25 @@ class TestPlacementClient(tests.TestCase):
self.assertRaises(
exceptions.ResourceProviderNotFound,
self.client.delete_reservation_inventory, host_name, "curr1")
@mock.patch('blazar.utils.openstack.placement.'
'BlazarPlacementClient.get_resource_provider')
@mock.patch('keystoneauth1.session.Session.request')
def test_delete_reservation_inventory_no_rc(self, kss_req, get_rp):
host_uuid = uuidutils.generate_uuid()
host_name = "compute-1"
rp_uuid = uuidutils.generate_uuid()
rp_name = "blazar_compute-1"
# Build the mock of current resource provider
mock_get_rp_json = {'uuid': rp_uuid,
'name': rp_name,
'generation': 0,
'parent_provider_uuid': host_uuid}
get_rp.return_value = mock_get_rp_json
# If no reservation class found or if no inventory found,
# then the placement API returns 404 error.
kss_req.return_value = fake_requests.FakeResponse(404)
# Ensure that no error is raised
self.client.delete_reservation_inventory(host_name, "curr1")

View File

@ -262,7 +262,12 @@ class BlazarPlacementClient(object):
# and "-"(hyphen) in its name. We should translate the uuid here.
reservation_uuid = reservation_uuid.upper().replace("-", "_")
rc_name = 'CUSTOM_RESERVATION_' + reservation_uuid
self.delete_resource_class(rc_name)
try:
self.delete_resource_class(rc_name)
except exceptions.ResourceClassDeletionFailed:
# We just log it and skip to keep the compatibility before Stein
LOG.info("Resource class %s doesn't exist. Skipped the deletion "
"of the resource class", rc_name)
def get_inventory(self, rp_uuid):
"""Calls the placement API to get resource inventory information.
@ -367,4 +372,10 @@ class BlazarPlacementClient(object):
# Convert reservation uuid to resource class name
reserv_uuid = reserv_uuid.upper().replace("-", "_")
rc_name = 'CUSTOM_RESERVATION_' + reserv_uuid
self.delete_inventory(rp_uuid, rc_name)
try:
self.delete_inventory(rp_uuid, rc_name)
except exceptions.InventoryUpdateFailed:
# We just log it and skip to keep the compatibility before Stein
LOG.info("Resource class %s doesn't exist or there is no "
"inventory for that resource class on resource provider "
"%s. Skipped the deletion", rc_name, rp_name)