Esempio n. 1
0
 def test_some_operations_exclude(self):
     self.assertEqual(
         ["dummy2"],
         simulate.get_resources_from_operations(
             self.operations, exclude={"dummy1", "dummy2:1", "dummyX"}
         ),
     )
Esempio n. 2
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,
                ))
Esempio n. 3
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,
                ))
Esempio n. 4
0
 def test_some_operations(self):
     self.assertEqual(["dummy1", "dummy2"],
                      simulate.get_resources_from_operations(
                          self.operations))
Esempio n. 5
0
 def test_no_operations_exclude(self):
     self.assertEqual([],
                      simulate.get_resources_from_operations(
                          [], exclude={"dummy1"}))
Esempio n. 6
0
 def test_no_operations(self):
     self.assertEqual([], simulate.get_resources_from_operations([]))