def test_unpack_dsc_with_vendor(self): # Some source packages unpack differently depending on dpkg's idea # of the "vendor", and in extreme cases may even fail with some # vendors. gina always sets the vendor to the target distribution # name to ensure that it unpacks packages as if unpacking on that # distribution. archive_root = self.useTempDir() pool_dir = os.path.join(archive_root, "pool/main/f/foo") os.makedirs(pool_dir) # Synthesise a package that can be unpacked with DEB_VENDOR=debian # but not with DEB_VENDOR=ubuntu. with open(os.path.join(pool_dir, "foo_1.0.orig.tar.gz"), "wb+") as buffer: orig_tar = LaunchpadWriteTarFile(buffer) orig_tar.add_directory("foo-1.0") orig_tar.close() buffer.seek(0) orig_tar_contents = buffer.read() with open(os.path.join(pool_dir, "foo_1.0-1.debian.tar.gz"), "wb+") as buffer: debian_tar = LaunchpadWriteTarFile(buffer) debian_tar.add_file("debian/source/format", "3.0 (quilt)\n") debian_tar.add_file("debian/patches/ubuntu.series", "--- corrupt patch\n") debian_tar.add_file("debian/rules", "") debian_tar.close() buffer.seek(0) debian_tar_contents = buffer.read() dsc_path = os.path.join(pool_dir, "foo_1.0-1.dsc") with open(dsc_path, "w") as dsc: dsc.write( dedent("""\ Format: 3.0 (quilt) Source: foo Binary: foo Architecture: all Version: 1.0-1 Maintainer: Foo Bar <*****@*****.**> Files: %s %s foo_1.0.orig.tar.gz %s %s foo_1.0-1.debian.tar.gz """ % (hashlib.md5(orig_tar_contents).hexdigest(), len(orig_tar_contents), hashlib.md5(debian_tar_contents).hexdigest(), len(debian_tar_contents)))) dsc_contents = parse_tagfile(dsc_path) dsc_contents["Directory"] = pool_dir dsc_contents["Package"] = "foo" dsc_contents["Component"] = "main" dsc_contents["Section"] = "misc" sp_data = SourcePackageData(**dsc_contents) # Unpacking this in an Ubuntu context fails. self.assertRaises(ExecutionError, sp_data.do_package, "ubuntu", archive_root) # But all is well in a Debian context. sp_data.do_package("debian", archive_root)
def do_one_sourcepackage(distro, source, package_root, importer_handler): source_data = SourcePackageData(**source) skip_key = u"%s/%s/%s" % (distro, source_data.package, source_data.version) skip_list = getFeatureFlag("soyuz.gina.skip_source_versions") if skip_list is not None and skip_key in skip_list.split(): log.info("Skipping %s %s as requested by feature flag.", source_data.package, source_data.version) return if importer_handler.preimport_sourcecheck(source_data): # Don't bother reading package information if the source package # already exists in the database log.info("%s already exists in the archive", source_data.package) return source_data.process_package(distro, package_root) source_data.ensure_complete() importer_handler.import_sourcepackage(source_data) importer_handler.commit()
def test_process_package_cleans_up_after_unpack_failure(self): archive_root = self.useTempDir() pool_dir = os.path.join(archive_root, "pool/main/f/foo") os.makedirs(pool_dir) with open(os.path.join( pool_dir, "foo_1.0.orig.tar.gz"), "wb+") as buffer: orig_tar = LaunchpadWriteTarFile(buffer) orig_tar.add_directory("foo-1.0") orig_tar.close() buffer.seek(0) orig_tar_contents = buffer.read() with open(os.path.join( pool_dir, "foo_1.0-1.debian.tar.gz"), "wb+") as buffer: debian_tar = LaunchpadWriteTarFile(buffer) debian_tar.add_file("debian/source/format", "3.0 (quilt)\n") debian_tar.add_file("debian/patches/series", "--- corrupt patch\n") debian_tar.add_file("debian/rules", "") debian_tar.close() buffer.seek(0) debian_tar_contents = buffer.read() dsc_path = os.path.join(pool_dir, "foo_1.0-1.dsc") with open(dsc_path, "w") as dsc: dsc.write(dedent("""\ Format: 3.0 (quilt) Source: foo Binary: foo Architecture: all Version: 1.0-1 Maintainer: Foo Bar <*****@*****.**> Files: %s %s foo_1.0.orig.tar.gz %s %s foo_1.0-1.debian.tar.gz """ % ( hashlib.md5(orig_tar_contents).hexdigest(), len(orig_tar_contents), hashlib.md5(debian_tar_contents).hexdigest(), len(debian_tar_contents)))) dsc_contents = parse_tagfile(dsc_path) dsc_contents["Directory"] = pool_dir dsc_contents["Package"] = "foo" dsc_contents["Component"] = "main" dsc_contents["Section"] = "misc" sp_data = SourcePackageData(**dsc_contents) unpack_tmpdir = self.makeTemporaryDirectory() with EnvironmentVariableFixture("TMPDIR", unpack_tmpdir): # Force tempfile to recheck TMPDIR. tempfile.tempdir = None try: self.assertRaises( ExecutionError, sp_data.process_package, "ubuntu", archive_root) finally: # Force tempfile to recheck TMPDIR for future tests. tempfile.tempdir = None self.assertEqual([], os.listdir(unpack_tmpdir))
def test_publish_creates_published_publication(self): maintainer = self.factory.makePerson() series = self.factory.makeDistroSeries() section = self.factory.makeSection() pocket = PackagePublishingPocket.RELEASE spr = self.factory.makeSourcePackageRelease() publisher = SourcePackagePublisher(series, pocket, None) publisher.publish(spr, SourcePackageData( component='main', section=section.name, version='1.0', maintainer=maintainer.preferredemail, architecture='all', files='foo.py', binaries='foo.py')) [spph] = series.main_archive.getPublishedSources() self.assertEqual(PackagePublishingStatus.PUBLISHED, spph.status)
def test_user_defined_fields(self): series = self.factory.makeDistroSeries() archive_root = self.useTempDir() sphandler = SourcePackageHandler( series.distribution.name, archive_root, PackagePublishingPocket.RELEASE, None) dsc_contents = { "Format": "3.0 (quilt)", "Source": "foo", "Binary": "foo", "Architecture": "all arm64", "Version": "1.0-1", "Maintainer": "Foo Bar <*****@*****.**>", "Files": "xxx 000 foo_1.0-1.dsc", "Build-Indep-Architecture": "amd64", "Directory": "pool/main/f/foo", "Package": "foo", "Component": "main", "Section": "misc", } sp_data = SourcePackageData(**dsc_contents) self.assertEqual( [["Build-Indep-Architecture", "amd64"]], sp_data._user_defined) sp_data.archive_root = archive_root sp_data.dsc = "" sp_data.copyright = "" sp_data.urgency = "low" sp_data.changelog = None sp_data.changelog_entry = None sp_data.date_uploaded = UTC_NOW # We don't need a real .dsc here. write_file( os.path.join(archive_root, "pool/main/f/foo/foo_1.0-1.dsc"), "x") spr = sphandler.createSourcePackageRelease(sp_data, series) self.assertIsNotNone(spr) self.assertEqual( [["Build-Indep-Architecture", "amd64"]], spr.user_defined_fields)
def test_checksum_fields(self): # We only need one of Files or Checksums-*. base_dsc_contents = { "Package": "foo", "Binary": "foo", "Version": "1.0-1", "Maintainer": "Foo Bar <*****@*****.**>", "Section": "misc", "Architecture": "all", "Directory": "pool/main/f/foo", "Component": "main", } for field in ( "Files", "Checksums-Sha1", "Checksums-Sha256", "Checksums-Sha512"): dsc_contents = dict(base_dsc_contents) dsc_contents[field] = "xxx 000 foo_1.0-1.dsc" sp_data = SourcePackageData(**dsc_contents) self.assertEqual(["foo_1.0-1.dsc"], sp_data.files) self.assertRaises( MissingRequiredArguments, SourcePackageData, **base_dsc_contents)
def _getSourcePackageDataFromDSC(self, sp_name, sp_version, sp_component, sp_section): try: dsc_name, dsc_path, sp_component = get_dsc_path( sp_name, sp_version, sp_component, self.archive_root) except PoolFileNotFound: # Aah well, no source package in archive either. return None log.debug("Found a source package for %s (%s) in %s" % (sp_name, sp_version, sp_component)) dsc_contents = parse_tagfile(dsc_path) dsc_contents = dict([(name.lower(), value) for (name, value) in dsc_contents.iteritems()]) # Since the dsc doesn't know, we add in the directory, package # component and section dsc_contents['directory'] = os.path.join( "pool", poolify(sp_name, sp_component)) dsc_contents['package'] = sp_name dsc_contents['component'] = sp_component dsc_contents['section'] = sp_section # the dsc doesn't list itself so add it ourselves if 'files' not in dsc_contents: log.error('DSC for %s didn\'t contain a files entry: %r' % (dsc_name, dsc_contents)) return None if not dsc_contents['files'].endswith("\n"): dsc_contents['files'] += "\n" # XXX kiko 2005-10-21: Why do we hack the md5sum and size of the DSC? # Should probably calculate it properly. dsc_contents['files'] += "xxx 000 %s" % dsc_name # SourcePackageData requires capitals capitalized_dsc = {} for k, v in dsc_contents.items(): capitalized_dsc[k.capitalize()] = v return SourcePackageData(**capitalized_dsc)
def do_one_sourcepackage(distro, source, package_root, importer_handler): source_data = SourcePackageData(**source) skip_key = u'%s/%s/%s' % (distro, source_data.package, source_data.version) skip_list = getFeatureFlag('soyuz.gina.skip_source_versions') if skip_list is not None and skip_key in skip_list.split(): log.info("Skipping %s %s as requested by feature flag.", source_data.package, source_data.version) return if importer_handler.preimport_sourcecheck(source_data): # Don't bother reading package information if the source package # already exists in the database log.info('%s already exists in the archive', source_data.package) return source_data.process_package(distro, package_root) source_data.ensure_complete() importer_handler.import_sourcepackage(source_data) importer_handler.commit()
def test_unpack_dsc_with_vendor(self): # Some source packages unpack differently depending on dpkg's idea # of the "vendor", and in extreme cases may even fail with some # vendors. gina always sets the vendor to the target distribution # name to ensure that it unpacks packages as if unpacking on that # distribution. archive_root = self.useTempDir() pool_dir = os.path.join(archive_root, "pool/main/f/foo") os.makedirs(pool_dir) # Synthesise a package that can be unpacked with DEB_VENDOR=debian # but not with DEB_VENDOR=ubuntu. with open(os.path.join(pool_dir, "foo_1.0.orig.tar.gz"), "wb+") as buffer: orig_tar = LaunchpadWriteTarFile(buffer) orig_tar.add_directory("foo-1.0") orig_tar.close() buffer.seek(0) orig_tar_contents = buffer.read() with open(os.path.join(pool_dir, "foo_1.0-1.debian.tar.gz"), "wb+") as buffer: debian_tar = LaunchpadWriteTarFile(buffer) debian_tar.add_file("debian/source/format", "3.0 (quilt)\n") debian_tar.add_file("debian/patches/ubuntu.series", "--- corrupt patch\n") debian_tar.add_file("debian/rules", "") debian_tar.close() buffer.seek(0) debian_tar_contents = buffer.read() dsc_path = os.path.join(pool_dir, "foo_1.0-1.dsc") with open(dsc_path, "w") as dsc: dsc.write( dedent( """\ Format: 3.0 (quilt) Source: foo Binary: foo Architecture: all Version: 1.0-1 Maintainer: Foo Bar <*****@*****.**> Files: %s %s foo_1.0.orig.tar.gz %s %s foo_1.0-1.debian.tar.gz """ % ( hashlib.md5(orig_tar_contents).hexdigest(), len(orig_tar_contents), hashlib.md5(debian_tar_contents).hexdigest(), len(debian_tar_contents), ) ) ) dsc_contents = parse_tagfile(dsc_path) dsc_contents["Directory"] = pool_dir dsc_contents["Package"] = "foo" dsc_contents["Component"] = "main" dsc_contents["Section"] = "misc" sp_data = SourcePackageData(**dsc_contents) # Unpacking this in an Ubuntu context fails. self.assertRaises(ExecutionError, sp_data.do_package, "ubuntu", archive_root) # But all is well in a Debian context. sp_data.do_package("debian", archive_root)