mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
parent
b3290f12d2
commit
4d8f9dd777
@ -59,6 +59,8 @@ config = {
|
||||
# Note: this section supports all the Gunicorn settings:
|
||||
# - http://docs.gunicorn.org/en/stable/settings.html
|
||||
'bind': os.environ.get('BIGCHAINDB_SERVER_BIND') or 'localhost:9984',
|
||||
'loglevel': logging.getLevelName(
|
||||
log_config['handlers']['console']['level']).lower(),
|
||||
'workers': None, # if none, the value will be cpu_count * 2 + 1
|
||||
'threads': None, # if none, the value will be cpu_count * 2 + 1
|
||||
},
|
||||
@ -86,6 +88,7 @@ config = {
|
||||
'datefmt_logfile': log_config['formatters']['file']['datefmt'],
|
||||
'fmt_console': log_config['formatters']['console']['format'],
|
||||
'fmt_logfile': log_config['formatters']['file']['format'],
|
||||
'granular_levels': {},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,13 @@ def test_bigchain_run_start_with_rethinkdb(mock_start_rethinkdb,
|
||||
mock_processes_start,
|
||||
mock_db_init_with_existing_db,
|
||||
mocked_setup_logging):
|
||||
from bigchaindb import config
|
||||
from bigchaindb.commands.bigchaindb import run_start
|
||||
args = Namespace(start_rethinkdb=True, allow_temp_keypair=False, config=None, yes=True)
|
||||
run_start(args)
|
||||
|
||||
mock_start_rethinkdb.assert_called_with()
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config={})
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config=config['log'])
|
||||
|
||||
|
||||
@patch('subprocess.Popen')
|
||||
|
@ -37,10 +37,11 @@ def test_bigchain_run_start(mock_run_configure,
|
||||
mock_processes_start,
|
||||
mock_db_init_with_existing_db,
|
||||
mocked_setup_logging):
|
||||
from bigchaindb import config
|
||||
from bigchaindb.commands.bigchaindb import run_start
|
||||
args = Namespace(start_rethinkdb=False, allow_temp_keypair=False, config=None, yes=True)
|
||||
run_start(args)
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config={})
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config=config['log'])
|
||||
|
||||
|
||||
@pytest.mark.skipif(reason="BigchainDB doesn't support the automatic creation of a config file anymore")
|
||||
@ -288,7 +289,8 @@ def test_allow_temp_keypair_generates_one_on_the_fly(
|
||||
args = Namespace(allow_temp_keypair=True, start_rethinkdb=False, config=None, yes=True)
|
||||
run_start(args)
|
||||
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config={})
|
||||
mocked_setup_logging.assert_called_once_with(
|
||||
user_log_config=bigchaindb.config['log'])
|
||||
assert bigchaindb.config['keypair']['private'] == 'private_key'
|
||||
assert bigchaindb.config['keypair']['public'] == 'public_key'
|
||||
|
||||
@ -313,7 +315,8 @@ def test_allow_temp_keypair_doesnt_override_if_keypair_found(mock_gen_keypair,
|
||||
args = Namespace(allow_temp_keypair=True, start_rethinkdb=False, config=None, yes=True)
|
||||
run_start(args)
|
||||
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config={})
|
||||
mocked_setup_logging.assert_called_once_with(
|
||||
user_log_config=bigchaindb.config['log'])
|
||||
assert bigchaindb.config['keypair']['private'] == original_private_key
|
||||
assert bigchaindb.config['keypair']['public'] == original_public_key
|
||||
|
||||
@ -322,6 +325,7 @@ def test_run_start_when_db_already_exists(mocker,
|
||||
monkeypatch,
|
||||
run_start_args,
|
||||
mocked_setup_logging):
|
||||
from bigchaindb import config
|
||||
from bigchaindb.commands.bigchaindb import run_start
|
||||
from bigchaindb.common.exceptions import DatabaseAlreadyExists
|
||||
mocked_start = mocker.patch('bigchaindb.processes.start')
|
||||
@ -332,7 +336,7 @@ def test_run_start_when_db_already_exists(mocker,
|
||||
monkeypatch.setattr(
|
||||
'bigchaindb.commands.bigchaindb._run_init', mock_run_init)
|
||||
run_start(run_start_args)
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config={})
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config=config['log'])
|
||||
assert mocked_start.called
|
||||
|
||||
|
||||
@ -340,6 +344,7 @@ def test_run_start_when_keypair_not_found(mocker,
|
||||
monkeypatch,
|
||||
run_start_args,
|
||||
mocked_setup_logging):
|
||||
from bigchaindb import config
|
||||
from bigchaindb.commands.bigchaindb import run_start
|
||||
from bigchaindb.commands.messages import CANNOT_START_KEYPAIR_NOT_FOUND
|
||||
from bigchaindb.common.exceptions import KeypairNotFoundException
|
||||
@ -354,7 +359,7 @@ def test_run_start_when_keypair_not_found(mocker,
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
run_start(run_start_args)
|
||||
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config={})
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config=config['log'])
|
||||
assert len(exc.value.args) == 1
|
||||
assert exc.value.args[0] == CANNOT_START_KEYPAIR_NOT_FOUND
|
||||
assert not mocked_start.called
|
||||
@ -364,6 +369,7 @@ def test_run_start_when_start_rethinkdb_fails(mocker,
|
||||
monkeypatch,
|
||||
run_start_args,
|
||||
mocked_setup_logging):
|
||||
from bigchaindb import config
|
||||
from bigchaindb.commands.bigchaindb import run_start
|
||||
from bigchaindb.commands.messages import RETHINKDB_STARTUP_ERROR
|
||||
from bigchaindb.common.exceptions import StartupError
|
||||
@ -380,7 +386,7 @@ def test_run_start_when_start_rethinkdb_fails(mocker,
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
run_start(run_start_args)
|
||||
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config={})
|
||||
mocked_setup_logging.assert_called_once_with(user_log_config=config['log'])
|
||||
assert len(exc.value.args) == 1
|
||||
assert exc.value.args[0] == RETHINKDB_STARTUP_ERROR.format(err_msg)
|
||||
assert not mocked_start.called
|
||||
|
@ -57,17 +57,16 @@ def test_configure_bigchaindb_configures_bigchaindb():
|
||||
@pytest.mark.usefixtures('ignore_local_config_file',
|
||||
'reset_bigchaindb_config',
|
||||
'reset_logging_config')
|
||||
@pytest.mark.parametrize('log_level', (
|
||||
logging.DEBUG,
|
||||
logging.INFO,
|
||||
logging.WARNING,
|
||||
logging.ERROR,
|
||||
logging.CRITICAL,
|
||||
))
|
||||
@pytest.mark.parametrize('log_level', tuple(map(
|
||||
logging.getLevelName,
|
||||
(logging.DEBUG,
|
||||
logging.INFO,
|
||||
logging.WARNING,
|
||||
logging.ERROR,
|
||||
logging.CRITICAL)
|
||||
)))
|
||||
def test_configure_bigchaindb_logging(log_level):
|
||||
from bigchaindb.commands.utils import configure_bigchaindb
|
||||
from bigchaindb import config
|
||||
assert not config['log']
|
||||
|
||||
@configure_bigchaindb
|
||||
def test_configure_logger(args):
|
||||
|
@ -1,4 +1,5 @@
|
||||
import copy
|
||||
import logging
|
||||
from unittest.mock import mock_open, patch
|
||||
|
||||
import pytest
|
||||
@ -147,12 +148,16 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
|
||||
WSSERVER_HOST = '1.2.3.4'
|
||||
WSSERVER_PORT = 57
|
||||
KEYRING = 'pubkey_0:pubkey_1:pubkey_2'
|
||||
LOG_FILE = '/somewhere/something.log'
|
||||
|
||||
file_config = {
|
||||
'database': {
|
||||
'host': DATABASE_HOST
|
||||
},
|
||||
'backlog_reassign_delay': 5
|
||||
'backlog_reassign_delay': 5,
|
||||
'log': {
|
||||
'level_console': 'debug',
|
||||
},
|
||||
}
|
||||
monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config)
|
||||
monkeypatch.setattr('os.environ', {'BIGCHAINDB_DATABASE_NAME': DATABASE_NAME,
|
||||
@ -161,10 +166,12 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
|
||||
'BIGCHAINDB_SERVER_BIND': SERVER_BIND,
|
||||
'BIGCHAINDB_WSSERVER_HOST': WSSERVER_HOST,
|
||||
'BIGCHAINDB_WSSERVER_PORT': WSSERVER_PORT,
|
||||
'BIGCHAINDB_KEYRING': KEYRING})
|
||||
'BIGCHAINDB_KEYRING': KEYRING,
|
||||
'BIGCHAINDB_LOG_FILE': LOG_FILE})
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb import config_utils
|
||||
from bigchaindb.log.configs import SUBSCRIBER_LOGGING_CONFIG as log_config
|
||||
config_utils.autoconfigure()
|
||||
|
||||
database_rethinkdb = {
|
||||
@ -199,6 +206,8 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
|
||||
'CONFIGURED': True,
|
||||
'server': {
|
||||
'bind': SERVER_BIND,
|
||||
'loglevel': logging.getLevelName(
|
||||
log_config['handlers']['console']['level']).lower(),
|
||||
'workers': None,
|
||||
'threads': None,
|
||||
},
|
||||
@ -213,7 +222,18 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
|
||||
},
|
||||
'keyring': KEYRING.split(':'),
|
||||
'backlog_reassign_delay': 5,
|
||||
'log': {},
|
||||
'log': {
|
||||
'file': LOG_FILE,
|
||||
'error_file': log_config['handlers']['errors']['filename'],
|
||||
'level_console': 'debug',
|
||||
'level_logfile': logging.getLevelName(
|
||||
log_config['handlers']['file']['level']),
|
||||
'datefmt_console': log_config['formatters']['console']['datefmt'],
|
||||
'datefmt_logfile': log_config['formatters']['file']['datefmt'],
|
||||
'fmt_console': log_config['formatters']['console']['format'],
|
||||
'fmt_logfile': log_config['formatters']['file']['format'],
|
||||
'granular_levels': {},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user