예제 #1
0
 def test_some_not_ok(self):
     too_many_devices = [
         "/dev" + str(i) for i in range(settings.sbd_max_device_num)
     ] + ["dev/sda2"]
     device_dict = {
         "node1": [],
         "node2": too_many_devices,
         "node3": ["/dev/vda"],
         "node4": ["/dev/vda1", "../dev/sda2"],
     }
     assert_report_item_list_equal(
         lib_sbd.validate_nodes_devices(device_dict), [
             (Severities.ERROR, report_codes.SBD_NO_DEVICE_FOR_NODE, {
                 "node": "node1",
             }),
             (Severities.ERROR, report_codes.SBD_TOO_MANY_DEVICES_FOR_NODE,
              {
                  "node": "node2",
                  "device_list": too_many_devices,
                  "max_devices": settings.sbd_max_device_num,
              }),
             (Severities.ERROR, report_codes.SBD_DEVICE_PATH_NOT_ABSOLUTE, {
                 "node": "node2",
                 "device": "dev/sda2",
             }),
             (Severities.ERROR, report_codes.SBD_DEVICE_PATH_NOT_ABSOLUTE, {
                 "node": "node4",
                 "device": "../dev/sda2",
             }),
         ])
예제 #2
0
파일: test_sbd.py 프로젝트: tomjelinek/pcs
 def test_some_not_ok(self):
     # pylint: disable=no-self-use
     too_many_devices = [
         "/dev" + str(i) for i in range(settings.sbd_max_device_num)
     ] + ["dev/sda2"]
     device_dict = {
         "node1": [],
         "node2": too_many_devices,
         "node3": ["/dev/vda"],
         "node4": ["/dev/vda1", "../dev/sda2"],
     }
     assert_report_item_list_equal(
         lib_sbd.validate_nodes_devices(device_dict),
         [
             (
                 Severities.ERROR,
                 report_codes.SBD_NO_DEVICE_FOR_NODE,
                 {
                     "node": "node1",
                 }
             ),
             (
                 Severities.ERROR,
                 report_codes.SBD_TOO_MANY_DEVICES_FOR_NODE,
                 {
                     "node": "node2",
                     "device_list": too_many_devices,
                     "max_devices": settings.sbd_max_device_num,
                 }
             ),
             (
                 Severities.ERROR,
                 report_codes.SBD_DEVICE_PATH_NOT_ABSOLUTE,
                 {
                     "node": "node2",
                     "device": "dev/sda2",
                 }
             ),
             (
                 Severities.ERROR,
                 report_codes.SBD_DEVICE_PATH_NOT_ABSOLUTE,
                 {
                     "node": "node4",
                     "device": "../dev/sda2",
                 }
             ),
         ]
     )
예제 #3
0
파일: sbd.py 프로젝트: miladalipour99/pcs
def enable_sbd(
    lib_env,
    default_watchdog,
    watchdog_dict,
    sbd_options,
    default_device_list=None,
    node_device_dict=None,
    allow_unknown_opts=False,
    ignore_offline_nodes=False,
    no_watchdog_validation=False,
    allow_invalid_option_values=False,
):
    # pylint: disable=too-many-arguments, too-many-locals
    """
    Enable SBD on all nodes in cluster.

    lib_env -- LibraryEnvironment
    default_watchdog -- watchdog for nodes which are not specified in
        watchdog_dict. Uses default value from settings if None.
    watchdog_dict -- dictionary with node names as keys and watchdog path
        as value
    sbd_options -- dictionary in format: <SBD config option>: <value>
    default_device_list -- list of devices for all nodes
    node_device_dict -- dictionary with node names as keys and list of devices
        as value
    allow_unknown_opts -- if True, accept also unknown options.
    ignore_offline_nodes -- if True, omit offline nodes
    no_watchdog_validation -- it True, do not validate existance of a watchdog
        on the nodes
    allow_invalid_option_values -- if True, invalid values of some options will
        be treated as warning instead of errors
    """
    using_devices = not (default_device_list is None
                         and node_device_dict is None)
    if default_device_list is None:
        default_device_list = []
    if node_device_dict is None:
        node_device_dict = {}
    if not default_watchdog:
        default_watchdog = settings.sbd_watchdog_default
    sbd_options = {opt.upper(): val for opt, val in sbd_options.items()}

    corosync_conf = lib_env.get_corosync_conf()

    node_list, get_nodes_report_list = get_existing_nodes_names(corosync_conf)
    if not node_list:
        get_nodes_report_list.append(
            reports.corosync_config_no_nodes_defined())
    target_list = lib_env.get_node_target_factory().get_target_list(
        node_list,
        skip_non_existing=ignore_offline_nodes,
    )

    full_watchdog_dict = _get_full_target_dict(target_list, watchdog_dict,
                                               default_watchdog)
    full_device_dict = _get_full_target_dict(target_list, node_device_dict,
                                             default_device_list)

    if lib_env.report_processor.report_list(
            get_nodes_report_list +
        [
            reports.node_not_found(node) for node in
            (set(list(watchdog_dict.keys()) + list(node_device_dict.keys())) -
             set(node_list))
        ] + _validate_watchdog_dict(full_watchdog_dict) +
        (sbd.validate_nodes_devices(full_device_dict) if using_devices else []
         ) + _validate_sbd_options(sbd_options, allow_unknown_opts,
                                   allow_invalid_option_values)).has_errors:
        raise LibraryError()

    com_cmd = GetOnlineTargets(
        lib_env.report_processor,
        ignore_offline_targets=ignore_offline_nodes,
    )
    com_cmd.set_targets(target_list)
    online_targets = run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # check if SBD can be enabled
    if no_watchdog_validation:
        lib_env.report_processor.report(
            reports.sbd_watchdog_validation_inactive())
    com_cmd = CheckSbd(lib_env.report_processor)
    for target in online_targets:
        com_cmd.add_request(
            target,
            (
                # Do not send watchdog if validation is turned off. Listing of
                # available watchdogs in pcsd may restart the machine in some
                # corner cases.
                "" if no_watchdog_validation else
                full_watchdog_dict[target.label]),
            full_device_dict[target.label] if using_devices else [],
        )
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # enable ATB if needed
    if not using_devices:
        if sbd.atb_has_to_be_enabled_pre_enable_check(corosync_conf):
            lib_env.report_processor.report(
                reports.corosync_quorum_atb_will_be_enabled_due_to_sbd())
            corosync_conf.set_quorum_options({"auto_tie_breaker": "1"})
            lib_env.push_corosync_conf(corosync_conf, ignore_offline_nodes)

    # distribute SBD configuration
    config = sbd.get_default_sbd_config()
    config.update(sbd_options)
    com_cmd = SetSbdConfig(lib_env.report_processor)
    for target in online_targets:
        com_cmd.add_request(
            target,
            sbd.create_sbd_config(config, target.label,
                                  full_watchdog_dict[target.label],
                                  full_device_dict[target.label]))
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # remove cluster prop 'stonith_watchdog_timeout'
    com_cmd = RemoveStonithWatchdogTimeout(lib_env.report_processor)
    com_cmd.set_targets(online_targets)
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # enable SBD service an all nodes
    com_cmd = EnableSbdService(lib_env.report_processor)
    com_cmd.set_targets(online_targets)
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    lib_env.report_processor.report(
        reports.cluster_restart_required_to_apply_changes())
예제 #4
0
파일: sbd.py 프로젝트: tomjelinek/pcs
def enable_sbd(
    lib_env, default_watchdog, watchdog_dict, sbd_options,
    default_device_list=None, node_device_dict=None, allow_unknown_opts=False,
    ignore_offline_nodes=False, no_watchdog_validation=False,
    allow_invalid_option_values=False,
):
    # pylint: disable=too-many-arguments, too-many-locals
    """
    Enable SBD on all nodes in cluster.

    lib_env -- LibraryEnvironment
    default_watchdog -- watchdog for nodes which are not specified in
        watchdog_dict. Uses default value from settings if None.
    watchdog_dict -- dictionary with node names as keys and watchdog path
        as value
    sbd_options -- dictionary in format: <SBD config option>: <value>
    default_device_list -- list of devices for all nodes
    node_device_dict -- dictionary with node names as keys and list of devices
        as value
    allow_unknown_opts -- if True, accept also unknown options.
    ignore_offline_nodes -- if True, omit offline nodes
    no_watchdog_validation -- it True, do not validate existance of a watchdog
        on the nodes
    allow_invalid_option_values -- if True, invalid values of some options will
        be treated as warning instead of errors
    """
    using_devices = not (
        default_device_list is None and node_device_dict is None
    )
    if default_device_list is None:
        default_device_list = []
    if node_device_dict is None:
        node_device_dict = {}
    if not default_watchdog:
        default_watchdog = settings.sbd_watchdog_default
    sbd_options = {opt.upper(): val for opt, val in sbd_options.items()}

    corosync_conf = lib_env.get_corosync_conf()

    node_list, get_nodes_report_list = get_existing_nodes_names(corosync_conf)
    if not node_list:
        get_nodes_report_list.append(reports.corosync_config_no_nodes_defined())
    target_list = lib_env.get_node_target_factory().get_target_list(
        node_list, skip_non_existing=ignore_offline_nodes,
    )

    full_watchdog_dict = _get_full_target_dict(
        target_list, watchdog_dict, default_watchdog
    )
    full_device_dict = _get_full_target_dict(
        target_list, node_device_dict, default_device_list
    )

    lib_env.report_processor.process_list(
        get_nodes_report_list
        +
        [
            reports.node_not_found(node)
            for node in (
                set(list(watchdog_dict.keys()) + list(node_device_dict.keys()))
                -
                set(node_list)
            )
        ]
        +
        _validate_watchdog_dict(full_watchdog_dict)
        +
        (sbd.validate_nodes_devices(full_device_dict) if using_devices else [])
        +
        _validate_sbd_options(
            sbd_options, allow_unknown_opts, allow_invalid_option_values
        )
    )

    com_cmd = GetOnlineTargets(
        lib_env.report_processor, ignore_offline_targets=ignore_offline_nodes,
    )
    com_cmd.set_targets(target_list)
    online_targets = run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # check if SBD can be enabled
    if no_watchdog_validation:
        lib_env.report_processor.report(
            reports.sbd_watchdog_validation_inactive()
        )
    com_cmd = CheckSbd(lib_env.report_processor)
    for target in online_targets:
        com_cmd.add_request(
            target,
            (
                # Do not send watchdog if validation is turned off. Listing of
                # available watchdogs in pcsd may restart the machine in some
                # corner cases.
                "" if no_watchdog_validation
                else full_watchdog_dict[target.label]
            ),
            full_device_dict[target.label] if using_devices else [],
        )
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # enable ATB if needed
    if not using_devices:
        if sbd.atb_has_to_be_enabled_pre_enable_check(corosync_conf):
            lib_env.report_processor.process(
                reports.corosync_quorum_atb_will_be_enabled_due_to_sbd()
            )
            corosync_conf.set_quorum_options({"auto_tie_breaker": "1"})
            lib_env.push_corosync_conf(corosync_conf, ignore_offline_nodes)

    # distribute SBD configuration
    config = sbd.get_default_sbd_config()
    config.update(sbd_options)
    com_cmd = SetSbdConfig(lib_env.report_processor)
    for target in online_targets:
        com_cmd.add_request(
            target,
            sbd.create_sbd_config(
                config,
                target.label,
                full_watchdog_dict[target.label],
                full_device_dict[target.label]
            )
        )
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # remove cluster prop 'stonith_watchdog_timeout'
    com_cmd = RemoveStonithWatchdogTimeout(lib_env.report_processor)
    com_cmd.set_targets(online_targets)
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # enable SBD service an all nodes
    com_cmd = EnableSbdService(lib_env.report_processor)
    com_cmd.set_targets(online_targets)
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    lib_env.report_processor.process(
        reports.cluster_restart_required_to_apply_changes()
    )
예제 #5
0
 def test_all_ok(self):
     device_dict = {
         "node1": ["/dev1", "/dev2"],
         "node2": ["/dev1"],
     }
     self.assertEqual([], lib_sbd.validate_nodes_devices(device_dict))
예제 #6
0
파일: sbd.py 프로젝트: junaruga/pcs
def enable_sbd(
    lib_env,
    default_watchdog,
    watchdog_dict,
    sbd_options,
    default_device_list=None,
    node_device_dict=None,
    allow_unknown_opts=False,
    ignore_offline_nodes=False,
):
    """
    Enable SBD on all nodes in cluster.

    lib_env -- LibraryEnvironment
    default_watchdog -- watchdog for nodes which are not specified in
        watchdog_dict. Uses default value from settings if None.
    watchdog_dict -- dictionary with node names as keys and watchdog path
        as value
    sbd_options -- dictionary in format: <SBD config option>: <value>
    default_device_list -- list of devices for all nodes
    node_device_dict -- dictionary with node names as keys and list of devices
        as value
    allow_unknown_opts -- if True, accept also unknown options.
    ignore_offline_nodes -- if True, omit offline nodes
    """
    corosync_conf = lib_env.get_corosync_conf()
    node_list = corosync_conf.get_nodes_names()
    target_list = lib_env.get_node_target_factory().get_target_list(
        node_list,
        skip_non_existing=ignore_offline_nodes,
    )
    using_devices = not (default_device_list is None
                         and node_device_dict is None)
    if default_device_list is None:
        default_device_list = []
    if node_device_dict is None:
        node_device_dict = {}
    if not default_watchdog:
        default_watchdog = settings.sbd_watchdog_default
    sbd_options = dict([(opt.upper(), val)
                        for opt, val in sbd_options.items()])

    full_watchdog_dict = _get_full_target_dict(target_list, watchdog_dict,
                                               default_watchdog)
    full_device_dict = _get_full_target_dict(target_list, node_device_dict,
                                             default_device_list)

    lib_env.report_processor.process_list([
        reports.node_not_found(node) for node in
        (set(list(watchdog_dict.keys()) + list(node_device_dict.keys())) -
         set(node_list))
    ] + _validate_watchdog_dict(full_watchdog_dict) + (
        sbd.validate_nodes_devices(full_device_dict) if using_devices else []
    ) + _validate_sbd_options(sbd_options, allow_unknown_opts))

    com_cmd = GetOnlineTargets(
        lib_env.report_processor,
        ignore_offline_targets=ignore_offline_nodes,
    )
    com_cmd.set_targets(target_list)
    online_targets = run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # check if SBD can be enabled
    com_cmd = CheckSbd(lib_env.report_processor)
    for target in online_targets:
        com_cmd.add_request(
            target,
            full_watchdog_dict[target.label],
            full_device_dict[target.label] if using_devices else [],
        )
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # enable ATB if neede
    if not using_devices:
        if sbd.atb_has_to_be_enabled_pre_enable_check(corosync_conf):
            lib_env.report_processor.process(
                reports.corosync_quorum_atb_will_be_enabled_due_to_sbd())
            corosync_conf.set_quorum_options({"auto_tie_breaker": "1"})
            lib_env.push_corosync_conf(corosync_conf, ignore_offline_nodes)

    # distribute SBD configuration
    config = sbd.get_default_sbd_config()
    config.update(sbd_options)
    com_cmd = SetSbdConfig(lib_env.report_processor)
    for target in online_targets:
        com_cmd.add_request(
            target,
            sbd.create_sbd_config(config, target.label,
                                  full_watchdog_dict[target.label],
                                  full_device_dict[target.label]))
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # remove cluster prop 'stonith_watchdog_timeout'
    com_cmd = RemoveStonithWatchdogTimeout(lib_env.report_processor)
    com_cmd.set_targets(online_targets)
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    # enable SBD service an all nodes
    com_cmd = EnableSbdService(lib_env.report_processor)
    com_cmd.set_targets(online_targets)
    run_and_raise(lib_env.get_node_communicator(), com_cmd)

    lib_env.report_processor.process(
        reports.cluster_restart_required_to_apply_changes())
예제 #7
0
파일: test_sbd.py 프로젝트: tomjelinek/pcs
 def test_all_ok(self):
     device_dict = {
         "node1": ["/dev1", "/dev2"],
         "node2": ["/dev1"],
     }
     self.assertEqual([], lib_sbd.validate_nodes_devices(device_dict))