Exemplo n.º 1
0
def node_standby(argv, standby=True):
    if (len(argv) > 1) or (len(argv) > 0 and "--all" in utils.pcs_options):
        usage.node(["standby" if standby else "unstandby"])
        sys.exit(1)

    all_nodes = "--all" in utils.pcs_options
    node_list = [argv[0]] if argv else []
    wait = False
    timeout = None
    if "--wait" in utils.pcs_options:
        wait = True
        timeout = utils.pcs_options["--wait"]

    try:
        if wait:
            lib_pacemaker.ensure_resource_wait_support(utils.cmd_runner())
            valid_timeout = get_valid_timeout_seconds(timeout)
        if standby:
            lib_pacemaker.nodes_standby(utils.cmd_runner(), node_list,
                                        all_nodes)
        else:
            lib_pacemaker.nodes_unstandby(utils.cmd_runner(), node_list,
                                          all_nodes)
        if wait:
            lib_pacemaker.wait_for_resources(utils.cmd_runner(), valid_timeout)
    except LibraryError as e:
        utils.process_library_reports(e.args)
Exemplo n.º 2
0
Arquivo: node.py Projeto: idevat/pcs
def node_standby(argv, standby=True):
    if (len(argv) > 1) or (len(argv) > 0 and "--all" in utils.pcs_options):
        usage.node(["standby" if standby else "unstandby"])
        sys.exit(1)

    all_nodes = "--all" in utils.pcs_options
    node_list = [argv[0]] if argv else []
    wait = False
    timeout = None
    if "--wait" in utils.pcs_options:
        wait = True
        timeout = utils.pcs_options["--wait"]

    try:
        if wait:
            lib_pacemaker.ensure_resource_wait_support(utils.cmd_runner())
            valid_timeout = get_valid_timeout_seconds(timeout)
        if standby:
            lib_pacemaker.nodes_standby(
                utils.cmd_runner(), node_list, all_nodes
            )
        else:
            lib_pacemaker.nodes_unstandby(
                utils.cmd_runner(), node_list, all_nodes
            )
        if wait:
            lib_pacemaker.wait_for_resources(utils.cmd_runner(), valid_timeout)
    except LibraryError as e:
        utils.process_library_reports(e.args)
Exemplo n.º 3
0
    def test_error_one_node(self):
        expected_stdout = "some info"
        expected_stderr = "some error"
        expected_retval = 1
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        assert_raise_library_error(
            lambda: lib.nodes_unstandby(mock_runner),
            (
                Severity.ERROR,
                report_codes.COMMON_ERROR,
                {
                    "text": expected_stderr + "\n" + expected_stdout,
                }
            )
        )

        mock_runner.run.assert_called_once_with(
            [self.path("crm_standby"), "-D"]
        )
Exemplo n.º 4
0
    def test_unstandby_local(self):
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = ("dummy", "", expected_retval)

        output = lib.nodes_unstandby(mock_runner)

        mock_runner.run.assert_called_once_with(
            [self.path("crm_standby"), "-D"])
        self.assertEqual(None, output)
Exemplo n.º 5
0
    def test_unstandby_local(self):
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = ("dummy", "", expected_retval)

        output = lib.nodes_unstandby(mock_runner)

        mock_runner.run.assert_called_once_with(
            [self.path("crm_standby"), "-D"]
        )
        self.assertEqual(None, output)
Exemplo n.º 6
0
    def test_unstandby_unknown_node(self):
        self.fixture_add_node_status(
            self.fixture_get_node_status("node_1", "id_1"))
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (str(self.status), "", 0)

        assert_raise_library_error(
            lambda: lib.nodes_unstandby(mock_runner, ["node_2", "node_3"]),
            (Severity.ERROR, report_codes.NODE_NOT_FOUND, {
                "node": "node_2"
            }), (Severity.ERROR, report_codes.NODE_NOT_FOUND, {
                "node": "node_3"
            }))

        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
Exemplo n.º 7
0
    def test_error_one_node(self):
        expected_stdout = "some info"
        expected_stderr = "some error"
        expected_retval = 1
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (expected_stdout, expected_stderr,
                                        expected_retval)

        assert_raise_library_error(
            lambda: lib.nodes_unstandby(mock_runner),
            (Severity.ERROR, report_codes.COMMON_ERROR, {
                "text": expected_stderr + "\n" + expected_stdout,
            }))

        mock_runner.run.assert_called_once_with(
            [self.path("crm_standby"), "-D"])
Exemplo n.º 8
0
    def test_unstandby_all(self):
        nodes = ("node1", "node2", "node3")
        for i, n in enumerate(nodes, 1):
            self.fixture_add_node_status(self.fixture_get_node_status(n, i))
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        call_list = [mock.call(self.crm_mon_cmd())]
        call_list += [
            mock.call([self.path("crm_standby"), "-D", "-N", n]) for n in nodes
        ]
        return_value_list = [(str(self.status), "", 0)]
        return_value_list += [("dummy", "", 0) for n in nodes]
        mock_runner.run.side_effect = return_value_list

        output = lib.nodes_unstandby(mock_runner, all_nodes=True)

        self.assertEqual(len(return_value_list), len(call_list))
        self.assertEqual(len(return_value_list), mock_runner.run.call_count)
        mock_runner.run.assert_has_calls(call_list)
        self.assertEqual(None, output)
Exemplo n.º 9
0
    def test_unstandby_unknown_node(self):
        self.fixture_add_node_status(
            self.fixture_get_node_status("node_1", "id_1")
        )
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (str(self.status), "", 0)

        assert_raise_library_error(
            lambda: lib.nodes_unstandby(mock_runner, ["node_2", "node_3"]),
            (
                Severity.ERROR,
                report_codes.NODE_NOT_FOUND,
                {"node": "node_2"}
            ),
            (
                Severity.ERROR,
                report_codes.NODE_NOT_FOUND,
                {"node": "node_3"}
            )
        )

        mock_runner.run.assert_called_once_with(self.crm_mon_cmd())
Exemplo n.º 10
0
    def test_unstandby_nodes(self):
        nodes = ("node1", "node2", "node3")
        for i, n in enumerate(nodes, 1):
            self.fixture_add_node_status(
                self.fixture_get_node_status(n, i)
            )
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        call_list = [mock.call(self.crm_mon_cmd())]
        call_list += [
            mock.call([self.path("crm_standby"), "-D", "-N", n])
            for n in nodes[:2]
        ]
        return_value_list = [(str(self.status), "", 0)]
        return_value_list += [("dummy", "", 0) for n in nodes[:2]]
        mock_runner.run.side_effect = return_value_list

        output = lib.nodes_unstandby(mock_runner, node_list=nodes[:2])

        self.assertEqual(len(return_value_list), len(call_list))
        self.assertEqual(len(return_value_list), mock_runner.run.call_count)
        mock_runner.run.assert_has_calls(call_list)
        self.assertEqual(None, output)