コード例 #1
0
    def test_some_node_names_missing(self):
        (self.config
            .env.set_known_nodes(["rh7-2"])
            .corosync_conf.load(filename="corosync-some-node-names.conf")
            .http.add_communication(
                "get_sbd_config",
                [
                    dict(
                        label="rh7-2",
                        output="OPTION=value",
                        response_code=200,
                    ),
                ],
                action="remote/get_sbd_config",
            )
        )

        result = get_cluster_sbd_config(self.env_assist.get_env())
        self.assertEqual(
            result,
            [
                {
                    "node": "rh7-2",
                    "config": {"OPTION": "value"}
                },
            ]
        )

        self.env_assist.assert_reports([
            fixture.warn(
                report_codes.COROSYNC_CONFIG_MISSING_NAMES_OF_NODES,
                fatal=False,
            ),
        ])
コード例 #2
0
    def test_some_node_names_missing(self):
        (self.config
            .env.set_known_nodes(["rh7-2"])
            .corosync_conf.load(filename="corosync-some-node-names.conf")
            .http.add_communication(
                "get_sbd_config",
                [
                    dict(
                        label="rh7-2",
                        output="OPTION=value",
                        response_code=200,
                    ),
                ],
                action="remote/get_sbd_config",
            )
        )

        result = get_cluster_sbd_config(self.env_assist.get_env())
        self.assertEqual(
            result,
            [
                {
                    "node": "rh7-2",
                    "config": {"OPTION": "value"}
                },
            ]
        )

        self.env_assist.assert_reports([
            fixture.warn(
                report_codes.COROSYNC_CONFIG_MISSING_NAMES_OF_NODES,
                fatal=False,
            ),
        ])
コード例 #3
0
    def test_few_failures(self, mock_sbd_cfg, mock_get_nodes):
        def ret_val(communicator, node):
            self.assertEqual(communicator, self.mock_com)
            if node.label == "node0":
                return """\
            # comment
            SBD_TEST=true
            ANOTHER_OPT=1
            """
            elif node.label == "node1":
                return """\
invalid value

            """
            elif node.label == "node2":
                raise NodeConnectionException(node.label, "command", "reason")
            else:
                raise AssertionError(
                    "Unexpected call: node={node}, node.label={label}".format(
                        node=str(node), label=node.label
                    )
                )

        mock_sbd_cfg.side_effect = ret_val
        self.mock_env.is_cman_cluster = False
        mock_get_nodes.return_value = self.node_list
        expected = [
            {
                "node": self.node_list.find_by_label("node0"),
                "config": {
                    "SBD_TEST": "true",
                    "ANOTHER_OPT": "1"
                }
            },
            {
                "node": self.node_list.find_by_label("node1"),
                "config": {}
            },
            {
                "node": self.node_list.find_by_label("node2"),
                "config": None
            }
        ]

        self.assertEqual(
            expected, cmd_sbd.get_cluster_sbd_config(self.mock_env)
        )
        mock_get_nodes.assert_called_once_with(self.mock_env)
        self.assertEqual(3, mock_sbd_cfg.call_count)
        assert_report_item_list_equal(
            self.mock_rep.report_item_list,
            [(
                Severities.WARNING,
                report_codes.UNABLE_TO_GET_SBD_CONFIG,
                {"node": "node2"}
            )]
        )
コード例 #4
0
    def test_success(self, mock_sbd_cfg, mock_get_nodes):
        this = self

        def ret_val(communicator, node):
            this.assertEqual(communicator, this.mock_com)
            if node.label == "node0":
                return """\
# comment
SBD_TEST=true
ANOTHER_OPT=1
"""
            elif node.label == "node1":
                return """\
OPTION=   value

"""
            elif node.label == "node2":
                return """\

# just comment

"""
            else:
                raise AssertionError(
                    "Unexpected call: node={node}, node.label={label}".format(
                        node=str(node), label=node.label
                    )
                )

        mock_sbd_cfg.side_effect = ret_val
        self.mock_env.is_cman_cluster = False
        mock_get_nodes.return_value = self.node_list
        expected = [
            {
                "node": self.node_list.find_by_label("node0"),
                "config": {
                    "SBD_TEST": "true",
                    "ANOTHER_OPT": "1"
                }
            },
            {
                "node": self.node_list.find_by_label("node1"),
                "config": {"OPTION": "value"}
            },
            {
                "node": self.node_list.find_by_label("node2"),
                "config": {}
            }
        ]

        self.assertEqual(
            expected, cmd_sbd.get_cluster_sbd_config(self.mock_env)
        )
        mock_get_nodes.assert_called_once_with(self.mock_env)
        self.assertEqual(3, mock_sbd_cfg.call_count)
        self.assertEqual(self.mock_log.warning.call_count, 0)
コード例 #5
0
    def test_success(self, mock_sbd_cfg, mock_get_nodes):
        this = self

        def ret_val(communicator, node):
            this.assertEqual(communicator, this.mock_com)
            if node.label == "node0":
                return """\
# comment
SBD_TEST=true
ANOTHER_OPT=1
"""
            elif node.label == "node1":
                return """\
OPTION=   value

"""
            elif node.label == "node2":
                return """\

# just comment

"""
            else:
                raise AssertionError(
                    "Unexpected call: node={node}, node.label={label}".format(
                        node=str(node), label=node.label
                    )
                )

        mock_sbd_cfg.side_effect = ret_val
        self.mock_env.is_cman_cluster = False
        mock_get_nodes.return_value = self.node_list
        expected = [
            {
                "node": self.node_list.find_by_label("node0"),
                "config": {
                    "SBD_TEST": "true",
                    "ANOTHER_OPT": "1"
                }
            },
            {
                "node": self.node_list.find_by_label("node1"),
                "config": {"OPTION": "value"}
            },
            {
                "node": self.node_list.find_by_label("node2"),
                "config": {}
            }
        ]

        _assert_equal_list_of_dictionaries_without_order(
            expected, cmd_sbd.get_cluster_sbd_config(self.mock_env)
        )
        mock_get_nodes.assert_called_once_with(self.mock_env)
        self.assertEqual(3, mock_sbd_cfg.call_count)
        self.assertEqual(self.mock_log.warning.call_count, 0)
コード例 #6
0
 def test_cman_cluster(self, mock_sbd_cfg, mock_get_nodes):
     self.mock_env.is_cman_cluster = True
     assert_raise_library_error(
         lambda: cmd_sbd.get_cluster_sbd_config(self.mock_env),
         (
             Severities.ERROR,
             report_codes.CMAN_UNSUPPORTED_COMMAND,
             {}
         )
     )
コード例 #7
0
    def test_all_node_names_missing(self):
        self.config.corosync_conf.load(filename="corosync-no-node-names.conf")

        self.env_assist.assert_raise_library_error(
            lambda: get_cluster_sbd_config(self.env_assist.get_env()))
        self.env_assist.assert_reports([
            fixture.warn(
                report_codes.COROSYNC_CONFIG_MISSING_NAMES_OF_NODES,
                fatal=False,
            ),
            fixture.error(report_codes.COROSYNC_CONFIG_NO_NODES_DEFINED, ),
        ])
コード例 #8
0
ファイル: test_lib_commands_sbd.py プロジェクト: jmartign/pcs
    def test_few_failures(self, mock_sbd_cfg, mock_get_nodes):
        def ret_val(communicator, node):
            self.assertEqual(communicator, self.mock_com)
            if node.label == "node0":
                return """\
            # comment
            SBD_TEST=true
            ANOTHER_OPT=1
            """
            elif node.label == "node1":
                return """\
invalid value

            """
            elif node.label == "node2":
                raise NodeConnectionException(node.label, "command", "reason")
            else:
                raise AssertionError(
                    "Unexpected call: node={node}, node.label={label}".format(
                        node=str(node), label=node.label))

        mock_sbd_cfg.side_effect = ret_val
        self.mock_env.is_cman_cluster = False
        mock_get_nodes.return_value = self.node_list
        expected = [{
            "node": self.node_list.find_by_label("node0"),
            "config": {
                "SBD_TEST": "true",
                "ANOTHER_OPT": "1"
            }
        }, {
            "node": self.node_list.find_by_label("node1"),
            "config": {}
        }, {
            "node": self.node_list.find_by_label("node2"),
            "config": None
        }]

        _assert_equal_list_of_dictionaries_without_order(
            expected, cmd_sbd.get_cluster_sbd_config(self.mock_env))
        mock_get_nodes.assert_called_once_with(self.mock_env)
        self.assertEqual(3, mock_sbd_cfg.call_count)
        assert_report_item_list_equal(self.mock_rep.report_item_list, [
            (Severities.WARNING,
             report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT, {
                 "node": "node2",
                 "reason": "reason",
                 "command": "command",
             }),
            (Severities.WARNING, report_codes.UNABLE_TO_GET_SBD_CONFIG, {
                "node": "node2"
            }),
        ])
コード例 #9
0
    def test_all_node_names_missing(self):
        self.config.corosync_conf.load(filename="corosync-no-node-names.conf")

        self.env_assist.assert_raise_library_error(
            lambda: get_cluster_sbd_config(self.env_assist.get_env()),
            [
                fixture.error(
                    report_codes.COROSYNC_CONFIG_NO_NODES_DEFINED,
                ),
            ]
        )
        self.env_assist.assert_reports([
            fixture.warn(
                report_codes.COROSYNC_CONFIG_MISSING_NAMES_OF_NODES,
                fatal=False,
            ),
        ])
コード例 #10
0
    def test_different_responses(self):
        node_name_list = ["node-1", "node-2", "node-3", "node-4", "node-5"]
        (self.config
            .env.set_known_nodes(node_name_list)
            .corosync_conf.load(
                node_name_list=node_name_list, auto_tie_breaker=True,
            )
            .http.add_communication(
                "get_sbd_config",
                [
                    dict(
                        label="node-1",
                        output=outdent(
                            """\
                            # This file has been generated by pcs.
                            SBD_DELAY_START=no
                            SBD_OPTS="-n node-1"
                            SBD_PACEMAKER=yes
                            SBD_STARTMODE=always
                            SBD_WATCHDOG_DEV=/dev/watchdog
                            SBD_WATCHDOG_TIMEOUT=5
                            """
                        ),
                        response_code=200,
                    ),
                    dict(
                        label="node-2",
                        was_connected=False,
                        errno=7,
                        error_msg="Failed connect to node-2:2224;"
                            " No route to host"
                        ,
                    ),
                    dict(
                        label="node-3",
                        output="OPTION=   value",
                        response_code=200,
                    ),
                    dict(
                        label="node-4",
                        output="# just comment",
                        response_code=200,
                    ),
                    dict(
                        label="node-5",
                        output="invalid value",
                        response_code=200,
                    ),
                ],
                action="remote/get_sbd_config",
            )
        )
        self.assertEqual(
            get_cluster_sbd_config(self.env_assist.get_env()),
            [
               {
                   'node': 'node-1',
                   'config': {
                       'SBD_WATCHDOG_TIMEOUT': '5',
                       'SBD_WATCHDOG_DEV': '/dev/watchdog',
                       'SBD_PACEMAKER': 'yes',
                       'SBD_OPTS': '"-n node-1"',
                       'SBD_STARTMODE': 'always',
                       'SBD_DELAY_START': 'no'
                   },
                },
                {
                    'node': 'node-3',
                    'config': {
                        "OPTION": "value",
                    }
                },
                {
                    'node': 'node-4',
                    'config': {},
                },
                {
                    'node': 'node-5',
                    'config': {},
                },
                {
                    'node': 'node-2',
                    'config': None,
                },
            ]
        )

        self.env_assist.assert_reports([
            fixture.warn(
                report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT,
                node="node-2",
                reason="Failed connect to node-2:2224; No route to host",
                command="remote/get_sbd_config",
            ),
            fixture.warn(
                report_codes.UNABLE_TO_GET_SBD_CONFIG,
                node="node-2",
                reason="",
            ),
        ])
コード例 #11
0
    def test_different_responses(self):
        node_name_list = ["node-1", "node-2", "node-3", "node-4", "node-5"]
        (self.config
            .env.set_known_nodes(node_name_list)
            .corosync_conf.load(
                node_name_list=node_name_list, auto_tie_breaker=True,
            )
            .http.add_communication(
                "get_sbd_config",
                [
                    dict(
                        label="node-1",
                        output=outdent(
                            """\
                            # This file has been generated by pcs.
                            SBD_DELAY_START=no
                            SBD_OPTS="-n node-1"
                            SBD_PACEMAKER=yes
                            SBD_STARTMODE=always
                            SBD_WATCHDOG_DEV=/dev/watchdog
                            SBD_WATCHDOG_TIMEOUT=5
                            """
                        ),
                        response_code=200,
                    ),
                    dict(
                        label="node-2",
                        was_connected=False,
                        errno=7,
                        error_msg="Failed connect to node-2:2224;"
                            " No route to host"
                        ,
                    ),
                    dict(
                        label="node-3",
                        output="OPTION=   value",
                        response_code=200,
                    ),
                    dict(
                        label="node-4",
                        output="# just comment",
                        response_code=200,
                    ),
                    dict(
                        label="node-5",
                        output="invalid value",
                        response_code=200,
                    ),
                ],
                action="remote/get_sbd_config",
            )
        )
        self.assertEqual(
            get_cluster_sbd_config(self.env_assist.get_env()),
            [
               {
                   'node': 'node-1',
                   'config': {
                       'SBD_WATCHDOG_TIMEOUT': '5',
                       'SBD_WATCHDOG_DEV': '/dev/watchdog',
                       'SBD_PACEMAKER': 'yes',
                       'SBD_OPTS': '"-n node-1"',
                       'SBD_STARTMODE': 'always',
                       'SBD_DELAY_START': 'no'
                   },
                },
                {
                    'node': 'node-3',
                    'config': {
                        "OPTION": "value",
                    }
                },
                {
                    'node': 'node-4',
                    'config': {},
                },
                {
                    'node': 'node-5',
                    'config': {},
                },
                {
                    'node': 'node-2',
                    'config': None,
                },
            ]
        )

        self.env_assist.assert_reports([
            fixture.warn(
                report_codes.NODE_COMMUNICATION_ERROR_UNABLE_TO_CONNECT,
                node="node-2",
                reason="Failed connect to node-2:2224; No route to host",
                command="remote/get_sbd_config",
            ),
            fixture.warn(
                report_codes.UNABLE_TO_GET_SBD_CONFIG,
                node="node-2",
                reason="",
            ),
        ])
コード例 #12
0
ファイル: test_lib_commands_sbd.py プロジェクト: jmartign/pcs
 def test_cman_cluster(self, mock_sbd_cfg, mock_get_nodes):
     self.mock_env.is_cman_cluster = True
     assert_raise_library_error(
         lambda: cmd_sbd.get_cluster_sbd_config(self.mock_env),
         (Severities.ERROR, report_codes.CMAN_UNSUPPORTED_COMMAND, {}))