#1284 several fixes for rawihde-to-release command
Merged 4 years ago by praiskup. Opened 4 years ago by praiskup.
Unknown source fix-rawhide-to-release  into  master

file modified
+2 -2
@@ -347,7 +347,7 @@

          try:

              chrootdir = os.path.join(self.opts.destdir, data["ownername"], data["projectname"], data["dest_chroot"])

              if not os.path.exists(chrootdir):

-                 self.log.debug("Create directory: %s", chrootdir)

+                 self.log.info("Create directory: %s", chrootdir)

                  os.makedirs(chrootdir)

  

              for build in data["builds"]:
@@ -355,7 +355,7 @@

                                        data["projectname"], data["rawhide_chroot"], build)

                  if os.path.exists(srcdir):

                      destdir = os.path.join(chrootdir, build)

-                     self.log.debug("Copy directory: %s as %s", srcdir, destdir)

+                     self.log.info("Copy directory: %s as %s", srcdir, destdir)

                      shutil.copytree(srcdir, destdir)

  

                      with open(os.path.join(destdir, "build.info"), "a") as f:

@@ -11,10 +11,18 @@

      type=int

  )

  @click.option(

+     "--retry-forked/--no-retry-forked",

+     default=False,

+     help=(

+         "Generate actions for backend also for already forked builds, useful "

+         "e.g. when previous run of this command failed."

+     )

+ )

+ @click.option(

      "--dist-git-branch", "-b", "branch",

      help="Branch name for this set of new chroots"

  )

- def branch_fedora(fedora_version, branch=None):

+ def branch_fedora(fedora_version, retry_forked, branch=None):

      """

      Branch fedora-rawhide-* chroots to fedora-N* and execute rawhide-to-release

      on them
@@ -30,7 +38,7 @@

          for rch in rawhide_chroots

      }

  

-     create_chroot_function(chroot_pairs.keys(), branch, True)

+     create_chroot_function(chroot_pairs.keys(), branch, False)

  

      for new_chroot, rawhide_chroot in chroot_pairs.items():

-         rawhide_to_release_function(rawhide_chroot, new_chroot)

+         rawhide_to_release_function(rawhide_chroot, new_chroot, retry_forked)

@@ -17,13 +17,22 @@

      "dest_chroot",

      required=True

  )

- def rawhide_to_release(rawhide_chroot, dest_chroot):

+ @click.option(

+     "--retry-forked/--no-retry-forked",

+     default=False,

+     help=(

+         "Generate actions for backend also for already forked builds, useful "

+         "e.g. when previous run of this command failed."

+     )

+ )

+ def rawhide_to_release(rawhide_chroot, dest_chroot, retry_forked):

      """

      Branching

      """

-     return rawhide_to_release_function(rawhide_chroot, dest_chroot)

+     return rawhide_to_release_function(rawhide_chroot, dest_chroot,

+                                        retry_forked)

  

- def rawhide_to_release_function(rawhide_chroot, dest_chroot):

+ def rawhide_to_release_function(rawhide_chroot, dest_chroot, retry_forked):

      mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(dest_chroot).first()

      if not mock_chroot:

          print("Given chroot does not exist. Please run:")
@@ -79,8 +88,10 @@

              continue

  

          for build in fork_builds:

-             if mock_chroot in build.chroots:

-                 # forked chroot already exists, from previous run?

+             chroot_exists = mock_chroot in build.chroots

+ 

+             if chroot_exists and not retry_forked:

+                 # this build should already be forked

                  continue

  

              # rbc means rawhide_build_chroot (we needed short variable)
@@ -89,13 +100,17 @@

                  if rbc.mock_chroot == mock_rawhide_chroot:

                      break

  

-             dest_build_chroot = models.BuildChroot(**rbc.to_dict())

-             dest_build_chroot.mock_chroot_id = mock_chroot.id

-             dest_build_chroot.mock_chroot = mock_chroot

-             dest_build_chroot.status = StatusEnum("forked")

-             db.session.add(dest_build_chroot)

- 

-             data['builds'].append(build.result_dir)

+             if not chroot_exists:

+                 # forked chroot may already exists, e.g. from prevoius

+                 # 'rawhide-to-release-run'

+                 dest_build_chroot = models.BuildChroot(**rbc.to_dict())

+                 dest_build_chroot.mock_chroot_id = mock_chroot.id

+                 dest_build_chroot.mock_chroot = mock_chroot

+                 dest_build_chroot.status = StatusEnum("forked")

+                 db.session.add(dest_build_chroot)

+ 

+             if rbc.result_dir:

+                 data['builds'].append(rbc.result_dir)

  

          if len(data["builds"]):

              actions_logic.ActionsLogic.send_rawhide_to_release(data)