Beispiel #1
0
 def push_corosync_conf(
     self, corosync_conf_facade, skip_offline_nodes=False
 ):
     corosync_conf_data = corosync_conf_facade.config.export()
     if self.is_corosync_conf_live:
         node_list = corosync_conf_facade.get_nodes()
         if corosync_conf_facade.need_stopped_cluster:
             check_corosync_offline_on_nodes(
                 self.node_communicator(),
                 self.report_processor,
                 node_list,
                 skip_offline_nodes
             )
         distribute_corosync_conf(
             self.node_communicator(),
             self.report_processor,
             node_list,
             corosync_conf_data,
             skip_offline_nodes
         )
         if is_service_running(self.cmd_runner(), "corosync"):
             reload_corosync_config(self.cmd_runner())
             self.report_processor.process(
                 reports.corosync_config_reloaded()
             )
         if corosync_conf_facade.need_qdevice_reload:
             qdevice_reload_on_nodes(
                 self.node_communicator(),
                 self.report_processor,
                 node_list,
                 skip_offline_nodes
             )
     else:
         self._corosync_conf_data = corosync_conf_data
Beispiel #2
0
    def test_success(self, mock_remote_start, mock_remote_stop):
        nodes = ["node1", "node2"]
        node_addrs_list = NodeAddressesList(
            [NodeAddresses(addr) for addr in nodes]
        )

        lib.qdevice_reload_on_nodes(
            self.mock_communicator,
            self.mock_reporter,
            node_addrs_list
        )

        node_calls = [
            mock.call(
                self.mock_reporter, self.mock_communicator, node_addrs_list[0]
            ),
            mock.call(
                self.mock_reporter, self.mock_communicator, node_addrs_list[1]
            ),
        ]
        self.assertEqual(len(node_calls), len(mock_remote_stop.mock_calls))
        self.assertEqual(len(node_calls), len(mock_remote_start.mock_calls))
        mock_remote_stop.assert_has_calls(node_calls, any_order=True)
        mock_remote_start.assert_has_calls(node_calls, any_order=True)

        assert_report_item_list_equal(
            self.mock_reporter.report_item_list,
            [
                (
                    severity.INFO,
                    report_codes.QDEVICE_CLIENT_RELOAD_STARTED,
                    {}
                ),
            ]
        )
Beispiel #3
0
 def push_corosync_conf(
     self, corosync_conf_facade, skip_offline_nodes=False
 ):
     corosync_conf_data = corosync_conf_facade.config.export()
     if self.is_corosync_conf_live:
         node_list = corosync_conf_facade.get_nodes()
         if corosync_conf_facade.need_stopped_cluster:
             check_corosync_offline_on_nodes(
                 self.node_communicator(),
                 self.report_processor,
                 node_list,
                 skip_offline_nodes
             )
         distribute_corosync_conf(
             self.node_communicator(),
             self.report_processor,
             node_list,
             corosync_conf_data,
             skip_offline_nodes
         )
         if is_service_running(self.cmd_runner(), "corosync"):
             reload_corosync_config(self.cmd_runner())
             self.report_processor.process(
                 reports.corosync_config_reloaded()
             )
         if corosync_conf_facade.need_qdevice_reload:
             qdevice_reload_on_nodes(
                 self.node_communicator(),
                 self.report_processor,
                 node_list,
                 skip_offline_nodes
             )
     else:
         self._corosync_conf_data = corosync_conf_data
Beispiel #4
0
    def test_fail_doesnt_prevent_start(self, mock_remote_start,
                                       mock_remote_stop):
        nodes = ["node1", "node2"]
        node_addrs_list = NodeAddressesList(
            [NodeAddresses(addr) for addr in nodes])

        def raiser(reporter, communicator, node):
            if node.ring0 == nodes[1]:
                raise NodeAuthenticationException(node.label, "command",
                                                  "HTTP error: 401")

        mock_remote_stop.side_effect = raiser

        assert_raise_library_error(
            lambda: lib.qdevice_reload_on_nodes(
                self.mock_communicator, self.mock_reporter, node_addrs_list),
            (severity.ERROR,
             report_codes.NODE_COMMUNICATION_ERROR_NOT_AUTHORIZED, {
                 "node": nodes[1],
                 "command": "command",
                 "reason": "HTTP error: 401",
             }, report_codes.SKIP_OFFLINE_NODES))

        node_calls = [
            mock.call(self.mock_reporter, self.mock_communicator,
                      node_addrs_list[0]),
            mock.call(self.mock_reporter, self.mock_communicator,
                      node_addrs_list[1]),
        ]
        self.assertEqual(len(node_calls), len(mock_remote_stop.mock_calls))
        self.assertEqual(len(node_calls), len(mock_remote_start.mock_calls))
        mock_remote_stop.assert_has_calls(node_calls, any_order=True)
        mock_remote_start.assert_has_calls(node_calls, any_order=True)

        assert_report_item_list_equal(
            self.mock_reporter.report_item_list,
            [
                (severity.INFO, report_codes.QDEVICE_CLIENT_RELOAD_STARTED,
                 {}),
                # why the same error twice?
                # 1. Tested piece of code calls a function which puts an error
                # into the reporter. The reporter raises an exception. The
                # exception is caught in the tested piece of code, stored, and
                # later put to reporter again.
                # 2. Mock reporter remembers everything that goes through it
                # and by the machanism described in 1 the error goes througt it
                # twice.
                (severity.ERROR,
                 report_codes.NODE_COMMUNICATION_ERROR_NOT_AUTHORIZED, {
                     "node": nodes[1],
                     "command": "command",
                     "reason": "HTTP error: 401",
                 }, report_codes.SKIP_OFFLINE_NODES),
                (severity.ERROR,
                 report_codes.NODE_COMMUNICATION_ERROR_NOT_AUTHORIZED, {
                     "node": nodes[1],
                     "command": "command",
                     "reason": "HTTP error: 401",
                 }, report_codes.SKIP_OFFLINE_NODES),
            ])
Beispiel #5
0
    def test_fail_doesnt_prevent_start(self, mock_remote_start, mock_remote_stop):
        nodes = ["node1", "node2"]
        node_addrs_list = NodeAddressesList([NodeAddresses(addr) for addr in nodes])

        def raiser(reporter, communicator, node):
            if node.ring0 == nodes[1]:
                raise NodeAuthenticationException(node.label, "command", "HTTP error: 401")

        mock_remote_stop.side_effect = raiser

        assert_raise_library_error(
            lambda: lib.qdevice_reload_on_nodes(self.mock_communicator, self.mock_reporter, node_addrs_list),
            (
                severity.ERROR,
                report_codes.NODE_COMMUNICATION_ERROR_NOT_AUTHORIZED,
                {"node": nodes[1], "command": "command", "reason": "HTTP error: 401"},
                report_codes.SKIP_OFFLINE_NODES,
            ),
        )

        node_calls = [
            mock.call(self.mock_reporter, self.mock_communicator, node_addrs_list[0]),
            mock.call(self.mock_reporter, self.mock_communicator, node_addrs_list[1]),
        ]
        self.assertEqual(len(node_calls), len(mock_remote_stop.mock_calls))
        self.assertEqual(len(node_calls), len(mock_remote_start.mock_calls))
        mock_remote_stop.assert_has_calls(node_calls, any_order=True)
        mock_remote_start.assert_has_calls(node_calls, any_order=True)

        assert_report_item_list_equal(
            self.mock_reporter.report_item_list,
            [
                (severity.INFO, report_codes.QDEVICE_CLIENT_RELOAD_STARTED, {}),
                # why the same error twice?
                # 1. Tested piece of code calls a function which puts an error
                # into the reporter. The reporter raises an exception. The
                # exception is caught in the tested piece of code, stored, and
                # later put to reporter again.
                # 2. Mock reporter remembers everything that goes through it
                # and by the machanism described in 1 the error goes througt it
                # twice.
                (
                    severity.ERROR,
                    report_codes.NODE_COMMUNICATION_ERROR_NOT_AUTHORIZED,
                    {"node": nodes[1], "command": "command", "reason": "HTTP error: 401"},
                    report_codes.SKIP_OFFLINE_NODES,
                ),
                (
                    severity.ERROR,
                    report_codes.NODE_COMMUNICATION_ERROR_NOT_AUTHORIZED,
                    {"node": nodes[1], "command": "command", "reason": "HTTP error: 401"},
                    report_codes.SKIP_OFFLINE_NODES,
                ),
            ],
        )
Beispiel #6
0
    def test_success(self, mock_remote_start, mock_remote_stop):
        nodes = ["node1", "node2"]
        node_addrs_list = NodeAddressesList(
            [NodeAddresses(addr) for addr in nodes])

        lib.qdevice_reload_on_nodes(self.mock_communicator, self.mock_reporter,
                                    node_addrs_list)

        node_calls = [
            mock.call(self.mock_reporter, self.mock_communicator,
                      node_addrs_list[0]),
            mock.call(self.mock_reporter, self.mock_communicator,
                      node_addrs_list[1]),
        ]
        self.assertEqual(len(node_calls), len(mock_remote_stop.mock_calls))
        self.assertEqual(len(node_calls), len(mock_remote_start.mock_calls))
        mock_remote_stop.assert_has_calls(node_calls, any_order=True)
        mock_remote_start.assert_has_calls(node_calls, any_order=True)

        assert_report_item_list_equal(self.mock_reporter.report_item_list, [
            (severity.INFO, report_codes.QDEVICE_CLIENT_RELOAD_STARTED, {}),
        ])