Example #1
0
    def resume_replications_mock(*args, **kwargs):
        nonlocal deleted
        if not deleted:
            # Snapshots are already listed, and now we remove one of them to simulate PULL replication
            # from remote system that has `allow_empty_snapshots: false`. Only do this once.
            subprocess.check_call("zfs destroy data/src@2018-10-01_01-00",
                                  shell=True)
            deleted = True

        return resume_replications(*args, **kwargs)
Example #2
0
def test__resume_replications__no_resume():
    dst_context = Mock(datasets=["data/dst", "data/dst/work"])
    dst = Mock(dst_context=dst_context, dst_dataset="data/dst")
    dst_work = Mock(dst_context=dst_context, dst_dataset="data/dst/work")
    dst_zzzz = Mock(dst_context=dst_context, dst_dataset="data/dst/zzzz")
    with patch("zettarepl.replication.run.get_receive_resume_token") as get_receive_resume_token:
        get_receive_resume_token.return_value = None
        with patch("zettarepl.replication.run.run_replication_step") as run_replication_step:
            result = resume_replications([dst, dst_work, dst_zzzz])

            run_replication_step.assert_not_called()

            assert result is False
Example #3
0
def test__resume_replications__resume():
    dst_context = Mock(datasets=["data/dst", "data/dst/work"])
    dst = Mock(dst_context=dst_context, dst_dataset="data/dst")
    dst_work = Mock(dst_context=dst_context, dst_dataset="data/dst/work")
    dst_zzzz = Mock(dst_context=dst_context, dst_dataset="data/dst/zzz")
    with patch("zettarepl.replication.run.get_receive_resume_token") as get_receive_resume_token:
        get_receive_resume_token.side_effect = lambda _, dataset: {"data/dst/work": "token"}.get(dataset)

        step = Mock()
        dst_work.instantiate.return_value = step
        with patch("zettarepl.replication.run.run_replication_step") as run_replication_step:
            result = resume_replications([dst, dst_work, dst_zzzz])

            dst_work.instantiate.assert_called_once_with(receive_resume_token="token")
            run_replication_step.assert_called_once_with(step, None)

            assert result is True