#1921 cli: add regenerate-repos command
Merged 2 years ago by praiskup. Opened 2 years ago by frostyx.
copr/ frostyx/copr cli-generate-repos  into  main

@@ -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

file modified
+24
@@ -610,6 +610,20 @@ 

              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 @@ 

      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\

@@ -60,6 +60,9 @@ 

  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 @@ 

  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

  -------------

  

file modified
+3
@@ -27,3 +27,6 @@ 

  

  # 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

@@ -358,7 +358,7 @@ 

          :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

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.

Build succeeded.

I would rather state what do we mean by repositories, ... "regenerate the project repositories (XML RPM metadata)" or something alike

Hmmm we seem to have some problem with ppc64le emulation? (#1923 created for this).

Man page should be updated, otherwise I think this is OK.

Is there's space to add additional options? Namely <chroot> should be added in the future, to not regenerate all the repositories in large projects if that is not needed.

rebased onto 76caffe06a6e791b6eb50fc7af4863469bb86fdc

2 years ago

Is there's space to add additional options? Namely <chroot> should be added in the future, to not regenerate all the repositories in large projects if that is not needed.

That shouldn't be a problem. We just need ProjectProxy.regenerate_repos to send chroots list as part of its data, the same way e.g. ProjectProxy.edit does it. And of course use them on frontend.

Build succeeded.

Thank you for the review,
updated PTAL.

s/automatical/automatic/

rebased onto de2efb24f8228c558504bd63471ea01f5639dd9f

2 years ago

s/automatical/automatic/

Right. Fixed, PTAL :-)

Build succeeded.

rebased onto 89a5c15

2 years ago

Pull-Request has been merged by praiskup

2 years ago

Build succeeded.