コード例 #1
0
def handle_osbuild_image(options, session, argv):
    "[build] Build images via osbuild"
    args = parse_args(argv)

    name, version, arch, target = args.name, args.version, args.arch, args.target
    distro, image_types = args.distro, args.image_type

    if not image_types:
        image_types = ["qcow2"]

    opts = {}

    if args.release:
        opts["release"] = args.release

    if args.repo:
        opts["repo"] = ",".join(args.repo)

    # Do some early checks to be able to give quick feedback
    check_target(session, target)

    if not options.quiet:
        print("name:", name)
        print("version:", version)
        print("distro:", distro)
        print("arches:", ", ".join(arch))
        print("target:", target)
        print("image types ", str(image_types))
        pprint(opts)

    kl.activate_session(session, options)

    task_id = session.osbuildImage(name,
                                   version,
                                   distro,
                                   image_types,
                                   target,
                                   arch,
                                   opts=opts)

    if not options.quiet:
        print("Created task: %s" % task_id)
        print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id))

    # pylint: disable=protected-access
    if (args.wait is None and kl._running_in_bg()) or args.wait is False:
        # either running in the background or must not wait by user's
        # request. All done.
        return None

    session.logout()
    res = kl.watch_tasks(session, [task_id], quiet=options.quiet)

    if res == 0:
        result = session.getTaskResult(task_id)
        print(result)
    return res
コード例 #2
0
def handle_build(options, session, args, flatpak=False, sourcebuild=False):
    if sourcebuild:
        build_opts, args, opts, parser = parse_source_arguments(options, args)
    else:
        build_opts, args, opts, parser = parse_arguments(
            options, args, flatpak)

    activate_session(session, options)

    target = args[0]
    build_target = session.getBuildTarget(target)
    if not build_target:
        parser.error(_("Unknown build target: %s" % target))
    dest_tag = session.getTag(build_target['dest_tag'])
    if not dest_tag:
        parser.error(
            _("Unknown destination tag: %s" % build_target['dest_tag_name']))
    if dest_tag['locked'] and not build_opts.scratch:
        parser.error(_("Destination tag %s is locked" % dest_tag['name']))

    priority = None
    if build_opts.background:
        # relative to koji.PRIO_DEFAULT
        priority = 5

    if sourcebuild:
        task_id = session.buildSourceContainer(
            target,
            opts,
            priority=priority,
            channel=build_opts.channel_override)
    else:
        source = args[1]
        task_id = session.buildContainer(source,
                                         target,
                                         opts,
                                         priority=priority,
                                         channel=build_opts.channel_override)

    if not build_opts.quiet:
        print("Created task: %s" % task_id)
        print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id))
    if build_opts.wait or (build_opts.wait is None and not _running_in_bg()):
        session.logout()
        rv = watch_tasks(session, [task_id], quiet=build_opts.quiet)

        # Task completed and a result should be available.
        if rv == 0:
            result = session.getTaskResult(task_id)
            print_task_result(task_id, result, options.weburl)

        return rv
    else:
        return
コード例 #3
0
    def test_running_in_bg(self, os_mock):
        os_mock.isatty.return_value = False
        self.assertTrue(_running_in_bg())
        os_mock.isatty.return_value = True
        os_mock.getpgrp.return_value = 0
        os_mock.tcgetpgrp.return_value = 1
        self.assertTrue(_running_in_bg())
        os_mock.tcgetpgrp.return_value = 0
        self.assertFalse(_running_in_bg())

        os_mock.reset_mock()
        os_mock.tcgetpgrp.side_effect = OSError
        self.assertTrue(_running_in_bg())
        os_mock.isatty.assert_called()
        os_mock.getpgrp.assert_called()
        os_mock.tcgetpgrp.assert_called()

        os_mock.reset_mock()
        os_mock.getpgrp.side_effect = OSError
        self.assertTrue(_running_in_bg())
        os_mock.isatty.assert_called()
        os_mock.getpgrp.assert_called()
        os_mock.tcgetpgrp.assert_not_called()

        os_mock.reset_mock()
        os_mock.isatty.side_effect = OSError
        self.assertTrue(_running_in_bg())
        os_mock.isatty.assert_called()
        os_mock.getpgrp.assert_not_called()
        os_mock.tcgetpgrp.assert_not_called()
コード例 #4
0
    def test_running_in_bg(self, os_mock):
        os_mock.isatty.return_value = False
        self.assertTrue(_running_in_bg())
        os_mock.isatty.return_value = True
        os_mock.getpgrp.return_value = 0
        os_mock.tcgetpgrp.return_value = 1
        self.assertTrue(_running_in_bg())
        os_mock.tcgetpgrp.return_value = 0
        self.assertFalse(_running_in_bg())

        os_mock.reset_mock()
        os_mock.tcgetpgrp.side_effect = OSError
        self.assertTrue(_running_in_bg())
        os_mock.isatty.assert_called()
        os_mock.getpgrp.assert_called()
        os_mock.tcgetpgrp.assert_called()

        os_mock.reset_mock()
        os_mock.getpgrp.side_effect = OSError
        self.assertTrue(_running_in_bg())
        os_mock.isatty.assert_called()
        os_mock.getpgrp.assert_called()
        os_mock.tcgetpgrp.assert_not_called()

        os_mock.reset_mock()
        os_mock.isatty.side_effect = OSError
        self.assertTrue(_running_in_bg())
        os_mock.isatty.assert_called()
        os_mock.getpgrp.assert_not_called()
        os_mock.tcgetpgrp.assert_not_called()
コード例 #5
0
def handle_build(options, session, args, flatpak):
    build_opts, args, opts, parser = parse_arguments(options, args, flatpak)

    activate_session(session, options)

    target = args[0]
    if target.lower() == "none" and build_opts.repo_id:
        target = None
        build_opts.skip_tag = True
    else:
        build_target = session.getBuildTarget(target)
        if not build_target:
            parser.error(_("Unknown build target: %s" % target))
        dest_tag = session.getTag(build_target['dest_tag'])
        if not dest_tag:
            parser.error(
                _("Unknown destination tag: %s" %
                  build_target['dest_tag_name']))
        if dest_tag['locked'] and not build_opts.scratch:
            parser.error(_("Destination tag %s is locked" % dest_tag['name']))
    source = args[1]

    priority = None
    if build_opts.background:
        # relative to koji.PRIO_DEFAULT
        priority = 5
    if '://' not in source:
        parser.error(
            _("scm URL does not look like an URL to a source repository"))
    if '#' not in source:
        parser.error(
            _("scm URL must be of the form <url_to_repository>#<revision>)"))
    task_id = session.buildContainer(source,
                                     target,
                                     opts,
                                     priority=priority,
                                     channel=build_opts.channel_override)
    if not build_opts.quiet:
        print("Created task: %s" % task_id)
        print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id))
    if build_opts.wait or (build_opts.wait is None and not _running_in_bg()):
        session.logout()
        rv = watch_tasks(session, [task_id], quiet=build_opts.quiet)

        # Task completed and a result should be available.
        if rv == 0:
            result = session.getTaskResult(task_id)
            print_task_result(task_id, result, options.weburl)

        return rv
    else:
        return
コード例 #6
0
ファイル: cli.py プロジェクト: vrutkovs/koji-containerbuild
def handle_build(options, session, args, flatpak):
    build_opts, args, opts, parser = parse_arguments(options, args, flatpak)

    activate_session(session, options)

    target = args[0]
    if target.lower() == "none" and build_opts.repo_id:
        target = None
        build_opts.skip_tag = True
    else:
        build_target = session.getBuildTarget(target)
        if not build_target:
            parser.error(_("Unknown build target: %s" % target))
        dest_tag = session.getTag(build_target['dest_tag'])
        if not dest_tag:
            parser.error(_("Unknown destination tag: %s" %
                           build_target['dest_tag_name']))
        if dest_tag['locked'] and not build_opts.scratch:
            parser.error(_("Destination tag %s is locked" % dest_tag['name']))
    source = args[1]

    priority = None
    if build_opts.background:
        # relative to koji.PRIO_DEFAULT
        priority = 5
    if '://' not in source:
        parser.error(_("scm URL does not look like an URL to a source repository"))
    if '#' not in source:
        parser.error(_("scm URL must be of the form <url_to_repository>#<revision>)"))
    task_id = session.buildContainer(source, target, opts, priority=priority,
                                     channel=build_opts.channel_override)
    if not build_opts.quiet:
        print "Created task:", task_id
        print "Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)
    if build_opts.wait or (build_opts.wait is None and not _running_in_bg()):
        session.logout()
        rv = clikoji.watch_tasks(session, [task_id], quiet=build_opts.quiet)

        # Task completed and a result should be available.
        if rv == 0:
            result = session.getTaskResult(task_id)
            print_task_result(task_id, result, options.weburl)

        return rv
    else:
        return
コード例 #7
0
def handle_kiwi_build(goptions, session, args):
    "[build] Run a command in a buildroot"
    usage = "usage: %prog kiwi-build [options] <target> <description_scm> <description_path>"
    usage += "\n(Specify the --help global option for a list of other help options)"
    parser = OptionParser(usage=usage)
    parser.add_option("--scratch",
                      action="store_true",
                      default=False,
                      help="Perform a scratch build")
    parser.add_option(
        "--repo",
        action="append",
        help="Specify a repo that will override the repo used to install "
        "RPMs in the image. May be used multiple times. The "
        "build tag repo associated with the target is the default.")
    parser.add_option("--noprogress",
                      action="store_true",
                      help="Do not display progress of the upload")
    parser.add_option("--kiwi-profile",
                      action="store",
                      default=None,
                      help="Select profile from description file")
    parser.add_option("--can-fail",
                      action="store",
                      dest="optional_arches",
                      metavar="ARCH1,ARCH2,...",
                      default="",
                      help="List of archs which are not blocking for build "
                      "(separated by commas.")
    parser.add_option("--arch",
                      action="append",
                      dest="arches",
                      default=[],
                      help="Limit arches to this subset")
    parser.add_option("--nowait",
                      action="store_false",
                      dest="wait",
                      default=True)
    parser.add_option(
        "--wait",
        action="store_true",
        help="Wait on the image creation, even if running in the background")
    (options, args) = parser.parse_args(args)

    if len(args) != 3:
        parser.error("Incorrect number of arguments")
        assert False  # pragma: no cover
    target, scm, path = args

    activate_session(session, goptions)

    kwargs = {
        'scratch':
        options.scratch,
        'optional_arches': [
            canonArch(arch) for arch in options.optional_arches.split(',')
            if arch
        ],
        'profile':
        options.kiwi_profile,
    }

    arches = []
    if options.arches:
        arches = [canonArch(arch) for arch in options.arches]

    task_id = session.kiwiBuild(target=target,
                                arches=arches,
                                desc_url=scm,
                                desc_path=path,
                                **kwargs)

    if not goptions.quiet:
        print("Created task: %d" % task_id)
        print("Task info: %s/taskinfo?taskID=%s" % (goptions.weburl, task_id))
    if options.wait or (options.wait is None and not _running_in_bg()):
        session.logout()
        return watch_tasks(session, [task_id],
                           quiet=goptions.quiet,
                           poll_interval=goptions.poll_interval,
                           topurl=goptions.topurl)
コード例 #8
0
ファイル: cli.py プロジェクト: owtaylor/koji-containerbuild
def handle_build(options, session, args, flatpak):
    "Build a container"
    if flatpak:
        usage = _("usage: %prog flatpak-build [options] target <scm url>")
    else:
        usage = _("usage: %prog container-build [options] target <scm url or "
                  "archive path>")
    usage += _("\n(Specify the --help global option for a list of other help "
               "options)")
    parser = OptionParser(usage=usage)
    if flatpak:
        parser.add_option("-m",
                          "--module",
                          metavar="NAME:STREAM[:VERSION]",
                          help="module to build against")
    parser.add_option("--scratch",
                      action="store_true",
                      help=_("Perform a scratch build"))
    parser.add_option("--wait",
                      action="store_true",
                      help=_("Wait on the build, even if running in the "
                             "background"))
    parser.add_option("--nowait",
                      action="store_false",
                      dest="wait",
                      help=_("Don't wait on build"))
    parser.add_option("--quiet",
                      action="store_true",
                      help=_("Do not print the task information"),
                      default=options.quiet)
    if not flatpak:
        parser.add_option("--noprogress",
                          action="store_true",
                          help=_("Do not display progress of the upload"))
    parser.add_option("--background",
                      action="store_true",
                      help=_("Run the build at a lower priority"))
    parser.add_option("--epoch",
                      help=_("Specify container epoch. Requires koji admin "
                             "permission."))
    parser.add_option("--repo-url",
                      dest='yum_repourls',
                      metavar="REPO_URL",
                      action='append',
                      help=_("URL of yum repo file. May be used multiple "
                             "times."))
    parser.add_option("--git-branch",
                      metavar="GIT_BRANCH",
                      help=_("Git branch"))
    parser.add_option("--channel-override",
                      help=_("Use a non-standard channel [default: %default]"),
                      default=DEFAULT_CHANNEL)
    if not flatpak:
        parser.add_option("--release", help=_("Set release label"))
    (build_opts, args) = parser.parse_args(args)
    if len(args) != 2:
        parser.error(
            _("Exactly two arguments (a build target and a SCM URL "
              "or archive file) are required"))
        assert False

    # Koji API has changed - activate_session requires two arguments
    # _running_in_bg has been moved to koji_cli.lib
    try:
        from koji_cli.lib import _running_in_bg, activate_session
    except ImportError:
        # Create wrappers for backwards compatibility.
        _running_in_bg = clikoji._running_in_bg

        def activate_session(session, options):
            try:
                clikoji.activate_session(session)
            except TypeError:
                clikoji.activate_session(session, options)

    activate_session(session, options)

    target = args[0]
    if target.lower() == "none" and build_opts.repo_id:
        target = None
        build_opts.skip_tag = True
    else:
        build_target = session.getBuildTarget(target)
        if not build_target:
            parser.error(_("Unknown build target: %s" % target))
        dest_tag = session.getTag(build_target['dest_tag'])
        if not dest_tag:
            parser.error(
                _("Unknown destination tag: %s" %
                  build_target['dest_tag_name']))
        if dest_tag['locked'] and not build_opts.scratch:
            parser.error(_("Destination tag %s is locked" % dest_tag['name']))
    source = args[1]
    opts = {}
    if flatpak:
        if not build_opts.module:
            parser.error(_("module must be specified"))
        if not build_opts.git_branch:
            parser.error(_("git-branch must be specified"))

        opts['flatpak'] = True
        opts['module'] = build_opts.module
    for key in ('scratch', 'epoch', 'yum_repourls', 'git_branch'):
        val = getattr(build_opts, key)
        if val is not None:
            opts[key] = val
    priority = None
    if build_opts.background:
        # relative to koji.PRIO_DEFAULT
        priority = 5
    # try to check that source is an archive
    if '://' not in source:
        if flatpak:
            parser.error(
                _("scm URL does not look like an URL to a source repository"))
        # treat source as an archive and upload it
        if not build_opts.quiet:
            print "Uploading archive: %s" % source
        serverdir = clikoji._unique_path('cli-build')
        if _running_in_bg() or build_opts.noprogress or build_opts.quiet:
            callback = None
        else:
            callback = clikoji._progress_callback
        session.uploadWrapper(source, serverdir, callback=callback)
        print
        source = "%s/%s" % (serverdir, os.path.basename(source))
    task_id = session.buildContainer(source,
                                     target,
                                     opts,
                                     priority=priority,
                                     channel=build_opts.channel_override)
    if not build_opts.quiet:
        print "Created task:", task_id
        print "Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)
    if build_opts.wait or (build_opts.wait is None and not _running_in_bg()):
        session.logout()
        rv = clikoji.watch_tasks(session, [task_id], quiet=build_opts.quiet)

        # Task completed and a result should be available.
        if rv == 0:
            result = session.getTaskResult(task_id)
            print_task_result(task_id, result, options.weburl)

        return rv
    else:
        return