From c8defb7ac384f98614da5bfeadcf19bab9fc84c0 Mon Sep 17 00:00:00 2001 From: Tetsuro Nakamura Date: Sun, 1 Apr 2018 18:05:38 +0900 Subject: [PATCH] Complement tests in allocation candidates In `test_allocation_candidates.py`, there are some tests that validate `allocation_requests` without checking `provider_summaries`. This patch complements the tests by adding to the test functions `_validate_provider_summary_resources`, a base test to check what is in `provider_summaries`. This change will help us build new features such as nested and shared providers without breaking the existing behavior. Change-Id: Ifa7a21a1f83f4a23747d1c6316d9bffcf158ff9a --- .../db/test_allocation_candidates.py | 172 +++++++++++++++++- 1 file changed, 169 insertions(+), 3 deletions(-) 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 91b498f531c4..4614a831d429 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 @@ -823,6 +823,21 @@ class AllocationCandidatesTestCase(ProviderDBBase): ] self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'cn1': set([ + (fields.ResourceClass.VCPU, 24 * 16.0, 0), + (fields.ResourceClass.MEMORY_MB, 1024 * 1.5, 0), + ]), + 'cn2': set([ + (fields.ResourceClass.VCPU, 24 * 16.0, 0), + (fields.ResourceClass.MEMORY_MB, 1024 * 1.5, 0), + ]), + 'shared custom resource provider': set([ + (magic_rc.name, 1024, 0) + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_mix_local_and_shared(self): # Create three compute node providers with VCPU and RAM, but only # the third compute node has DISK. The first two computes will @@ -1016,6 +1031,18 @@ class AllocationCandidatesTestCase(ProviderDBBase): self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'cn': set([ + (fields.ResourceClass.VCPU, 24, 0), + (fields.ResourceClass.MEMORY_MB, 2048, 0), + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + 'ss': set([ + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_common_rc_traits_split(self): """Validate filters when traits are split across cn and shared RPs.""" # NOTE(efried): This test case only applies to the scenario where we're @@ -1054,6 +1081,19 @@ class AllocationCandidatesTestCase(ProviderDBBase): ] self._validate_allocation_requests(expected, alloc_cands) + # expected = {} + expected = { + 'cn': set([ + (fields.ResourceClass.VCPU, 24, 0), + (fields.ResourceClass.MEMORY_MB, 2048, 0), + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + 'ss': set([ + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_only_one_sharing_provider(self): ss1 = self._create_provider('ss1', uuids.agg1) _set_traits(ss1, "MISC_SHARES_VIA_AGGREGATE") @@ -1079,6 +1119,15 @@ class AllocationCandidatesTestCase(ProviderDBBase): ] self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'ss1': set([ + (fields.ResourceClass.IPV4_ADDRESS, 24, 0), + (fields.ResourceClass.SRIOV_NET_VF, 16, 0), + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_all_sharing_providers_no_rc_overlap(self): ss1 = self._create_provider('ss1', uuids.agg1) _set_traits(ss1, "MISC_SHARES_VIA_AGGREGATE") @@ -1104,6 +1153,16 @@ class AllocationCandidatesTestCase(ProviderDBBase): ] self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'ss1': set([ + (fields.ResourceClass.IPV4_ADDRESS, 24, 0), + ]), + 'ss2': set([ + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_all_sharing_providers_no_rc_overlap_more_classes(self): ss1 = self._create_provider('ss1', uuids.agg1) _set_traits(ss1, "MISC_SHARES_VIA_AGGREGATE") @@ -1132,6 +1191,17 @@ class AllocationCandidatesTestCase(ProviderDBBase): ] self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'ss1': set([ + (fields.ResourceClass.IPV4_ADDRESS, 24, 0), + (fields.ResourceClass.SRIOV_NET_VF, 16, 0) + ]), + 'ss2': set([ + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_all_sharing_providers(self): ss1 = self._create_provider('ss1', uuids.agg1) _set_traits(ss1, "MISC_SHARES_VIA_AGGREGATE") @@ -1166,6 +1236,18 @@ class AllocationCandidatesTestCase(ProviderDBBase): ] self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'ss1': set([ + (fields.ResourceClass.IPV4_ADDRESS, 24, 0), + (fields.ResourceClass.SRIOV_NET_VF, 16, 0), + (fields.ResourceClass.DISK_GB, 1600, 0) + ]), + 'ss2': set([ + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_two_non_sharing_connect_to_one_sharing_different_aggregate(self): # Covering the following setup: # @@ -1204,6 +1286,19 @@ class AllocationCandidatesTestCase(ProviderDBBase): ] self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'cn1': set([ + (fields.ResourceClass.VCPU, 24, 0) + ]), + 'cn2': set([ + (fields.ResourceClass.VCPU, 24, 0) + ]), + 'ss1': set([ + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_two_non_sharing_one_common_and_two_unique_sharing(self): # Covering the following setup: # @@ -1252,9 +1347,27 @@ class AllocationCandidatesTestCase(ProviderDBBase): ('ss1', fields.ResourceClass.DISK_GB, 1500), ('ss2', fields.ResourceClass.IPV4_ADDRESS, 2)], ] - self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'cn1': set([ + (fields.ResourceClass.VCPU, 24, 0), + ]), + 'cn2': set([ + (fields.ResourceClass.VCPU, 24, 0), + ]), + 'ss1': set([ + (fields.ResourceClass.DISK_GB, 1600, 0), + ]), + 'ss2': set([ + (fields.ResourceClass.IPV4_ADDRESS, 24, 0), + ]), + 'ss3': set([ + (fields.ResourceClass.IPV4_ADDRESS, 24, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_rc_split_between_sharing_and_non_sharing(self): # cn1(VCPU,MEM,DISK) Non-sharing RP with all resources # | agg1 aggregated with @@ -1279,9 +1392,20 @@ class AllocationCandidatesTestCase(ProviderDBBase): ('cn1', fields.ResourceClass.MEMORY_MB, 64), ('ss1', fields.ResourceClass.DISK_GB, 1500)], ] - self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'cn1': set([ + (fields.ResourceClass.VCPU, 24, 0), + (fields.ResourceClass.MEMORY_MB, 2048, 0), + (fields.ResourceClass.DISK_GB, 2000, 0), + ]), + 'ss1': set([ + (fields.ResourceClass.DISK_GB, 2000, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_rc_not_split_between_sharing_and_non_sharing(self): # cn1(VCPU,MEM) Non-sharing RP with some of the resources # | agg1 aggregated with @@ -1319,6 +1443,26 @@ class AllocationCandidatesTestCase(ProviderDBBase): self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'cn1': set([ + (fields.ResourceClass.VCPU, 24, 0), + (fields.ResourceClass.MEMORY_MB, 2048, 0), + ]), + 'ss1': set([ + (fields.ResourceClass.DISK_GB, 2000, 0), + ]), + 'cn2': set([ + (fields.ResourceClass.VCPU, 24, 0), + ]), + 'ss2_1': set([ + (fields.ResourceClass.MEMORY_MB, 2048, 0), + ]), + 'ss2_2': set([ + (fields.ResourceClass.DISK_GB, 2000, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_multiple_sharing_providers_with_same_rc(self): # cn1(VCPU,MEM) Non-sharing with some of the resources; # / agg1 \ aggregated with multiple sharing providers @@ -1359,9 +1503,31 @@ class AllocationCandidatesTestCase(ProviderDBBase): ('ss2_1', fields.ResourceClass.MEMORY_MB, 64), ('ss2_2', fields.ResourceClass.DISK_GB, 1500)], ] - self._validate_allocation_requests(expected, alloc_cands) + expected = { + 'cn1': set([ + (fields.ResourceClass.VCPU, 24, 0), + (fields.ResourceClass.MEMORY_MB, 2048, 0), + ]), + 'ss1_1': set([ + (fields.ResourceClass.DISK_GB, 2000, 0), + ]), + 'ss1_2': set([ + (fields.ResourceClass.DISK_GB, 2000, 0), + ]), + 'cn2': set([ + (fields.ResourceClass.VCPU, 24, 0), + ]), + 'ss2_1': set([ + (fields.ResourceClass.MEMORY_MB, 2048, 0), + ]), + 'ss2_2': set([ + (fields.ResourceClass.DISK_GB, 2000, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_simple_tree_of_providers(self): """Create a hierarchy of resource providers with various inventories on the different levels of provider and see that allocation candidates