Exemple #1
0
    def tearDown(self):
        out = destroy_filesystem(self.job.filesystem)
        if out.returncode:
            self.assertIn('dataset does not exist', out.stderr)

        for item in self.bucket.objects.all():
            item.delete()
Exemple #2
0
    def test_restore_filesystem(self):
        """ Restore filesystem from snapshot stream. """
        # Given
        out = create_snapshot(self.filesystem, self.snapshot_name)
        self.assertEqual(0, out.returncode, msg=out.stderr)

        # When
        with open_snapshot_stream(self.filesystem, self.snapshot_name,
                                  'r') as f:
            snapshot = f.stdout.read()
            stderr = f.stderr.read().decode('utf-8')
        self.assertEqual(0, f.returncode, msg=stderr)

        out = destroy_filesystem(self.filesystem)
        self.assertEqual(0, out.returncode, msg=out.stderr)

        # Then
        with open_snapshot_stream(self.filesystem, self.snapshot_name,
                                  'w') as f:
            f.stdin.write(snapshot)
            stderr = f.stderr.read().decode('utf-8')
        self.assertEqual(0, f.returncode, msg=stderr)

        with open(self.test_file, 'r') as f:
            out = f.read()
        self.assertEqual(self.test_data, out)
Exemple #3
0
    def test_restore_from_full_backup(self):
        """ Test restore from full backup. """
        # Given
        self.job.start()

        out = destroy_filesystem(self.job.filesystem)
        self.assertEqual(0, out.returncode, msg=out.stderr)

        # When
        self.job.restore()

        # Then
        with open(self.test_file, 'r') as f:
            out = f.read()
        self.assertEqual(self.test_data, out)
Exemple #4
0
    def test_restore_filesystem_with_increment(self):
        """ Restore filesystem from initial and increment snapshot stream. """
        # Given
        out = create_snapshot(self.filesystem, self.snapshot_name)
        self.assertEqual(0, out.returncode, msg=out.stderr)

        with open(self.test_file, 'a') as f:
            f.write('append')

        out = create_snapshot(self.filesystem, 'snap_2')
        self.assertEqual(0, out.returncode, msg=out.stderr)

        # When
        with open_snapshot_stream(self.filesystem, self.snapshot_name,
                                  'r') as f:
            snapshot_initial = f.stdout.read()
            stderr = f.stderr.read().decode('utf-8')
        self.assertEqual(0, f.returncode, msg=stderr)

        with open_snapshot_stream_inc(self.filesystem, self.snapshot_name,
                                      'snap_2') as f:
            snapshot_increment = f.stdout.read()
            stderr = f.stderr.read().decode('utf-8')
        self.assertEqual(0, f.returncode, msg=stderr)

        out = destroy_filesystem(self.filesystem)
        self.assertEqual(0, out.returncode, msg=out.stderr)

        # Then
        with open_snapshot_stream(self.filesystem, self.snapshot_name,
                                  'w') as f:
            f.stdin.write(snapshot_initial)
            stderr = f.stderr.read().decode('utf-8')
        self.assertEqual(0, f.returncode, msg=stderr)

        with open_snapshot_stream(self.filesystem, 'snap_2', 'w') as f:
            f.stdin.write(snapshot_increment)
            stderr = f.stderr.read().decode('utf-8')
        self.assertEqual(0, f.returncode, msg=stderr)

        with open(self.test_file, 'r') as f:
            out = f.read()
        self.assertEqual(self.test_data + 'append', out)
Exemple #5
0
    def test_restore_from_incremental_backup(self):
        """ Test restore from incremental backup. """
        # Given
        self.job.start()

        with open(self.test_file, 'a') as f:
            f.write('append')
        self.job.start()

        out = destroy_filesystem(self.job.filesystem)
        self.assertEqual(0, out.returncode, msg=out.stderr)

        # When
        self.job.restore()

        # Then
        with open(self.test_file, 'r') as f:
            out = f.read()
        self.assertEqual(self.test_data + 'append', out)
Exemple #6
0
    def test_restore_command(self):
        """ Test restore command. """
        # Given
        self.job.start()

        with open(self.test_file, 'a') as f:
            f.write('append')
        self.job.start()

        out = destroy_filesystem(self.job.filesystem)
        self.assertEqual(0, out.returncode, msg=out.stderr)

        # When
        result = self.runner.invoke(cli, ['restore', self.job.filesystem])
        self.assertEqual(result.exit_code, 0, msg=_format_exception(result))

        # Then
        with open(self.test_file, 'r') as f:
            out = f.read()
        self.assertEqual(self.test_data + 'append', out)
Exemple #7
0
    def test_restore_specific_backup(self):
        """ Test restoring from specific backup. """
        # Given
        self.job.start()

        with open(self.test_file, 'a') as f:
            f.write('append')
        self.job.start()

        out = destroy_filesystem(self.job.filesystem)
        self.assertEqual(0, out.returncode, msg=out.stderr)

        # When
        backups = self.job._backup_db.get_backup_times('inc')
        self.job.restore(backups[0])

        # Then
        with open(self.test_file, 'r') as f:
            out = f.read()
        self.assertEqual(self.test_data + 'append', out)
Exemple #8
0
 def tearDown(self):
     out = destroy_filesystem(self.filesystem)
     if out.returncode:
         self.assertIn('dataset does not exist', out.stderr)
Exemple #9
0
 def test_destroy_filesystem(self):
     """ Destroy filesystem. """
     out = destroy_filesystem(self.filesystem)
     self.assertEqual(0, out.returncode, msg=out.stderr)
     self.assertFalse(os.path.isfile(self.test_file))