Example #1
0
    def test_backup_restore(self):
        """ Test if backup and restore works correctly """

        backup_id = common.backup(self.backend, self.backup_dir)
        old_file = os.path.join(self.storage_dir, backup_id)

        # Create new backup, this should reuse the last metadata set and the
        # checksum should be reused. Metadata set should be identical
        with mock.patch('logging.info') as mock_log:
            backup_id = common.backup(self.backend, self.backup_dir)
            mock_log.assert_any_call('Skipped unchanged sub/o\xcc\x88')
        new_file = os.path.join(self.storage_dir, backup_id)
        self.assertEqual(utils.sha256_file(old_file), utils.sha256_file(new_file))

        # Check if data deduplication works
        chunks = utils.find_modified_files(self.storage_dir)
        storage_size = 0
        for filename, stat in chunks.items():
            if filename.startswith('c-'):
                storage_size += stat['s']
        self.assertTrue(storage_size < self.original_size)

        common.restore(self.backend, self.restore_dir, backup_id)

        # Compare original file content to restored file content
        for fn in ['x', 'sub/y']:
            old_filename = os.path.join(self.backup_dir, fn)
            old_hash = utils.sha256_file(old_filename)
            new_filename = os.path.join(self.restore_dir, fn)
            new_hash = utils.sha256_file(new_filename)
            self.assertEqual(old_hash, new_hash)
Example #2
0
    def test_hmac_file(self):
        """ Test if file SHA256 is computed correctly """

        checksum = utils.sha256_file(self.tempfile)
        self.assertEqual(self.reference, checksum)

        checksum = utils.sha256_file(self.tempfile + ' ')
        self.assertEqual(None, checksum)