osbs: Accept local paths as repo URLs
Translate the using configured patterns, and give OSBS a repo file with that URL. JIRA: COMPOSE-3290 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
3efcfede6a
commit
95596f1c69
@ -157,29 +157,44 @@ class OSBSThread(WorkerThread):
|
|||||||
|
|
||||||
def _get_repo(self, compose, repo, gpgkey=None):
|
def _get_repo(self, compose, repo, gpgkey=None):
|
||||||
"""
|
"""
|
||||||
Return repo file URL of repo, if repo contains "://", it's already
|
Return repo file URL of repo, if repo contains "://", it's already a
|
||||||
a URL of repo file. Or it's a variant UID, then write a .repo file
|
URL of repo file. Or it's a variant UID or local path, then write a .repo
|
||||||
pointing to current variant and return the URL to .repo file.
|
file pointing to that location and return the URL to .repo file.
|
||||||
"""
|
"""
|
||||||
if "://" in repo:
|
if "://" in repo:
|
||||||
return repo
|
return repo
|
||||||
|
|
||||||
|
if repo.startswith("/"):
|
||||||
|
# The repo is an absolute path on the filesystem
|
||||||
|
repo_path = repo
|
||||||
|
variant = "local"
|
||||||
|
repo_file = os.path.join(
|
||||||
|
compose.paths.work.tmp_dir(None, None),
|
||||||
|
"compose-rpms-%s-%s.repo" % (variant, self.num),
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# We got a variant name and have to find the repository for that variant.
|
||||||
try:
|
try:
|
||||||
variant = compose.all_variants[repo]
|
variant = compose.all_variants[repo]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
'There is no variant %s to get repo from to pass to OSBS.'
|
"There is no variant %s to get repo from to pass to OSBS." % repo
|
||||||
% (repo))
|
)
|
||||||
os_tree = compose.paths.compose.repository('$basearch', variant,
|
repo_path = compose.paths.compose.repository(
|
||||||
create_dir=False)
|
"$basearch", variant, create_dir=False
|
||||||
repo_file = os.path.join(compose.paths.work.tmp_dir(None, variant),
|
)
|
||||||
'compose-rpms-%s-%s.repo' % (variant, self.num))
|
|
||||||
|
repo_file = os.path.join(
|
||||||
|
compose.paths.work.tmp_dir(None, variant),
|
||||||
|
'compose-rpms-%s-%s.repo' % (variant, self.num),
|
||||||
|
)
|
||||||
|
|
||||||
gpgcheck = 1 if gpgkey else 0
|
gpgcheck = 1 if gpgkey else 0
|
||||||
with open(repo_file, 'w') as f:
|
with open(repo_file, 'w') as f:
|
||||||
f.write('[%s-%s-%s]\n' % (compose.compose_id, variant, self.num))
|
f.write('[%s-%s-%s]\n' % (compose.compose_id, variant, self.num))
|
||||||
f.write('name=Compose %s (RPMs) - %s\n' % (compose.compose_id, variant))
|
f.write('name=Compose %s (RPMs) - %s\n' % (compose.compose_id, variant))
|
||||||
f.write('baseurl=%s\n' % util.translate_path(compose, os_tree))
|
f.write('baseurl=%s\n' % util.translate_path(compose, repo_path))
|
||||||
f.write('enabled=1\n')
|
f.write('enabled=1\n')
|
||||||
f.write('gpgcheck=%s\n' % gpgcheck)
|
f.write('gpgcheck=%s\n' % gpgcheck)
|
||||||
if gpgcheck:
|
if gpgcheck:
|
||||||
|
@ -333,8 +333,9 @@ class OSBSThreadTest(helpers.PungiTestCase):
|
|||||||
'git_branch': 'f24-docker',
|
'git_branch': 'f24-docker',
|
||||||
'name': 'my-name',
|
'name': 'my-name',
|
||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'repo': ['Everything', 'http://pkgs.example.com/my.repo']
|
"repo": ["Everything", "http://pkgs.example.com/my.repo", "/extra/repo"],
|
||||||
}
|
}
|
||||||
|
self.compose.conf["translate_paths"].append(("/extra", "http://example.com"))
|
||||||
self._setupMock(KojiWrapper)
|
self._setupMock(KojiWrapper)
|
||||||
self._assertConfigCorrect(cfg)
|
self._assertConfigCorrect(cfg)
|
||||||
|
|
||||||
@ -348,12 +349,16 @@ class OSBSThreadTest(helpers.PungiTestCase):
|
|||||||
'http://root/work/global/tmp-Server/compose-rpms-Server-1.repo',
|
'http://root/work/global/tmp-Server/compose-rpms-Server-1.repo',
|
||||||
'http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo',
|
'http://root/work/global/tmp-Everything/compose-rpms-Everything-1.repo',
|
||||||
'http://pkgs.example.com/my.repo',
|
'http://pkgs.example.com/my.repo',
|
||||||
|
"http://root/work/global/tmp/compose-rpms-local-1.repo",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
self._assertCorrectCalls(options)
|
self._assertCorrectCalls(options)
|
||||||
self._assertCorrectMetadata()
|
self._assertCorrectMetadata()
|
||||||
self._assertRepoFile(['Server', 'Everything'])
|
self._assertRepoFile(['Server', 'Everything'])
|
||||||
|
|
||||||
|
with open(os.path.join(self.topdir, "work/global/tmp/compose-rpms-local-1.repo")) as f:
|
||||||
|
self.assertIn("baseurl=http://example.com/repo\n", f)
|
||||||
|
|
||||||
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
@mock.patch("pungi.phases.osbs.kojiwrapper.KojiWrapper")
|
||||||
def test_run_with_registry(self, KojiWrapper):
|
def test_run_with_registry(self, KojiWrapper):
|
||||||
cfg = {
|
cfg = {
|
||||||
|
Loading…
Reference in New Issue
Block a user