コード例 #1
0
ファイル: testing.py プロジェクト: Damenus/owca
    def unpatched():

        if len(subcgroups_paths):
            platform = Platform(sockets=1,
                                cores=1,
                                cpus=2,
                                numa_nodes=2,
                                topology={0: {
                                    0: [1, 2]
                                }},
                                cpu_model='intel xeon',
                                cpu_model_number=0x5E,
                                cpu_codename=CPUCodeName.SKYLAKE,
                                timestamp=time.time(),
                                rdt_information=RDTInformation(
                                    True, True, rdt_mb_control_enabled,
                                    rdt_cache_control_enabled, '0', '0', 0, 0,
                                    0),
                                node_cpus={0: {0, 1}},
                                node_distances={0: {
                                    0: 10
                                }},
                                measurements={},
                                swap_enabled=False)
            return ContainerSet(
                cgroup_path=cgroup_path,
                cgroup_paths=subcgroups_paths,
                platform=platform,
                allocation_configuration=AllocationConfiguration()
                if with_config else None,
                resgroup=ResGroup(name=resgroup_name) if rdt_enabled else None,
                event_names=['task_cycles'])
        else:
            platform = Platform(sockets=1,
                                cores=1,
                                cpus=2,
                                numa_nodes=2,
                                topology={0: {
                                    0: [1, 2]
                                }},
                                cpu_model='intel xeon',
                                cpu_model_number=0x5E,
                                cpu_codename=CPUCodeName.SKYLAKE,
                                timestamp=time.time(),
                                rdt_information=RDTInformation(
                                    True, True, True, True, '0', '0', 0, 0, 0),
                                node_cpus={0: {0, 1}},
                                node_distances={0: {
                                    0: 10
                                }},
                                measurements={},
                                swap_enabled=False)
            return Container(
                cgroup_path=cgroup_path,
                platform=platform,
                allocation_configuration=AllocationConfiguration()
                if with_config else None,
                resgroup=ResGroup(name=resgroup_name) if rdt_enabled else None,
                event_names=['task_cycles'],
            )
コード例 #2
0
def test_migrate_pages_raise_exception_when_swap_is_enabled(*mocks):
    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]
        },
        numa_nodes=2,
        swap_enabled=is_swap_enabled(),
    )

    foo_container = Container('/somepath', platform=platform_mock)

    foo_container._cgroup.platform = platform_mock

    migrate_pages = MigratePagesAllocationValue(0, foo_container,
                                                dict(foo='bar'))

    with pytest.raises(
            InvalidAllocations,
            match=
            "Swap should be disabled due to possibility of OOM killer occurrence!"
    ):
        migrate_pages.validate()
コード例 #3
0
 def unpatched():
     if len(subcgroups_paths):
         return ContainerSet(
             cgroup_path=cgroup_path,
             cgroup_paths=subcgroups_paths,
             platform_cpus=1,
             platform_sockets=1,
             allocation_configuration=AllocationConfiguration()
             if with_config else None,
             resgroup=ResGroup(name=resgroup_name) if rdt_enabled else None,
             rdt_information=RDTInformation(True, True,
                                            rdt_mb_control_enabled,
                                            rdt_cache_control_enabled, '0',
                                            '0', 0, 0, 0),
             event_names=DEFAULT_EVENTS)
     else:
         return Container(
             cgroup_path=cgroup_path,
             platform_cpus=1,
             platform_sockets=1,
             rdt_information=RDTInformation(True, True, True, True, '0',
                                            '0', 0, 0, 0),
             allocation_configuration=AllocationConfiguration()
             if with_config else None,
             resgroup=ResGroup(name=resgroup_name) if rdt_enabled else None,
             event_names=DEFAULT_EVENTS)
コード例 #4
0
def test_prepare_task_data_cgroup_not_found(*mocks):
    containers = {
        task('/t1', labels={'label_key': 'label_value'}, resources={'cpu': 3}):
        Container('/t1', platform_mock)
    }
    tasks_measurements, tasks_resources, tasks_labels = \
        _prepare_tasks_data(containers)
    assert tasks_measurements == {}
コード例 #5
0
def test_prepare_task_data_cgroup_not_found(*mocks):
    containers = {
        task('/t1', labels={'label_key': 'label_value'}, resources={'cpu': 3}):
        Container('/t1', platform_mock)
    }
    with pytest.raises(MissingMeasurementException):
        tasks_measurements, tasks_resources, tasks_labels = \
            _prepare_tasks_data(containers)
コード例 #6
0
def test_prepare_task_data_cgroup_not_found(*mocks):
    rdt_information = RDTInformation(True, True, True, True, '0', '0', 0, 0, 0)
    containers = {
        task('/t1', labels={'label_key': 'label_value'}, resources={'cpu': 3}):
        Container('/t1', 1, 1, rdt_information)
    }
    tasks_measurements, tasks_resources, tasks_labels = \
        _prepare_tasks_data(containers)
    assert tasks_measurements == {}
def test_get_tasks_allocations_fail(*mock):
    containers = {
        task('/t1', labels={'label_key': 'label_value'}, resources={'cpu': 3}):
        Container('/t1',
                  platform_mock,
                  allocation_configuration=AllocationConfiguration(
                      cpu_quota_period=1000))
    }
    assert {} == _get_tasks_allocations(containers)
def test_get_tasks_allocations_fail(*mock):
    rdt_information = RDTInformation(True, True, True, True, '0', '0', 0, 0, 0)
    containers = {
        task('/t1', labels={'label_key': 'label_value'}, resources={'cpu': 3}):
            Container('/t1', 1, 1, rdt_information,
                      allocation_configuration=AllocationConfiguration(
                          cpu_quota_period=1000))
    }
    assert {} == _get_tasks_allocations(containers)
コード例 #9
0
def test_prepare_tasks_data(*mocks):
    containers = {
        task('/t1', labels={'label_key': 'label_value'}, resources={'cpu': 3}):
        Container('/t1', platform_mock)
    }

    tasks_measurements, tasks_resources, tasks_labels = _prepare_tasks_data(
        containers)

    assert tasks_measurements == {'t1_task_id': {'cpu_usage': 13}}
    assert tasks_resources == {'t1_task_id': {'cpu': 3}}
    assert tasks_labels == {'t1_task_id': {'label_key': 'label_value'}}
コード例 #10
0
def test_prepare_tasks_data(*mocks):
    rdt_information = RDTInformation(True, True, True, True, '0', '0', 0, 0, 0)
    containers = {
        task('/t1', labels={'label_key': 'label_value'}, resources={'cpu': 3}):
        Container('/t1', 1, 1, rdt_information)
    }

    tasks_measurements, tasks_resources, tasks_labels = _prepare_tasks_data(
        containers)

    assert tasks_measurements == {'t1_task_id': {'cpu_usage': 13}}
    assert tasks_resources == {'t1_task_id': {'cpu': 3}}
    assert tasks_labels == {'t1_task_id': {'label_key': 'label_value'}}
コード例 #11
0
    def unpatched():

        if len(subcgroups_paths):
            platform = Platform(sockets=1,
                                cores=1,
                                cpus=2,
                                cpu_model='intel xeon',
                                cpu_model_number=0x5E,
                                cpu_codename=CPUCodeName.SKYLAKE,
                                cpus_usage={
                                    0: 10,
                                    1: 10
                                },
                                total_memory_used=10,
                                timestamp=time.time(),
                                rdt_information=RDTInformation(
                                    True, True, rdt_mb_control_enabled,
                                    rdt_cache_control_enabled, '0', '0', 0, 0,
                                    0))
            return ContainerSet(
                cgroup_path=cgroup_path,
                cgroup_paths=subcgroups_paths,
                platform=platform,
                allocation_configuration=AllocationConfiguration()
                if with_config else None,
                resgroup=ResGroup(name=resgroup_name) if rdt_enabled else None,
                event_names=DEFAULT_EVENTS)
        else:
            platform = Platform(sockets=1,
                                cores=1,
                                cpus=2,
                                cpu_model='intel xeon',
                                cpu_model_number=0x5E,
                                cpu_codename=CPUCodeName.SKYLAKE,
                                cpus_usage={
                                    0: 10,
                                    1: 10
                                },
                                total_memory_used=10,
                                timestamp=time.time(),
                                rdt_information=RDTInformation(
                                    True, True, True, True, '0', '0', 0, 0, 0))
            return Container(
                cgroup_path=cgroup_path,
                platform=platform,
                allocation_configuration=AllocationConfiguration()
                if with_config else None,
                resgroup=ResGroup(name=resgroup_name) if rdt_enabled else None,
                event_names=DEFAULT_EVENTS)
コード例 #12
0
def test_prepare_tasks_data(*mocks):
    t = task('/t1', labels={'label_key': 'label_value'}, resources={'cpu': 3})
    containers = {t: Container('/t1', platform_mock)}

    tasks_data = _prepare_tasks_data(containers)

    assert tasks_data == {
        't1_task_id':
        TaskData(t.name, t.task_id, t.cgroup_path, t.subcgroups_paths,
                 t.labels, t.resources, {
                     'task_up': 1,
                     'task_last_seen': 12345.6,
                     'task_cpu_usage_seconds': 13
                 })
    }
コード例 #13
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,
                         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)
コード例 #14
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)