Example #1
0
def run_remove_replicas(args):
    # Note: This command is specific to MongoDB
    conn = backend.connect()

    try:
        remove_replicas(conn, args.replicas)
    except (OperationError, NotImplementedError) as e:
        sys.exit(str(e))
    else:
        print('Removed {} from the replicaset.'.format(args.replicas))
Example #2
0
def run_remove_replicas(args):
    # Note: This command is specific to MongoDB
    conn = backend.connect()

    try:
        remove_replicas(conn, args.replicas)
    except (OperationError, NotImplementedError) as e:
        sys.exit(str(e))
    else:
        print('Removed {} from the replicaset.'.format(args.replicas))
Example #3
0
def test_remove_replicas_raises(mock_replicaset_config, connection):
    from bigchaindb.backend.admin import remove_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):
            remove_replicas(connection, ['localhost:27018'])
Example #4
0
def run_remove_replicas(args):
    # Note: This command is specific to MongoDB
    bigchaindb.config_utils.autoconfigure(filename=args.config, force=True)
    conn = backend.connect()

    try:
        remove_replicas(conn, args.replicas)
    except (OperationError, NotImplementedError) as e:
        logger.warn(e)
    else:
        logger.info('Removed {} from the replicaset.'.format(args.replicas))
Example #5
0
def test_remove_replicas(mock_replicaset_config, connection):
    from bigchaindb.backend.admin import remove_replicas

    expected_config = copy.deepcopy(mock_replicaset_config)
    expected_config['config']['version'] += 1

    # add some hosts to the configuration to remove
    mock_replicaset_config['config']['members'] += [{
        '_id': 1,
        'host': 'localhost:27018'
    }, {
        '_id': 2,
        'host': 'localhost:27019'
    }]

    with mock.patch.object(Database, 'command') as mock_command:
        mock_command.return_value = mock_replicaset_config
        remove_replicas(connection, ['localhost:27018', 'localhost:27019'])

    mock_command.assert_called_with('replSetReconfig',
                                    expected_config['config'])