コード例 #1
0
ファイル: fedpkg.py プロジェクト: sturivny/packit
    def build(
        self,
        scratch: bool = False,
        nowait: bool = False,
        koji_target: Optional[str] = None,
        srpm_path: Optional[Path] = None,
    ):
        """
        build in koji

        :param scratch: scratch (temporary) build or not?
        :param nowait: False == wait for the build to finish
        :param koji_target: koji target to build in (`koji list-targets`)
        :param srpm_path: use selected SRPM for build, not dist-git repo & ref
        :return:
        """
        cmd = [self.fedpkg_exec, "build"]
        if scratch:
            cmd.append("--scratch")
        if nowait:
            cmd.append("--nowait")
        if koji_target:
            cmd += ["--target", koji_target]
        if srpm_path:
            cmd += ["--srpm", str(srpm_path)]

        try:
            utils.run_command_remote(
                cmd=cmd,
                cwd=self.directory,
                error_message="Submission of build to koji failed.",
                fail=True,
            )

        except PackitCommandFailedError as ex:
            # fail on the fedpkg side, the build is triggered
            if (
                "watch_tasks() got an unexpected keyword argument 'ki_handler'"
                in ex.stderr_output
            ):
                logger.info(
                    "The 'fedpkg build' command crashed which is a known issue: "
                    "the build is submitted in koji anyway."
                )
                logger.debug(ex.stdout_output)

            else:
                raise
コード例 #2
0
    def new_sources(self, sources="", fail=True):
        if not Path(self.directory).is_dir():
            raise Exception("Cannot access fedpkg repository:")

        return utils.run_command_remote(
            cmd=[self.fedpkg_exec, "new-sources", sources],
            cwd=self.directory,
            error_message=f"Adding new sources failed:",
            fail=fail,
        )
コード例 #3
0
 def build(
     self,
     scratch: bool = False,
     nowait: bool = False,
     koji_target: Optional[str] = None,
 ):
     cmd = [self.fedpkg_exec, "build"]
     if scratch:
         cmd.append("--scratch")
     if nowait:
         cmd.append("--nowait")
     if koji_target:
         cmd += ["--target", koji_target]
     utils.run_command_remote(
         cmd=cmd,
         cwd=self.directory,
         error_message="Submission of build to koji failed.",
         fail=True,
     )
コード例 #4
0
    def _run_kinit(self) -> None:
        """
        Run `kinit` if we have fas_user and keytab_path configured.
        """
        if (not self.config.fas_user or not self.config.keytab_path
                or not Path(self.config.keytab_path).is_file()):
            logger.info("Won't be doing kinit, no credentials provided.")
            return

        cmd = [
            "kinit",
            f"{self.config.fas_user}@FEDORAPROJECT.ORG",
            "-k",
            "-t",
            self.config.keytab_path,
        ]

        utils.run_command_remote(
            cmd=cmd,
            error_message="Failed to init kerberos ticket:",
            fail=True)
コード例 #5
0
 def init_ticket(self, keytab: str = None):
     # TODO: this method has nothing to do with fedpkg, pull it out
     if not self.fas_username or not keytab or not Path(keytab).is_file():
         logger.info("won't be doing kinit, no credentials provided")
         return
     cmd = [
         "kinit",
         f"{self.fas_username}@FEDORAPROJECT.ORG",
         "-k",
         "-t",
         keytab,
     ]
     return utils.run_command_remote(
         cmd=cmd, error_message="Failed to init kerberos ticket:", fail=True
     )
コード例 #6
0
 def init_ticket(self, keytab: str = None):
     # TODO: this method has nothing to do with fedpkg, pull it out
     if not keytab and not self.fas_username:
         logger.info("won't be doing kinit, no credentials provided")
         return
     if keytab and Path(keytab).is_file():
         cmd = [
             "kinit",
             f"{self.fas_username}@FEDORAPROJECT.ORG",
             "-k",
             "-t",
             keytab,
         ]
     else:
         # there is no keytab, but user still might have active ticket - try to renew it
         cmd = ["kinit", "-R", f"{self.fas_username}@FEDORAPROJECT.ORG"]
     return utils.run_command_remote(
         cmd=cmd,
         error_message="Failed to init kerberos ticket:",
         fail=True)
コード例 #7
0
    def koji_build(
        self,
        scratch: bool = False,
        nowait: bool = False,
        koji_target: Optional[str] = None,
        srpm_path: Optional[Path] = None,
    ):
        """
        Perform a `koji build` in the repository

        :param scratch: should the build be a scratch build?
        :param nowait: don't wait on build?
        :param koji_target: koji target to pick (see `koji list-targets`)
        :param srpm_path: use selected SRPM for build, not dist-git repo & ref
        """
        if not koji_target:
            raise PackitException(
                "koji target needs to be set when building directly from upstream"
            )
        # we can't use fedpkg b/c upstream repo is not dist-git
        cmd = ["koji", "build"]
        if scratch:
            cmd.append("--scratch")
        if nowait:
            cmd.append("--nowait")
        cmd += [koji_target, str(srpm_path)]
        logger.info("Starting a koji build.")
        if not nowait:
            logger.info(
                "We will be actively waiting for the build to finish, it may take some time."
            )
        out = utils.run_command_remote(
            cmd,
            cwd=self.local_project.working_dir,
            output=True,
            decode=True,
            print_live=True,
        )
        return out