fepitre / rpms / pungi

Forked from rpms/pungi 5 years ago
Clone
4d55a48
From 625183a5a3c35c68184b5da8166775de691e6d61 Mon Sep 17 00:00:00 2001
35a6361
From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= <lsedlar@redhat.com>
35a6361
Date: Wed, 11 Apr 2018 09:20:51 +0200
a3e2978
Subject: [PATCH 3/3] Revert "Ostree can use pkgset repos"
35a6361
35a6361
This reverts commit c7cc200246300c6a3946b2e3a9f5f7693896a7d6.
35a6361
---
4d55a48
 pungi/phases/ostree.py               |  7 +---
4d55a48
 pungi/util.py                        | 35 +++++++++++--------
a431383
 tests/test_config_validate_script.py |  4 ++-
4d55a48
 tests/test_ostree_phase.py           | 52 +++++-----------------------
4d55a48
 tests/test_util.py                   | 26 +++++++++-----
a431383
 5 files changed, 50 insertions(+), 74 deletions(-)
35a6361
35a6361
diff --git a/pungi/phases/ostree.py b/pungi/phases/ostree.py
a431383
index 2918fff8..0550b18c 100644
35a6361
--- a/pungi/phases/ostree.py
35a6361
+++ b/pungi/phases/ostree.py
a431383
@@ -58,12 +58,7 @@ class OSTreeThread(WorkerThread):
35a6361
         repodir = os.path.join(workdir, 'config_repo')
35a6361
         self._clone_repo(repodir, config['config_url'], config.get('config_branch', 'master'))
35a6361
 
35a6361
-        repo_baseurl = compose.paths.work.arch_repo('$basearch', create_dir=False)
a431383
-        comps_repo = compose.paths.work.comps_repo('$basearch', variant=variant, create_dir=False)
a431383
-        repos = shortcuts.force_list(config['repo']) + [translate_path(compose, repo_baseurl)]
a431383
-        if compose.has_comps:
a431383
-            repos.append(translate_path(compose, comps_repo))
a431383
-        repos = get_repo_dicts(repos, logger=self.pool)
35a6361
+        repos = get_repo_dicts(compose, shortcuts.force_list(config['repo']))
35a6361
 
35a6361
         # copy the original config and update before save to a json file
35a6361
         new_config = copy.copy(config)
35a6361
diff --git a/pungi/util.py b/pungi/util.py
4d55a48
index 37b4d5f5..1a95e1f4 100644
35a6361
--- a/pungi/util.py
35a6361
+++ b/pungi/util.py
a3e2978
@@ -731,16 +731,19 @@ def _translate_url_to_repo_id(url):
35a6361
     return ''.join([s if s in list(_REPOID_CHARS) else '_' for s in url])
35a6361
 
35a6361
 
35a6361
-def get_repo_dict(repo):
35a6361
+def get_repo_dict(compose, repo, arch='$basearch'):
35a6361
     """
35a6361
     Convert repo to a dict of repo options.
35a6361
 
35a6361
-    If repo is a string that represents url, set it as 'baseurl' in result dict,
35a6361
-    also generate a repo id/name as 'name' key in result dict.
35a6361
-    If repo is a dict, and if 'name' key is missing in the dict, generate one for it.
35a6361
-    Repo (str or dict) that has not url format is no longer processed.
35a6361
+    If repo is a string, translate it to repo url if necessary (when it's
35a6361
+    not a url), and set it as 'baseurl' in result dict, also generate
35a6361
+    a repo id/name as 'name' key in result dict.
35a6361
+    If repo is a dict, translate value of 'baseurl' key to url if necessary,
35a6361
+    if 'name' key is missing in the dict, generate one for it.
35a6361
 
35a6361
+    @param compose - required for access to variants
35a6361
     @param repo - A string or dict, if it is a dict, key 'baseurl' is required
35a6361
+    @param arch - string to be used as arch in repo url
35a6361
     """
35a6361
     repo_dict = {}
35a6361
     if isinstance(repo, dict):
a3e2978
@@ -750,8 +753,10 @@ def get_repo_dict(repo):
35a6361
             if name is None:
35a6361
                 name = _translate_url_to_repo_id(url)
35a6361
         else:
35a6361
-            # url is variant uid - this possibility is now discontinued
35a6361
-            return {}
35a6361
+            # url is variant uid
35a6361
+            if name is None:
35a6361
+                name = '%s-%s' % (compose.compose_id, url)
35a6361
+            url = get_repo_url(compose, url, arch=arch)
35a6361
         repo['name'] = name
35a6361
         repo['baseurl'] = url
35a6361
         return repo
a3e2978
@@ -762,24 +767,24 @@ def get_repo_dict(repo):
35a6361
             repo_dict['name'] = _translate_url_to_repo_id(repo)
35a6361
             repo_dict['baseurl'] = repo
35a6361
         else:
35a6361
-            return {}
35a6361
+            repo_dict['name'] = '%s-%s' % (compose.compose_id, repo)
35a6361
+            repo_dict['baseurl'] = get_repo_url(compose, repo)
35a6361
+
35a6361
     return repo_dict
35a6361
 
35a6361
 
35a6361
-def get_repo_dicts(repos, logger=None):
35a6361
+def get_repo_dicts(compose, repos, arch='$basearch'):
35a6361
     """
35a6361
     Convert repos to a list of repo dicts.
35a6361
 
35a6361
+    @param compose - required for access to variants
35a6361
     @param repo - A list of string or dict, if item is a dict, key 'baseurl' is required
35a6361
+    @param arch - string to be used as arch in repo url
35a6361
     """
35a6361
     repo_dicts = []
35a6361
     for repo in repos:
35a6361
-        repo_dict = get_repo_dict(repo)
35a6361
-        if repo_dict == {}:
35a6361
-            if logger:
35a6361
-                logger.log_warning("Variant-type source repository is deprecated and will be ignored during 'ostree' phase: %s" % (repo))
35a6361
-        else:
35a6361
-            repo_dicts.append(repo_dict)
35a6361
+        repo_dict = get_repo_dict(compose, repo, arch=arch)
35a6361
+        repo_dicts.append(repo_dict)
35a6361
     return repo_dicts
35a6361
 
35a6361
 
35a6361
diff --git a/tests/test_config_validate_script.py b/tests/test_config_validate_script.py
35a6361
index 031a15a4..c73fe126 100644
35a6361
--- a/tests/test_config_validate_script.py
35a6361
+++ b/tests/test_config_validate_script.py
35a6361
@@ -1,6 +1,7 @@
35a6361
 # -*- coding: utf-8 -*-
35a6361
 
35a6361
 
35a6361
+import mock
35a6361
 import os
35a6361
 import subprocess
35a6361
 import sys
35a6361
@@ -19,7 +20,8 @@ from tests import helpers
35a6361
 
35a6361
 class ConfigValidateScriptTest(helpers.PungiTestCase):
35a6361
 
35a6361
-    def test_validate_dummy_config(self):
35a6361
+    @mock.patch('kobo.shortcuts.run')
35a6361
+    def test_validate_dummy_config(self, run):
35a6361
         DUMMY_CONFIG = os.path.join(HERE, 'data/dummy-pungi.conf')
35a6361
         interp = 'python2' if six.PY2 else 'python3'
35a6361
         p = subprocess.Popen([interp, PUNGI_CONFIG_VALIDATE, DUMMY_CONFIG],
35a6361
diff --git a/tests/test_ostree_phase.py b/tests/test_ostree_phase.py
a3e2978
index c2986bc8..4ce66bbd 100644
35a6361
--- a/tests/test_ostree_phase.py
35a6361
+++ b/tests/test_ostree_phase.py
35a6361
@@ -118,7 +118,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
35a6361
             'koji_profile': 'koji',
35a6361
             'runroot_tag': 'rrt',
35a6361
             'translate_paths': [
35a6361
-                (self.topdir, 'http://example.com')
35a6361
+                (self.topdir + '/compose', 'http://example.com')
35a6361
             ]
35a6361
         })
35a6361
         self.pool = mock.Mock()
a431383
@@ -148,36 +148,6 @@ class OSTreeThreadTest(helpers.PungiTestCase):
a431383
             return {'task_id': 1234, 'retcode': retcode, 'output': 'Foo bar\n'}
a431383
         return fake_runroot
35a6361
 
a431383
-    @mock.patch('pungi.wrappers.scm.get_dir_from_scm')
a431383
-    @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
35a6361
-    def test_extra_config_content(self, KojiWrapper, get_dir_from_scm):
35a6361
-        get_dir_from_scm.side_effect = self._dummy_config_repo
35a6361
-        self.compose.conf['runroot_weights'] = {'ostree': 123}
35a6361
-
35a6361
-        koji = KojiWrapper.return_value
35a6361
-        koji.run_runroot_cmd.side_effect = self._mock_runroot(0)
35a6361
-
35a6361
-        t = ostree.OSTreeThread(self.pool)
35a6361
-
35a6361
-        extra_config_file = os.path.join(self.topdir, 'work/ostree-1/extra_config.json')
35a6361
-        self.assertFalse(os.path.isfile(extra_config_file))
35a6361
-
35a6361
-        t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1)
35a6361
-
35a6361
-        self.assertTrue(os.path.isfile(extra_config_file))
35a6361
-        with open(extra_config_file, 'r') as f:
35a6361
-            extraconf_content = json.load(f)
a431383
-
a431383
-        proper_extraconf_content = {
a431383
-            "repo": [
a431383
-                {"name": "http:__example.com_work__basearch_repo",
a431383
-                 "baseurl": "http://example.com/work/$basearch/repo"},
a431383
-                {"name": "http:__example.com_work__basearch_comps_repo_Everything",
a431383
-                 "baseurl": "http://example.com/work/$basearch/comps_repo_Everything"}
a431383
-            ]
a431383
-        }
35a6361
-        self.assertEqual(proper_extraconf_content, extraconf_content)
35a6361
-
a431383
     @mock.patch('pungi.wrappers.scm.get_dir_from_scm')
a431383
     @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper')
35a6361
     def test_run(self, KojiWrapper, get_dir_from_scm):
a431383
@@ -299,7 +269,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
35a6361
                                     arch='x86_64',
35a6361
                                     ref='fedora-atomic/25/x86_64',
35a6361
                                     commitid=None,
35a6361
-                                    repo_path='http://example.com/place/for/atomic',
35a6361
+                                    repo_path=self.repo,
35a6361
                                     local_repo_path=self.repo)])
35a6361
 
35a6361
     @mock.patch('pungi.wrappers.scm.get_dir_from_scm')
a431383
@@ -432,14 +402,14 @@ class OSTreeThreadTest(helpers.PungiTestCase):
35a6361
         koji.run_runroot_cmd.side_effect = self._mock_runroot(0)
35a6361
 
35a6361
         cfg = {
35a6361
-            'repo': [  # Variant type repos will not be included into extra_config. This part of the config is deprecated
35a6361
-                'Everything',  # do not include
35a6361
+            'repo': [
35a6361
+                'Everything',
35a6361
                 {
35a6361
                     'name': 'repo_a',
35a6361
                     'baseurl': 'http://url/to/repo/a',
35a6361
                     'exclude': 'systemd-container'
35a6361
                 },
35a6361
-                {  # do not include
35a6361
+                {
35a6361
                     'name': 'Server',
35a6361
                     'baseurl': 'Server',
35a6361
                     'exclude': 'systemd-container'
a431383
@@ -458,16 +428,12 @@ class OSTreeThreadTest(helpers.PungiTestCase):
35a6361
 
35a6361
         extra_config_file = os.path.join(self.topdir, 'work/ostree-1/extra_config.json')
35a6361
         self.assertTrue(os.path.isfile(extra_config_file))
35a6361
-        with open(extra_config_file, 'r') as extra_config_fd:
35a6361
-            extra_config = json.load(extra_config_fd)
35a6361
+        extra_config = json.load(open(extra_config_file, 'r'))
35a6361
         self.assertTrue(extra_config.get('keep_original_sources', False))
a431383
-        # should equal to number of valid repositories in cfg['repo'] + default repository + comps repository
a431383
-        self.assertEqual(len(extra_config.get('repo', [])), 3)
a431383
-        self.assertEqual(extra_config.get('repo').pop()['baseurl'],
a431383
-                         'http://example.com/work/$basearch/comps_repo_Everything')
35a6361
-        self.assertEqual(extra_config.get('repo').pop()['baseurl'], 'http://example.com/work/$basearch/repo')
35a6361
+        self.assertEqual(len(extra_config.get('repo', [])), len(cfg['repo']))
35a6361
+        self.assertEqual(extra_config.get('repo').pop()['baseurl'], 'http://example.com/Server/$basearch/os')
35a6361
         self.assertEqual(extra_config.get('repo').pop()['baseurl'], 'http://url/to/repo/a')
35a6361
-
35a6361
+        self.assertEqual(extra_config.get('repo').pop()['baseurl'], 'http://example.com/Everything/$basearch/os')
35a6361
 
35a6361
 if __name__ == '__main__':
35a6361
     unittest.main()
35a6361
diff --git a/tests/test_util.py b/tests/test_util.py
a3e2978
index 9e247cde..2b93e496 100644
35a6361
--- a/tests/test_util.py
35a6361
+++ b/tests/test_util.py
a3e2978
@@ -624,35 +624,43 @@ class GetRepoFuncsTestCase(unittest.TestCase):
35a6361
         self.assertEqual(util.get_repo_urls(self.compose, repos), expect)
35a6361
 
35a6361
     def test_get_repo_dict_from_normal_url(self):
35a6361
-        repo_dict = util.get_repo_dict('http://example.com/repo')
35a6361
+        repo_dict = util.get_repo_dict(self.compose, 'http://example.com/repo')
35a6361
         expect = {'name': 'http:__example.com_repo', 'baseurl': 'http://example.com/repo'}
35a6361
         self.assertEqual(repo_dict, expect)
35a6361
 
35a6361
     def test_get_repo_dict_from_variant_uid(self):
35a6361
-        repo_dict = util.get_repo_dict('Server')  # this repo format is deprecated
35a6361
-        expect = {}
35a6361
+        repo_dict = util.get_repo_dict(self.compose, 'Server')
35a6361
+        expect = {
35a6361
+            'name': "%s-%s" % (self.compose.compose_id, 'Server'),
35a6361
+            'baseurl': 'http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os',
35a6361
+        }
35a6361
         self.assertEqual(repo_dict, expect)
35a6361
 
35a6361
     def test_get_repo_dict_from_repo_dict(self):
35a6361
-        repo = {'baseurl': 'Server'}  # this repo format is deprecated
35a6361
-        expect = {}
35a6361
-        repo_dict = util.get_repo_dict(repo)
35a6361
+        repo = {'baseurl': 'Server'}
35a6361
+        expect = {
35a6361
+            'name': '%s-%s' % (self.compose.compose_id, 'Server'),
35a6361
+            'baseurl': 'http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os'
35a6361
+        }
35a6361
+        repo_dict = util.get_repo_dict(self.compose, repo)
35a6361
         self.assertEqual(repo_dict, expect)
35a6361
 
35a6361
     def test_get_repo_dicts(self):
35a6361
         repos = [
35a6361
             'http://example.com/repo',
35a6361
-            'Server',  # this repo format is deprecated (and will not be included into final repo_dict)
35a6361
-            {'baseurl': 'Client'},  # this repo format is deprecated
35a6361
+            'Server',
35a6361
+            {'baseurl': 'Client'},
35a6361
             {'baseurl': 'ftp://example.com/linux/repo'},
35a6361
             {'name': 'testrepo', 'baseurl': 'ftp://example.com/linux/repo'},
35a6361
         ]
35a6361
         expect = [
35a6361
             {'name': 'http:__example.com_repo', 'baseurl': 'http://example.com/repo'},
35a6361
+            {'name': '%s-%s' % (self.compose.compose_id, 'Server'), 'baseurl': 'http://example.com/RHEL-8.0-20180101.n.0/compose/Server/$basearch/os'},
35a6361
+            {'name': '%s-%s' % (self.compose.compose_id, 'Client'), 'baseurl': 'http://example.com/RHEL-8.0-20180101.n.0/compose/Client/$basearch/os'},
35a6361
             {'name': 'ftp:__example.com_linux_repo', 'baseurl': 'ftp://example.com/linux/repo'},
35a6361
             {'name': 'testrepo', 'baseurl': 'ftp://example.com/linux/repo'},
35a6361
         ]
35a6361
-        repos = util.get_repo_dicts(repos)
35a6361
+        repos = util.get_repo_dicts(self.compose, repos)
35a6361
         self.assertEqual(repos, expect)
35a6361
 
35a6361
 
35a6361
-- 
4d55a48
2.17.1
35a6361