def test_removes_path(self, mock_remove): path = '/a/b/c' with util.deleting(path): pass mock_remove.assert_called_once_with(path)
def download_succeeded(self, report): with util.deleting(report.destination): unit = report.data try: super(RPMListener, self).download_succeeded(report) except (verification.VerificationException, util.InvalidChecksumType): # verification failed, unit not added return # we need to read package header in order to extract signature info # unit is not added if header cannot be read headers = rpm_parse.package_headers(report.destination) unit['signing_key'] = rpm_parse.package_signature(headers) added_unit = self.sync.add_rpm_unit(self.metadata_files, unit) try: added_unit.safe_import_content(report.destination) except verification.VerificationException as e: error_report = { constants.NAME: unit.name, constants.UNIT_KEY: unit.unit_key, constants.ERROR_CODE: constants.ERROR_SIZE_VERIFICATION, constants.ERROR_KEY_EXPECTED_SIZE: unit.size, constants.ERROR_KEY_ACTUAL_SIZE: e[0] } self.sync.progress_report['content'].failure( unit, error_report) raise if self.sync.signature_filter_passed(added_unit): self.sync.associate_rpm_unit(added_unit) if not added_unit.downloaded: added_unit.downloaded = True added_unit.save()
def download_succeeded(self, report): with util.deleting(report.destination): unit = report.data try: super(RPMListener, self).download_succeeded(report) except (verification.VerificationException, util.InvalidChecksumType): # verification failed, unit not added return # we need to read package header in order to extract signature info # unit is not added if header cannot be read headers = rpm_parse.package_headers(report.destination) unit["signing_key"] = rpm_parse.package_signature(headers) added_unit = self.sync.add_rpm_unit(self.metadata_files, unit) try: added_unit.safe_import_content(report.destination) except verification.VerificationException as e: error_report = { constants.NAME: unit.name, constants.UNIT_KEY: unit.unit_key, constants.ERROR_CODE: constants.ERROR_SIZE_VERIFICATION, constants.ERROR_KEY_EXPECTED_SIZE: unit.size, constants.ERROR_KEY_ACTUAL_SIZE: e[0], } self.sync.progress_report["content"].failure(unit, error_report) raise if self.sync.signature_filter_passed(added_unit): self.sync.associate_rpm_unit(added_unit) if not added_unit.downloaded: added_unit.downloaded = True added_unit.save()
def test_squashes_exception(self, mock_remove): path = '/a/b/c' # this should not raise any exceptions with util.deleting(path): pass mock_remove.assert_called_once_with(path)
def download_succeeded(self, report): with util.deleting(report.destination): unit = report.data try: super(RPMListener, self).download_succeeded(report) except (verification.VerificationException, verification.InvalidChecksumType): # verification failed, unit not added return added_unit = self.sync.add_rpm_unit(self.metadata_files, unit) added_unit.safe_import_content(report.destination) if not added_unit.downloaded: added_unit.downloaded = True added_unit.save()
def download_succeeded(self, report): with util.deleting(report.destination): unit = report.data try: super(RPMListener, self).download_succeeded(report) except (verification.VerificationException, util.InvalidChecksumType): # verification failed, unit not added return # we need to read package header in order to extract signature info # unit is not added if header cannot be read headers = rpm_parse.package_headers(report.destination) added_unit = self.sync.add_rpm_unit(self.metadata_files, unit) added_unit.safe_import_content(report.destination) if not added_unit.downloaded: added_unit.downloaded = True added_unit['signature'] = rpm_parse.package_signature(headers) added_unit.save()
def download_succeeded(self, report): with util.deleting(report.destination): unit = report.data try: super(RPMListener, self).download_succeeded(report) except (verification.VerificationException, util.InvalidChecksumType): # verification failed, unit not added return # we need to read package header in order to extract signature info # unit is not added if header cannot be read headers = rpm_parse.package_headers(report.destination) unit['signing_key'] = rpm_parse.package_signature(headers) added_unit = self.sync.add_rpm_unit(self.metadata_files, unit) added_unit.safe_import_content(report.destination) if self.sync.signature_filter_passed(added_unit): self.sync.associate_rpm_unit(added_unit) if not added_unit.downloaded: added_unit.downloaded = True added_unit.save()
def download_succeeded(self, report): _logger.info("%s: download succeeded", report.data._content_type_id) with util.deleting(report.destination): unit = report.data try: super(CustomPackageListener, self).download_succeeded(report) except (verification.VerificationException, util.InvalidChecksumType): # verification failed, unit not added return # At this point, the checksum validation should have already # caught whether the unit is invalid, so we should be reasonably # sure the same unit is on disk unit_dl = unit.__class__.from_file(report.destination) _logger.info("Adding %s unit", unit_dl._content_type_id) added_unit = self.sync.add_unit(self.metadata_files, unit_dl, report.destination) if not added_unit.downloaded: added_unit.downloaded = True added_unit.save()
def download_succeeded(self, report): with util.deleting(report.destination): unit = report.data try: super(CustomPackageListener, self).download_succeeded(report) except (verification.VerificationException, util.InvalidChecksumType): # verification failed, unit not added _logger.error("%s: download failed", report.data._content_type_id) return # At this point, the checksum validation should have already # caught whether the unit is invalid, so we should be reasonably # sure the same unit is on disk unit_dl = unit.__class__.from_file(report.destination) _logger.info("Adding %s unit", unit_dl._content_type_id) added_unit = self.sync.add_unit(self.metadata_files, unit_dl, report.destination) if not added_unit.downloaded: added_unit.downloaded = True added_unit.save()