def main():
    statuses = build.run_build()
    if statuses:
        bad_results, good_results, unmatched_results = statuses
        if bad_results:
            return 1
    return 0
Exemple #2
0
def main():
    statuses = build.run_build()
    if statuses:
        bad_results, good_results, unmatched_results = statuses
        if bad_results:
            return 1
    return 0
Exemple #3
0
    def runTest(self):
        with patch.object(sys, 'argv', self.build_args):
            LOG.info("Running with args %s", self.build_args)
            bad_results, good_results, unmatched_results = build.run_build()

        failures = 0
        for image, result in bad_results.items():
            if image in self.excluded_images:
                if result is 'error':
                    continue
                failures = failures + 1
                LOG.warning(
                    ">>> Expected image '%s' to fail, please update"
                    " the excluded_images in source file above if the"
                    " image build has been fixed.", image)
            else:
                if result is not 'error':
                    continue
                failures = failures + 1
                LOG.critical(">>> Expected image '%s' to succeed!", image)

        for image in unmatched_results.keys():
            LOG.warning(">>> Image '%s' was not matched", image)

        self.assertEqual(failures, 0, "%d failure(s) occurred" % failures)
Exemple #4
0
    def runTest(self):
        with patch.object(sys, 'argv', self.build_args):
            LOG.info("Running with args %s", self.build_args)
            (bad_results, good_results, unmatched_results,
             skipped_results) = build.run_build()

        failures = 0
        for image, result in bad_results.items():
            if image in self.excluded_images:
                if result is 'error':
                    continue
                failures = failures + 1
                LOG.warning(">>> Expected image '%s' to fail, please update"
                            " the excluded_images in source file above if the"
                            " image build has been fixed.", image)
            else:
                if result is not 'error':
                    continue
                failures = failures + 1
                LOG.critical(">>> Expected image '%s' to succeed!", image)

        for image in unmatched_results.keys():
            LOG.warning(">>> Image '%s' was not matched", image)

        self.assertEqual(failures, 0, "%d failure(s) occurred" % failures)
Exemple #5
0
def main():
    try:
        statuses = build.run_build()
        if statuses:
            (bad_results, good_results, unmatched_results,
             skipped_results) = statuses
            if bad_results:
                return 1
        return 0
    except jinja2.exceptions.TemplateSyntaxError as e:
        build.LOG.error("Syntax error in template: %s" % e.name)
        build.LOG.error(e.message)
        return 1
Exemple #6
0
def main():
    try:
        statuses = build.run_build()
        if statuses:
            (bad_results, good_results, unmatched_results,
             skipped_results) = statuses
            if bad_results:
                return 1
        return 0
    except jinja2.exceptions.TemplateSyntaxError as e:
        build.LOG.error("Syntax error in template: %s" % e.name)
        build.LOG.error(e.message)
        return 1
Exemple #7
0
    def runTest(self):
        with patch.object(sys, 'argv', self.build_args):
            LOG.info("Running with args %s", self.build_args)
            (bad_results, good_results, unmatched_results,
             skipped_results) = build.run_build()

        failures = 0
        for image, result in bad_results.items():
            if result is not 'error':
                continue
            failures = failures + 1
            LOG.critical(">>> Expected image '%s' to succeed!", image)

        for image in unmatched_results:
            LOG.warning(">>> Image '%s' was not matched", image)

        self.assertEqual(0, failures, "%d failure(s) occurred" % failures)
Exemple #8
0
 def test_run_build(self, mock_sys):
     result = build.run_build()
     self.assertTrue(result)
Exemple #9
0
 def test_run_build(self, mock_client, mock_sys):
     result = build.run_build()
     self.assertTrue(result)
Exemple #10
0
def cli(config_file=None,
        config_set=None,
        profile=None,
        pattern=None,
        build_dir=None,
        push=None,
        use_cache=None):
    build_config = {}
    with open(config_file, "r") as f:
        build_config = yaml.safe_load(f)

    build_dir = pathlib.Path(build_dir)
    build_dir.mkdir(exist_ok=True)
    source_dir = pathlib.Path("./sources")
    source_dir.mkdir(exist_ok=True)

    kolla_config = {
        # We will chdir into the build directory before invoking Kolla
        "work_dir": ".",
        "config_file": "kolla-build.conf",
        "template_override": "kolla-template-overrides.j2",
        "locals_base": "../sources",
    }

    default_config_set = build_config.get("defaults", {})
    # Extract build conf extras; they are not a "real" kolla config
    # option and can't be passed to Kolla.
    build_conf_extras = default_config_set.pop("build_conf_extras", {})
    if default_config_set:
        kolla_config.update(default_config_set)

    if config_set:
        config_set_name = config_set
        config_set = build_config.get("config_sets", {}).get(config_set_name)
        if not config_set:
            raise ValueError(f"No config set found for '{config_set_name}'")
        cfgset_build_conf_extras = config_set.pop("build_conf_extras", {})
        kolla_config.update(config_set)
        build_conf_extras.update(cfgset_build_conf_extras)

    kolla_namespace = os.getenv("KOLLA_NAMESPACE")
    if kolla_namespace:
        kolla_config["namespace"] = kolla_namespace

    docker_tag = os.getenv("DOCKER_TAG")
    if docker_tag:
        kolla_config["tag"] = docker_tag
    openstack_release = os.getenv("OPENSTACK_BASE_RELEASE")
    if openstack_release:
        kolla_config["openstack_release"] = openstack_release

    profile = profile or os.getenv("KOLLA_BUILD_PROFILE")
    if profile:
        kolla_config["profiles"] = profile.split(",")

    kolla_argv = []
    for arg, value in kolla_config.items():
        if arg == "profiles":
            for profile in value:
                kolla_argv.append(f"--profile={profile}")
        elif value is not None:
            kolla_argv.append(f"--{arg.replace('_', '-')}={value}")

    if push:
        kolla_argv.append("--push")
    if use_cache:
        # Always skip ancestors; we want to explicitly build the ancestor
        # images instead of automagically doing this.
        kolla_argv.append("--skip-parents")
        kolla_argv.append("--cache")
    else:
        kolla_argv.append("--nocache")

    # This argument needs to go last
    pattern = pattern or os.getenv("KOLLA_BUILD_PATTERN")
    if pattern:
        kolla_argv.append(pattern)

    def add_tar_path(additions_dir: pathlib.Path):
        if additions_dir.exists():
            with tarfile.open(source_dir.joinpath("additions.tar"),
                              "w") as tar:
                tar.add(additions_dir, arcname=os.path.sep)

    if kolla_config.get("profiles"):
        for profile in kolla_config["profiles"]:
            additions_dir = pathlib.Path(profile, "additions")
            add_tar_path(additions_dir)
    elif kolla_config.get("profile"):
        additions_dir = pathlib.Path(kolla_config["profile"], "additions")
        add_tar_path(additions_dir)

    shutil.copy(
        "./kolla-template-overrides.j2",
        build_dir.joinpath("kolla-template-overrides.j2"),
    )

    env = Environment(loader=FileSystemLoader("."),
                      autoescape=select_autoescape())
    kolla_build_conf_tmpl = env.get_template("kolla-build.conf.j2")
    with open(pathlib.Path(build_dir, "kolla-build.conf"), "w") as f:
        tmpl_vars = kolla_config.copy()
        tmpl_vars.update(build_conf_extras)
        f.write(kolla_build_conf_tmpl.render(**tmpl_vars))

    os.chdir(build_dir.absolute())

    print("kolla-build \\")
    print("  " + " \\\n  ".join(kolla_argv))
    print()

    # Kolla reads its input straight from sys.argv
    sys.argv = [""] + kolla_argv
    bad, good, unmatched, skipped, unbuildable = kolla_build.run_build()
    if bad:
        sys.exit(1)