Exemple #1
0
 def test_checksum_directory(self):
     old_dir = os.path.join(self.temp_dir, "old")
     old_iso_i386_path = os.path.join(old_dir, "foo-i386.iso")
     with mkfile(old_iso_i386_path) as old_iso_i386:
         print("foo-i386.iso", end="", file=old_iso_i386)
     old_metalink_i386_path = os.path.join(old_dir, "foo-i386.metalink")
     with mkfile(old_metalink_i386_path) as old_metalink_i386:
         print("foo-i386.metalink", end="", file=old_metalink_i386)
     self.create_checksum_files(["foo-i386.metalink"], directory=old_dir)
     metalink_amd64_path = os.path.join(self.temp_dir, "foo-amd64.metalink")
     with mkfile(metalink_amd64_path) as metalink_amd64:
         print("foo-amd64.metalink", end="", file=metalink_amd64)
     touch(os.path.join(self.temp_dir, "foo-amd64.list"))
     shutil.copy(old_metalink_i386_path,
                 os.path.join(self.temp_dir, "foo-i386.metalink"))
     metalink_checksum_directory(self.config,
                                 self.temp_dir,
                                 old_directories=[old_dir],
                                 sign=False)
     with open(os.path.join(self.temp_dir, "MD5SUMS-metalink")) as md5sums:
         digests = (
             hashlib.md5(b"foo-amd64.metalink").hexdigest(),
             hashlib.md5(b"foo-i386.metalink").hexdigest(),
         )
         self.assertEqual(
             dedent("""\
             %s *foo-amd64.metalink
             %s *foo-i386.metalink
             """) % digests, md5sums.read())
 def test_checksum_directory(self):
     old_dir = os.path.join(self.temp_dir, "old")
     os.mkdir(old_dir)
     old_iso_i386_path = os.path.join(self.temp_dir, "old", "foo-i386.iso")
     with open(old_iso_i386_path, "w") as old_iso_i386:
         print("foo-i386.iso", end="", file=old_iso_i386)
     old_metalink_i386_path = os.path.join(
         self.temp_dir, "old", "foo-i386.metalink")
     with open(old_metalink_i386_path, "w") as old_metalink_i386:
         print("foo-i386.metalink", end="", file=old_metalink_i386)
     self.create_checksum_files(
         ["foo-i386.metalink"], directory=old_dir)
     metalink_amd64_path = os.path.join(self.temp_dir, "foo-amd64.metalink")
     with open(metalink_amd64_path, "w") as metalink_amd64:
         print("foo-amd64.metalink", end="", file=metalink_amd64)
     touch(os.path.join(self.temp_dir, "foo-amd64.list"))
     shutil.copy(
         old_metalink_i386_path,
         os.path.join(self.temp_dir, "foo-i386.metalink"))
     metalink_checksum_directory(
         self.config, self.temp_dir, old_directories=[old_dir])
     with open(os.path.join(self.temp_dir, "MD5SUMS-metalink")) as md5sums:
         digests = (
             hashlib.md5("foo-amd64.metalink").hexdigest(),
             hashlib.md5("foo-i386.metalink").hexdigest(),
             )
         self.assertEqual(dedent("""\
             %s *foo-amd64.metalink
             %s *foo-i386.metalink
             """) % digests, md5sums.read())
Exemple #3
0
    def publish(self, date):
        self.new_publish_dir(date)
        published = []
        self.checksum_dirs = []
        if not self.config["CDIMAGE_ONLYSOURCE"]:
            for arch in self.config.arches:
                published.extend(
                    list(self.publish_binary(self.publish_type, arch, date)))
            if self.project == "edubuntu" and self.publish_type == "server":
                for arch in self.config.arches:
                    published.extend(
                        list(self.publish_binary("serveraddon", arch, date)))
        published.extend(list(self.publish_source(date)))

        if not published:
            logger.warning("No CDs produced!")
            return

        target_dir = os.path.join(self.publish_base, date)

        source_report = os.path.join(
            self.britney_report, "%s_probs.html" % self.config.series)
        target_report = os.path.join(target_dir, "report.html")
        if (self.config["CDIMAGE_INSTALL_BASE"] and
            os.path.exists(source_report)):
            shutil.copy2(source_report, target_report)
        else:
            osextras.unlink_force(target_report)

        if not self.config["CDIMAGE_ONLYSOURCE"]:
            checksum_directory(
                self.config, target_dir, old_directories=self.checksum_dirs,
                map_expr=r"s/\.\(img\|img\.gz\|iso\|iso\.gz\|tar\.gz\)$/.raw/")
            subprocess.check_call(
                [os.path.join(self.config.root, "bin", "make-web-indices"),
                 target_dir, self.config.series, "daily"])

        target_dir_source = os.path.join(target_dir, "source")
        if os.path.isdir(target_dir_source):
            checksum_directory(
                self.config, target_dir_source,
                old_directories=[os.path.join(self.image_output, "src")],
                map_expr=r"s/\.\(img\|img\.gz\|iso\|iso\.gz\|tar\.gz\)$/.raw/")
            subprocess.check_call(
                [os.path.join(self.config.root, "bin", "make-web-indices"),
                 target_dir_source, self.config.series, "daily"])

        if (self.image_type.endswith("-live") or
            self.image_type.endswith("dvd")):
            # Create and publish metalink files.
            md5sums_metalink = os.path.join(target_dir, "MD5SUMS-metalink")
            md5sums_metalink_gpg = os.path.join(
                target_dir, "MD5SUMS-metalink.gpg")
            osextras.unlink_force(md5sums_metalink)
            osextras.unlink_force(md5sums_metalink_gpg)
            basedir, reldir = self.metalink_dirs(date)
            if subprocess.call([
                os.path.join(self.config.root, "bin", "make-metalink"),
                basedir, self.config.series, reldir, "cdimage.ubuntu.com",
                ]) == 0:
                metalink_checksum_directory(self.config, target_dir)
            else:
                for name in os.listdir(target_dir):
                    if name.endswith(".metalink"):
                        osextras.unlink_force(os.path.join(target_dir, name))

        publish_current = os.path.join(self.publish_base, "current")
        osextras.unlink_force(publish_current)
        os.symlink(date, publish_current)

        manifest_lock = os.path.join(
            self.config.root, "etc", ".lock-manifest-daily")
        try:
            subprocess.check_call(["lockfile", "-r", "4", manifest_lock])
        except subprocess.CalledProcessError:
            logger.error("Couldn't acquire manifest-daily lock!")
            raise
        try:
            manifest_daily = os.path.join(
                self.tree.directory, ".manifest-daily")
            with AtomicFile(manifest_daily) as manifest_daily_file:
                for line in self.tree.manifest():
                    print(line, file=manifest_daily_file)
            os.chmod(
                manifest_daily, os.stat(manifest_daily).st_mode | stat.S_IWGRP)

            # Create timestamps for this run.
            # TODO cjwatson 20120807: Shouldn't these be in www/full
            # rather than www/full[/project]?
            trace_dir = os.path.join(self.full_tree, ".trace")
            osextras.ensuredir(trace_dir)
            fqdn = socket.getfqdn()
            with open(os.path.join(trace_dir, fqdn), "w") as trace_file:
                subprocess.check_call(["date", "-u"], stdout=trace_file)
        finally:
            osextras.unlink_force(manifest_lock)

        subprocess.check_call([
            os.path.join(self.config.root, "bin", "post-qa"), date,
            ] + published)