Esempio n. 1
0
def test_placement_group() -> None:
    node = SchedulerNode("", {})
    node.exists = False

    node.placement_group = ""
    assert node.placement_group is None

    node.placement_group = "a"
    assert node.placement_group == "a"

    node.placement_group = "0"
    assert node.placement_group == "0"
    try:
        node.placement_group = "."
    except Exception:
        pass

    assert node.placement_group == "0"
    node.set_placement_group_escaped(".")
    assert node.placement_group == "_"

    node.exists = True
    try:
        node.placement_group = "123"
    except Exception:
        assert node.placement_group == "_"
Esempio n. 2
0
def test_custom_parser() -> None:
    ge_env = common_ge_env()
    qc = driver.HostgroupConstraint
    hg = Hostgroup("@htc_q_mpipg0", {"node.nodearray": "htc"})
    bhg = BoundHostgroup(ge_env.queues["htc.q"], hg, 0)
    q = qc(bhg, bhg.name.replace("@", "pg0"))
    json_dump(q.to_dict())
    expected_dict: Dict[str, Optional[Any]] = {
        "hostgroup-and-pg": {
            "hostgroup": "@htc_q_mpipg0",
            "user": None,
            "project": None,
            "placement-group": "pg0htc_q_mpipg0",
            "seq-no": 0,
            "constraints": [{
                "nodearray": ["htc"]
            }],
        }
    }
    assert q.to_dict() == expected_dict
    parsed = constraints.get_constraint(q.to_dict())
    assert parsed.hostgroups_set == q.hostgroups_set
    assert parsed.hostgroups_sorted == q.hostgroups_sorted
    assert parsed.placement_group == q.placement_group

    q = qc("htc.q", ["@htc.q", "@another"], None)
    expected_dict = {
        "hostgroups-and-pg": {
            "hostgroups": ["@another",
                           "@htc.q"],  # sort the hostgroups for consistency
            "placement-group": None,
        }
    }
    assert q.to_dict() == expected_dict
    parsed = constraints.get_constraint(q.to_dict())
    assert parsed.hostgroups_set == q.hostgroups_set
    assert parsed.hostgroups_sorted == q.hostgroups_sorted
    assert parsed.placement_group == q.placement_group

    node = SchedulerNode(
        "tux",
        {"_gridengine_hostgroups": q.hostgroups_sorted},
    )
    assert q.satisfied_by_node(node)
    assert q.do_decrement(node)

    node = SchedulerNode(
        "tux",
        {"_gridengine_hostgroups": q.hostgroups_sorted},
    )
    node.placement_group = "pg0"
    assert not q.satisfied_by_node(node)

    node = SchedulerNode("tux", {})
    node.exists = True
    assert not q.satisfied_by_node(node)

    node.exists = False
    assert q.satisfied_by_node(node)
    assert q.do_decrement(node)
    assert node.available["_gridengine_hostgroups"] == q.hostgroups_sorted
    assert node.software_configuration["gridengine_hostgroups"] == " ".join(
        q.hostgroups_sorted)