Adds subnormal path for placement client (2)
We start to support placement api from Stein, so there are cases where the resource classs of the reservation id doesn't exist if the reservation been created before Rocky release. This patch changes the placement client code to be aware of the cases. Namely, in cases the resource class is not found, this patch changes delete_reservation_inventory() and delete_reservation_class() to skip the operation. Change-Id: I5c4a4b8c90f237fa392c2a3ae3ffc9be64df7d64 Blueprint: placement-api
This commit is contained in:
parent
5e114768a3
commit
ebb95f6296
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue