Example #1
0
    def test_aggregate_values_from_db(self, get_by_host):
        context = mock.MagicMock()
        get_by_host.return_value = objects.AggregateList(
            objects=_AGGREGATE_FIXTURES)

        values = utils.aggregate_values_from_db(context,
                                                'fake-host', key_name='k1')

        get_by_host.assert_called_with(context.elevated(),
                                       'fake-host', key='k1')
        self.assertEqual(set(['1', '3']), values)
Example #2
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_db(
            filter_properties['context'], host_state.host, 'instance_type')

        if not aggregate_vals:
            return True
        return instance_type['name'] in aggregate_vals
Example #3
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_db(
            filter_properties['context'], host_state.host, 'instance_type')

        if not aggregate_vals:
            return True
        return instance_type['name'] in aggregate_vals
Example #4
0
    def test_aggregate_values_from_db(self, get_by_host):
        context = mock.MagicMock()
        get_by_host.return_value = objects.AggregateList(
            objects=_AGGREGATE_FIXTURES)

        values = utils.aggregate_values_from_db(context,
                                                'fake-host',
                                                key_name='k1')

        get_by_host.assert_called_with(context.elevated(),
                                       'fake-host',
                                       key='k1')
        self.assertEqual(set(['1', '3']), values)
Example #5
0
    def test_aggregate_values_from_db(self, get_by_host):
        aggrA = mock.MagicMock()
        aggrB = mock.MagicMock()
        context = mock.MagicMock()

        get_by_host.return_value = [aggrA, aggrB]
        aggrA.metadata = {'k1': 1, 'k2': 2}
        aggrB.metadata = {'k1': 3, 'k2': 4}

        values = utils.aggregate_values_from_db(context, 'h1', key_name='k1')

        self.assertTrue(context.elevated.called)
        self.assertEqual(set([1, 3]), values)
Example #6
0
    def _weigh_object(self, host_state, weight_properties):
        """if aggregate don't set ratio, weight is zero"""
        aggregate_vals = utils.aggregate_values_from_db(
            weight_properties['context'], host_state.host,
            'cpu_allocation_ratio')

        try:
            ratio = self._validate_num_values(aggregate_vals,
                                              CONF.cpu_allocation_ratio)
        except ValueError as e:
            LOG.warning(_LW("Could not decode cpu_allocation_ratio: '%s'"), e)
            ratio = CONF.cpu_allocation_ratio
        return host_state.vcpus_total * ratio - host_state.vcpus_used
Example #7
0
    def test_aggregate_values_from_db(self, get_by_host):
        aggrA = mock.MagicMock()
        aggrB = mock.MagicMock()
        context = mock.MagicMock()

        get_by_host.return_value = [aggrA, aggrB]
        aggrA.metadata = {'k1': 1, 'k2': 2}
        aggrB.metadata = {'k1': 3, 'k2': 4}

        values = utils.aggregate_values_from_db(context, 'h1', key_name='k1')

        self.assertTrue(context.elevated.called)
        self.assertEqual(set([1, 3]), values)
Example #8
0
    def _weigh_object(self, host_state, weight_properties):
        """if aggregate don't set ratio, weight is zero"""
        aggregate_vals = utils.aggregate_values_from_db(
            weight_properties['context'],
            host_state.host,
            'cpu_allocation_ratio')

        try:
            ratio = self._validate_num_values(
                aggregate_vals, CONF.cpu_allocation_ratio)
        except ValueError as e:
            LOG.warning(_LW("Could not decode cpu_allocation_ratio: '%s'"), e)
            ratio = CONF.cpu_allocation_ratio
        return host_state.vcpus_total*ratio - host_state.vcpus_used
Example #9
0
    def _get_disk_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_db(
            filter_properties["context"], host_state.host, "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
Example #10
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_db(
            filter_properties['context'], host_state.host,
            'cpu_allocation_ratio')
        try:
            ratio = self._validate_num_values(aggregate_vals,
                                              CONF.cpu_allocation_ratio)
        except ValueError as e:
            LOG.warning(_LW("Could not decode cpu_allocation_ratio: '%s'"), e)
            ratio = CONF.cpu_allocation_ratio

        return ratio
    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_db(
            filter_properties['context'],
            host_state.host,
            '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.warn(_LW("Could not decode max_io_ops_per_host: '%s'"), e)
            value = CONF.max_io_ops_per_host

        return value
Example #12
0
    def _get_max_instances_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 solutnumn here to fix
        # all filters with aggregate DB call things.
        aggregate_vals = utils.aggregate_values_from_db(
            filter_properties['context'], host_state.host,
            'max_instances_per_host')
        try:
            value = utils.validate_num_values(aggregate_vals,
                                              CONF.max_instances_per_host,
                                              cast_to=int)
        except ValueError as e:
            LOG.warn(_LW("Could not decode max_instances_per_host: '%s'"), e)
            value = CONF.max_instances_per_host

        return value