Ejemplo n.º 1
0
def test_conditions_returns_all_native_conditions(node: agent.Node):
    conditions = node.conditions()
    assert conditions is not None
    conditions_dict = conditions.dict()
    assert len(conditions_dict) == len(agent.NATIVE_NODE_CONDITION_TYPES)
    assert all(condition_type.lower() in conditions_dict
               for condition_type in agent.NATIVE_NODE_CONDITION_TYPES)
Ejemplo n.º 2
0
def test_conditions_falsy_vs_status(node: agent.Node):
    conditions = node.conditions()
    assert conditions is not None

    falsy_conditions = [
        c for _, c in conditions if isinstance(c, section.FalsyNodeCondition)
    ]
    assert len(falsy_conditions) > 0
    assert all(c.is_ok() is (c.status == api.NodeConditionStatus.FALSE)
               for c in falsy_conditions)
Ejemplo n.º 3
0
def test_conditions_truthy_vs_status(node: agent.Node):
    conditions = node.conditions()
    assert conditions is not None

    truthy_conditions = [
        c for _, c in conditions if isinstance(c, section.TruthyNodeCondition)
    ]
    assert len(truthy_conditions) > 0
    assert all(c.is_ok() is (c.status == api.NodeConditionStatus.TRUE)
               for c in truthy_conditions)
Ejemplo n.º 4
0
def test_conditions_respects_status_conditions(node: agent.Node):
    api_conditions = node.status.conditions
    assert api_conditions is not None

    native_conditions = [
        cond for cond in api_conditions
        if cond.type_ in agent.NATIVE_NODE_CONDITION_TYPES
    ]

    conditions = node.conditions()
    assert conditions is not None
    conditions_dict = conditions.dict()
    assert len(conditions_dict) == len(native_conditions)
    assert all(
        conditions_dict[condition.type_.lower()]["status"] == condition.status
        for condition in native_conditions)
Ejemplo n.º 5
0
def test_custom_conditions_respects_status_conditions(node: agent.Node):
    status_conditions = node.status.conditions
    assert status_conditions is not None

    npd_conditions_status = [
        cond.status
        for cond in sorted(status_conditions, key=lambda cond: cond.type_)
        if cond.type_ not in agent.NATIVE_NODE_CONDITION_TYPES
    ]

    node_custom_conditions = node.custom_conditions()
    assert node_custom_conditions is not None
    custom_conditions_status = [
        cond.status
        for cond in sorted(node_custom_conditions.custom_conditions,
                           key=lambda cond: cond.type_)
    ]
    assert npd_conditions_status == custom_conditions_status
Ejemplo n.º 6
0
def test_node_alloctable_pods(node_allocatable_pods: int,
                              node_capacity_pods: int, node: agent.Node):
    expected = section.AllocatablePods(capacity=node_capacity_pods,
                                       allocatable=node_allocatable_pods)
    actual = node.allocatable_pods()
    assert actual == expected
Ejemplo n.º 7
0
def test_node_allocatable_cpu_resource(node_allocatable_cpu: float,
                                       node: agent.Node):
    expected = section.AllocatableResource(context="node",
                                           value=node_allocatable_cpu)
    actual = node.allocatable_cpu_resource()
    assert actual == expected
Ejemplo n.º 8
0
def test_node_pod_resources_pods_in_phase_no_phase_param(
        node: agent.Node, node_pods: int):
    pods = node.pods()
    assert len(pods) == node_pods
Ejemplo n.º 9
0
def test_node_pod_resources_pods_in_phase(node: agent.Node, phases,
                                          node_pods: int):
    pods = node.pods(phases[0])
    assert len(pods) == node_pods
Ejemplo n.º 10
0
def test_node_pod_resources_one_pod_per_phase(node: agent.Node):
    resources = dict(node.pod_resources())
    pod_resources = section.PodResources(**resources)
    for _phase, pods in pod_resources:
        assert len(pods) == 1
Ejemplo n.º 11
0
def test_node_info_section(node: agent.Node):
    info = node.info("cluster", agent.AnnotationNonPatternOption.ignore_all)
    assert info.name == node.metadata.name
    assert info.labels == node.metadata.labels
    assert isinstance(info.creation_timestamp, float)
Ejemplo n.º 12
0
def test_conditions_with_status_conditions_none(node: agent.Node):
    node.status.conditions = None
    conditions = node.conditions()
    assert conditions is None