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))
p_sums = _transform_provider_summaries(alloc_cands.provider_summaries,
include_traits)
include_traits=include_traits)
return {
'allocation_requests': a_reqs,
'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(','))
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

View File

@ -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")

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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:<trait_name>=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.