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 <mriedem.os@gmail.com>

Change-Id: I366b97ef3c141834f48949700edb968a7c7c4167
This commit is contained in:
He Jie Xu 2018-01-24 14:15:56 +08:00 committed by Matt Riedemann
parent 6a818ebc19
commit 284ba35c33
9 changed files with 39 additions and 25 deletions

View File

@ -196,7 +196,7 @@ def _transform_allocation_candidates(alloc_cands, want_version):
include_traits = want_version.matches((1, 17)) include_traits = want_version.matches((1, 17))
p_sums = _transform_provider_summaries(alloc_cands.provider_summaries, p_sums = _transform_provider_summaries(alloc_cands.provider_summaries,
include_traits) include_traits=include_traits)
return { return {
'allocation_requests': a_reqs, 'allocation_requests': a_reqs,
'provider_summaries': p_sums, 'provider_summaries': p_sums,

View File

@ -306,9 +306,9 @@ def normalize_traits_qs_param(val):
""" """
ret = set(substr.strip() for substr in val.split(',')) ret = set(substr.strip() for substr in val.split(','))
if not all(trait for trait in ret): if not all(trait for trait in ret):
msg = _('Invalid query string parameters: Expected \'required\' ' msg = _("Invalid query string parameters: Expected 'required' "
'parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC. ' "parameter value of the form: HW_CPU_X86_VMX,CUSTOM_MAGIC. "
'Got: "%s"') % val "Got: %s") % val
raise webob.exc.HTTPBadRequest(msg) raise webob.exc.HTTPBadRequest(msg)
return ret return ret

View File

@ -196,9 +196,8 @@ class UpgradeCommands(object):
versions = self._placement_get("/") versions = self._placement_get("/")
max_version = pkg_resources.parse_version( max_version = pkg_resources.parse_version(
versions["versions"][0]["max_version"]) versions["versions"][0]["max_version"])
# NOTE(mriedem): 1.14 is required by nova-compute services to # NOTE(mriedem): 1.17 is required by nova-scheduler to get
# get and set parent resource provider UUIDs for nested resource # allocation candidates with required traits from the flavor.
# provider support.
# NOTE: If you bump this version, remember to update the history # NOTE: If you bump this version, remember to update the history
# section in the nova-status man page (doc/source/cli/nova-status). # section in the nova-status man page (doc/source/cli/nova-status).
needs_version = pkg_resources.parse_version("1.17") needs_version = pkg_resources.parse_version("1.17")

View File

@ -2216,7 +2216,7 @@ class PowerVMAPIFailed(NovaException):
class TraitNotFound(NotFound): class TraitNotFound(NotFound):
msg_fmt = _("No such trait(s): %(name)s.") msg_fmt = _("No such trait(s): %(names)s.")
class TraitExists(NovaException): class TraitExists(NovaException):

View File

@ -2481,7 +2481,7 @@ class Trait(base.NovaObject, base.NovaTimestampObject):
result = context.session.query(models.Trait).filter_by( result = context.session.query(models.Trait).filter_by(
name=name).first() name=name).first()
if not result: if not result:
raise exception.TraitNotFound(name=name) raise exception.TraitNotFound(names=name)
return result return result
@classmethod @classmethod
@ -2500,7 +2500,7 @@ class Trait(base.NovaObject, base.NovaTimestampObject):
res = context.session.query(models.Trait).filter_by( res = context.session.query(models.Trait).filter_by(
name=name).delete() name=name).delete()
if not res: if not res:
raise exception.TraitNotFound(name=name) raise exception.TraitNotFound(names=name)
def destroy(self): def destroy(self):
if 'name' not in 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 # Double-check that we found a trait ID for each requested name
if len(trait_map) != len(traits): if len(trait_map) != len(traits):
missing = traits - set(trait_map) 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 # Contains a set of resource provider IDs that share some inventory for
# each resource class requested. We do this here as an optimization. If # each resource class requested. We do this here as an optimization. If

View File

@ -311,8 +311,8 @@ class SchedulerReportClient(object):
the requested resource constraints. the requested resource constraints.
The provider summaries is a dict, keyed by resource provider UUID, of The provider summaries is a dict, keyed by resource provider UUID, of
inventory and capacity information for any resource provider involved inventory and capacity information and traits for any resource
in the allocation_requests. provider involved in the allocation_requests.
:returns: A tuple with a list of allocation_request dicts, a dict of :returns: A tuple with a list of allocation_request dicts, a dict of
provider information, and the microversion used to request provider information, and the microversion used to request
@ -347,13 +347,20 @@ class SchedulerReportClient(object):
return (data['allocation_requests'], data['provider_summaries'], return (data['allocation_requests'], data['provider_summaries'],
version) version)
msg = ("Failed to retrieve allocation candidates from placement API "
"for filters %(resources)s. Got %(status_code)d: %(err_text)s.")
args = { args = {
'resources': res, 'resources': res,
'status_code': resp.status_code, 'status_code': resp.status_code,
'err_text': resp.text, '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) LOG.error(msg, args)
return None, None, None return None, None, None

View File

@ -56,7 +56,7 @@ allocation_candidates_required:
required: false required: false
min_version: 1.17 min_version: 1.17
description: > 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 response will be for resource providers that have capacity for all
requested resources and the set of those resource providers will requested resources and the set of those resource providers will
*collectively* contain all of the required traits. *collectively* contain all of the required traits.
@ -252,7 +252,8 @@ provider_summaries:
description: > description: >
A dictionary keyed by resource provider UUID, A dictionary keyed by resource provider UUID,
of dictionaries of inventory/capacity information. The list of traits 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 reserved: &reserved
type: integer type: integer
in: body in: body

View File

@ -6,5 +6,5 @@ features:
separated by ``,``, which is used to further limit the list of allocation separated by ``,``, which is used to further limit the list of allocation
requests to resource providers that have the capacity to fulfill the requests to resource providers that have the capacity to fulfill the
requested resources AND *collectively* have all of the required traits requested resources AND *collectively* have all of the required traits
associated with them. In the same microversion, the candidate attached associated with them. In the same microversion, the provider summary
traits returned in the provider summary. includes the traits associated with each provider.

View File

@ -1,14 +1,21 @@
--- ---
features: 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 support specifying the required traits. The syntax of extra spec is
as below: ``trait:<trait_name>=required``, for example:
- trait:HW_CPU_X86_AVX2=required - trait:HW_CPU_X86_AVX2=required
- trait:STORAGE_DISK_SSD=required - trait:STORAGE_DISK_SSD=required
The scheduler will pass traits to the GET /allocation_candidates endpoint The scheduler will pass required traits to the
in the Placement API to filter out resource providers with each of the ``GET /allocation_candidates`` endpoint in the Placement API to include
required traits. Currently the only valid value is required. For any other only resource providers that can satisfy the required traits. Currently
value will be considered as invalid. 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.