def test_success(self): mock_communicator = mock.MagicMock(spec_set=NodeCommunicator) node = NodeAddresses("node1") lib_sbd.enable_sbd_service(mock_communicator, node) mock_communicator.call_node.assert_called_once_with( node, "remote/sbd_enable", None)
def test_success(self): mock_communicator = mock.MagicMock(spec_set=NodeCommunicator) node = NodeAddresses("node1") lib_sbd.check_sbd(mock_communicator, node, "/dev/watchdog") mock_communicator.call_node.assert_called_once_with( node, "remote/check_sbd", "watchdog=%2Fdev%2Fwatchdog")
def setUp(self): self.mock_com = mock.MagicMock(spec_set=NodeCommunicator) self.mock_rep = MockLibraryReportProcessor() self.node = NodeAddresses("node1")
def test_one_node_down(self, mock_corosync_live): conf_text = "test conf text" nodes = ["node1", "node2"] node_addrs_list = NodeAddressesList( [NodeAddresses(addr) for addr in nodes]) mock_corosync_live.set_remote_corosync_conf = mock.MagicMock() def raiser(comm, node, conf): if node.ring0 == nodes[1]: raise NodeAuthenticationException(nodes[1], "command", "HTTP error: 401") mock_corosync_live.set_remote_corosync_conf.side_effect = raiser assert_raise_library_error( lambda: lib.distribute_corosync_conf( self.mock_communicator, self.mock_reporter, node_addrs_list, conf_text), (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.COROSYNC_CONFIG_DISTRIBUTION_NODE_ERROR, { "node": nodes[1], }, report_codes.SKIP_OFFLINE_NODES)) corosync_live_calls = [ mock.call.set_remote_corosync_conf("mock node communicator", nodes[0], conf_text), mock.call.set_remote_corosync_conf("mock node communicator", nodes[1], conf_text), ] self.assertEqual(len(corosync_live_calls), len(mock_corosync_live.mock_calls)) mock_corosync_live.set_remote_corosync_conf.assert_has_calls( [ mock.call("mock node communicator", node_addrs_list[0], conf_text), mock.call("mock node communicator", node_addrs_list[1], conf_text), ], any_order=True) assert_report_item_list_equal( self.mock_reporter.report_item_list, [(severity.INFO, report_codes.COROSYNC_CONFIG_DISTRIBUTION_STARTED, {}), (severity.INFO, report_codes.COROSYNC_CONFIG_ACCEPTED_BY_NODE, { "node": nodes[0] }), (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.COROSYNC_CONFIG_DISTRIBUTION_NODE_ERROR, { "node": nodes[1], }, report_codes.SKIP_OFFLINE_NODES)])
def setUp(self): self.node_list = NodeAddressesList( [NodeAddresses("node" + str(i)) for i in range(5)])
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_start.side_effect = raiser assert_raise_library_error( lambda: lib.qdevice_reload_on_nodes( self.mock_communicator, self.mock_reporter, node_addrs_list), # 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)) 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), ])
def test_success(self): mock_communicator = mock.MagicMock(spec_set=NodeCommunicator) node = NodeAddresses("node1") lib.node_check_auth(mock_communicator, node) mock_communicator.call_node.assert_called_once_with( node, "remote/check_auth", "check_auth_only=1")
def test_all_ok(self): watchdog_dict = { NodeAddresses("node1"): "/dev/watchdog1", NodeAddresses("node2"): "/dev/watchdog2", } self.assertEqual([], cmd_sbd._validate_watchdog_dict(watchdog_dict))
def setUp(self): self.node_list = NodeAddressesList([ NodeAddresses("node1"), NodeAddresses("node2"), NodeAddresses("node3"), ])
def setUp(self): self.mock_communicator = mock.MagicMock(spec_set=NodeCommunicator) self.mock_reporter = MockLibraryReportProcessor() self.node_list = NodeAddressesList( [NodeAddresses("node" + str(i) for i in range(5))])
def setUp(self): self.mock_communicator = mock.MagicMock(spec_set=NodeCommunicator) self.node = NodeAddresses("node")
def validate(self, options, name="some_name"): return guest_node.validate_set_as_guest(etree.fromstring('<cib/>'), [ NodeAddresses("EXISTING-HOST-RING0", "EXISTING-HOST-RING0", name="EXISTING-HOST-NAME") ], name, options)
def setUp(self): self.mock_com = mock.MagicMock(spec_set=NodeCommunicator) self.node_list = [NodeAddresses("node" + str(i)) for i in range(5)]
def setUp(self): self.mock_com = mock.MagicMock(spec_set=NodeCommunicator) self.mock_rep = MockLibraryReportProcessor() self.node = NodeAddresses("node1") self.device_list = ["/dev/sdb1", "/dev/sdc"]
def test_ring0(self): ring0 = "ring0" target = lib.RequestTarget.from_node_addresses(NodeAddresses(ring0)) self.assertEqual(ring0, target.label) self.assertEqual([ring0], target.address_list)
def test_success(self): mock_communicator = mock.MagicMock(spec_set=NodeCommunicator) node = NodeAddresses("node1") lib_sbd.remove_stonith_watchdog_timeout(mock_communicator, node) mock_communicator.call_node.assert_called_once_with( node, "remote/remove_stonith_watchdog_timeout", None)