Exemplo n.º 1
0
def test_builder(builder_config):
    metadata_path = os.path.join(os.path.dirname(__file__),
                                 'mock_metadata.yml')
    metadata = MetadataConfig.from_file(metadata_path)
    builder = Builder(builder_config, metadata)
    for build_result in builder.build_package():
        continue
    assert build_result.progress == 100
    assert build_result.parent is None
    assert build_result.interpreter_version == '1.8.7'
    assert build_result.filename
    assert build_result.checksum
    assert build_result.bytes > 0
Exemplo n.º 2
0
    def handle_flag(self, flag):

        app = flag.application
        self.app_name = app.name
        current_package = app.current_package
        force_fresh = flag.options.get(
            NeedsBuildingFlag.Options.build_fresh_package, False)
        interpreter_version = flag.options.get(
            NeedsBuildingFlag.Options.build_interpreter_version)

        system_filename = None
        current_revision = None
        if not force_fresh and current_package:
            system_filename = current_package.filename
            current_revision = current_package.revision_id
            interpreter_version = current_package.interpreter_version

        log.info(_("Building new package for {name} [{id}]").format(
            name=app.name, id=app.safe_id))

        task = self.create_task(app, flag.title, flag=flag.name)

        metadata = flag.application.metadata
        metadata_obj = flag.application.metadata_config
        if not metadata or not metadata_obj:
            log.error(_("Missing or invalid application metadata"))
            self.fail_flag(flag, task)

        upaas_config = load_main_config()
        if not upaas_config:
            log.error(_("Missing or invalid uPaaS configuration"))
            self.fail_flag(flag, task)

        log.info(_("Building package for application {name} "
                   "[{id}]").format(name=flag.application.name,
                                    id=flag.application.safe_id))
        log.info(_("Fresh package: {fresh}").format(fresh=force_fresh))
        log.info(_("Base image: {name}").format(name=system_filename))
        log.info(_("Interpreter version: {ver}").format(
            ver=interpreter_version))
        log.info(_("Current revision: {rev}").format(
            rev=current_revision))

        env = {'UPAAS_SYSTEM_DOMAIN': app.system_domain}
        for feature in app.feature_helper.load_enabled_features():
            feature.before_building(app)
            env = feature.update_env(app, env)

        build_result = None
        try:
            builder = Builder(upaas_config, metadata_obj)
            for result in builder.build_package(
                    system_filename=system_filename,
                    interpreter_version=interpreter_version,
                    current_revision=current_revision,
                    env=env):
                log.debug(_("Build progress: {proc}%").format(
                    proc=result.progress))
                build_result = result
                task.update(set__progress=result.progress)
        except BuildError:
            self.fail_flag(flag, task)
        else:
            self.create_package(app, task, metadata_obj, metadata,
                                build_result, current_package)
        self.mark_task_successful(task)