AggregateCoreFilter return incorrect value

Bug #1431746 reported by shihanzhang
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
shihanzhang

Bug Description

I find AggregateCoreFilter will return incorrect value, the analysis is bellow:

class AggregateCoreFilter(BaseCoreFilter):
    def _get_cpu_allocation_ratio(self, host_state, filter_properties):
        # TODO(uni): DB query in filter is a performance hit, especially for
        # system with lots of hosts. Will need a general solution here to fix
        # all filters with aggregate DB call things.
        aggregate_vals = utils.aggregate_values_from_key(
            host_state,
            'cpu_allocation_ratio')
        try:
            ratio = utils.validate_num_values(
                aggregate_vals, CONF.cpu_allocation_ratio, cast_to=float)
        except ValueError as e:
            LOG.warning(_LW("Could not decode cpu_allocation_ratio: '%s'"), e)
            ratio = CONF.cpu_allocation_ratio

in function validate_num_values, it use min() to get the minimum ratio, but for aggregate, its 'cpu_allocation_ratio' is a string,
for example: vals=set('10', '9'), the 'validate_num_values' will return 10, but correct is 9

def validate_num_values(vals, default=None, cast_to=int, based_on=min):
    num_values = len(vals)
    if num_values == 0:
        return default

    if num_values > 1:
        LOG.info(_LI("%(num_values)d values found, "
                     "of which the minimum value will be used."),
                 {'num_values': num_values})

    return cast_to(based_on(vals))

Changed in nova:
assignee: nobody → shihanzhang (shihanzhang)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/164128

Changed in nova:
status: New → In Progress
Changed in nova:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/164128
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=e3d3f7435cf60fbb469cdd547a3624a2f0a23a55
Submitter: Jenkins
Branch: master

commit e3d3f7435cf60fbb469cdd547a3624a2f0a23a55
Author: shihanzhang <email address hidden>
Date: Fri Mar 13 17:54:50 2015 +0800

    Fix AggregateCoreFilter return incorrect value

    the value of aggregate metadata 'cpu_allocation_ratio' is string,
    in 'validate_num_values',it should not directly use min/max to get
    values.

    Change-Id: I486da120939ea3fa139ee81d9ea3fb15373bc606
    Closes-Bug: #1431746

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → kilo-rc1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: kilo-rc1 → 2015.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.