From 89a5c15ba6652cdda1928f5764d35cdea60311c9 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Sep 27 2021 06:19:30 +0000 Subject: cli: add regenerate-repos command Fix #1915 See PR#1907 In the PR#1907, @tstellar already implemented the support for regenerating repositories in APIv3 (on the frontend side) and in the python-copr package. I am just finishing it by adding support for copr-cli and covering it with beaker test. Also, there was two typos in python-copr in the API endpoint URL, so I am fixing them as well. --- diff --git a/beaker-tests/Sanity/copr-cli-basic-operations/runtest-regenerate-repos.sh b/beaker-tests/Sanity/copr-cli-basic-operations/runtest-regenerate-repos.sh new file mode 100755 index 0000000..2b6c00c --- /dev/null +++ b/beaker-tests/Sanity/copr-cli-basic-operations/runtest-regenerate-repos.sh @@ -0,0 +1,45 @@ +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +# Load config settings +HERE=$(dirname "$(realpath "$0")") +source "$HERE/config" +source "$HERE/helpers" + +rlJournalStart + rlPhaseStartSetup + setup_checks + rlPhaseEnd + + rlPhaseStartTest + PROJECT=${NAME_PREFIX}RegenerateRepos + URL="$BACKEND_URL/results/$PROJECT/$CHROOT/repodata/" + + # Create a project that doesn't generate repositories automatically + # and build some package in it + rlRun "copr-cli create --chroot $CHROOT --disable_createrepo true $PROJECT" + rlRun "copr-cli build $PROJECT $HELLO" + + # The repository shouldn't provide any packages + rlRun "wget -r -np -P /tmp/$PROJECT/1 $URL" + FILELISTS=`find /tmp/$PROJECT/1/ -name "*-filelists.xml.gz"` + rlRun "gunzip -c $FILELISTS |grep 'packages=\"0\"'" + + # Request to regenerate repositories and wait for a minute for the + # action to finish + rlRun "copr-cli regenerate-repos $PROJECT" + sleep 60 + + # Once the repository is regenerated, some packages should be available + rlRun "wget -r -np -P /tmp/$PROJECT/2 $URL" + FILELISTS=`find /tmp/$PROJECT/2/ -name "*-filelists.xml.gz"` + rlRun "gunzip -c $FILELISTS |grep 'packages=\"4\"'" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm -rf /tmp/$PROJECT" + cleanProject "$PROJECT" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/cli/copr_cli/main.py b/cli/copr_cli/main.py index 9ac0002..89e3e68 100644 --- a/cli/copr_cli/main.py +++ b/cli/copr_cli/main.py @@ -610,6 +610,20 @@ class Commands(object): print("Updating packages in {0} from {1}/{2}.\nPlease be aware that it may take a few minutes " "to duplicate backend data.".format(project.full_name, srcownername, srcprojectname)) + @requires_api_auth + def action_regenerate_repos(self, args): + """ Method called when the 'regenerate-repos' action has been selected + by the user. + + :param args: argparse arguments provided by the user + """ + ownername, projectname = self.parse_name(args.copr) + project = self.client.project_proxy.regenerate_repos( + ownername, projectname) + + print("Submitted action to regenerate repository metadata for " + "the '{0}' project.".format(project.full_name)) + def action_list_builds(self, args): """ Method called when the 'list-builds' action has been selected by the user. @@ -1199,6 +1213,16 @@ def setup_parser(): parser_delete.add_argument("--confirm", action="store_true", help="Confirm forking into existing project") parser_delete.set_defaults(func="action_fork") + # create the parser for the "regenerate-repos" command + parser_regenerate_repos = subparsers.add_parser( + "regenerate-repos", + help=("Regenerate repository metadata for a project. " + "Useful when automatic generation is disabled")) + parser_regenerate_repos.add_argument( + "copr", + help=("Can be just name of project or even in format owner/project.")) + parser_regenerate_repos.set_defaults(func="action_regenerate_repos") + parser_builds = subparsers.add_parser("list-builds", help="List all builds in the project") parser_builds.add_argument("project", help="Which project's builds should be listed.\ Can be just a name of the project or even in format\ diff --git a/cli/man/copr-cli.1.asciidoc b/cli/man/copr-cli.1.asciidoc index 054d9e3..6693c0d 100644 --- a/cli/man/copr-cli.1.asciidoc +++ b/cli/man/copr-cli.1.asciidoc @@ -60,6 +60,9 @@ Download a build to local directory. modify:: Modify existing copr +regenerate-repos:: +Regenerate repository metadata for a project + add-package-*:: Add a new package of the specified source type (e.g. add-package-tito) @@ -194,6 +197,14 @@ Choose the isolation method for running commands in buildroot name:: Can be just name of the project or in form username/projectname or @groupname/projectname. +`copr-cli regenerate-repos [options]` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +usage: copr-cli regenerate-repos [-h] copr + +copr:: +Can be just name of the project or in form username/projectname or @groupname/projectname. + BUILD ACTIONS ------------- diff --git a/cli/man/copr-cli.cheat b/cli/man/copr-cli.cheat index 3fdedc0..6e82e85 100644 --- a/cli/man/copr-cli.cheat +++ b/cli/man/copr-cli.cheat @@ -27,3 +27,6 @@ copr-cli cancel # to build rpm(s) from GIT copr-cli buildscm test-project --clone-url https://pagure.io/copr/copr.git --subdir cli + +# to regenerate repository metadata for a project +copr-cli regenerate-repos test-project diff --git a/python/copr/v3/proxies/project.py b/python/copr/v3/proxies/project.py index 7bec23d..525943a 100644 --- a/python/copr/v3/proxies/project.py +++ b/python/copr/v3/proxies/project.py @@ -358,7 +358,7 @@ class ProjectProxy(BaseProxy): :param str ownername: owner of the project to regenerate :param str projectname: name of the project to regenerate """ - endpoint = "/projects/regenerate-repo/{ownername}/{projectname}" + endpoint = "/project/regenerate-repos/{ownername}/{projectname}" params = { "ownername": ownername, "projectname": projectname