[placement] Stringify class and provider uuid in error

When attempting to make an allocation of a particular class of
resource against a resource provider which has no inventory for that
class, an InvalidInventory exception is raised. This was workign
okay but the associated message was displaying stringified sets
of resource class ids, and not the resource classes names.

This changes joins the sets into strings for both resource classes
and provider uuids and turns the class indexes into their names.
A functional test which was checking for the exception has been
updated to also check the exception's message.

Change-Id: Ife38220da1069ffb6da26a4f8e3b954f0dc12f13
Closes-Bug: #1620748
This commit is contained in:
Chris Dent 2016-09-20 14:36:37 +00:00
parent 8237bb8770
commit 995d283e4f
2 changed files with 13 additions and 4 deletions

View File

@ -739,8 +739,11 @@ def _check_capacity_exceeded(conn, allocs):
# Ensure that all providers have existing inventory
missing_provs = provider_uuids - provs_with_inv
if missing_provs:
raise exception.InvalidInventory(resource_class=str(res_classes),
resource_provider=missing_provs)
class_str = ', '.join([fields.ResourceClass.from_index(res_class)
for res_class in res_classes])
provider_str = ', '.join(missing_provs)
raise exception.InvalidInventory(resource_class=class_str,
resource_provider=provider_str)
res_providers = {}
for alloc in allocs:

View File

@ -731,8 +731,14 @@ class TestAllocationListCreateDelete(ResourceProviderBaseCase):
self.context, objects=[allocation_1, allocation_2])
# There's no inventory, we have a failure.
self.assertRaises(exception.InvalidInventory,
allocation_list.create_all)
error = self.assertRaises(exception.InvalidInventory,
allocation_list.create_all)
# Confirm that the resource class string, not index, is in
# the exception and resource providers are listed by uuid.
self.assertIn(rp1_class, str(error))
self.assertIn(rp2_class, str(error))
self.assertIn(rp1.uuid, str(error))
self.assertIn(rp2.uuid, str(error))
# Add inventory for one of the two resource providers. This should also
# fail, since rp2 has no inventory.