def test_get_tasks(get_mock):

    expected_tasks = [
        KubernetesTask(name='default/test',
                       task_id='4d6a81df-3448-11e9-8e1d-246e96663c22',
                       qos='burstable',
                       labels={
                           'exampleKey': 'value',
                           QOS_LABELNAME: 'burstable'
                       },
                       resources={
                           'requests_cpu': 0.25,
                           'requests_memory': float(64 * 1024**2),
                           'cpus': 0.25,
                           'mem': float(64 * 1024**2)
                       },
                       cgroup_path='/kubepods/burstable/pod4d6a81df'
                       '-3448-11e9-8e1d-246e96663c22',
                       subcgroups_paths=[
                           '/kubepods/burstable/pod4d'
                           '6a81df-3448-11e9-8e1d-246'
                           'e96663c22/eb9c378219b6a4e'
                           'fc034ea8898b19faa0e27c7b2'
                           '0b8eb254fda361cceacf8e90'
                       ]),
        KubernetesTask(name='default/test2',
                       task_id='567975a0-3448-11e9-8e1d-246e96663c22',
                       qos='besteffort',
                       labels={QOS_LABELNAME: 'besteffort'},
                       resources={},
                       cgroup_path='/kubepods/besteffort/pod567975a0-3448-'
                       '11e9-8e1d-246e96663c22',
                       subcgroups_paths=[
                           '/kubepods/besteffort/pod5'
                           '67975a0-3448-11e9-8e1d-24'
                           '6e96663c22/e90bbbb3b060ba'
                           'a1d354cd9b26f353d66fbb08d'
                           '785abd32f4f6ec52ac843a2e7'
                       ])
    ]

    node = KubernetesNode()
    tasks = node.get_tasks()

    assert len(tasks) == 2
    for i, task in enumerate(tasks):
        assert task == expected_tasks[i]
def test_invalid_kubelet_response(get_mock):
    node = KubernetesNode()
    with pytest.raises(ValidationError):
        node.get_tasks()
def test_get_tasks_not_all_ready(get_mock):
    node = KubernetesNode()
    tasks = node.get_tasks()
    assert len(tasks) == 0
def test_get_tasks_synchronization_error(request):
    node = KubernetesNode(kubelet_enabled=True)
    with pytest.raises(TaskSynchronizationException):
        node.get_tasks()
def test_invalid_kubelet_response(mock_path_exists, get_mock):
    node = KubernetesNode(kubelet_enabled=True)
    with pytest.raises(ValidationError):
        node.get_tasks()
def test_get_tasks_not_all_ready(get_mock):
    node = KubernetesNode(kubelet_enabled=True)
    tasks = node.get_tasks()
    assert len(tasks) == 0
def test_get_tasks_kubeapi(mock_path_exists, get_mock, pathlib_open_mock):
    node = KubernetesNode(node_ip="100.64.176.37")
    tasks = node.get_tasks()
    assert len(tasks) == 11
Esempio n. 8
0
def test_get_tasks_kubeapi_invalid_res_missing_host_ip(mock_path_exists,
                                                       get_mock,
                                                       pathlib_open_mock):
    node = KubernetesNode(node_ip="100.64.176.37")
    tasks = node.get_tasks()
    assert len(tasks) == 0