async def reverse_source_target_datasets(self, source_datasets, target_dataset): if len(source_datasets) == 1: return [target_dataset], source_datasets[0] else: replication_task = SimpleNamespace(source_datasets=source_datasets, target_dataset=target_dataset) return ( [ get_target_dataset(replication_task, source_dataset) for source_dataset in source_datasets ], get_source_dataset_base(replication_task) )
async def target_unmatched_snapshots(self, direction, source_datasets, target_dataset, transport, ssh_credentials): fake_replication_task = types.SimpleNamespace() fake_replication_task.source_datasets = source_datasets fake_replication_task.target_dataset = target_dataset datasets = { source_dataset: get_target_dataset(fake_replication_task, source_dataset) for source_dataset in source_datasets } try: local_shell = LocalShell() async with self._get_zettarepl_shell( transport, ssh_credentials) as remote_shell: if direction == "PUSH": source_shell = local_shell target_shell = remote_shell else: source_shell = remote_shell target_shell = local_shell target_datasets = set(list_datasets(target_shell)) datasets = { source_dataset: target_dataset for source_dataset, target_dataset in datasets.items() if target_dataset in target_datasets } source_snapshots = group_snapshots_by_datasets( await self.middleware.run_in_thread( multilist_snapshots, source_shell, [(dataset, False) for dataset in datasets.keys()])) target_snapshots = group_snapshots_by_datasets( await self.middleware.run_in_thread( multilist_snapshots, target_shell, [(dataset, False) for dataset in datasets.values()])) except Exception as e: raise CallError(repr(e)) errors = {} for source_dataset, target_dataset in datasets.items(): unmatched_snapshots = list( set(target_snapshots.get(target_dataset, [])) - set(source_snapshots.get(source_dataset, []))) if unmatched_snapshots: errors[target_dataset] = unmatched_snapshots return errors
def test__get_target_dataset(source_datasets, target_dataset, src_dataset, result): assert get_target_dataset( Mock(source_datasets=source_datasets, target_dataset=target_dataset), src_dataset) == result