#1420 Create arch repo when reusing failed
Merged 3 years ago by lsedlar. Opened 3 years ago by hlin.
hlin/pungi RHELCMP-994  into  master

file modified
+19 -17
@@ -90,9 +90,8 @@ 

  

  

  def create_arch_repos(compose, path_prefix, paths, pkgset, mmds):

-     reuse = getattr(pkgset, "reuse", None)

      run_in_threads(

-         _create_arch_repo if reuse is None else _reuse_arch_repo,

+         _create_arch_repo,

          [

              (

                  compose,
@@ -111,12 +110,28 @@ 

  def _create_arch_repo(worker_thread, args, task_num):

      """Create a single pkgset repo for given arch."""

      compose, arch, path_prefix, paths, pkgset, mmd = args

+     repo_dir = compose.paths.work.pkgset_repo(pkgset.name, arch=arch)

+     paths[arch] = repo_dir

+ 

+     # Try to reuse arch repo from old compose

+     reuse = getattr(pkgset, "reuse", None)

+     if reuse:

+         old_repo_dir = compose.paths.old_compose_path(repo_dir)

+         if os.path.isdir(old_repo_dir):

+             msg = "Copying repodata for reuse: %s" % old_repo_dir

+             try:

+                 compose.log_info("[BEGIN] %s", msg)

+                 copy_all(old_repo_dir, repo_dir)

+                 compose.log_info("[DONE ] %s", msg)

+                 return

+             except Exception as e:

+                 compose.log_debug(str(e))

+                 compose.log_info("[FAILED] %s will try to create arch repo", msg)

+ 

      createrepo_c = compose.conf["createrepo_c"]

      createrepo_checksum = compose.conf["createrepo_checksum"]

      repo = CreaterepoWrapper(createrepo_c=createrepo_c)

      repo_dir_global = compose.paths.work.pkgset_repo(pkgset.name, arch="global")

-     repo_dir = compose.paths.work.pkgset_repo(pkgset.name, arch=arch)

-     paths[arch] = repo_dir

      msg = "Running createrepo for arch '%s'" % arch

  

      compose.log_info("[BEGIN] %s", msg)
@@ -156,19 +171,6 @@ 

      compose.log_info("[DONE ] %s", msg)

  

  

- def _reuse_arch_repo(worker_thread, args, task_num):

-     """Reuse a single pkgset repo for given arch."""

-     compose, arch, _, paths, pkgset, _ = args

-     repo_dir = compose.paths.work.pkgset_repo(pkgset.name, arch=arch)

-     paths[arch] = repo_dir

-     old_repo_dir = compose.paths.old_compose_path(repo_dir)

-     msg = "Copying repodata for reuse: %s" % old_repo_dir

- 

-     compose.log_info("[BEGIN] %s", msg)

-     copy_all(old_repo_dir, repo_dir)

-     compose.log_info("[DONE ] %s", msg)

- 

- 

  class MaterializedPackageSet(object):

      """A wrapper for PkgsetBase object that represents the package set created

      as repos on the filesystem.

file modified
+8 -30
@@ -153,47 +153,25 @@ 

              ]

          )

  

-     @mock.patch("pungi.phases.pkgset.common._reuse_arch_repo")

-     def test_call_reuse_arch_repo(self, mock_reuse):

+     @mock.patch("pungi.phases.pkgset.common.os.path.isdir", return_value=True)

+     @mock.patch("pungi.phases.pkgset.common.copy_all")

+     def test_reuse_arch_repo(self, mock_copy_all, mock_isdir):

          self.pkgset.reuse = "/path/to/old/global/repo"

+         old_repo = "/path/to/old/repo"

+         self.compose.paths.old_compose_path = mock.Mock(return_value=old_repo)

          common.create_arch_repos(

              self.compose, self.prefix, self.paths, self.pkgset, None

          )

-         mock_reuse.assert_has_calls(

+         mock_copy_all.assert_has_calls(

              [

                  mock.call(

-                     mock.ANY,

-                     (self.compose, "amd64", self.prefix, self.paths, self.pkgset, None),

-                     1,

+                     old_repo, os.path.join(self.compose.topdir, "work/amd64/repo/foo")

                  ),

                  mock.call(

-                     mock.ANY,

-                     (

-                         self.compose,

-                         "x86_64",

-                         self.prefix,

-                         self.paths,

-                         self.pkgset,

-                         None,

-                     ),

-                     2,

+                     old_repo, os.path.join(self.compose.topdir, "work/x86_64/repo/foo")

                  ),

              ]

          )

- 

-     @mock.patch("pungi.phases.pkgset.common.copy_all")

-     def test_reuse_arch_repo(self, mock_copy_all):

-         self.pkgset.reuse = "/path/to/old/global/repo"

-         old_repo = "/path/to/old/repo"

-         self.compose.paths.old_compose_path = mock.Mock(return_value=old_repo)

-         common._reuse_arch_repo(

-             mock.Mock(),

-             (self.compose, "x86_64", self.prefix, self.paths, self.pkgset, None),

-             1,

-         )

-         mock_copy_all.assert_called_once_with(

-             old_repo, os.path.join(self.compose.topdir, "work/x86_64/repo/foo")

-         )

          self.compose.log_info.assert_has_calls(

              [

                  mock.call("[BEGIN] %s", "Copying repodata for reuse: %s" % old_repo),

Reusing old arch repo may fail for reasons such as arch not
available in old compose or unexpected error when copying data
from old compose.

JIRA: RHELCMP-994
Signed-off-by: Haibo Lin hlin@redhat.com

Looks good to me. :thumbsup:

rebased onto 44a113071b08170b01ab71e0a13268b4911a653d

3 years ago

I rebased the PR using Pagure, and the tests failed. It looks like some calls are maybe ordered incorrectly.

rebased onto 0ab6f48

3 years ago

Pull-Request has been merged by lsedlar

3 years ago