Esempio n. 1
0
 def test_cleanCaches_union_architectures(self):
     # cleanCaches operates on the union of architectures for all
     # considered series.
     for series in self._distribution.series:
         series.status = SeriesStatus.OBSOLETE
     stable = self.factory.makeDistroSeries(distribution=self._distribution,
                                            status=SeriesStatus.CURRENT)
     unstable = self.factory.makeDistroSeries(
         distribution=self._distribution)
     for ds, arch in ((stable, "i386"), (stable, "armel"),
                      (unstable, "i386"), (unstable, "armhf")):
         self.factory.makeDistroArchSeries(distroseries=ds,
                                           architecturetag=arch)
     self._publisher = Publisher(self._logger, self._config, self._dp,
                                 self._archive)
     fa = self._setUpFTPArchiveHandler()
     fa.cleanCaches()
     path = os.path.join(self._config.miscroot, "apt-cleanup.conf")
     with open(path) as config_file:
         arch_lines = [
             line for line in config_file if " Architectures " in line
         ]
     self.assertNotEqual([], arch_lines)
     for line in arch_lines:
         match = re.search(r' Architectures "(.*)"', line)
         self.assertIsNotNone(match)
         config_arches = set(match.group(1).split())
         config_arches.discard("source")
         self.assertContentEqual(["armel", "armhf", "i386"], config_arches)
Esempio n. 2
0
    def test_generateConfig(self):
        # Generate apt-ftparchive configuration file and run it.

        # Setup FTPArchiveHandler with a real Publisher for Ubuntutest.
        publisher = Publisher(self._logger, self._config, self._dp,
                              self._archive)
        fa = FTPArchiveHandler(self._logger, self._config, self._dp,
                               self._distribution, publisher)
        fa.createEmptyPocketRequests(fullpublish=True)

        # Calculate overrides and filelists.
        self._publishDefaultOverrides(fa, 'main')
        self._publishDefaultFileLists(fa, 'main')

        # Add mentioned files in the repository pool/.
        self._addRepositoryFile('main', 'tiny', 'tiny_0.1.dsc')
        self._addRepositoryFile('main', 'tiny', 'tiny_0.1.tar.gz')
        self._addRepositoryFile('main', 'tiny', 'tiny_0.1_i386.deb')

        # When include_long_descriptions is set, apt.conf has
        # LongDescription "true" for that series.
        hoary_test = self._distribution.getSeries('hoary-test')
        self.assertTrue(hoary_test.include_long_descriptions)
        breezy_autotest = self._distribution.getSeries('breezy-autotest')
        breezy_autotest.include_long_descriptions = False

        # XXX cprov 2007-03-21: Relying on byte-to-byte configuration file
        # comparing is weak. We should improve this methodology to avoid
        # wasting time on test failures due to irrelevant format changes.
        apt_conf = fa.generateConfig(fullpublish=True)
        self._verifyFile("apt.conf", self._confdir)

        # XXX cprov 2007-03-21: This is an extra problem. Running a-f on
        # developer machines is wasteful. We need to find a away to split
        # those kind of tests and avoid to run it when performing 'make
        # check'. Although they should remain active in PQM to avoid possible
        # regressions.
        fa.runApt(apt_conf)
        self._verifyFile(
            "Packages",
            os.path.join(self._distsdir, "hoary-test", "main", "binary-i386"),
            skip_sha512)
        self._verifyEmpty(
            os.path.join(self._distsdir, "hoary-test", "main",
                         "debian-installer", "binary-i386", "Packages"))
        self._verifyFile(
            "Sources",
            os.path.join(self._distsdir, "hoary-test", "main", "source"),
            sanitize_apt_ftparchive_Sources_output)

        # XXX cprov 2007-03-21: see above, byte-to-byte configuration
        # comparing is weak.
        # Test that a publisher run now will generate an empty apt
        # config and nothing else.
        apt_conf = fa.generateConfig()
        assert len(file(apt_conf).readlines()) == 24

        # XXX cprov 2007-03-21: see above, do not run a-f on dev machines.
        fa.runApt(apt_conf)
Esempio n. 3
0
    def test_cleanCaches(self):
        # cleanCaches does real work.
        self._publisher = Publisher(self._logger, self._config, self._dp,
                                    self._archive)
        fa = self._setUpFTPArchiveHandler()
        fa.createEmptyPocketRequests(fullpublish=True)

        # Set up an initial repository.
        source_overrides = FakeSelectResult([("tiny", "main", "devel")])
        binary_overrides = FakeSelectResult([
            ("bin%d" % i, "main", "misc", "i386",
             PackagePublishingPriority.EXTRA, BinaryPackageFormat.DEB, None)
            for i in range(50)
        ])
        fa.publishOverrides("hoary-test", source_overrides, binary_overrides)
        source_files = FakeSelectResult([("tiny", "tiny_0.1.dsc", "main")])
        binary_files = FakeSelectResult([("bin%d" % i, "bin%d_1_i386.deb" % i,
                                          "main", "binary-i386")
                                         for i in range(50)])
        fa.publishFileLists("hoary-test", source_files, binary_files)
        self._addRepositoryFile("main", "tiny", "tiny_0.1.dsc")
        for i in range(50):
            self._addRepositoryFile("main",
                                    "bin%d" % i,
                                    "bin%d_1_i386.deb" % i,
                                    samplename="tiny_0.1_i386.deb")
        apt_conf = fa.generateConfig(fullpublish=True)
        fa.runApt(apt_conf)

        # Remove most of this repository's files so that cleanCaches has
        # something to do.
        for i in range(49):
            os.unlink(
                self._dp.pathFor("main", "bin%d" % i, "bin%d_1_i386.deb" % i))

        cache_path = os.path.join(self._config.cacheroot, "packages-i386.db")
        old_cache_size = os.stat(cache_path).st_size
        fa.cleanCaches()
        self.assertThat(os.stat(cache_path).st_size, LessThan(old_cache_size))
Esempio n. 4
0
    def test_generateConfig_index_compressors_changed(self):
        # If index_compressors changes between runs, then old compressed
        # files are removed.
        publisher = Publisher(self._logger, self._config, self._dp,
                              self._archive)
        fa = FTPArchiveHandler(self._logger, self._config, self._dp,
                               self._distribution, publisher)
        fa.createEmptyPocketRequests(fullpublish=True)
        self._publishDefaultOverrides(fa, "main")
        self._publishDefaultFileLists(fa, "main")
        self._addRepositoryFile("main", "tiny", "tiny_0.1.dsc")
        self._addRepositoryFile("main", "tiny", "tiny_0.1.tar.gz")
        self._addRepositoryFile("main", "tiny", "tiny_0.1_i386.deb")
        comp_dir = os.path.join(self._distsdir, "hoary-test", "main")
        os.makedirs(os.path.join(comp_dir, "signed"))
        with open(os.path.join(comp_dir, "signed", "stuff"), "w"):
            pass
        os.symlink("signed", os.path.join(comp_dir, "uefi"))
        os.makedirs(os.path.join(comp_dir, "i18n"))
        for name in ("Translation-de", "Translation-de.gz", "Translation-en",
                     "Translation-en.Z"):
            with open(os.path.join(comp_dir, "i18n", name), "w"):
                pass
        self._distribution["hoary-test"].include_long_descriptions = False

        # Run the publisher once with gzip and bzip2 compressors.
        apt_conf = fa.generateConfig(fullpublish=True)
        with open(apt_conf) as apt_conf_file:
            self.assertIn('Packages::Compress "gzip bzip2";',
                          apt_conf_file.read())
        fa.runApt(apt_conf)
        self.assertContentEqual(["Packages.gz", "Packages.bz2"],
                                os.listdir(
                                    os.path.join(comp_dir, "binary-i386")))
        self.assertContentEqual(["Packages.gz", "Packages.bz2"],
                                os.listdir(
                                    os.path.join(comp_dir, "debian-installer",
                                                 "binary-i386")))
        self.assertContentEqual(["Sources.gz", "Sources.bz2"],
                                os.listdir(os.path.join(comp_dir, "source")))
        self.assertContentEqual([
            "Translation-de", "Translation-de.gz", "Translation-en.gz",
            "Translation-en.bz2"
        ], os.listdir(os.path.join(comp_dir, "i18n")))

        # Try again, this time with gzip and xz compressors.  There are no
        # bzip2 leftovers, but other files are left untouched.
        self._distribution["hoary-test"].index_compressors = [
            IndexCompressionType.GZIP, IndexCompressionType.XZ
        ]
        apt_conf = fa.generateConfig(fullpublish=True)
        with open(apt_conf) as apt_conf_file:
            self.assertIn('Packages::Compress "gzip xz";',
                          apt_conf_file.read())
        fa.runApt(apt_conf)
        self.assertContentEqual(["Packages.gz", "Packages.xz"],
                                os.listdir(
                                    os.path.join(comp_dir, "binary-i386")))
        self.assertContentEqual(["Packages.gz", "Packages.xz"],
                                os.listdir(
                                    os.path.join(comp_dir, "debian-installer",
                                                 "binary-i386")))
        self.assertContentEqual(["Sources.gz", "Sources.xz"],
                                os.listdir(os.path.join(comp_dir, "source")))
        self.assertEqual(["stuff"],
                         os.listdir(os.path.join(comp_dir, "signed")))
        self.assertEqual(["stuff"], os.listdir(os.path.join(comp_dir, "uefi")))
        self.assertContentEqual([
            "Translation-de", "Translation-de.gz", "Translation-en.gz",
            "Translation-en.xz"
        ], os.listdir(os.path.join(comp_dir, "i18n")))
Esempio n. 5
0
    def test_generateConfig_empty_and_careful(self):
        # Generate apt-ftparchive config for an specific empty suite.
        #
        # By passing 'careful_apt' option associated with 'allowed_suite'
        # we can publish only a specific group of the suites even if they
        # are still empty. It makes APT clients happier during development
        # cycle.
        #
        # This test should check:
        #
        #  * if apt.conf was generated correctly.
        #  * a-f runs based on this config without any errors
        #  * a-f *only* creates the wanted archive indexes.
        allowed_suites = set()
        allowed_suites.add(('hoary-test', PackagePublishingPocket.UPDATES))

        publisher = Publisher(self._logger,
                              self._config,
                              self._dp,
                              allowed_suites=allowed_suites,
                              archive=self._archive)

        fa = FTPArchiveHandler(self._logger, self._config, self._dp,
                               self._distribution, publisher)

        fa.createEmptyPocketRequests(fullpublish=True)

        # createEmptyPocketRequests creates empty override and file
        # listings.
        lists = (
            'hoary-test-updates_main_source',
            'hoary-test-updates_main_binary-i386',
            'hoary-test-updates_main_debian-installer_binary-i386',
            'override.hoary-test-updates.main',
            'override.hoary-test-updates.extra.main',
            'override.hoary-test-updates.main.src',
        )

        for listname in lists:
            path = os.path.join(self._config.overrideroot, listname)
            self._verifyEmpty(path)

        # XXX cprov 2007-03-21: see above, byte-to-byte configuration
        # comparing is weak.
        apt_conf = fa.generateConfig(fullpublish=True)
        self.assertTrue(os.path.exists(apt_conf))
        apt_conf_content = file(apt_conf).read()
        sample_content = file(
            os.path.join(self._sampledir,
                         'apt_conf_single_empty_suite_test')).read()
        self.assertEqual(apt_conf_content, sample_content)

        # XXX cprov 2007-03-21: see above, do not run a-f on dev machines.
        fa.runApt(apt_conf)
        self.assertTrue(
            os.path.exists(
                os.path.join(self._distsdir, "hoary-test-updates", "main",
                             "binary-i386", "Packages.gz")))
        self.assertTrue(
            os.path.exists(
                os.path.join(self._distsdir, "hoary-test-updates", "main",
                             "debian-installer", "binary-i386",
                             "Packages.gz")))
        self.assertTrue(
            os.path.exists(
                os.path.join(self._distsdir, "hoary-test-updates", "main",
                             "source", "Sources.gz")))

        self.assertFalse(
            os.path.exists(
                os.path.join(self._distsdir, "hoary-test", "main",
                             "binary-i386", "Packages.gz")))
        self.assertFalse(
            os.path.exists(
                os.path.join(self._distsdir, "hoary-test", "main",
                             "debian-installer", "binary-i386",
                             "Packages.gz")))
        self.assertFalse(
            os.path.exists(
                os.path.join(self._distsdir, "hoary-test", "main", "source",
                             "Sources.gz")))