Exemple #1
0
def is_resource_managed(cluster_state, resource_id):
    """
    Check if the resource is managed

    etree cluster_state -- status of the cluster
    string resource_id -- id of the resource
    """
    primitive_list = cluster_state.xpath("""
        .//resource[{predicate_id}]
        |
        .//group[{predicate_id}]/resource
        """.format(predicate_id=_id_xpath_predicate(resource_id)))
    if primitive_list:
        for primitive in primitive_list:
            if is_false(primitive.attrib.get("managed", "")):
                return False
            clone = find_parent(primitive, ["clone"])
            if clone is not None and is_false(clone.attrib.get("managed", "")):
                return False
        return True

    clone_list = cluster_state.xpath(
        """.//clone[@id="{0}"]""".format(resource_id))
    for clone in clone_list:
        if is_false(clone.attrib.get("managed", "")):
            return False
        for primitive in clone.xpath(".//resource"):
            if is_false(primitive.attrib.get("managed", "")):
                return False
        return True

    raise ResourceNotFound(resource_id)
Exemple #2
0
 def test_false_is_false(self):
     self.assertTrue(lib.is_false("false"))
     self.assertTrue(lib.is_false("faLse"))
     self.assertTrue(lib.is_false("off"))
     self.assertTrue(lib.is_false("OFF"))
     self.assertTrue(lib.is_false("no"))
     self.assertTrue(lib.is_false("nO"))
     self.assertTrue(lib.is_false("n"))
     self.assertTrue(lib.is_false("N"))
     self.assertTrue(lib.is_false("0"))
Exemple #3
0
 def test_false_is_false(self):
     self.assertTrue(lib.is_false("false"))
     self.assertTrue(lib.is_false("faLse"))
     self.assertTrue(lib.is_false("off"))
     self.assertTrue(lib.is_false("OFF"))
     self.assertTrue(lib.is_false("no"))
     self.assertTrue(lib.is_false("nO"))
     self.assertTrue(lib.is_false("n"))
     self.assertTrue(lib.is_false("N"))
     self.assertTrue(lib.is_false("0"))
Exemple #4
0
def status_stonith_check():
    # We should read the default value from pacemaker. However that may slow
    # pcs down as we need to run 'pengine metadata' to get it.
    stonith_enabled = True
    stonith_devices = []
    stonith_devices_id_action = []
    stonith_devices_id_method_cycle = []
    sbd_running = False

    cib = utils.get_cib_dom()
    for conf in cib.getElementsByTagName("configuration"):
        for crm_config in conf.getElementsByTagName("crm_config"):
            for nvpair in crm_config.getElementsByTagName("nvpair"):
                if (nvpair.getAttribute("name") == "stonith-enabled"
                        and is_false(nvpair.getAttribute("value"))):
                    stonith_enabled = False
                    break
            if not stonith_enabled:
                break
        for resource in conf.getElementsByTagName("primitive"):
            if resource.getAttribute("class") == "stonith":
                stonith_devices.append(resource)
                for attribs in resource.getElementsByTagName(
                        "instance_attributes"):
                    for nvpair in attribs.getElementsByTagName("nvpair"):
                        if (nvpair.getAttribute("name") == "action"
                                and nvpair.getAttribute("value")):
                            stonith_devices_id_action.append(
                                resource.getAttribute("id"))
                        if (nvpair.getAttribute("name") == "method"
                                and nvpair.getAttribute("value") == "cycle"):
                            stonith_devices_id_method_cycle.append(
                                resource.getAttribute("id"))

    if not utils.usefile:
        # check if SBD daemon is running
        try:
            sbd_running = utils.is_service_running(utils.cmd_runner(),
                                                   get_sbd_service_name())
        except LibraryError:
            pass

    if stonith_enabled and not stonith_devices and not sbd_running:
        print("WARNING: no stonith devices and stonith-enabled is not false")

    if stonith_devices_id_action:
        print(
            "WARNING: following stonith devices have the 'action' option set, "
            "it is recommended to set {0} instead: {1}".format(
                ", ".join(
                    ["'{0}'".format(x) for x in _STONITH_ACTION_REPLACED_BY]),
                ", ".join(sorted(stonith_devices_id_action))))
    if stonith_devices_id_method_cycle:
        print(
            "WARNING: following stonith devices have the 'method' option set "
            "to 'cycle' which is potentially dangerous, please consider using "
            "'onoff': {0}".format(", ".join(
                sorted(stonith_devices_id_method_cycle))))
Exemple #5
0
def is_resource_managed(cluster_state, resource_id):
    """
    Check if the resource is managed

    etree cluster_state -- status of the cluster
    string resource_id -- id of the resource
    """
    primitive_list = cluster_state.xpath(
        """
        .//resource[{predicate_id}]
        |
        .//group[{predicate_id}]/resource
        """.format(predicate_id=_id_xpath_predicate),
        id=resource_id,
    )
    if primitive_list:
        for primitive in primitive_list:
            if is_false(primitive.attrib.get("managed", "")):
                return False
            parent = find_parent(primitive, ["clone", "bundle"])
            if parent is not None and is_false(parent.attrib.get(
                    "managed", "")):
                return False
        return True

    parent_list = cluster_state.xpath(
        """
        .//clone[@id=$resource_id]
        |
        .//bundle[@id=$resource_id]
        """,
        resource_id=resource_id,
    )
    for parent in parent_list:
        if is_false(parent.attrib.get("managed", "")):
            return False
        for primitive in parent.xpath(".//resource"):
            if is_false(primitive.attrib.get("managed", "")):
                return False
        return True

    raise ResourceNotFound(resource_id)
Exemple #6
0
def is_stonith_enabled(crm_config_el: _Element) -> bool:
    # We should read the default value from pacemaker. However, that may slow
    # pcs down as we need to run 'pacemaker-schedulerd metadata' to get it.
    stonith_enabled = True
    # TODO properly support multiple cluster_property_set with rules
    for nvpair in crm_config_el.iterfind(
            "cluster_property_set/nvpair[@name='stonith-enabled']"):
        if is_false(nvpair.get("value")):
            stonith_enabled = False
            break
    return stonith_enabled
Exemple #7
0
def is_resource_managed(cluster_state, resource_id):
    """
    Check if the resource is managed

    etree cluster_state -- status of the cluster
    string resource_id -- id of the resource
    """
    primitive_list = cluster_state.xpath("""
        .//resource[{predicate_id}]
        |
        .//group[{predicate_id}]/resource
        """.format(predicate_id=_id_xpath_predicate(resource_id))
    )
    if primitive_list:
        for primitive in primitive_list:
            if is_false(primitive.attrib.get("managed", "")):
                return False
            parent = find_parent(primitive, ["clone", "bundle"])
            if (
                parent is not None
                and
                is_false(parent.attrib.get("managed", ""))
            ):
                return False
        return True

    parent_list = cluster_state.xpath("""
        .//clone[@id="{0}"]
        |
        .//bundle[@id="{0}"]
        """.format(resource_id)
    )
    for parent in parent_list:
        if is_false(parent.attrib.get("managed", "")):
            return False
        for primitive in parent.xpath(".//resource"):
            if is_false(primitive.attrib.get("managed", "")):
                return False
        return True

    raise ResourceNotFound(resource_id)
Exemple #8
0
 def test_nonfalse_is_not_false(self):
     self.assertFalse(lib.is_false(""))
     self.assertFalse(lib.is_false(" 0 "))
     self.assertFalse(lib.is_false("x"))
     self.assertFalse(lib.is_false("-1"))
     self.assertFalse(lib.is_false("10"))
     self.assertFalse(lib.is_false("heck no"))
Exemple #9
0
 def test_nonfalse_is_not_false(self):
     self.assertFalse(lib.is_false(""))
     self.assertFalse(lib.is_false(" 0 "))
     self.assertFalse(lib.is_false("x"))
     self.assertFalse(lib.is_false("-1"))
     self.assertFalse(lib.is_false("10"))
     self.assertFalse(lib.is_false("heck no"))
Exemple #10
0
def status_stonith_check(modifiers):
    """
    Commandline options:
      * -f - CIB file, to get stonith devices and cluster property
        stonith-enabled from CIB, to determine whenever we are working with
        files or cluster
    """
    # pylint: disable=too-many-nested-blocks
    # We should read the default value from pacemaker. However that may slow
    # pcs down as we need to run 'pacemaker-schedulerd metadata' to get it.
    warnings = []
    stonith_enabled = True
    stonith_devices = []
    stonith_devices_id_action = []
    stonith_devices_id_method_cycle = []
    sbd_running = False

    cib = utils.get_cib_dom()
    for conf in cib.getElementsByTagName("configuration"):
        for crm_config in conf.getElementsByTagName("crm_config"):
            for nvpair in crm_config.getElementsByTagName("nvpair"):
                if (nvpair.getAttribute("name") == "stonith-enabled"
                        and is_false(nvpair.getAttribute("value"))):
                    stonith_enabled = False
                    break
            if not stonith_enabled:
                break
        for resource_el in conf.getElementsByTagName("primitive"):
            if resource_el.getAttribute("class") == "stonith":
                stonith_devices.append(resource_el)
                for attribs in resource_el.getElementsByTagName(
                        "instance_attributes"):
                    for nvpair in attribs.getElementsByTagName("nvpair"):
                        if (nvpair.getAttribute("name") == "action"
                                and nvpair.getAttribute("value")):
                            stonith_devices_id_action.append(
                                resource_el.getAttribute("id"))
                        if (nvpair.getAttribute("name") == "method"
                                and nvpair.getAttribute("value") == "cycle"):
                            stonith_devices_id_method_cycle.append(
                                resource_el.getAttribute("id"))

    if not modifiers.is_specified("-f"):
        # check if SBD daemon is running
        try:
            sbd_running = utils.is_service_running(utils.cmd_runner(),
                                                   get_sbd_service_name())
        except LibraryError:
            pass

    if stonith_enabled and not stonith_devices and not sbd_running:
        warnings.append("No stonith devices and stonith-enabled is not false")

    if stonith_devices_id_action:
        warnings.append(
            "Following stonith devices have the 'action' option set, "
            "it is recommended to set {0} instead: {1}".format(
                ", ".join(
                    ["'{0}'".format(x) for x in _STONITH_ACTION_REPLACED_BY]),
                ", ".join(sorted(stonith_devices_id_action))))
    if stonith_devices_id_method_cycle:
        warnings.append(
            "Following stonith devices have the 'method' option set "
            "to 'cycle' which is potentially dangerous, please consider using "
            "'onoff': {0}".format(", ".join(
                sorted(stonith_devices_id_method_cycle))))
    return warnings