From dc26780ef88a256aa9b581d4e6fe710af0afe0a1 Mon Sep 17 00:00:00 2001 From: Tetsuro Nakamura Date: Tue, 7 Aug 2018 23:38:07 +0900 Subject: [PATCH] Adds a test for _get_provider_ids_matching() This patch adds a test for _get_provider_ids_matching() to verify it works correctly with required traits. Related-Bug: #1786519 Change-Id: I2512e361f5eaa4e60701be7c8bf57b2e0a02a146 --- .../placement/db/test_allocation_candidates.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nova/tests/functional/api/openstack/placement/db/test_allocation_candidates.py b/nova/tests/functional/api/openstack/placement/db/test_allocation_candidates.py index e78adadc6241..c0d1fafa8f3a 100644 --- a/nova/tests/functional/api/openstack/placement/db/test_allocation_candidates.py +++ b/nova/tests/functional/api/openstack/placement/db/test_allocation_candidates.py @@ -40,6 +40,13 @@ class ProviderDBHelperTestCase(tb.PlacementDbBaseTestCase): tb.add_inventory(excl_big_cm_noalloc, fields.ResourceClass.MEMORY_MB, 4096, max_unit=2048) + # Inventory of adequate memory and disk, no allocations against it. + excl_big_md_noalloc = self._create_provider('big_md_noalloc') + tb.add_inventory(excl_big_md_noalloc, fields.ResourceClass.MEMORY_MB, + 4096, max_unit=2048) + tb.add_inventory(excl_big_md_noalloc, fields.ResourceClass.DISK_GB, + 2000) + # Adequate inventory, no allocations against it. incl_biginv_noalloc = self._create_provider('biginv_noalloc') tb.add_inventory(incl_biginv_noalloc, fields.ResourceClass.VCPU, 15) @@ -185,7 +192,14 @@ class ProviderDBHelperTestCase(tb.PlacementDbBaseTestCase): self.assertEqual([], res) - # OK, now add the trait to one of the providers and verify that + # Next let's set the required trait to an excl_* RPs. + # This should result in no results returned as well. + excl_big_md_noalloc.set_traits([avx2_t]) + res = rp_obj._get_provider_ids_matching(self.ctx, resources, + req_traits, {}) + self.assertEqual([], res) + + # OK, now add the trait to one of the incl_* providers and verify that # provider now shows up in our results incl_biginv_noalloc.set_traits([avx2_t]) res = rp_obj._get_provider_ids_matching(self.ctx, resources,