def run_add_replicas(args): # Note: This command is specific to MongoDB conn = backend.connect() try: add_replicas(conn, args.replicas) except (OperationError, NotImplementedError) as e: sys.exit(str(e)) else: print('Added {} to the replicaset.'.format(args.replicas))
def test_add_replicas_raises(mock_replicaset_config, connection): from bigchaindb.backend.admin import add_replicas from bigchaindb.backend.exceptions import OperationError with mock.patch.object(Database, 'command') as mock_command: mock_command.side_effect = [ mock_replicaset_config, OperationFailure(error=1, details={'errmsg': ''}) ] with pytest.raises(OperationError): add_replicas(connection, ['localhost:27018'])
def run_add_replicas(args): # Note: This command is specific to MongoDB bigchaindb.config_utils.autoconfigure(filename=args.config, force=True) conn = backend.connect() try: add_replicas(conn, args.replicas) except (OperationError, NotImplementedError) as e: logger.warn(e) else: logger.info('Added {} to the replicaset.'.format(args.replicas))
def test_add_replicas(mock_replicaset_config, connection): from bigchaindb.backend.admin import add_replicas expected_config = copy.deepcopy(mock_replicaset_config) expected_config['config']['members'] += [{ '_id': 1, 'host': 'localhost:27018' }, { '_id': 2, 'host': 'localhost:27019' }] expected_config['config']['version'] += 1 with mock.patch.object(Database, 'command') as mock_command: mock_command.return_value = mock_replicaset_config add_replicas(connection, ['localhost:27018', 'localhost:27019']) mock_command.assert_called_with('replSetReconfig', expected_config['config'])