Esempio n. 1
0
def process_library_reports(report_item_list: ReportItemList) -> None:
    if not report_item_list:
        raise error(
            "Errors have occurred, therefore pcs is unable to continue")

    critical_error = False
    for report_item in report_item_list:
        report_dto = report_item.to_dto()
        msg = report_item_msg_from_dto(report_dto.message).message
        severity = report_dto.severity.level

        if severity == ReportItemSeverity.WARNING:
            warn(msg)
            continue

        if severity == ReportItemSeverity.DEPRECATION:
            deprecation_warning(msg)
            continue

        if severity != ReportItemSeverity.ERROR:
            print_to_stderr(msg)
            continue

        error("{msg}{force}".format(
            msg=msg,
            force=prepare_force_text(report_item),
        ))
        critical_error = True

    if critical_error:
        sys.exit(1)
Esempio n. 2
0
def quorum_unblock_cmd(lib, argv, modifiers):
    """
    Options:
      * --force - no error when removing non existing property and no warning
        about this action
    """
    modifiers.ensure_only_supported("--force")
    if argv:
        raise CmdLineInputError()

    output, retval = utils.run(
        ["corosync-cmapctl", "-g", "runtime.votequorum.wait_for_all_status"])
    if (retval == 1 and "Error CS_ERR_NOT_EXIST" in output) or (
            retval == 0 and output.rsplit("=", maxsplit=1)[-1].strip() != "1"):
        utils.err("cluster is not waiting for nodes to establish quorum")
    if retval != 0:
        utils.err("unable to check quorum status")

    all_nodes, report_list = get_existing_nodes_names(
        utils.get_corosync_conf_facade())
    if report_list:
        process_library_reports(report_list)

    unjoined_nodes = set(all_nodes) - set(utils.getCorosyncActiveNodes())
    if not unjoined_nodes:
        utils.err("no unjoined nodes found")
    if not utils.get_continue_confirmation_or_force(
            f"If node(s) {format_list(unjoined_nodes)} are not powered off or they "
            "do have access to shared resources, data corruption and/or cluster "
            "failure may occur",
            modifiers.get("--force"),
    ):
        return
    for node in unjoined_nodes:
        # pass --force so no warning will be displayed
        stonith.stonith_confirm(lib, [node],
                                parse_args.InputModifiers({"--force": ""}))

    output, retval = utils.run(
        ["corosync-cmapctl", "-s", "quorum.cancel_wait_for_all", "u8", "1"])
    if retval != 0:
        utils.err("unable to cancel waiting for nodes")
    print_to_stderr("Quorum unblocked")

    startup_fencing = utils.get_set_properties().get("startup-fencing", "")
    utils.set_cib_property(
        "startup-fencing",
        "false" if startup_fencing.lower() != "false" else "true",
    )
    utils.set_cib_property("startup-fencing", startup_fencing)
    print_to_stderr("Waiting for nodes canceled")
Esempio n. 3
0
def find_single_agent(agent_names: List[ResourceAgentNameDto],
                      to_find: str) -> ResourceAgentNameDto:
    to_find_normalized = to_find.lower()
    matches = [
        agent_name for agent_name in agent_names
        if agent_name.type.lower() == to_find_normalized
    ]
    if len(matches) == 1:
        print_to_stderr(
            reports.messages.AgentNameGuessed(
                to_find, get_resource_agent_full_name(matches[0])).message)
        return matches[0]

    report_msg: reports.item.ReportItemMessage
    if matches:
        report_msg = reports.messages.AgentNameGuessFoundMoreThanOne(
            to_find, sorted(map(get_resource_agent_full_name, matches)))
    else:
        report_msg = reports.messages.AgentNameGuessFoundNone(to_find)
    raise CmdLineInputError(report_msg.message)
Esempio n. 4
0
    def _do_report(self, report_item: ReportItem) -> None:
        report_dto = report_item.to_dto()
        msg = report_item_msg_from_dto(report_dto.message).message
        if report_dto.context:
            msg = f"{report_dto.context.node}: {msg}"
        severity = report_dto.severity.level

        if severity in self._ignore_severities:
            # DEBUG overrides ignoring severities for debug reports
            if msg and self.debug and severity == ReportItemSeverity.DEBUG:
                print_to_stderr(msg)
            return

        if severity == ReportItemSeverity.ERROR:
            error("{msg}{force}".format(
                msg=msg,
                force=prepare_force_text(report_item),
            ))
        elif severity == ReportItemSeverity.WARNING:
            warn(msg)
        elif msg and (self.debug or severity != ReportItemSeverity.DEBUG):
            print_to_stderr(msg)
Esempio n. 5
0
def error(message: str) -> SystemExit:
    print_to_stderr(f"Error: {message}")
    return SystemExit(1)
Esempio n. 6
0
def warn(message: str) -> None:
    print_to_stderr(f"Warning: {message}")
Esempio n. 7
0
def deprecation_warning(message: str) -> None:
    print_to_stderr(f"Deprecation Warning: {message}")