Ejemplo n.º 1
0
def disable_safe(env, resource_ids, strict, wait):
    """
    Disallow specified resource to be started by the cluster only if there is
    no effect on other resources

    LibraryEnvironment env --
    strings resource_ids -- ids of the resources to be disabled
    bool strict -- if False, allow resources to be migrated
    mixed wait -- False: no wait, None: wait default timeout, int: wait timeout
    """
    if not env.is_cib_live:
        raise LibraryError(
            reports.live_environment_required([file_type_codes.CIB]))

    with resource_environment(
            env, wait, resource_ids,
            _ensure_disabled_after_wait(True)) as resources_section:
        id_provider = IdProvider(resources_section)
        resource_el_list = _find_resources_or_raise(resources_section,
                                                    resource_ids)
        env.report_processor.process_list(
            _resource_list_enable_disable(resource_el_list,
                                          resource.common.disable, id_provider,
                                          env.get_cluster_state()))

        inner_resources_names_set = set()
        for resource_el in resource_el_list:
            inner_resources_names_set.update({
                inner_resource_el.get("id")
                for inner_resource_el in
                resource.common.get_all_inner_resources(resource_el)
            })

        plaintext_status, transitions, dummy_cib = simulate_cib(
            env.cmd_runner(), get_root(resources_section))
        simulated_operations = (
            simulate_tools.get_operations_from_transitions(transitions))
        other_affected = set()
        if strict:
            other_affected = set(
                simulate_tools.get_resources_from_operations(
                    simulated_operations, exclude=resource_ids))
        else:
            other_affected = set(
                simulate_tools.get_resources_left_stopped(
                    simulated_operations, exclude=resource_ids) +
                simulate_tools.get_resources_left_demoted(
                    simulated_operations, exclude=resource_ids))

        # Stopping a clone stops all its inner resources. That should not block
        # stopping the clone.
        other_affected = other_affected - inner_resources_names_set
        if other_affected:
            raise LibraryError(
                reports.resource_disable_affects_other_resources(
                    resource_ids,
                    other_affected,
                    plaintext_status,
                ))
Ejemplo n.º 2
0
 def test_success(self, mock_simulate):
     mock_simulate.return_value = (self.simulate_output, self.transitions,
                                   self.new_cib)
     result = lib.simulate_cib(self.runner, self.cib)
     self.assertEqual(result[0], "some output")
     self.assertEqual(etree_to_str(result[1]), self.transitions)
     self.assertEqual(etree_to_str(result[2]), self.new_cib)
     mock_simulate.assert_called_once_with(self.runner, self.cib_xml)
Ejemplo n.º 3
0
 def test_invalid_transitions(self, mock_simulate):
     mock_simulate.return_value = (self.simulate_output, self.transitions,
                                   "bad new cib")
     assert_raise_library_error(
         lambda: lib.simulate_cib(self.runner, self.cib),
         fixture.error(
             report_codes.CIB_SIMULATE_ERROR,
             reason=("Start tag expected, '<' not found, line 1, column 1 "
                     "(<string>, line 1)"),
         ),
     )
Ejemplo n.º 4
0
def disable_simulate(env, resource_ids):
    """
    Simulate disallowing specified resource to be started by the cluster

    LibraryEnvironment env --
    strings resource_ids -- ids of the resources to be disabled
    """
    if not env.is_cib_live:
        raise LibraryError(
            reports.live_environment_required([file_type_codes.CIB]))

    resources_section = get_resources(env.get_cib())
    _disable_validate_and_edit_cib(env, resources_section, resource_ids)
    plaintext_status, dummy_transitions, dummy_cib = simulate_cib(
        env.cmd_runner(), get_root(resources_section))
    return plaintext_status
Ejemplo n.º 5
0
def disable_safe(env, resource_ids, strict, wait):
    """
    Disallow specified resource to be started by the cluster only if there is
    no effect on other resources

    LibraryEnvironment env --
    strings resource_ids -- ids of the resources to be disabled
    bool strict -- if False, allow resources to be migrated
    mixed wait -- False: no wait, None: wait default timeout, int: wait timeout
    """
    if not env.is_cib_live:
        raise LibraryError(
            reports.live_environment_required([file_type_codes.CIB]))

    with resource_environment(
            env, wait, resource_ids,
            _ensure_disabled_after_wait(True)) as resources_section:
        _disable_validate_and_edit_cib(env, resources_section, resource_ids)
        plaintext_status, transitions, dummy_cib = simulate_cib(
            env.cmd_runner(), get_root(resources_section))
        simulated_operations = (
            simulate_tools.get_operations_from_transitions(transitions))
        other_affected = set()
        if strict:
            other_affected = set(
                simulate_tools.get_resources_from_operations(
                    simulated_operations, exclude=resource_ids))
        else:
            other_affected = set(
                simulate_tools.get_resources_left_stopped(
                    simulated_operations, exclude=resource_ids) +
                simulate_tools.get_resources_left_demoted(
                    simulated_operations, exclude=resource_ids))
        if other_affected:
            raise LibraryError(
                reports.resource_disable_affects_other_resources(
                    resource_ids,
                    other_affected,
                    plaintext_status,
                ))