コード例 #1
0
def test_get_resource_utilization_by_grouping(
    mock_get_all_tasks_from_state,
    mock_calculate_resource_utilization_for_slaves,
    mock_group_slaves_by_key_func,
):
    mock_group_slaves_by_key_func.return_value = {
        'somenametest-habitat': [{
            'id': 'abcd',
            'hostname': 'test.somewhere.www'
        }],
        'somenametest-habitat-2': [{
            'id': 'abcd',
            'hostname': 'test2.somewhere.www'
        }]
    }
    mock_calculate_resource_utilization_for_slaves.return_value = {
        'free': paasta_metastatus.ResourceInfo(cpus=10, mem=10, disk=10),
        'total': paasta_metastatus.ResourceInfo(cpus=20, mem=20, disk=20)
    }
    mock_get_all_tasks_from_state([Mock(), Mock()])
    state = {'frameworks': Mock(), 'slaves': [{}]}
    actual = paasta_metastatus.get_resource_utilization_by_grouping(
        grouping_func=lambda slave: slave['attributes']['habitat'],
        mesos_state=state,
    )
    assert sorted(actual.keys()) == sorted(
        ['somenametest-habitat', 'somenametest-habitat-2'])
    for k, v in actual.items():
        print v
        assert v['total'] == paasta_metastatus.ResourceInfo(cpus=20,
                                                            disk=20,
                                                            mem=20)
        assert v['free'] == paasta_metastatus.ResourceInfo(cpus=10,
                                                           disk=10,
                                                           mem=10)
コード例 #2
0
def test_get_resource_utilization_per_slave():
    tasks = [{
        'resources': {
            'cpus': 10,
            'mem': 10,
            'disk': 10
        }
    }, {
        'resources': {
            'cpus': 10,
            'mem': 10,
            'disk': 10
        }
    }]
    slaves = [
        {
            'id': 'somenametest-slave',
            'hostname': 'test.somewhere.www',
            'resources': {
                'cpus': 75,
                'disk': 250,
                'mem': 100,
            },
            'reserved_resources': {},
            'attributes': {
                'habitat': 'somenametest-habitat',
            },
        },
        {
            'id': 'somenametest-slave2',
            'hostname': 'test2.somewhere.www',
            'resources': {
                'cpus': 500,
                'disk': 200,
                'mem': 750,
            },
            'reserved_resources': {
                'some-role': {
                    'cpus': 10,
                    'disk': 0,
                    'mem': 150,
                },
            },
            'attributes': {
                'habitat': 'somenametest-habitat-2',
            },
        },
    ]
    actual = paasta_metastatus.calculate_resource_utilization_for_slaves(
        slaves=slaves, tasks=tasks)
    assert sorted(actual.keys()) == sorted(['total', 'free'])
    assert actual['total'] == paasta_metastatus.ResourceInfo(cpus=575,
                                                             disk=450,
                                                             mem=850)
    assert actual['free'] == paasta_metastatus.ResourceInfo(cpus=545,
                                                            disk=430,
                                                            mem=680)