From a6122a7a64694b87978c4db2939dc69dddcee730 Mon Sep 17 00:00:00 2001 From: Tetsuro Nakamura Date: Sat, 31 Mar 2018 17:52:50 +0900 Subject: [PATCH] [placement] Add test for provider summaries In ``GET /allocation_candidates`` API, ``provider_summaries`` should show all the inventories for all the resource classes in all the resource providers. However, ``provider_summaries`` currently doesn't contain resources that aren't requested. This patch adds a simple test case to describe the bug. Change-Id: Ida9cddc5a2b43917e7b5900fe68a413b18c6cb2d Partial-Bug: #1760276 --- .../db/test_allocation_candidates.py | 37 +++++++++++++++++++ .../gabbits/allocation-candidates.yaml | 11 ++++++ 2 files changed, 48 insertions(+) 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..d960d6e5b24e 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 @@ -439,6 +439,43 @@ class AllocationCandidatesTestCase(ProviderDBBase): rp_obj.AllocationCandidates.get_by_requests, self.ctx, requests) + def test_allc_req_and_prov_summary(self): + """Simply test with one resource provider that the allocation + requests returned by AllocationCandidates have valid + allocation_requests and provider_summaries. + """ + cn1 = self._create_provider('cn1') + _add_inventory(cn1, fields.ResourceClass.VCPU, 8) + _add_inventory(cn1, fields.ResourceClass.MEMORY_MB, 2048) + _add_inventory(cn1, fields.ResourceClass.DISK_GB, 2000) + + alloc_cands = self._get_allocation_candidates([ + placement_lib.RequestGroup( + use_same_provider=False, + resources={ + fields.ResourceClass.VCPU: 1 + } + )] + ) + + expected = [ + [('cn1', fields.ResourceClass.VCPU, 1)] + ] + self._validate_allocation_requests(expected, alloc_cands) + + expected = { + 'cn1': set([ + (fields.ResourceClass.VCPU, 8, 0), + # TODO(tetsuro) - Bug#1760276: provider_summaries should + # include all the resources that the resource provider has, + # but currently it includes only resources that are requested. + # + # (fields.ResourceClass.MEMORY_MB, 2048, 0), + # (fields.ResourceClass.DISK_GB, 2000, 0), + ]), + } + self._validate_provider_summary_resources(expected, alloc_cands) + def test_all_local(self): """Create some resource providers that can satisfy the request for resources with local (non-shared) resources and verify that the diff --git a/nova/tests/functional/api/openstack/placement/gabbits/allocation-candidates.yaml b/nova/tests/functional/api/openstack/placement/gabbits/allocation-candidates.yaml index 6b94e0f5c938..ec405b6fb013 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/allocation-candidates.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/allocation-candidates.yaml @@ -247,3 +247,14 @@ tests: response_json_paths: $.allocation_requests.`len`: 0 $.provider_summaries.`len`: 0 + +# Bug#1760276: provider_summaries should include all the resources that the +# resource provider has, ut currently it includes only resources that are requested. +- name: get allocation candidates provider summaries with requested resource + GET: /allocation_candidates?resources=VCPU:1 + status: 200 + response_json_paths: + $.allocation_requests.`len`: 2 + $.provider_summaries.`len`: 2 + $.provider_summaries["$ENVIRON['CN1_UUID']"].resources.`len`: 1 + $.provider_summaries["$ENVIRON['CN2_UUID']"].resources.`len`: 1