Example #1
0
def get_shard_allocation_func(mock_shard_allocation):
    allocations_by_db = {
        allocation['_id']: ShardAllocationDoc.wrap(allocation)
        for allocation in mock_shard_allocation
    }

    def _mock_get_shard_allocation(config, db_name, create=False):
        return allocations_by_db[db_name]

    return _mock_get_shard_allocation
def get_shard_allocation_func(mock_shard_allocation):
    allocations_by_db = {
        allocation['_id']: ShardAllocationDoc.wrap(allocation)
        for allocation in mock_shard_allocation
    }

    def _mock_get_shard_allocation(config, db_name, create=False):
        return allocations_by_db[db_name]

    return _mock_get_shard_allocation
def _generate_plan_and_rsync_lists(migration, plan_name):
    mock_shard_allocation = _get_expected_yml(plan_name, 'mock_shard_allocation.yml')
    mock_func = get_shard_allocation_func(mock_shard_allocation)

    db_info = [
        (allocation['_id'], 10, {'a': 10}, sorted(allocation['by_range']), ShardAllocationDoc.wrap(allocation))
        for allocation in mock_shard_allocation
    ]
    with patch('couchdb_cluster_admin.suggest_shard_allocation.get_db_info', return_value=db_info):
        generate_shard_plan(migration)

    with patch('couchdb_cluster_admin.file_plan.get_shard_allocation', mock_func):
        files_by_host = generate_rsync_lists(migration)
    return files_by_host
Example #4
0
def _generate_plan_and_rsync_lists(migration, plan_name):
    mock_shard_allocation = _get_expected_yml(plan_name, 'mock_shard_allocation.yml')
    mock_func = get_shard_allocation_func(mock_shard_allocation)

    db_info = [
        (allocation['_id'], 10, {'a': 10}, sorted(allocation['by_range']), ShardAllocationDoc.wrap(allocation))
        for allocation in mock_shard_allocation
    ]
    with patch('couchdb_cluster_admin.suggest_shard_allocation.get_db_info', return_value=db_info):
        generate_shard_plan(migration)

    with patch('couchdb_cluster_admin.file_plan.get_shard_allocation', mock_func):
        # this also get's called in generate_rsync_lists but we want the result to test against
        migration_file_configs = get_migration_file_configs(migration)
        generate_rsync_lists(migration)
    return migration_file_configs
def _generate_plan_and_rsync_lists(migration, plan_name):
    mock_shard_allocation = _get_expected_yml(plan_name, 'mock_shard_allocation_pre_migration.yml')
    mock_func = get_shard_allocation_func(mock_shard_allocation)

    db_info = [
        (allocation['_id'], 10, {'a': 10}, sorted(allocation['by_range']), ShardAllocationDoc.wrap(allocation))
        for allocation in mock_shard_allocation
    ]
    with patch('couchdb_cluster_admin.suggest_shard_allocation.get_db_info', return_value=db_info):
        generate_shard_plan(migration)

    with patch('couchdb_cluster_admin.file_plan.get_shard_allocation', mock_func):
        # this also get's called in generate_rsync_lists but we want the result to test against
        migration_file_configs = get_migration_file_configs(migration)
        generate_rsync_lists(migration)
    return migration_file_configs