Exemplo n.º 1
0
def assess_status_helper():
    """Assess status of unit

    @returns status, message - status is workload status and message is any
                               corresponding messages
    """
    if config('stonith_enabled') in ['true', 'True', True]:
        return ('blocked',
                'stonith_enabled config option is no longer supported')

    if is_unit_upgrading_set():
        return ("blocked",
                "Ready for do-release-upgrade. Set complete when finished")
    if is_waiting_unit_series_upgrade_set():
        return ("blocked",
                "HA services shutdown, peers are ready for series upgrade")
    if is_unit_paused_set():
        return ("maintenance",
                "Paused. Use 'resume' action to resume normal service.")

    node_count = int(config('cluster_count'))
    status = 'active'
    message = 'Unit is ready and clustered'
    try:
        try_pcmk_wait()
    except pcmk.ServicesNotUp:
        message = 'Pacemaker is down'
        status = 'blocked'
    for relid in relation_ids('hanode'):
        if len(related_units(relid)) + 1 < node_count:
            status = 'blocked'
            message = ("Insufficient peer units for ha cluster "
                       "(require {})".format(node_count))

    # if the status was not changed earlier, we verify the maintenance status
    try:
        if status == 'active':
            prop = pcmk.get_property('maintenance-mode').strip()
    except pcmk.PropertyNotFound:
        # the property is not the output of 'crm configure show xml', so we use
        # the default value for this property. For crmsh>=2.2.0 the default
        # value is automatically provided by show-property or get-property.
        prop = 'false'

    if (status == 'active' and prop == 'true'):
        # maintenance mode enabled in pacemaker
        status = 'maintenance'
        message = 'Pacemaker in maintenance mode'

    for resource in get_resources().keys():
        if not pcmk.is_resource_present(resource):
            return ("waiting",
                    "Resource: {} not yet configured".format(resource))
        if not pcmk.crm_res_running_on_node(resource, get_hostname()):
            return ("blocked", "Resource: {} not running".format(resource))

    return status, message
Exemplo n.º 2
0
    def test_crm_res_running_on_node(self, getstatusoutput):
        _resource = "res_nova_consoleauth"
        _this_node = "node1"
        _another_node = "node5"

        # Not running
        getstatusoutput.return_value = (1, "foobar")
        self.assertFalse(
            pcmk.crm_res_running_on_node(_resource, _this_node))

        # Running active/passive on some other node
        getstatusoutput.return_value = (
            0, "resource {} is running: {}".format(_resource, _another_node))
        self.assertTrue(
            pcmk.crm_res_running_on_node('res_nova_consoleauth', _this_node))

        # Running active/passive on this node
        getstatusoutput.return_value = (
            0, "resource {} is running: {}".format(_resource, _this_node))
        self.assertTrue(
            pcmk.crm_res_running_on_node('res_nova_consoleauth', _this_node))

        # Running on some but not this node
        getstatusoutput.return_value = (
            0, ("resource {} is running: {}\nresource {} is NOT running"
                .format(_resource, _another_node, _resource)))
        self.assertFalse(
            pcmk.crm_res_running_on_node('res_nova_consoleauth', _this_node))

        # Running on this node and not others
        getstatusoutput.return_value = (
            0, ("resource {} is running: {}\nresource {} is NOT running"
                .format(_resource, _this_node, _resource)))
        self.assertTrue(
            pcmk.crm_res_running_on_node('res_nova_consoleauth', _this_node))

        # Running on more than one and this node
        getstatusoutput.return_value = (
            0, ("resource {} is running: {}\nresource {} is running: {}"
                .format(_resource, _another_node, _resource, _this_node)))
        self.assertTrue(
            pcmk.crm_res_running_on_node('res_nova_consoleauth', _this_node))