#262 Save merged repos in the subdirectory according to content-set.
Merged 5 years ago by jkaluza. Opened 5 years ago by jkaluza.
jkaluza/odcs merge-repo-two-repos  into  master

@@ -106,15 +106,17 @@ 

                  data_url = os.path.join(baseurl, data_location)

                  downloader.submit(self._download_file, path, data_url)

  

-     def run(self, arch, repos):

+     def run(self, arch, repos, repo_name):

          """

          Merges multiple RPM repositories and stores the output to

-         `os.path.join(compose.result_repo_dir, arch)`.

+         `os.path.join(compose.result_repo_dir, repo_name, arch)`.

  

          Raises an RuntimeError in case of error.

  

          :param str arch: Architecture of RPMs in repositories.

          :param list repos: List of URLs pointing to repos to merge.

+         :param str repo_name: Name of the repository defining the subdirectory

+             in `compose.result_repo_dir`.

          """

          # Multiple MergeRepo tasks can be running in the same time, so the

          # pulp_repo_cache must be protected by lock.
@@ -150,7 +152,7 @@ 

              if not mergerepo_exe:

                  raise RuntimeError("mergerepo_c is not available on system")

  

-             result_repo_dir = os.path.join(self.compose.result_repo_dir, arch)

+             result_repo_dir = os.path.join(self.compose.result_repo_dir, repo_name, arch)

              makedirs(result_repo_dir)

  

              args = [mergerepo_exe, "--method", "nvr", "-o",

file modified
+4 -4
@@ -90,7 +90,7 @@ 

              first_repo["arches"] = first_repo["arches"].union(repo["arches"])

          return first_repo

  

-     def _merge_repos(self, content_set_repos):

+     def _merge_repos(self, content_set, content_set_repos):

          """

          Merges the repositories of the same arch from `content_set_repos`

          and returns the new repository dict pointing to the newly created
@@ -122,10 +122,10 @@ 

  

          for arch, repos in per_arch_repos.items():

              urls = [repo["url"] for repo in repos]

-             merge_repo.run(arch, urls)

+             merge_repo.run(arch, urls, content_set)

  

          return {

-             "url": self.compose.result_repo_url + "/$basearch",

+             "url": "%s/%s/$basearch" % (self.compose.result_repo_url, content_set),

              "arches": set(per_arch_repos.keys()),

              "sigkeys": content_set_repos[0]["sigkeys"],

          }
@@ -191,7 +191,7 @@ 

              if not merged_repos:

                  # In case we cannot merge repositories by replacing the arch

                  # with $basearch, call mergerepo_c.

-                 merged_repos = self._merge_repos(repos)

+                 merged_repos = self._merge_repos(cs, repos)

              if merged_repos:

                  ret[cs] = merged_repos

              else:

file modified
+5 -5
@@ -170,26 +170,26 @@ 

              ret,

              {

                  "foo-1": {

-                     "url": "http://localhost/odcs/latest-odcs-1-1/compose/Temporary/$basearch",

+                     "url": "http://localhost/odcs/latest-odcs-1-1/compose/Temporary/foo-1/$basearch",

                      "arches": set(["x86_64", "ppc64le"]),

                      "sigkeys": ["SIG1", "SIG2"],

                  }

              })

  

-         makedirs.assert_any_call(c.result_repo_dir + "/x86_64")

-         makedirs.assert_any_call(c.result_repo_dir + "/ppc64le")

+         makedirs.assert_any_call(c.result_repo_dir + "/foo-1/x86_64")

+         makedirs.assert_any_call(c.result_repo_dir + "/foo-1/ppc64le")

  

          repo_prefix = "%s/pulp_repo_cache/content/" % conf.target_dir

          execute_cmd.assert_any_call(

              ['/usr/bin/mergerepo_c', '--method', 'nvr', '-o',

-              c.result_repo_dir + '/x86_64',

+              c.result_repo_dir + '/foo-1/x86_64',

               '--repo-prefix-search', '%s/pulp_repo_cache' % conf.target_dir,

               '--repo-prefix-replace', 'http://localhost/',

               '-r', repo_prefix + "1.0/x86_64/os",

               '-r', repo_prefix + "1.1/x86_64/os"])

          execute_cmd.assert_any_call(

              ['/usr/bin/mergerepo_c', '--method', 'nvr', '-o',

-              c.result_repo_dir + '/ppc64le',

+              c.result_repo_dir + '/foo-1/ppc64le',

               '--repo-prefix-search', '%s/pulp_repo_cache' % conf.target_dir,

               '--repo-prefix-replace', 'http://localhost/',

               '-r', repo_prefix + "1.0/ppc64le/os"])

This fixes an issue when first merged repository was overwriten by
the second one in case we were generating two merged repos in single
compose.

Previously, the merged repo was generated directly in
$results_repo_dir/. In this commit, it is generated in the
$results_repo_dir/$content_set_name/.

Pull-Request has been merged by jkaluza

5 years ago