Make external repo URL prefix configurable

Not both Fedora and internal Brew uses config topurl as the external
repo's URL prefix. Hence, make it configurable to fulfill this
difference.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
Chenxiong Qi
2018-10-31 16:41:21 +08:00
parent 917c06ad0c
commit 5d3ea762c6
3 changed files with 46 additions and 37 deletions

View File

@@ -477,6 +477,10 @@ class Config(object):
'default': 'db',
'desc': 'Where to look up for modules. Note that this can (and '
'probably will) be builder-specific.'},
'koji_external_repo_url_prefix': {
'type': str,
'default': 'https://kojipkgs.fedoraproject.org/',
'desc': 'URL prefix of base module\'s external repo.'},
}
def __init__(self, conf_section_obj):

View File

@@ -64,7 +64,7 @@ def find_build_tags_from_external_repos(koji_session, repo_infos):
:rtype: list[str]
"""
re_external_repo_url = r'^{}/repos/(.+-build)/latest/\$arch/?$'.format(
koji_session.opts['topurl'].rstrip('/'))
conf.koji_external_repo_url_prefix.rstrip('/'))
tag_names = []
for info in repo_infos:
om = re.match(re_external_repo_url, info['url'])

View File

@@ -58,51 +58,56 @@ class TestFindUrsineRootTags:
def setup_method(self):
self.koji_session = Mock()
self.koji_session.opts = {'topurl': 'http://example.com/brewroot/'}
self.koji_session.getTag.side_effect = lambda name: \
None if name == 'X-build' else {'name': name}
def test_find_build_tags(self):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'http://example.com/brewroot/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'http://example.com/brewroot/repos/tag-2-build/latest/$arch/'
},
])
with patch.object(conf, 'koji_external_repo_url_prefix',
new='http://example.com/brewroot/'):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'http://example.com/brewroot/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'http://example.com/brewroot/repos/tag-2-build/latest/$arch/'
},
])
assert ['tag-1-build', 'tag-2-build'] == tags
assert ['tag-1-build', 'tag-2-build'] == tags
def test_return_emtpy_if_no_match_external_repo_url(self):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'https://another-site.org/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'https://another-site.org/repos/tag-2-build/latest/$arch/'
},
])
with patch.object(conf, 'koji_external_repo_url_prefix',
new='http://example.com/brewroot/'):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'https://another-site.org/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'https://another-site.org/repos/tag-2-build/latest/$arch/'
},
])
assert [] == tags
assert [] == tags
def test_some_tag_is_not_koji_tag(self):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'http://example.com/brewroot/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'http://example.com/brewroot/repos/X-build/latest/$arch/'
},
])
with patch.object(conf, 'koji_external_repo_url_prefix',
new='http://example.com/brewroot/'):
tags = ursine.find_build_tags_from_external_repos(self.koji_session, [
{
'external_repo_name': 'tag-1-external-repo',
'url': 'http://example.com/brewroot/repos/tag-1-build/latest/$arch/'
},
{
'external_repo_name': 'tag-2-external-repo',
'url': 'http://example.com/brewroot/repos/X-build/latest/$arch/'
},
])
assert ['tag-1-build'] == tags
assert ['tag-1-build'] == tags
class TestGetModulemdsFromUrsineContent:
@@ -140,7 +145,6 @@ class TestGetModulemdsFromUrsineContent:
@patch('koji.ClientSession')
def test_get_modulemds(self, ClientSession):
session = ClientSession.return_value
session.opts = {'topurl': 'http://example.com/'}
# Ensure to to get build tag for further query of ursine content.
# For this test, the build tag is tag-4-build
@@ -175,7 +179,8 @@ class TestGetModulemdsFromUrsineContent:
xmd={'mbs': {'koji_tag': 'module-name2-s-2021-c'}})
koji_tag = 'tag' # It's ok to use arbitrary tag name.
modulemds = ursine.get_modulemds_from_ursine_content(koji_tag)
with patch.object(conf, 'koji_external_repo_url_prefix', new='http://example.com/'):
modulemds = ursine.get_modulemds_from_ursine_content(koji_tag)
test_nsvcs = [item.dup_nsvc() for item in modulemds]
test_nsvcs.sort()