Skip to content

Commit

Permalink
Allow passing a custom URL for the dependency repo
Browse files Browse the repository at this point in the history
Previously, DLRN would always use a hardcoded URL of
"baseurl + /delorean-deps.repo" to fetch a .repo file with a set
of dependency repositories.

This commit enables a new option in projects.ini: "deps_url". When
set, it will point to a custom URL where the .repo file will be
fetched from.

Note if can be a network URL like:

  deps_url=https://trunk.rdoproject.org/centos8-master/test-deps.repo

or a local URL:

  deps_url=file:///tmp/test-deps.repo

Change-Id: Iaf2c4818b0f993a1ca2334c165b57776dc92f6bf
Closes: #38
  • Loading branch information
javierpena committed Apr 19, 2021
1 parent 1a1ab24 commit 7ea4ff4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
18 changes: 11 additions & 7 deletions dlrn/build.py
Expand Up @@ -158,6 +158,12 @@ def build_rpm_wrapper(commit, dev_mode, use_public, bootstrap, env_vars,
newcfg = os.path.join(datadir, mock_config + ".new")
oldcfg = os.path.join(datadir, mock_config)
shutil.copyfile(templatecfg, newcfg)
deps_url = config_options.deps_url.strip()
if deps_url == '' or not deps_url:
if not baseurl:
raise Exception("No baseurl defined")
# Default to baseurl + delorean_deps.repo
deps_url = os.path.join(baseurl, 'delorean-deps.repo')

if (config_options.build_driver ==
'dlrn.drivers.kojidriver.KojiBuildDriver' and
Expand Down Expand Up @@ -195,16 +201,14 @@ def build_rpm_wrapper(commit, dev_mode, use_public, bootstrap, env_vars,
contents = contents[:-1]

try:
if not baseurl:
raise Exception("No baseurl defined")
r = urlopen(baseurl + "/delorean-deps.repo")
r = urlopen(deps_url)
delorean_deps = True
except Exception:
logger.warning(
"Could not open %s/delorean-deps.repo. If some dependent"
" repositories must be included in the mock then check the"
" baseurl value in projects.ini, and make sure the file can be"
" downloaded." % baseurl)
"Could not open %s. If some dependent repositories must be "
"included in the mock configuration, then check the baseurl "
" and deps_url values in projects.ini, and make sure the file "
"can be accesed." % deps_url)
delorean_deps = False

if delorean_deps:
Expand Down
1 change: 1 addition & 0 deletions dlrn/config.py
Expand Up @@ -68,6 +68,7 @@ def _default_templatedir():
'keep_changelog': {'type': 'boolean', 'default': False},
'allow_force_rechecks': {'type': 'boolean', 'default': False},
'use_components': {'type': 'boolean', 'default': False},
'deps_url': {'default': ''},
}
}

Expand Down
29 changes: 29 additions & 0 deletions dlrn/tests/test_build.py
Expand Up @@ -91,6 +91,35 @@ def test_build_rpm_wrapper(self, ld_mock, sh_mock, env_mock, rc_mock):
self.assertTrue(os.path.exists(os.path.join(self.config.datadir,
"dlrn-1.cfg")))

@mock.patch('dlrn.build.urlopen')
@mock.patch('os.listdir', side_effect=mocked_listdir)
def test_build_rpm_wrapper_custom_deps_url(self, ld_mock, url_mock,
sh_mock, env_mock, rc_mock):
self.configfile.set('DEFAULT', 'build_driver',
'dlrn.drivers.mockdriver.MockBuildDriver')
self.configfile.set('DEFAULT', 'deps_url',
'file://%s/custom-deps.repo' %
self.configfile.get('DEFAULT', 'datadir'))
self.config = ConfigOptions(self.configfile)
commit = db.getCommits(self.session)[-1]
build_rpm_wrapper(commit, False, False, False, None, True)
expected = [mock.call('file://%s/custom-deps.repo' %
self.configfile.get('DEFAULT', 'datadir'))]
self.assertEqual(expected, url_mock.call_args_list)

@mock.patch('dlrn.build.urlopen')
@mock.patch('os.listdir', side_effect=mocked_listdir)
def test_build_rpm_wrapper_default_deps_url(self, ld_mock, url_mock,
sh_mock, env_mock, rc_mock):
self.configfile.set('DEFAULT', 'build_driver',
'dlrn.drivers.mockdriver.MockBuildDriver')
self.config = ConfigOptions(self.configfile)
commit = db.getCommits(self.session)[-1]
build_rpm_wrapper(commit, False, False, False, None, True)
expected = [mock.call('file://%s/delorean-deps.repo' %
self.configfile.get('DEFAULT', 'datadir'))]
self.assertEqual(expected, url_mock.call_args_list)

@mock.patch('os.listdir', side_effect=mocked_listdir)
def test_build_rpm_wrapper_release_numbering(self, ld_mock, sh_mock,
env_mock, rc_mock):
Expand Down
7 changes: 7 additions & 0 deletions doc/source/installation.rst
Expand Up @@ -87,6 +87,7 @@ The configuration file looks like this:
include_srpm_in_repo=true
keep_changelog=false
use_components=false
deps_url=
* ``datadir`` is the directory where the packages and repositories will be
created. If not set, it will default to ``./data`` on the parent directory
Expand Down Expand Up @@ -270,6 +271,12 @@ The configuration file looks like this:
Please refer to the `internals <internals.html>`_ page for details on component
support.

* ``deps_url`` allows the user to specify a custom URL for the dependency
repositories file. By default, if not set, DLRN will fetch a file from the URL
formed by ``baseurl`` + ``delorean-deps.repo``. Note it is possible to specify
a URL in the traditional ``http://example.com/path/to/file.repo`` as well as
a local file using ``file:///path/to/file.repo``.

The optional ``[gitrepo_driver]`` section has the following configuration
options:

Expand Down
1 change: 1 addition & 0 deletions projects.ini
Expand Up @@ -29,6 +29,7 @@ include_srpm_in_repo=true
keep_changelog=false
allow_force_rechecks=false
use_components=false
deps_url=

[gitrepo_driver]
# options to be specified if pkginfo_driver is set to
Expand Down

0 comments on commit 7ea4ff4

Please sign in to comment.