Example #1
0
    def test_delete(self):
        service = CephBackupService(self.ctxt)
        self._create_volume_db_entry(self.vol_id, 1)
        backup = db.backup_get(self.ctxt, self.backup_id)

        # Must be something mutable
        remove_called = []

        def remove(inst, ioctx, name):
            remove_called.append(True)

        self.stubs.Set(service.rbd.RBD, "remove", remove)
        service.delete(backup)
        self.assertTrue(remove_called[0])
Example #2
0
    def test_backup_volume_from_file(self):
        service = CephBackupService(self.ctxt)

        with tempfile.NamedTemporaryFile() as test_file:
            checksum = hashlib.sha256()

            def write_data(inst, data, offset):
                checksum.update(data)
                test_file.write(data)

            self.stubs.Set(service.rbd.Image, "write", write_data)

            service._backup_volume_from_file("foo", self.length, self.volume_file)

            # Ensure the files are equal
            self.assertEquals(checksum.digest(), self.checksum.digest())
Example #3
0
    def test_backup_good(self):
        service = CephBackupService(self.ctxt)
        backup = db.backup_get(self.ctxt, self.backup_id)
        self._create_volume_db_entry(self.vol_id, 1)

        with tempfile.NamedTemporaryFile() as test_file:
            checksum = hashlib.sha256()

            def write_data(inst, data, offset):
                checksum.update(data)
                test_file.write(data)

            self.stubs.Set(service.rbd.Image, "write", write_data)

            service.backup(backup, self.volume_file)

            # Ensure the files are equal
            self.assertEquals(checksum.digest(), self.checksum.digest())
Example #4
0
    def test_tranfer_data_from_rbd(self):
        service = CephBackupService(self.ctxt)

        with tempfile.NamedTemporaryFile() as test_file:
            self.volume_file.seek(0)

            def read_data(inst, offset, length):
                return self.volume_file.read(self.length)

            self.stubs.Set(service.rbd.Image, "read", read_data)

            service._transfer_data(service.rbd.Image(), test_file, "foo", self.length)

            checksum = hashlib.sha256()
            test_file.seek(0)
            for c in xrange(0, self.num_chunks):
                checksum.update(test_file.read(self.chunk_size))

            # Ensure the files are equal
            self.assertEquals(checksum.digest(), self.checksum.digest())
Example #5
0
    def test_get_rbd_support(self):
        service = CephBackupService(self.ctxt)

        self.assertFalse(hasattr(service.rbd, "RBD_FEATURE_LAYERING"))
        self.assertFalse(hasattr(service.rbd, "RBD_FEATURE_STRIPINGV2"))

        oldformat, features = service._get_rbd_support()
        self.assertTrue(oldformat)
        self.assertEquals(features, 0)

        service.rbd.RBD_FEATURE_LAYERING = 1

        oldformat, features = service._get_rbd_support()
        self.assertFalse(oldformat)
        self.assertEquals(features, 1)

        service.rbd.RBD_FEATURE_STRIPINGV2 = 2

        oldformat, features = service._get_rbd_support()
        self.assertFalse(oldformat)
        self.assertEquals(features, 1 | 2)
Example #6
0
    def test_restore(self):
        service = CephBackupService(self.ctxt)
        self._create_volume_db_entry(self.vol_id, 1)
        backup = db.backup_get(self.ctxt, self.backup_id)

        with tempfile.NamedTemporaryFile() as test_file:
            self.volume_file.seek(0)

            def read_data(inst, offset, length):
                return self.volume_file.read(self.length)

            self.stubs.Set(service.rbd.Image, "read", read_data)

            service.restore(backup, self.vol_id, test_file)

            checksum = hashlib.sha256()
            test_file.seek(0)
            for c in xrange(0, self.num_chunks):
                checksum.update(test_file.read(self.chunk_size))

            # Ensure the files are equal
            self.assertEquals(checksum.digest(), self.checksum.digest())