Exemple #1
0
def test_process_numeric_quotas() -> None:
    # test a node that is part of multiple hostgroups
    # what about default values in complexes file?
    N = Union[int, float]

    def run_test(
        ctype: str,
        node_pcpu: Optional[N],
        hg_pcpu: N,
        q_default_pcpu: N,
        complex_default: Optional[N],
    ) -> SchedulerNode:
        cast = float if ctype == "DOUBLE" else int
        node_res = {}
        if node_pcpu is not None:
            node_res["pcpu"] = cast(node_pcpu)
            node_res["p"] = cast(node_pcpu)

        node = SchedulerNode("tux", node_res)
        ge_env = common_ge_env()

        q = ge_env.queues["hpc.q"]
        complex_default_str = (
            "NONE" if complex_default is None else str(complex_default)
        )
        ge_env.complexes["pcpu"] = Complex(
            "pcpu", "p", ctype, "<=", True, True, complex_default_str, 0
        )

        q.complex_values[None] = {"pcpu": cast(q_default_pcpu)}
        q.complex_values["@hpc.q"] = {"pcpu": cast(hg_pcpu)}

        assert node.available.get("pcpu") == node_pcpu
        process_quotas(node, ge_env.complexes, ["@hpc.q"], [q])
        return node

    for ctype in ["INT", "RSMAP", "DOUBLE", "MEMORY"]:
        node = run_test(ctype, 12, 8, 10, 0)
        assert node.available["pcpu"] == 12
        assert node.available["p"] == 12
        json_dump(node.available)
        assert node.available["hpc.q@pcpu"] == 8
        assert node.available["hpc.q@p"] == 8
        assert node.metadata["quotas"]["hpc.q"]["@hpc.q"]["pcpu"] == 8
        assert node.metadata["quotas"]["hpc.q"]["@hpc.q"]["p"] == 8

        node = run_test(ctype, 12, 10, 8, 0)
        # assert node.available["pcpu"] == 12
        assert node.available["hpc.q@pcpu"] == 10
        assert node.metadata["quotas"]["hpc.q"]["@hpc.q"]["pcpu"] == 10

        node = run_test(ctype, 6, 8, 10, 0)
        # assert node.available["pcpu"] == 6
        assert node.available["hpc.q@pcpu"] == 6
        assert node.metadata["quotas"]["hpc.q"]["@hpc.q"]["pcpu"] == 6

        node = run_test(ctype, None, 8, 10, 0)
        # assert node.available["pcpu"] == 8
        assert node.available["hpc.q@pcpu"] == 8
        assert node.metadata["quotas"]["hpc.q"]["@hpc.q"]["pcpu"] == 8
    def parse_jobs(self) -> List[Job]:
        ret = _parse_jobs(self.doc, self.ge_env)

        from gridengine import util

        util.json_dump(ret)
        return ret
Exemple #3
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)
def jobs_and_nodes(config: Dict) -> None:
    """Writes out SchedulerNode and Job objects as json - simultaneously to avoid race"""
    ge_env = environment.from_qconf(config)
    to_dump = {"jobs": ge_env.jobs, "nodes": ge_env.nodes}
    util.json_dump(to_dump)
def scheduler_nodes(config: Dict) -> None:
    """Writes out SchedulerNode objects as json"""
    ge_env = environment.from_qconf(config)
    util.json_dump(ge_env.nodes)
def jobs(config: Dict) -> None:
    """Writes out Job objects as json"""
    ge_env = environment.from_qconf(config)
    util.json_dump(ge_env.jobs)