How to use the freezer.utils.checksum.CheckSum function in freezer

To help you get started, we’ve selected a few freezer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / freezer / tests / unit / utils / test_checksum.py View on Github external
def test_get_hash_files(self, mock_isfile, mock_open):
        """
        Test calculating the hash of a file
        """
        mock_isfile.return_value = True
        mock_open.return_value = self.fake_file
        chksum = CheckSum('onefile')
        chksum.get_hash('onefile')
        self.assertEqual(self.increment_hash_one, chksum._increment_hash)
        chksum.get_hash('otherfile')
        self.assertEqual(self.increment_hash_multi, chksum._increment_hash)
github openstack / freezer / tests / unit / utils / test_checksum.py View on Github external
def test_compare_file_not_match(self, mock_get_hashes):
        """
        compute checksum for a file and it should not match
        """
        mock_get_hashes.return_value = self.hello_world_sha256sum
        chksum = CheckSum('onefile')
        self.assertFalse(chksum.compare('badchecksum'))
github openstack / freezer / tests / unit / utils / test_checksum.py View on Github external
def test_hello_world_checksum_md5(self):
        """
        Test calculating the md5 of a string
        """
        chksum = CheckSum('nofile', 'md5')
        mdsum = chksum.hashfile(self.fake_file)
        self.assertEqual(self.hello_world_md5sum, mdsum)
github openstack / freezer / tests / unit / utils / test_checksum.py View on Github external
def test_hello_world_checksum_sha256(self):
        """
        Test calculating the sha256 of a string
        """
        chksum = CheckSum('nofile', 'sha256')
        shasum = chksum.hashfile(self.fake_file)
        self.assertEqual(self.hello_world_sha256sum, shasum)
github openstack / freezer / tests / unit / utils / test_checksum.py View on Github external
def test_compute_file(self, mock_get_checksum):
        """
        Test compute the checksum of a file
        """
        mock_get_checksum.return_value = self.hello_world_sha256sum
        chksum = CheckSum('onefile')
        chksum.count = 1
        result = chksum.compute()
        self.assertEquals(self.file_compute, result)
github openstack / freezer / tests / unit / utils / test_checksum.py View on Github external
def test_get_hash_multi(self, mock_isfile):
        """
        Calculate the hash of files in a directory
        """
        mock_isfile.return_value = False
        chksum = CheckSum('onedir')
        chksum.get_hash(u"./emptydir")
        self.assertEqual(self.increment_hash_emptydir, chksum._increment_hash)
github openstack / freezer / tests / unit / utils / test_checksum.py View on Github external
def test_compare_file_match(self, mock_get_hashes):
        """
        compute checksum for a file and it should match
        """
        mock_get_hashes.return_value = self.hello_world_sha256sum
        chksum = CheckSum('onefile')
        self.assertTrue(chksum.compare(self.file_compute))
github openstack / freezer / freezer / job.py View on Github external
os.path.normpath(self.conf.path_to_backup.strip()))
                if not os.path.exists(chdir_path):
                    msg = 'Path to backup does not exist {0}'.format(
                        chdir_path)
                    LOG.critical(msg)
                    raise IOError(msg)
                if not os.path.isdir(chdir_path):
                    filepath = os.path.basename(chdir_path)
                    chdir_path = os.path.dirname(chdir_path)
                os.chdir(chdir_path)

                # Checksum for Backup Consistency
                if self.conf.consistency_check:
                    ignorelinks = (self.conf.dereference_symlink is None or
                                   self.conf.dereference_symlink == 'hard')
                    consistency_checksum = checksum.CheckSum(
                        filepath, ignorelinks=ignorelinks).compute()
                    LOG.info('Computed checksum for consistency {0}'.
                             format(consistency_checksum))
                    self.conf.consistency_checksum = consistency_checksum

                return self.engine.backup(
                    backup_resource=filepath,
                    hostname_backup_name=self.conf.hostname_backup_name,
                    no_incremental=self.conf.no_incremental,
                    max_level=self.conf.max_level,
                    always_level=self.conf.always_level,
                    restart_always_level=self.conf.restart_always_level)

            finally:
                # whether an error occurred or not, remove the snapshot anyway
                app_mode.release()
github openstack / freezer / freezer / job.py View on Github external
restore_abs_path = conf.restore_abs_path
        if conf.restore_from_date:
            restore_timestamp = utils.date_to_timestamp(conf.restore_from_date)
        if conf.backup_media == 'fs':
            self.engine.restore(
                hostname_backup_name=self.conf.hostname_backup_name,
                restore_resource=restore_abs_path,
                overwrite=conf.overwrite,
                recent_to_date=restore_timestamp,
                backup_media=conf.mode)

            try:
                if conf.consistency_checksum:
                    backup_checksum = conf.consistency_checksum
                    restore_checksum = checksum.CheckSum(restore_abs_path,
                                                         ignorelinks=True)
                    if restore_checksum.compare(backup_checksum):
                        LOG.info('Consistency check success.')
                    else:
                        raise ConsistencyCheckException(
                            "Backup Consistency Check failed: backup checksum "
                            "({0}) and restore checksum ({1}) did not match.".
                            format(backup_checksum, restore_checksum.checksum))
            except OSError as e:
                raise ConsistencyCheckException(
                    "Backup Consistency Check failed: could not checksum file"
                    " {0} ({1})".format(e.filename, e.strerror))
            return {}
        res = restore.RestoreOs(conf.client_manager, conf.container,
                                self.storage)
        if conf.backup_media == 'nova':