def test_watchdog_does_not_exist_and_sbd_not_installed( self, mock_check_sbd ): mock_check_sbd.return_value = json.dumps({ "sbd": { "installed": False }, "watchdog": { "exist": False } }) assert_raise_library_error( lambda: lib_sbd.check_sbd_on_node( self.mock_rep, self.mock_com, self.node, "watchdog" ), ( Severities.ERROR, report_codes.WATCHDOG_NOT_FOUND, {"node": self.node.label} ), ( Severities.ERROR, report_codes.SBD_NOT_INSTALLED, {"node": self.node.label} ) ) mock_check_sbd.assert_called_once_with( self.mock_com, self.node, "watchdog" ) self.assertEqual(0, len(self.mock_rep.report_item_list))
def test_watchdog_does_not_exist_and_sbd_not_installed( self, mock_check_sbd ): mock_check_sbd.return_value = json.dumps({ "sbd": { "installed": False }, "watchdog": { "exist": False } }) assert_raise_library_error( lambda: lib_sbd.check_sbd_on_node( self.mock_rep, self.mock_com, self.node, "watchdog", self.device_list ), ( Severities.ERROR, report_codes.WATCHDOG_NOT_FOUND, {"node": self.node.label} ), ( Severities.ERROR, report_codes.SBD_NOT_INSTALLED, {"node": self.node.label} ) ) mock_check_sbd.assert_called_once_with( self.mock_com, self.node, "watchdog", self.device_list ) self.assertEqual(0, len(self.mock_rep.report_item_list))
def test_devices_issues(self, mock_check_sbd): mock_check_sbd.return_value = json.dumps({ "sbd": { "installed": True }, "watchdog": { "exist": True }, "device_list": [{ "path": "/dev/sdb", "exist": True, "block_device": False, }, { "path": "/dev/sdc", "exist": False, "block_device": False, }] }) assert_raise_library_error( lambda: lib_sbd.check_sbd_on_node(self.mock_rep, self.mock_com, self.node, "watchdog", self. device_list), (Severities.ERROR, report_codes.SBD_DEVICE_DOES_NOT_EXIST, { "device": "/dev/sdc", "node": self.node.label, }), (Severities.ERROR, report_codes.SBD_DEVICE_IS_NOT_BLOCK_DEVICE, { "device": "/dev/sdb", "node": self.node.label, })) mock_check_sbd.assert_called_once_with(self.mock_com, self.node, "watchdog", self.device_list) self.assertEqual(0, len(self.mock_rep.report_item_list))
def test_unable_to_connect(self, mock_check_sbd): mock_check_sbd.side_effect = NodeConnectionException( self.node.label, "command", "reason") self.assertRaises( NodeCommunicationException, lambda: lib_sbd.check_sbd_on_node( self.mock_rep, self.mock_com, self.node, "watchdog")) mock_check_sbd.assert_called_once_with(self.mock_com, self.node, "watchdog") self.assertEqual(0, len(self.mock_rep.report_item_list))
def test_success(self, mock_check_sbd): mock_check_sbd.return_value = json.dumps({ "sbd": { "installed": True }, "watchdog": { "exist": True } }) # if no exception was raised, it's fine lib_sbd.check_sbd_on_node(self.mock_rep, self.mock_com, self.node, "watchdog") mock_check_sbd.assert_called_once_with(self.mock_com, self.node, "watchdog") assert_report_item_list_equal( self.mock_rep.report_item_list, [(Severities.INFO, report_codes.SBD_CHECK_SUCCESS, { "node": self.node.label })])
def test_data_parsing_error(self, mock_check_sbd): mock_check_sbd.return_value = "invalid JSON" assert_raise_library_error( lambda: lib_sbd.check_sbd_on_node(self.mock_rep, self.mock_com, self.node, "watchdog"), (Severities.ERROR, report_codes.INVALID_RESPONSE_FORMAT, { "node": self.node.label })) mock_check_sbd.assert_called_once_with(self.mock_com, self.node, "watchdog") self.assertEqual(0, len(self.mock_rep.report_item_list))
def test_unable_to_connect(self, mock_check_sbd): mock_check_sbd.side_effect = NodeConnectionException( self.node.label, "command", "reason" ) self.assertRaises( NodeCommunicationException, lambda: lib_sbd.check_sbd_on_node( self.mock_rep, self.mock_com, self.node, "watchdog" ) ) mock_check_sbd.assert_called_once_with( self.mock_com, self.node, "watchdog" ) self.assertEqual(0, len(self.mock_rep.report_item_list))
def test_success(self, mock_check_sbd): mock_check_sbd.return_value = json.dumps({ "sbd": { "installed": True }, "watchdog": { "exist": True } }) # if no exception was raised, it's fine lib_sbd.check_sbd_on_node( self.mock_rep, self.mock_com, self.node, "watchdog" ) mock_check_sbd.assert_called_once_with( self.mock_com, self.node, "watchdog" ) assert_report_item_list_equal( self.mock_rep.report_item_list, [( Severities.INFO, report_codes.SBD_CHECK_SUCCESS, {"node": self.node.label} )] )
def test_data_parsing_error(self, mock_check_sbd): mock_check_sbd.return_value = "invalid JSON" assert_raise_library_error( lambda: lib_sbd.check_sbd_on_node( self.mock_rep, self.mock_com, self.node, "watchdog" ), ( Severities.ERROR, report_codes.INVALID_RESPONSE_FORMAT, {"node": self.node.label} ) ) mock_check_sbd.assert_called_once_with( self.mock_com, self.node, "watchdog" ) self.assertEqual(0, len(self.mock_rep.report_item_list))
def test_invalid_response_format(self, mock_check_sbd): mock_check_sbd.return_value = json.dumps({ "not_sbd": { "installed": False }, "watchdog": { "exist": False } }) assert_raise_library_error( lambda: lib_sbd.check_sbd_on_node(self.mock_rep, self.mock_com, self.node, "watchdog"), (Severities.ERROR, report_codes.INVALID_RESPONSE_FORMAT, { "node": self.node.label })) mock_check_sbd.assert_called_once_with(self.mock_com, self.node, "watchdog") self.assertEqual(0, len(self.mock_rep.report_item_list))
def test_invalid_response_format(self, mock_check_sbd): mock_check_sbd.return_value = json.dumps({ "not_sbd": { "installed": False }, "watchdog": { "exist": False } }) assert_raise_library_error( lambda: lib_sbd.check_sbd_on_node( self.mock_rep, self.mock_com, self.node, "watchdog" ), ( Severities.ERROR, report_codes.INVALID_RESPONSE_FORMAT, {"node": self.node.label} ) ) mock_check_sbd.assert_called_once_with( self.mock_com, self.node, "watchdog" ) self.assertEqual(0, len(self.mock_rep.report_item_list))