def test_cgroup_allocations(Cgroup_mock, PerfCounters_mock):
    rdt_information = RDTInformation(True, True, True, True, '0', '0', 0, 0, 0)
    platform_mock = Mock(spec=Platform,
                         sockets=1,
                         cpus=1,
                         rdt_information=rdt_information)

    foo_container = Container('/somepath', platform=platform_mock)
    foo_container._cgroup.allocation_configuration = AllocationConfiguration()
    foo_container._cgroup.platform_cpus = 10
    foo_container._cgroup.platform_sockets = 1

    quota_allocation_value = QuotaAllocationValue(0.2, foo_container,
                                                  dict(foo='bar'))
    quota_allocation_value.perform_allocations()
    assert quota_allocation_value.generate_metrics() == [
        allocation_metric('cpu_quota', 0.2, foo='bar')
    ]

    shares_allocation_value = SharesAllocationValue(0.5, foo_container,
                                                    dict(foo='bar'))
    shares_allocation_value.perform_allocations()

    assert shares_allocation_value.generate_metrics() == [
        allocation_metric('cpu_shares', 0.5, foo='bar')
    ]

    cpuset_allocation_value = CPUSetAllocationValue('0-2,4,6-8', foo_container,
                                                    dict(foo='bar'))
    cpuset_allocation_value.perform_allocations()

    assert cpuset_allocation_value.generate_metrics() == [
        allocation_metric('cpuset', [0, 1, 2, 4, 6, 7, 8], foo='bar')
    ]

    Cgroup_mock.assert_has_calls([
        call().set_quota(0.2),
        call().set_shares(0.5),
        call().set_cpuset('0,1,2,4,6,7,8', '0')
    ], True)
示例#2
0
                                    TaskAllocationsValues, AllocationRunner,
                                    validate_shares_allocation_for_kubernetes,
                                    _get_tasks_allocations,
                                    _update_tasks_data_with_allocations)
from wca.runners.measurement import MeasurementRunner
from wca.storage import Storage


@pytest.mark.parametrize('tasks_allocations, expected_metrics', (
    ({}, []),
    ({
        't1_task_id': {
            AllocationType.SHARES: 0.5
        }
    }, [
        allocation_metric(
            'cpu_shares', value=0.5, container_name='t1', task='t1_task_id')
    ]),
    ({
        't1_task_id': {
            AllocationType.RDT: RDTAllocation(mb='MB:0=20')
        }
    }, [
        allocation_metric('rdt_mb',
                          20,
                          group_name='t1',
                          domain_id='0',
                          container_name='t1',
                          task='t1_task_id')
    ]),
    ({
        't1_task_id': {
示例#3
0
             validate=Mock(
                 side_effect=InvalidAllocations('some generic error')))
    }), 'some generic error'),
    (AllocationsDict({'x': BoxedNumericDummy(-1)
                      }), 'does not belong to range'),
    (AllocationsDict({'x': AllocationsDict({'y': BoxedNumericDummy(-1)})
                      }), 'does not belong to range'),
])
def test_allocation_value_validate(allocation_dict, expected_error):
    with pytest.raises(InvalidAllocations, match=expected_error):
        allocation_dict.validate()


@pytest.mark.parametrize('allocation_value, expected_metrics', [
    (AllocationsDict({}), []),
    (BoxedNumericDummy(2), [allocation_metric('numeric', 2)]),
    (AllocationsDict({
        'x': BoxedNumericDummy(2),
        'y': BoxedNumericDummy(3)
    }), [allocation_metric('numeric', 2),
         allocation_metric('numeric', 3)]),
    (AllocationsDict({
        'x': BoxedNumericDummy(2),
        'y': BoxedNumericDummy(3)
    }), [allocation_metric('numeric', 2),
         allocation_metric('numeric', 3)]),
    (AllocationsDict({
        'x': BoxedNumericDummy(2),
        'y': BoxedNumericDummy(3.5, common_labels=dict(foo='bar'))
    }), [
        allocation_metric('numeric', 2),
示例#4
0
def test_cgroup_allocations(Cgroup_mock, PerfCounters_mock):
    rdt_information = RDTInformation(True, True, True, True, '0', '0', 0, 0, 0)

    platform_mock = Mock(
        spec=Platform,
        cpus=10,
        sockets=1,
        rdt_information=rdt_information,
        node_cpus={
            0: [0, 1],
            1: [2, 3]
        },
    )

    foo_container = Container('/somepath', platform=platform_mock)
    foo_container._cgroup.allocation_configuration = AllocationConfiguration()
    foo_container._cgroup.platform = platform_mock

    quota_allocation_value = QuotaAllocationValue(0.2, foo_container,
                                                  dict(foo='bar'))
    quota_allocation_value.perform_allocations()
    assert quota_allocation_value.generate_metrics() == [
        allocation_metric('cpu_quota', 0.2, foo='bar')
    ]

    shares_allocation_value = SharesAllocationValue(0.5, foo_container,
                                                    dict(foo='bar'))
    shares_allocation_value.perform_allocations()

    assert shares_allocation_value.generate_metrics() == [
        allocation_metric('cpu_shares', 0.5, foo='bar')
    ]

    cpuset_cpus_allocation_value = CPUSetCPUSAllocationValue(
        '0-2,4,6-8', foo_container, dict(foo='bar'))
    cpuset_cpus_allocation_value.perform_allocations()

    cpuset_mems_allocation_value = CPUSetMEMSAllocationValue(
        '0-1', foo_container, dict(foo='bar'))
    cpuset_mems_allocation_value.perform_allocations()

    assert cpuset_cpus_allocation_value.generate_metrics() == [
        Metric(name='allocation_cpuset_cpus_number_of_cpus',
               value=7,
               labels={
                   'allocation_type': AllocationType.CPUSET_CPUS,
                   'foo': 'bar'
               },
               type=MetricType.GAUGE)
    ]

    assert cpuset_mems_allocation_value.generate_metrics() == [
        Metric(name='allocation_cpuset_mems_number_of_mems',
               value=2,
               labels={
                   'allocation_type': AllocationType.CPUSET_MEMS,
                   'foo': 'bar'
               },
               type=MetricType.GAUGE)
    ]

    Cgroup_mock.assert_has_calls([
        call().set_quota(0.2),
        call().set_shares(0.5),
        call().set_cpuset_cpus({0, 1, 2, 4, 6, 7, 8}),
        call().set_cpuset_mems({0, 1})
    ], True)
示例#5
0
            return None

    current_value = convert(current)
    new_value = convert(new)

    got_target, got_changeset = \
        new_value.calculate_changeset(current_value)

    assert got_target == convert(expected_target)
    assert got_changeset == convert(expected_changeset)


@pytest.mark.parametrize('rdt_allocation, extra_labels, expected_metrics', (
        (RDTAllocation(), {}, []),
        (RDTAllocation(mb='mb:0=20'), {}, [
            allocation_metric('rdt_mb', 20, group_name='c1', domain_id='0', container_name='c1')
        ]),
        (RDTAllocation(mb='mb:0=20'), {'foo': 'bar'}, [
            allocation_metric('rdt_mb', 20, group_name='c1', domain_id='0',
                              container_name='c1', foo='bar')
        ]),
        (RDTAllocation(mb='mb:0=20'), {}, [
            allocation_metric('rdt_mb', 20, group_name='c1', domain_id='0', container_name='c1')
        ]),
        (RDTAllocation(mb='mb:0=20;1=30'), {}, [
            allocation_metric('rdt_mb', 20, group_name='c1', domain_id='0', container_name='c1'),
            allocation_metric('rdt_mb', 30, group_name='c1', domain_id='1', container_name='c1'),
        ]),
        (RDTAllocation(l3='l3:0=ff'), {}, [
            allocation_metric('rdt_l3_cache_ways', 8, group_name='c1', domain_id='0',
                              container_name='c1'),