Esempio n. 1
0
def _update_scsi_devices_get_element_and_devices(
    runner: CommandRunner,
    report_processor: ReportProcessor,
    cib: _Element,
    stonith_id: str,
) -> Tuple[_Element, List[str]]:
    """
    Do checks and return stonith element and list of current scsi devices.
    Raise LibraryError if checks fail.

    runner -- command runner instance
    report_processor -- tool for warning/info/error reporting
    cib -- cib element
    stonith_id -- id of stonith resource
    """
    if not is_getting_resource_digest_supported(runner):
        raise LibraryError(
            ReportItem.error(
                reports.messages.
                StonithRestartlessUpdateOfScsiDevicesNotSupported()))
    (
        stonith_el,
        report_list,
    ) = stonith.validate_stonith_restartless_update(cib, stonith_id)
    if report_processor.report_list(report_list).has_errors:
        raise LibraryError()
    # for mypy, this should not happen because exception would be raised
    if stonith_el is None:
        raise AssertionError("stonith element is None")
    current_device_list = get_value(INSTANCE_ATTRIBUTES_TAG, stonith_el,
                                    "devices")
    if current_device_list is None:
        raise AssertionError("current_device_list is None")
    return stonith_el, current_device_list.split(",")
Esempio n. 2
0
 def test_supported(self):
     stonith_el, report_list = stonith.validate_stonith_restartless_update(
         self.RESOURCES, "supported"
     )
     self.assertEqual(
         stonith_el, self.RESOURCES.find(".//primitive[@id='supported']")
     )
     assert_report_item_list_equal(report_list, [])
Esempio n. 3
0
 def test_not_a_resource_id(self):
     stonith_el, report_list = stonith.validate_stonith_restartless_update(
         self.RESOURCES, "empty-instance_attributes-devices"
     )
     self.assertEqual(stonith_el, None)
     assert_report_item_list_equal(
         report_list,
         [
             fixture.error(
                 reports.codes.ID_BELONGS_TO_UNEXPECTED_TYPE,
                 id="empty-instance_attributes-devices",
                 expected_types=["primitive"],
                 current_type="nvpair",
             )
         ],
     )
Esempio n. 4
0
 def test_nonexistent_id(self):
     stonith_el, report_list = stonith.validate_stonith_restartless_update(
         self.RESOURCES, "non-existent"
     )
     self.assertEqual(stonith_el, None)
     assert_report_item_list_equal(
         report_list,
         [
             fixture.error(
                 reports.codes.ID_NOT_FOUND,
                 id="non-existent",
                 expected_types=["primitive"],
                 context_type="resources",
                 context_id="",
             )
         ],
     )
Esempio n. 5
0
 def assert_unsupported_stonith_agent(self, resource_id, resource_type):
     stonith_el, report_list = stonith.validate_stonith_restartless_update(
         self.RESOURCES, resource_id
     )
     self.assertEqual(
         stonith_el,
         self.RESOURCES.find(f".//primitive[@id='{resource_id}']"),
     )
     assert_report_item_list_equal(
         report_list,
         [
             fixture.error(
                 reports.codes.STONITH_RESTARTLESS_UPDATE_UNSUPPORTED_AGENT,
                 resource_id=resource_id,
                 resource_type=resource_type,
                 supported_stonith_types=["fence_scsi"],
             )
         ],
     )
Esempio n. 6
0
 def assert_no_devices(self, resource_id):
     stonith_el, report_list = stonith.validate_stonith_restartless_update(
         self.RESOURCES, resource_id
     )
     self.assertEqual(
         stonith_el,
         self.RESOURCES.find(f".//primitive[@id='{resource_id}']"),
     )
     assert_report_item_list_equal(
         report_list,
         [
             fixture.error(
                 reports.codes.STONITH_RESTARTLESS_UPDATE_UNABLE_TO_PERFORM,
                 reason=(
                     "no devices option configured for stonith device "
                     f"'{resource_id}'"
                 ),
                 reason_type="other",
             )
         ],
     )
Esempio n. 7
0
def update_scsi_devices(
    env: LibraryEnvironment,
    stonith_id: str,
    set_device_list: Iterable[str],
    force_flags: Container[reports.types.ForceCode] = (),
) -> None:
    """
    Update scsi fencing devices without restart and affecting other resources.

    env -- provides all for communication with externals
    stonith_id -- id of stonith resource
    set_device_list -- paths to the scsi devices that would be set for stonith
        resource
    force_flags -- list of flags codes
    """
    if not is_getting_resource_digest_supported(env.cmd_runner()):
        raise LibraryError(
            ReportItem.error(
                reports.messages.StonithRestartlessUpdateOfScsiDevicesNotSupported()
            )
        )
    cib = env.get_cib()
    if not set_device_list:
        env.report_processor.report(
            ReportItem.error(
                reports.messages.InvalidOptionValue(
                    "devices", "", None, cannot_be_empty=True
                )
            )
        )
    (
        stonith_el,
        report_list,
    ) = stonith.validate_stonith_restartless_update(cib, stonith_id)
    if env.report_processor.report_list(report_list).has_errors:
        raise LibraryError()
    # for mypy, this should not happen because exeption would be raised
    if stonith_el is None:
        raise AssertionError("stonith element is None")

    stonith.update_scsi_devices_without_restart(
        env.cmd_runner(),
        env.get_cluster_state(),
        stonith_el,
        IdProvider(cib),
        set_device_list,
    )

    # Unfencing
    cluster_nodes_names, nodes_report_list = get_existing_nodes_names(
        env.get_corosync_conf(),
        error_on_missing_name=True,
    )
    env.report_processor.report_list(nodes_report_list)
    (
        target_report_list,
        cluster_nodes_target_list,
    ) = env.get_node_target_factory().get_target_list_with_reports(
        cluster_nodes_names,
        allow_skip=False,
    )
    env.report_processor.report_list(target_report_list)
    if env.report_processor.has_errors:
        raise LibraryError()
    com_cmd: AllSameDataMixin = GetCorosyncOnlineTargets(
        env.report_processor,
        skip_offline_targets=reports.codes.SKIP_OFFLINE_NODES in force_flags,
    )
    com_cmd.set_targets(cluster_nodes_target_list)
    online_corosync_target_list = run_and_raise(
        env.get_node_communicator(), com_cmd
    )
    com_cmd = Unfence(env.report_processor, sorted(set_device_list))
    com_cmd.set_targets(online_corosync_target_list)
    run_and_raise(env.get_node_communicator(), com_cmd)

    env.push_cib()