def validate_nodes()

in gridengine/src/gridengine/validate.py [0:0]


def validate_nodes(config: Dict, dcalc: DemandCalculator, warn: WarnFunction) -> bool:
    failure = False

    pg_to_hg: Dict[str, Dict[str, List[Node]]] = {}

    for node in dcalc.node_mgr.get_nodes():
        hostgroups = get_node_hostgroups(config, node)
        if not hostgroups:
            failure = True
            warn(
                "%s does not define gridengine_hostgroups and will not be able to join the cluster.",
                node,
            )

        if not node.placement_group:
            continue

        if node.placement_group not in pg_to_hg:
            pg_to_hg[node.placement_group] = {}

        for hg in hostgroups:

            if hg not in pg_to_hg[node.placement_group]:
                pg_to_hg[node.placement_group][hg] = []

            pg_to_hg[node.placement_group][hg].append(node)

    duplicates: Dict[str, List[str]] = {}
    processed: Set[str] = set()
    for pg_name, hg_dict in pg_to_hg.items():
        for hg, node_list in hg_dict.items():
            if hg in processed:
                failure = True
                duplicates[hg].append(pg_name)
            processed.add(hg)
            if hg not in duplicates:
                # ideal case is they are all size 1 lists
                duplicates[hg] = [pg_name]

    warned_longform = False
    for pg_name, multiple_hgs in duplicates.items():
        if len(duplicates[pg_name]) <= 1:
            continue
        warn(
            "Found nodes from multiple placement_groups that will join the same hostgroup: "
            + bold("%s=%s"),
            pg_name,
            ",".join(multiple_hgs),
        )
        if not warned_longform:
            warn(
                "    Any job that relies on colocation must either specify "
                + bold("-l placement_group-[one of the above]")
            )
            warn(
                "    or update their queue config ("
                + bold("qconf -mq")
                + ") to point the relevant parallel environments"
            )
            warn("    to a different hostgroup.")

            warned_longform = True

        warn("    Affected nodes:")
        for bad_hg in multiple_hgs:
            for bad_pg in pg_to_hg[bad_hg]:
                names = ",".join(
                    ["%s(%s)" % (x.name, x.hostname) for x in pg_to_hg[bad_hg][bad_pg]]
                )
                warn("        %s = %s", bad_pg, names)

    return not failure