From 284ba35c33053f9ef2786eacf81d6c8cdcf8e24a Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Wed, 24 Jan 2018 14:15:56 +0800 Subject: [PATCH] Fix nits in support traits changes Addresses the comments from earlier patches: https://review.openstack.org/535642 https://review.openstack.org/536085 Co-Authored-By: Matt Riedemann Change-Id: I366b97ef3c141834f48949700edb968a7c7c4167 --- .../handlers/allocation_candidate.py | 2 +- nova/api/openstack/placement/util.py | 6 +++--- nova/cmd/status.py | 5 ++--- nova/exception.py | 2 +- nova/objects/resource_provider.py | 6 +++--- nova/scheduler/client/report.py | 15 +++++++++++---- placement-api-ref/source/parameters.yaml | 5 +++-- ...on-candidates-traits-1adf079ed0c6563c.yaml | 4 ++-- ...quest-traits-in-nova-ffcb00f76229b6e9.yaml | 19 +++++++++++++------ 9 files changed, 39 insertions(+), 25 deletions(-) diff --git a/nova/api/openstack/placement/handlers/allocation_candidate.py b/nova/api/openstack/placement/handlers/allocation_candidate.py index 5d30ffd95da7..391113fca71d 100644 --- a/nova/api/openstack/placement/handlers/allocation_candidate.py +++ b/nova/api/openstack/placement/handlers/allocation_candidate.py @@ -196,7 +196,7 @@ def _transform_allocation_candidates(alloc_cands, want_version): include_traits = want_version.matches((1, 17)) p_sums = _transform_provider_summaries(alloc_cands.provider_summaries, - include_traits) + include_traits=include_traits) return { 'allocation_requests': a_reqs, 'provider_summaries': p_sums, diff --git a/nova/api/openstack/placement/util.py b/nova/api/openstack/placement/util.py index 30961cd10a89..588f1b913142 100644 --- a/nova/api/openstack/placement/util.py +++ b/nova/api/openstack/placement/util.py @@ -306,9 +306,9 @@ def normalize_traits_qs_param(val): """ ret = set(substr.strip() for substr in val.split(',')) if not all(trait for trait in ret): - msg = _('Invalid query string parameters: Expected \'required\' ' - 'parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC. ' - 'Got: "%s"') % val + msg = _("Invalid query string parameters: Expected 'required' " + "parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC. " + "Got: %s") % val raise webob.exc.HTTPBadRequest(msg) return ret diff --git a/nova/cmd/status.py b/nova/cmd/status.py index 218c8f53f9ac..a234662d3fbe 100644 --- a/nova/cmd/status.py +++ b/nova/cmd/status.py @@ -196,9 +196,8 @@ class UpgradeCommands(object): versions = self._placement_get("/") max_version = pkg_resources.parse_version( versions["versions"][0]["max_version"]) - # NOTE(mriedem): 1.14 is required by nova-compute services to - # get and set parent resource provider UUIDs for nested resource - # provider support. + # NOTE(mriedem): 1.17 is required by nova-scheduler to get + # allocation candidates with required traits from the flavor. # NOTE: If you bump this version, remember to update the history # section in the nova-status man page (doc/source/cli/nova-status). needs_version = pkg_resources.parse_version("1.17") diff --git a/nova/exception.py b/nova/exception.py index 493eac85951d..77c34d260f70 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -2216,7 +2216,7 @@ class PowerVMAPIFailed(NovaException): class TraitNotFound(NotFound): - msg_fmt = _("No such trait(s): %(name)s.") + msg_fmt = _("No such trait(s): %(names)s.") class TraitExists(NovaException): diff --git a/nova/objects/resource_provider.py b/nova/objects/resource_provider.py index 0ec49255a0a9..b57d0ed7803b 100644 --- a/nova/objects/resource_provider.py +++ b/nova/objects/resource_provider.py @@ -2481,7 +2481,7 @@ class Trait(base.NovaObject, base.NovaTimestampObject): result = context.session.query(models.Trait).filter_by( name=name).first() if not result: - raise exception.TraitNotFound(name=name) + raise exception.TraitNotFound(names=name) return result @classmethod @@ -2500,7 +2500,7 @@ class Trait(base.NovaObject, base.NovaTimestampObject): res = context.session.query(models.Trait).filter_by( name=name).delete() if not res: - raise exception.TraitNotFound(name=name) + raise exception.TraitNotFound(names=name) def destroy(self): if 'name' not in self: @@ -3515,7 +3515,7 @@ class AllocationCandidates(base.NovaObject): # Double-check that we found a trait ID for each requested name if len(trait_map) != len(traits): missing = traits - set(trait_map) - raise exception.TraitNotFound(name=', '.join(missing)) + raise exception.TraitNotFound(names=', '.join(missing)) # Contains a set of resource provider IDs that share some inventory for # each resource class requested. We do this here as an optimization. If diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index 901fab3c0c1d..ac3fb2decffc 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -311,8 +311,8 @@ class SchedulerReportClient(object): the requested resource constraints. The provider summaries is a dict, keyed by resource provider UUID, of - inventory and capacity information for any resource provider involved - in the allocation_requests. + inventory and capacity information and traits for any resource + provider involved in the allocation_requests. :returns: A tuple with a list of allocation_request dicts, a dict of provider information, and the microversion used to request @@ -347,13 +347,20 @@ class SchedulerReportClient(object): return (data['allocation_requests'], data['provider_summaries'], version) - msg = ("Failed to retrieve allocation candidates from placement API " - "for filters %(resources)s. Got %(status_code)d: %(err_text)s.") args = { 'resources': res, 'status_code': resp.status_code, 'err_text': resp.text, } + if required_traits: + msg = ("Failed to retrieve allocation candidates from placement " + "API for filters %(resources)s and traits %(traits)s. Got " + "%(status_code)d: %(err_text)s.") + args['traits'] = qs_params['required'] + else: + msg = ("Failed to retrieve allocation candidates from placement " + "API for filters %(resources)s. Got %(status_code)d: " + "%(err_text)s.") LOG.error(msg, args) return None, None, None diff --git a/placement-api-ref/source/parameters.yaml b/placement-api-ref/source/parameters.yaml index 80e35417d768..6c1e87bdd99a 100644 --- a/placement-api-ref/source/parameters.yaml +++ b/placement-api-ref/source/parameters.yaml @@ -56,7 +56,7 @@ allocation_candidates_required: required: false min_version: 1.17 description: > - Accepts a list of traits separated by `,`. Allocation requests in the + Accepts a list of comma-separated traits. Allocation requests in the response will be for resource providers that have capacity for all requested resources and the set of those resource providers will *collectively* contain all of the required traits. @@ -252,7 +252,8 @@ provider_summaries: description: > A dictionary keyed by resource provider UUID, of dictionaries of inventory/capacity information. The list of traits - the resource provider has associated with it is included in version `1.17`. + the resource provider has associated with it is included in version `1.17` + and above. reserved: &reserved type: integer in: body diff --git a/releasenotes/notes/allocation-candidates-traits-1adf079ed0c6563c.yaml b/releasenotes/notes/allocation-candidates-traits-1adf079ed0c6563c.yaml index af7aae46a0cd..eceb9b3aef1c 100644 --- a/releasenotes/notes/allocation-candidates-traits-1adf079ed0c6563c.yaml +++ b/releasenotes/notes/allocation-candidates-traits-1adf079ed0c6563c.yaml @@ -6,5 +6,5 @@ features: separated by ``,``, which is used to further limit the list of allocation requests to resource providers that have the capacity to fulfill the requested resources AND *collectively* have all of the required traits - associated with them. In the same microversion, the candidate attached - traits returned in the provider summary. + associated with them. In the same microversion, the provider summary + includes the traits associated with each provider. diff --git a/releasenotes/notes/request-traits-in-nova-ffcb00f76229b6e9.yaml b/releasenotes/notes/request-traits-in-nova-ffcb00f76229b6e9.yaml index a35e2745e686..bff1732698e0 100644 --- a/releasenotes/notes/request-traits-in-nova-ffcb00f76229b6e9.yaml +++ b/releasenotes/notes/request-traits-in-nova-ffcb00f76229b6e9.yaml @@ -1,14 +1,21 @@ --- features: - | - Add traits support to the Nova. The new flavor extra spec is added to + Added traits support to the scheduler. A new flavor extra spec is added to support specifying the required traits. The syntax of extra spec is - as below: + ``trait:=required``, for example: - trait:HW_CPU_X86_AVX2=required - trait:STORAGE_DISK_SSD=required - The scheduler will pass traits to the GET /allocation_candidates endpoint - in the Placement API to filter out resource providers with each of the - required traits. Currently the only valid value is required. For any other - value will be considered as invalid. + The scheduler will pass required traits to the + ``GET /allocation_candidates`` endpoint in the Placement API to include + only resource providers that can satisfy the required traits. Currently + the only valid value is ``required``. Any other value will be considered + invalid. + + This requires that the Placement API version 1.17 is available before + the ``nova-scheduler`` service can use this feature. + + The FilterScheduler is currently the only scheduler driver that supports + this feature.