From 995d283e4f9a6a0cbf44f840c643d7dd99212f82 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Tue, 20 Sep 2016 14:36:37 +0000 Subject: [PATCH] [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 --- nova/objects/resource_provider.py | 7 +++++-- nova/tests/functional/db/test_resource_provider.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/nova/objects/resource_provider.py b/nova/objects/resource_provider.py index bc61a92d9c1b..54377d06b369 100644 --- a/nova/objects/resource_provider.py +++ b/nova/objects/resource_provider.py @@ -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: diff --git a/nova/tests/functional/db/test_resource_provider.py b/nova/tests/functional/db/test_resource_provider.py index 1774195e8db5..355c8d7f3b56 100644 --- a/nova/tests/functional/db/test_resource_provider.py +++ b/nova/tests/functional/db/test_resource_provider.py @@ -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.