mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Make some improvements to command line messages and error handling
This commit is contained in:
parent
edc5887b42
commit
2e398f606f
@ -126,7 +126,6 @@ def run_configure(args, skip_if_exists=False):
|
|||||||
def run_export_my_pubkey(args):
|
def run_export_my_pubkey(args):
|
||||||
"""Export this node's public key to standard output
|
"""Export this node's public key to standard output
|
||||||
"""
|
"""
|
||||||
print('bigchaindb args = {}'.format(args))
|
|
||||||
bigchaindb.config_utils.autoconfigure(filename=args.config, force=True)
|
bigchaindb.config_utils.autoconfigure(filename=args.config, force=True)
|
||||||
pubkey = bigchaindb.config['keypair']['public']
|
pubkey = bigchaindb.config['keypair']['public']
|
||||||
if pubkey is not None:
|
if pubkey is not None:
|
||||||
@ -145,9 +144,8 @@ def _run_init():
|
|||||||
|
|
||||||
schema.init_database(connection=b.connection)
|
schema.init_database(connection=b.connection)
|
||||||
|
|
||||||
print('Create genesis block.')
|
|
||||||
b.create_genesis_block()
|
b.create_genesis_block()
|
||||||
print('Done, have fun!')
|
logger.info('Genesis block created.')
|
||||||
|
|
||||||
|
|
||||||
def run_init(args):
|
def run_init(args):
|
||||||
@ -180,7 +178,7 @@ def run_drop(args):
|
|||||||
|
|
||||||
def run_start(args):
|
def run_start(args):
|
||||||
"""Start the processes to run the node"""
|
"""Start the processes to run the node"""
|
||||||
print('BigchainDB Version {}'.format(bigchaindb.__version__))
|
logger.info('BigchainDB Version %s', bigchaindb.__version__)
|
||||||
bigchaindb.config_utils.autoconfigure(filename=args.config, force=True)
|
bigchaindb.config_utils.autoconfigure(filename=args.config, force=True)
|
||||||
|
|
||||||
if args.allow_temp_keypair:
|
if args.allow_temp_keypair:
|
||||||
@ -231,7 +229,7 @@ def _run_load(tx_left, stats):
|
|||||||
|
|
||||||
def run_load(args):
|
def run_load(args):
|
||||||
bigchaindb.config_utils.autoconfigure(filename=args.config, force=True)
|
bigchaindb.config_utils.autoconfigure(filename=args.config, force=True)
|
||||||
print('Starting %s processes', args.multiprocess)
|
logger.info('Starting %s processes', args.multiprocess)
|
||||||
stats = logstats.Logstats()
|
stats = logstats.Logstats()
|
||||||
logstats.thread.start(stats)
|
logstats.thread.start(stats)
|
||||||
|
|
||||||
@ -250,7 +248,7 @@ def run_set_shards(args):
|
|||||||
try:
|
try:
|
||||||
set_shards(conn, shards=args.num_shards)
|
set_shards(conn, shards=args.num_shards)
|
||||||
except OperationError as e:
|
except OperationError as e:
|
||||||
print(e)
|
sys.exit(str(e))
|
||||||
|
|
||||||
|
|
||||||
def run_set_replicas(args):
|
def run_set_replicas(args):
|
||||||
@ -258,7 +256,7 @@ def run_set_replicas(args):
|
|||||||
try:
|
try:
|
||||||
set_replicas(conn, replicas=args.num_replicas)
|
set_replicas(conn, replicas=args.num_replicas)
|
||||||
except OperationError as e:
|
except OperationError as e:
|
||||||
print(e)
|
sys.exit(str(e))
|
||||||
|
|
||||||
|
|
||||||
def run_add_replicas(args):
|
def run_add_replicas(args):
|
||||||
@ -269,7 +267,7 @@ def run_add_replicas(args):
|
|||||||
try:
|
try:
|
||||||
add_replicas(conn, args.replicas)
|
add_replicas(conn, args.replicas)
|
||||||
except (OperationError, NotImplementedError) as e:
|
except (OperationError, NotImplementedError) as e:
|
||||||
print(e)
|
sys.exit(str(e))
|
||||||
else:
|
else:
|
||||||
print('Added {} to the replicaset.'.format(args.replicas))
|
print('Added {} to the replicaset.'.format(args.replicas))
|
||||||
|
|
||||||
@ -282,7 +280,7 @@ def run_remove_replicas(args):
|
|||||||
try:
|
try:
|
||||||
remove_replicas(conn, args.replicas)
|
remove_replicas(conn, args.replicas)
|
||||||
except (OperationError, NotImplementedError) as e:
|
except (OperationError, NotImplementedError) as e:
|
||||||
print(e)
|
sys.exit(str(e))
|
||||||
else:
|
else:
|
||||||
print('Removed {} from the replicaset.'.format(args.replicas))
|
print('Removed {} from the replicaset.'.format(args.replicas))
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ def test_set_shards(mock_reconfigure, monkeypatch, b):
|
|||||||
mock_reconfigure.assert_called_with(replicas=3, shards=3, dry_run=False)
|
mock_reconfigure.assert_called_with(replicas=3, shards=3, dry_run=False)
|
||||||
|
|
||||||
|
|
||||||
def test_set_shards_raises_exception(monkeypatch, b, capsys):
|
def test_set_shards_raises_exception(monkeypatch, b):
|
||||||
from bigchaindb.commands.bigchain import run_set_shards
|
from bigchaindb.commands.bigchain import run_set_shards
|
||||||
|
|
||||||
# test that we are correctly catching the exception
|
# test that we are correctly catching the exception
|
||||||
@ -73,11 +73,9 @@ def test_set_shards_raises_exception(monkeypatch, b, capsys):
|
|||||||
monkeypatch.setattr(rethinkdb.ast.Table, 'reconfigure', mock_raise)
|
monkeypatch.setattr(rethinkdb.ast.Table, 'reconfigure', mock_raise)
|
||||||
|
|
||||||
args = Namespace(num_shards=3)
|
args = Namespace(num_shards=3)
|
||||||
|
with pytest.raises(SystemExit) as exc:
|
||||||
run_set_shards(args)
|
run_set_shards(args)
|
||||||
|
assert exc.value.args == ('Failed to reconfigure tables.',)
|
||||||
out, err = capsys.readouterr()
|
|
||||||
assert out[:-1] == 'Failed to reconfigure tables.'
|
|
||||||
assert not err
|
|
||||||
|
|
||||||
|
|
||||||
@patch('rethinkdb.ast.Table.reconfigure')
|
@patch('rethinkdb.ast.Table.reconfigure')
|
||||||
@ -104,7 +102,7 @@ def test_set_replicas(mock_reconfigure, monkeypatch, b):
|
|||||||
mock_reconfigure.assert_called_with(replicas=2, shards=3, dry_run=False)
|
mock_reconfigure.assert_called_with(replicas=2, shards=3, dry_run=False)
|
||||||
|
|
||||||
|
|
||||||
def test_set_replicas_raises_exception(monkeypatch, b, capsys):
|
def test_set_replicas_raises_exception(monkeypatch, b):
|
||||||
from bigchaindb.commands.bigchain import run_set_replicas
|
from bigchaindb.commands.bigchain import run_set_replicas
|
||||||
|
|
||||||
# test that we are correctly catching the exception
|
# test that we are correctly catching the exception
|
||||||
@ -118,8 +116,6 @@ def test_set_replicas_raises_exception(monkeypatch, b, capsys):
|
|||||||
monkeypatch.setattr(rethinkdb.ast.Table, 'reconfigure', mock_raise)
|
monkeypatch.setattr(rethinkdb.ast.Table, 'reconfigure', mock_raise)
|
||||||
|
|
||||||
args = Namespace(num_replicas=2)
|
args = Namespace(num_replicas=2)
|
||||||
|
with pytest.raises(SystemExit) as exc:
|
||||||
run_set_replicas(args)
|
run_set_replicas(args)
|
||||||
|
assert exc.value.args == ('Failed to reconfigure tables.',)
|
||||||
out, err = capsys.readouterr()
|
|
||||||
assert out[:-1] == 'Failed to reconfigure tables.'
|
|
||||||
assert not err
|
|
||||||
|
@ -135,7 +135,6 @@ def test_bigchain_export_my_pubkey_when_pubkey_set(capsys, monkeypatch):
|
|||||||
lines = out.splitlines()
|
lines = out.splitlines()
|
||||||
assert config['keypair']['public'] in lines
|
assert config['keypair']['public'] in lines
|
||||||
assert 'Charlie_Bucket' in lines
|
assert 'Charlie_Bucket' in lines
|
||||||
assert 'bigchaindb args = {}'.format(args) in lines
|
|
||||||
|
|
||||||
|
|
||||||
def test_bigchain_export_my_pubkey_when_pubkey_not_set(monkeypatch):
|
def test_bigchain_export_my_pubkey_when_pubkey_not_set(monkeypatch):
|
||||||
@ -455,14 +454,18 @@ def test_run_add_replicas(mock_add_replicas):
|
|||||||
mock_add_replicas.reset_mock()
|
mock_add_replicas.reset_mock()
|
||||||
|
|
||||||
# test add_replicas with `OperationError`
|
# test add_replicas with `OperationError`
|
||||||
mock_add_replicas.side_effect = OperationError()
|
mock_add_replicas.side_effect = OperationError('err')
|
||||||
assert run_add_replicas(args) is None
|
with pytest.raises(SystemExit) as exc:
|
||||||
|
run_add_replicas(args)
|
||||||
|
assert exc.value.args == ('err',)
|
||||||
assert mock_add_replicas.call_count == 1
|
assert mock_add_replicas.call_count == 1
|
||||||
mock_add_replicas.reset_mock()
|
mock_add_replicas.reset_mock()
|
||||||
|
|
||||||
# test add_replicas with `NotImplementedError`
|
# test add_replicas with `NotImplementedError`
|
||||||
mock_add_replicas.side_effect = NotImplementedError()
|
mock_add_replicas.side_effect = NotImplementedError('err')
|
||||||
assert run_add_replicas(args) is None
|
with pytest.raises(SystemExit) as exc:
|
||||||
|
run_add_replicas(args)
|
||||||
|
assert exc.value.args == ('err',)
|
||||||
assert mock_add_replicas.call_count == 1
|
assert mock_add_replicas.call_count == 1
|
||||||
mock_add_replicas.reset_mock()
|
mock_add_replicas.reset_mock()
|
||||||
|
|
||||||
@ -482,14 +485,18 @@ def test_run_remove_replicas(mock_remove_replicas):
|
|||||||
mock_remove_replicas.reset_mock()
|
mock_remove_replicas.reset_mock()
|
||||||
|
|
||||||
# test add_replicas with `OperationError`
|
# test add_replicas with `OperationError`
|
||||||
mock_remove_replicas.side_effect = OperationError()
|
mock_remove_replicas.side_effect = OperationError('err')
|
||||||
assert run_remove_replicas(args) is None
|
with pytest.raises(SystemExit) as exc:
|
||||||
|
run_remove_replicas(args)
|
||||||
|
assert exc.value.args == ('err',)
|
||||||
assert mock_remove_replicas.call_count == 1
|
assert mock_remove_replicas.call_count == 1
|
||||||
mock_remove_replicas.reset_mock()
|
mock_remove_replicas.reset_mock()
|
||||||
|
|
||||||
# test add_replicas with `NotImplementedError`
|
# test add_replicas with `NotImplementedError`
|
||||||
mock_remove_replicas.side_effect = NotImplementedError()
|
mock_remove_replicas.side_effect = NotImplementedError('err')
|
||||||
assert run_remove_replicas(args) is None
|
with pytest.raises(SystemExit) as exc:
|
||||||
|
run_remove_replicas(args)
|
||||||
|
assert exc.value.args == ('err',)
|
||||||
assert mock_remove_replicas.call_count == 1
|
assert mock_remove_replicas.call_count == 1
|
||||||
mock_remove_replicas.reset_mock()
|
mock_remove_replicas.reset_mock()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user