fus: Strip protocol from repo path

Only local paths are supported currently. As such, `file://` can be
stripped, and for anything else we should raise an exception.

JIRA: COMPOSE-2996
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-10-03 09:45:14 +02:00
parent 37c89dfde6
commit 4537001ff6
2 changed files with 34 additions and 2 deletions

View File

@ -37,9 +37,9 @@ def get_cmd(
cmd = ["fus", "--verbose", "--arch", arch]
for idx, repo in enumerate(repos):
cmd.append("--repo=repo-%s,repo,%s" % (idx, repo))
cmd.append("--repo=repo-%s,repo,%s" % (idx, _prep_path(repo)))
for idx, repo in enumerate(lookasides):
cmd.append("--repo=lookaside-%s,lookaside,%s" % (idx, repo))
cmd.append("--repo=lookaside-%s,lookaside,%s" % (idx, _prep_path(repo)))
if platform:
cmd.append("--platform=%s" % platform)
@ -52,6 +52,17 @@ def get_cmd(
return cmd
def _prep_path(path):
"""Strip file:// from the path if present or raise exception for other
protocols.
"""
if "://" in path:
proto, path = path.split("://", 2)
if proto != "file":
raise ValueError("Only repositories on local filesystem are supported.")
return path
def parse_output(output):
"""Read output of fus from the given filepath, and return a set of tuples
(NVR, arch, flags) and a set of module NSVCs.

View File

@ -47,6 +47,27 @@ class TestGetCmd(unittest.TestCase):
],
)
def test_strip_file_protocol(self):
cmd = fus.get_cmd("x86_64", ["file:///tmp"], [], [], [], [])
self.assertEqual(
cmd, ["fus", "--verbose", "--arch", "x86_64", "--repo=repo-0,repo,/tmp"]
)
def test_fail_on_http_repo(self):
with self.assertRaises(ValueError):
fus.get_cmd("x86_64", ["http:///tmp"], [], [], [], [])
def test_strip_file_protocol_lookaside(self):
cmd = fus.get_cmd("x86_64", [], ["file:///r"], [], [], [])
self.assertEqual(
cmd,
["fus", "--verbose", "--arch", "x86_64", "--repo=lookaside-0,lookaside,/r"]
)
def test_fail_on_http_repo_lookaside(self):
with self.assertRaises(ValueError):
fus.get_cmd("x86_64", [], ["http:///tmp"], [], [], [])
class TestParseOutput(unittest.TestCase):
def setUp(self):