Пример #1
0
    def shard_plan(self):
        with open(self.shard_plan_path) as f:
            plan = yaml.safe_load(f)

        return [
            ShardAllocationDoc.from_plan_json(db_name, plan_json)
            for db_name, plan_json in plan.items()
        ]
Пример #2
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
Пример #5
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
Пример #6
0
def _get_aliased_allocation_docs(migration):
    def convert_to_aliases(nodes):
        return [
            migration.target_couch_config.aliases.get(node, node)
            for node in nodes
        ]

    printable_docs = []
    for doc in migration.shard_plan:
        doc_json = doc.to_plan_json()
        doc_json['by_range'] = {
            shard: convert_to_aliases(by_range)
            for shard, by_range in doc_json['by_range'].items()
        }
        printable_docs.append(ShardAllocationDoc.from_plan_json(doc.db_name, doc_json))
    return printable_docs
Пример #7
0
def _get_aliased_allocation_docs(migration):
    def convert_to_aliases(nodes):
        return [
            migration.target_couch_config.aliases.get(node, node)
            for node in nodes
        ]

    printable_docs = []
    for doc in migration.shard_plan:
        doc_json = doc.to_plan_json()
        doc_json['by_range'] = {
            shard: convert_to_aliases(by_range)
            for shard, by_range in doc_json['by_range'].items()
        }
        printable_docs.append(ShardAllocationDoc.from_plan_json(doc.db_name, doc_json))
    return printable_docs
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