コード例 #1
0
def build_image_set_locked(config, options, multipidfile_state):
    image_type = config.image_type
    config["CDIMAGE_DATE"] = date = next_build_id(config, image_type)
    log_path = None

    try:
        configure_for_project(config)
        log_path = open_log(config)

        if want_live_builds(options):
            log_marker("Building live filesystems")
            live_successful = run_live_builds(config)
            config.limit_arches(live_successful)
        else:
            tracker_set_rebuild_status(config, [0, 1], 2)

        if not is_live_fs_only(config):
            sync_local_mirror(config, multipidfile_state)

            if config["LOCAL"]:
                log_marker("Updating archive of local packages")
                update_local_indices(config)

            build_britney(config)

            log_marker("Extracting debootstrap scripts")
            extract_debootstrap(config)

        if config["UBUNTU_DEFAULTS_LOCALE"]:
            build_ubuntu_defaults_locale(config)
        elif is_live_fs_only(config):
            build_livecd_base(config)
        else:
            if not config["CDIMAGE_PREINSTALLED"]:
                log_marker("Germinating")
                germination = Germination(config)
                germination.run()

                log_marker("Generating new task lists")
                germinate_output = germination.output(config.project)
                germinate_output.write_tasks()

                log_marker("Checking for other task changes")
                germinate_output.update_tasks(date)

            if (config["CDIMAGE_LIVE"] or config["CDIMAGE_SQUASHFS_BASE"] or
                    config["CDIMAGE_PREINSTALLED"]):
                log_marker("Downloading live filesystem images")
                download_live_filesystems(config)

            configure_splash(config)

            run_debian_cd(config)
            fix_permissions(config)

        # Temporarily turned off for live builds.
        if (config["CDIMAGE_INSTALL_BASE"] and
                not config["CDIMAGE_ADDON"] and
                not config["CDIMAGE_PREINSTALLED"]):
            log_marker("Producing installability report")
            check_installable(config)

        if not config["DEBUG"] and not config["CDIMAGE_NOPUBLISH"]:
            log_marker("Publishing")
            tree = Tree.get_daily(config)
            publisher = Publisher.get_daily(tree, image_type)
            publisher.publish(date)

            log_marker("Purging old images")
            publisher.purge()

            log_marker("Triggering mirrors")
            trigger_mirrors(config)

        log_marker("Finished")
        return True
    except Exception as e:
        for line in traceback.format_exc().splitlines():
            logger.error(line)
        sys.stdout.flush()
        sys.stderr.flush()
        if not isinstance(e, LiveBuildsFailed):
            notify_failure(config, log_path)
        return False
コード例 #2
0
class TestGermination(TestCase):
    def setUp(self):
        super(TestGermination, self).setUp()
        self.config = Config(read=False)
        self.germination = Germination(self.config)

    def test_germinate_path(self):
        self.config.root = self.use_temp_dir()

        self.assertRaises(
            GerminateNotInstalled, getattr, self.germination, "germinate_path")

        germinate_dir = os.path.join(self.temp_dir, "germinate")
        old_germinate = os.path.join(germinate_dir, "germinate.py")
        touch(old_germinate)
        os.chmod(old_germinate, 0o755)
        self.assertEqual(old_germinate, self.germination.germinate_path)

        new_germinate = os.path.join(germinate_dir, "bin", "germinate")
        touch(new_germinate)
        os.chmod(new_germinate, 0o755)
        self.assertEqual(new_germinate, self.germination.germinate_path)

    def test_output_dir(self):
        self.config.root = "/cdimage"
        self.config["DIST"] = "raring"
        self.config["IMAGE_TYPE"] = "daily"
        self.assertEqual(
            "/cdimage/scratch/ubuntu/raring/daily/germinate",
            self.germination.output_dir("ubuntu"))

    def test_seed_sources_local_seeds(self):
        self.config["LOCAL_SEEDS"] = "http://www.example.org/"
        self.assertEqual(
            ["http://www.example.org/"],
            self.germination.seed_sources("ubuntu"))

    def test_seed_sources_bzr(self):
        for project, series, owners in (
            ("ubuntu", "raring", ["ubuntu-core-dev"]),
            ("kubuntu", "natty", ["ubuntu-core-dev"]),
            ("kubuntu", "oneiric", ["kubuntu-dev", "ubuntu-core-dev"]),
            ("kubuntu-active", "natty", ["ubuntu-core-dev"]),
            ("kubuntu-active", "oneiric", ["kubuntu-dev", "ubuntu-core-dev"]),
            ("kubuntu-plasma5", "utopic", ["kubuntu-dev", "ubuntu-core-dev"]),
            ("ubuntustudio", "raring",
             ["ubuntustudio-dev", "ubuntu-core-dev"]),
            ("mythbuntu", "raring", ["mythbuntu-dev", "ubuntu-core-dev"]),
            ("xubuntu", "hardy", ["ubuntu-core-dev"]),
            ("xubuntu", "intrepid", ["xubuntu-dev", "ubuntu-core-dev"]),
            ("lubuntu", "raring", ["lubuntu-dev", "ubuntu-core-dev"]),
            ("ubuntu-gnome", "raring",
             ["ubuntu-gnome-dev", "ubuntu-core-dev"]),
            ("ubuntu-budgie", "zesty",
             ["ubuntubudgie-dev", "ubuntu-core-dev"]),
            ("ubuntu-mate", "vivid",
             ["ubuntu-mate-dev", "ubuntu-core-dev"]),
            ("ubuntu-moblin-remix", "hardy", ["moblin", "ubuntu-core-dev"]),
            ("ubuntukylin", "trusty", ["ubuntu-core-dev"]),
            ("ubuntukylin", "utopic",
             ["ubuntukylin-members", "ubuntu-core-dev"]),
        ):
            self.config["DIST"] = series
            sources = [
                "http://bazaar.launchpad.net/~%s/ubuntu-seeds/" % owner
                for owner in owners]
            self.assertEqual(sources, self.germination.seed_sources(project))

    def test_seed_sources_non_bzr(self):
        self.germination = Germination(self.config, prefer_bzr=False)
        self.config["DIST"] = "raring"
        self.assertEqual(
            ["http://people.canonical.com/~ubuntu-archive/seeds/"],
            self.germination.seed_sources("ubuntu"))

    def test_use_bzr_local_seeds(self):
        self.config["LOCAL_SEEDS"] = "http://www.example.org/"
        self.assertFalse(self.germination.use_bzr)

    def test_use_bzr_honours_preference(self):
        self.assertTrue(self.germination.prefer_bzr)
        self.assertTrue(self.germination.use_bzr)
        self.germination.prefer_bzr = False
        self.assertFalse(self.germination.use_bzr)

    def test_make_index(self):
        self.config.root = self.use_temp_dir()
        self.config["DIST"] = "raring"
        self.config["IMAGE_TYPE"] = "daily"
        files = []
        for component in "main", "restricted", "universe", "multiverse":
            source_dir = os.path.join(
                self.temp_dir, "ftp", "dists", "raring", component, "source")
            os.makedirs(source_dir)
            with gzip.GzipFile(
                    os.path.join(source_dir, "Sources.gz"), "wb") as sources:
                sources.write(component.encode("UTF-8"))
                sources.write(b"\n")
            files.append("dists/raring/%s/source/Sources.gz" % component)
        self.germination.make_index("ubuntu", "i386", files[0], files)
        output_file = os.path.join(
            self.temp_dir, "scratch", "ubuntu", "raring", "daily", "germinate",
            "dists", "raring", "main", "source", "Sources.gz")
        self.assertTrue(os.path.exists(output_file))
        with gzip.GzipFile(output_file, "rb") as output_sources:
            self.assertEqual(
                b"main\nrestricted\nuniverse\nmultiverse\n",
                output_sources.read())

    def test_germinate_dists_environment_override(self):
        self.config["GERMINATE_DISTS"] = "sentinel,sentinel-updates"
        self.assertEqual(
            ["sentinel", "sentinel-updates"], self.germination.germinate_dists)

    def test_germinate_dists_proposed(self):
        self.config["DIST"] = "precise"
        self.config["PROPOSED"] = "1"
        self.assertEqual([
            "precise",
            "precise-security",
            "precise-updates",
            "precise-proposed",
        ], self.germination.germinate_dists)

    def test_germinate_dists_no_proposed(self):
        self.config["DIST"] = "raring"
        self.assertEqual([
            "raring",
            "raring-security",
            "raring-updates",
        ], self.germination.germinate_dists)

    def test_seed_dist(self):
        for project, series, seed_dist in (
            ("ubuntu", "raring", "ubuntu.raring"),
            ("ubuntu-server", "breezy", "ubuntu-server.breezy"),
            ("ubuntu-server", "raring", "ubuntu.raring"),
            ("jeos", "breezy", "jeos.breezy"),
            ("jeos", "hardy", "ubuntu.hardy"),
            ("ubuntukylin", "raring", "ubuntu.raring"),
            ("ubuntukylin", "utopic", "ubuntukylin.utopic"),
            ("ubuntu-mid", "hardy", "mobile.hardy"),
            ("ubuntu-netbook", "maverick", "netbook.maverick"),
            ("ubuntu-headless", "lucid", "ubuntu.lucid"),
            ("ubuntu-moblin-remix", "hardy", "moblin.hardy"),
            ("ubuntu-desktop-next", "utopic", "ubuntu-touch.utopic"),
        ):
            self.config["DIST"] = series
            self.assertEqual(seed_dist, self.germination.seed_dist(project))

    def test_components(self):
        self.assertEqual(
            ["main", "restricted"], list(self.germination.components))
        self.config["CDIMAGE_UNSUPPORTED"] = "1"
        self.assertEqual(
            ["main", "restricted", "universe", "multiverse"],
            list(self.germination.components))
        self.config["CDIMAGE_ONLYFREE"] = "1"
        self.assertEqual(
            ["main", "universe"], list(self.germination.components))
        del self.config["CDIMAGE_UNSUPPORTED"]
        self.assertEqual(["main"], list(self.germination.components))

    @mock.patch("subprocess.check_call")
    def test_germinate_arch(self, mock_check_call):
        self.config.root = self.use_temp_dir()
        germinate_path = os.path.join(
            self.temp_dir, "germinate", "bin", "germinate")
        touch(germinate_path)
        os.chmod(germinate_path, 0o755)
        self.config["DIST"] = "raring"
        self.config["IMAGE_TYPE"] = "daily"

        output_dir = "%s/scratch/ubuntu/raring/daily/germinate" % self.temp_dir
        expected_files = []

        for dist in "raring", "raring-security", "raring-updates":
            for suffix in (
                "binary-amd64/Packages.gz",
                "source/Sources.gz",
                "debian-installer/binary-amd64/Packages.gz",
            ):
                for component in "main", "restricted":
                    path = os.path.join(
                        self.temp_dir, "ftp", "dists", dist, component, suffix)
                    os.makedirs(os.path.dirname(path))
                    with gzip.GzipFile(path, "wb"):
                        pass
                expected_files.append(
                    os.path.join(output_dir, "dists", dist, "main", suffix))

        def check_call_side_effect(*args, **kwargs):
            touch(os.path.join(output_dir, "amd64+mac", "structure"))

        mock_check_call.side_effect = check_call_side_effect
        self.germination.germinate_arch("ubuntu", "amd64+mac")
        for expected_file in expected_files:
            self.assertTrue(os.path.exists(expected_file))
        expected_command = [
            germinate_path,
            "--seed-source",
            "http://bazaar.launchpad.net/~ubuntu-core-dev/ubuntu-seeds/",
            "--mirror", "file://%s/" % output_dir,
            "--seed-dist", "ubuntu.raring",
            "--dist", "raring,raring-security,raring-updates",
            "--arch", "amd64",
            "--components", "main",
            "--no-rdepends",
            "--bzr",
        ]
        self.assertEqual(1, mock_check_call.call_count)
        self.assertEqual(expected_command, mock_check_call.call_args[0][0])
        self.assertEqual(
            "%s/amd64+mac" % output_dir, mock_check_call.call_args[1]["cwd"])

    @mock.patch("cdimage.germinate.Germination.germinate_arch")
    def test_germinate_project(self, mock_germinate_arch):
        self.config.root = self.use_temp_dir()
        self.config["DIST"] = "raring"
        self.config["ARCHES"] = "amd64 i386"
        self.config["IMAGE_TYPE"] = "daily"
        self.capture_logging()
        self.germination.germinate_project("ubuntu")
        self.assertTrue(os.path.isdir(os.path.join(
            self.temp_dir, "scratch", "ubuntu", "raring", "daily",
            "germinate")))
        mock_germinate_arch.assert_has_calls(
            [mock.call("ubuntu", "amd64"), mock.call("ubuntu", "i386")])
        self.assertLogEqual([
            "Germinating for raring/amd64 ...",
            "Germinating for raring/i386 ...",
        ])

    @mock.patch("cdimage.germinate.Germination.germinate_project")
    def test_run(self, mock_germinate_project):
        self.config["PROJECT"] = "ubuntu"
        self.config["IMAGE_TYPE"] = "daily"
        self.germination.run()
        mock_germinate_project.assert_called_once_with("ubuntu")

        mock_germinate_project.reset_mock()
        del self.config["PROJECT"]
        self.config["ALL_PROJECTS"] = "ubuntu kubuntu"
        self.config["IMAGE_TYPE"] = "source"
        self.germination.run()
        mock_germinate_project.assert_has_calls(
            [mock.call("ubuntu"), mock.call("kubuntu")])

    def test_output(self):
        self.config.root = self.use_temp_dir()
        self.config["DIST"] = "precise"
        output_dir = self.germination.output_dir("ubuntu")
        touch(os.path.join(output_dir, "STRUCTURE"))
        output = self.germination.output("ubuntu")
        self.assertEqual(self.config, output.config)
        self.assertEqual(output_dir, output.directory)
コード例 #3
0
 def setUp(self):
     super(TestGermination, self).setUp()
     self.config = Config(read=False)
     self.germination = Germination(self.config)
コード例 #4
0
 def test_seed_sources_non_bzr(self):
     self.germination = Germination(self.config, prefer_bzr=False)
     self.config["DIST"] = "raring"
     self.assertEqual(
         ["http://people.canonical.com/~ubuntu-archive/seeds/"],
         self.germination.seed_sources("ubuntu"))