Esempio n. 1
0
    def test_aggregate_values_from_key_with_wrong_key(self):
        host_state = fakes.FakeHostState(
            'fake', 'node', {'aggregates': _AGGREGATE_FIXTURES})

        values = utils.aggregate_values_from_key(host_state, key_name='k3')

        self.assertEqual(set(), values)
Esempio n. 2
0
    def test_aggregate_values_from_key_with_wrong_key(self):
        host_state = fakes.FakeHostState('fake', 'node',
                                         {'aggregates': _AGGREGATE_FIXTURES})

        values = utils.aggregate_values_from_key(host_state, key_name='k3')

        self.assertEqual(set(), values)
Esempio n. 3
0
def get_weight_multiplier(host_state, multiplier_name, multiplier_config):
    """Given a HostState object, multplier_type name and multiplier_config,
    returns the weight multiplier.

    It reads the "multiplier_name" from "aggregate metadata" in host_state
    to override the multiplier_config. If the aggregate metadata doesn't
    contain the multiplier_name, the multiplier_config will be returned
    directly.

    :param host_state: The HostState object, which contains aggregate metadata
    :param multiplier_name: The weight multiplier name, like
           "cpu_weight_multiplier".
    :param multiplier_config: The weight multiplier configuration value
    """
    aggregate_vals = filters_utils.aggregate_values_from_key(
        host_state, multiplier_name)
    try:
        value = filters_utils.validate_num_values(aggregate_vals,
                                                  multiplier_config,
                                                  cast_to=float)
    except ValueError as e:
        LOG.warning("Could not decode '%(name)s' weight multiplier: %(exce)s",
                    {
                        'exce': e,
                        'name': multiplier_name
                    })
        value = multiplier_config

    return value
Esempio n. 4
0
def get_weight_multiplier(host_state, multiplier_name, multiplier_config):
    """Given a HostState object, multplier_type name and multiplier_config,
    returns the weight multiplier.

    It reads the "multiplier_name" from "aggregate metadata" in host_state
    to override the multiplier_config. If the aggregate metadata doesn't
    contain the multiplier_name, the multiplier_config will be returned
    directly.

    :param host_state: The HostState object, which contains aggregate metadata
    :param multiplier_name: The weight multiplier name, like
           "cpu_weight_multiplier".
    :param multiplier_config: The weight multiplier configuration value
    """
    aggregate_vals = filters_utils.aggregate_values_from_key(host_state,
                                                             multiplier_name)
    try:
        value = filters_utils.validate_num_values(
            aggregate_vals, multiplier_config, cast_to=float)
    except ValueError as e:
        LOG.warning("Could not decode '%(name)s' weight multiplier: %(exce)s",
                    {'exce': e, 'name': multiplier_name})
        value = multiplier_config

    return value
Esempio n. 5
0
    def host_passes(self, host_state, filter_properties):
        instance_type = filter_properties.get('instance_type')

        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'instance_type')

        if not aggregate_vals:
            return True
        return instance_type['name'] in aggregate_vals
Esempio n. 6
0
    def host_passes(self, host_state, spec_obj):
        # TODO(stephenfin): Add support for 'flavor' key
        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'instance_type')

        for val in aggregate_vals:
            if spec_obj.flavor.name in [x.strip() for x in val.split(',')]:
                return True
        return not aggregate_vals
Esempio n. 7
0
    def _get_max_io_ops_per_host(self, host_state, filter_properties):
        aggregate_vals = utils.aggregate_values_from_key(host_state, "max_io_ops_per_host")
        try:
            value = utils.validate_num_values(aggregate_vals, CONF.max_io_ops_per_host, cast_to=int)
        except ValueError as e:
            LOG.warning(_LW("Could not decode max_io_ops_per_host: '%s'"), e)
            value = CONF.max_io_ops_per_host

        return value
Esempio n. 8
0
    def _get_max_instances_per_host(self, host_state, spec_obj):
        max_instances_per_host = CONF.filter_scheduler.max_instances_per_host
        aggregate_vals = utils.aggregate_values_from_key(host_state, "max_instances_per_host")
        try:
            value = utils.validate_num_values(aggregate_vals, max_instances_per_host, cast_to=int)
        except ValueError as e:
            LOG.warning(_LW("Could not decode max_instances_per_host: '%s'"), e)
            value = max_instances_per_host

        return value
Esempio n. 9
0
    def host_passes(self, host_state, filter_properties):
        instance_type = filter_properties.get('instance_type')

        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'instance_type')

        for val in aggregate_vals:
            if (instance_type['name'] in [x.strip() for x in val.split(',')]):
                return True
        return not aggregate_vals
Esempio n. 10
0
    def host_passes(self, host_state, spec_obj):
        instance_type = spec_obj.flavor

        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'instance_type')

        for val in aggregate_vals:
            if (instance_type.name in [x.strip() for x in val.split(',')]):
                return True
        return not aggregate_vals
Esempio n. 11
0
    def host_passes(self, host_state, spec_obj):
        instance_type = spec_obj.flavor

        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'instance_type')

        for val in aggregate_vals:
            if (instance_type.name in
                    [x.strip() for x in val.split(',')]):
                return True
        return not aggregate_vals
Esempio n. 12
0
    def host_passes(self, host_state, filter_properties):
        instance_type = filter_properties.get('instance_type')

        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'instance_type')

        for val in aggregate_vals:
            if (instance_type['name'] in
                    [x.strip() for x in val.split(',')]):
                return True
        return not aggregate_vals
Esempio n. 13
0
    def _get_disk_allocation_ratio(self, host_state, filter_properties):
        aggregate_vals = utils.aggregate_values_from_key(
            host_state,
            'disk_allocation_ratio')
        try:
            ratio = utils.validate_num_values(
                aggregate_vals, CONF.disk_allocation_ratio, cast_to=float)
        except ValueError as e:
            LOG.warning(_LW("Could not decode disk_allocation_ratio: '%s'"), e)
            ratio = CONF.disk_allocation_ratio

        return ratio
Esempio n. 14
0
    def _get_max_io_ops_per_host(self, host_state, filter_properties):
        aggregate_vals = utils.aggregate_values_from_key(
            host_state,
            'max_io_ops_per_host')
        try:
            value = utils.validate_num_values(
                aggregate_vals, CONF.max_io_ops_per_host, cast_to=int)
        except ValueError as e:
            LOG.warning(_LW("Could not decode max_io_ops_per_host: '%s'"), e)
            value = CONF.max_io_ops_per_host

        return value
Esempio n. 15
0
    def _get_cpu_allocation_ratio(self, host_state, spec_obj):
        aggregate_vals = utils.aggregate_values_from_key(
            host_state,
            'cpu_allocation_ratio')
        try:
            ratio = utils.validate_num_values(
                aggregate_vals, host_state.cpu_allocation_ratio, cast_to=float)
        except ValueError as e:
            LOG.warning("Could not decode cpu_allocation_ratio: '%s'", e)
            ratio = host_state.cpu_allocation_ratio

        return ratio
Esempio n. 16
0
    def host_passes(self, host_state, filter_properties):
        instance_type = filter_properties.get('instance_type')

        # 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, 'instance_type')

        if not aggregate_vals:
            return True
        return instance_type['name'] in aggregate_vals
Esempio n. 17
0
    def _get_cpu_allocation_ratio(self, host_state, filter_properties):
        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

        return ratio
Esempio n. 18
0
    def _get_max_io_ops_per_host(self, host_state, spec_obj):
        max_io_ops_per_host = CONF.filter_scheduler.max_io_ops_per_host
        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'max_io_ops_per_host')

        try:
            value = utils.validate_num_values(aggregate_vals,
                                              max_io_ops_per_host,
                                              cast_to=int)
        except ValueError as e:
            LOG.warning(_LW("Could not decode max_io_ops_per_host: '%s'"), e)
            value = max_io_ops_per_host

        return value
Esempio n. 19
0
    def _get_max_io_ops_per_host(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, 'max_io_ops_per_host')
        try:
            value = utils.validate_num_values(aggregate_vals,
                                              CONF.max_io_ops_per_host,
                                              cast_to=int)
        except ValueError as e:
            LOG.warning(_LW("Could not decode max_io_ops_per_host: '%s'"), e)
            value = CONF.max_io_ops_per_host

        return value
Esempio n. 20
0
    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

        return ratio
Esempio n. 21
0
    def _get_max_io_ops_per_host(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,
            'max_io_ops_per_host')
        try:
            value = utils.validate_num_values(
                aggregate_vals, CONF.max_io_ops_per_host, cast_to=int)
        except ValueError as e:
            LOG.warning(_LW("Could not decode max_io_ops_per_host: '%s'"), e)
            value = CONF.max_io_ops_per_host

        return value
Esempio n. 22
0
    def host_passes(self, host_state, spec_obj):
        instance_type = spec_obj.flavor

        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'instance_type')

        for val in aggregate_vals:
            if (instance_type.name in [x.strip() for x in val.split(',')]):
                return True
        if aggregate_vals:
            msg = ('%(name)s not found in: %(agg)s' % {
                'name': instance_type.name,
                'agg': aggregate_vals
            })
            self.filter_reject(host_state, spec_obj, msg)
        return not aggregate_vals
Esempio n. 23
0
    def _get_max_instances_per_host(self, host_state, spec_obj):
        max_instances_per_host = CONF.filter_scheduler.max_instances_per_host

        # TODO(sfinucan): Remove this warning when the named config options
        # gains a 'min' parameter.
        if max_instances_per_host < 1:
            LOG.warning(_LW('Future versions of nova will restrict the '
                '"filter_scheduler.max_instances_per_host" config option to '
                'values >=0. Update your configuration file to mitigate '
                'future upgrade issues.'))

        aggregate_vals = utils.aggregate_values_from_key(
            host_state,
            'max_instances_per_host')
        try:
            value = utils.validate_num_values(
                aggregate_vals, max_instances_per_host, cast_to=int)
        except ValueError as e:
            LOG.warning(_LW("Could not decode max_instances_per_host: '%s'"),
                        e)
            value = max_instances_per_host

        return value
    def _get_max_instances_per_host(self, host_state, spec_obj):
        max_instances_per_host = CONF.filter_scheduler.max_instances_per_host

        # TODO(sfinucan): Remove this warning when the named config options
        # gains a 'min' parameter.
        if max_instances_per_host < 1:
            LOG.warning(
                _LW('Future versions of nova will restrict the '
                    '"filter_scheduler.max_instances_per_host" config option to '
                    'values >=0. Update your configuration file to mitigate '
                    'future upgrade issues.'))

        aggregate_vals = utils.aggregate_values_from_key(
            host_state, 'max_instances_per_host')
        try:
            value = utils.validate_num_values(aggregate_vals,
                                              max_instances_per_host,
                                              cast_to=int)
        except ValueError as e:
            LOG.warning(_LW("Could not decode max_instances_per_host: '%s'"),
                        e)
            value = max_instances_per_host

        return value
Esempio n. 25
0
    def test_aggregate_values_from_key_with_wrong_key(self):
        host_state = fakes.FakeHostState("fake", "node", {"aggregates": _AGGREGATE_FIXTURES})

        values = utils.aggregate_values_from_key(host_state, key_name="k3")

        self.assertEqual(set(), values)