예제 #1
0
파일: test_live.py 프로젝트: zht750808/pcs
    def test_error_not_connected(self):
        expected_stdout = '<crm_mon version="2.0.5"/>\n'
        expected_stderr = (
            "Not connected\n"
            "Could not connect to the CIB: Transport endpoint is not connected\n"
            "crm_mon: Error: cluster is not available on this node\n")
        expected_retval = _EXITCODE_NOT_CONNECTED
        mock_runner = get_runner(expected_stdout, expected_stderr,
                                 expected_retval)

        with self.assertRaises(lib.PacemakerNotConnectedException) as cm:
            lib.get_cluster_status_xml(mock_runner)
        assert_report_item_list_equal(
            cm.exception.args,
            [
                (
                    Severity.ERROR,
                    report_codes.CRM_MON_ERROR,
                    {
                        "reason": expected_stderr + expected_stdout.strip(),
                    },
                ),
            ],
        )
        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
예제 #2
0
def verify(env, verbose=False):
    runner = env.cmd_runner()
    dummy_stdout, verify_stderr, verify_returncode = verify_cmd(
        runner,
        verbose=verbose,
    )

    #1) Do not even try to think about upgrading!
    #2) We do not need cib management in env (no need for push...).
    #So env.get_cib is not best choice here (there were considerations to
    #upgrade cib at all times inside env.get_cib). Go to a lower level here.
    if verify_returncode != 0:
        env.report_processor.append(reports.invalid_cib_content(verify_stderr))

        #Cib is sometimes loadable even if `crm_verify` fails (e.g. when
        #fencing topology is invalid). On the other hand cib with id duplication
        #is not loadable.
        #We try extra checks when cib is possible to load.
        cib_xml, dummy_stderr, returncode = get_cib_xml_cmd_results(runner)
        if returncode != 0:
            #can raise; raise LibraryError is better but in this case we prefer
            #be consistent with raising below
            env.report_processor.send()
    else:
        cib_xml = get_cib_xml(runner)

    cib = get_cib(cib_xml)
    fencing_topology.verify(
        env.report_processor, get_fencing_topology(cib), get_resources(cib),
        ClusterState(get_cluster_status_xml(runner)).node_section.nodes)
    #can raise
    env.report_processor.send()
예제 #3
0
def add_level(lib_env,
              level,
              target_type,
              target_value,
              devices,
              force_device=False,
              force_node=False):
    """
    Validate and add a new fencing level

    LibraryError lib_env -- environment
    int|string level -- level (index) of the new fencing level
    constant target_type -- the new fencing level target value type
    mixed target_value -- the new fencing level target value
    Iterable devices -- list of stonith devices for the new fencing level
    bool force_device -- continue even if a stonith device does not exist
    bool force_node -- continue even if a node (target) does not exist
    """
    version_check = None
    if target_type == TARGET_TYPE_REGEXP:
        version_check = (2, 3, 0)
    elif target_type == TARGET_TYPE_ATTRIBUTE:
        version_check = (2, 4, 0)

    cib = lib_env.get_cib(version_check)
    cib_fencing_topology.add_level(
        lib_env.report_processor, get_fencing_topology(cib),
        get_resources(cib), level, target_type, target_value, devices,
        ClusterState(get_cluster_status_xml(
            lib_env.cmd_runner())).node_section.nodes, force_device,
        force_node)
    lib_env.report_processor.send()
    lib_env.push_cib()
예제 #4
0
파일: node.py 프로젝트: junaruga/pcs
def cib_runner_nodes(lib_env, wait):
    lib_env.ensure_wait_satisfiable(wait)
    runner = lib_env.cmd_runner()

    state_nodes = ClusterState(
        get_cluster_status_xml(runner)).node_section.nodes

    yield (lib_env.get_cib(), runner, state_nodes)
    lib_env.push_cib(wait=wait)
예제 #5
0
파일: node.py 프로젝트: tomjelinek/pcs
def cib_runner_nodes(lib_env, wait):
    lib_env.ensure_wait_satisfiable(wait)
    runner = lib_env.cmd_runner()

    state_nodes = ClusterState(
        get_cluster_status_xml(runner)
    ).node_section.nodes

    yield (lib_env.get_cib(), runner, state_nodes)
    lib_env.push_cib(wait=wait)
예제 #6
0
    def test_success(self):
        expected_stdout = "<xml />"
        expected_stderr = ""
        expected_retval = 0
        mock_runner = get_runner(expected_stdout, expected_stderr,
                                 expected_retval)

        real_xml = lib.get_cluster_status_xml(mock_runner)

        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
        self.assertEqual(expected_stdout, real_xml)
예제 #7
0
    def test_success(self):
        expected_stdout = "<xml />"
        expected_stderr = ""
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (expected_stdout, expected_stderr,
                                        expected_retval)

        real_xml = lib.get_cluster_status_xml(mock_runner)

        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
        self.assertEqual(expected_stdout, real_xml)
예제 #8
0
def verify(lib_env):
    """
    Check if all cluster nodes and stonith devices used in fencing levels exist

    LibraryError lib_env -- environment
    """
    cib = lib_env.get_cib()
    cib_fencing_topology.verify(
        lib_env.report_processor, get_fencing_topology(cib),
        get_resources(cib),
        ClusterState(get_cluster_status_xml(
            lib_env.cmd_runner())).node_section.nodes)
    lib_env.report_processor.send()
예제 #9
0
파일: test_live.py 프로젝트: tomjelinek/pcs
    def test_success(self):
        expected_stdout = "<xml />"
        expected_stderr = ""
        expected_retval = 0
        mock_runner = get_runner(
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        real_xml = lib.get_cluster_status_xml(mock_runner)

        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
        self.assertEqual(expected_stdout, real_xml)
예제 #10
0
    def test_error(self):
        expected_stdout = "some info"
        expected_stderr = "some error"
        expected_retval = 1
        mock_runner = get_runner(expected_stdout, expected_stderr,
                                 expected_retval)

        assert_raise_library_error(
            lambda: lib.get_cluster_status_xml(mock_runner),
            (Severity.ERROR, report_codes.CRM_MON_ERROR, {
                "reason": expected_stderr + "\n" + expected_stdout,
            }))

        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
예제 #11
0
    def test_success(self):
        expected_stdout = "<xml />"
        expected_stderr = ""
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        real_xml = lib.get_cluster_status_xml(mock_runner)

        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
        self.assertEqual(expected_stdout, real_xml)
예제 #12
0
def verify(lib_env):
    """
    Check if all cluster nodes and stonith devices used in fencing levels exist

    LibraryEnvironment lib_env -- environment
    """
    cib = lib_env.get_cib()
    cib_fencing_topology.verify(
        lib_env.report_processor,
        get_fencing_topology(cib),
        get_resources(cib),
        ClusterState(
            get_cluster_status_xml(lib_env.cmd_runner())
        ).node_section.nodes
    )
    lib_env.report_processor.send()
예제 #13
0
def verify(lib_env: LibraryEnvironment):
    """
    Check if all cluster nodes and stonith devices used in fencing levels exist

    LibraryEnvironment lib_env -- environment
    """
    cib = lib_env.get_cib()
    lib_env.report_processor.report_list(
        cib_fencing_topology.verify(
            get_fencing_topology(cib),
            get_resources(cib),
            ClusterState(
                get_cluster_status_xml(lib_env.cmd_runner())
            ).node_section.nodes,
        )
    )
    if lib_env.report_processor.has_errors:
        raise LibraryError()
예제 #14
0
파일: test_live.py 프로젝트: tomjelinek/pcs
    def test_error(self):
        expected_stdout = "some info"
        expected_stderr = "some error"
        expected_retval = 1
        mock_runner = get_runner(
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        assert_raise_library_error(
            lambda: lib.get_cluster_status_xml(mock_runner),
            (
                Severity.ERROR,
                report_codes.CRM_MON_ERROR,
                {
                    "reason": expected_stderr + "\n" + expected_stdout,
                }
            )
        )

        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
예제 #15
0
def add_level(
    lib_env, level, target_type, target_value, devices,
    force_device=False, force_node=False
):
    """
    Validate and add a new fencing level

    LibraryEnvironment lib_env -- environment
    int|string level -- level (index) of the new fencing level
    constant target_type -- the new fencing level target value type
    mixed target_value -- the new fencing level target value
    Iterable devices -- list of stonith devices for the new fencing level
    bool force_device -- continue even if a stonith device does not exist
    bool force_node -- continue even if a node (target) does not exist
    """
    version_check = None
    if target_type == TARGET_TYPE_REGEXP:
        version_check = Version(2, 3, 0)
    elif target_type == TARGET_TYPE_ATTRIBUTE:
        version_check = Version(2, 4, 0)

    cib = lib_env.get_cib(version_check)
    cib_fencing_topology.add_level(
        lib_env.report_processor,
        get_fencing_topology(cib),
        get_resources(cib),
        level,
        target_type,
        target_value,
        devices,
        ClusterState(
            get_cluster_status_xml(lib_env.cmd_runner())
        ).node_section.nodes,
        force_device,
        force_node
    )
    lib_env.report_processor.send()
    lib_env.push_cib()
예제 #16
0
파일: env.py 프로젝트: HideoYamauchi/pcs
 def get_cluster_state(self):
     return get_cluster_state_dom(get_cluster_status_xml(self.cmd_runner()))
예제 #17
0
 def get_cluster_state(self):
     return get_cluster_state_dom(get_cluster_status_xml(self.cmd_runner()))