Пример #1
0
    def test_snapshot_local_parent(self, content, filename):
        """
        Create a local snapshot and then another local snapshot with the
        first as parent. Then upload both at once.
        """
        data = io.BytesIO(content)

        # create LocalSnapshot
        local_snapshot = success_result_of(
            create_snapshot(
                relpath=filename,
                author=self.alice,
                data_producer=data,
                snapshot_stash_dir=self.stash_dir,
                parents=[],
                cooperator=self.uncooperator,
            ))

        # create another LocalSnapshot with the first as parent
        child_snapshot = success_result_of(
            create_snapshot(
                relpath=filename,
                author=self.alice,
                data_producer=data,
                snapshot_stash_dir=self.stash_dir,
                parents=[local_snapshot],
                cooperator=self.uncooperator,
            ))

        # turn them both into RemoteSnapshots
        remote_snapshot = success_result_of(
            write_snapshot_to_tahoe(child_snapshot, self.alice,
                                    self.tahoe_client))

        # ...the last thing we wrote is now a RemoteSnapshot and
        # should have a single parent.
        self.assertThat(
            remote_snapshot,
            MatchesStructure(
                metadata=ContainsDict({"relpath": Equals(filename)}),
                parents_raw=AfterPreprocessing(len, Equals(1)),
            ))

        # turn the parent into a RemoteSnapshot
        parent_snapshot = success_result_of(
            create_snapshot_from_capability(
                Capability.from_string(remote_snapshot.parents_raw[0]),
                self.tahoe_client,
            ))
        self.assertThat(
            parent_snapshot,
            MatchesStructure(
                metadata=ContainsDict({"relpath": Equals(filename)}),
                parents_raw=Equals([]),
            ))
Пример #2
0
    def test_snapshot_roundtrip(self, content, filename):
        """
        Create a local snapshot, write into tahoe to create a remote snapshot,
        then read back the data from the snapshot cap to recreate the remote
        snapshot and check if it is the same as the previous one.
        """
        data = io.BytesIO(content)

        snapshots = []
        # create LocalSnapshot
        d = create_snapshot(
            name=filename,
            author=self.alice,
            data_producer=data,
            snapshot_stash_dir=self.stash_dir,
            parents=[],
        )
        d.addCallback(snapshots.append)
        self.assertThat(
            d,
            succeeded(Always()),
        )

        # create remote snapshot
        d = write_snapshot_to_tahoe(snapshots[0], self.alice,
                                    self.tahoe_client)
        d.addCallback(snapshots.append)

        self.assertThat(
            d,
            succeeded(Always()),
        )

        # snapshots[1] is a RemoteSnapshot
        note("remote snapshot: {}".format(snapshots[1]))

        # now, recreate remote snapshot from the cap string and compare with the original.
        # Check whether information is preserved across these changes.

        snapshot_d = create_snapshot_from_capability(snapshots[1].capability,
                                                     self.tahoe_client)
        snapshot_d.addCallback(snapshots.append)
        self.assertThat(snapshot_d, succeeded(Always()))
        snapshot = snapshots[-1]

        self.assertThat(snapshot, MatchesStructure(name=Equals(filename)))
        content_io = io.BytesIO()
        self.assertThat(
            snapshot.fetch_content(self.tahoe_client, content_io),
            succeeded(Always()),
        )
        self.assertEqual(content_io.getvalue(), content)
Пример #3
0
    def test_snapshot_roundtrip(self, content, filename, modified_time):
        """
        Create a local snapshot, write into tahoe to create a remote snapshot,
        then read back the data from the snapshot cap to recreate the remote
        snapshot and check if it is the same as the previous one.
        """
        data = io.BytesIO(content)

        # create LocalSnapshot
        local_snapshot = success_result_of(
            create_snapshot(
                relpath=filename,
                author=self.alice,
                data_producer=data,
                snapshot_stash_dir=self.stash_dir,
                parents=[],
                modified_time=modified_time,
                cooperator=self.uncooperator,
            ))

        # create remote snapshot
        remote_snapshot = success_result_of(
            write_snapshot_to_tahoe(local_snapshot, self.alice,
                                    self.tahoe_client))

        note("remote snapshot: {}".format(remote_snapshot))

        # now, recreate remote snapshot from the cap string and compare with the original.
        # Check whether information is preserved across these changes.

        downloaded_snapshot = success_result_of(
            create_snapshot_from_capability(remote_snapshot.capability,
                                            self.tahoe_client))

        self.assertThat(
            downloaded_snapshot,
            MatchesStructure(metadata=ContainsDict({
                "relpath":
                Equals(filename),
                "modification_time":
                Equals(modified_time),
            }), ),
        )
        content_io = io.BytesIO()
        self.assertThat(
            downloaded_snapshot.fetch_content(self.tahoe_client, content_io),
            succeeded(Always()),
        )
        self.assertEqual(content_io.getvalue(), content)
Пример #4
0
    def test_snapshot_local_parent(self, content, filename):
        """
        Create a local snapshot and then another local snapshot with the
        first as parent. Then upload both at once.
        """
        data = io.BytesIO(content)

        snapshots = []
        # create LocalSnapshot
        d = create_snapshot(
            name=filename,
            author=self.alice,
            data_producer=data,
            snapshot_stash_dir=self.stash_dir,
            parents=[],
        )
        d.addCallback(snapshots.append)
        self.assertThat(
            d,
            succeeded(Always()),
        )

        # snapshots[0] is a LocalSnapshot with no parents

        # create another LocalSnapshot with the first as parent
        d = create_snapshot(
            name=filename,
            author=self.alice,
            data_producer=data,
            snapshot_stash_dir=self.stash_dir,
            parents=[snapshots[0]],
        )
        d.addCallback(snapshots.append)
        self.assertThat(
            d,
            succeeded(Always()),
        )

        # turn them both into RemoteSnapshots
        d = write_snapshot_to_tahoe(snapshots[1], self.alice,
                                    self.tahoe_client)
        d.addCallback(snapshots.append)
        self.assertThat(d, succeeded(Always()))

        # ...the last thing we wrote is now a RemoteSnapshot and
        # should have a single parent.
        self.assertThat(
            snapshots[2],
            MatchesStructure(
                name=Equals(filename),
                parents_raw=AfterPreprocessing(len, Equals(1)),
            ))

        # turn the parent into a RemoteSnapshot
        d = snapshots[2].fetch_parent(self.tahoe_client, 0)
        d.addCallback(snapshots.append)
        self.assertThat(d, succeeded(Always()))
        self.assertThat(
            snapshots[3],
            MatchesStructure(
                name=Equals(filename),
                parents_raw=Equals([]),
            ))
Пример #5
0
    def test_snapshot_remote_parent(self, content, filename):
        """
        Create a local snapshot, write into tahoe to create a remote
        snapshot, then create another local snapshot with a remote
        parent. This local snapshot retains its parent when converted
        to a remote.
        """
        data = io.BytesIO(content)

        snapshots = []
        # create LocalSnapshot
        d = create_snapshot(
            name=filename,
            author=self.alice,
            data_producer=data,
            snapshot_stash_dir=self.stash_dir,
            parents=[],
        )
        d.addCallback(snapshots.append)
        self.assertThat(
            d,
            succeeded(Always()),
        )

        # snapshots[0] is a LocalSnapshot with no parents

        # turn it into a remote snapshot by uploading
        d = write_snapshot_to_tahoe(snapshots[0], self.alice,
                                    self.tahoe_client)
        d.addCallback(snapshots.append)

        self.assertThat(
            d,
            succeeded(Always()),
        )

        # snapshots[1] is a RemoteSnapshot with no parents,
        # corresponding to snapshots[0]

        d = create_snapshot(
            name=filename,
            author=self.alice,
            data_producer=data,
            snapshot_stash_dir=self.stash_dir,
            parents=[snapshots[1]],
        )
        d.addCallback(snapshots.append)
        self.assertThat(
            d,
            succeeded(Always()),
        )
        self.assertThat(
            snapshots[2],
            MatchesStructure(
                name=Equals(filename),
                parents_remote=AfterPreprocessing(len, Equals(1)),
            ))

        # upload snapshots[2], turning it into a RemoteSnapshot
        # .. which should have one parent

        d = write_snapshot_to_tahoe(snapshots[2], self.alice,
                                    self.tahoe_client)
        d.addCallback(snapshots.append)

        self.assertThat(
            d,
            succeeded(Always()),
        )
        # ...the last thing we wrote is now a RemoteSnapshot and
        # should have a single parent
        self.assertThat(
            snapshots[3],
            MatchesStructure(
                name=Equals(filename),
                parents_raw=Equals([snapshots[1].capability]),
            ))